AOMedia AV1 Codec
Inter Mode Search

Functions

int64_t av1_interpolation_filter_search (MACROBLOCK *const x, const AV1_COMP *const cpi, const TileDataEnc *tile_data, BLOCK_SIZE bsize, const BUFFER_SET *const tmp_dst, const BUFFER_SET *const orig_dst, int64_t *const rd, int *const switchable_rate, int *skip_build_pred, HandleInterModeArgs *args, int64_t ref_best_rd)
 AV1 interpolation filter search.
 
void av1_rd_pick_inter_mode (struct AV1_COMP *cpi, struct TileDataEnc *tile_data, struct macroblock *x, struct RD_STATS *rd_cost, BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, int64_t best_rd_so_far)
 AV1 inter mode selection.
 
static int64_t motion_mode_rd (const AV1_COMP *const cpi, TileDataEnc *tile_data, MACROBLOCK *const x, BLOCK_SIZE bsize, RD_STATS *rd_stats, RD_STATS *rd_stats_y, RD_STATS *rd_stats_uv, HandleInterModeArgs *const args, int64_t ref_best_rd, int64_t *ref_skip_rd, int *rate_mv, const BUFFER_SET *orig_dst, int64_t *best_est_rd, int do_tx_search, InterModesInfo *inter_modes_info, int eval_motion_mode, int64_t *yrd)
 AV1 motion mode search.
 
static int process_compound_inter_mode (AV1_COMP *const cpi, MACROBLOCK *x, HandleInterModeArgs *args, int64_t ref_best_rd, int_mv *cur_mv, BLOCK_SIZE bsize, int *compmode_interinter_cost, const CompoundTypeRdBuffers *rd_buffers, const BUFFER_SET *orig_dst, const BUFFER_SET *tmp_dst, int *rate_mv, RD_STATS *rd_stats, int64_t *skip_rd, int *skip_build_pred)
 High level function to select parameters for compound mode.
 
static int prune_zero_mv_with_sse (const aom_variance_fn_ptr_t *fn_ptr, const MACROBLOCK *x, BLOCK_SIZE bsize, const HandleInterModeArgs *args, int prune_zero_mv_with_sse)
 Prunes ZeroMV Search Using Best NEWMV's SSE.
 
static bool fast_interp_search (const AV1_COMP *cpi, MACROBLOCK *x, int mi_row, int mi_col, BLOCK_SIZE bsize)
 Searches for interpolation filter in realtime mode during winner eval.
 
static int64_t handle_inter_mode (AV1_COMP *const cpi, TileDataEnc *tile_data, MACROBLOCK *x, BLOCK_SIZE bsize, RD_STATS *rd_stats, RD_STATS *rd_stats_y, RD_STATS *rd_stats_uv, HandleInterModeArgs *args, int64_t ref_best_rd, uint8_t *const tmp_buf, const CompoundTypeRdBuffers *rd_buffers, int64_t *best_est_rd, const int do_tx_search, InterModesInfo *inter_modes_info, motion_mode_candidate *motion_mode_cand, int64_t *skip_rd, PruneInfoFromTpl *inter_cost_info_from_tpl, int64_t *yrd)
 AV1 inter mode RD computation.
 

Detailed Description

This module describes inter mode search algorithm in AV1. More details will be added.

Function Documentation

◆ av1_interpolation_filter_search()

int64_t av1_interpolation_filter_search ( MACROBLOCK *const x,
const AV1_COMP *const cpi,
const TileDataEnc * tile_data,
BLOCK_SIZE bsize,
const BUFFER_SET *const tmp_dst,
const BUFFER_SET *const orig_dst,
int64_t *const rd,
int *const switchable_rate,
int * skip_build_pred,
HandleInterModeArgs * args,
int64_t ref_best_rd )

AV1 interpolation filter search.

