AOMedia AV1 Codec
Partition Search

Functions

static void encode_nonrd_sb (AV1_COMP *cpi, ThreadData *td, TileDataEnc *tile_data, TokenExtra **tp, const int mi_row, const int mi_col, const int seg_skip)
 Encode a superblock (minimal RD search involved)
 
static void encode_rd_sb (AV1_COMP *cpi, ThreadData *td, TileDataEnc *tile_data, TokenExtra **tp, const int mi_row, const int mi_col, const int seg_skip)
 CONFIG_REALTIME_ONLY.
 
static uint64_t get_sb_source_sad (const AV1_COMP *cpi, int mi_row, int mi_col)
 Calculate source SAD at superblock level using 64x64 block source SAD.
 
static bool is_calc_src_content_needed (AV1_COMP *cpi, MACROBLOCK *const x, int mi_row, int mi_col)
 Determine whether grading content can be skipped based on sad stat.
 
static void grade_source_content_sb (AV1_COMP *cpi, MACROBLOCK *const x, TileDataEnc *tile_data, int mi_row, int mi_col)
 Determine whether grading content is needed based on sf and frame stat.
 
static void encode_sb_row (AV1_COMP *cpi, ThreadData *td, TileDataEnc *tile_data, int mi_row, TokenExtra **tp)
 Encode a superblock row by breaking it into superblocks.
 
void av1_encode_sb_row (AV1_COMP *cpi, ThreadData *td, int tile_row, int tile_col, int mi_row)
 Encode a superblock row.
 
void av1_encode_tile (AV1_COMP *cpi, ThreadData *td, int tile_row, int tile_col)
 Encode a tile.
 
static void encode_tiles (AV1_COMP *cpi)
 Break one frame into tiles and encode the tiles.
 
static void pick_sb_modes (AV1_COMP *const cpi, TileDataEnc *tile_data, MACROBLOCK *const x, int mi_row, int mi_col, RD_STATS *rd_cost, PARTITION_TYPE partition, BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, RD_STATS best_rd)
 Interface for AV1 mode search for an individual coding block.
 
static void encode_b (const AV1_COMP *const cpi, TileDataEnc *tile_data, ThreadData *td, TokenExtra **tp, int mi_row, int mi_col, RUN_TYPE dry_run, BLOCK_SIZE bsize, PARTITION_TYPE partition, PICK_MODE_CONTEXT *const ctx, int *rate)
 Reconstructs an individual coding block.
 
static void encode_sb (const AV1_COMP *const cpi, ThreadData *td, TileDataEnc *tile_data, TokenExtra **tp, int mi_row, int mi_col, RUN_TYPE dry_run, BLOCK_SIZE bsize, PC_TREE *pc_tree, int *rate)
 Reconstructs a partition (may contain multiple coding blocks)
 
void av1_rd_use_partition (AV1_COMP *cpi, ThreadData *td, TileDataEnc *tile_data, MB_MODE_INFO **mib, TokenExtra **tp, int mi_row, int mi_col, BLOCK_SIZE bsize, int *rate, int64_t *dist, int do_recon, PC_TREE *pc_tree)
 AV1 block partition search (partition estimation and partial search).
 
static void pick_sb_modes_nonrd (AV1_COMP *const cpi, TileDataEnc *tile_data, MACROBLOCK *const x, int mi_row, int mi_col, RD_STATS *rd_cost, BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx)
 Top level function to pick block mode for non-RD optimized case.
 
void av1_nonrd_use_partition (AV1_COMP *cpi, ThreadData *td, TileDataEnc *tile_data, MB_MODE_INFO **mib, TokenExtra **tp, int mi_row, int mi_col, BLOCK_SIZE bsize, PC_TREE *pc_tree)
 AV1 block partition application (minimal RD search).
 
bool av1_rd_pick_partition (AV1_COMP *const cpi, ThreadData *td, TileDataEnc *tile_data, TokenExtra **tp, int mi_row, int mi_col, BLOCK_SIZE bsize, RD_STATS *rd_cost, RD_STATS best_rdc, PC_TREE *pc_tree, SIMPLE_MOTION_DATA_TREE *sms_tree, int64_t *none_rd, SB_MULTI_PASS_MODE multi_pass_mode, RD_RECT_PART_WIN_INFO *rect_part_win_info)
 AV1 block partition search (full search).
 

Detailed Description

For and overview of the partition search see Block Partition Search

Function Documentation

◆ encode_nonrd_sb()

static void encode_nonrd_sb ( AV1_COMP * cpi,
ThreadData * td,
TileDataEnc * tile_data,
TokenExtra ** tp,
const int mi_row,
const int mi_col,
const int seg_skip )
inlinestatic

Encode a superblock (minimal RD search involved)

Encodes the superblock by a pre-determined partition pattern, only minor rd-based searches are allowed to adjust the initial pattern. It is only used by realtime encoding.

References av1_choose_var_based_partitioning(), av1_nonrd_use_partition(), MB_MODE_INFO::cdef_strength, AV1_COMP::common, macroblock::content_state_sb, LAYER_CONTEXT::is_key_frame, SVC::layer_context, CommonModeInfoParams::mi_grid_base, AV1Common::mi_params, CommonModeInfoParams::mi_stride, SPEED_FEATURES::part_sf, AV1_COMP::ppi, SPEED_FEATURES::rt_sf, macroblock::sb_force_fixed_part, AV1Common::seq_params, AV1_COMP::sf, AV1_COMP::svc, and AV1_PRIMARY::use_svc.

Referenced by encode_sb_row().

◆ encode_rd_sb()

static void encode_rd_sb ( AV1_COMP * cpi,
ThreadData * td,
TileDataEnc * tile_data,
TokenExtra ** tp,
const int mi_row,
const int mi_col,
const int seg_skip )
inlinestatic

◆ encode_sb_row()

static void encode_sb_row ( AV1_COMP * cpi,
ThreadData * td,
TileDataEnc * tile_data,
int mi_row,
TokenExtra ** tp )
inlinestatic

◆ encode_tiles()

static void encode_tiles ( AV1_COMP * cpi)
inlinestatic

◆ pick_sb_modes()

static void pick_sb_modes ( AV1_COMP *const cpi,
TileDataEnc * tile_data,
MACROBLOCK *const x,
int mi_row,
int mi_col,
RD_STATS * rd_cost,
PARTITION_TYPE partition,
BLOCK_SIZE bsize,
PICK_MODE_CONTEXT * ctx,
RD_STATS best_rd )
static

Interface for AV1 mode search for an individual coding block.

Searches prediction modes, transform, and coefficient coding modes for an individual coding block. This function is the top-level interface that directs the encoder to the proper mode search function, among these implemented for inter/intra + rd/non-rd + non-skip segment/skip segment.

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]mi_rowRow coordinate of the block in a step size of MI_SIZE
[in]mi_colColumn coordinate of the block in a step size of MI_SIZE
[in]rd_costPointer to structure holding rate and distortion stats for the current block
[in]partitionPartition mode of the parent block
[in]bsizeCurrent block size
[in]ctxPointer to structure holding coding contexts and chosen modes for the current block
[in]best_rdUpper bound of rd cost of a valid partition
Remarks
Nothing is returned. Instead, the chosen modes and contexts necessary for reconstruction are stored in ctx, the rate-distortion stats are stored in rd_cost. If no valid mode leading to rd_cost <= best_rd, the status will be signalled by an INT64_MAX rd_cost->rdcost.

< Y (Luminance) plane

References AOM_PLANE_Y, av1_rd_pick_inter_mode(), av1_rd_pick_intra_mode_sb(), MB_MODE_INFO::bsize, macroblock_plane::coeff, AV1_COMP::common, macroblock_plane::dqcoeff, macroblock::e_mbd, MultiThreadInfo::enc_row_mt, macroblock_plane::eobs, macroblock::errorperbit, macroblockd::mi, AV1_COMP::mt_info, AV1_COMP::oxcf, SPEED_FEATURES::part_sf, MB_MODE_INFO::partition, macroblockd::plane, macroblock::plane, macroblock_plane::qcoeff, macroblock::rdmult, AV1Common::seg, MB_MODE_INFO::segment_id, AV1Common::seq_params, AV1_COMP::sf, MB_MODE_INFO::skip_mode, MB_MODE_INFO::skip_txfm, macroblock::source_variance, macroblock_plane::src, macroblockd::tx_type_map, TxfmSearchInfo::tx_type_map_, macroblockd::tx_type_map_stride, macroblock_plane::txb_entropy_ctx, and macroblock::txfm_search_info.

Referenced by av1_rd_use_partition().

◆ encode_b()

static void encode_b ( const AV1_COMP *const cpi,
TileDataEnc * tile_data,
ThreadData * td,
TokenExtra ** tp,
int mi_row,
int mi_col,
RUN_TYPE dry_run,
BLOCK_SIZE bsize,
PARTITION_TYPE partition,
PICK_MODE_CONTEXT *const ctx,
int * rate )
static

Reconstructs an individual coding block.

Reconstructs an individual coding block by applying the chosen modes stored in ctx, also updates mode counts and entropy models.

Parameters
[in]cpiTop-level encoder structure
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding
[in]tdPointer to thread data
[in]tpPointer to the starting token
[in]mi_rowRow coordinate of the block in a step size of MI_SIZE
[in]mi_colColumn coordinate of the block in a step size of MI_SIZE
[in]dry_runA code indicating whether it is part of the final pass for reconstructing the superblock
[in]bsizeCurrent block size
[in]partitionPartition mode of the parent block
[in]ctxPointer to structure holding coding contexts and the chosen modes for the current block
[in]ratePointer to the total rate for the current block
Remarks
Nothing is returned. Instead, reconstructions (w/o in-loop filters) will be updated in the pixel buffers in td->mb.e_mbd. Also, the chosen modes will be stored in the MB_MODE_INFO buffer td->mb.e_mbd.mi[0].

References FeatureFlags::allow_warped_motion, MB_MODE_INFO_EXT_FRAME::cb_offset, macroblock::cb_offset, AV1_COMP::common, MB_MODE_INFO::comp_group_idx, MB_MODE_INFO::compound_idx, macroblockd::current_base_qindex, AV1Common::current_frame, MB_MODE_INFO::current_qindex, MB_MODE_INFO::delta_lf, macroblockd::delta_lf, MB_MODE_INFO::delta_lf_from_base, macroblockd::delta_lf_from_base, AV1Common::delta_q_info, macroblock::e_mbd, AV1Common::features, macroblockd::global_motion, SPEED_FEATURES::inter_sf, MB_MODE_INFO::interinter_comp, macroblock::mbmi_ext, macroblock::mbmi_ext_frame, macroblockd::mi, MB_MODE_INFO::motion_mode, MB_MODE_INFO::partition, macroblock::rdmult, MB_MODE_INFO::ref_frame, AV1Common::seg, MB_MODE_INFO::segment_id, AV1Common::seq_params, AV1_COMP::sf, MB_MODE_INFO::skip_mode, MB_MODE_INFO::skip_txfm, and FeatureFlags::switchable_motion_mode.

Referenced by encode_sb().

◆ encode_sb()

static void encode_sb ( const AV1_COMP *const cpi,
ThreadData * td,
TileDataEnc * tile_data,
TokenExtra ** tp,
int mi_row,
int mi_col,
RUN_TYPE dry_run,
BLOCK_SIZE bsize,
PC_TREE * pc_tree,
int * rate )
static

Reconstructs a partition (may contain multiple coding blocks)

Reconstructs a sub-partition of the superblock by applying the chosen modes and partition trees stored in pc_tree.

Parameters
[in]cpiTop-level encoder structure
[in]tdPointer to thread data
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding
[in]tpPointer to the starting token
[in]mi_rowRow coordinate of the block in a step size of MI_SIZE
[in]mi_colColumn coordinate of the block in a step size of MI_SIZE
[in]dry_runA code indicating whether it is part of the final pass for reconstructing the superblock
[in]bsizeCurrent block size
[in]pc_treePointer to the PC_TREE node storing the picked partitions and mode info for the current block
[in]ratePointer to the total rate for the current block
Remarks
Nothing is returned. Instead, reconstructions (w/o in-loop filters) will be updated in the pixel buffers in td->mb.e_mbd.

References AV1_COMP::common, macroblock::e_mbd, encode_b(), encode_sb(), CommonModeInfoParams::mi_cols, AV1Common::mi_params, CommonModeInfoParams::mi_rows, and macroblockd::tile_ctx.

Referenced by av1_rd_pick_partition(), av1_rd_use_partition(), and encode_sb().

◆ av1_rd_use_partition()

void av1_rd_use_partition ( AV1_COMP * cpi,
ThreadData * td,
TileDataEnc * tile_data,
MB_MODE_INFO ** mib,
TokenExtra ** tp,
int mi_row,
int mi_col,
BLOCK_SIZE bsize,
int * rate,
int64_t * dist,
int do_recon,
PC_TREE * pc_tree )

AV1 block partition search (partition estimation and partial search).

Encode the block by applying pre-calculated partition patterns that are represented by coding block sizes stored in the mbmi array. Minor partition adjustments are tested and applied if they lead to lower rd costs. The partition types are limited to a basic set: none, horz, vert, and split.

Parameters
[in]cpiTop-level encoder structure
[in]tdPointer to thread data
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding
[in]mibArray representing MB_MODE_INFO pointers for mi blocks starting from the first pixel of the current block
[in]tpPointer to the starting token
[in]mi_rowRow coordinate of the block in a step size of MI_SIZE
[in]mi_colColumn coordinate of the block in a step size of MI_SIZE
[in]bsizeCurrent block size
[in]ratePointer to the final rate for encoding the current block
[in]distPointer to the final distortion of the current block
[in]do_reconWhether the reconstruction function needs to be run, either for finalizing a superblock or providing reference for future sub-partitions
[in]pc_treePointer to the PC_TREE node holding the picked partitions and mode info for the current block
Remarks
Nothing is returned. The pc_tree struct is modified to store the picked partition and modes. The rate and dist are also updated with those corresponding to the best partition found.

References AV1Common::above_contexts, macroblockd::above_txfm_context, AOM_CODEC_MEM_ERROR, av1_rd_use_partition(), MB_MODE_INFO::bsize, macroblock::cb_offset, AV1_COMP::common, macroblock::e_mbd, encode_sb(), macroblockd::error_info, macroblockd::left_txfm_context, macroblockd::left_txfm_context_buffer, macroblock::mb_energy, CommonModeInfoParams::mi_cols, AV1Common::mi_params, CommonModeInfoParams::mi_rows, CommonModeInfoParams::mi_stride, macroblock::mode_costs, SPEED_FEATURES::part_sf, ModeCosts::partition_cost, pick_sb_modes(), macroblock::rdmult, AV1Common::seq_params, AV1_COMP::sf, macroblock::try_merge_partition, CommonContexts::txfm, and AV1_COMP::vaq_refresh.

Referenced by av1_rd_use_partition(), and encode_rd_sb().

◆ pick_sb_modes_nonrd()

static void pick_sb_modes_nonrd ( AV1_COMP *const cpi,
TileDataEnc * tile_data,
MACROBLOCK *const x,
int mi_row,
int mi_col,
RD_STATS * rd_cost,
BLOCK_SIZE bsize,
PICK_MODE_CONTEXT * ctx )
static

Top level function to pick block mode for non-RD optimized case.

Searches prediction modes, transform, and coefficient coding modes for an individual coding block. This function is the top-level function that is used for non-RD optimized mode search (controlled by cpi->sf.rt_sf.use_nonrd_pick_mode). Depending on frame type it calls inter/skip/hybrid-intra mode search functions

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]mi_rowRow coordinate of the block in a step size of MI_SIZE
[in]mi_colColumn coordinate of the block in a step size of MI_SIZE
[in]rd_costPointer to structure holding rate and distortion stats for the current block
[in]bsizeCurrent block size
[in]ctxPointer to structure holding coding contexts and chosen modes for the current block
Remarks
Nothing is returned. Instead, the chosen modes and contexts necessary for reconstruction are stored in ctx, the rate-distortion stats are stored in rd_cost. If no valid mode leading to rd_cost <= best_rd, the status will be signalled by an INT64_MAX rd_cost->rdcost.

< Y (Luminance) plane

< U (Chroma) plane

< V (Chroma) plane

References AOM_PLANE_U, AOM_PLANE_V, AOM_PLANE_Y, av1_nonrd_pick_inter_mode_sb(), MB_MODE_INFO::cdef_strength, macroblock_plane::coeff, COLOR_SENS_IDX, macroblock::color_sensitivity, AV1_COMP::common, macroblock_plane::dqcoeff, macroblock::e_mbd, MultiThreadInfo::enc_row_mt, macroblock_plane::eobs, macroblock::errorperbit, macroblock::force_zeromv_skip_for_blk, hybrid_intra_mode_search(), macroblock::last_set_offsets_loc, macroblockd::mi, CommonModeInfoParams::mi_grid_base, AV1Common::mi_params, MB_MODE_INFO::mode, AV1_COMP::mt_info, AV1_COMP::oxcf, macroblockd::plane, macroblock::plane, macroblock_plane::qcoeff, AV1_COMP::rc, macroblock::rdmult, SPEED_FEATURES::rt_sf, AV1Common::seg, MB_MODE_INFO::segment_id, AV1Common::seq_params, AV1_COMP::sf, macroblock::source_variance, macroblock_plane::src, macroblockd::tx_type_map, TxfmSearchInfo::tx_type_map_, macroblockd::tx_type_map_stride, macroblock_plane::txb_entropy_ctx, and macroblock::txfm_search_info.

Referenced by av1_nonrd_use_partition().

◆ av1_nonrd_use_partition()

void av1_nonrd_use_partition ( AV1_COMP * cpi,
ThreadData * td,
TileDataEnc * tile_data,
MB_MODE_INFO ** mib,
TokenExtra ** tp,
int mi_row,
int mi_col,
BLOCK_SIZE bsize,
PC_TREE * pc_tree )

AV1 block partition application (minimal RD search).

