av1/encoder/mcomp.c
/* do_refine: If last step (1-away) of n-step search doesn't pick the center
              point as the best match, we will do a final 1-away diamond
              refining search  */
If last step (1-away) of n-step search doesn't pick the center
point as the best match, we will do a final 1-away diamond
refining search
If last step ( 1 - away ) of n - step search doesn ' t pick the center point as the best match we will do a final 1 - away diamond refining search
static int full_pixel_diamond(const MACROBLOCK *x, const FULLPEL_MV start_mv,
                              int step_param, int sadpb, int *cost_list,
                              const aom_variance_fn_ptr_t *fn_ptr,
                              const MV *ref_mv, const search_site_config *cfg,
                              uint8_t *second_pred, uint8_t *mask,
                              int mask_stride, int inv_mask,
                              FULLPEL_MV *best_mv, FULLPEL_MV *second_best_mv) {
  int thissme, n, num00 = 0;
  int bestsme = diamond_search_sad(x, cfg, start_mv, best_mv, second_best_mv,
                                   step_param, sadpb, &n, fn_ptr, ref_mv,
                                   second_pred, mask, mask_stride, inv_mask);
  if (bestsme < INT_MAX) {
    if (mask)
      bestsme = av1_get_mvpred_mask_var(
          x, best_mv, ref_mv, second_pred, mask, mask_stride, inv_mask, fn_ptr,
          &x->plane[0].src, &x->e_mbd.plane[0].pre[0]);
    else if (second_pred)
      bestsme =
          av1_get_mvpred_av_var(x, best_mv, ref_mv, second_pred, fn_ptr,
                                &x->plane[0].src, &x->e_mbd.plane[0].pre[0]);
    else
      bestsme = av1_get_mvpred_var(x, best_mv, ref_mv, fn_ptr);
  }
  const int further_steps = cfg->ss_count - 1 - step_param;
  while (n < further_steps) {
    ++n;
    FULLPEL_MV tmp_best_mv;
    if (num00) {
      num00--;
    } else {
      thissme = diamond_search_sad(
          x, cfg, start_mv, &tmp_best_mv, second_best_mv, step_param + n, sadpb,
          &num00, fn_ptr, ref_mv, second_pred, mask, mask_stride, inv_mask);
      if (thissme < INT_MAX) {
        if (mask)
          thissme = av1_get_mvpred_mask_var(
              x, &tmp_best_mv, ref_mv, second_pred, mask, mask_stride, inv_mask,
              fn_ptr, &x->plane[0].src, &x->e_mbd.plane[0].pre[0]);
        else if (second_pred)
          thissme = av1_get_mvpred_av_var(x, &tmp_best_mv, ref_mv, second_pred,
                                          fn_ptr, &x->plane[0].src,
                                          &x->e_mbd.plane[0].pre[0]);
        else
          thissme = av1_get_mvpred_var(x, &tmp_best_mv, ref_mv, fn_ptr);
      }
      if (thissme < bestsme) {
        bestsme = thissme;
        *best_mv = tmp_best_mv;
      }
    }
  }
  if (cost_list) {
    if (USE_SAD_COSTLIST) {
      const int costlist_has_sad = 0;
      calc_int_sad_list(x, ref_mv, sadpb, fn_ptr, &x->best_mv.as_fullmv,
                        cost_list, costlist_has_sad);
    } else {
      calc_int_cost_list(x, ref_mv, fn_ptr, &x->best_mv.as_fullmv, cost_list);
    }
  }
  return bestsme;
}
static int full_pixel_diamond ( const MACROBLOCK * x , const FULLPEL_MV start_mv , int step_param , int sadpb , int * cost_list , const aom_variance_fn_ptr_t * fn_ptr , const MV * ref_mv , const search_site_config * cfg , uint8_t * second_pred , uint8_t * mask , int mask_stride , int inv_mask , FULLPEL_MV * best_mv , FULLPEL_MV * second_best_mv ) { int thissme , n , num00 = 0 ; int bestsme = diamond_search_sad ( x , cfg , start_mv , best_mv , second_best_mv , step_param , sadpb , & n , fn_ptr , ref_mv , second_pred , mask , mask_stride , inv_mask ) ; if ( bestsme < INT_MAX ) { if ( mask ) bestsme = av1_get_mvpred_mask_var ( x , best_mv , ref_mv , second_pred , mask , mask_stride , inv_mask , fn_ptr , & x -> plane [ 0 ] . src , & x -> e_mbd . plane [ 0 ] . pre [ 0 ] ) ; else if ( second_pred ) bestsme = av1_get_mvpred_av_var ( x , best_mv , ref_mv , second_pred , fn_ptr , & x -> plane [ 0 ] . src , & x -> e_mbd . plane [ 0 ] . pre [ 0 ] ) ; else bestsme = av1_get_mvpred_var ( x , best_mv , ref_mv , fn_ptr ) ; } const int further_steps = cfg -> ss_count - 1 - step_param ; while ( n < further_steps ) { ++ n ; FULLPEL_MV tmp_best_mv ; if ( num00 ) { num00 -- ; } else { thissme = diamond_search_sad ( x , cfg , start_mv , & tmp_best_mv , second_best_mv , step_param + n , sadpb , & num00 , fn_ptr , ref_mv , second_pred , mask , mask_stride , inv_mask ) ; if ( thissme < INT_MAX ) { if ( mask ) thissme = av1_get_mvpred_mask_var ( x , & tmp_best_mv , ref_mv , second_pred , mask , mask_stride , inv_mask , fn_ptr , & x -> plane [ 0 ] . src , & x -> e_mbd . plane [ 0 ] . pre [ 0 ] ) ; else if ( second_pred ) thissme = av1_get_mvpred_av_var ( x , & tmp_best_mv , ref_mv , second_pred , fn_ptr , & x -> plane [ 0 ] . src , & x -> e_mbd . plane [ 0 ] . pre [ 0 ] ) ; else thissme = av1_get_mvpred_var ( x , & tmp_best_mv , ref_mv , fn_ptr ) ; } if ( thissme < bestsme ) { bestsme = thissme ; * best_mv = tmp_best_mv ; } } } if ( cost_list ) { if ( USE_SAD_COSTLIST ) { const int costlist_has_sad = 0 ; calc_int_sad_list ( x , ref_mv , sadpb , fn_ptr , & x -> best_mv . as_fullmv , cost_list , costlist_has_sad ) ; } else { calc_int_cost_list ( x , ref_mv , fn_ptr , & x -> best_mv . as_fullmv , cost_list ) ; } } return bestsme ; }
do_refine: If last step (1-away) of n-step search doesn't pick the center
point as the best match, we will do a final 1-away diamond
refining search
do_refine : If last step ( 1 - away ) of n - step search doesn ' t pick the center point as the best match we will do a final 1 - away diamond refining search
// If there won't be more n-step search, check to see if refining search is // needed. // TODO(chiyotsai@google.com): There is another bug here where the second // best mv gets incorrectly overwritten. Fix it later. // Return cost list.