[FFmpeg-devel] [PATCH 11/12] asfdec: properly handle multiple index objects

Anton Khirnov anton
Wed Feb 9 21:56:01 CET 2011


Current code assumes there's always only one and that it's always the
right one for the stream we're seeking in.
---
 libavformat/asfdec.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index a3ac3af..648dbd5 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -1145,12 +1145,13 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos,
     return pts;
 }
 
-static void asf_build_simple_index(AVFormatContext *s, int stream_index)
+static void asf_build_simple_index(AVFormatContext *s)
 {
     ff_asf_guid g;
     ASFContext *asf = s->priv_data;
     int64_t current_pos= url_ftell(s->pb);
-    int i;
+    int i, stream_index = 0;
+    AVStream *st;
 
     url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
     ff_get_guid(s->pb, &g);
@@ -1167,7 +1168,7 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
         ff_get_guid(s->pb, &g);
     }
 
-    {
+    while (!ff_guidcmp(&g, &ff_asf_guid_simple_index)) {
         int64_t itime, last_pos=-1;
         int pct, ict;
         int64_t av_unused gsize= get_le64(s->pb);
@@ -1177,6 +1178,19 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
         ict=get_le32(s->pb);
         av_log(s, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict);
 
+        /* find next video stream */
+        for (i = stream_index; i < s->nb_streams; i++) {
+            st = s->streams[i];
+            if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+                stream_index = i;
+                break;
+            }
+        }
+        if (i == s->nb_streams) {
+            av_log(s, AV_LOG_ERROR, "Found an index not corresponding to any stream.\n");
+            return;
+        }
+
         for (i=0;i<ict;i++){
             int pktnum=get_le32(s->pb);
             int pktct =get_le16(s->pb);
@@ -1185,11 +1199,12 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
 
             if(pos != last_pos){
             av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
-            av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME);
+            av_add_index_entry(st, pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME);
             last_pos=pos;
             }
         }
         asf->index_read= 1;
+        ff_get_guid(s->pb, &g);
     }
     url_fseek(s->pb, current_pos, SEEK_SET);
 }
@@ -1214,7 +1229,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int
     }
 
     if (!asf->index_read)
-        asf_build_simple_index(s, stream_index);
+        asf_build_simple_index(s);
 
     if(!(asf->index_read && st->index_entries)){
         if(av_seek_frame_binary(s, stream_index, pts, flags)<0)
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list