changeset 3438:40995a9455e3 libavformat

fix pts handling in ffm
author bcoudurier
date Sat, 07 Jun 2008 00:49:03 +0000
parents 82c4cc2aae2a
children 0dfc37ba9453
files ffm.h ffmdec.c ffmenc.c
diffstat 3 files changed, 9 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/ffm.h	Sat Jun 07 00:35:37 2008 +0000
+++ b/ffm.h	Sat Jun 07 00:49:03 2008 +0000
@@ -32,10 +32,6 @@
 #define FRAME_HEADER_SIZE    8
 #define FLAG_KEY_FRAME       0x01
 
-typedef struct FFMStream {
-    int64_t pts;
-} FFMStream;
-
 enum {
     READ_HEADER,
     READ_DATA,
@@ -55,6 +51,7 @@
     int64_t pts;
     uint8_t *packet_ptr, *packet_end;
     uint8_t packet[FFM_PACKET_SIZE];
+    int64_t start_time;
 } FFMContext;
 
 #endif /* FFMPEG_FFM_H */
--- a/ffmdec.c	Sat Jun 07 00:35:37 2008 +0000
+++ b/ffmdec.c	Sat Jun 07 00:49:03 2008 +0000
@@ -232,7 +232,6 @@
 {
     FFMContext *ffm = s->priv_data;
     AVStream *st;
-    FFMStream *fst;
     ByteIOContext *pb = s->pb;
     AVCodecContext *codec;
     int i, nb_streams;
@@ -263,15 +262,10 @@
         st = av_new_stream(s, 0);
         if (!st)
             goto fail;
-        fst = av_mallocz(sizeof(FFMStream));
-        if (!fst)
-            goto fail;
         s->streams[i] = st;
 
         av_set_pts_info(st, 64, 1, 1000000);
 
-        st->priv_data = fst;
-
         codec = st->codec;
         /* generic info */
         codec->codec_id = get_be32(pb);
--- a/ffmenc.c	Sat Jun 07 00:35:37 2008 +0000
+++ b/ffmenc.c	Sat Jun 07 00:49:03 2008 +0000
@@ -92,7 +92,6 @@
 {
     FFMContext *ffm = s->priv_data;
     AVStream *st;
-    FFMStream *fst;
     ByteIOContext *pb = s->pb;
     AVCodecContext *codec;
     int bit_rate, i;
@@ -116,11 +115,7 @@
     /* list of streams */
     for(i=0;i<s->nb_streams;i++) {
         st = s->streams[i];
-        fst = av_mallocz(sizeof(FFMStream));
-        if (!fst)
-            goto fail;
         av_set_pts_info(st, 64, 1, 1000000);
-        st->priv_data = fst;
 
         codec = st->codec;
         /* generic info */
@@ -176,13 +171,14 @@
         default:
             return -1;
         }
-        /* hack to have real time */
-        if (ffm_nopts)
-            fst->pts = 0;
-        else
-            fst->pts = av_gettime();
     }
 
+    /* hack to have real time */
+    if (ffm_nopts)
+        ffm->start_time = 0;
+    else
+        ffm->start_time = av_gettime();
+
     /* flush until end of block reached */
     while ((url_ftell(pb) % ffm->packet_size) != 0)
         put_byte(pb, 0);
@@ -198,22 +194,16 @@
     ffm->first_packet = 1;
 
     return 0;
- fail:
-    for(i=0;i<s->nb_streams;i++) {
-        st = s->streams[i];
-        av_freep(&st->priv_data);
-    }
-    return -1;
 }
 
 static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
+    FFMContext *ffm = s->priv_data;
     AVStream *st = s->streams[pkt->stream_index];
-    FFMStream *fst = st->priv_data;
     int64_t pts;
     uint8_t header[FRAME_HEADER_SIZE];
 
-    pts = fst->pts;
+    pts = ffm->start_time + pkt->pts;
     /* packet size & key_frame */
     header[0] = pkt->stream_index;
     header[1] = 0;
@@ -224,7 +214,6 @@
     ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
     ffm_write_data(s, pkt->data, pkt->size, pts, 0);
 
-    fst->pts += pkt->duration;
     return 0;
 }