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

/*
 * Copyright (c) 2020, 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_ENCODEFRAME_UTILS_H_
#define AOM_AV1_ENCODER_ENCODEFRAME_UTILS_H_

#include "aom_ports/aom_timer.h"

#include "av1/common/reconinter.h"

#include "av1/encoder/encoder.h"
#include "av1/encoder/rdopt.h"

#ifdef __cplusplus
extern "C" {
#endif

#define WRITE_FEATURE_TO_FILE

#define FEATURE_SIZE_SMS_SPLIT_FAST
#define FEATURE_SIZE_SMS_SPLIT
#define FEATURE_SIZE_SMS_PRUNE_PART
#define FEATURE_SIZE_SMS_TERM_NONE
#define FEATURE_SIZE_FP_SMS_TERM_NONE
#define FEATURE_SIZE_MAX_MIN_PART_PRED
#define MAX_NUM_CLASSES_MAX_MIN_PART_PRED

#define FEATURE_SMS_NONE_FLAG
#define FEATURE_SMS_SPLIT_FLAG
#define FEATURE_SMS_RECT_FLAG

#define FEATURE_SMS_PRUNE_PART_FLAG
#define FEATURE_SMS_SPLIT_MODEL_FLAG

// Number of sub-partitions in rectangular partition types.
#define SUB_PARTITIONS_RECT

// Number of sub-partitions in split partition type.
#define SUB_PARTITIONS_SPLIT

// Number of sub-partitions in AB partition types.
#define SUB_PARTITIONS_AB

// Number of sub-partitions in 4-way partition types.
#define SUB_PARTITIONS_PART4

// 4part partition types.
enum {} UENUM1BYTE();

// AB partition types.
enum {} UENUM1BYTE();

// Rectangular partition types.
enum {} UENUM1BYTE();

// Structure to keep win flags for HORZ and VERT partition evaluations.
RD_RECT_PART_WIN_INFO;

enum {};

enum {} UENUM1BYTE();

RD_SEARCH_MACROBLOCK_CONTEXT;

// This struct is used to store the statistics used by sb-level multi-pass
// encoding. Currently, this is only used to make a copy of the state before we
// perform the first pass
SB_FIRST_PASS_STATS;

// This structure contains block size related
// variables for use in rd_pick_partition().
PartitionBlkParams;

#if CONFIG_COLLECT_PARTITION_STATS
typedef struct PartitionTimingStats {
  // Tracks the number of partition decision used in the current call to \ref
  // av1_rd_pick_partition
  int partition_decisions[EXT_PARTITION_TYPES];
  // Tracks the number of partition_block searched in the current call to \ref
  // av1_rd_pick_partition
  int partition_attempts[EXT_PARTITION_TYPES];
  // Tracks the time spent on each partition search in the current call to \ref
  // av1_rd_pick_partition
  int64_t partition_times[EXT_PARTITION_TYPES];
  // Tracks the rdcost spent on each partition search in the current call to
  // \ref av1_rd_pick_partition
  int64_t partition_rdcost[EXT_PARTITION_TYPES];
  // Timer used to time the partitions.
  struct aom_usec_timer timer;
  // Whether the timer is on
  int timer_is_on;
} PartitionTimingStats;
#endif  // CONFIG_COLLECT_PARTITION_STATS

// Structure holding state variables for partition search.
PartitionSearchState;

static inline void av1_disable_square_split_partition(
    PartitionSearchState *part_state) {}

// Disables all possible rectangular splits. This includes PARTITION_AB4 as they
// depend on the corresponding partition_rect_allowed.
static inline void av1_disable_rect_partitions(
    PartitionSearchState *part_state) {}

// Disables all possible splits so that only PARTITION_NONE *might* be allowed.
static inline void av1_disable_all_splits(PartitionSearchState *part_state) {}

static inline void av1_set_square_split_only(PartitionSearchState *part_state) {}

static inline bool av1_blk_has_rows_and_cols(
    const PartitionBlkParams *blk_params) {}

static inline bool av1_is_whole_blk_in_frame(
    const PartitionBlkParams *blk_params,
    const CommonModeInfoParams *mi_params) {}

static inline void update_filter_type_cdf(const MACROBLOCKD *xd,
                                          const MB_MODE_INFO *mbmi,
                                          int dual_filter) {}

static inline int set_rdmult(const AV1_COMP *const cpi,
                             const MACROBLOCK *const x, int segment_id) {}

static inline int do_split_check(BLOCK_SIZE bsize) {}

#if !CONFIG_REALTIME_ONLY
static inline const FIRSTPASS_STATS *read_one_frame_stats(const TWO_PASS *p,
                                                          int frm) {
  assert(frm >= 0);
  if (frm < 0 ||
      p->stats_buf_ctx->stats_in_start + frm > p->stats_buf_ctx->stats_in_end) {
    return NULL;
  }

  return &p->stats_buf_ctx->stats_in_start[frm];
}

int av1_get_rdmult_delta(AV1_COMP *cpi, BLOCK_SIZE bsize, int mi_row,
                         int mi_col, int orig_rdmult);

int av1_active_h_edge(const AV1_COMP *cpi, int mi_row, int mi_step);

int av1_active_v_edge(const AV1_COMP *cpi, int mi_col, int mi_step);

void av1_get_tpl_stats_sb(AV1_COMP *cpi, BLOCK_SIZE bsize, int mi_row,
                          int mi_col, SuperBlockEnc *sb_enc);

int av1_get_q_for_deltaq_objective(AV1_COMP *const cpi, ThreadData *td,
                                   int64_t *delta_dist, BLOCK_SIZE bsize,
                                   int mi_row, int mi_col);

int av1_get_q_for_hdr(AV1_COMP *const cpi, MACROBLOCK *const x,
                      BLOCK_SIZE bsize, int mi_row, int mi_col);

int av1_get_cb_rdmult(const AV1_COMP *const cpi, MACROBLOCK *const x,
                      const BLOCK_SIZE bsize, const int mi_row,
                      const int mi_col);
#endif  // !CONFIG_REALTIME_ONLY

void av1_set_ssim_rdmult(const AV1_COMP *const cpi, int *errorperbit,
                         const BLOCK_SIZE bsize, const int mi_row,
                         const int mi_col, int *const rdmult);

#if CONFIG_SALIENCY_MAP
void av1_set_saliency_map_vmaf_rdmult(const AV1_COMP *const cpi,
                                      int *errorperbit, const BLOCK_SIZE bsize,
                                      const int mi_row, const int mi_col,
                                      int *const rdmult);
#endif

void av1_update_state(const AV1_COMP *const cpi, ThreadData *td,
                      const PICK_MODE_CONTEXT *const ctx, int mi_row,
                      int mi_col, BLOCK_SIZE bsize, RUN_TYPE dry_run);

void av1_update_inter_mode_stats(FRAME_CONTEXT *fc, FRAME_COUNTS *counts,
                                 PREDICTION_MODE mode, int16_t mode_context);

void av1_sum_intra_stats(const AV1_COMMON *const cm, FRAME_COUNTS *counts,
                         MACROBLOCKD *xd, const MB_MODE_INFO *const mbmi,
                         const MB_MODE_INFO *above_mi,
                         const MB_MODE_INFO *left_mi, const int intraonly);

void av1_restore_context(MACROBLOCK *x, const RD_SEARCH_MACROBLOCK_CONTEXT *ctx,
                         int mi_row, int mi_col, BLOCK_SIZE bsize,
                         const int num_planes);

void av1_save_context(const MACROBLOCK *x, RD_SEARCH_MACROBLOCK_CONTEXT *ctx,
                      int mi_row, int mi_col, BLOCK_SIZE bsize,
                      const int num_planes);

void av1_set_fixed_partitioning(AV1_COMP *cpi, const TileInfo *const tile,
                                MB_MODE_INFO **mib, int mi_row, int mi_col,
                                BLOCK_SIZE bsize);

int av1_is_leaf_split_partition(AV1_COMMON *cm, int mi_row, int mi_col,
                                BLOCK_SIZE bsize);

void av1_reset_simple_motion_tree_partition(SIMPLE_MOTION_DATA_TREE *sms_tree,
                                            BLOCK_SIZE bsize);

void av1_update_picked_ref_frames_mask(MACROBLOCK *const x, int ref_type,
                                       BLOCK_SIZE bsize, int mib_size,
                                       int mi_row, int mi_col);

void av1_avg_cdf_symbols(FRAME_CONTEXT *ctx_left, FRAME_CONTEXT *ctx_tr,
                         int wt_left, int wt_tr);

void av1_source_content_sb(AV1_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data,
                           int mi_row, int mi_col);

void av1_reset_mbmi(CommonModeInfoParams *const mi_params, BLOCK_SIZE sb_size,
                    int mi_row, int mi_col);

void av1_backup_sb_state(SB_FIRST_PASS_STATS *sb_fp_stats, const AV1_COMP *cpi,
                         ThreadData *td, const TileDataEnc *tile_data,
                         int mi_row, int mi_col);

void av1_restore_sb_state(const SB_FIRST_PASS_STATS *sb_fp_stats, AV1_COMP *cpi,
                          ThreadData *td, TileDataEnc *tile_data, int mi_row,
                          int mi_col);

void av1_set_cost_upd_freq(AV1_COMP *cpi, ThreadData *td,
                           const TileInfo *const tile_info, const int mi_row,
                           const int mi_col);

void av1_dealloc_src_diff_buf(struct macroblock *mb, int num_planes);

static inline void av1_dealloc_mb_data(struct macroblock *mb, int num_planes) {}

static inline void allocate_winner_mode_stats(const AV1_COMP *cpi,
                                              struct macroblock *mb) {}

void av1_alloc_src_diff_buf(const struct AV1Common *cm, struct macroblock *mb);

static inline void av1_alloc_mb_data(const AV1_COMP *cpi,
                                     struct macroblock *mb) {}

// This function will compute the number of reference frames to be disabled
// based on selective_ref_frame speed feature.
static inline unsigned int get_num_refs_to_disable(
    const AV1_COMP *cpi, const int *ref_frame_flags,
    const unsigned int *ref_display_order_hint,
    unsigned int cur_frame_display_index) {}

static inline int get_max_allowed_ref_frames(
    const AV1_COMP *cpi, const int *ref_frame_flags,
    const unsigned int *ref_display_order_hint,
    unsigned int cur_frame_display_index) {}

// Enforce the number of references for each arbitrary frame based on user
// options and speed.
static inline void enforce_max_ref_frames(
    AV1_COMP *cpi, int *ref_frame_flags,
    const unsigned int *ref_display_order_hint,
    unsigned int cur_frame_display_index) {}

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

#endif  // AOM_AV1_ENCODER_ENCODEFRAME_UTILS_H_