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

/*
 * 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.
 */

#ifndef AOM_AV1_ENCODER_RD_H_
#define AOM_AV1_ENCODER_RD_H_

#include <limits.h>

#include "av1/common/blockd.h"

#include "av1/encoder/block.h"
#include "av1/encoder/context_tree.h"
#include "av1/encoder/cost.h"
#include "av1/encoder/ratectrl.h"
#include "config/aom_config.h"

#ifdef __cplusplus
extern "C" {
#endif

#define RDDIV_BITS
#define RD_EPB_SHIFT

#define RDCOST(RM, R, D)

#define RDCOST_NEG_R(RM, R, D)

#define RDCOST_DBL_WITH_NATIVE_BD_DIST(RM, R, D, BD)

#define QIDX_SKIP_THRESH

#define MV_COST_WEIGHT
#define MV_COST_WEIGHT_SUB

// The fractional part of rd_thresh factor is stored with 5 bits. The maximum
// factor that we allow is two, which is stored as 2 ** (5+1) = 64
#define RD_THRESH_FAC_FRAC_BITS
#define RD_THRESH_FAC_FRAC_VAL
#define RD_THRESH_MAX_FACT
#define RD_THRESH_LOG_DEC_FACTOR
#define RD_THRESH_INC

// Factor to weigh the rate for switchable interp filters.
#define SWITCHABLE_INTERP_RATE_FACTOR

// Macros for common video resolutions: width x height
// For example, 720p represents video resolution of 1280x720 pixels.
#define RESOLUTION_288P
#define RESOLUTION_360P
#define RESOLUTION_480P
#define RESOLUTION_720P
#define RESOLUTION_1080P
#define RESOLUTION_1440P
#define RESOLUTION_4K

#define RTC_REFS
static const MV_REFERENCE_FRAME real_time_ref_combos[RTC_REFS][2] =;

static inline int mode_offset(const PREDICTION_MODE mode) {}

enum {} UENUM1BYTE();

RD_OPT;

static inline void av1_init_rd_stats(RD_STATS *rd_stats) {}

static inline void av1_invalid_rd_stats(RD_STATS *rd_stats) {}

static inline void av1_merge_rd_stats(RD_STATS *rd_stats_dst,
                                      const RD_STATS *rd_stats_src) {}

static inline void av1_accumulate_rd_stats(RD_STATS *rd_stats, int64_t dist,
                                           int rate, int skip_txfm, int64_t sse,
                                           int zero_rate) {}

static inline int64_t av1_calculate_rd_cost(int mult, int rate, int64_t dist) {}

static inline void av1_rd_cost_update(int mult, RD_STATS *rd_cost) {}

static inline void av1_rd_stats_subtraction(int mult,
                                            const RD_STATS *const left,
                                            const RD_STATS *const right,
                                            RD_STATS *result) {}

struct TileInfo;
struct TileDataEnc;
struct AV1_COMP;
struct macroblock;

/*!\brief Compute rdmult based on q index and frame update type
 *
 * \param[in]       bit_depth       bit depth
 * \param[in]       update_type     frame update type
 * \param[in]       qindex          q index
 *
 * \return rdmult
 */
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);

void av1_initialize_rd_consts(struct AV1_COMP *cpi);

// Sets the multiplier to convert mv cost to l1 error during motion search.
void av1_set_sad_per_bit(const struct AV1_COMP *cpi, int *sadperbit,
                         int qindex);

void av1_model_rd_from_var_lapndz(int64_t var, unsigned int n,
                                  unsigned int qstep, int *rate, int64_t *dist);

void av1_model_rd_curvfit(BLOCK_SIZE bsize, double sse_norm, double xqr,
                          double *rate_f, double *distbysse_f);

int av1_get_switchable_rate(const MACROBLOCK *x, const MACROBLOCKD *xd,
                            InterpFilter interp_filter, int dual_filter);

YV12_BUFFER_CONFIG *av1_get_scaled_ref_frame(const struct AV1_COMP *cpi,
                                             int ref_frame);

void av1_init_me_luts(void);

void av1_set_mvcost(MACROBLOCK *x, int ref, int ref_mv_idx);

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]);

void av1_set_rd_speed_thresholds(struct AV1_COMP *cpi);

void av1_update_rd_thresh_fact(const AV1_COMMON *const cm,
                               int (*fact)[MAX_MODES], int 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);

static inline void reset_thresh_freq_fact(MACROBLOCK *const x) {}

static inline int rd_less_than_thresh(int64_t best_rd, int64_t thresh,
                                      int thresh_fact) {}

void av1_mv_pred(const struct AV1_COMP *cpi, MACROBLOCK *x,
                 uint8_t *ref_y_buffer, int ref_y_stride, int ref_frame,
                 BLOCK_SIZE block_size);

// Sets the multiplier to convert mv cost to l2 error during motion search.
static inline void av1_set_error_per_bit(int *errorperbit, int rdmult) {}

// Get the threshold for R-D optimization of coefficients depending upon mode
// decision/winner mode processing
static inline void get_rd_opt_coeff_thresh(
    const uint32_t (*const coeff_opt_threshold)[2],
    TxfmSearchParams *txfm_params, int enable_winner_mode_for_coeff_opt,
    int is_winner_mode) {}

// Used to reset the state of mb rd hash information
static inline void reset_mb_rd_record(MB_RD_RECORD *const mb_rd_record) {}

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);

int av1_get_intra_cost_penalty(int qindex, int qdelta,
                               aom_bit_depth_t bit_depth);

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);
#endif

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);

#if !CONFIG_REALTIME_ONLY
int av1_get_adaptive_rdmult(const struct AV1_COMP *cpi, double beta);
#endif

int av1_get_deltaq_offset(aom_bit_depth_t bit_depth, int qindex, double beta);

/*!\brief Adjust current superblock's q_index based on delta q resolution
 *
 * \param[in]       delta_q_res       delta q resolution
 * \param[in]       prev_qindex       previous superblock's q index
 * \param[in]       curr_qindex       current superblock's q index
 *
 * \return the current superblock's adjusted q_index
 */
int av1_adjust_q_from_delta_q_res(int delta_q_res, int prev_qindex,
                                  int curr_qindex);

#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // AOM_AV1_ENCODER_RD_H_