[FFmpeg-devel] [RFC] use ff_avc_find_startcode in ff_find_start_code

Reimar Döffinger Reimar.Doeffinger
Mon Feb 18 23:07:38 CET 2008


Hello,
First I wonder if that ff_find_start_code function is
not quite buggy anyway, or is it intentional that it searches for 
00 00 01 00 in the part involving the state but for 00 00 01 ?? in the
later code? If so, could somebody document the code?.
Anyway, this is a quite ugly patch that makes the function use
ff_avc_find_startcode (since that is in lavf, it can't be used as is of
course).
It probably also breaks the original use of ff_avc_find_startcode,
though I found the current behaviour a bit strange as well, and this
function is undocumented, too.
This causes at least a 6% speedup when decoding
http://samples.mplayerhq.hu/GXF/THX_Science_FLT_1920.gxf (I only tested
with MPlayer though).

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/avc.c
===================================================================
--- libavformat/avc.c	(revision 12135)
+++ libavformat/avc.c	(working copy)
@@ -37,15 +37,15 @@
         if( (x - 0x01010101) & (~x) & 0x80808080 ) { // generic
             if( p[1] == 0 ) {
                 if( p[0] == 0 && p[2] == 1 )
-                    return p-1;
+                    return p;
                 if( p[2] == 0 && p[3] == 1 )
-                    return p;
+                    return p+1;
             }
             if( p[3] == 0 ) {
                 if( p[2] == 0 && p[4] == 1 )
-                    return p+1;
+                    return p+2;
                 if( p[4] == 0 && p[5] == 1 )
-                    return p+2;
+                    return p+3;
             }
         }
     }
Index: libavcodec/mpegvideo.c
===================================================================
--- libavcodec/mpegvideo.c	(revision 12135)
+++ libavcodec/mpegvideo.c	(working copy)
@@ -97,6 +97,8 @@
     }
 }
 
+uint8_t *ff_avc_find_startcode(uint8_t *p, uint8_t *end);
+
 const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
     int i;
 
@@ -111,15 +113,8 @@
             return p;
     }
 
-    while(p<end){
-        if     (p[-1] > 1      ) p+= 3;
-        else if(p[-2]          ) p+= 2;
-        else if(p[-3]|(p[-1]-1)) p++;
-        else{
-            p++;
-            break;
-        }
-    }
+    p = ff_avc_find_startcode(p-3, end);
+    p = FFMIN(p + 4, end);
 
     p= FFMIN(p, end)-4;
     *state= AV_RB32(p);



More information about the ffmpeg-devel mailing list