AOMedia AV1 Codec: NonRD Optimized Mode Search

| AOMedia AV1 Codec

Functions
NonRD Optimized Mode Search
Encoder Algorithm

## Functions
void | av1_nonrd_pick_intra_mode (AV1_COMP *cpi, MACROBLOCK *x, RD_STATS *rd_cost, BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx)
| AV1 intra mode selection based on Non-RD optimized model. More...
void | av1_nonrd_pick_inter_mode_sb (struct AV1_COMP *cpi, struct TileDataEnc *tile_data, struct macroblock *x, struct RD_STATS *rd_cost, BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx)
| AV1 inter mode selection based on Non-RD optimized model. More...
static int | combined_motion_search (AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row, int mi_col, int_mv *tmp_mv, int *rate_mv, int64_t best_rd_sofar, int use_base_mv)
| Runs Motion Estimation for a specific block and specific ref frame. More...
static int | search_new_mv (AV1_COMP *cpi, MACROBLOCK *x, int_mv frame_mv[][REF_FRAMES], MV_REFERENCE_FRAME ref_frame, int gf_temporal_ref, BLOCK_SIZE bsize, int mi_row, int mi_col, int *rate_mv, RD_STATS *best_rdc)
| Searches for the best New Motion Vector. More...
static void | find_predictors (AV1_COMP *cpi, MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame, int_mv frame_mv[MB_MODE_COUNT][REF_FRAMES], TileDataEnc *tile_data, struct buf_2d yv12_mb[8][3], BLOCK_SIZE bsize, int force_skip_low_temp_var, int skip_pred_mv)
| Finds predicted motion vectors for a block. More...
static void | block_yrd (AV1_COMP *cpi, MACROBLOCK *x, int mi_row, int mi_col, RD_STATS *this_rdc, int *skippable, BLOCK_SIZE bsize, TX_SIZE tx_size)
| Calculates RD Cost using Hadamard transform. More...
static void | estimate_block_intra (int plane, int block, int row, int col, BLOCK_SIZE plane_bsize, TX_SIZE tx_size, void *arg)
| Estimation of RD cost of an intra mode for Non-RD optimized case. More...
static void | search_filter_ref (AV1_COMP *cpi, MACROBLOCK *x, RD_STATS *this_rdc, int mi_row, int mi_col, PRED_BUFFER *tmp, BLOCK_SIZE bsize, int reuse_inter_pred, PRED_BUFFER **this_mode_pred, int *this_early_term, int use_model_yrd_large)
| Searches for the best intrpolation filter. More...
static void | estimate_intra_mode (AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int use_modeled_non_rd_cost, int best_early_term, unsigned int ref_cost_intra, int reuse_prediction, struct buf_2d *orig_dst, PRED_BUFFER *tmp_buffers, PRED_BUFFER **this_mode_pred, RD_STATS *best_rdc, BEST_PICKMODE *best_pickmode)
| Estimates best intra mode for inter mode search. More...

## Detailed Description

This module describes NonRD Optimized Mode Search used in Real-Time mode. More details will be added.

## Function Documentation

## ◆ av1_nonrd_pick_intra_mode()

void av1_nonrd_pick_intra_mode | ( | AV1_COMP * | cpi,
|  | MACROBLOCK * | x,
|  | RD_STATS * | rd_cost,
|  | BLOCK_SIZE | bsize,
|  | PICK_MODE_CONTEXT * | ctx
| ) |  |

AV1 intra mode selection based on Non-RD optimized model.

Top level function for Non-RD optimized intra mode selection. This finction will loop over subset of intra modes and select the best one based on calculated modelled RD cost. Only 4 intra modes are checked as specified in `intra_mode_list`. When calculating RD cost Hadamard transform of residual is used to calculate rate. Estmation of RD cost is performed in `estimate_block_intra` which is called from this function

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | x | Pointer to structure holding all the data for the current macroblock
  [in] | rd_cost | Struct to keep track of the RD information
  [in] | bsize | Current block size
  [in] | ctx | Structure to hold snapshot of coding context during the mode picking process

Returns
  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 macroblockd::above_mbmi, macroblock::e_mbd, estimate_block_intra(), macroblockd::left_mbmi, macroblockd::mi, MB_MODE_INFO::mode, macroblock::mode_costs, MB_MODE_INFO::mv, macroblock::rdmult, ModeCosts::skip_txfm_cost, TxfmSearchParams::tx_mode_search_type, MB_MODE_INFO::tx_size, macroblock::txfm_search_params, MB_MODE_INFO::uv_mode, and ModeCosts::y_mode_costs.

Referenced by hybrid_intra_mode_search().

## ◆ av1_nonrd_pick_inter_mode_sb()

void av1_nonrd_pick_inter_mode_sb | ( | struct AV1_COMP * | cpi,
|  | struct TileDataEnc * | tile_data,
|  | struct macroblock * | x,
|  | struct RD_STATS * | rd_cost,
|  | BLOCK_SIZE | bsize,
|  | PICK_MODE_CONTEXT * | ctx
| ) |  |

AV1 inter mode selection based on Non-RD optimized model.

Top level function for Non-RD optimized inter mode selection. This finction will loop over subset of inter modes and select the best one based on calculated modelled RD cost. While making decisions which modes to check, this function applies heuristics based on previously checked modes, block residual variance, block size, and other factors to prune certain modes and reference frames. Currently only single reference frame modes are checked. Additional heuristics are applied to decide if intra modes need to be checked.

- Parameters

    [in] | cpi | Top-level encoder structure
    [in] | tile_data | Pointer to struct holding adaptive data/contexts/models for the tile during encoding
    [in] | x | Pointer to structure holding all the data for the current macroblock
    [in] | rd_cost | Struct to keep track of the RD information
    [in] | bsize | Current block size
    [in] | ctx | Structure to hold snapshot of coding context during the mode picking process

  Returns
    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.

< U (Chroma) plane

< U (Chroma) plane

< V (Chroma) plane

< V (Chroma) plane

References macroblockd::above_mbmi, MB_MODE_INFO::angle_delta, AOM_BITS_8, AOM_CBR, AOM_PLANE_U, AOM_PLANE_V, CommonQuantParams::base_qindex, block_yrd(), MB_MODE_INFO::bsize, macroblock::color_sensitivity, macroblock::color_sensitivity_sb, MB_MODE_INFO::comp_group_idx, MB_MODE_INFO::compound_idx, macroblock::content_state_sb, SVC::downsample_filter_phase, macroblock::e_mbd, estimate_intra_mode(), AV1Common::features, MB_MODE_INFO::filter_intra_mode_info, find_predictors(), AV1Common::height, MB_MODE_INFO::inter_tx_size, MB_MODE_INFO::interinter_comp, FeatureFlags::interp_filter, MB_MODE_INFO::interp_filters, macroblockd::left_mbmi, macroblock::mbmi_ext, macroblockd::mi, macroblockd::mi_col, macroblockd::mi_row, MB_MODE_INFO::mode, MB_MODE_INFO_EXT::mode_context, macroblock::mode_costs, MB_MODE_INFO::motion_mode, MB_MODE_INFO::mv, macroblock::nonrd_prune_ref_frame_search, WARP_SAMPLE_INFO::num, MB_MODE_INFO::num_proj_ref, macroblockd::plane, macroblock::pred_mv0_sad, macroblock::pred_mv1_sad, macroblock::pred_mv_sad, AV1Common::quant_params, macroblock::rdmult, MB_MODE_INFO::ref_frame, search_filter_ref(), search_new_mv(), AV1Common::seg, MB_MODE_INFO::segment_id, AV1Common::seq_params, TxfmSearchInfo::skip_txfm, ModeCosts::skip_txfm_cost, macroblock::source_variance, macroblock::thresh_freq_fact, TxfmSearchParams::tx_mode_search_type, MB_MODE_INFO::tx_size, macroblock::txfm_search_info, macroblock::txfm_search_params, macroblock::warp_sample_info, AV1Common::width, and MB_MODE_INFO::wm_params.

Referenced by pick_sb_modes_nonrd().

## ◆ combined_motion_search()

static int combined_motion_search | ( | AV1_COMP * | cpi,
|  | MACROBLOCK * | x,
|  | BLOCK_SIZE | bsize,
|  | int | mi_row,
|  | int | mi_col,
|  | int_mv * | tmp_mv,
|  | int * | rate_mv,
|  | int64_t | best_rd_sofar,
|  | int | use_base_mv
| ) |  |
| static

Runs Motion Estimation for a specific block and specific ref frame.

Finds the best Motion Vector by running Motion Estimation for a specific block and a specific reference frame. Exits early if RDCost of Full Pel part exceeds best RD Cost fund so far

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | x | Pointer to structure holding all the data for the current macroblock
  [in] | bsize | Current block size
  [in] | mi_row | Row index in 4x4 units
  [in] | mi_col | Column index in 4x4 units
  [in] | tmp_mv | Pointer to best found New MV
  [in] | rate_mv | Pointer to Rate of the best new MV
  [in] | best_rd_sofar | RD Cost of the best mode found so far
  [in] | use_base_mv | Flag, indicating that tmp_mv holds specific MV to start the search with

Returns
  Returns 0 if ME was terminated after Full Pel Search because too high RD Cost. Otherwise returns 1. Best New MV is placed into `tmp_mv`. Rate estimation for this vector is placed to `rate_mv`

References macroblock::e_mbd, macroblockd::mi, MvCosts::mv_cost_stack, macroblock::mv_costs, MvCosts::nmv_joint_cost, macroblockd::plane, macroblock::pred_sse, macroblock::rdmult, MB_MODE_INFO::ref_frame, and MB_MODE_INFO::ref_mv_idx.

Referenced by search_new_mv().

## ◆ search_new_mv()

static int search_new_mv | ( | AV1_COMP * | cpi,
|  | MACROBLOCK * | x,
|  | int_mv | frame_mv[][REF_FRAMES],
|  | MV_REFERENCE_FRAME | ref_frame,
|  | int | gf_temporal_ref,
|  | BLOCK_SIZE | bsize,
|  | int | mi_row,
|  | int | mi_col,
|  | int * | rate_mv,
|  | RD_STATS * | best_rdc
| ) |  |
| static

Searches for the best New Motion Vector.

Finds the best Motion Vector by doing Motion Estimation. Uses reduced complexity ME for non-LAST frames or calls `combined_motion_search` for LAST reference frame

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | x | Pointer to structure holding all the data for the current macroblock
  [in] | frame_mv | Array that holds MVs for all modes and ref frames
  [in] | ref_frame | Reference freme for which to find the best New MVs
  [in] | gf_temporal_ref | Flag, indicating temporal reference for GOLDEN frame
  [in] | bsize | Current block size
  [in] | mi_row | Row index in 4x4 units
  [in] | mi_col | Column index in 4x4 units
  [in] | rate_mv | Pointer to Rate of the best new MV
  [in] | best_rdc | Pointer to the RD Cost for the best mode found so far

Returns
  Returns -1 if the search was not done, otherwise returns 0. Best New MV is placed into `frame_mv` array, Rate estimation for this vector is placed to `rate_mv`

References AOM_CBR, combined_motion_search(), macroblock::e_mbd, macroblock::mbmi_ext, macroblockd::mi, MB_MODE_INFO::mv, MvCosts::mv_cost_stack, macroblock::mv_costs, MvCosts::nmv_joint_cost, macroblock::pred_mv_sad, macroblock::pred_sse, and MB_MODE_INFO_EXT::ref_mv_stack.

Referenced by av1_nonrd_pick_inter_mode_sb().

## ◆ find_predictors()

static void find_predictors | ( | AV1_COMP * | cpi,
|  | MACROBLOCK * | x,
|  | MV_REFERENCE_FRAME | ref_frame,
|  | int_mv | frame_mv[MB_MODE_COUNT][REF_FRAMES],
|  | TileDataEnc * | tile_data,
|  | struct buf_2d | yv12_mb[8][3],
|  | BLOCK_SIZE | bsize,
|  | int | force_skip_low_temp_var,
|  | int | skip_pred_mv
| ) |  |
| inlinestatic

Finds predicted motion vectors for a block.

Finds predicted motion vectors for a block from a certain reference frame. First, it fills reference MV stack, then picks the test from the stack and predicts the final MV for a block for each mode.

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | x | Pointer to structure holding all the data for the current macroblock
  [in] | ref_frame | Reference freme for which to find ref MVs
  [in] | frame_mv | Predicted MVs for a block
  [in] | tile_data | Pointer to struct holding adaptive data/contexts/models for the tile during encoding
  [in] | yv12_mb | Buffer to hold predicted block
  [in] | bsize | Current block size
  [in] | force_skip_low_temp_var | Flag indicating possible mode search prune for low temporal variance block
  [in] | skip_pred_mv | Flag indicating to skip av1_mv_pred

Returns
  Nothing is returned. Instead, predicted MVs are placed into `frame_mv` array

References FeatureFlags::allow_high_precision_mv, macroblock::e_mbd, AV1Common::features, MB_MODE_INFO_EXT::global_mvs, macroblock::mbmi_ext, macroblockd::mi, MB_MODE_INFO_EXT::mode_context, MB_MODE_INFO::num_proj_ref, macroblock::pred_mv0_sad, macroblock::pred_mv1_sad, macroblock::pred_mv_sad, MB_MODE_INFO_EXT::ref_mv_count, macroblockd::ref_mv_stack, and macroblockd::weight.

Referenced by av1_nonrd_pick_inter_mode_sb().

## ◆ block_yrd()

static void block_yrd | ( | AV1_COMP * | cpi,
|  | MACROBLOCK * | x,
|  | int | mi_row,
|  | int | mi_col,
|  | RD_STATS * | this_rdc,
|  | int * | skippable,
|  | BLOCK_SIZE | bsize,
|  | TX_SIZE | tx_size
| ) |  |
| static

Calculates RD Cost using Hadamard transform.

Calculates RD Cost using Hadamard transform. For low bit depth this function uses low-precision set of functions (16-bit) and 32 bit for high bit depth

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | x | Pointer to structure holding all the data for the current macroblock
  [in] | mi_row | Row index in 4x4 units
  [in] | mi_col | Column index in 4x4 units
  [in] | this_rdc | Pointer to calculated RD Cost
  [in] | skippable | Pointer to a flag indicating possible tx skip
  [in] | bsize | Current block size
  [in] | tx_size | Transform size

Returns
  Nothing is returned. Instead, calculated RD cost is placed to `this_rdc`. `skippable` flag is set if there is no non-zero quantized coefficients for Hadamard transform

References macroblockd::bd, macroblock_plane::coeff, macroblock_plane::dequant_QTX, macroblock_plane::dqcoeff, macroblock::e_mbd, macroblock_plane::eobs, macroblockd::mb_to_bottom_edge, macroblockd::mb_to_right_edge, macroblockd::plane, macroblock::plane, macroblock_plane::qcoeff, macroblock_plane::quant_fp_QTX, macroblock_plane::quant_shift_QTX, macroblock_plane::round_fp_QTX, macroblock_plane::src, macroblock_plane::src_diff, and macroblock_plane::zbin_QTX.

Referenced by av1_nonrd_pick_inter_mode_sb(), estimate_block_intra(), and estimate_intra_mode().

## ◆ estimate_block_intra()

static void estimate_block_intra | ( | int | plane,
|  | int | block,
|  | int | row,
|  | int | col,
|  | BLOCK_SIZE | plane_bsize,
|  | TX_SIZE | tx_size,
|  | void * | arg
| ) |  |
| static

Estimation of RD cost of an intra mode for Non-RD optimized case.

Calculates RD Cost for an intra mode for a single TX block using Hadamard transform.

Parameters

  [in] | plane | Color plane
  [in] | block | Index of a TX block in a prediction block
  [in] | row | Row of a current TX block
  [in] | col | Column of a current TX block
  [in] | plane_bsize | Block size of a current prediction block
  [in] | tx_size | Transform size
  [in] | arg | Pointer to a structure that holds paramaters for intra mode search

Returns
  Nothing is returned. Instead, best mode and RD Cost of the best mode are set in `args->rdc` and `args->mode`

References block_yrd(), macroblock::e_mbd, macroblockd::plane, macroblock::plane, and macroblock_plane::src.

Referenced by av1_nonrd_pick_intra_mode(), and estimate_intra_mode().

## ◆ search_filter_ref()

static void search_filter_ref | ( | AV1_COMP * | cpi,
|  | MACROBLOCK * | x,
|  | RD_STATS * | this_rdc,
|  | int | mi_row,
|  | int | mi_col,
|  | PRED_BUFFER * | tmp,
|  | BLOCK_SIZE | bsize,
|  | int | reuse_inter_pred,
|  | PRED_BUFFER ** | this_mode_pred,
|  | int * | this_early_term,
|  | int | use_model_yrd_large
| ) |  |
| static

Searches for the best intrpolation filter.

