[FFmpeg-devel] ff_rtmp_packet_write do not allow channel_id larger than 64 when send chunk with header type 3.

Submitted by Wentao Tang on Jan. 23, 2017, 9:34 a.m.

Details

Message ID HK2PR0401MB131602F0F304779DA23DBDB393720@HK2PR0401MB1316.apcprd04.prod.outlook.com
State New
Headers show

Commit Message

Wentao Tang Jan. 23, 2017, 9:34 a.m.
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 <wentao.t@hotmail.com>
---
 libavformat/rtmppkt.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

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(&p, pkt->channel_id | (mode << 6));
-    } else if (pkt->channel_id < 64 + 256) {
-        bytestream_put_byte(&p, 0               | (mode << 6));
-        bytestream_put_byte(&p, pkt->channel_id - 64);
-    } else {
-        bytestream_put_byte(&p, 1               | (mode << 6));
-        bytestream_put_le16(&p, pkt->channel_id - 64);
-    }
+    ff_rtmp_packet_write_chunk_basic_header(&p, mode, pkt->channel_id);
+
     if (mode != RTMP_PS_ONEBYTE) {
         bytestream_put_be24(&p, 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, &marker, 1)) < 0)
+            p = pkt_hdr;
+            ff_rtmp_packet_write_chunk_basic_header(&p, 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 == 0xFFFFFF) {
                 uint8_t ts_header[4];
                 AV_WB32(ts_header, timestamp);