Parameters
[in]cpiTop-level encoder structure.
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding.
[in]xPointer to struc holding all the data for the current macroblock.
[in]bsizeCurrent block size.
[in]tmp_dstA temporary prediction buffer to hold a computed prediction.
[in,out]orig_dstA prediction buffer to hold a computed prediction. This will eventually hold the final prediction, and the tmp_dst info will be copied here.
[in,out]rdThe RD cost associated with the selected interpolation filter parameters.
[in,out]switchable_rateThe rate associated with using a SWITCHABLE filter mode.
[in,out]skip_build_predIndicates whether or not to build the inter predictor. If this is 0, the inter predictor has already been built and thus we can avoid repeating computation.
[in]argsHandleInterModeArgs struct holding miscellaneous arguments for inter mode search. See the documentation for this struct for a description of each member.
[in]ref_best_rdBest RD found so far for this block. It is used for early termination of this search if the RD exceeds this value.
Returns
Returns INT64_MAX if the filter parameters are invalid and the current motion mode being tested should be skipped. It returns 0 if the parameter search is a success.

< Y (Luminance) plane

< Y (Luminance) plane

< U (Chroma) plane

< V (Chroma) plane

< Y (Luminance) plane

< Y (Luminance) plane

References AOM_PLANE_U, AOM_PLANE_V, AOM_PLANE_Y, av1_pick_recursive_tx_size_type_yrd(), AV1_COMP::common, InterpSearchFlags::default_interp_skip_flags, macroblock::e_mbd, AV1Common::features, FeatureFlags::interp_filter, MB_MODE_INFO::interp_filters, AV1_COMP::interp_search_flags, SPEED_FEATURES::interp_sf, macroblockd::mi, macroblockd::mi_col, macroblockd::mi_row, MB_MODE_INFO::mode, macroblock::pred_sse, macroblock::rdmult, macroblock::recalc_luma_mc_data, MB_MODE_INFO::ref_frame, MB_MODE_INFO::ref_mv_idx, AV1Common::seq_params, and AV1_COMP::sf.

Referenced by handle_inter_mode().

◆ av1_rd_pick_inter_mode()

void av1_rd_pick_inter_mode ( struct AV1_COMP * cpi,
struct TileDataEnc * tile_data,
struct macroblock * x,
struct RD_STATS * rd_cost,
BLOCK_SIZE bsize,
PICK_MODE_CONTEXT * ctx,
int64_t best_rd_so_far )

AV1 inter mode selection.

Top level function for inter mode selection. This function will loop over all possible inter modes and select the best one for the current block by computing the RD cost. The mode search and RD are computed in handle_inter_mode(), which is called from this function within the main loop.

Parameters
[in]cpiTop-level encoder structure
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding
[in]xPointer to structure holding all the data for the current macroblock
[in]rd_costStruct to keep track of the RD information
[in]bsizeCurrent block size
[in]ctxStructure to hold snapshot of coding context during the mode picking process
[in]best_rd_so_farBest RD seen for this block so far
Remarks
Nothing is returned. Instead, the MB_MODE_INFO struct inside x is modified to store information about the best mode computed in this function. The rd_cost struct is also updated with the RD stats corresponding to the best mode found.

References AV1EncoderConfig::algo_cfg, FeatureFlags::allow_screen_content_tools, MB_MODE_INFO::angle_delta, av1_restore_uv_color_map(), av1_search_palette_mode(), TxfmSearchInfo::blk_skip, MB_MODE_INFO::bsize, AV1_COMP::common, ModeCosts::comp_inter_cost, macroblock::comp_rd_buffer, AV1Common::cur_frame, AV1Common::current_frame, macroblock::e_mbd, AlgoCfg::enable_tpl_model, AV1Common::features, MB_MODE_INFO::filter_intra_mode_info, handle_inter_mode(), AV1Common::height, macroblock::inter_modes_info, SPEED_FEATURES::inter_sf, FeatureFlags::interp_filter, MB_MODE_INFO::interp_filters, SPEED_FEATURES::intra_sf, macroblockd::mi, macroblockd::mi_col, macroblockd::mi_row, MB_MODE_INFO::mode, macroblock::mode_costs, MB_MODE_INFO::mv, WARP_SAMPLE_INFO::num, inter_modes_info::num, AV1_COMP::oxcf, MB_MODE_INFO::palette_mode_info, MB_MODE_INFO::partition, macroblockd::plane, macroblock::pred_sse, macroblock::qindex, AV1_COMP::rc, macroblock::rdmult, MB_MODE_INFO::ref_mv_idx, search_intra_modes_in_interframe(), AV1Common::seg, MB_MODE_INFO::segment_id, AV1Common::seq_params, AV1_COMP::sf, motion_mode_candidate::skip_motion_mode, MB_MODE_INFO::skip_txfm, TxfmSearchInfo::skip_txfm, AV1_COMP::speed, macroblock::thresh_freq_fact, macroblock::tmp_pred_bufs, macroblock::tpl_keep_ref_frame, macroblockd::tx_type_map, macroblock::txfm_search_info, macroblock::warp_sample_info, AV1Common::width, macroblock::winner_mode_count, SPEED_FEATURES::winner_mode_sf, and macroblock::winner_mode_stats.

Referenced by pick_sb_modes().

◆ motion_mode_rd()

static int64_t motion_mode_rd ( const AV1_COMP *const cpi,
TileDataEnc * tile_data,
MACROBLOCK *const x,
BLOCK_SIZE bsize,
RD_STATS * rd_stats,
RD_STATS * rd_stats_y,
RD_STATS * rd_stats_uv,
HandleInterModeArgs *const args,
int64_t ref_best_rd,
int64_t * ref_skip_rd,
int * rate_mv,
const BUFFER_SET * orig_dst,
int64_t * best_est_rd,
int do_tx_search,
InterModesInfo * inter_modes_info,
int eval_motion_mode,
int64_t * yrd )
static

AV1 motion mode search.

Function to search over and determine the motion mode. It will update mbmi->motion_mode to one of SIMPLE_TRANSLATION, OBMC_CAUSAL, or WARPED_CAUSAL and determine any necessary side information for the selected motion mode. It will also perform the full transform search, unless the input parameter do_tx_search indicates to do an estimation of the RD rather than an RD corresponding to a full transform search. It will return the RD for the final motion_mode. Do the RD search for a given inter mode and compute all information relevant to the input mode. It will compute the best MV, compound parameters (if the mode is a compound mode) and interpolation filter parameters.

Parameters
[in]cpiTop-level encoder structure.
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding.
[in]xPointer to struct holding all the data for the current macroblock.
[in]bsizeCurrent block size.
[in,out]rd_statsStruct to keep track of the overall RD information.
[in,out]rd_stats_yStruct to keep track of the RD information for only the Y plane.
[in,out]rd_stats_uvStruct to keep track of the RD information for only the UV planes.
[in]argsHandleInterModeArgs struct holding miscellaneous arguments for inter mode search. See the documentation for this struct for a description of each member.
[in]ref_best_rdBest RD found so far for this block. It is used for early termination of this search if the RD exceeds this value.
[in,out]ref_skip_rdA length 2 array, where skip_rd[0] is the best total RD for a skip mode so far, and skip_rd[1] is the best RD for a skip mode so far in luma. This is used as a speed feature to skip the transform search if the computed skip RD for the current mode is not better than the best skip_rd so far.
[in,out]rate_mvThe rate associated with the motion vectors. This will be modified if a motion search is done in the motion mode search.
[in,out]orig_dstA prediction buffer to hold a computed prediction. This will eventually hold the final prediction, and the tmp_dst info will be copied here.
[in,out]best_est_rdEstimated RD for motion mode search if do_tx_search (see below) is 0.
[in]do_tx_searchParameter to indicate whether or not to do a full transform search. This will compute an estimated RD for the modes without the transform search and later perform the full transform search on the best candidates.
[in]inter_modes_infoInterModesInfo struct to hold inter mode information to perform a full transform search only on winning candidates searched with an estimate for transform coding RD.
[in]eval_motion_modeBoolean whether or not to evaluate motion motion modes other than SIMPLE_TRANSLATION.
[out]yrdStores the rdcost corresponding to encoding the luma plane.
Returns
Returns INT64_MAX if the determined motion mode is invalid and the current motion mode being tested should be skipped. It returns 0 if the motion mode search is a success.

References FeatureFlags::allow_warped_motion, av1_txfm_search(), TxfmSearchInfo::blk_skip, MB_MODE_INFO::bsize, AV1_COMP::common, MB_MODE_INFO::compound_idx, AV1Common::current_frame, macroblock::e_mbd, AV1Common::features, AV1_PRIMARY::frame_probs, AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, macroblockd::global_motion, macroblockd::height, SPEED_FEATURES::inter_sf, ModeCosts::interintra_cost, FeatureFlags::interp_filter, MB_MODE_INFO::interp_filters, macroblockd::mi, macroblockd::mi_col, macroblockd::mi_row, MB_MODE_INFO::mode, macroblock::mode_costs, MB_MODE_INFO::motion_mode, ModeCosts::motion_mode_cost, ModeCosts::motion_mode_cost1, MB_MODE_INFO::mv, MvCosts::mv_cost_stack, macroblock::mv_costs, SPEED_FEATURES::mv_sf, MvCosts::nmv_joint_cost, WARP_SAMPLE_INFO::num, MB_MODE_INFO::num_proj_ref, FrameProbInfo::obmc_probs, AV1_COMP::oxcf, AV1_COMP::ppi, WARP_SAMPLE_INFO::pts, WARP_SAMPLE_INFO::pts_inref, macroblock::rdmult, MB_MODE_INFO::ref_frame, MB_MODE_INFO::ref_mv_idx, SPEED_FEATURES::rt_sf, AV1Common::seq_params, AV1_COMP::sf, MB_MODE_INFO::skip_txfm, TxfmSearchInfo::skip_txfm, ModeCosts::skip_txfm_cost, FeatureFlags::switchable_motion_mode, macroblockd::tx_type_map, macroblock::txfm_search_info, macroblock::warp_sample_info, macroblockd::width, and MB_MODE_INFO::wm_params.

Referenced by handle_inter_mode().

◆ process_compound_inter_mode()

static int process_compound_inter_mode ( AV1_COMP *const cpi,
MACROBLOCK * x,
HandleInterModeArgs * args,
int64_t ref_best_rd,
int_mv * cur_mv,
BLOCK_SIZE bsize,
int * compmode_interinter_cost,
const CompoundTypeRdBuffers * rd_buffers,
const BUFFER_SET * orig_dst,
const BUFFER_SET * tmp_dst,
int * rate_mv,
RD_STATS * rd_stats,
int64_t * skip_rd,
int * skip_build_pred )
static

High level function to select parameters for compound mode.

The main search functionality is done in the call to av1_compound_type_rd().

Parameters
[in]cpiTop-level encoder structure.
[in]xPointer to struct holding all the data for the current macroblock.
[in]argsHandleInterModeArgs struct holding miscellaneous arguments for inter mode search. See the documentation for this struct for a description of each member.
[in]ref_best_rdBest RD found so far for this block. It is used for early termination of this search if the RD exceeds this value.
[in,out]cur_mvCurrent motion vector.
[in]bsizeCurrent block size.
[in,out]compmode_interinter_costRD of the selected interinter compound mode.
[in,out]rd_buffersCompoundTypeRdBuffers struct to hold all allocated buffers for the compound predictors and masks in the compound type search.
[in,out]orig_dstA prediction buffer to hold a computed prediction. This will eventually hold the final prediction, and the tmp_dst info will be copied here.
[in]tmp_dstA temporary prediction buffer to hold a computed prediction.
[in,out]rate_mvThe rate associated with the motion vectors. This will be modified if a motion search is done in the motion mode search.
[in,out]rd_statsStruct to keep track of the overall RD information.
[in,out]skip_rdAn array of length 2 where skip_rd[0] is the best total RD for a skip mode so far, and skip_rd[1] is the best RD for a skip mode so far in luma. This is used as a speed feature to skip the transform search if the computed skip RD for the current mode is not better than the best skip_rd so far.
[in,out]skip_build_predIndicates whether or not to build the inter predictor. If this is 0, the inter predictor has already been built and thus we can avoid repeating computation.
Returns
Returns 1 if this mode is worse than one already seen and 0 if it is a viable candidate.

< U (Chroma) plane

References AOM_PLANE_U, AV1_COMP::common, macroblock::e_mbd, AV1Common::features, MB_MODE_INFO::interinter_comp, FeatureFlags::interp_filter, macroblockd::mi, macroblockd::mi_col, macroblockd::mi_row, and AV1Common::seq_params.

Referenced by handle_inter_mode().

◆ prune_zero_mv_with_sse()

static int prune_zero_mv_with_sse ( const aom_variance_fn_ptr_t * fn_ptr,
const MACROBLOCK * x,
BLOCK_SIZE bsize,
const HandleInterModeArgs * args,
int prune_zero_mv_with_sse )
inlinestatic

Prunes ZeroMV Search Using Best NEWMV's SSE.

Compares the sse of zero mv and the best sse found in single new_mv. If the sse of the zero_mv is higher, returns 1 to signal zero_mv can be skipped. Else returns 0.

Note that the sse of here comes from single_motion_search. So it is interpolated with the filter in motion search, not the actual interpolation filter used in encoding.

Parameters
[in]fn_ptrA table of function pointers to compute SSE.
[in]xPointer to struct holding all the data for the current macroblock.
[in]bsizeThe current block_size.
[in]argsThe args to handle_inter_mode, used to track the best SSE.
[in]prune_zero_mv_with_sseThe argument holds speed feature prune_zero_mv_with_sse value
Returns
Returns 1 if zero_mv is pruned, 0 otherwise.

< Y (Luminance) plane

References AOM_PLANE_Y, macroblock::e_mbd, macroblockd::global_motion, macroblockd::mi, MB_MODE_INFO::mv, macroblockd::plane, macroblock::plane, prune_zero_mv_with_sse(), MB_MODE_INFO::ref_frame, and macroblock_plane::src.

Referenced by handle_inter_mode(), and prune_zero_mv_with_sse().

◆ fast_interp_search()

static bool fast_interp_search ( const AV1_COMP * cpi,
MACROBLOCK * x,
int mi_row,
int mi_col,
BLOCK_SIZE bsize )
inlinestatic

Searches for interpolation filter in realtime mode during winner eval.

Does a simple interpolation filter search during winner mode evaluation. This is currently only used by realtime mode as av1_interpolation_filter_search is not called during realtime encoding.

This function only searches over two possible filters. EIGHTTAP_REGULAR is always search. For lowres clips (<= 240p), MULTITAP_SHARP is also search. For higher res slips (>240p), EIGHTTAP_SMOOTH is also searched.

  • Parameters
    [in]cpiPointer to the compressor. Used for feature flags.
    [in,out]xPointer to macroblock. This is primarily used to access the buffers.
    [in]mi_rowThe current row in mi unit (4X4 pixels).
    [in]mi_colThe current col in mi unit (4X4 pixels).
    [in]bsizeThe current block_size.
    Returns
    Returns true if a predictor is built in xd->dst, false otherwise.

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< Y (Luminance) plane

< U (Chroma) plane

< V (Chroma) plane

References AOM_PLANE_U, AOM_PLANE_V, AOM_PLANE_Y, AV1_COMP::common, macroblock::e_mbd, AV1Common::features, AV1Common::height, FeatureFlags::interp_filter, MB_MODE_INFO::interp_filters, macroblockd::mi, MB_MODE_INFO::mode, MB_MODE_INFO::motion_mode, macroblockd::plane, SPEED_FEATURES::rt_sf, AV1Common::seq_params, AV1_COMP::sf, macroblock::tmp_pred_bufs, and AV1Common::width.

◆ handle_inter_mode()

static int64_t handle_inter_mode ( AV1_COMP *const cpi,
TileDataEnc * tile_data,
MACROBLOCK * x,
BLOCK_SIZE bsize,
RD_STATS * rd_stats,
RD_STATS * rd_stats_y,
RD_STATS * rd_stats_uv,
HandleInterModeArgs * args,
int64_t ref_best_rd,
uint8_t *const tmp_buf,
const CompoundTypeRdBuffers * rd_buffers,
int64_t * best_est_rd,
const int do_tx_search,
InterModesInfo * inter_modes_info,
motion_mode_candidate * motion_mode_cand,
int64_t * skip_rd,
PruneInfoFromTpl * inter_cost_info_from_tpl,
int64_t * yrd )
static

