changeset 3442:a6f4d53b738d libavformat

pass dts and pts through ffm, should fix streaming b frames
author bcoudurier
date Mon, 09 Jun 2008 07:43:14 +0000
parents 2d52ccde8f86
children 90782b5e5ece
files ffm.h ffmdec.c ffmenc.c
diffstat 3 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ffm.h	Mon Jun 09 00:36:27 2008 +0000
+++ b/ffm.h	Mon Jun 09 07:43:14 2008 +0000
@@ -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 @@
     /* 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;
--- a/ffmdec.c	Mon Jun 09 00:36:27 2008 +0000
+++ b/ffmdec.c	Mon Jun 09 07:43:14 2008 +0000
@@ -100,7 +100,6 @@
             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 @@
 
     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 @@
         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 @@
             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;
     }
--- a/ffmenc.c	Mon Jun 09 00:36:27 2008 +0000
+++ b/ffmenc.c	Mon Jun 09 07:43:14 2008 +0000
@@ -197,6 +197,7 @@
     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 @@
         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;