📄 analyse.c
字号:
/* BI mode */
h->mc.mc_luma( m->p_fref, m->i_stride[0], pix[l], 8,
m->mv[0], m->mv[1], 8, 8 );
i_part_cost_bi += m->cost_mv;
/* FIXME: ref cost */
}
WEIGHTED_AVG( PIXEL_8x8, pix[0], 8, pix[1], 8 );
i_part_cost_bi += h->pixf.mbcmp[PIXEL_8x8]( a->l0.me8x8[i].p_fenc[0], FENC_STRIDE, pix[0], 8 )
+ a->i_lambda * i_sub_mb_b_cost_table[D_BI_8x8];
a->l0.me8x8[i].cost += a->i_lambda * i_sub_mb_b_cost_table[D_L0_8x8];
a->l1.me8x8[i].cost += a->i_lambda * i_sub_mb_b_cost_table[D_L1_8x8];
i_part_cost = a->l0.me8x8[i].cost;
h->mb.i_sub_partition[i] = D_L0_8x8;
COPY2_IF_LT( i_part_cost, a->l1.me8x8[i].cost, h->mb.i_sub_partition[i], D_L1_8x8 );
COPY2_IF_LT( i_part_cost, i_part_cost_bi, h->mb.i_sub_partition[i], D_BI_8x8 );
COPY2_IF_LT( i_part_cost, a->i_cost8x8direct[i], h->mb.i_sub_partition[i], D_DIRECT_8x8 );
a->i_cost8x8bi += i_part_cost;
/* XXX Needed for x264_mb_predict_mv */
x264_mb_cache_mv_b8x8( h, a, i, 0 );
}
/* mb type cost */
a->i_cost8x8bi += a->i_lambda * i_mb_b_cost_table[B_8x8];
}
static void x264_mb_analyse_inter_b16x8( x264_t *h, x264_mb_analysis_t *a )
{
/*
uint8_t **p_fref[2] =
{ h->mb.pic.p_fref[0][a->l0.i_ref],
h->mb.pic.p_fref[1][a->l1.i_ref] };
*/
uint8_t pix[2][16*8];//DECLARE_ALIGNED( uint8_t, pix[2][16*8], 16 );
int mvc[2][2];
int i, l;
uint8_t **p_fref[2];
p_fref[0] = h->mb.pic.p_fref[0][a->l0.i_ref];
p_fref[1] = h->mb.pic.p_fref[1][a->l1.i_ref];
h->mb.i_partition = D_16x8;
a->i_cost16x8bi = 0;
for( i = 0; i < 2; i++ )
{
int i_part_cost;
int i_part_cost_bi = 0;
/* TODO: check only the list(s) that were used in b8x8? */
for( l = 0; l < 2; l++ )
{
x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
x264_me_t *m = &lX->me16x8[i];
m->i_pixel = PIXEL_16x8;
m->p_cost_mv = a->p_cost_mv;
LOAD_FENC( m, h->mb.pic.p_fenc, 0, 8*i );
LOAD_HPELS( m, p_fref[l], l, lX->i_ref, 0, 8*i );
mvc[0][0] = lX->me8x8[2*i].mv[0];
mvc[0][1] = lX->me8x8[2*i].mv[1];
mvc[1][0] = lX->me8x8[2*i+1].mv[0];
mvc[1][1] = lX->me8x8[2*i+1].mv[1];
x264_mb_predict_mv( h, 0, 8*i, 2, m->mvp );
x264_me_search( h, m, mvc, 2 );
/* BI mode */
h->mc.mc_luma( m->p_fref, m->i_stride[0], pix[l], 16,
m->mv[0], m->mv[1], 16, 8 );
/* FIXME: ref cost */
i_part_cost_bi += m->cost_mv;
}
WEIGHTED_AVG( PIXEL_16x8, pix[0], 16, pix[1], 16 );
i_part_cost_bi += h->pixf.mbcmp[PIXEL_16x8]( a->l0.me16x8[i].p_fenc[0], FENC_STRIDE, pix[0], 16 );
i_part_cost = a->l0.me16x8[i].cost;
a->i_mb_partition16x8[i] = D_L0_8x8; /* not actually 8x8, only the L0 matters */
if( a->l1.me16x8[i].cost < i_part_cost )
{
i_part_cost = a->l1.me16x8[i].cost;
a->i_mb_partition16x8[i] = D_L1_8x8;
}
if( i_part_cost_bi + a->i_lambda * 1 < i_part_cost )
{
i_part_cost = i_part_cost_bi;
a->i_mb_partition16x8[i] = D_BI_8x8;
}
a->i_cost16x8bi += i_part_cost;
x264_mb_cache_mv_b16x8( h, a, i, 0 );
}
/* mb type cost */
a->i_mb_type16x8 = B_L0_L0
+ (a->i_mb_partition16x8[0]>>2) * 3
+ (a->i_mb_partition16x8[1]>>2);
a->i_cost16x8bi += a->i_lambda * i_mb_b16x8_cost_table[a->i_mb_type16x8];
}
static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a )
{
/*
uint8_t **p_fref[2] =
{ h->mb.pic.p_fref[0][a->l0.i_ref],
h->mb.pic.p_fref[1][a->l1.i_ref] };
*/
uint8_t pix[2][8*16];
int mvc[2][2];
int i, l;
uint8_t **p_fref[2];
p_fref[0] = h->mb.pic.p_fref[0][a->l0.i_ref];
p_fref[1] = h->mb.pic.p_fref[1][a->l1.i_ref];
h->mb.i_partition = D_8x16;
a->i_cost8x16bi = 0;
for( i = 0; i < 2; i++ )
{
int i_part_cost;
int i_part_cost_bi = 0;
for( l = 0; l < 2; l++ )
{
x264_mb_analysis_list_t *lX = l ? &a->l1 : &a->l0;
x264_me_t *m = &lX->me8x16[i];
m->i_pixel = PIXEL_8x16;
m->p_cost_mv = a->p_cost_mv;
LOAD_FENC( m, h->mb.pic.p_fenc, 8*i, 0 );
LOAD_HPELS( m, p_fref[l], l, lX->i_ref, 8*i, 0 );
mvc[0][0] = lX->me8x8[i].mv[0];
mvc[0][1] = lX->me8x8[i].mv[1];
mvc[1][0] = lX->me8x8[i+2].mv[0];
mvc[1][1] = lX->me8x8[i+2].mv[1];
x264_mb_predict_mv( h, 0, 4*i, 2, m->mvp );
x264_me_search( h, m, mvc, 2 );
/* BI mode */
h->mc.mc_luma( m->p_fref, m->i_stride[0], pix[l], 8,
m->mv[0], m->mv[1], 8, 16 );
/* FIXME: ref cost */
i_part_cost_bi += m->cost_mv;
}
WEIGHTED_AVG( PIXEL_8x16, pix[0], 8, pix[1], 8 );
i_part_cost_bi += h->pixf.mbcmp[PIXEL_8x16]( a->l0.me8x16[i].p_fenc[0], FENC_STRIDE, pix[0], 8 );
i_part_cost = a->l0.me8x16[i].cost;
a->i_mb_partition8x16[i] = D_L0_8x8;
if( a->l1.me8x16[i].cost < i_part_cost )
{
i_part_cost = a->l1.me8x16[i].cost;
a->i_mb_partition8x16[i] = D_L1_8x8;
}
if( i_part_cost_bi + a->i_lambda * 1 < i_part_cost )
{
i_part_cost = i_part_cost_bi;
a->i_mb_partition8x16[i] = D_BI_8x8;
}
a->i_cost8x16bi += i_part_cost;
x264_mb_cache_mv_b8x16( h, a, i, 0 );
}
/* mb type cost */
a->i_mb_type8x16 = B_L0_L0
+ (a->i_mb_partition8x16[0]>>2) * 3
+ (a->i_mb_partition8x16[1]>>2);
a->i_cost8x16bi += a->i_lambda * i_mb_b16x8_cost_table[a->i_mb_type8x16];
}
static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
{
int thresh = i_satd * 5/4;
h->mb.i_type = P_L0;
if( a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2 )
{
h->mb.i_partition = D_16x16;
x264_analyse_update_cache( h, a );
a->l0.i_rd16x16 = x264_rd_cost_mb( h, a->i_lambda2 );
}
a->l0.me16x16.cost = a->l0.i_rd16x16;
if( a->l0.i_cost16x8 <= thresh )
{
h->mb.i_partition = D_16x8;
x264_analyse_update_cache( h, a );
a->l0.i_cost16x8 = x264_rd_cost_mb( h, a->i_lambda2 );
}
else
a->l0.i_cost16x8 = COST_MAX;
if( a->l0.i_cost8x16 <= thresh )
{
h->mb.i_partition = D_8x16;
x264_analyse_update_cache( h, a );
a->l0.i_cost8x16 = x264_rd_cost_mb( h, a->i_lambda2 );
}
else
a->l0.i_cost8x16 = COST_MAX;
if( a->l0.i_cost8x8 <= thresh )
{
h->mb.i_type = P_8x8;
x264_analyse_update_cache( h, a );
a->l0.i_cost8x8 = x264_rd_cost_mb( h, a->i_lambda2 );
if( h->param.analyse.inter & X264_ANALYSE_PSUB8x8 )
{
/* FIXME: RD per subpartition */
int part_bak[4];
int i, i_cost;
int b_sub8x8 = 0;
for( i=0; i<4; i++ )
{
part_bak[i] = h->mb.i_sub_partition[i];
b_sub8x8 |= (part_bak[i] != D_L0_8x8);
}
if( b_sub8x8 )
{
h->mb.i_sub_partition[0] = h->mb.i_sub_partition[1] =
h->mb.i_sub_partition[2] = h->mb.i_sub_partition[3] = D_L0_8x8;
i_cost = x264_rd_cost_mb( h, a->i_lambda2 );
if( a->l0.i_cost8x8 < i_cost )
{
for( i=0; i<4; i++ )
h->mb.i_sub_partition[i] = part_bak[i];
}
else
a->l0.i_cost8x8 = i_cost;
}
}
}
else
a->l0.i_cost8x8 = COST_MAX;
}
static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_inter )
{
int thresh = i_satd_inter * 17/16;
if( a->b_direct_available && a->i_rd16x16direct == COST_MAX )
{
h->mb.i_type = B_DIRECT;
x264_analyse_update_cache( h, a );
a->i_rd16x16direct = x264_rd_cost_mb( h, a->i_lambda2 );
}
//FIXME not all the update_cache calls are needed
h->mb.i_partition = D_16x16;
/* L0 */
if( a->l0.me16x16.cost <= thresh && a->l0.i_rd16x16 == COST_MAX )
{
h->mb.i_type = B_L0_L0;
x264_analyse_update_cache( h, a );
a->l0.i_rd16x16 = x264_rd_cost_mb( h, a->i_lambda2 );
}
/* L1 */
if( a->l1.me16x16.cost <= thresh && a->l1.i_rd16x16 == COST_MAX )
{
h->mb.i_type = B_L1_L1;
x264_analyse_update_cache( h, a );
a->l1.i_rd16x16 = x264_rd_cost_mb( h, a->i_lambda2 );
}
/* BI */
if( a->i_cost16x16bi <= thresh && a->i_rd16x16bi == COST_MAX )
{
h->mb.i_type = B_BI_BI;
x264_analyse_update_cache( h, a );
a->i_rd16x16bi = x264_rd_cost_mb( h, a->i_lambda2 );
}
/* 8x8 */
if( a->i_cost8x8bi <= thresh && a->i_rd8x8bi == COST_MAX )
{
h->mb.i_type = B_8x8;
h->mb.i_partition = D_8x8;
x264_analyse_update_cache( h, a );
a->i_rd8x8bi = x264_rd_cost_mb( h, a->i_lambda2 );
x264_macroblock_cache_skip( h, 0, 0, 4, 4, 0 );
}
/* 16x8 */
if( a->i_cost16x8bi <= thresh && a->i_rd16x8bi == COST_MAX )
{
h->mb.i_type = a->i_mb_type16x8;
h->mb.i_partition = D_16x8;
x264_analyse_update_cache( h, a );
a->i_rd16x8bi = x264_rd_cost_mb( h, a->i_lambda2 );
}
/* 8x16 */
if( a->i_cost8x16bi <= thresh && a->i_rd8x16bi == COST_MAX )
{
h->mb.i_type = a->i_mb_type8x16;
h->mb.i_partition = D_8x16;
x264_analyse_update_cache( h, a );
a->i_rd8x16bi = x264_rd_cost_mb( h, a->i_lambda2 );
}
}
static void refine_bidir( x264_t *h, x264_mb_analysis_t *a )
{
const int i_biweight = h->mb.bipred_weight[a->l0.i_ref][a->l1.i_ref];
int i;
switch( h->mb.i_partition )
{
case D_16x16:
if( h->mb.i_type == B_BI_BI )
x264_me_refine_bidir( h, &a->l0.me16x16, &a->l1.me16x16, i_biweight );
break;
case D_16x8:
for( i=0; i<2; i++ )
if( a->i_mb_partition16x8[i] == D_BI_8x8 )
x264_me_refine_bidir( h, &a->l0.me16x8[i], &a->l1.me16x8[i], i_biweight );
break;
case D_8x16:
for( i=0; i<2; i++ )
if( a->i_mb_partition8x16[i] == D_BI_8x8 )
x264_me_refine_bidir( h, &a->l0.me8x16[i], &a->l1.me8x16[i], i_biweight );
break;
case D_8x8:
for( i=0; i<4; i++ )
if( h->mb.i_sub_partition[i] == D_BI_8x8 )
x264_me_refine_bidir( h, &a->l0.me8x8[i], &a->l1.me8x8[i], i_biweight );
break;
}
}
static inline void x264_mb_analyse_transform( x264_t *h )
{
h->mb.cache.b_transform_8x8_allowed =
h->param.analyse.b_transform_8x8
&& !IS_INTRA( h->mb.i_type ) && x264_mb_transform_8x8_allowed( h );
if( h->mb.cache.b_transform_8x8_allowed )
{
int i_cost4, i_cost8;
/* FIXME only luma mc is needed */
x264_mb_mc( h );
i_cost8 = h->pixf.sa8d[PIXEL_16x16]( h->mb.pic.p_fenc[0], FENC_STRIDE,
h->mb.pic.p_fdec[0], FDEC_STRIDE );
i_cost4 = h->pixf.satd[PIXEL_16x16]( h->mb.pic.p_fenc[0], FENC_STRIDE,
h->mb.pic.p_fdec[0], FDEC_STRIDE );
h->mb.b_transform_8x8 = i_cost8 < i_cost4;
}
}
static inline void x264_mb_analyse_transform_rd( x264_t *h, x264_mb_analysis_t *a, int *i_satd, int *i_rd )
{
h->mb.cache.b_tr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -