[SCM] libav/experimental: find_start_code() optimization (about 2x faster now) this may improve decoding speed with multiple threads

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 15:39:29 UTC 2013


The following commit has been merged in the experimental branch:
commit c7516a000c4c6469543326779da87995d8d15dd3
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Tue Mar 9 15:23:14 2004 +0000

    find_start_code() optimization (about 2x faster now) this may improve decoding speed with multiple threads
    
    Originally committed as revision 2862 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 1bf66e7..28a6791 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1770,24 +1770,27 @@ static int mpeg_decode_init(AVCodecContext *avctx)
    state. Return -1 if no start code found */
 static int find_start_code(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
 {
-    const uint8_t *buf_ptr;
-    unsigned int state=0xFFFFFFFF, v;
-    int val;
+    const uint8_t *buf_ptr= *pbuf_ptr;
+
+    buf_ptr++; //gurantees that -1 is within the array
+    buf_end -= 2; // gurantees that +2 is within the array
 
-    buf_ptr = *pbuf_ptr;
     while (buf_ptr < buf_end) {
-        v = *buf_ptr++;
-        if (state == 0x000001) {
-            state = ((state << 8) | v) & 0xffffff;
-            val = state;
-            goto found;
+        if(*buf_ptr==0){
+            while(buf_ptr < buf_end && buf_ptr[1]==0)
+                buf_ptr++;
+
+            if(buf_ptr[-1] == 0 && buf_ptr[1] == 1){
+                *pbuf_ptr = buf_ptr+3;
+                return buf_ptr[2] + 0x100;
+            }
         }
-        state = ((state << 8) | v) & 0xffffff;
+        buf_ptr += 2;
     }
-    val = -1;
- found:
-    *pbuf_ptr = buf_ptr;
-    return val;
+    buf_end += 2; //undo the hack above
+    
+    *pbuf_ptr = buf_end;
+    return -1;
 }
 
 static int mpeg1_decode_picture(AVCodecContext *avctx, 

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list