Commit bf749f76 authored by Fiona Glaser's avatar Fiona Glaser

CAVLC optimizations

faster bs_write_te, port CABAC context selection optimization to CAVLC.
parent be3c3d21
......@@ -233,7 +233,7 @@ static inline void bs_write_te( bs_t *s, int x, int val )
{
if( x == 1 )
bs_write1( s, 1^val );
else if( x > 1 )
else //if( x > 1 )
bs_write_ue( s, val );
}
......@@ -265,10 +265,8 @@ static inline int bs_size_te( int x, int val )
{
if( x == 1 )
return 1;
else if( x > 1 )
else //if( x > 1 )
return x264_ue_size_tab[val+1];
else
return 0;
}
#endif
......@@ -195,7 +195,7 @@ static void x264_mb_analyse_load_costs( x264_t *h, x264_mb_analysis_t *a )
}
for( i = 0; i < 3; i++ )
for( j = 0; j < 33; j++ )
x264_cost_ref[a->i_qp][i][j] = a->i_lambda * bs_size_te( i, j );
x264_cost_ref[a->i_qp][i][j] = i ? a->i_lambda * bs_size_te( i, j ) : 0;
}
a->p_cost_mv = p_cost_mv[a->i_qp];
a->p_cost_ref0 = x264_cost_ref[a->i_qp][x264_clip3(h->sh.i_num_ref_idx_l0_active-1,0,2)];
......
......@@ -112,16 +112,13 @@ static inline int block_residual_write_cavlc_escape( x264_t *h, bs_t *s, int i_s
return i_suffix_length;
}
static void block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, int i_idx, int16_t *l, int i_count )
static void block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, int i_idx, int16_t *l, int i_count, int nC )
{
static const uint8_t ct_index[17] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3};
static const uint8_t ctz_index[8] = {3,0,1,0,2,0,1,0};
x264_run_level_t runlevel;
int i_trailing, i_total_zero, i_suffix_length, i;
int i_total = 0;
unsigned int i_sign;
/* x264_mb_predict_non_zero_code return 0 <-> (16+16+1)>>1 = 16 */
int nC = i_idx >= 25 ? 4 : ct_index[x264_mb_predict_non_zero_code( h, i_idx == 24 ? 0 : i_idx )];
if( !h->mb.cache.non_zero_count[x264_scan8[i_idx]] )
{
......@@ -198,6 +195,14 @@ static void block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, i
}
}
static const uint8_t ct_index[17] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3};
#define block_residual_write_cavlc(h,s,cat,idx,l,count)\
{\
int nC = cat == DCT_CHROMA_DC ? 4 : ct_index[x264_mb_predict_non_zero_code( h, cat == DCT_LUMA_DC ? 0 : idx )];\
block_residual_write_cavlc(h,s,cat,idx,l,count,nC);\
}
static void cavlc_qp_delta( x264_t *h, bs_t *s )
{
int i_dqp = h->mb.i_qp - h->mb.i_last_qp;
......@@ -319,7 +324,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
}
#if !RDO_SKIP_BS
if( i_mb_type == I_PCM)
if( i_mb_type == I_PCM )
{
bs_write_ue( s, i_mb_i_offset + 25 );
i_mb_pos_tex = bs_pos( s );
......@@ -382,7 +387,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
if( h->mb.i_partition == D_16x16 )
{
bs_write_ue( s, 0 );
bs_write1( s, 1 );
if( h->mb.pic.i_fref[0] > 1 )
bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
......@@ -437,7 +442,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
else
{
bs_write_ue( s, 3 );
b_sub_ref = h->mb.pic.i_fref[0] > 1;
b_sub_ref = 1;
}
/* sub mb type */
......@@ -468,12 +473,14 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
bs_write_ue( s, sub_mb_type_b_to_golomb[ h->mb.i_sub_partition[i] ] );
/* ref */
for( i = 0; i < 4; i++ )
if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[i*4]] );
for( i = 0; i < 4; i++ )
if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
bs_write_te( s, h->mb.pic.i_fref[1] - 1, h->mb.cache.ref[1][x264_scan8[i*4]] );
if( h->mb.pic.i_fref[0] > 1 )
for( i = 0; i < 4; i++ )
if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[i*4]] );
if( h->mb.pic.i_fref[1] > 1 )
for( i = 0; i < 4; i++ )
if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
bs_write_te( s, h->mb.pic.i_fref[1] - 1, h->mb.cache.ref[1][x264_scan8[i*4]] );
/* mvd */
for( i = 0; i < 4; i++ )
......@@ -555,7 +562,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
}
}
else if( i_mb_type == B_DIRECT )
bs_write_ue( s, 0 );
bs_write1( s, 1 );
else
{
x264_log(h, X264_LOG_ERROR, "invalid/unhandled mb_type\n" );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment