changeset 1482:b372ecde32a8 libavcodec

h263 stuffing decode fix
author michaelni
date Fri, 26 Sep 2003 22:18:25 +0000
parents 0cfed95c7707
children 8e7d8112de29
files h263.c h263data.h
diffstat 2 files changed, 44 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/h263.c	Thu Sep 25 12:19:26 2003 +0000
+++ b/h263.c	Fri Sep 26 22:18:25 2003 +0000
@@ -40,7 +40,7 @@
 //#include <assert.h>
 
 #define INTRA_MCBPC_VLC_BITS 6
-#define INTER_MCBPC_VLC_BITS 6
+#define INTER_MCBPC_VLC_BITS 7
 #define CBPY_VLC_BITS 6
 #define MV_VLC_BITS 9
 #define DC_VLC_BITS 9
@@ -2428,10 +2428,10 @@
     if (!done) {
         done = 1;
 
-        init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 8, 
+        init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, 
                  intra_MCBPC_bits, 1, 1,
                  intra_MCBPC_code, 1, 1);
-        init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 25, 
+        init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, 
                  inter_MCBPC_bits, 1, 1,
                  inter_MCBPC_code, 1, 1);
         init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
@@ -2871,12 +2871,14 @@
                     return mb_num-1;
                 }
 
-                cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
-                if (cbpc < 0){
-
-                    fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
-                    return -1;
-                }
+                do{
+                    cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+                    if (cbpc < 0){
+                        fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
+                        return -1;
+                    }
+                }while(cbpc == 8);
+
                 s->cbp_table[xy]= cbpc & 3;
                 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
                 s->mb_intra = 1;
@@ -2903,6 +2905,7 @@
                 int16_t * const mot_val= s->motion_val[s->block_index[0]];
                 const int stride= s->block_wrap[0]*2;
 
+              do{
                 bits= show_bits(&s->gb, 17);
                 if(bits==MOTION_MARKER){
                     return mb_num-1;
@@ -2927,15 +2930,14 @@
                         ff_clean_intra_table_entries(s);
                     continue;
                 }
+
                 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
                 if (cbpc < 0){
                     fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
                     return -1;
                 }
-                if (cbpc > 20)
-                    cbpc+=3;
-                else if (cbpc == 20)
-                    fprintf(stderr, "Stuffing !");
+              }while(cbpc == 20);
+
                 s->cbp_table[xy]= cbpc&(8+3); //8 is dquant
     
                 s->mb_intra = ((cbpc & 4) != 0);
@@ -3234,6 +3236,7 @@
     const int xy= s->mb_x + s->mb_y * s->mb_stride;
 
     if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) {
+      do{
         if (get_bits1(&s->gb)) {
             /* skip mb */
             s->mb_intra = 0;
@@ -3259,12 +3262,11 @@
         }
         cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
         //fprintf(stderr, "\tCBPC: %d", cbpc);
-        if (cbpc < 0)
+        if (cbpc < 0){
+            fprintf(stderr, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
             return -1;
-        if (cbpc > 20)
-            cbpc+=3;
-        else if (cbpc == 20)
-            fprintf(stderr, "Stuffing !");
+        }
+      }while(cbpc == 20);
         
         dquant = cbpc & 8;
         s->mb_intra = ((cbpc & 4) != 0);
@@ -3501,9 +3503,14 @@
         }
         s->current_picture.mb_type[xy]= mb_type;
     } else { /* I-Frame */
-        cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
-        if (cbpc < 0)
-            return -1;
+        do{
+            cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+            if (cbpc < 0){
+                fprintf(stderr, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
+                return -1;
+            }
+        }while(cbpc == 8);
+
         dquant = cbpc & 4;
         s->mb_intra = 1;
 intra:
@@ -3520,7 +3527,10 @@
             s->ac_pred = 0;
         
         cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
-        if(cbpy<0) return -1;
+        if(cbpy<0){
+            fprintf(stderr, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
+            return -1;
+        }
         cbp = (cbpc & 3) | (cbpy << 2);
         if (dquant) {
             change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
--- a/h263data.h	Thu Sep 25 12:19:26 2003 +0000
+++ b/h263data.h	Fri Sep 26 22:18:25 2003 +0000
@@ -5,46 +5,30 @@
 
 
 /* intra MCBPC, mb_type = (intra), then (intraq) */
-const uint8_t intra_MCBPC_code[8] = { 1, 1, 2, 3, 1, 1, 2, 3 };
-const uint8_t intra_MCBPC_bits[8] = { 1, 3, 3, 3, 4, 6, 6, 6 };
+const uint8_t intra_MCBPC_code[9] = { 1, 1, 2, 3, 1, 1, 2, 3, 1 };
+const uint8_t intra_MCBPC_bits[9] = { 1, 3, 3, 3, 4, 6, 6, 6, 9 };
 
 /* inter MCBPC, mb_type = (inter), (intra), (interq), (intraq), (inter4v) */
 /* Changed the tables for interq and inter4v+q, following the standard ** Juanjo ** */
-const uint8_t inter_MCBPC_code[25] = { 
+const uint8_t inter_MCBPC_code[28] = { 
     1, 3, 2, 5, 
     3, 4, 3, 3, 
     3, 7, 6, 5,
     4, 4, 3, 2,
     2, 5, 4, 5,
-    1, /* Stuffing */
+    1, 0, 0, 0, /* Stuffing */
     2, 12, 14, 15,
 };
-const uint8_t inter_MCBPC_bits[25] = { 
-    1, 4, 4, 6, 
-    5, 8, 8, 7,
-    3, 7, 7, 9,
-    6, 9, 9, 9,
-    3, 7, 7, 8,
-    9, /* Stuffing */
-    11, 13, 13, 13,
+const uint8_t inter_MCBPC_bits[28] = { 
+    1, 4, 4, 6, /* inter  */
+    5, 8, 8, 7, /* intra  */
+    3, 7, 7, 9, /* interQ */
+    6, 9, 9, 9, /* intraQ */
+    3, 7, 7, 8, /* inter4 */
+    9, 0, 0, 0, /* Stuffing */
+    11, 13, 13, 13,/* inter4Q*/
 };
 
-/* This is the old table 
-static const uint8_t inter_MCBPC_code[20] = { 
-    1, 3, 2, 5, 
-    3, 4, 3, 3, 
-    0, 1, 2, 3,
-    4, 4, 3, 2,
-    2, 5, 4, 5,
-};
-static const uint8_t inter_MCBPC_bits[20] = { 
-    1, 4, 4, 6, 
-    5, 8, 8, 7,
-    12, 12, 12, 12,
-    6, 9, 9, 9,
-    3, 7, 7, 8,
-};*/
-
 const uint8_t cbpy_tab[16][2] =
 {
   {3,4}, {5,5}, {4,5}, {9,4}, {3,5}, {7,4}, {2,6}, {11,4},