Commit a352b605 authored by Sergiy's avatar Sergiy Committed by Kostya Shishkov

RTMP packets with one-byte header use previous packet timestamp difference, so

track timestamp difference as well.
Patch by Sergiy (mail.composeAddress("piratfm","gmail.com"))

Originally committed as revision 20714 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 15e65f83
...@@ -93,7 +93,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, ...@@ -93,7 +93,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
hdr >>= 6; hdr >>= 6;
if (hdr == RTMP_PS_ONEBYTE) { if (hdr == RTMP_PS_ONEBYTE) {
timestamp = prev_pkt[channel_id].timestamp; timestamp = prev_pkt[channel_id].ts_delta;
} else { } else {
if (url_read_complete(h, buf, 3) != 3) if (url_read_complete(h, buf, 3) != 3)
return AVERROR(EIO); return AVERROR(EIO);
...@@ -116,9 +116,10 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, ...@@ -116,9 +116,10 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
return AVERROR(EIO); return AVERROR(EIO);
timestamp = AV_RB32(buf); timestamp = AV_RB32(buf);
} }
}
if (hdr != RTMP_PS_TWELVEBYTES) if (hdr != RTMP_PS_TWELVEBYTES)
timestamp += prev_pkt[channel_id].timestamp; timestamp += prev_pkt[channel_id].timestamp;
}
if (ff_rtmp_packet_create(p, channel_id, type, timestamp, data_size)) if (ff_rtmp_packet_create(p, channel_id, type, timestamp, data_size))
return -1; return -1;
p->extra = extra; p->extra = extra;
...@@ -126,6 +127,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, ...@@ -126,6 +127,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
prev_pkt[channel_id].channel_id = channel_id; prev_pkt[channel_id].channel_id = channel_id;
prev_pkt[channel_id].type = type; prev_pkt[channel_id].type = type;
prev_pkt[channel_id].data_size = data_size; prev_pkt[channel_id].data_size = data_size;
prev_pkt[channel_id].ts_delta = timestamp - prev_pkt[channel_id].timestamp;
prev_pkt[channel_id].timestamp = timestamp; prev_pkt[channel_id].timestamp = timestamp;
prev_pkt[channel_id].extra = extra; prev_pkt[channel_id].extra = extra;
while (data_size > 0) { while (data_size > 0) {
...@@ -151,6 +153,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, ...@@ -151,6 +153,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
uint8_t pkt_hdr[16], *p = pkt_hdr; uint8_t pkt_hdr[16], *p = pkt_hdr;
int mode = RTMP_PS_TWELVEBYTES; int mode = RTMP_PS_TWELVEBYTES;
int off = 0; int off = 0;
pkt->ts_delta = pkt->timestamp - prev_pkt[pkt->channel_id].timestamp;
//TODO: header compression //TODO: header compression
if (pkt->channel_id < 64) { if (pkt->channel_id < 64) {
...@@ -165,7 +168,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, ...@@ -165,7 +168,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
if (mode != RTMP_PS_ONEBYTE) { if (mode != RTMP_PS_ONEBYTE) {
uint32_t timestamp = pkt->timestamp; uint32_t timestamp = pkt->timestamp;
if (mode != RTMP_PS_TWELVEBYTES) if (mode != RTMP_PS_TWELVEBYTES)
timestamp -= prev_pkt[pkt->channel_id].timestamp; timestamp = pkt->ts_delta;
bytestream_put_be24(&p, timestamp >= 0xFFFFFF ? 0xFFFFFF : timestamp); bytestream_put_be24(&p, timestamp >= 0xFFFFFF ? 0xFFFFFF : timestamp);
if (mode != RTMP_PS_FOURBYTES) { if (mode != RTMP_PS_FOURBYTES) {
bytestream_put_be24(&p, pkt->data_size); bytestream_put_be24(&p, pkt->data_size);
...@@ -200,6 +203,7 @@ int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, ...@@ -200,6 +203,7 @@ int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
pkt->type = type; pkt->type = type;
pkt->timestamp = timestamp; pkt->timestamp = timestamp;
pkt->extra = 0; pkt->extra = 0;
pkt->ts_delta = 0;
return 0; return 0;
} }
......
...@@ -75,7 +75,8 @@ enum RTMPPacketSize { ...@@ -75,7 +75,8 @@ enum RTMPPacketSize {
typedef struct RTMPPacket { typedef struct RTMPPacket {
uint8_t channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though) uint8_t channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though)
RTMPPacketType type; ///< packet payload type RTMPPacketType type; ///< packet payload type
uint32_t timestamp; ///< packet full timestamp or timestamp increment to the previous one in milliseconds (latter only for media packets) uint32_t timestamp; ///< packet full timestamp
uint32_t ts_delta; ///< timestamp increment to the previous one in milliseconds (latter only for media packets)
uint32_t extra; ///< probably an additional channel ID used during streaming data uint32_t extra; ///< probably an additional channel ID used during streaming data
uint8_t *data; ///< packet payload uint8_t *data; ///< packet payload
int data_size; ///< packet payload size int data_size; ///< packet payload size
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment