Write a basic header into buf and forward the buf.
| 577 | |
| 578 | // Write a basic header into buf and forward the buf. |
| 579 | static void |
| 580 | WriteBasicHeader(char** buf, RtmpChunkType chunk_type, uint32_t cs_id) { |
| 581 | char* out = *buf; |
| 582 | if (cs_id < 2) { |
| 583 | CHECK(false) << "Reserved chunk_stream_id=" << cs_id; |
| 584 | } else if (cs_id <= 63) { |
| 585 | *out++ = (((uint32_t)chunk_type << 6) | cs_id); |
| 586 | } else if (cs_id <= 319) { |
| 587 | *out++ = ((uint32_t)chunk_type << 6); |
| 588 | *out++ = cs_id - 64; |
| 589 | } else if (cs_id <= RTMP_MAX_CHUNK_STREAM_ID) { |
| 590 | *out++ = (((uint32_t)chunk_type << 6) | 1); |
| 591 | *out++ = (cs_id - 64) & 0xFF; |
| 592 | *out++ = ((cs_id - 64) >> 8); |
| 593 | } else { |
| 594 | CHECK(false) << "Invalid chunk_stream_id=" << cs_id; |
| 595 | } |
| 596 | *buf = out; |
| 597 | } |
| 598 | |
| 599 | // Write all data in *buf into fd. |
| 600 | // Returns 0 on success, -1 otherwise. |