]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/ffm.c
use duration from pkt
[ffmpeg] / libavformat / ffm.c
index baff5bcfad45555f1b653b436ac198c824d19414..6c79a9d7338173c48f1a8614e8454063a5dd3417 100644 (file)
@@ -247,28 +247,16 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt)
     FFMStream *fst = st->priv_data;
     int64_t pts;
     uint8_t header[FRAME_HEADER_SIZE];
-    int duration;
     int size= pkt->size;
 
-    //XXX/FIXME use duration from pkt
-    if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
-        duration = ((float)st->codec->frame_size / st->codec->sample_rate * 1000000.0);
-    } else {
-        duration = (1000000.0 * st->codec->time_base.num / (float)st->codec->time_base.den);
-    }
-
     pts = fst->pts;
     /* packet size & key_frame */
     header[0] = pkt->stream_index;
     header[1] = 0;
     if (pkt->flags & PKT_FLAG_KEY)
         header[1] |= FLAG_KEY_FRAME;
-    header[2] = (size >> 16) & 0xff;
-    header[3] = (size >> 8) & 0xff;
-    header[4] = size & 0xff;
-    header[5] = (duration >> 16) & 0xff;
-    header[6] = (duration >> 8) & 0xff;
-    header[7] = duration & 0xff;
+    AV_WB24(header+2, size);
+    AV_WB24(header+5, pkt->duration);
     ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
     ffm_write_data(s, pkt->data, size, pts, 0);
 
@@ -610,6 +598,12 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
 
         av_new_packet(pkt, size);
         pkt->stream_index = ffm->header[0];
+        if ((unsigned)pkt->stream_index >= s->nb_streams) {
+            av_log(s, AV_LOG_ERROR, "invalid stream index %d\n", pkt->stream_index);
+            av_free_packet(pkt);
+            ffm->read_state = READ_HEADER;
+            return AVERROR(EAGAIN);
+        }
         pkt->pos = url_ftell(s->pb);
         if (ffm->header[1] & FLAG_KEY_FRAME)
             pkt->flags |= PKT_FLAG_KEY;
@@ -665,7 +659,7 @@ static int64_t get_pts(AVFormatContext *s, offset_t pos)
 }
 
 /* seek to a given time in the file. The file read pointer is
-   positionned at or before pts. XXX: the following code is quite
+   positioned at or before pts. XXX: the following code is quite
    approximative */
 static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags)
 {