Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.88 KB | None | 0 0
  1. diff --git a/encoder/analyse.c b/encoder/analyse.c
  2. index f27169c..3bf3153 100644
  3. --- a/encoder/analyse.c
  4. +++ b/encoder/analyse.c
  5. @@ -132,6 +132,7 @@ typedef struct
  6.      int i_mb_type8x16;
  7.  
  8.      int b_direct_available;
  9. +    int b_early_terminate;
  10.  
  11.  } x264_mb_analysis_t;
  12.  
  13. @@ -587,6 +588,8 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int qp )
  14.          else
  15.              a->b_force_intra = 0;
  16.      }
  17. +    
  18. +    a->b_early_terminate = h->param.analyse.i_subpel_refine < 11;
  19.  }
  20.  
  21.  /* Prediction modes allowed for various combinations of neighbors. */
  22. @@ -782,7 +785,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  23.  
  24.      /* Not heavily tuned */
  25.      static const uint8_t i16x16_thresh_lut[11] = { 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4 };
  26. -    int i16x16_thresh = a->b_fast_intra ? (i16x16_thresh_lut[h->mb.i_subpel_refine]*i_satd_inter)>>1 : COST_MAX;
  27. +    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;
  28.  
  29.      if( !h->mb.b_lossless && predict_mode[3] >= 0 )
  30.      {
  31. @@ -834,7 +837,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  32.      {
  33.          ALIGNED_ARRAY_16( pixel, edge,[33] );
  34.          x264_pixel_cmp_t sa8d = (h->pixf.mbcmp[0] == h->pixf.satd[0]) ? h->pixf.sa8d[PIXEL_8x8] : h->pixf.mbcmp[PIXEL_8x8];
  35. -        int i_satd_thresh = a->i_mbrd ? COST_MAX : X264_MIN( i_satd_inter, a->i_satd_i16x16 );
  36. +        int i_satd_thresh = (!a->b_early_terminate || a->i_mbrd) ? COST_MAX : X264_MIN( i_satd_inter, a->i_satd_i16x16 );
  37.  
  38.          // FIXME some bias like in i4x4?
  39.          int i_cost = lambda * 4; /* base predmode costs */
  40. @@ -927,7 +930,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  41.          }
  42.          /* Not heavily tuned */
  43.          static const uint8_t i8x8_thresh[11] = { 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6 };
  44. -        if( X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*i8x8_thresh[h->mb.i_subpel_refine])>>2 )
  45. +        if( a->b_early_terminate && X264_MIN(i_cost, a->i_satd_i16x16) > (i_satd_inter*i8x8_thresh[h->mb.i_subpel_refine])>>2 )
  46.              return;
  47.      }
  48.  
  49. @@ -935,10 +938,10 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  50.      if( flags & X264_ANALYSE_I4x4 )
  51.      {
  52.          int i_cost = lambda * (24+16); /* 24from JVT (SATD0), 16 from base predmode costs */
  53. -        int i_satd_thresh = X264_MIN3( i_satd_inter, a->i_satd_i16x16, a->i_satd_i8x8 );
  54. +        int i_satd_thresh = a->b_early_terminate ? X264_MIN3( i_satd_inter, a->i_satd_i16x16, a->i_satd_i8x8 ) : COST_MAX;
  55.          h->mb.i_cbp_luma = 0;
  56.  
  57. -        if( a->i_mbrd )
  58. +        if( a->b_early_terminate && a->i_mbrd )
  59.              i_satd_thresh = i_satd_thresh * (10-a->b_fast_intra)/8;
  60.  
  61.          if( h->sh.i_type == SLICE_TYPE_B )
  62. @@ -1572,7 +1575,7 @@ static void x264_mb_analyse_inter_p16x8( x264_t *h, x264_mb_analysis_t *a, int i
  63.  
  64.          /* Early termination based on the current SATD score of partition[0]
  65.             plus the estimated SATD score of partition[1] */
  66. -        if( !i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
  67. +        if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
  68.          {
  69.              a->l0.i_cost16x8 = COST_MAX;
  70.              return;
  71. @@ -1637,7 +1640,7 @@ static void x264_mb_analyse_inter_p8x16( x264_t *h, x264_mb_analysis_t *a, int i
  72.  
  73.          /* Early termination based on the current SATD score of partition[0]
  74.             plus the estimated SATD score of partition[1] */
  75. -        if( !i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
  76. +        if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
  77.          {
  78.              a->l0.i_cost8x16 = COST_MAX;
  79.              return;
  80. @@ -2454,8 +2457,8 @@ static void x264_mb_analyse_inter_b16x8( x264_t *h, x264_mb_analysis_t *a, int i
  81.  
  82.          /* Early termination based on the current SATD score of partition[0]
  83.             plus the estimated SATD score of partition[1] */
  84. -        if( !i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
  85. -            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
  86. +        if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
  87. +            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
  88.          {
  89.              a->i_cost16x8bi = COST_MAX;
  90.              return;
  91. @@ -2547,8 +2550,8 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
  92.  
  93.          /* Early termination based on the current SATD score of partition[0]
  94.             plus the estimated SATD score of partition[1] */
  95. -        if( !i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
  96. -            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
  97. +        if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
  98. +            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
  99.          {
  100.              a->i_cost8x16bi = COST_MAX;
  101.              return;
  102. @@ -2566,10 +2569,10 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
  103.  
  104.  static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  105.  {
  106. -    int thresh = i_satd * 5/4;
  107. +    int thresh = a->b_early_terminate ? i_satd * 5/4 : COST_MAX;
  108.  
  109.      h->mb.i_type = P_L0;
  110. -    if( a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2 )
  111. +    if( !a->b_early_terminate || (a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2) )
  112.      {
  113.          h->mb.i_partition = D_16x16;
  114.          x264_analyse_update_cache( h, a );
  115. @@ -2639,7 +2642,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  116.  
  117.  static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_inter )
  118.  {
  119. -    int thresh = i_satd_inter * (17 + (!!h->mb.i_psy_rd))/16;
  120. +    int thresh = a->b_early_terminate ? i_satd_inter * (17 + (!!h->mb.i_psy_rd))/16 : COST_MAX;
  121.  
  122.      if( a->b_direct_available && a->i_rd16x16direct == COST_MAX )
  123.      {
  124. @@ -3020,8 +3023,8 @@ intra_analysis:
  125.              i_partition = D_16x16;
  126.              i_cost = analysis.l0.me16x16.cost;
  127.  
  128. -            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
  129. -                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost )
  130. +            if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
  131. +                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost) )
  132.              {
  133.                  i_type = P_8x8;
  134.                  i_partition = D_8x8;
  135. @@ -3056,8 +3059,8 @@ intra_analysis:
  136.  
  137.              /* Now do 16x8/8x16 */
  138.              i_thresh16x8 = analysis.l0.me8x8[1].cost_mv + analysis.l0.me8x8[2].cost_mv;
  139. -            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
  140. -                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8 )
  141. +            if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
  142. +                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8) )
  143.              {
  144.                  int i_avg_mv_ref_cost = (analysis.l0.me8x8[2].cost_mv + analysis.l0.me8x8[2].i_ref_cost
  145.                                        + analysis.l0.me8x8[3].cost_mv + analysis.l0.me8x8[3].i_ref_cost + 1) >> 1;
  146. @@ -3177,7 +3180,7 @@ intra_analysis:
  147.                  h->mb.i_partition = i_partition;
  148.                  if( i_cost < COST_MAX )
  149.                      x264_mb_analyse_transform_rd( h, &analysis, &i_satd_inter, &i_cost );
  150. -                x264_intra_rd( h, &analysis, i_satd_inter * 5/4 );
  151. +                x264_intra_rd( h, &analysis, analysis.b_early_terminate ? i_satd_inter * 5/4 : COST_MAX );
  152.              }
  153.  
  154.              COPY2_IF_LT( i_cost, analysis.i_satd_i16x16, i_type, I_16x16 );
  155. @@ -3431,17 +3434,17 @@ intra_analysis:
  156.  
  157.                  /* We can gain a little speed by checking the mode with the lowest estimated cost first */
  158.                  int try_16x8_first = i_cost_est16x8bi_total < i_cost_est8x16bi_total;
  159. -                if( try_16x8_first && i_cost_est16x8bi_total < i_cost )
  160. +                if( !analysis.b_early_terminate || (try_16x8_first && i_cost_est16x8bi_total < i_cost) )
  161.                  {
  162.                      x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
  163.                      COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
  164.                  }
  165. -                if( i_cost_est8x16bi_total < i_cost )
  166. +                if( !analysis.b_early_terminate || i_cost_est8x16bi_total < i_cost )
  167.                  {
  168.                      x264_mb_analyse_inter_b8x16( h, &analysis, i_cost );
  169.                      COPY3_IF_LT( i_cost, analysis.i_cost8x16bi, i_type, analysis.i_mb_type8x16, i_partition, D_8x16 );
  170.                  }
  171. -                if( !try_16x8_first && i_cost_est16x8bi_total < i_cost )
  172. +                if( analysis.b_early_terminate && (!try_16x8_first && i_cost_est16x8bi_total < i_cost) )
  173.                  {
  174.                      x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
  175.                      COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
  176. diff --git a/encoder/encoder.c b/encoder/encoder.c
  177. index 79880a3..4022819 100644
  178. --- a/encoder/encoder.c
  179. +++ b/encoder/encoder.c
  180. @@ -503,7 +503,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
  181.      h->param.rc.f_rf_constant = x264_clip3f( h->param.rc.f_rf_constant, -QP_BD_OFFSET, 51 );
  182.      h->param.rc.f_rf_constant_max = x264_clip3f( h->param.rc.f_rf_constant_max, -QP_BD_OFFSET, 51 );
  183.      h->param.rc.i_qp_constant = x264_clip3( h->param.rc.i_qp_constant, 0, QP_MAX );
  184. -    h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 10 );
  185. +    h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 11 );
  186.      h->param.rc.f_ip_factor = X264_MAX( h->param.rc.f_ip_factor, 0.01f );
  187.      h->param.rc.f_pb_factor = X264_MAX( h->param.rc.f_pb_factor, 0.01f );
  188.      if( h->param.rc.i_rc_method == X264_RC_CRF )
  189. @@ -784,7 +784,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
  190.          h->param.rc.f_aq_strength = 0;
  191.      }
  192.      h->param.analyse.i_noise_reduction = x264_clip3( h->param.analyse.i_noise_reduction, 0, 1<<16 );
  193. -    if( h->param.analyse.i_subpel_refine == 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
  194. +    if( h->param.analyse.i_subpel_refine >= 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
  195.          h->param.analyse.i_subpel_refine = 9;
  196.  
  197.      {
  198. diff --git a/encoder/me.c b/encoder/me.c
  199. index ca6c602..10b7ef2 100644
  200. --- a/encoder/me.c
  201. +++ b/encoder/me.c
  202. @@ -46,6 +46,7 @@ static const uint8_t subpel_iterations[][4] =
  203.      {0,0,2,2},
  204.      {0,0,4,10},
  205.      {0,0,4,10},
  206. +    {0,0,4,10},
  207.      {0,0,4,10}};
  208.  
  209.  /* (x-1)%6 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement