[FFmpeg-devel] [PATCH] ff_rtmp_packet_write do not allow channel_id larger than 64 when send chunk with header type 3.
Although ffmpeg use internel defined video and audio channel ids that are than less than 64, I think it's better to patch ff_rtmp_packet_write write chunk logic for more clearness? Signed-off-by: Wentao--- libavformat/rtmppkt.c | 31 +++ 1 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index cde0da7..51288ad 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -310,6 +310,18 @@ int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size, } } +static void ff_rtmp_packet_write_chunk_basic_header(uint8_t **p, int mode, int channel_id) { +if (channel_id < 64) { +bytestream_put_byte(p, channel_id | (mode << 6)); +} else if (channel_id < 64 + 256) { +bytestream_put_byte(p, 0 | (mode << 6)); +bytestream_put_byte(p, channel_id - 64); +} else { +bytestream_put_byte(p, 1 | (mode << 6)); +bytestream_put_le16(p, channel_id - 64); +} +} + int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, int chunk_size, RTMPPacket **prev_pkt_ptr, int *nb_prev_pkt) @@ -354,15 +366,8 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, } } -if (pkt->channel_id < 64) { -bytestream_put_byte(, pkt->channel_id | (mode << 6)); -} else if (pkt->channel_id < 64 + 256) { -bytestream_put_byte(, 0 | (mode << 6)); -bytestream_put_byte(, pkt->channel_id - 64); -} else { -bytestream_put_byte(, 1 | (mode << 6)); -bytestream_put_le16(, pkt->channel_id - 64); -} +ff_rtmp_packet_write_chunk_basic_header(, mode, pkt->channel_id); + if (mode != RTMP_PS_ONEBYTE) { bytestream_put_be24(, pkt->ts_field); if (mode != RTMP_PS_FOURBYTES) { @@ -391,10 +396,12 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, return ret; off += towrite; if (off < pkt->size) { -uint8_t marker = 0xC0 | pkt->channel_id; -if ((ret = ffurl_write(h, , 1)) < 0) +p = pkt_hdr; +ff_rtmp_packet_write_chunk_basic_header(, RTMP_PS_ONEBYTE, pkt->channel_id); +if ((ret = ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0) return ret; -written++; +written += p - pkt_hdr; + if (pkt->ts_field == 0xFF) { uint8_t ts_header[4]; AV_WB32(ts_header, timestamp); -- 1.7.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] libavformat/rtmppkt.c ff_rtmp_packet_write write RTMP_PS_ONEBYTE chunks based on hypothesis than channel_id < 64.
Although ffmpeg use internel defined video and audio channel ids that are than less than 64, I think it's better to patch ff_rtmp_packet_write write chunk logic for more clearness? here is the patch(already tested by changing RTMP_VIDEO_CHANNEL >64 even >256): diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index cde0da7..51288ad 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -310,6 +310,18 @@ int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size, } } +static void ff_rtmp_packet_write_chunk_basic_header(uint8_t **p, int mode, int channel_id) { +if (channel_id < 64) { +bytestream_put_byte(p, channel_id | (mode << 6)); +} else if (channel_id < 64 + 256) { +bytestream_put_byte(p, 0 | (mode << 6)); +bytestream_put_byte(p, channel_id - 64); +} else { +bytestream_put_byte(p, 1 | (mode << 6)); +bytestream_put_le16(p, channel_id - 64); +} +} + int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, int chunk_size, RTMPPacket **prev_pkt_ptr, int *nb_prev_pkt) @@ -354,15 +366,8 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, } } -if (pkt->channel_id < 64) { -bytestream_put_byte(, pkt->channel_id | (mode << 6)); -} else if (pkt->channel_id < 64 + 256) { -bytestream_put_byte(, 0 | (mode << 6)); -bytestream_put_byte(, pkt->channel_id - 64); -} else { -bytestream_put_byte(, 1 | (mode << 6)); -bytestream_put_le16(, pkt->channel_id - 64); -} +ff_rtmp_packet_write_chunk_basic_header(, mode, pkt->channel_id); + if (mode != RTMP_PS_ONEBYTE) { bytestream_put_be24(, pkt->ts_field); if (mode != RTMP_PS_FOURBYTES) { @@ -391,10 +396,12 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, return ret; off += towrite; if (off < pkt->size) { -uint8_t marker = 0xC0 | pkt->channel_id; -if ((ret = ffurl_write(h, , 1)) < 0) +p = pkt_hdr; +ff_rtmp_packet_write_chunk_basic_header(, RTMP_PS_ONEBYTE, pkt->channel_id); +if ((ret = ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0) return ret; -written++; +written += p - pkt_hdr; + if (pkt->ts_field == 0xFF) { uint8_t ts_header[4]; AV_WB32(ts_header, timestamp); ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel