12#ifndef AOM_AV1_ENCODER_RDOPT_H_
13#define AOM_AV1_ENCODER_RDOPT_H_
17#include "av1/common/blockd.h"
18#include "av1/common/txb_common.h"
21#include "av1/encoder/context_tree.h"
23#include "av1/encoder/encodetxb.h"
24#include "av1/encoder/rdopt_utils.h"
30#define COMP_TYPE_RD_THRESH_SCALE 11
31#define COMP_TYPE_RD_THRESH_SHIFT 4
32#define MAX_WINNER_MOTION_MODES 10
63 struct RD_STATS *rd_cost, BLOCK_SIZE bsize,
64 PICK_MODE_CONTEXT *ctx, int64_t best_rd);
94 struct macroblock *x,
struct RD_STATS *rd_cost,
95 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx,
96 int64_t best_rd_so_far);
124 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx);
156 struct TileDataEnc *tile_data,
158 struct RD_STATS *rd_cost, BLOCK_SIZE bsize,
159 PICK_MODE_CONTEXT *ctx);
161void av1_rd_pick_inter_mode_sb_seg_skip(
162 const struct AV1_COMP *cpi,
struct TileDataEnc *tile_data,
163 struct macroblock *x,
int mi_row,
int mi_col,
struct RD_STATS *rd_cost,
164 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, int64_t best_rd_so_far);
166void av1_inter_mode_data_init(
struct TileDataEnc *tile_data);
167void av1_inter_mode_data_fit(TileDataEnc *tile_data,
int rdmult);
170 int mi_col, RD_STATS *this_rdc,
int *skippable,
171 BLOCK_SIZE bsize, TX_SIZE tx_size, TX_TYPE tx_type,
174static INLINE
int coded_to_superres_mi(
int mi_col,
int denom) {
175 return (mi_col * denom + SCALE_NUMERATOR / 2) / SCALE_NUMERATOR;
178static INLINE
int av1_encoder_get_relative_dist(
int a,
int b) {
179 assert(a >= 0 && b >= 0);
184static INLINE
int av1_get_sb_mi_size(
const AV1_COMMON *
const cm) {
187 (mi_size_wide[cm->
seq_params->sb_size] + mi_alloc_size_1d - 1) /
189 assert(mi_size_wide[cm->
seq_params->sb_size] ==
191 int sb_mi_size = sb_mi_rows * sb_mi_rows;
198static INLINE
int prune_ref(
const MV_REFERENCE_FRAME *
const ref_frame,
199 const unsigned int *
const ref_display_order_hint,
200 const unsigned int frame_display_order_hint,
201 const int *ref_frame_list) {
202 for (
int i = 0; i < 2; i++) {
203 if (ref_frame_list[i] == NONE_FRAME)
continue;
205 if (ref_frame[0] == ref_frame_list[i] ||
206 ref_frame[1] == ref_frame_list[i]) {
207 if (av1_encoder_get_relative_dist(
208 ref_display_order_hint[ref_frame_list[i] - LAST_FRAME],
209 frame_display_order_hint) < 0)
216static INLINE
int has_closest_ref_frames(
const MV_REFERENCE_FRAME *ref_frame,
217 int8_t closest_past_ref,
218 int8_t closest_future_ref) {
219 int has_closest_past_ref =
220 (ref_frame[0] == closest_past_ref) || (ref_frame[1] == closest_past_ref);
221 int has_closest_future_ref = (ref_frame[0] == closest_future_ref) ||
222 (ref_frame[1] == closest_future_ref);
223 return (has_closest_past_ref && has_closest_future_ref);
226static INLINE
int has_best_pred_mv_sad(
const MV_REFERENCE_FRAME *ref_frame,
228 int has_best_past_pred_mv_sad = 0;
229 int has_best_future_pred_mv_sad = 0;
231 has_best_past_pred_mv_sad =
234 has_best_future_pred_mv_sad =
238 return (has_best_past_pred_mv_sad && has_best_future_pred_mv_sad);
241static INLINE
int prune_ref_by_selective_ref_frame(
242 const AV1_COMP *
const cpi,
const MACROBLOCK *
const x,
243 const MV_REFERENCE_FRAME *
const ref_frame,
244 const unsigned int *
const ref_display_order_hint) {
246 if (!sf->
inter_sf.selective_ref_frame)
return 0;
248 const int comp_pred = ref_frame[1] > INTRA_FRAME;
250 if (sf->
inter_sf.selective_ref_frame >= 2 ||
251 (sf->
inter_sf.selective_ref_frame == 1 && comp_pred)) {
252 int ref_frame_list[2] = { LAST3_FRAME, LAST2_FRAME };
259 ref_frame_list[0] = NONE_FRAME;
263 ref_frame_list[1] = NONE_FRAME;
267 if (prune_ref(ref_frame, ref_display_order_hint,
268 ref_display_order_hint[GOLDEN_FRAME - LAST_FRAME],
273 if (sf->
inter_sf.selective_ref_frame >= 3) {
274 int ref_frame_list[2] = { ALTREF2_FRAME, BWDREF_FRAME };
281 ref_frame_list[0] = NONE_FRAME;
285 ref_frame_list[1] = NONE_FRAME;
289 if (prune_ref(ref_frame, ref_display_order_hint,
290 ref_display_order_hint[LAST_FRAME - LAST_FRAME],
295 if (x != NULL && sf->
inter_sf.prune_comp_ref_frames && comp_pred) {
296 int closest_ref_frames = has_closest_ref_frames(
297 ref_frame, cpi->ref_frame_dist_info.nearest_past_ref,
298 cpi->ref_frame_dist_info.nearest_future_ref);
299 if (closest_ref_frames == 0) {
301 if (sf->
inter_sf.prune_comp_ref_frames >= 2) {
303 }
else if (sf->
inter_sf.prune_comp_ref_frames == 1) {
305 if (has_best_pred_mv_sad(ref_frame, x) == 0)
return 1;
315static INLINE
void av1_copy_mbmi_ext_to_mbmi_ext_frame(
319 sizeof(mbmi_ext->
ref_mv_stack[USABLE_REF_MV_STACK_SIZE]));
320 memcpy(mbmi_ext_best->
weight, mbmi_ext->
weight[ref_frame_type],
321 sizeof(mbmi_ext->
weight[USABLE_REF_MV_STACK_SIZE]));
Declares top-level encoder structures and functions.
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.
Definition: rdopt.c:5669
void av1_rd_pick_intra_mode_sb(const struct AV1_COMP *cpi, struct macroblock *x, struct RD_STATS *rd_cost, BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, int64_t best_rd)
AV1 intra mode selection for intra frames.
Definition: rdopt.c:3284
void av1_block_yrd(const AV1_COMP *const cpi, MACROBLOCK *x, int mi_row, int mi_col, RD_STATS *this_rdc, int *skippable, BLOCK_SIZE bsize, TX_SIZE tx_size, TX_TYPE tx_type, int is_inter_mode)
Calculates RD Cost using Hadamard transform.
Definition: nonrd_pickmode.c:883
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.
Definition: nonrd_pickmode.c:2498
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.
Definition: nonrd_pickmode.c:1861
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:750
SequenceHeader * seq_params
Definition: av1_common_int.h:976
CommonModeInfoParams mi_params
Definition: av1_common_int.h:910
BLOCK_SIZE mi_alloc_bsize
Definition: av1_common_int.h:550
Stores best extended mode information at frame level.
Definition: block.h:212
uint8_t ref_mv_count
Number of ref mvs in the drl.
Definition: block.h:218
uint16_t weight[USABLE_REF_MV_STACK_SIZE]
The weights used to compute the ref mvs.
Definition: block.h:216
CANDIDATE_MV ref_mv_stack[USABLE_REF_MV_STACK_SIZE]
The reference mv list for the current block.
Definition: block.h:214
int16_t mode_context
Context used to encode the current mode.
Definition: block.h:223
int_mv global_mvs[REF_FRAMES]
Global mvs.
Definition: block.h:221
Extended mode info derived from mbmi.
Definition: block.h:192
int_mv global_mvs[REF_FRAMES]
Global mvs.
Definition: block.h:201
CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE]
The reference mv list for the current block.
Definition: block.h:195
uint16_t weight[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE]
The weights used to compute the ref mvs.
Definition: block.h:197
int16_t mode_context[MODE_CTX_REF_FRAMES]
Context used to encode the current mode.
Definition: block.h:203
uint8_t ref_mv_count[MODE_CTX_REF_FRAMES]
Number of ref mvs in the drl.
Definition: block.h:199
Top level speed vs quality trade off data struture.
Definition: speed_features.h:1528
INTER_MODE_SPEED_FEATURES inter_sf
Definition: speed_features.h:1562
Encoder's parameters related to the current coding block.
Definition: block.h:813
int best_pred_mv_sad[2]
The minimum of pred_mv_sad.
Definition: block.h:1024
int pred_mv_sad[REF_FRAMES]
Sum absolute distortion of the predicted mv for each ref frame.
Definition: block.h:1018
uint8_t tpl_keep_ref_frame[REF_FRAMES]
Disables certain ref frame pruning based on tpl.
Definition: block.h:1036