]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/asfdec.c
Merge commit '2f02bbcca050936686482453078e83dc25493da0'
[ffmpeg] / libavformat / asfdec.c
index 1f8b25c9102a154126d08b316321d115dc22deb9..52773ae57eb5f0cb74a134d8a811a6486c0cab3f 100644 (file)
@@ -1159,6 +1159,16 @@ static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
         asf_st = asf->asf_st;
         av_assert0(asf_st);
 
+        if (!asf_st->frag_offset && asf->packet_frag_offset) {
+            av_dlog(s, "skipping asf data pkt with fragment offset for "
+                    "stream:%d, expected:%d but got %d from pkt)\n",
+                    asf->stream_index, asf_st->frag_offset,
+                    asf->packet_frag_offset);
+            avio_skip(pb, asf->packet_frag_size);
+            asf->packet_size_left -= asf->packet_frag_size;
+            continue;
+        }
+
         if (asf->packet_replic_size == 1) {
             // frag_offset is here used as the beginning timestamp
             asf->packet_frag_timestamp = asf->packet_time_start;
@@ -1456,30 +1466,30 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index,
     return pts;
 }
 
-static void asf_build_simple_index(AVFormatContext *s, int stream_index)
+static int asf_build_simple_index(AVFormatContext *s, int stream_index)
 {
     ff_asf_guid g;
     ASFContext *asf     = s->priv_data;
     int64_t current_pos = avio_tell(s->pb);
+    int ret = 0;
 
-    if(avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET) < 0) {
-        asf->index_read= -1;
-        return;
+    if((ret = avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET)) < 0) {
+        return ret;
     }
 
-    ff_get_guid(s->pb, &g);
+    if ((ret = ff_get_guid(s->pb, &g)) < 0)
+        goto end;
 
     /* the data object can be followed by other top-level objects,
      * skip them until the simple index object is reached */
     while (ff_guidcmp(&g, &ff_asf_simple_index_header)) {
         int64_t gsize = avio_rl64(s->pb);
         if (gsize < 24 || url_feof(s->pb)) {
-            avio_seek(s->pb, current_pos, SEEK_SET);
-            asf->index_read= -1;
-            return;
+            goto end;
         }
         avio_skip(s->pb, gsize - 24);
-        ff_get_guid(s->pb, &g);
+        if ((ret = ff_get_guid(s->pb, &g)) < 0)
+            goto end;
     }
 
     {
@@ -1487,7 +1497,8 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
         int pct, ict;
         int i;
         int64_t av_unused gsize = avio_rl64(s->pb);
-        ff_get_guid(s->pb, &g);
+        if ((ret = ff_get_guid(s->pb, &g)) < 0)
+            goto end;
         itime = avio_rl64(s->pb);
         pct   = avio_rl32(s->pb);
         ict   = avio_rl32(s->pb);
@@ -1510,7 +1521,12 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
         }
         asf->index_read = ict > 1;
     }
+end:
+//     if (url_feof(s->pb)) {
+//         ret = 0;
+//     }
     avio_seek(s->pb, current_pos, SEEK_SET);
+    return ret;
 }
 
 static int asf_read_seek(AVFormatContext *s, int stream_index,
@@ -1518,6 +1534,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
 {
     ASFContext *asf = s->priv_data;
     AVStream *st    = s->streams[stream_index];
+    int ret = 0;
 
     if (s->packet_size <= 0)
         return -1;
@@ -1531,10 +1548,20 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
             return ret;
     }
 
-    if (!asf->index_read)
-        asf_build_simple_index(s, stream_index);
+    /* explicitly handle the case of seeking to 0 */
+    if (!pts) {
+        asf_reset_header(s);
+        avio_seek(s->pb, s->data_offset, SEEK_SET);
+        return 0;
+    }
+
+    if (!asf->index_read) {
+        ret = asf_build_simple_index(s, stream_index);
+        if (ret < 0)
+            asf->index_read = -1;
+    }
 
-    if ((asf->index_read > 0 && st->index_entries)) {
+    if (asf->index_read > 0 && st->index_entries) {
         int index = av_index_search_timestamp(st, pts, flags);
         if (index >= 0) {
             /* find the position */