📄 analyse.c
字号:
x264_me_search( h, m, &lX->me16x16.mv, 1 ); x264_macroblock_cache_mv( h, 2*x8, 2*y8, 2, 2, l, m->mv[0], m->mv[1] ); /* 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.satd[PIXEL_8x8]( a->l0.me8x8[i].p_fenc[0], h->mb.pic.i_stride[0], 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; if( a->l1.me8x8[i].cost < i_part_cost ) { i_part_cost = a->l1.me8x8[i].cost; h->mb.i_sub_partition[i] = D_L1_8x8; } if( i_part_cost_bi < i_part_cost ) { i_part_cost = i_part_cost_bi; h->mb.i_sub_partition[i] = D_BI_8x8; } if( a->i_cost8x8direct[i] < i_part_cost ) { 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]; int mvc[2][2]; int i, l; 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], 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.satd[PIXEL_16x8]( a->l0.me16x8[i].p_fenc[0], h->mb.pic.i_stride[0], 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; if( i == 0 ) 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; 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], 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.satd[PIXEL_8x16]( a->l0.me8x16[i].p_fenc[0], h->mb.pic.i_stride[0], 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; if( i == 0 ) 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];}/***************************************************************************** * x264_macroblock_analyse: *****************************************************************************/void x264_macroblock_analyse( x264_t *h ){ x264_mb_analysis_t analysis; int i; h->mb.qp[h->mb.i_mb_xy] = x264_ratecontrol_qp(h); /* prevent QP from varying too fast. FIXME what's a sane limit? */ h->mb.qp[h->mb.i_mb_xy] = x264_clip3( h->mb.qp[h->mb.i_mb_xy], h->mb.i_last_qp - 12, h->mb.i_last_qp + 12 ); /* init analysis */ x264_mb_analyse_init( h, &analysis, h->mb.qp[h->mb.i_mb_xy] ); /*--------------------------- Do the analysis ---------------------------*/ if( h->sh.i_type == SLICE_TYPE_I ) { x264_mb_analyse_intra( h, &analysis, COST_MAX ); if( analysis.i_sad_i4x4 < analysis.i_sad_i16x16 ) h->mb.i_type = I_4x4; else h->mb.i_type = I_16x16; } else if( h->sh.i_type == SLICE_TYPE_P ) { const unsigned int i_neighbour = h->mb.i_neighbour; int b_skip = 0; int i_cost; int i_intra_cost, i_intra_type; /* Fast P_SKIP detection */ if( ( (i_neighbour&MB_LEFT) && h->mb.type[h->mb.i_mb_xy - 1] == P_SKIP ) || ( (i_neighbour&MB_TOP) && h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride] == P_SKIP ) || ( ((i_neighbour&(MB_TOP|MB_LEFT)) == (MB_TOP|MB_LEFT) ) && h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride-1 ] == P_SKIP ) || ( (i_neighbour&MB_TOPRIGHT) && h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride+1 ] == P_SKIP ) ) { b_skip = x264_macroblock_probe_pskip( h ); } if( b_skip ) { h->mb.i_type = P_SKIP; h->mb.i_partition = D_16x16; } else { const unsigned int flags = h->param.analyse.inter; int i_type; int i_partition; x264_mb_analyse_load_costs( h, &analysis ); x264_mb_analyse_inter_p16x16( h, &analysis ); if( flags & X264_ANALYSE_PSUB16x16 ) x264_mb_analyse_inter_p8x8( h, &analysis ); /* Select best inter mode */ i_type = P_L0; i_partition = D_16x16; i_cost = analysis.l0.me16x16.cost; if( ( flags & X264_ANALYSE_PSUB16x16 ) && analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost ) { int i; i_type = P_8x8; i_partition = D_8x8; h->mb.i_sub_partition[0] = D_L0_8x8; h->mb.i_sub_partition[1] = D_L0_8x8; h->mb.i_sub_partition[2] = D_L0_8x8; h->mb.i_sub_partition[3] = D_L0_8x8; i_cost = analysis.l0.i_cost8x8; /* Do sub 8x8 */ if( flags & X264_ANALYSE_PSUB8x8 ) { for( i = 0; i < 4; i++ ) { x264_mb_analyse_inter_p4x4( h, &analysis, i ); if( analysis.l0.i_cost4x4[i] < analysis.l0.me8x8[i].cost ) { int i_cost8x8; h->mb.i_sub_partition[i] = D_L0_4x4; i_cost8x8 = analysis.l0.i_cost4x4[i]; x264_mb_analyse_inter_p8x4( h, &analysis, i ); if( analysis.l0.i_cost8x4[i] < analysis.l0.i_cost4x4[i] ) { h->mb.i_sub_partition[i] = D_L0_8x4; i_cost8x8 = analysis.l0.i_cost8x4[i]; } x264_mb_analyse_inter_p4x8( h, &analysis, i ); if( analysis.l0.i_cost4x8[i] < analysis.l0.i_cost4x4[i] ) { h->mb.i_sub_partition[i] = D_L0_4x8; i_cost8x8 = analysis.l0.i_cost4x8[i]; } i_cost += i_cost8x8 - analysis.l0.me8x8[i].cost; } } } /* Now do sub 16x8/8x16 */ x264_mb_analyse_inter_p16x8( h, &analysis ); if( analysis.l0.i_cost16x8 < i_cost ) { i_type = P_L0; i_partition = D_16x8; i_cost = analysis.l0.i_cost16x8; } x264_mb_analyse_inter_p8x16( h, &analysis ); if( analysis.l0.i_cost8x16 < i_cost ) { i_type = P_L0; i_partition = D_8x16; i_cost = analysis.l0.i_cost8x16; } } h->mb.i_type = i_type; h->mb.i_partition = i_partition; /* refine qpel */ if( h->mb.i_partition == D_16x16 ) { x264_me_refine_qpel( h, &analysis.l0.me16x16 ); i_cost = analysis.l0.me16x16.cost; } else if( h->mb.i_partition == D_16x8 ) { x264_me_refine_qpel( h, &analysis.l0.me16x8[0] ); x264_me_refine_qpel( h, &analysis.l0.me16x8[1] ); i_cost = analysis.l0.me16x8[0].cost + analysis.l0.me16x8[1].cost; } else if( h->mb.i_partition == D_8x16 ) { x264_me_refine_qpel( h, &analysis.l0.me8x16[0] ); x264_me_refine_qpel( h, &analysis.l0.me8x16[1] ); i_cost = analysis.l0.me8x16[0].cost + analysis.l0.me8x16[1].cost; } else if( h->mb.i_partition == D_8x8 ) { int i8x8; i_cost = 0; for( i8x8 = 0; i8x8 < 4; i8x8++ ) { switch( h->mb.i_sub_partition[i8x8] ) { case D_L0_8x8: x264_me_refine_qpel( h, &analysis.l0.me8x8[i8x8] ); i_cost += analysis.l0.me8x8[i8x8].cost; break; case D_L0_8x4: x264_me_refine_qpel( h, &analysis.l0.me8x4[i8x8][0] ); x264_me_refine_qpel( h, &analysis.l0.me8x4[i8x8][1] ); i_cost += analysis.l0.me8x4[i8x8][0].cost + analysis.l0.me8x4[i8x8][1].cost; break; case D_L0_4x8: x264_me_refine_qpel( h, &analysis.l0.me4x8[i8x8][0] ); x264_me_refine_qpel( h, &analysis.l0.me4x8[i8x8][1] ); i_cost += analysis.l0.me4x8[i8x8][0].cost + analysis.l0.me4x8[i8x8][1].cost; break; case D_L0_4x4: x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][0] ); x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][1] ); x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][2] ); x264_me_refine_qpel( h, &analysis.l0.me4x4[i8x8][3] ); i_cost += analysis.l0.me4x4[i8x8][0].cost + analysis.l0.me4x4[i8x8][1].cost + analysis.l0.me4x4[i8x8][2].cost + analysis.l0.me4x4[i8x8][3].cost;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -