diff options
author | Sergiy <piratfm@gmail.com> | 2009-12-04 15:01:58 +0000 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2009-12-04 15:01:58 +0000 |
commit | 84a29dc10a9b51a20ea628480df61b43c2b655f8 (patch) | |
tree | c2057b696fff0843abaf2aa60ef56b2bea6f5e0d /libavformat/rtmppkt.c | |
parent | 1e68cefe546d8b8eda4248113f2635dbbf1df071 (diff) | |
download | ffmpeg-84a29dc10a9b51a20ea628480df61b43c2b655f8.tar.gz |
Compress headers for output RTMP packets.
Patch by Sergiy (piratfmGMAIL)
Originally committed as revision 20728 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/rtmppkt.c')
-rw-r--r-- | libavformat/rtmppkt.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index 2eab1c13df..4ee06bc341 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -155,7 +155,19 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, int off = 0; pkt->ts_delta = pkt->timestamp - prev_pkt[pkt->channel_id].timestamp; - //TODO: header compression + //if channel_id = 0, this is first presentation of prev_pkt, send full hdr. + if (prev_pkt[pkt->channel_id].channel_id && + pkt->extra == prev_pkt[pkt->channel_id].extra) { + if (pkt->type == prev_pkt[pkt->channel_id].type && + pkt->data_size == prev_pkt[pkt->channel_id].data_size) { + mode = RTMP_PS_FOURBYTES; + if (pkt->ts_delta == prev_pkt[pkt->channel_id].ts_delta) + mode = RTMP_PS_ONEBYTE; + } else { + mode = RTMP_PS_EIGHTBYTES; + } + } + if (pkt->channel_id < 64) { bytestream_put_byte(&p, pkt->channel_id | (mode << 6)); } else if (pkt->channel_id < 64 + 256) { @@ -179,6 +191,18 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, if (timestamp >= 0xFFFFFF) bytestream_put_be32(&p, timestamp); } + // save history + prev_pkt[pkt->channel_id].channel_id = pkt->channel_id; + prev_pkt[pkt->channel_id].type = pkt->type; + prev_pkt[pkt->channel_id].data_size = pkt->data_size; + prev_pkt[pkt->channel_id].timestamp = pkt->timestamp; + if (mode != RTMP_PS_TWELVEBYTES) { + prev_pkt[pkt->channel_id].ts_delta = pkt->ts_delta; + } else { + prev_pkt[pkt->channel_id].ts_delta = pkt->timestamp; + } + prev_pkt[pkt->channel_id].extra = pkt->extra; + url_write(h, pkt_hdr, p-pkt_hdr); while (off < pkt->data_size) { int towrite = FFMIN(chunk_size, pkt->data_size - off); |