Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 15.45 KB | None | 0 0
  1. diff --git a/encoder/analyse.c b/encoder/analyse.c
  2. index 0dd7235..e7ed1cc 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. @@ -1033,7 +1036,7 @@ static void x264_mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_
  63.  
  64.  static void x264_intra_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_thresh )
  65.  {
  66. -    if( a->i_satd_i16x16 <= i_satd_thresh )
  67. +    if( a->i_satd_i16x16 < i_satd_thresh )
  68.      {
  69.          h->mb.i_type = I_16x16;
  70.          x264_analyse_update_cache( h, a );
  71. @@ -1042,7 +1045,7 @@ static void x264_intra_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_thresh )
  72.      else
  73.          a->i_satd_i16x16 = COST_MAX;
  74.  
  75. -    if( a->i_satd_i4x4 <= i_satd_thresh && a->i_satd_i4x4 < COST_MAX )
  76. +    if( a->i_satd_i4x4 < i_satd_thresh && a->i_satd_i4x4 < COST_MAX )
  77.      {
  78.          h->mb.i_type = I_4x4;
  79.          x264_analyse_update_cache( h, a );
  80. @@ -1051,7 +1054,7 @@ static void x264_intra_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_thresh )
  81.      else
  82.          a->i_satd_i4x4 = COST_MAX;
  83.  
  84. -    if( a->i_satd_i8x8 <= i_satd_thresh && a->i_satd_i8x8 < COST_MAX )
  85. +    if( a->i_satd_i8x8 < i_satd_thresh && a->i_satd_i8x8 < COST_MAX )
  86.      {
  87.          h->mb.i_type = I_8x8;
  88.          x264_analyse_update_cache( h, a );
  89. @@ -1572,7 +1575,7 @@ static void x264_mb_analyse_inter_p16x8( x264_t *h, x264_mb_analysis_t *a, int i
  90.  
  91.          /* Early termination based on the current SATD score of partition[0]
  92.             plus the estimated SATD score of partition[1] */
  93. -        if( !i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
  94. +        if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est16x8[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
  95.          {
  96.              a->l0.i_cost16x8 = COST_MAX;
  97.              return;
  98. @@ -1637,7 +1640,7 @@ static void x264_mb_analyse_inter_p8x16( x264_t *h, x264_mb_analysis_t *a, int i
  99.  
  100.          /* Early termination based on the current SATD score of partition[0]
  101.             plus the estimated SATD score of partition[1] */
  102. -        if( !i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4 )
  103. +        if( a->b_early_terminate && (!i && l0m->cost + a->i_cost_est8x16[1] > i_best_satd * (4 + !!a->i_mbrd) / 4) )
  104.          {
  105.              a->l0.i_cost8x16 = COST_MAX;
  106.              return;
  107. @@ -2454,8 +2457,8 @@ static void x264_mb_analyse_inter_b16x8( x264_t *h, x264_mb_analysis_t *a, int i
  108.  
  109.          /* Early termination based on the current SATD score of partition[0]
  110.             plus the estimated SATD score of partition[1] */
  111. -        if( !i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
  112. -            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
  113. +        if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est16x8[1] > i_best_satd
  114. +            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
  115.          {
  116.              a->i_cost16x8bi = COST_MAX;
  117.              return;
  118. @@ -2547,8 +2550,8 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
  119.  
  120.          /* Early termination based on the current SATD score of partition[0]
  121.             plus the estimated SATD score of partition[1] */
  122. -        if( !i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
  123. -            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16 )
  124. +        if( a->b_early_terminate && (!i && i_part_cost + a->i_cost_est8x16[1] > i_best_satd
  125. +            * (16 + (!!a->i_mbrd + !!h->mb.i_psy_rd))/16) )
  126.          {
  127.              a->i_cost8x16bi = COST_MAX;
  128.              return;
  129. @@ -2566,17 +2569,17 @@ static void x264_mb_analyse_inter_b8x16( x264_t *h, x264_mb_analysis_t *a, int i
  130.  
  131.  static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  132.  {
  133. -    int thresh = i_satd * 5/4;
  134. +    int thresh = a->b_early_terminate ? COST_MAX : i_satd * 5/4;
  135.  
  136.      h->mb.i_type = P_L0;
  137. -    if( a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2 )
  138. +    if( !a->b_early_terminate || (a->l0.i_rd16x16 == COST_MAX && a->l0.me16x16.cost <= i_satd * 3/2) )
  139.      {
  140.          h->mb.i_partition = D_16x16;
  141.          x264_analyse_update_cache( h, a );
  142.          a->l0.i_rd16x16 = x264_rd_cost_mb( h, a->i_lambda2 );
  143.      }
  144.  
  145. -    if( a->l0.i_cost16x8 <= thresh )
  146. +    if( a->l0.i_cost16x8 < thresh )
  147.      {
  148.          h->mb.i_partition = D_16x8;
  149.          x264_analyse_update_cache( h, a );
  150. @@ -2585,7 +2588,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  151.      else
  152.          a->l0.i_cost16x8 = COST_MAX;
  153.  
  154. -    if( a->l0.i_cost8x16 <= thresh )
  155. +    if( a->l0.i_cost8x16 < thresh )
  156.      {
  157.          h->mb.i_partition = D_8x16;
  158.          x264_analyse_update_cache( h, a );
  159. @@ -2594,7 +2597,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  160.      else
  161.          a->l0.i_cost8x16 = COST_MAX;
  162.  
  163. -    if( a->l0.i_cost8x8 <= thresh )
  164. +    if( a->l0.i_cost8x8 < thresh )
  165.      {
  166.          h->mb.i_type = P_8x8;
  167.          h->mb.i_partition = D_8x8;
  168. @@ -2639,7 +2642,7 @@ static void x264_mb_analyse_p_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd )
  169.  
  170.  static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_inter )
  171.  {
  172. -    int thresh = i_satd_inter * (17 + (!!h->mb.i_psy_rd))/16;
  173. +    int thresh = !a->b_early_terminate ? COST_MAX : i_satd_inter * (17 + (!!h->mb.i_psy_rd))/16;
  174.  
  175.      if( a->b_direct_available && a->i_rd16x16direct == COST_MAX )
  176.      {
  177. @@ -2655,7 +2658,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  178.      //FIXME not all the update_cache calls are needed
  179.      h->mb.i_partition = D_16x16;
  180.      /* L0 */
  181. -    if( a->l0.me16x16.cost <= thresh && a->l0.i_rd16x16 == COST_MAX )
  182. +    if( a->l0.me16x16.cost < thresh && a->l0.i_rd16x16 == COST_MAX )
  183.      {
  184.          h->mb.i_type = B_L0_L0;
  185.          x264_analyse_update_cache( h, a );
  186. @@ -2663,7 +2666,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  187.      }
  188.  
  189.      /* L1 */
  190. -    if( a->l1.me16x16.cost <= thresh && a->l1.i_rd16x16 == COST_MAX )
  191. +    if( a->l1.me16x16.cost < thresh && a->l1.i_rd16x16 == COST_MAX )
  192.      {
  193.          h->mb.i_type = B_L1_L1;
  194.          x264_analyse_update_cache( h, a );
  195. @@ -2671,7 +2674,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  196.      }
  197.  
  198.      /* BI */
  199. -    if( a->i_cost16x16bi <= thresh && a->i_rd16x16bi == COST_MAX )
  200. +    if( a->i_cost16x16bi < thresh && a->i_rd16x16bi == COST_MAX )
  201.      {
  202.          h->mb.i_type = B_BI_BI;
  203.          x264_analyse_update_cache( h, a );
  204. @@ -2679,7 +2682,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  205.      }
  206.  
  207.      /* 8x8 */
  208. -    if( a->i_cost8x8bi <= thresh && a->i_rd8x8bi == COST_MAX )
  209. +    if( a->i_cost8x8bi < thresh && a->i_rd8x8bi == COST_MAX )
  210.      {
  211.          h->mb.i_type = B_8x8;
  212.          h->mb.i_partition = D_8x8;
  213. @@ -2689,7 +2692,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  214.      }
  215.  
  216.      /* 16x8 */
  217. -    if( a->i_cost16x8bi <= thresh && a->i_rd16x8bi == COST_MAX )
  218. +    if( a->i_cost16x8bi < thresh && a->i_rd16x8bi == COST_MAX )
  219.      {
  220.          h->mb.i_type = a->i_mb_type16x8;
  221.          h->mb.i_partition = D_16x8;
  222. @@ -2698,7 +2701,7 @@ static void x264_mb_analyse_b_rd( x264_t *h, x264_mb_analysis_t *a, int i_satd_i
  223.      }
  224.  
  225.      /* 8x16 */
  226. -    if( a->i_cost8x16bi <= thresh && a->i_rd8x16bi == COST_MAX )
  227. +    if( a->i_cost8x16bi < thresh && a->i_rd8x16bi == COST_MAX )
  228.      {
  229.          h->mb.i_type = a->i_mb_type8x16;
  230.          h->mb.i_partition = D_8x16;
  231. @@ -3020,8 +3023,8 @@ intra_analysis:
  232.              i_partition = D_16x16;
  233.              i_cost = analysis.l0.me16x16.cost;
  234.  
  235. -            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
  236. -                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost )
  237. +            if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
  238. +                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost) )
  239.              {
  240.                  i_type = P_8x8;
  241.                  i_partition = D_8x8;
  242. @@ -3056,8 +3059,8 @@ intra_analysis:
  243.  
  244.              /* Now do 16x8/8x16 */
  245.              i_thresh16x8 = analysis.l0.me8x8[1].cost_mv + analysis.l0.me8x8[2].cost_mv;
  246. -            if( ( flags & X264_ANALYSE_PSUB16x16 ) &&
  247. -                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8 )
  248. +            if( ( flags & X264_ANALYSE_PSUB16x16 ) && (!analysis.b_early_terminate ||
  249. +                analysis.l0.i_cost8x8 < analysis.l0.me16x16.cost + i_thresh16x8) )
  250.              {
  251.                  int i_avg_mv_ref_cost = (analysis.l0.me8x8[2].cost_mv + analysis.l0.me8x8[2].i_ref_cost
  252.                                        + analysis.l0.me8x8[3].cost_mv + analysis.l0.me8x8[3].i_ref_cost + 1) >> 1;
  253. @@ -3177,7 +3180,7 @@ intra_analysis:
  254.                  h->mb.i_partition = i_partition;
  255.                  if( i_cost < COST_MAX )
  256.                      x264_mb_analyse_transform_rd( h, &analysis, &i_satd_inter, &i_cost );
  257. -                x264_intra_rd( h, &analysis, i_satd_inter * 5/4 );
  258. +                x264_intra_rd( h, &analysis, analysis.b_early_terminate ? i_satd_inter * 5/4 : COST_MAX );
  259.              }
  260.  
  261.              COPY2_IF_LT( i_cost, analysis.i_satd_i16x16, i_type, I_16x16 );
  262. @@ -3431,17 +3434,17 @@ intra_analysis:
  263.  
  264.                  /* We can gain a little speed by checking the mode with the lowest estimated cost first */
  265.                  int try_16x8_first = i_cost_est16x8bi_total < i_cost_est8x16bi_total;
  266. -                if( try_16x8_first && i_cost_est16x8bi_total < i_cost )
  267. +                if( !analysis.b_early_terminate || (try_16x8_first && i_cost_est16x8bi_total < i_cost) )
  268.                  {
  269.                      x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
  270.                      COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
  271.                  }
  272. -                if( i_cost_est8x16bi_total < i_cost )
  273. +                if( !analysis.b_early_terminate || (i_cost_est8x16bi_total < i_cost) )
  274.                  {
  275.                      x264_mb_analyse_inter_b8x16( h, &analysis, i_cost );
  276.                      COPY3_IF_LT( i_cost, analysis.i_cost8x16bi, i_type, analysis.i_mb_type8x16, i_partition, D_8x16 );
  277.                  }
  278. -                if( !try_16x8_first && i_cost_est16x8bi_total < i_cost )
  279. +                if( analysis.b_early_terminate && (!try_16x8_first && i_cost_est16x8bi_total < i_cost) )
  280.                  {
  281.                      x264_mb_analyse_inter_b16x8( h, &analysis, i_cost );
  282.                      COPY3_IF_LT( i_cost, analysis.i_cost16x8bi, i_type, analysis.i_mb_type16x8, i_partition, D_16x8 );
  283. @@ -3573,7 +3576,7 @@ intra_analysis:
  284.              if( analysis.i_mbrd )
  285.              {
  286.                  x264_mb_analyse_transform_rd( h, &analysis, &i_satd_inter, &i_cost );
  287. -                x264_intra_rd( h, &analysis, i_satd_inter * 17/16 );
  288. +                x264_intra_rd( h, &analysis, analysis.b_early_terminate ? i_satd_inter * 17/16 : COST_MAX );
  289.              }
  290.  
  291.              COPY2_IF_LT( i_cost, analysis.i_satd_i16x16, i_type, I_16x16 );
  292. diff --git a/encoder/encoder.c b/encoder/encoder.c
  293. index 85ad046..9c63859 100644
  294. --- a/encoder/encoder.c
  295. +++ b/encoder/encoder.c
  296. @@ -503,7 +503,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
  297.      h->param.rc.f_rf_constant = x264_clip3f( h->param.rc.f_rf_constant, -QP_BD_OFFSET, 51 );
  298.      h->param.rc.f_rf_constant_max = x264_clip3f( h->param.rc.f_rf_constant_max, -QP_BD_OFFSET, 51 );
  299.      h->param.rc.i_qp_constant = x264_clip3( h->param.rc.i_qp_constant, 0, QP_MAX );
  300. -    h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 10 );
  301. +    h->param.analyse.i_subpel_refine = x264_clip3( h->param.analyse.i_subpel_refine, 0, 11 );
  302.      h->param.rc.f_ip_factor = X264_MAX( h->param.rc.f_ip_factor, 0.01f );
  303.      h->param.rc.f_pb_factor = X264_MAX( h->param.rc.f_pb_factor, 0.01f );
  304.      if( h->param.rc.i_rc_method == X264_RC_CRF )
  305. @@ -784,7 +784,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
  306.          h->param.rc.f_aq_strength = 0;
  307.      }
  308.      h->param.analyse.i_noise_reduction = x264_clip3( h->param.analyse.i_noise_reduction, 0, 1<<16 );
  309. -    if( h->param.analyse.i_subpel_refine == 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
  310. +    if( h->param.analyse.i_subpel_refine >= 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
  311.          h->param.analyse.i_subpel_refine = 9;
  312.  
  313.      {
  314. diff --git a/encoder/me.c b/encoder/me.c
  315. index ca6c602..10b7ef2 100644
  316. --- a/encoder/me.c
  317. +++ b/encoder/me.c
  318. @@ -46,6 +46,7 @@ static const uint8_t subpel_iterations[][4] =
  319.      {0,0,2,2},
  320.      {0,0,4,10},
  321.      {0,0,4,10},
  322. +    {0,0,4,10},
  323.      {0,0,4,10}};
  324.  
  325.  /* (x-1)%6 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement