Commit 3c6a9f66 authored by Baptiste Coudurier's avatar Baptiste Coudurier

pass dts and pts through ffm, should fix streaming b frames

Originally committed as revision 13725 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 8983aa33
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
#define PACKET_ID 0x666d #define PACKET_ID 0x666d
/* each packet contains frames (which can span several packets */ /* each packet contains frames (which can span several packets */
#define FRAME_HEADER_SIZE 8 #define FRAME_HEADER_SIZE 16
#define FLAG_KEY_FRAME 0x01 #define FLAG_KEY_FRAME 0x01
#define FLAG_DTS 0x02
enum { enum {
READ_HEADER, READ_HEADER,
...@@ -41,11 +42,10 @@ typedef struct FFMContext { ...@@ -41,11 +42,10 @@ typedef struct FFMContext {
/* only reading mode */ /* only reading mode */
offset_t write_index, file_size; offset_t write_index, file_size;
int read_state; int read_state;
uint8_t header[FRAME_HEADER_SIZE]; uint8_t header[FRAME_HEADER_SIZE+4];
/* read and write */ /* read and write */
int first_packet; /* true if first packet, needed to set the discontinuity tag */ int first_packet; /* true if first packet, needed to set the discontinuity tag */
int first_frame_in_packet; /* true if first frame in packet, needed to know if PTS information is valid */
int packet_size; int packet_size;
int frame_offset; int frame_offset;
int64_t pts; int64_t pts;
......
...@@ -100,7 +100,6 @@ static int ffm_read_data(AVFormatContext *s, ...@@ -100,7 +100,6 @@ static int ffm_read_data(AVFormatContext *s,
get_be16(pb); /* PACKET_ID */ get_be16(pb); /* PACKET_ID */
fill_size = get_be16(pb); fill_size = get_be16(pb);
ffm->pts = get_be64(pb); ffm->pts = get_be64(pb);
ffm->first_frame_in_packet = 1;
frame_offset = get_be16(pb); frame_offset = get_be16(pb);
get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE); get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);
ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size); ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);
...@@ -361,7 +360,7 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -361,7 +360,7 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
switch(ffm->read_state) { switch(ffm->read_state) {
case READ_HEADER: case READ_HEADER:
if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) { if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) {
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
} }
dprintf(s, "pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n", dprintf(s, "pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n",
...@@ -369,6 +368,9 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -369,6 +368,9 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) != if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
FRAME_HEADER_SIZE) FRAME_HEADER_SIZE)
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
if (ffm->header[1] & FLAG_DTS)
if (ffm_read_data(s, ffm->header+16, 4, 1) != 4)
return AVERROR(EAGAIN);
#if 0 #if 0
av_hexdump_log(s, AV_LOG_DEBUG, ffm->header, FRAME_HEADER_SIZE); av_hexdump_log(s, AV_LOG_DEBUG, ffm->header, FRAME_HEADER_SIZE);
#endif #endif
...@@ -400,11 +402,11 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -400,11 +402,11 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
av_free_packet(pkt); av_free_packet(pkt);
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
} }
if (ffm->first_frame_in_packet) pkt->pts = AV_RB64(ffm->header+8);
{ if (ffm->header[1] & FLAG_DTS)
pkt->pts = ffm->pts; pkt->dts = pkt->pts - AV_RB32(ffm->header+16);
ffm->first_frame_in_packet = 0; else
} pkt->dts = pkt->pts;
pkt->duration = duration; pkt->duration = duration;
break; break;
} }
......
...@@ -197,6 +197,7 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -197,6 +197,7 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
AVStream *st = s->streams[pkt->stream_index]; AVStream *st = s->streams[pkt->stream_index];
int64_t pts; int64_t pts;
uint8_t header[FRAME_HEADER_SIZE]; uint8_t header[FRAME_HEADER_SIZE];
int header_size = FRAME_HEADER_SIZE;
pts = s->timestamp + pkt->pts; pts = s->timestamp + pkt->pts;
/* packet size & key_frame */ /* packet size & key_frame */
...@@ -206,7 +207,13 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -206,7 +207,13 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
header[1] |= FLAG_KEY_FRAME; header[1] |= FLAG_KEY_FRAME;
AV_WB24(header+2, pkt->size); AV_WB24(header+2, pkt->size);
AV_WB24(header+5, pkt->duration); AV_WB24(header+5, pkt->duration);
ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1); AV_WB64(header+8, pts);
if (pkt->pts != pkt->dts) {
header[1] |= FLAG_DTS;
AV_WB32(header+16, pkt->pts - pkt->dts);
header_size += 4;
}
ffm_write_data(s, header, header_size, pts, 1);
ffm_write_data(s, pkt->data, pkt->size, pts, 0); ffm_write_data(s, pkt->data, pkt->size, pts, 0);
return 0; return 0;
......
...@@ -15,9 +15,9 @@ bdb7484c68db722f66ba1630cf79844c *./tests/data/b-libav.mpg ...@@ -15,9 +15,9 @@ bdb7484c68db722f66ba1630cf79844c *./tests/data/b-libav.mpg
d6fdeb9f7083cc827f9510c6c4517dc0 *./tests/data/b-libav.swf d6fdeb9f7083cc827f9510c6c4517dc0 *./tests/data/b-libav.swf
335771 ./tests/data/b-libav.swf 335771 ./tests/data/b-libav.swf
./tests/data/b-libav.swf CRC=0xe14e8847 ./tests/data/b-libav.swf CRC=0xe14e8847
bf28235fdc3bdd77faf251a239b6bc58 *./tests/data/b-libav.ffm bbdd9a4904eceb530b1a9ae02c48d76f *./tests/data/b-libav.ffm
380928 ./tests/data/b-libav.ffm 380928 ./tests/data/b-libav.ffm
./tests/data/b-libav.ffm CRC=0xca8f6870 ./tests/data/b-libav.ffm CRC=0x2b71a386
f8ad5bd78f4d012a8ce9570aa395ac54 *./tests/data/b-libav.flv f8ad5bd78f4d012a8ce9570aa395ac54 *./tests/data/b-libav.flv
335833 ./tests/data/b-libav.flv 335833 ./tests/data/b-libav.flv
./tests/data/b-libav.flv CRC=0xe14e8847 ./tests/data/b-libav.flv CRC=0xe14e8847
......
...@@ -2830,7 +2830,7 @@ ret: 0 st:-1 ts:-0.645825 flags:1 ...@@ -2830,7 +2830,7 @@ ret: 0 st:-1 ts:-0.645825 flags:1
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1
---------------- ----------------
tests/data/b-libav.ffm tests/data/b-libav.ffm
ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st:-1 ts:-1.000000 flags:0 ret: 0 st:-1 ts:-1.000000 flags:0
ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st:-1 ts:1.894167 flags:1 ret: 0 st:-1 ts:1.894167 flags:1
...@@ -2838,15 +2838,15 @@ ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1 ...@@ -2838,15 +2838,15 @@ ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 0 ts:0.788334 flags:0 ret: 0 st: 0 ts:0.788334 flags:0
ret: 0 st: 1 dts:0.731429 pts:0.731429 pos:307200 size:209 flags:1 ret: 0 st: 1 dts:0.731429 pts:0.731429 pos:307200 size:209 flags:1
ret: 0 st: 0 ts:-0.317499 flags:1 ret: 0 st: 0 ts:-0.317499 flags:1
ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 1 ts:2.576668 flags:0 ret: 0 st: 1 ts:2.576668 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1
ret: 0 st: 1 ts:1.470835 flags:1 ret: 0 st: 1 ts:1.470835 flags:1
ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st:-1 ts:0.365002 flags:0 ret: 0 st:-1 ts:0.365002 flags:0
ret: 0 st: 0 dts:0.339592 pts:0.339592 pos:147456 size:12220 flags:0 ret: 0 st: 1 dts:0.313469 pts:0.313469 pos:147456 size:209 flags:1
ret: 0 st:-1 ts:-0.740831 flags:1 ret: 0 st:-1 ts:-0.740831 flags:1
ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 0 ts:2.153336 flags:0 ret: 0 st: 0 ts:2.153336 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1
ret: 0 st: 0 ts:1.047503 flags:1 ret: 0 st: 0 ts:1.047503 flags:1
...@@ -2874,15 +2874,15 @@ ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1 ...@@ -2874,15 +2874,15 @@ ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st: 0 ts:0.883340 flags:0 ret: 0 st: 0 ts:0.883340 flags:0
ret: 0 st: 1 dts:0.809796 pts:0.809796 pos:331776 size:209 flags:1 ret: 0 st: 1 dts:0.809796 pts:0.809796 pos:331776 size:209 flags:1
ret: 0 st: 0 ts:-0.222493 flags:1 ret: 0 st: 0 ts:-0.222493 flags:1
ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
ret: 0 st: 1 ts:2.671674 flags:0 ret: 0 st: 1 ts:2.671674 flags:0
ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1 ret: 0 st: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 flags:1
ret: 0 st: 1 ts:1.565841 flags:1 ret: 0 st: 1 ts:1.565841 flags:1
ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1 ret: 0 st: 1 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1
ret: 0 st:-1 ts:0.460008 flags:0 ret: 0 st:-1 ts:0.460008 flags:0
ret: 0 st: 1 dts:0.365714 pts:0.365714 pos:167936 size:209 flags:1 ret: 0 st: 0 dts:0.400000 pts:0.440000 pos:172032 size:12546 flags:0
ret: 0 st:-1 ts:-0.645825 flags:1 ret: 0 st:-1 ts:-0.645825 flags:1
ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:8192 size:24795 flags:1 ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:8192 size:24795 flags:1
---------------- ----------------
tests/data/b-libav.flv tests/data/b-libav.flv
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1
......
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