changeset 154:f914f710b8d0 libavcodec

- Fixed a bug on H.263 MV prediction for MB on GOBs limits. - Now we can decode H.263v1 streams found on QT without problems.
author pulento
date Mon, 12 Nov 2001 05:19:55 +0000
parents acbd3bc999b3
children 3c3449bce692
files h263.c h263dec.c mpegvideo.h
diffstat 3 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/h263.c	Sun Nov 11 17:55:54 2001 +0000
+++ b/h263.c	Mon Nov 12 05:19:55 2001 +0000
@@ -252,7 +252,7 @@
     mot_val = s->motion_val[(x) + (y) * wrap];
 
     /* special case for first line */
-    if (y == 1 || s->first_slice_line) {
+    if (y == 1 || s->first_slice_line || s->first_gob_line) {
         A = s->motion_val[(x-1) + (y) * wrap];
         *px = A[0];
         *py = A[1];
@@ -779,32 +779,32 @@
     unsigned int val;
     INT16 *mot_val;
     static INT8 quant_tab[4] = { -1, -2, 1, 2 };
-        
+    unsigned int gfid;        
+    
     /* Check for GOB Start Code */
     val = show_bits(&s->gb, 16);
     
     if (val == 0) {
         /* We have a GBSC probably with GSTUFF */
-#ifdef DEBUG
-        unsigned int gn, gfid;
-#endif
         //skip_bits(&s->gb, 16); /* Drop the zeros */
         while (get_bits1(&s->gb) == 0); /* Seek the '1' bit */
 #ifdef DEBUG
         fprintf(stderr,"\nGOB Start Code at MB %d\n", 
             (s->mb_y * s->mb_width) + s->mb_x);
-        gn = get_bits(&s->gb, 5); /* GN */
+#endif
+        s->gob_number = get_bits(&s->gb, 5); /* GN */
         gfid = get_bits(&s->gb, 2); /* GFID */
-#else
-        skip_bits(&s->gb, 5); /* GN */
-        skip_bits(&s->gb, 2); /* GFID */
-#endif        
         s->qscale = get_bits(&s->gb, 5); /* GQUANT */
 #ifdef DEBUG
         fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", gn, gfid, s->qscale);
 #endif
     }
-    
+
+    if (s->mb_y == s->gob_number)
+        s->first_gob_line = 1;
+    else
+        s->first_gob_line = 0;
+            
     if (s->pict_type == P_TYPE) {
         if (get_bits1(&s->gb)) {
             /* skip mb */
@@ -863,6 +863,9 @@
                 return -1;
             s->mv[0][0][0] = mx;
             s->mv[0][0][1] = my;
+            /*fprintf(stderr, "\n MB %d", (s->mb_y * s->mb_width) + s->mb_x);
+            fprintf(stderr, "\n\tmvx: %d\t\tpredx: %d", mx, pred_x);
+            fprintf(stderr, "\n\tmvy: %d\t\tpredy: %d", my, pred_y);*/
             if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)
                skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
                            
@@ -957,6 +960,7 @@
             val += 64;
         if (pred > 32 && val > 63)
             val -= 64;
+        
     }
     return val;
 }
@@ -1211,6 +1215,10 @@
     skip_bits1(&s->gb);	/* camera  off */
     skip_bits1(&s->gb);	/* freeze picture release off */
 
+    /* Reset GOB data */
+    s->gob_number = 0;
+    s->first_gob_line = 0;
+    
     format = get_bits(&s->gb, 3);
 
     if (format != 7) {
--- a/h263dec.c	Sun Nov 11 17:55:54 2001 +0000
+++ b/h263dec.c	Mon Nov 12 05:19:55 2001 +0000
@@ -39,6 +39,8 @@
     /* select sub codec */
     switch(avctx->codec->id) {
     case CODEC_ID_H263:
+        s->gob_number = 0;
+        s->first_gob_line = 0;
         break;
     case CODEC_ID_MPEG4:
         s->time_increment_bits = 4; /* default value for broken headers */
--- a/mpegvideo.h	Sun Nov 11 17:55:54 2001 +0000
+++ b/mpegvideo.h	Mon Nov 12 05:19:55 2001 +0000
@@ -129,6 +129,10 @@
     INT64 wanted_bits;
     INT64 total_bits;
     
+    /* H.263 specific */
+    int gob_number;
+    int first_gob_line;
+    
     /* H.263+ specific */
     int umvplus;
     int umvplus_dec;