diff options
-rw-r--r-- | libavformat/ffm.h | 6 | ||||
-rw-r--r-- | libavformat/ffmdec.c | 16 | ||||
-rw-r--r-- | libavformat/ffmenc.c | 9 | ||||
-rw-r--r-- | tests/libav.regression.ref | 4 | ||||
-rw-r--r-- | tests/seek.regression.ref | 14 |
5 files changed, 29 insertions, 20 deletions
diff --git a/libavformat/ffm.h b/libavformat/ffm.h index c758f9d817..97b7a5c716 100644 --- a/libavformat/ffm.h +++ b/libavformat/ffm.h @@ -29,8 +29,9 @@ #define PACKET_ID 0x666d /* 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_DTS 0x02 enum { READ_HEADER, @@ -41,11 +42,10 @@ typedef struct FFMContext { /* only reading mode */ offset_t write_index, file_size; int read_state; - uint8_t header[FRAME_HEADER_SIZE]; + uint8_t header[FRAME_HEADER_SIZE+4]; /* read and write */ 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 frame_offset; int64_t pts; diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c index dd9fa9789b..7f9cf9a853 100644 --- a/libavformat/ffmdec.c +++ b/libavformat/ffmdec.c @@ -100,7 +100,6 @@ static int ffm_read_data(AVFormatContext *s, get_be16(pb); /* PACKET_ID */ fill_size = get_be16(pb); ffm->pts = get_be64(pb); - ffm->first_frame_in_packet = 1; frame_offset = get_be16(pb); get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_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) switch(ffm->read_state) { 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); } 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) if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) != FRAME_HEADER_SIZE) 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 av_hexdump_log(s, AV_LOG_DEBUG, ffm->header, FRAME_HEADER_SIZE); #endif @@ -400,11 +402,11 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) av_free_packet(pkt); return AVERROR(EAGAIN); } - if (ffm->first_frame_in_packet) - { - pkt->pts = ffm->pts; - ffm->first_frame_in_packet = 0; - } + pkt->pts = AV_RB64(ffm->header+8); + if (ffm->header[1] & FLAG_DTS) + pkt->dts = pkt->pts - AV_RB32(ffm->header+16); + else + pkt->dts = pkt->pts; pkt->duration = duration; break; } diff --git a/libavformat/ffmenc.c b/libavformat/ffmenc.c index 738d3101da..70306b1f5a 100644 --- a/libavformat/ffmenc.c +++ b/libavformat/ffmenc.c @@ -197,6 +197,7 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt) AVStream *st = s->streams[pkt->stream_index]; int64_t pts; uint8_t header[FRAME_HEADER_SIZE]; + int header_size = FRAME_HEADER_SIZE; pts = s->timestamp + pkt->pts; /* packet size & key_frame */ @@ -206,7 +207,13 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt) header[1] |= FLAG_KEY_FRAME; AV_WB24(header+2, pkt->size); 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); return 0; diff --git a/tests/libav.regression.ref b/tests/libav.regression.ref index bac56bcccf..c68bc29ba6 100644 --- a/tests/libav.regression.ref +++ b/tests/libav.regression.ref @@ -15,9 +15,9 @@ bdb7484c68db722f66ba1630cf79844c *./tests/data/b-libav.mpg d6fdeb9f7083cc827f9510c6c4517dc0 *./tests/data/b-libav.swf 335771 ./tests/data/b-libav.swf ./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 -./tests/data/b-libav.ffm CRC=0xca8f6870 +./tests/data/b-libav.ffm CRC=0x2b71a386 f8ad5bd78f4d012a8ce9570aa395ac54 *./tests/data/b-libav.flv 335833 ./tests/data/b-libav.flv ./tests/data/b-libav.flv CRC=0xe14e8847 diff --git a/tests/seek.regression.ref b/tests/seek.regression.ref index 1bb0d4ec36..e1ac17dc5e 100644 --- a/tests/seek.regression.ref +++ b/tests/seek.regression.ref @@ -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 ---------------- 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 dts:0.940408 pts:0.940408 pos:380928 size:209 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 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: 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 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 dts:0.940408 pts:0.940408 pos:380928 size:209 flags:1 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: 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: 1 dts:0.888163 pts:0.888163 pos:356352 size:209 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 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: 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 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 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 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: 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 ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 |