Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/encoder/analyse.c b/encoder/analyse.c
- index f27169c..3bf3153 100644
- --- a/encoder/analyse.c
- +++ b/encoder/analyse.c
- @@ -132,6 +132,7 @@ typedef struct
- int i_mb_type8x16;
- int b_direct_available;
- + int b_early_terminate;
- } x264_mb_analysis_t;
- @@ -587,6 +588,8 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int qp )
- else
- a->b_force_intra = 0;
- }
- +
- + a->b_early_terminate = h->param.analyse.i_subpel_refine < 11;
- }
- /* Prediction modes allowed for various combinations of neighbors. */
- @@ -782,7 +785,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
- /* Not heavily tuned */
- static const uint8_t i16x16_thresh_lut[11] = { 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4 };
- - int i16x16_thresh = a->b_fast_intra ? (i16x16_thresh_lut[h->mb.i_subpel_refine]*i_satd_inter)>>1 : COST_MAX;
- + int i16x16_thresh = (a->b_early_terminate && a->b_fast_intra) ? (i16x16_thresh_lut[h->mb.i_subpel_refine]*i_satd_inter)>>1 : COST_MAX;
- if( !h->mb.b_lossless && predict_mode[3] >= 0 )
- {
- @@ -834,7 +837,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
- {
- ALIGNED_ARRAY_16( pixel, edge,[33] );
- x264_pixel_cmp_t sa8d = (h->pixf.mbcmp[0] == h->pixf.satd[0]) ? h->pixf.sa8d[PIXEL_8x8] : h->pixf.mbcmp[PIXEL_8x8];
- - int i_satd_thresh = a->i_mbrd ? COST_MAX : X264_MIN( i_satd_inter, a->i_satd_i16x16 );
- + int i_satd_thresh = (!a->b_early_terminate || a->i_mbrd) ? COST_MAX : X264_MIN( i_satd_inter, a->i_satd_i16x16 );
- // FIXME some bias like in i4x4?
- int i_cost = lambda * 4; /* base predmode costs */
- @@ -927,7 +930,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
- }
- /* Not heavily tuned */
- static const uint8_t i8x8_thresh[11] = { 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6 };
- - if( X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*i8x8_thresh[h->mb.i_subpel_refine])>>2 )
- + if( a->b_early_terminate && X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*i8x8_thresh[h->mb.i_subpel_refine])>>2 )
- return;
- }
- @@ -935,10 +938,10 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
- if( flags & X264_ANALYSE_I4x4 )
- {
- int i_cost = lambda * (24+16); /* 24from JVT (SATD0), 16 from base predmode costs */
- - int i_satd_thresh = X264_MIN3( i_satd_inter, a->i_satd_i16x16, a->i_satd_i8x8 );
- + int i_satd_thresh = a->b_early_terminate ? X264_MIN3( i_satd_inter, a->i_satd_i16x16, a->i_satd_i8x8 ) : COST_MAX;
- h->mb.i_cbp_luma = 0;
- - if( a->i_mbrd )
- + if( a->b_early_terminate && a->i_mbrd )
- i_satd_thresh = i_satd_thresh * (10-a->b_fast_intra)/8;
- if( h->sh.i_type == SLICE_TYPE_B )
- @@ -1572,7 +1575,7 @@ static void x264_mb_analyse_inter_p16x8( x264_t *h, x264_mb_analysis_t *a, int i
- /* Early termination based on the current SATD score of partition[0]
- plus the estimated SATD score of partition[1] */
- - if( !i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
- + if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
- {
- a->l0.i_cost16x8 = COST_MAX;
- return;
- @@ -1637,7 +1640,7 @@ static void x264_mb_analyse_inter_p8x16( x264_t *h, x264_mb_analysis_t *a, int i
- /* Early termination based on the current SATD score of partition[0]
- plus the estimated SATD score of partition[1] */
- - if( !i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
- + if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
- {
- a->l0.i_cost8x16 = COST_MAX;
- return;
- @@ -2454,8 +2457,8 @@ static void x264_mb_analyse_inter_b16x8( x264_t *h, x264_mb_analysis_t *a, int i
- /* Early termination based on the current SATD score of partition[0]
- plus the estimated SATD score of partition[1] */
- - if( !i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
- - * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
- + if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
- + * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
- {
- a->i_cost16x8bi = COST_MAX;
- return;
- @@ -2547,8 +2550,8 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
- /* Early termination based on the current SATD score of partition[0]
- plus the estimated SATD score of partition[1] */
- - if( !i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
- - * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
- + if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
- + * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
- {
- a->i_cost8x16bi = COST_MAX;
- return;
- @@ -2566,10 +2569,10 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
- static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
- {
- - int thresh = i_satd * 5/4;
- + int thresh = a->b_early_terminate ? i_satd * 5/4 : COST_MAX;
- h->mb.i_type = P_L0;
- - if( a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2 )
- + if( !a->b_early_terminate || (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 );
- @@ -2639,7 +2642,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
- 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 + (!!h->mb.i_psy_rd))/16;
- + int thresh = a->b_early_terminate ? i_satd_inter * (17 + (!!h->mb.i_psy_rd))/16 : COST_MAX;
- if( a->b_direct_available && a->i_rd16x16direct == COST_MAX )
- {
- @@ -3020,8 +3023,8 @@ intra_analysis:
- i_partition = D_16x16;
- i_cost = analysis.l0.me16x16.cost;
- - if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
- - analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost )
- + if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
- + analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost) )
- {
- i_type = P_8x8;
- i_partition = D_8x8;
- @@ -3056,8 +3059,8 @@ intra_analysis:
- /* Now do 16x8/8x16 */
- i_thresh16x8 = analysis.l0.me8x8[1].cost_mv + analysis.l0.me8x8[2].cost_mv;
- - if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
- - analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8 )
- + if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
- + analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8) )
- {
- int i_avg_mv_ref_cost = (analysis.l0.me8x8[2].cost_mv + analysis.l0.me8x8[2].i_ref_cost
- + analysis.l0.me8x8[3].cost_mv + analysis.l0.me8x8[3].i_ref_cost + 1) >> 1;
- @@ -3177,7 +3180,7 @@ intra_analysis:
- h->mb.i_partition = i_partition;
- if( i_cost < COST_MAX )
- x264_mb_analyse_transform_rd( h, &analysis, &i_satd_inter, &i_cost );
- - x264_intra_rd( h, &analysis, i_satd_inter * 5/4 );
- + x264_intra_rd( h, &analysis, analysis.b_early_terminate ? i_satd_inter * 5/4 : COST_MAX );
- }
- COPY2_IF_LT( i_cost, analysis.i_satd_i16x16, i_type, I_16x16 );
- @@ -3431,17 +3434,17 @@ intra_analysis:
- /* We can gain a little speed by checking the mode with the lowest estimated cost first */
- int try_16x8_first = i_cost_est16x8bi_total < i_cost_est8x16bi_total;
- - if( try_16x8_first && i_cost_est16x8bi_total < i_cost )
- + if( !analysis.b_early_terminate || (try_16x8_first && i_cost_est16x8bi_total < i_cost) )
- {
- x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
- COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
- }
- - if( i_cost_est8x16bi_total < i_cost )
- + if( !analysis.b_early_terminate || i_cost_est8x16bi_total < i_cost )
- {
- x264_mb_analyse_inter_b8x16( h, &analysis, i_cost );
- COPY3_IF_LT( i_cost, analysis.i_cost8x16bi, i_type, analysis.i_mb_type8x16, i_partition, D_8x16 );
- }
- - if( !try_16x8_first && i_cost_est16x8bi_total < i_cost )
- + if( analysis.b_early_terminate && (!try_16x8_first && i_cost_est16x8bi_total < i_cost) )
- {
- x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
- COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
- diff --git a/encoder/encoder.c b/encoder/encoder.c
- index 79880a3..4022819 100644
- --- a/encoder/encoder.c
- +++ b/encoder/encoder.c
- @@ -503,7 +503,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
- h->param.rc.f_rf_constant = x264_clip3f( h->param.rc.f_rf_constant, -QP_BD_OFFSET, 51 );
- h->param.rc.f_rf_constant_max = x264_clip3f( h->param.rc.f_rf_constant_max, -QP_BD_OFFSET, 51 );
- h->param.rc.i_qp_constant = x264_clip3( h->param.rc.i_qp_constant, 0, QP_MAX );
- - h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 10 );
- + h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 11 );
- h->param.rc.f_ip_factor = X264_MAX( h->param.rc.f_ip_factor, 0.01f );
- h->param.rc.f_pb_factor = X264_MAX( h->param.rc.f_pb_factor, 0.01f );
- if( h->param.rc.i_rc_method == X264_RC_CRF )
- @@ -784,7 +784,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
- h->param.rc.f_aq_strength = 0;
- }
- h->param.analyse.i_noise_reduction = x264_clip3( h->param.analyse.i_noise_reduction, 0, 1<<16 );
- - if( h->param.analyse.i_subpel_refine == 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
- + if( h->param.analyse.i_subpel_refine >= 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
- h->param.analyse.i_subpel_refine = 9;
- {
- diff --git a/encoder/me.c b/encoder/me.c
- index ca6c602..10b7ef2 100644
- --- a/encoder/me.c
- +++ b/encoder/me.c
- @@ -46,6 +46,7 @@ static const uint8_t subpel_iterations[][4] =
- {0,0,2,2},
- {0,0,4,10},
- {0,0,4,10},
- + {0,0,4,10},
- {0,0,4,10}};
- /* (x-1)%6 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement