[Ffmpeg-cvslog] r7649 - trunk/libavformat/asf.c

michael subversion
Mon Jan 22 13:55:24 CET 2007


Author: michael
Date: Mon Jan 22 13:55:23 2007
New Revision: 7649

Modified:
   trunk/libavformat/asf.c

Log:
move frame header reading into its own function


Modified: trunk/libavformat/asf.c
==============================================================================
--- trunk/libavformat/asf.c	(original)
+++ trunk/libavformat/asf.c	Mon Jan 22 13:55:23 2007
@@ -530,6 +530,63 @@
     return 0;
 }
 
+/**
+ *
+ * @return <0 if error
+ */
+static int asf_read_frame_header(AVFormatContext *s){
+    ASFContext *asf = s->priv_data;
+    ByteIOContext *pb = &s->pb;
+    int rsize = 1;
+    int num = get_byte(pb);
+
+    asf->packet_segments--;
+    asf->packet_key_frame = num >> 7;
+    asf->stream_index = asf->asfid2avid[num & 0x7f];
+    // sequence should be ignored!
+    DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
+    DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
+    DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
+//printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
+    if (asf->packet_replic_size >= 8) {
+        asf->packet_obj_size = get_le32(pb);
+        if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
+            av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
+            return -1;
+        }
+        asf->packet_frag_timestamp = get_le32(pb); // timestamp
+        url_fskip(pb, asf->packet_replic_size - 8);
+        rsize += asf->packet_replic_size; // FIXME - check validity
+    } else if (asf->packet_replic_size==1){
+        // multipacket - frag_offset is begining timestamp
+        asf->packet_time_start = asf->packet_frag_offset;
+        asf->packet_frag_offset = 0;
+        asf->packet_frag_timestamp = asf->packet_timestamp;
+
+        asf->packet_time_delta = get_byte(pb);
+        rsize++;
+    }else if(asf->packet_replic_size!=0){
+        av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
+        return -1;
+    }
+    if (asf->packet_flags & 0x01) {
+        DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
+        //printf("Fragsize %d\n", asf->packet_frag_size);
+    } else {
+        asf->packet_frag_size = asf->packet_size_left - rsize;
+        //printf("Using rest  %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
+    }
+    if (asf->packet_replic_size == 1) {
+        asf->packet_multi_size = asf->packet_frag_size;
+        if (asf->packet_multi_size > asf->packet_size_left)
+            return -1;
+    }
+    asf->packet_size_left -= rsize;
+    //printf("___objsize____  %d   %d    rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
+
+    return 0;
+}
+
 static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     ASFContext *asf = s->priv_data;
@@ -537,7 +594,6 @@
     ByteIOContext *pb = &s->pb;
     //static int pc = 0;
     for (;;) {
-        int rsize = 0;
         if (asf->packet_size_left < FRAME_HEADER_SIZE
             || asf->packet_segments < 1) {
             //asf->packet_size_left <= asf->packet_padsize) {
@@ -565,56 +621,10 @@
             continue;
         }
         if (asf->packet_time_start == 0) {
-            /* read frame header */
-            int num = get_byte(pb);
-            asf->packet_segments--;
-            rsize++;
-            asf->packet_key_frame = num >> 7;
-            asf->stream_index = asf->asfid2avid[num & 0x7f];
-            // sequence should be ignored!
-            DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
-            DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
-            DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
-//printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
-            if (asf->packet_replic_size >= 8) {
-                asf->packet_obj_size = get_le32(pb);
-                if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
-                    av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
-                    continue;
-                }
-                asf->packet_frag_timestamp = get_le32(pb); // timestamp
-                url_fskip(pb, asf->packet_replic_size - 8);
-                rsize += asf->packet_replic_size; // FIXME - check validity
-            } else if (asf->packet_replic_size==1){
-                // multipacket - frag_offset is begining timestamp
-                asf->packet_time_start = asf->packet_frag_offset;
-                asf->packet_frag_offset = 0;
-                asf->packet_frag_timestamp = asf->packet_timestamp;
-
-                asf->packet_time_delta = get_byte(pb);
-                rsize++;
-            }else if(asf->packet_replic_size!=0){
-                av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
+            if(asf_read_frame_header(s) < 0){
+                asf->packet_segments= 0;
                 continue;
             }
-            if (asf->packet_flags & 0x01) {
-                DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
-#undef DO_2BITS
-                //printf("Fragsize %d\n", asf->packet_frag_size);
-            } else {
-                asf->packet_frag_size = asf->packet_size_left - rsize;
-                //printf("Using rest  %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
-            }
-            if (asf->packet_replic_size == 1) {
-                asf->packet_multi_size = asf->packet_frag_size;
-                if (asf->packet_multi_size > asf->packet_size_left) {
-                    asf->packet_segments = 0;
-                    continue;
-                }
-            }
-            asf->packet_size_left -= rsize;
-            //printf("___objsize____  %d   %d    rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
-
             if (asf->stream_index < 0
                 || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
                 || (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
@@ -624,7 +634,7 @@
                 url_fskip(pb, asf->packet_frag_size);
                 asf->packet_size_left -= asf->packet_frag_size;
                 if(asf->stream_index < 0)
-                    av_log(s, AV_LOG_ERROR, "ff asf skip %d  %d\n", asf->packet_frag_size, num & 0x7f);
+                    av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
                 continue;
             }
             asf->asf_st = s->streams[asf->stream_index]->priv_data;




More information about the ffmpeg-cvslog mailing list