Iterates through subset of possible interpolation filters (EIGHTTAP_REGULAR, EIGTHTAP_SMOOTH, MULTITAP_SHARP, depending on FILTER_SEARCH_SIZE) and selects the one that gives lowest RD cost. RD cost is calculated using curvfit model. Support for dual filters (different filters in the x & y directions) is allowed if sf.interp_sf.disable_dual_filter = 0.

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | x | Pointer to structure holding all the data for the current macroblock
  [in] | this_rdc | Pointer to calculated RD Cost
  [in] | mi_row | Row index in 4x4 units
  [in] | mi_col | Column index in 4x4 units
  [in] | tmp | Pointer to a temporary buffer for prediction re-use
  [in] | bsize | Current block size
  [in] | reuse_inter_pred | Flag, indicating prediction re-use
  [out] | this_mode_pred | Pointer to store prediction buffer for prediction re-use
  [out] | this_early_term | Flag, indicating that transform can be skipped
  [in] | use_model_yrd_large | Flag, indicating special logic to handle large blocks

Returns
  Nothing is returned. Instead, calculated RD cost is placed to `this_rdc` and best filter is placed to `mi->interp_filters`. In case `reuse_inter_pred` flag is set, this function also ouputs `this_mode_pred`. Also `this_early_temp` is set if transform can be skipped

References macroblock::e_mbd, AV1Common::features, FeatureFlags::interp_filter, MB_MODE_INFO::interp_filters, macroblockd::mi, macroblockd::plane, macroblock::rdmult, AV1Common::seq_params, and MB_MODE_INFO::tx_size.

Referenced by av1_nonrd_pick_inter_mode_sb().

## ◆ estimate_intra_mode()

static void estimate_intra_mode | ( | AV1_COMP * | cpi,
|  | MACROBLOCK * | x,
|  | BLOCK_SIZE | bsize,
|  | int | use_modeled_non_rd_cost,
|  | int | best_early_term,
|  | unsigned int | ref_cost_intra,
|  | int | reuse_prediction,
|  | struct buf_2d * | orig_dst,
|  | PRED_BUFFER * | tmp_buffers,
|  | PRED_BUFFER ** | this_mode_pred,
|  | RD_STATS * | best_rdc,
|  | BEST_PICKMODE * | best_pickmode
| ) |  |
| static

Estimates best intra mode for inter mode search.

Using heuristics based on best inter mode, block size, and other decides whether to check intra modes. If so, estimates and selects best intra mode from the reduced set of intra modes (max 4 intra modes checked)

Parameters

  [in] | cpi | Top-level encoder structure
  [in] | x | Pointer to structure holding all the data for the current macroblock
  [in] | bsize | Current block size
  [in] | use_modeled_non_rd_cost | Flag, indicating usage of curvfit model for RD cost
  [in] | best_early_term | Flag, indicating that TX for the best inter mode was skipped
  [in] | ref_cost_intra | Cost of signalling intra mode
  [in] | reuse_prediction | Flag, indicating prediction re-use
  [in] | orig_dst | Original destination buffer
  [in] | tmp_buffers | Pointer to a temporary buffers for prediction re-use
  [out] | this_mode_pred | Pointer to store prediction buffer for prediction re-use
  [in] | best_rdc | Pointer to RD cost for the best selected intra mode
  [in] | best_pickmode | Pointer to a structure containing best mode picked so far

Returns
  Nothing is returned. Instead, calculated RD cost is placed to `best_rdc` and best selected mode is placed to `best_pickmode`

References MB_MODE_INFO::angle_delta, ModeCosts::angle_delta_cost, CommonQuantParams::base_qindex, block_yrd(), macroblock::color_sensitivity, macroblock::content_state_sb, macroblock::e_mbd, estimate_block_intra(), ModeCosts::filter_intra_cost, macroblockd::mi, macroblockd::mi_col, macroblockd::mi_row, MB_MODE_INFO::mode, macroblock::mode_costs, MB_MODE_INFO::mv, macroblockd::plane, AV1Common::quant_params, macroblock::rdmult, MB_MODE_INFO::ref_frame, MB_MODE_INFO::segment_id, AV1Common::seq_params, macroblock::source_variance, macroblock::thresh_freq_fact, TxfmSearchParams::tx_mode_search_type, MB_MODE_INFO::tx_size, macroblock::txfm_search_params, MB_MODE_INFO::uv_mode, and CommonQuantParams::y_dc_delta_q.

Referenced by av1_nonrd_pick_inter_mode_sb().