]> git.videolan.org Git - x264.git/commitdiff
remove cabac byte-stuffing code, because it just wastes bits in lossless, and does...
authorLoren Merritt <pengvado@videolan.org>
Sun, 9 Oct 2005 03:32:56 +0000 (03:32 +0000)
committerLoren Merritt <pengvado@videolan.org>
Sun, 9 Oct 2005 03:32:56 +0000 (03:32 +0000)
git-svn-id: svn://svn.videolan.org/x264/trunk@321 df754926-b1dd-0310-bc7b-ec298dee348c

common/cabac.c
common/cabac.h
encoder/encoder.c

index bd4435939f9f7a475185e916e2800cc700dc5a96..99bce82f8482b50cb03ed6c8e9db8f09a4167540 100644 (file)
@@ -971,7 +971,6 @@ void x264_cabac_encode_init( x264_cabac_t *cb, bs_t *s )
     cb->i_range = 0x01FE;
     cb->b_first_bit= 1;
     cb->i_bits_outstanding = 0;
-    cb->i_sym_cnt = 0;
     cb->s = s;
 }
 
@@ -1056,8 +1055,6 @@ void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx, int b )
     cb->ctxstate[i_ctx].i_count++;
 
     x264_cabac_encode_renorm( cb );
-
-    cb->i_sym_cnt++;
 }
 
 void x264_cabac_encode_bypass( x264_cabac_t *cb, int b )
@@ -1089,7 +1086,6 @@ void x264_cabac_encode_bypass( x264_cabac_t *cb, int b )
             cb->i_bits_outstanding++;
         }
     }
-    cb->i_sym_cnt++;
 }
 
 void x264_cabac_encode_terminal( x264_cabac_t *cb, int b )
@@ -1105,8 +1101,6 @@ void x264_cabac_encode_terminal( x264_cabac_t *cb, int b )
         cb->i_range = 2;
     }
     x264_cabac_encode_renorm( cb );
-
-    cb->i_sym_cnt++;
 }
 
 void x264_cabac_encode_flush( x264_cabac_t *cb )
index db15ee09172a0d26d3ec386509f2fe71201c0587..251922d2e5ce19acb927d52a9f6e17df391565d5 100644 (file)
@@ -46,8 +46,6 @@ typedef struct
     int i_low;
     int i_range;
 
-    int i_sym_cnt;
-
     /* bit stream */
     int b_first_bit;
     int i_bits_outstanding;
index a34dfa8b61877df2c1c585c9bea77797bf758e01..dec9ad452dd69448ede89e709030fa8daaec1513 100644 (file)
@@ -1051,16 +1051,25 @@ static int x264_slice_write( x264_t *h )
 
     if( h->param.b_cabac )
     {
-        int i_cabac_word;
         x264_cabac_encode_flush( &h->cabac );
-        /* TODO cabac stuffing things (p209) */
-        i_cabac_word = (((3 * h->cabac.i_sym_cnt - 3 * 96 * h->sps->i_mb_width * h->sps->i_mb_height)/32) - bs_pos( &h->out.bs)/8)/3;
+
+#if 0
+        /* The standard doesn't explain why one should perform cabac byte stuffing,
+         * and I see no possible reason. Decoding works fine without it;
+         * JM and libavcodec don't even check whether it's present.
+         * Stuffing can cost up to 25% of the total bitrate and 3% of encode time
+         * in lossless mode. */
+
+        int i_cabac_word = ((h->cabac.i_sym_cnt
+                             - 96 * h->sps->i_mb_width * h->sps->i_mb_height) * 3/32
+                           - bs_pos(&h->out.bs)/8)/3;
 
         while( i_cabac_word > 0 )
         {
             bs_write( &h->out.bs, 16, 0x0000 );
             i_cabac_word--;
         }
+#endif
     }
     else
     {