chromium/third_party/libaom/source/libaom/av1/encoder/rd.c

/*
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#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

// The baseline rd thresholds for breaking out of the rd loop for
// certain modes are assumed to be based on 8x8 blocks.
// This table is used to correct for block size.
// The factors here are << 2 (2 = x0.5, 32 = x8 etc).
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  // !CONFIG_REALTIME_ONLY

// Values are now correlated to quantizer.
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] =;

// Returns the default rd multiplier for inter frames for a given qindex.
// The function here is a first pass estimate based on data from
// a previous Vizer run
static double def_inter_rd_multiplier(int qindex) {}

// Returns the default rd multiplier for ARF/Golden Frames for a given qindex.
// The function here is a first pass estimate based on data from
// a previous Vizer run
static double def_arf_rd_multiplier(int qindex) {}

// Returns the default rd multiplier for key frames for a given qindex.
// The function here is a first pass estimate based on data from
// a previous Vizer run
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  // !CONFIG_REALTIME_ONLY

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) {}

// Populates speed features based on codec control settings (of type
// COST_UPDATE_TYPE) and expected speed feature settings (of type
// INTERNAL_COST_UPDATE_TYPE) by considering the least frequent cost update.
// The populated/updated speed features are used for cost updates in the
// encoder.
// WARNING: Population of unified cost update frequency needs to be taken care
// accordingly, in case of any modifications/additions to the enum
// COST_UPDATE_TYPE/INTERNAL_COST_UPDATE_TYPE.
static inline void populate_unified_cost_update_freq(
    const CostUpdateFreq cost_upd_freq, SPEED_FEATURES *const sf) {}

// Checks if entropy costs should be initialized/updated at frame level or not.
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) {}

// Decide whether we want to update the mode entropy cost for the current frame.
// The logit is currently inherited from selective_disable_cdf_rtc.
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 double interp_bicubic(const double *p, int p_stride, double x,
                             double y) {
  double q[4];
  q[0] = interp_cubic(p, x);
  q[1] = interp_cubic(p + p_stride, x);
  q[2] = interp_cubic(p + 2 * p_stride, x);
  q[3] = interp_cubic(p + 3 * p_stride, x);
  return interp_cubic(q, y);
}
*/

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]) {}

// Special clamping used in the encoder when calculating a prediction
//
// Logically, all pixel fetches used for prediction are clamped against the
// edges of the frame. But doing this directly is slow, so instead we allocate
// a finite border around the frame and fill it with copies of the outermost
// pixels.
//
// Since this border is finite, we need to clamp the motion vector before
// prediction in order to avoid out-of-bounds reads. At the same time, this
// clamp must not change the prediction result.
//
// We can balance both of these concerns by calculating how far we would have
// to go in each direction before the extended prediction region (the current
// block + AOM_INTERP_EXTEND many pixels around the block) would be mapped
// so that it touches the frame only at one row or column. This is a special
// point because any more extreme MV will always lead to the same prediction.
// So it is safe to clamp at that point.
//
// In the worst case, this requires a border of
//   max_block_width + 2*AOM_INTERP_EXTEND = 128 + 2*4 = 136 pixels
// around the frame edges.
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) {}