msmpeg4 2pass support & some related cleanup
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 2 Apr 2003 09:57:34 +0000 (09:57 +0000)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 2 Apr 2003 09:57:34 +0000 (09:57 +0000)
Originally committed as revision 1724 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/h263.c
libavcodec/mpeg12.c
libavcodec/mpegvideo.h
libavcodec/msmpeg4.c

index 2e7e19e..d6da47a 100644 (file)
@@ -544,9 +544,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
             }
 
             if(interleaved_stats){
-                bits= get_bit_count(&s->pb);
-                s->misc_bits+= bits - s->last_bits;
-                s->last_bits=bits;
+                s->misc_bits+= get_bits_diff(s);
             }
 
             switch(mb_type)
@@ -589,9 +587,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
             }
 
             if(interleaved_stats){
-                bits= get_bit_count(&s->pb);
-                s->mv_bits+= bits - s->last_bits;
-                s->last_bits=bits;
+                s->mv_bits+= get_bits_diff(s);
             }
 
             /* encode each block */
@@ -600,9 +596,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
             }
 
             if(interleaved_stats){
-                bits= get_bit_count(&s->pb);
-                s->p_tex_bits+= bits - s->last_bits;
-                s->last_bits=bits;
+                s->p_tex_bits+= get_bits_diff(s);
             }
         }else{ /* s->pict_type==B_TYPE */
             if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) {
@@ -673,9 +667,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
                 }
                     
                 if(interleaved_stats){
-                    bits= get_bit_count(&s->pb);
-                    s->misc_bits+= bits - s->last_bits;
-                    s->last_bits=bits;
+                    s->misc_bits+= get_bits_diff(s);
                 }
 
                 /* motion vectors: 16x16 mode */
@@ -698,9 +690,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
                 }
     
                 if(interleaved_stats){
-                    bits= get_bit_count(&s->pb);
-                    s->misc_bits+= bits - s->last_bits;
-                    s->last_bits=bits;
+                    s->misc_bits+= get_bits_diff(s);
                 }
 
                 for(i=0; i<4; i++){
@@ -713,9 +703,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
             }
 
             if(interleaved_stats){ 
-                bits= get_bit_count(&s->pb);
-                s->mv_bits+= bits - s->last_bits;
-                s->last_bits=bits;
+                s->mv_bits+= get_bits_diff(s);
             }
 
             /* encode each block */
@@ -724,9 +712,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
             }
 
             if(interleaved_stats){
-                bits= get_bit_count(&s->pb);
-                s->p_tex_bits+= bits - s->last_bits;
-                s->last_bits=bits;
+                s->p_tex_bits+= get_bits_diff(s);
             }
             s->f_count++;
         }
@@ -803,9 +789,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
         }
 
         if(interleaved_stats){
-            bits= get_bit_count(&s->pb);
-            s->misc_bits+= bits - s->last_bits;
-            s->last_bits=bits;
+            s->misc_bits+= get_bits_diff(s);
         }
 
         /* encode each block */
@@ -814,9 +798,7 @@ void mpeg4_encode_mb(MpegEncContext * s,
         }
 
         if(interleaved_stats){
-            bits= get_bit_count(&s->pb);
-            s->i_tex_bits+= bits - s->last_bits;
-            s->last_bits=bits;
+            s->i_tex_bits+= get_bits_diff(s);
         }
         s->i_count++;
 
index 95ce87e..019e293 100644 (file)
@@ -80,16 +80,6 @@ static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2];
 static uint8_t  uni_mpeg1_ac_vlc_len [64*64*2];
 #endif
 
-static inline int get_bits_diff(MpegEncContext *s){
-    int bits,ret;
-    
-    bits= get_bit_count(&s->pb);
-    ret= bits - s->last_bits;
-    s->last_bits=bits;
-    
-    return ret;
-}
-
 static void init_2d_vlc_rl(RLTable *rl)
 {
     int i;
index 050d991..dbbc1bb 100644 (file)
@@ -662,6 +662,14 @@ static inline void ff_update_block_index(MpegEncContext *s){
     s->block_index[5]++;
 }
 
+static inline int get_bits_diff(MpegEncContext *s){
+    const int bits= get_bit_count(&s->pb);
+    const int last= s->last_bits;
+
+    s->last_bits = bits;
+
+    return bits - last;
+}
 
 /* motion_est.c */
 void ff_estimate_p_frame_motion(MpegEncContext * s,
index 115e713..9560aaf 100644 (file)
@@ -549,6 +549,9 @@ void msmpeg4_encode_mb(MpegEncContext * s,
        if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
            /* skip macroblock */
            put_bits(&s->pb, 1, 1);
+            s->last_bits++;
+           s->misc_bits++;
+
            return;
        }
         if (s->use_skip_mb_code)
@@ -564,7 +567,9 @@ void msmpeg4_encode_mb(MpegEncContext * s,
             put_bits(&s->pb, 
                      cbpy_tab[coded_cbp>>2][1], 
                      cbpy_tab[coded_cbp>>2][0]);
-                        
+
+            s->misc_bits += get_bits_diff(s);
+
             h263_pred_motion(s, 0, &pred_x, &pred_y);
             msmpeg4v2_encode_motion(s, motion_x - pred_x);
             msmpeg4v2_encode_motion(s, motion_y - pred_y);
@@ -573,11 +578,20 @@ void msmpeg4_encode_mb(MpegEncContext * s,
                      table_mb_non_intra[cbp + 64][1], 
                      table_mb_non_intra[cbp + 64][0]);
 
+            s->misc_bits += get_bits_diff(s);
+
             /* motion vector */
             h263_pred_motion(s, 0, &pred_x, &pred_y);
             msmpeg4_encode_motion(s, motion_x - pred_x, 
                                   motion_y - pred_y);
         }
+
+        s->mv_bits += get_bits_diff(s);
+
+        for (i = 0; i < 6; i++) {
+            msmpeg4_encode_block(s, block[i], i);
+        }
+        s->p_tex_bits += get_bits_diff(s);
     } else {
        /* compute cbp */
        cbp = 0;
@@ -633,10 +647,12 @@ void msmpeg4_encode_mb(MpegEncContext * s,
                 put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
             }
         }
-    }
+        s->misc_bits += get_bits_diff(s);
 
-    for (i = 0; i < 6; i++) {
-        msmpeg4_encode_block(s, block[i], i);
+        for (i = 0; i < 6; i++) {
+            msmpeg4_encode_block(s, block[i], i);
+        }
+        s->i_tex_bits += get_bits_diff(s);
     }
 }