av1/encoder/mcomp.c
// This function is called when we do joint motion search in comp_inter_inter
// mode, or when searching for one component of an ext-inter compound mode.
This function is called when we do joint motion search in comp_inter_inter
mode, or when searching for one component of an ext-inter compound mode.
This function is called when we do joint motion search in comp_inter_inter mode or when searching for one component of an ext - inter compound mode .
int av1_refining_search_8p_c(MACROBLOCK *x, int error_per_bit, int search_range,
                             const aom_variance_fn_ptr_t *fn_ptr,
                             const uint8_t *mask, int mask_stride,
                             int invert_mask, const MV *ref_mv,
                             const uint8_t *second_pred,
                             const struct buf_2d *src,
                             const struct buf_2d *pre) {
  static const search_neighbors neighbors[8] = {
    { { -1, 0 }, -1 * SEARCH_GRID_STRIDE_8P + 0 },
    { { 0, -1 }, 0 * SEARCH_GRID_STRIDE_8P - 1 },
    { { 0, 1 }, 0 * SEARCH_GRID_STRIDE_8P + 1 },
    { { 1, 0 }, 1 * SEARCH_GRID_STRIDE_8P + 0 },
    { { -1, -1 }, -1 * SEARCH_GRID_STRIDE_8P - 1 },
    { { 1, -1 }, 1 * SEARCH_GRID_STRIDE_8P - 1 },
    { { -1, 1 }, -1 * SEARCH_GRID_STRIDE_8P + 1 },
    { { 1, 1 }, 1 * SEARCH_GRID_STRIDE_8P + 1 }
  };
  const struct buf_2d *const what = src;
  const struct buf_2d *const in_what = pre;
  const FULLPEL_MV full_ref_mv = get_fullmv_from_mv(ref_mv);
  FULLPEL_MV *best_mv = &x->best_mv.as_fullmv;
  unsigned int best_sad = INT_MAX;
  int i, j;
  uint8_t do_refine_search_grid[SEARCH_GRID_STRIDE_8P *
                                SEARCH_GRID_STRIDE_8P] = { 0 };
  int grid_center = SEARCH_GRID_CENTER_8P;
  int grid_coord = grid_center;
  clamp_fullmv(best_mv, &x->mv_limits);
  if (mask) {
    best_sad = fn_ptr->msdf(what->buf, what->stride,
                            get_buf_from_mv(in_what, best_mv), in_what->stride,
                            second_pred, mask, mask_stride, invert_mask) +
               mvsad_err_cost(x, best_mv, &full_ref_mv, error_per_bit);
  } else {
    best_sad =
        fn_ptr->sdaf(what->buf, what->stride, get_buf_from_mv(in_what, best_mv),
                     in_what->stride, second_pred) +
        mvsad_err_cost(x, best_mv, &full_ref_mv, error_per_bit);
  }
  do_refine_search_grid[grid_coord] = 1;
  for (i = 0; i < search_range; ++i) {
    int best_site = -1;
    for (j = 0; j < 8; ++j) {
      grid_coord = grid_center + neighbors[j].coord_offset;
      if (do_refine_search_grid[grid_coord] == 1) {
        continue;
      }
      const FULLPEL_MV mv = { best_mv->row + neighbors[j].coord.row,
                              best_mv->col + neighbors[j].coord.col };
      do_refine_search_grid[grid_coord] = 1;
      if (av1_is_fullmv_in_range(&x->mv_limits, mv)) {
        unsigned int sad;
        if (mask) {
          sad = fn_ptr->msdf(what->buf, what->stride,
                             get_buf_from_mv(in_what, &mv), in_what->stride,
                             second_pred, mask, mask_stride, invert_mask);
        } else {
          sad = fn_ptr->sdaf(what->buf, what->stride,
                             get_buf_from_mv(in_what, &mv), in_what->stride,
                             second_pred);
        }
        if (sad < best_sad) {
          sad += mvsad_err_cost(x, &mv, &full_ref_mv, error_per_bit);
          if (sad < best_sad) {
            best_sad = sad;
            best_site = j;
          }
        }
      }
    }
    if (best_site == -1) {
      break;
    } else {
      best_mv->row += neighbors[best_site].coord.row;
      best_mv->col += neighbors[best_site].coord.col;
      grid_center += neighbors[best_site].coord_offset;
    }
  }
  return best_sad;
}
int av1_refining_search_8p_c ( MACROBLOCK * x , int error_per_bit , int search_range , const aom_variance_fn_ptr_t * fn_ptr , const uint8_t * mask , int mask_stride , int invert_mask , const MV * ref_mv , const uint8_t * second_pred , const struct buf_2d * src , const struct buf_2d * pre ) { static const search_neighbors neighbors [ 8 ] = { { { -1 , 0 } , -1 * SEARCH_GRID_STRIDE_8P + 0 } , { { 0 , -1 } , 0 * SEARCH_GRID_STRIDE_8P - 1 } , { { 0 , 1 } , 0 * SEARCH_GRID_STRIDE_8P + 1 } , { { 1 , 0 } , 1 * SEARCH_GRID_STRIDE_8P + 0 } , { { -1 , -1 } , -1 * SEARCH_GRID_STRIDE_8P - 1 } , { { 1 , -1 } , 1 * SEARCH_GRID_STRIDE_8P - 1 } , { { -1 , 1 } , -1 * SEARCH_GRID_STRIDE_8P + 1 } , { { 1 , 1 } , 1 * SEARCH_GRID_STRIDE_8P + 1 } } ; const struct buf_2d * const what = src ; const struct buf_2d * const in_what = pre ; const FULLPEL_MV full_ref_mv = get_fullmv_from_mv ( ref_mv ) ; FULLPEL_MV * best_mv = & x -> best_mv . as_fullmv ; unsigned int best_sad = INT_MAX ; int i , j ; uint8_t do_refine_search_grid [ SEARCH_GRID_STRIDE_8P * SEARCH_GRID_STRIDE_8P ] = { 0 } ; int grid_center = SEARCH_GRID_CENTER_8P ; int grid_coord = grid_center ; clamp_fullmv ( best_mv , & x -> mv_limits ) ; if ( mask ) { best_sad = fn_ptr -> msdf ( what -> buf , what -> stride , get_buf_from_mv ( in_what , best_mv ) , in_what -> stride , second_pred , mask , mask_stride , invert_mask ) + mvsad_err_cost ( x , best_mv , & full_ref_mv , error_per_bit ) ; } else { best_sad = fn_ptr -> sdaf ( what -> buf , what -> stride , get_buf_from_mv ( in_what , best_mv ) , in_what -> stride , second_pred ) + mvsad_err_cost ( x , best_mv , & full_ref_mv , error_per_bit ) ; } do_refine_search_grid [ grid_coord ] = 1 ; for ( i = 0 ; i < search_range ; ++ i ) { int best_site = -1 ; for ( j = 0 ; j < 8 ; ++ j ) { grid_coord = grid_center + neighbors [ j ] . coord_offset ; if ( do_refine_search_grid [ grid_coord ] == 1 ) { continue ; } const FULLPEL_MV mv = { best_mv -> row + neighbors [ j ] . coord . row , best_mv -> col + neighbors [ j ] . coord . col } ; do_refine_search_grid [ grid_coord ] = 1 ; if ( av1_is_fullmv_in_range ( & x -> mv_limits , mv ) ) { unsigned int sad ; if ( mask ) { sad = fn_ptr -> msdf ( what -> buf , what -> stride , get_buf_from_mv ( in_what , & mv ) , in_what -> stride , second_pred , mask , mask_stride , invert_mask ) ; } else { sad = fn_ptr -> sdaf ( what -> buf , what -> stride , get_buf_from_mv ( in_what , & mv ) , in_what -> stride , second_pred ) ; } if ( sad < best_sad ) { sad += mvsad_err_cost ( x , & mv , & full_ref_mv , error_per_bit ) ; if ( sad < best_sad ) { best_sad = sad ; best_site = j ; } } } } if ( best_site == -1 ) { break ; } else { best_mv -> row += neighbors [ best_site ] . coord . row ; best_mv -> col += neighbors [ best_site ] . coord . col ; grid_center += neighbors [ best_site ] . coord_offset ; } } return best_sad ; }
This function is called when we do joint motion search in comp_inter_inter
mode, or when searching for one component of an ext-inter compound mode.
This function is called when we do joint motion search in comp_inter_inter mode or when searching for one component of an ext - inter compound mode .