changeset 1164:0e3c0c4a7b3d libavcodec

msmpeg4 2pass support & some related cleanup
author michaelni
date Wed, 02 Apr 2003 09:57:34 +0000
parents 0951691c4225
children f0c39139426d
files h263.c mpeg12.c mpegvideo.h msmpeg4.c
diffstat 4 files changed, 37 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/h263.c	Tue Apr 01 15:38:01 2003 +0000
+++ b/h263.c	Wed Apr 02 09:57:34 2003 +0000
@@ -544,9 +544,7 @@
             }
 
             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 @@
             }
 
             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 @@
             }
 
             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 @@
                 }
                     
                 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 @@
                 }
     
                 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 @@
             }
 
             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 @@
             }
 
             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 @@
         }
 
         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 @@
         }
 
         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++;
 
--- a/mpeg12.c	Tue Apr 01 15:38:01 2003 +0000
+++ b/mpeg12.c	Wed Apr 02 09:57:34 2003 +0000
@@ -80,16 +80,6 @@
 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;
--- a/mpegvideo.h	Tue Apr 01 15:38:01 2003 +0000
+++ b/mpegvideo.h	Wed Apr 02 09:57:34 2003 +0000
@@ -662,6 +662,14 @@
     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,
--- a/msmpeg4.c	Tue Apr 01 15:38:01 2003 +0000
+++ b/msmpeg4.c	Wed Apr 02 09:57:34 2003 +0000
@@ -549,6 +549,9 @@
 	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 @@
             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 @@
                      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 @@
                 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);
     }
 }