ffm has no per stream priv_data anymore
[ffmpeg.git] / libavformat / ffmdec.c
index 9c0ea89..37a60a5 100644 (file)
@@ -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);
@@ -320,7 +319,13 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
         default:
             goto fail;
         }
-
+        if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) {
+            codec->extradata_size = get_be32(pb);
+            codec->extradata = av_malloc(codec->extradata_size);
+            if (!codec->extradata)
+                return AVERROR(ENOMEM);
+            get_buffer(pb, codec->extradata, codec->extradata_size);
+        }
     }
 
     /* get until end of block reached */
@@ -339,7 +344,6 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
     for(i=0;i<s->nb_streams;i++) {
         st = s->streams[i];
         if (st) {
-            av_freep(&st->priv_data);
             av_free(st);
         }
     }
@@ -355,14 +359,17 @@ 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",
-               url_ftell(s->pb), s->pb.pos, ffm->write_index, ffm->file_size);
+               url_ftell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size);
         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
@@ -394,11 +401,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;
     }
@@ -458,18 +465,6 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
     return 0;
 }
 
-static int ffm_read_close(AVFormatContext *s)
-{
-    AVStream *st;
-    int i;
-
-    for(i=0;i<s->nb_streams;i++) {
-        st = s->streams[i];
-        av_freep(&st->priv_data);
-    }
-    return 0;
-}
-
 static int ffm_probe(AVProbeData *p)
 {
     if (
@@ -486,6 +481,6 @@ AVInputFormat ffm_demuxer = {
     ffm_probe,
     ffm_read_header,
     ffm_read_packet,
-    ffm_read_close,
+    NULL,
     ffm_seek,
 };