#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include "config/aom_config.h"
#include "config/aom_dsp_rtcd.h"
#include "config/av1_rtcd.h"
#include "aom_dsp/aom_dsp_common.h"
#include "aom_dsp/binary_codes_writer.h"
#include "aom_ports/mem.h"
#include "aom_ports/aom_timer.h"
#include "av1/common/reconinter.h"
#include "av1/common/blockd.h"
#include "av1/encoder/encodeframe.h"
#include "av1/encoder/encodeframe_utils.h"
#include "av1/encoder/var_based_part.h"
#include "av1/encoder/reconinter_enc.h"
#include "av1/encoder/rdopt_utils.h"
enum { … } UENUM1BYTE(…) …;
variance_node;
static inline void tree_to_node(void *data, BLOCK_SIZE bsize,
variance_node *node) { … }
static inline void fill_variance(uint32_t s2, int32_t s, int c, VPartVar *v) { … }
static inline void get_variance(VPartVar *v) { … }
static inline void sum_2_variances(const VPartVar *a, const VPartVar *b,
VPartVar *r) { … }
static inline void fill_variance_tree(void *data, BLOCK_SIZE bsize) { … }
static inline void set_block_size(AV1_COMP *const cpi, int mi_row, int mi_col,
BLOCK_SIZE bsize) { … }
static int set_vt_partitioning(AV1_COMP *cpi, MACROBLOCKD *const xd,
const TileInfo *const tile, void *data,
BLOCK_SIZE bsize, int mi_row, int mi_col,
int64_t threshold, BLOCK_SIZE bsize_min,
PART_EVAL_STATUS force_split) { … }
static inline int all_blks_inside(int x16_idx, int y16_idx, int pixels_wide,
int pixels_high) { … }
#if CONFIG_AV1_HIGHBITDEPTH
static inline void fill_variance_8x8avg_highbd(
const uint8_t *src_buf, int src_stride, const uint8_t *dst_buf,
int dst_stride, int x16_idx, int y16_idx, VP16x16 *vst, int pixels_wide,
int pixels_high) {
for (int idx = 0; idx < 4; idx++) {
const int x8_idx = x16_idx + GET_BLK_IDX_X(idx, 3);
const int y8_idx = y16_idx + GET_BLK_IDX_Y(idx, 3);
unsigned int sse = 0;
int sum = 0;
if (x8_idx < pixels_wide && y8_idx < pixels_high) {
int src_avg = aom_highbd_avg_8x8(src_buf + y8_idx * src_stride + x8_idx,
src_stride);
int dst_avg = aom_highbd_avg_8x8(dst_buf + y8_idx * dst_stride + x8_idx,
dst_stride);
sum = src_avg - dst_avg;
sse = sum * sum;
}
fill_variance(sse, sum, 0, &vst->split[idx].part_variances.none);
}
}
#endif
static inline void fill_variance_8x8avg_lowbd(
const uint8_t *src_buf, int src_stride, const uint8_t *dst_buf,
int dst_stride, int x16_idx, int y16_idx, VP16x16 *vst, int pixels_wide,
int pixels_high) { … }
static inline void fill_variance_8x8avg(const uint8_t *src_buf, int src_stride,
const uint8_t *dst_buf, int dst_stride,
int x16_idx, int y16_idx, VP16x16 *vst,
int highbd_flag, int pixels_wide,
int pixels_high) { … }
static int compute_minmax_8x8(const uint8_t *src_buf, int src_stride,
const uint8_t *dst_buf, int dst_stride,
int x16_idx, int y16_idx,
#if CONFIG_AV1_HIGHBITDEPTH
int highbd_flag,
#endif
int pixels_wide, int pixels_high) { … }
static inline void fill_variance_4x4avg(const uint8_t *src_buf, int src_stride,
int x8_idx, int y8_idx, VP8x8 *vst,
#if CONFIG_AV1_HIGHBITDEPTH
int highbd_flag,
#endif
int pixels_wide, int pixels_high,
int border_offset_4x4) { … }
static int64_t scale_part_thresh_content(int64_t threshold_base, int speed,
int width, int height,
int non_reference_frame) { … }
static inline void tune_thresh_based_on_qindex(
AV1_COMP *cpi, int64_t thresholds[], uint64_t block_sad, int current_qindex,
int num_pixels, bool is_segment_id_boosted, int source_sad_nonrd,
int lighting_change) { … }
static void set_vbp_thresholds_key_frame(AV1_COMP *cpi, int64_t thresholds[],
int64_t threshold_base,
int threshold_left_shift,
int num_pixels) { … }
static inline void tune_thresh_based_on_resolution(
AV1_COMP *cpi, int64_t thresholds[], int64_t threshold_base,
int current_qindex, int source_sad_rd, int num_pixels) { … }
static inline int64_t tune_base_thresh_content(AV1_COMP *cpi,
int64_t threshold_base,
int content_lowsumdiff,
int source_sad_nonrd,
int num_pixels) { … }
static inline void set_vbp_thresholds(AV1_COMP *cpi, int64_t thresholds[],
uint64_t blk_sad, int qindex,
int content_lowsumdiff,
int source_sad_nonrd, int source_sad_rd,
bool is_segment_id_boosted,
int lighting_change) { … }
static inline void set_low_temp_var_flag_64x64(CommonModeInfoParams *mi_params,
PartitionSearchInfo *part_info,
MACROBLOCKD *xd, VP64x64 *vt,
const int64_t thresholds[],
int mi_col, int mi_row) { … }
static inline void set_low_temp_var_flag_128x128(
CommonModeInfoParams *mi_params, PartitionSearchInfo *part_info,
MACROBLOCKD *xd, VP128x128 *vt, const int64_t thresholds[], int mi_col,
int mi_row) { … }
static inline void set_low_temp_var_flag(
AV1_COMP *cpi, PartitionSearchInfo *part_info, MACROBLOCKD *xd,
VP128x128 *vt, int64_t thresholds[], MV_REFERENCE_FRAME ref_frame_partition,
int mi_col, int mi_row, const bool is_small_sb) { … }
static const int pos_shift_16x16[4][4] = …;
int av1_get_force_skip_low_temp_var_small_sb(const uint8_t *variance_low,
int mi_row, int mi_col,
BLOCK_SIZE bsize) { … }
int av1_get_force_skip_low_temp_var(const uint8_t *variance_low, int mi_row,
int mi_col, BLOCK_SIZE bsize) { … }
void av1_set_variance_partition_thresholds(AV1_COMP *cpi, int qindex,
int content_lowsumdiff) { … }
static inline void chroma_check(AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
unsigned int y_sad, unsigned int y_sad_g,
unsigned int y_sad_alt, bool is_key_frame,
bool zero_motion, unsigned int *uv_sad) { … }
static void fill_variance_tree_leaves(
AV1_COMP *cpi, MACROBLOCK *x, VP128x128 *vt, PART_EVAL_STATUS *force_split,
int avg_16x16[][4], int maxvar_16x16[][4], int minvar_16x16[][4],
int64_t *thresholds, const uint8_t *src_buf, int src_stride,
const uint8_t *dst_buf, int dst_stride, bool is_key_frame,
const bool is_small_sb) { … }
static inline void set_ref_frame_for_partition(
AV1_COMP *cpi, MACROBLOCK *x, MACROBLOCKD *xd,
MV_REFERENCE_FRAME *ref_frame_partition, MB_MODE_INFO *mi,
unsigned int *y_sad, unsigned int *y_sad_g, unsigned int *y_sad_alt,
const YV12_BUFFER_CONFIG *yv12_g, const YV12_BUFFER_CONFIG *yv12_alt,
int mi_row, int mi_col, int num_planes) { … }
static AOM_FORCE_INLINE int mv_distance(const FULLPEL_MV *mv0,
const FULLPEL_MV *mv1) { … }
static inline void evaluate_neighbour_mvs(AV1_COMP *cpi, MACROBLOCK *x,
unsigned int *y_sad, bool is_small_sb,
int est_motion) { … }
static void setup_planes(AV1_COMP *cpi, MACROBLOCK *x, unsigned int *y_sad,
unsigned int *y_sad_g, unsigned int *y_sad_alt,
unsigned int *y_sad_last,
MV_REFERENCE_FRAME *ref_frame_partition,
struct scale_factors *sf_no_scale, int mi_row,
int mi_col, bool is_small_sb, bool scaled_ref_last) { … }
static inline PART_EVAL_STATUS get_part_eval_based_on_sub_blk_var(
VP16x16 *var_16x16_info, int64_t threshold16) { … }
static inline bool is_set_force_zeromv_skip_based_on_src_sad(
int set_zeromv_skip_based_on_source_sad, SOURCE_SAD source_sad_nonrd) { … }
static inline bool set_force_zeromv_skip_for_sb(
AV1_COMP *cpi, MACROBLOCK *x, const TileInfo *const tile, VP128x128 *vt,
unsigned int *uv_sad, int mi_row, int mi_col, unsigned int y_sad,
BLOCK_SIZE bsize) { … }
int av1_choose_var_based_partitioning(AV1_COMP *cpi, const TileInfo *const tile,
ThreadData *td, MACROBLOCK *x, int mi_row,
int mi_col) { … }