Encode the block by applying pre-calculated partition patterns that are represented by coding block sizes stored in the mbmi array. The only partition adjustment allowed is merging leaf split nodes if it leads to a lower rd cost. The partition types are limited to a basic set: none, horz, vert, and split. This function is only used in the real-time mode.

Parameters
[in]cpiTop-level encoder structure
[in]tdPointer to thread data
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding
[in]mibArray representing MB_MODE_INFO pointers for mi blocks starting from the first pixel of the current block
[in]tpPointer to the starting token
[in]mi_rowRow coordinate of the block in a step size of MI_SIZE
[in]mi_colColumn coordinate of the block in a step size of MI_SIZE
[in]bsizeCurrent block size
[in]pc_treePointer to the PC_TREE node holding the picked partitions and mode info for the current block
Remarks
Nothing is returned. The pc_tree struct is modified to store the picked partition and modes.

References AV1Common::above_contexts, macroblockd::above_txfm_context, AOM_CODEC_MEM_ERROR, av1_nonrd_use_partition(), AV1_COMP::common, macroblock::e_mbd, macroblockd::error_info, macroblockd::left_txfm_context, macroblockd::left_txfm_context_buffer, CommonModeInfoParams::mi_cols, AV1Common::mi_params, CommonModeInfoParams::mi_rows, CommonModeInfoParams::mi_stride, macroblock::mode_costs, ModeCosts::partition_cost, pick_sb_modes_nonrd(), macroblock::reuse_inter_pred, SPEED_FEATURES::rt_sf, AV1_COMP::sf, and CommonContexts::txfm.

Referenced by av1_nonrd_use_partition(), and encode_nonrd_sb().

◆ av1_rd_pick_partition()

bool av1_rd_pick_partition ( AV1_COMP *const cpi,
ThreadData * td,
TileDataEnc * tile_data,
TokenExtra ** tp,
int mi_row,
int mi_col,
BLOCK_SIZE bsize,
RD_STATS * rd_cost,
RD_STATS best_rdc,
PC_TREE * pc_tree,
SIMPLE_MOTION_DATA_TREE * sms_tree,
int64_t * none_rd,
SB_MULTI_PASS_MODE multi_pass_mode,
RD_RECT_PART_WIN_INFO * rect_part_win_info )

AV1 block partition search (full search).

Searches for the best partition pattern for a block based on the rate-distortion cost, and returns a bool value to indicate whether a valid partition pattern is found. The partition can recursively go down to the smallest block size.

Parameters
[in]cpiTop-level encoder structure
[in]tdPointer to thread data
[in]tile_dataPointer to struct holding adaptive data/contexts/models for the tile during encoding
[in]tpPointer to the starting token
[in]mi_rowRow coordinate of the block in a step size of MI_SIZE
[in]mi_colColumn coordinate of the block in a step size of MI_SIZE
[in]bsizeCurrent block size
[in]rd_costPointer to the final rd cost of the block
[in]best_rdcUpper bound of rd cost of a valid partition
[in]pc_treePointer to the PC_TREE node storing the picked partitions and mode info for the current block
[in]sms_treePointer to struct holding simple motion search data for the current block
[in]none_rdPointer to the rd cost in the case of not splitting the current block
[in]multi_pass_modeSB_SINGLE_PASS/SB_DRY_PASS/SB_WET_PASS
[in]rect_part_win_infoPointer to struct storing whether horz/vert partition outperforms previously tested partitions
Returns
A bool value is returned indicating if a valid partition is found. The pc_tree struct is modified to store the picked partition and modes. The rd_cost struct is also updated with the RD stats corresponding to the best partition found.

< Y (Luminance) plane

References AV1Common::above_contexts, macroblockd::above_txfm_context, AOM_PLANE_Y, TxfmSearchInfo::blk_skip, macroblock::cb_offset, AV1_COMP::common, AV1Common::current_frame, macroblock::e_mbd, encode_sb(), AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, macroblock::intra_sb_rdmult_modifier, macroblockd::left_txfm_context, macroblockd::left_txfm_context_buffer, SuperBlockEnc::max_partition_size, macroblock::mb_energy, macroblock::must_find_valid_partition, AV1_COMP::oxcf, SPEED_FEATURES::part_sf, macroblock::plane, AV1_COMP::ppi, macroblock::qindex, macroblock::rdmult, AV1_COMP::sb_counter, macroblock::sb_enc, AV1Common::seq_params, AV1_COMP::sf, AV1Common::show_frame, AV1_COMP::source, macroblock_plane::src, CommonContexts::txfm, macroblock::txfm_search_info, and AV1_COMP::vaq_refresh.

Referenced by encode_rd_sb().