changeset 750:4adadf210b3b libavcodec

better padding bug detection
author michaelni
date Mon, 14 Oct 2002 19:53:04 +0000
parents 07e58dc635a5
children cbe316f082bc
files h263dec.c mpegvideo.h
diffstat 2 files changed, 37 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/h263dec.c	Mon Oct 14 18:25:58 2002 +0000
+++ b/h263dec.c	Mon Oct 14 19:53:04 2002 +0000
@@ -208,7 +208,9 @@
                     s->error_status_table[xy]|= AC_END;
                     if(!s->partitioned_frame)
                         s->error_status_table[xy]|= MV_END|DC_END;
-                    
+
+                    s->padding_bug_score--;
+                        
                     if(++s->mb_x >= s->mb_width){
                         s->mb_x=0;
                         ff_draw_horiz_band(s);
@@ -237,6 +239,35 @@
     
     assert(s->mb_x==0 && s->mb_y==s->mb_height);
 
+    /* try to detect the padding bug */
+    if(      s->codec_id==CODEC_ID_MPEG4
+       &&   (s->workaround_bugs&FF_BUG_AUTODETECT) 
+       &&    s->gb.size*8 - get_bits_count(&s->gb) >=0
+       &&    s->gb.size*8 - get_bits_count(&s->gb) < 48
+       &&   !s->resync_marker
+       &&   !s->data_partitioning){
+        
+        const int bits_count= get_bits_count(&s->gb);
+        const int bits_left = s->gb.size*8 - bits_count;
+        
+        if(bits_left==0 || bits_left>8){
+            s->padding_bug_score++;
+        } else {
+            int v= show_bits(&s->gb, 8);
+            v|= 0x7F >> (7-(bits_count&7));
+                
+            if(v==0x7F)
+                s->padding_bug_score--;
+            else
+                s->padding_bug_score++;            
+        }
+        
+        if(s->padding_bug_score > -2)
+            s->workaround_bugs |=  FF_BUG_NO_PADDING;
+        else
+            s->workaround_bugs &= ~FF_BUG_NO_PADDING;
+    }
+
     // handle formats which dont have unique end markers
     if(s->msmpeg4_version || (s->workaround_bugs&FF_BUG_NO_PADDING)){ //FIXME perhaps solve this more cleanly
         int left= s->gb.size*8 - get_bits_count(&s->gb);
@@ -262,7 +293,7 @@
         
         return 0;
     }
-        
+
     fprintf(stderr, "slice end not reached but screenspace end (%d left %06X)\n", 
             s->gb.size*8 - get_bits_count(&s->gb),
             show_bits(&s->gb, 24));
@@ -341,7 +372,8 @@
             s->workaround_bugs|= FF_BUG_UMP4;
             s->workaround_bugs|= FF_BUG_AC_VLC;
         }
-        
+//printf("padding_bug_score: %d\n", s->padding_bug_score);
+#if 0
         if(s->divx_version==500)
             s->workaround_bugs|= FF_BUG_NO_PADDING;
 
@@ -354,6 +386,7 @@
         
         if(s->lavc_build && s->lavc_build<4609) //FIXME not sure about the version num but a 4609 file seems ok
             s->workaround_bugs|= FF_BUG_NO_PADDING;
+#endif
     }
     
 
--- a/mpegvideo.h	Mon Oct 14 18:25:58 2002 +0000
+++ b/mpegvideo.h	Mon Oct 14 19:53:04 2002 +0000
@@ -404,6 +404,7 @@
     INT16 (*field_mv_table)[2][2];   /* used for interlaced b frame decoding */
     INT8 (*field_select_table)[2];   /* wtf, no really another table for interlaced b frames */
     int t_frame;                     /* time distance of first I -> B, used for interlaced b frames */
+    int padding_bug_score;           /* used to detect the VERY common padding bug in MPEG4 */
 
     /* divx specific, used to workaround (many) bugs in divx5 */
     int divx_version;