]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/asf.c
oggflac: fix bitstream reader usage
[ffmpeg] / libavformat / asf.c
index e8b91446094f1f99178f0c4db2c8cce980b429a1..18eafdedbec5880fd33e0de0c1f1f36f0c50917e 100644 (file)
@@ -26,7 +26,7 @@
 #include "asf.h"
 #include "asfcrypt.h"
 
-extern void ff_mms_set_stream_selection(URLContext *h, AVFormatContext *format);
+void ff_mms_set_stream_selection(URLContext *h, AVFormatContext *format);
 
 #undef NDEBUG
 #include <assert.h>
@@ -567,7 +567,7 @@ static int asf_get_packet(AVFormatContext *s)
     int rsize = 8;
     int c, d, e, off;
 
-    off= (url_ftell(s->pb) - s->data_offset) % asf->packet_size + 3;
+    off= (url_ftell(pb) - s->data_offset) % asf->packet_size + 3;
 
     c=d=e=-1;
     while(off-- > 0){
@@ -705,12 +705,17 @@ static int asf_read_frame_header(AVFormatContext *s){
     return 0;
 }
 
-static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
+/**
+ * Parse data from individual ASF packets (which were previously loaded
+ * with asf_get_packet()).
+ * @returns 0 if data was stored in pkt, <0 on error or 1 if more ASF
+ *          packets need to be loaded (through asf_get_packet())
+ */
+static int asf_parse_packet(AVFormatContext *s, AVPacket *pkt)
 {
     ASFContext *asf = s->priv_data;
     ASFStream *asf_st = 0;
     ByteIOContext *pb = s->pb;
-    //static int pc = 0;
     for (;;) {
         if(url_feof(pb))
             return AVERROR(EIO);
@@ -723,16 +728,11 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
             /* fail safe */
             url_fskip(pb, ret);
 
-            asf->packet_pos= url_ftell(s->pb);
+            asf->packet_pos= url_ftell(pb);
             if (asf->data_object_size != (uint64_t)-1 &&
                 (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
                 return AVERROR(EIO); /* Do not exceed the size of the data object */
-            ret = asf_get_packet(s);
-            //printf("READ ASF PACKET  %d   r:%d   c:%d\n", ret, asf->packet_size_left, pc++);
-            if (ret < 0)
-                assert(asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1);
-            asf->packet_time_start = 0;
-            continue;
+            return 1;
         }
         if (asf->packet_time_start == 0) {
             if(asf_read_frame_header(s) < 0){
@@ -791,7 +791,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
             /* new packet */
             av_new_packet(&asf_st->pkt, asf->packet_obj_size);
             asf_st->seq = asf->packet_seq;
-            asf_st->pkt.pts = asf->packet_frag_timestamp;
+            asf_st->pkt.dts = asf->packet_frag_timestamp;
             asf_st->pkt.stream_index = asf->stream_index;
             asf_st->pkt.pos =
             asf_st->packet_pos= asf->packet_pos;
@@ -879,6 +879,24 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
+static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    ASFContext *asf = s->priv_data;
+
+    for (;;) {
+        int ret;
+
+        /* parse cached packets, if any */
+        if ((ret = asf_parse_packet(s, pkt)) <= 0)
+            return ret;
+        if ((ret = asf_get_packet(s)) < 0)
+            assert(asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1);
+        asf->packet_time_start = 0;
+    }
+
+    return 0;
+}
+
 // Added to support seeking after packets have been read
 // If information is not reset, read_packet fails due to
 // leftover information from previous reads