AV1 inter mode RD computation.

Do the RD search for a given inter mode and compute all information relevant to the input mode. It will compute the best MV, compound parameters (if the mode is a compound mode) and interpolation filter parameters.

Parameters
[in]cpiTop-level encoder structure.
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding.
[in]xPointer to structure holding all the data for the current macroblock.
[in]bsizeCurrent block size.
[in,out]rd_statsStruct to keep track of the overall RD information.
[in,out]rd_stats_yStruct to keep track of the RD information for only the Y plane.
[in,out]rd_stats_uvStruct to keep track of the RD information for only the UV planes.
[in]argsHandleInterModeArgs struct holding miscellaneous arguments for inter mode search. See the documentation for this struct for a description of each member.
[in]ref_best_rdBest RD found so far for this block. It is used for early termination of this search if the RD exceeds this value.
[in]tmp_bufTemporary buffer used to hold predictors built in this search.
[in,out]rd_buffersCompoundTypeRdBuffers struct to hold all allocated buffers for the compound predictors and masks in the compound type search.
[in,out]best_est_rdEstimated RD for motion mode search if do_tx_search (see below) is 0.
[in]do_tx_searchParameter to indicate whether or not to do a full transform search. This will compute an estimated RD for the modes without the transform search and later perform the full transform search on the best candidates.
[in,out]inter_modes_infoInterModesInfo struct to hold inter mode information to perform a full transform search only on winning candidates searched with an estimate for transform coding RD.
[in,out]motion_mode_candA motion_mode_candidate struct to store motion mode information used in a speed feature to search motion modes other than SIMPLE_TRANSLATION only on winning candidates.
[in,out]skip_rdA length 2 array, where skip_rd[0] is the best total RD for a skip mode so far, and skip_rd[1] is the best RD for a skip mode so far in luma. This is used as a speed feature to skip the transform search if the computed skip RD for the current mode is not better than the best skip_rd so far.
[in]inter_cost_info_from_tplA PruneInfoFromTpl struct used to narrow down the search based on data collected in the TPL model.
[out]yrdStores the rdcost corresponding to encoding the luma plane.
Returns
The RD cost for the mode being searched.

References av1_interpolation_filter_search(), TxfmSearchInfo::blk_skip, AV1_COMP::common, MB_MODE_INFO::comp_group_idx, MB_MODE_INFO::compound_idx, ModeCosts::drl_mode_cost0, macroblock::e_mbd, AV1_PRIMARY::fn_ptr, AV1_COMP::gf_frame_index, SPEED_FEATURES::gm_sf, macroblockd::height, SPEED_FEATURES::inter_sf, MB_MODE_INFO::interinter_comp, macroblock::mbmi_ext, macroblockd::mi, macroblockd::mi_col, CommonModeInfoParams::mi_cols, AV1Common::mi_params, macroblockd::mi_row, CommonModeInfoParams::mi_rows, MB_MODE_INFO::mode, MB_MODE_INFO_EXT::mode_context, macroblock::mode_costs, MB_MODE_INFO::motion_mode, motion_mode_rd(), MB_MODE_INFO::mv, MB_MODE_INFO::num_proj_ref, macroblockd::plane, AV1_COMP::ppi, macroblock::pred_sse, process_compound_inter_mode(), prune_zero_mv_with_sse(), motion_mode_candidate::rate2_nocoeff, motion_mode_candidate::rate_mv, macroblock::rdmult, MB_MODE_INFO::ref_frame, MB_MODE_INFO::ref_mv_idx, SPEED_FEATURES::rt_sf, AV1_COMP::sf, TxfmSearchInfo::skip_txfm, AV1_PRIMARY::tpl_data, macroblockd::tx_type_map, macroblock::txfm_search_info, macroblockd::width, and SPEED_FEATURES::winner_mode_sf.

Referenced by av1_rd_pick_inter_mode().