av1/encoder/motion_search_facade.c
// Search for the best mv for one component of a compound,
// given that the other component is fixed.
Search for the best mv for one component of a compound,
given that the other component is fixed.
Search for the best mv for one component of a compound given that the other component is fixed .
void av1_compound_single_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
                                       BLOCK_SIZE bsize, MV *this_mv,
                                       const uint8_t *second_pred,
                                       const uint8_t *mask, int mask_stride,
                                       int *rate_mv, int ref_idx) {
  const AV1_COMMON *const cm = &cpi->common;
  const int num_planes = av1_num_planes(cm);
  MACROBLOCKD *xd = &x->e_mbd;
  MB_MODE_INFO *mbmi = xd->mi[0];
  const int ref = mbmi->ref_frame[ref_idx];
  const int_mv ref_mv = av1_get_ref_mv(x, ref_idx);
  struct macroblockd_plane *const pd = &xd->plane[0];
  struct buf_2d backup_yv12[MAX_MB_PLANE];
  const YV12_BUFFER_CONFIG *const scaled_ref_frame =
      av1_get_scaled_ref_frame(cpi, ref);
  assert(has_second_ref(mbmi) || (ref_idx == 0 && is_interintra_mode(mbmi)));
  struct buf_2d orig_yv12;
  struct buf_2d ref_yv12 = pd->pre[ref_idx];
  if (ref_idx) {
    orig_yv12 = pd->pre[0];
    pd->pre[0] = pd->pre[ref_idx];
  }
  if (scaled_ref_frame) {
    for (int i = 0; i < num_planes; i++) {
      backup_yv12[i] = xd->plane[i].pre[ref_idx];
    }
    const int mi_row = xd->mi_row;
    const int mi_col = xd->mi_col;
    av1_setup_pre_planes(xd, ref_idx, scaled_ref_frame, mi_row, mi_col, NULL,
                         num_planes);
  }
  int bestsme = INT_MAX;
  int sadpb = x->sadperbit;
  int_mv *best_int_mv = &x->best_mv;
  int search_range = SEARCH_RANGE_8P;
  FullMvLimits tmp_mv_limits = x->mv_limits;
  av1_set_mv_search_range(&x->mv_limits, &ref_mv.as_mv);
  best_int_mv->as_fullmv = get_fullmv_from_mv(this_mv);
  bestsme = av1_refining_search_8p_c(
      x, sadpb, search_range, &cpi->fn_ptr[bsize], mask, mask_stride, ref_idx,
      &ref_mv.as_mv, second_pred, &x->plane[0].src, &ref_yv12);
  if (bestsme < INT_MAX) {
    if (mask)
      bestsme = av1_get_mvpred_mask_var(
          x, &best_int_mv->as_fullmv, &ref_mv.as_mv, second_pred, mask,
          mask_stride, ref_idx, &cpi->fn_ptr[bsize], &x->plane[0].src,
          &ref_yv12);
    else
      bestsme = av1_get_mvpred_av_var(x, &best_int_mv->as_fullmv, &ref_mv.as_mv,
                                      second_pred, &cpi->fn_ptr[bsize],
                                      &x->plane[0].src, &ref_yv12);
  }
  x->mv_limits = tmp_mv_limits;
  if (scaled_ref_frame) {
    for (int i = 0; i < num_planes; i++) {
      xd->plane[i].pre[ref_idx] = backup_yv12[i];
    }
  }
  if (cpi->common.cur_frame_force_integer_mv) {
    convert_fullmv_to_mv(best_int_mv);
  }
  const int use_fractional_mv =
      bestsme < INT_MAX && cpi->common.cur_frame_force_integer_mv == 0;
  if (use_fractional_mv) {
    int dis; 
    unsigned int sse;
    SUBPEL_MOTION_SEARCH_PARAMS ms_params;
    av1_make_default_subpel_ms_params(&ms_params, cpi, x, bsize, &ref_mv.as_mv,
                                      NULL, second_pred, mask, mask_stride,
                                      ref_idx, 1);
    ms_params.forced_stop = EIGHTH_PEL;
    bestsme = cpi->find_fractional_mv_step(x, cm, &ms_params, &dis, &sse);
  }
  if (ref_idx) pd->pre[0] = orig_yv12;
  if (bestsme < INT_MAX) *this_mv = best_int_mv->as_mv;
  *rate_mv = 0;
  *rate_mv += av1_mv_bit_cost(this_mv, &ref_mv.as_mv, x->nmv_vec_cost,
                              x->mv_cost_stack, MV_COST_WEIGHT);
}
void av1_compound_single_motion_search ( const AV1_COMP * cpi , MACROBLOCK * x , BLOCK_SIZE bsize , MV * this_mv , const uint8_t * second_pred , const uint8_t * mask , int mask_stride , int * rate_mv , int ref_idx ) { const AV1_COMMON * const cm = & cpi -> common ; const int num_planes = av1_num_planes ( cm ) ; MACROBLOCKD * xd = & x -> e_mbd ; MB_MODE_INFO * mbmi = xd -> mi [ 0 ] ; const int ref = mbmi -> ref_frame [ ref_idx ] ; const int_mv ref_mv = av1_get_ref_mv ( x , ref_idx ) ; struct macroblockd_plane * const pd = & xd -> plane [ 0 ] ; struct buf_2d backup_yv12 [ MAX_MB_PLANE ] ; const YV12_BUFFER_CONFIG * const scaled_ref_frame = av1_get_scaled_ref_frame ( cpi , ref ) ; assert ( has_second_ref ( mbmi ) || ( ref_idx == 0 && is_interintra_mode ( mbmi ) ) ) ; struct buf_2d orig_yv12 ; struct buf_2d ref_yv12 = pd -> pre [ ref_idx ] ; if ( ref_idx ) { orig_yv12 = pd -> pre [ 0 ] ; pd -> pre [ 0 ] = pd -> pre [ ref_idx ] ; } if ( scaled_ref_frame ) { for ( int i = 0 ; i < num_planes ; i ++ ) { backup_yv12 [ i ] = xd -> plane [ i ] . pre [ ref_idx ] ; } const int mi_row = xd -> mi_row ; const int mi_col = xd -> mi_col ; av1_setup_pre_planes ( xd , ref_idx , scaled_ref_frame , mi_row , mi_col , NULL , num_planes ) ; } int bestsme = INT_MAX ; int sadpb = x -> sadperbit ; int_mv * best_int_mv = & x -> best_mv ; int search_range = SEARCH_RANGE_8P ; FullMvLimits tmp_mv_limits = x -> mv_limits ; av1_set_mv_search_range ( & x -> mv_limits , & ref_mv . as_mv ) ; best_int_mv -> as_fullmv = get_fullmv_from_mv ( this_mv ) ; bestsme = av1_refining_search_8p_c ( x , sadpb , search_range , & cpi -> fn_ptr [ bsize ] , mask , mask_stride , ref_idx , & ref_mv . as_mv , second_pred , & x -> plane [ 0 ] . src , & ref_yv12 ) ; if ( bestsme < INT_MAX ) { if ( mask ) bestsme = av1_get_mvpred_mask_var ( x , & best_int_mv -> as_fullmv , & ref_mv . as_mv , second_pred , mask , mask_stride , ref_idx , & cpi -> fn_ptr [ bsize ] , & x -> plane [ 0 ] . src , & ref_yv12 ) ; else bestsme = av1_get_mvpred_av_var ( x , & best_int_mv -> as_fullmv , & ref_mv . as_mv , second_pred , & cpi -> fn_ptr [ bsize ] , & x -> plane [ 0 ] . src , & ref_yv12 ) ; } x -> mv_limits = tmp_mv_limits ; if ( scaled_ref_frame ) { for ( int i = 0 ; i < num_planes ; i ++ ) { xd -> plane [ i ] . pre [ ref_idx ] = backup_yv12 [ i ] ; } } if ( cpi -> common . cur_frame_force_integer_mv ) { convert_fullmv_to_mv ( best_int_mv ) ; } const int use_fractional_mv = bestsme < INT_MAX && cpi -> common . cur_frame_force_integer_mv == 0 ; if ( use_fractional_mv ) { int dis ; unsigned int sse ; SUBPEL_MOTION_SEARCH_PARAMS ms_params ; av1_make_default_subpel_ms_params ( & ms_params , cpi , x , bsize , & ref_mv . as_mv , NULL , second_pred , mask , mask_stride , ref_idx , 1 ) ; ms_params . forced_stop = EIGHTH_PEL ; bestsme = cpi -> find_fractional_mv_step ( x , cm , & ms_params , & dis , & sse ) ; } if ( ref_idx ) pd -> pre [ 0 ] = orig_yv12 ; if ( bestsme < INT_MAX ) * this_mv = best_int_mv -> as_mv ; * rate_mv = 0 ; * rate_mv += av1_mv_bit_cost ( this_mv , & ref_mv . as_mv , x -> nmv_vec_cost , x -> mv_cost_stack , MV_COST_WEIGHT ) ; }
Search for the best mv for one component of a compound,
given that the other component is fixed.
Search for the best mv for one component of a compound given that the other component is fixed .
// Check that this is either an interinter or an interintra block // Store the first prediction buffer. // Swap out the reference frame for a version that's been scaled to // match the resolution of the current frame, allowing the existing // full-pixel motion search code to be used without additional // modifications. // Do compound motion search on the current reference frame. // Use the mv result from the single mode as mv predictor. // Small-range full-pixel motion search. // Swap back the original buffers for subpel motion search. /* TODO: use dis in distortion calculation later. */ // Restore the pointer to the first unscaled prediction buffer.