[Ffmpeg-cvslog] CVS: ffmpeg/libavcodec mpegvideo.c, 1.506, 1.507 mpegvideo.h, 1.235, 1.236 parser.c, 1.35, 1.36 mpeg12.c, 1.247, 1.248

Michael Niedermayer CVS michael
Sat Feb 4 21:32:05 CET 2006


Update of /cvsroot/ffmpeg/ffmpeg/libavcodec
In directory mail:/var2/tmp/cvs-serv981

Modified Files:
	mpegvideo.c mpegvideo.h parser.c mpeg12.c 
Log Message:
faster find_startcode()


Index: mpegvideo.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/mpegvideo.c,v
retrieving revision 1.506
retrieving revision 1.507
diff -u -d -r1.506 -r1.507
--- mpegvideo.c	28 Jan 2006 00:57:59 -0000	1.506
+++ mpegvideo.c	4 Feb 2006 20:32:02 -0000	1.507
@@ -228,6 +228,34 @@
 }
 #endif //CONFIG_ENCODERS
 
+const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
+    int i;
+
+    for(i=0; i<3; i++){
+        uint32_t tmp= *state << 8;
+        *state= tmp + *(p++);
+        if(tmp == 0x100 || p==end)
+            return p;
+    }
+    p--;   // need to recheck or might miss one
+    end--; // we need the byte after 00 00 01 too
+
+    while(p<end){
+        if     (p[ 0] > 1) p+= 3;
+        else if(p[-1]    ) p+= 2;
+        else if(p[-2]|(p[0]-1)) p++;
+        else{
+            p++;
+            break;
+        }
+    }
+
+    p= FFMIN(p, end)-3;
+    *state=  be2me_32(unaligned32(p));
+
+    return p+4;
+}
+
 /* init common dct for both encoder and decoder */
 int DCT_common_init(MpegEncContext *s)
 {

Index: mpegvideo.h
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/mpegvideo.h,v
retrieving revision 1.235
retrieving revision 1.236
diff -u -d -r1.235 -r1.236
--- mpegvideo.h	27 Jan 2006 13:19:13 -0000	1.235
+++ mpegvideo.h	4 Feb 2006 20:32:02 -0000	1.236
@@ -773,6 +773,7 @@
 int ff_find_unused_picture(MpegEncContext *s, int shared);
 void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
 void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
+const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state);
 
 void ff_er_frame_start(MpegEncContext *s);
 void ff_er_frame_end(MpegEncContext *s);

Index: parser.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/parser.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- parser.c	2 Feb 2006 18:38:47 -0000	1.35
+++ parser.c	4 Feb 2006 20:32:02 -0000	1.36
@@ -272,28 +272,6 @@
     return 0;
 }
 
-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;
-
-    buf_ptr = *pbuf_ptr;
-    while (buf_ptr < buf_end) {
-        v = *buf_ptr++;
-        if (state == 0x000001) {
-            state = ((state << 8) | v) & 0xffffff;
-            val = state;
-            goto found;
-        }
-        state = ((state << 8) | v) & 0xffffff;
-    }
-    val = -1;
- found:
-    *pbuf_ptr = buf_ptr;
-    return val;
-}
-
 /* XXX: merge with libavcodec ? */
 #define MPEG1_FRAME_RATE_BASE 1001
 
@@ -335,7 +313,8 @@
     s->repeat_pict = 0;
     buf_end = buf + buf_size;
     while (buf < buf_end) {
-        start_code = find_start_code(&buf, buf_end);
+        start_code= -1;
+        buf= ff_find_start_code(buf, buf_end, &start_code);
         bytes_left = buf_end - buf;
         switch(start_code) {
         case PICTURE_START_CODE:

Index: mpeg12.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/mpeg12.c,v
retrieving revision 1.247
retrieving revision 1.248
diff -u -d -r1.247 -r1.248
--- mpeg12.c	14 Jan 2006 17:43:22 -0000	1.247
+++ mpeg12.c	4 Feb 2006 20:32:02 -0000	1.248
@@ -2171,33 +2171,6 @@
     return 0;
 }
 
-/* return the 8 bit start code value and update the search
-   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= *pbuf_ptr;
-
-    buf_ptr++; //gurantees that -1 is within the array
-    buf_end -= 3; // gurantees that +3 is within the array
-
-    while (buf_ptr < buf_end) {
-        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;
-            }
-        }
-        buf_ptr += 2;
-    }
-    buf_end += 3; //undo the hack above
-
-    *pbuf_ptr = buf_end;
-    return -1;
-}
-
 static int mpeg1_decode_picture(AVCodecContext *avctx,
                                 const uint8_t *buf, int buf_size)
 {
@@ -2715,7 +2688,8 @@
         if(s->mb_y == s->end_mb_y)
             return 0;
 
-        start_code = find_start_code(&buf, s->gb.buffer_end);
+        start_code= -1;
+        buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code);
         mb_y= start_code - SLICE_MIN_START_CODE;
         if(mb_y < 0 || mb_y >= s->end_mb_y)
             return -1;
@@ -2995,14 +2969,12 @@
 int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
 {
     int i;
-    uint32_t state;
-
-    state= pc->state;
+    uint32_t state= pc->state;
 
     i=0;
     if(!pc->frame_start_found){
         for(i=0; i<buf_size; i++){
-            state= (state<<8) | buf[i];
+            i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
             if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
                 i++;
                 pc->frame_start_found=1;
@@ -3016,7 +2988,7 @@
         if (buf_size == 0)
             return 0;
         for(; i<buf_size; i++){
-            state= (state<<8) | buf[i];
+            i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
             if((state&0xFFFFFF00) == 0x100){
                 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
                     pc->frame_start_found=0;
@@ -3083,7 +3055,8 @@
 
     for(;;) {
         /* find start next code */
-        start_code = find_start_code(&buf_ptr, buf_end);
+        start_code = -1;
+        buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
         if (start_code < 0){
             if(s2->pict_type != B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){
                 if(avctx->thread_count > 1){





More information about the ffmpeg-cvslog mailing list