]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Separate the packet fetching from the data reading, so that the data reading
authorrbultje <rbultje@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sat, 13 Dec 2008 17:18:11 +0000 (17:18 +0000)
committerrbultje <rbultje@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sat, 13 Dec 2008 17:18:11 +0000 (17:18 +0000)
function is assured to parse at most one packet. This makes this function
useful for ASF data packet parsing in a "push-mode" in addition to the
current "pull-mode", and therefore allows for use of these functions in,
for example, the RTSP demuxer (for MS-RTSP support). Tested to give identical
output before and after for regular ASF playback, also see discussion in the
ML thread "[PATCH] asf.c: move packet_time_start=0 statement". Testsuite also
works after the patch, tested by Benoit Fouet.

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@16108 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavformat/asf.c

index 247cc2cc2a125cd8f84926a1b1377f8113634d9a..18eafdedbec5880fd33e0de0c1f1f36f0c50917e 100644 (file)
@@ -705,7 +705,13 @@ 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;
@@ -726,11 +732,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
             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);
-            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){
@@ -877,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