#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include "aom_dsp/aom_dsp_common.h"
#include "aom_mem/aom_mem.h"
#include "aom_ports/bitops.h"
#include "aom_ports/mem.h"
#include "aom_ports/aom_once.h"
#include "av1/common/common.h"
#include "av1/common/entropy.h"
#include "av1/common/entropymode.h"
#include "av1/common/pred_common.h"
#include "av1/common/quant_common.h"
#include "av1/common/reconinter.h"
#include "av1/common/reconintra.h"
#include "av1/common/seg_common.h"
#include "av1/encoder/cost.h"
#include "av1/encoder/encodemv.h"
#include "av1/encoder/encoder.h"
#include "av1/encoder/nonrd_opt.h"
#include "av1/encoder/ratectrl.h"
#include "av1/encoder/rd.h"
#include "config/aom_config.h"
#define RD_THRESH_POW …
static const uint8_t rd_thresh_block_size_factor[BLOCK_SIZES_ALL] = …;
static const int use_intra_ext_tx_for_txsize[EXT_TX_SETS_INTRA]
[EXT_TX_SIZES] = …;
static const int use_inter_ext_tx_for_txsize[EXT_TX_SETS_INTER]
[EXT_TX_SIZES] = …;
static const int av1_ext_tx_set_idx_to_type[2][AOMMAX(EXT_TX_SETS_INTRA,
EXT_TX_SETS_INTER)] = …;
void av1_fill_mode_rates(AV1_COMMON *const cm, ModeCosts *mode_costs,
FRAME_CONTEXT *fc) { … }
#if !CONFIG_REALTIME_ONLY
void av1_fill_lr_rates(ModeCosts *mode_costs, FRAME_CONTEXT *fc) {
av1_cost_tokens_from_cdf(mode_costs->switchable_restore_cost,
fc->switchable_restore_cdf, NULL);
av1_cost_tokens_from_cdf(mode_costs->wiener_restore_cost,
fc->wiener_restore_cdf, NULL);
av1_cost_tokens_from_cdf(mode_costs->sgrproj_restore_cost,
fc->sgrproj_restore_cdf, NULL);
}
#endif
static int sad_per_bit_lut_8[QINDEX_RANGE];
static int sad_per_bit_lut_10[QINDEX_RANGE];
static int sad_per_bit_lut_12[QINDEX_RANGE];
static void init_me_luts_bd(int *bit16lut, int range,
aom_bit_depth_t bit_depth) { … }
static void init_me_luts(void) { … }
void av1_init_me_luts(void) { … }
static const int rd_boost_factor[16] = …;
static const int rd_layer_depth_factor[7] = …;
static double def_inter_rd_multiplier(int qindex) { … }
static double def_arf_rd_multiplier(int qindex) { … }
static double def_kf_rd_multiplier(int qindex) { … }
int av1_compute_rd_mult_based_on_qindex(aom_bit_depth_t bit_depth,
FRAME_UPDATE_TYPE update_type,
int qindex) { … }
int av1_compute_rd_mult(const int qindex, const aom_bit_depth_t bit_depth,
const FRAME_UPDATE_TYPE update_type,
const int layer_depth, const int boost_index,
const FRAME_TYPE frame_type,
const int use_fixed_qp_offsets,
const int is_stat_consumption_stage) { … }
int av1_get_deltaq_offset(aom_bit_depth_t bit_depth, int qindex, double beta) { … }
int av1_adjust_q_from_delta_q_res(int delta_q_res, int prev_qindex,
int curr_qindex) { … }
#if !CONFIG_REALTIME_ONLY
int av1_get_adaptive_rdmult(const AV1_COMP *cpi, double beta) {
assert(beta > 0.0);
const AV1_COMMON *cm = &cpi->common;
const GF_GROUP *const gf_group = &cpi->ppi->gf_group;
const int boost_index = AOMMIN(15, (cpi->ppi->p_rc.gfu_boost / 100));
const int layer_depth = AOMMIN(gf_group->layer_depth[cpi->gf_frame_index], 6);
const FRAME_TYPE frame_type = cm->current_frame.frame_type;
const int qindex_rdmult = cm->quant_params.base_qindex;
return (int)(av1_compute_rd_mult(
qindex_rdmult, cm->seq_params->bit_depth,
cpi->ppi->gf_group.update_type[cpi->gf_frame_index],
layer_depth, boost_index, frame_type,
cpi->oxcf.q_cfg.use_fixed_qp_offsets,
is_stat_consumption_stage(cpi)) /
beta);
}
#endif
static int compute_rd_thresh_factor(int qindex, aom_bit_depth_t bit_depth) { … }
void av1_set_sad_per_bit(const AV1_COMP *cpi, int *sadperbit, int qindex) { … }
static void set_block_thresholds(const AV1_COMMON *cm, RD_OPT *rd,
int use_nonrd_pick_mode) { … }
void av1_fill_coeff_costs(CoeffCosts *coeff_costs, FRAME_CONTEXT *fc,
const int num_planes) { … }
void av1_fill_mv_costs(const nmv_context *nmvc, int integer_mv, int usehp,
MvCosts *mv_costs) { … }
void av1_fill_dv_costs(const nmv_context *ndvc, IntraBCMVCosts *dv_costs) { … }
static inline void populate_unified_cost_update_freq(
const CostUpdateFreq cost_upd_freq, SPEED_FEATURES *const sf) { … }
static inline int is_frame_level_cost_upd_freq_set(
const AV1_COMMON *const cm, const INTERNAL_COST_UPDATE_TYPE cost_upd_level,
const int use_nonrd_pick_mode, const int frames_since_key) { … }
static inline int should_force_mode_cost_update(const AV1_COMP *cpi) { … }
void av1_initialize_rd_consts(AV1_COMP *cpi) { … }
static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { … }
void av1_model_rd_from_var_lapndz(int64_t var, unsigned int n_log2,
unsigned int qstep, int *rate,
int64_t *dist) { … }
static double interp_cubic(const double *p, double x) { … }
static const uint8_t bsize_curvfit_model_cat_lookup[BLOCK_SIZES_ALL] = …;
static int sse_norm_curvfit_model_cat_lookup(double sse_norm) { … }
static const double interp_rgrid_curv[4][65] = …;
static const double interp_dgrid_curv[3][65] = …;
void av1_model_rd_curvfit(BLOCK_SIZE bsize, double sse_norm, double xqr,
double *rate_f, double *distbysse_f) { … }
static void get_entropy_contexts_plane(BLOCK_SIZE plane_bsize,
const struct macroblockd_plane *pd,
ENTROPY_CONTEXT t_above[MAX_MIB_SIZE],
ENTROPY_CONTEXT t_left[MAX_MIB_SIZE]) { … }
void av1_get_entropy_contexts(BLOCK_SIZE plane_bsize,
const struct macroblockd_plane *pd,
ENTROPY_CONTEXT t_above[MAX_MIB_SIZE],
ENTROPY_CONTEXT t_left[MAX_MIB_SIZE]) { … }
static inline void enc_clamp_mv(const AV1_COMMON *cm, const MACROBLOCKD *xd,
MV *mv) { … }
void av1_mv_pred(const AV1_COMP *cpi, MACROBLOCK *x, uint8_t *ref_y_buffer,
int ref_y_stride, int ref_frame, BLOCK_SIZE block_size) { … }
void av1_setup_pred_block(const MACROBLOCKD *xd,
struct buf_2d dst[MAX_MB_PLANE],
const YV12_BUFFER_CONFIG *src,
const struct scale_factors *scale,
const struct scale_factors *scale_uv,
const int num_planes) { … }
YV12_BUFFER_CONFIG *av1_get_scaled_ref_frame(const AV1_COMP *cpi,
int ref_frame) { … }
int av1_get_switchable_rate(const MACROBLOCK *x, const MACROBLOCKD *xd,
InterpFilter interp_filter, int dual_filter) { … }
void av1_set_rd_speed_thresholds(AV1_COMP *cpi) { … }
static inline void update_thr_fact(int (*factor_buf)[MAX_MODES],
THR_MODES best_mode_index,
THR_MODES mode_start, THR_MODES mode_end,
BLOCK_SIZE min_size, BLOCK_SIZE max_size,
int max_rd_thresh_factor) { … }
void av1_update_rd_thresh_fact(
const AV1_COMMON *const cm, int (*factor_buf)[MAX_MODES],
int use_adaptive_rd_thresh, BLOCK_SIZE bsize, THR_MODES best_mode_index,
THR_MODES inter_mode_start, THR_MODES inter_mode_end,
THR_MODES intra_mode_start, THR_MODES intra_mode_end) { … }
int av1_get_intra_cost_penalty(int qindex, int qdelta,
aom_bit_depth_t bit_depth) { … }