1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_ENCODER_MCOMP_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_ENCODER_MCOMP_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/mv.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/block.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/rd.h"
18*77c1e3ccSAndroid Build Coastguard Worker
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/variance.h"
20*77c1e3ccSAndroid Build Coastguard Worker
21*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
22*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
23*77c1e3ccSAndroid Build Coastguard Worker #endif
24*77c1e3ccSAndroid Build Coastguard Worker
25*77c1e3ccSAndroid Build Coastguard Worker struct AV1_COMP;
26*77c1e3ccSAndroid Build Coastguard Worker struct SPEED_FEATURES;
27*77c1e3ccSAndroid Build Coastguard Worker
28*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
29*77c1e3ccSAndroid Build Coastguard Worker // Cost functions
30*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
31*77c1e3ccSAndroid Build Coastguard Worker
32*77c1e3ccSAndroid Build Coastguard Worker enum {
33*77c1e3ccSAndroid Build Coastguard Worker MV_COST_ENTROPY, // Use the entropy rate of the mv as the cost
34*77c1e3ccSAndroid Build Coastguard Worker MV_COST_L1_LOWRES, // Use the l1 norm of the mv as the cost (<480p)
35*77c1e3ccSAndroid Build Coastguard Worker MV_COST_L1_MIDRES, // Use the l1 norm of the mv as the cost (>=480p)
36*77c1e3ccSAndroid Build Coastguard Worker MV_COST_L1_HDRES, // Use the l1 norm of the mv as the cost (>=720p)
37*77c1e3ccSAndroid Build Coastguard Worker MV_COST_NONE // Use 0 as as cost irrespective of the current mv
38*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(MV_COST_TYPE);
39*77c1e3ccSAndroid Build Coastguard Worker
40*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
41*77c1e3ccSAndroid Build Coastguard Worker // The reference mv used to compute the mv cost
42*77c1e3ccSAndroid Build Coastguard Worker const MV *ref_mv;
43*77c1e3ccSAndroid Build Coastguard Worker FULLPEL_MV full_ref_mv;
44*77c1e3ccSAndroid Build Coastguard Worker MV_COST_TYPE mv_cost_type;
45*77c1e3ccSAndroid Build Coastguard Worker const int *mvjcost;
46*77c1e3ccSAndroid Build Coastguard Worker const int *mvcost[2];
47*77c1e3ccSAndroid Build Coastguard Worker int error_per_bit;
48*77c1e3ccSAndroid Build Coastguard Worker // A multiplier used to convert rate to sad cost
49*77c1e3ccSAndroid Build Coastguard Worker int sad_per_bit;
50*77c1e3ccSAndroid Build Coastguard Worker } MV_COST_PARAMS;
51*77c1e3ccSAndroid Build Coastguard Worker
52*77c1e3ccSAndroid Build Coastguard Worker int av1_mv_bit_cost(const MV *mv, const MV *ref_mv, const int *mvjcost,
53*77c1e3ccSAndroid Build Coastguard Worker int *const mvcost[2], int weight);
54*77c1e3ccSAndroid Build Coastguard Worker
55*77c1e3ccSAndroid Build Coastguard Worker int av1_get_mvpred_sse(const MV_COST_PARAMS *mv_cost_params,
56*77c1e3ccSAndroid Build Coastguard Worker const FULLPEL_MV best_mv,
57*77c1e3ccSAndroid Build Coastguard Worker const aom_variance_fn_ptr_t *vfp,
58*77c1e3ccSAndroid Build Coastguard Worker const struct buf_2d *src, const struct buf_2d *pre);
59*77c1e3ccSAndroid Build Coastguard Worker
60*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
61*77c1e3ccSAndroid Build Coastguard Worker // Motion Search
62*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
63*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
64*77c1e3ccSAndroid Build Coastguard Worker // The reference buffer
65*77c1e3ccSAndroid Build Coastguard Worker const struct buf_2d *ref;
66*77c1e3ccSAndroid Build Coastguard Worker
67*77c1e3ccSAndroid Build Coastguard Worker // The source and predictors/mask used by translational search
68*77c1e3ccSAndroid Build Coastguard Worker const struct buf_2d *src;
69*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *second_pred;
70*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *mask;
71*77c1e3ccSAndroid Build Coastguard Worker int mask_stride;
72*77c1e3ccSAndroid Build Coastguard Worker int inv_mask;
73*77c1e3ccSAndroid Build Coastguard Worker
74*77c1e3ccSAndroid Build Coastguard Worker // The weighted source and mask used by OBMC
75*77c1e3ccSAndroid Build Coastguard Worker const int32_t *wsrc;
76*77c1e3ccSAndroid Build Coastguard Worker const int32_t *obmc_mask;
77*77c1e3ccSAndroid Build Coastguard Worker } MSBuffers;
78*77c1e3ccSAndroid Build Coastguard Worker
av1_set_ms_compound_refs(MSBuffers * ms_buffers,const uint8_t * second_pred,const uint8_t * mask,int mask_stride,int invert_mask)79*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_set_ms_compound_refs(MSBuffers *ms_buffers,
80*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *second_pred,
81*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *mask,
82*77c1e3ccSAndroid Build Coastguard Worker int mask_stride, int invert_mask) {
83*77c1e3ccSAndroid Build Coastguard Worker ms_buffers->second_pred = second_pred;
84*77c1e3ccSAndroid Build Coastguard Worker ms_buffers->mask = mask;
85*77c1e3ccSAndroid Build Coastguard Worker ms_buffers->mask_stride = mask_stride;
86*77c1e3ccSAndroid Build Coastguard Worker ms_buffers->inv_mask = invert_mask;
87*77c1e3ccSAndroid Build Coastguard Worker }
88*77c1e3ccSAndroid Build Coastguard Worker
89*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
90*77c1e3ccSAndroid Build Coastguard Worker // Fullpixel Motion Search
91*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
92*77c1e3ccSAndroid Build Coastguard Worker // This struct holds fullpixel motion search parameters that should be constant
93*77c1e3ccSAndroid Build Coastguard Worker // during the search
94*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
95*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE bsize;
96*77c1e3ccSAndroid Build Coastguard Worker // A function pointer to the simd function for fast computation
97*77c1e3ccSAndroid Build Coastguard Worker const aom_variance_fn_ptr_t *vfp;
98*77c1e3ccSAndroid Build Coastguard Worker
99*77c1e3ccSAndroid Build Coastguard Worker MSBuffers ms_buffers;
100*77c1e3ccSAndroid Build Coastguard Worker
101*77c1e3ccSAndroid Build Coastguard Worker // WARNING: search_method should be regarded as a private variable and should
102*77c1e3ccSAndroid Build Coastguard Worker // not be modified directly so it is in sync with search_sites. To modify it,
103*77c1e3ccSAndroid Build Coastguard Worker // use av1_set_mv_search_method.
104*77c1e3ccSAndroid Build Coastguard Worker SEARCH_METHODS search_method;
105*77c1e3ccSAndroid Build Coastguard Worker const search_site_config *search_sites;
106*77c1e3ccSAndroid Build Coastguard Worker FullMvLimits mv_limits;
107*77c1e3ccSAndroid Build Coastguard Worker
108*77c1e3ccSAndroid Build Coastguard Worker int run_mesh_search; // Sets mesh search unless it got pruned by
109*77c1e3ccSAndroid Build Coastguard Worker // prune_mesh_search.
110*77c1e3ccSAndroid Build Coastguard Worker int prune_mesh_search; // Disables mesh search if the best_mv after a normal
111*77c1e3ccSAndroid Build Coastguard Worker // search if close to the start_mv.
112*77c1e3ccSAndroid Build Coastguard Worker int mesh_search_mv_diff_threshold; // mv diff threshold to enable
113*77c1e3ccSAndroid Build Coastguard Worker // prune_mesh_search
114*77c1e3ccSAndroid Build Coastguard Worker int force_mesh_thresh; // Forces mesh search if the residue variance is
115*77c1e3ccSAndroid Build Coastguard Worker // higher than the threshold.
116*77c1e3ccSAndroid Build Coastguard Worker const struct MESH_PATTERN *mesh_patterns[2];
117*77c1e3ccSAndroid Build Coastguard Worker
118*77c1e3ccSAndroid Build Coastguard Worker // Use maximum search interval of 4 if true. This helps motion search to find
119*77c1e3ccSAndroid Build Coastguard Worker // the best motion vector for screen content types.
120*77c1e3ccSAndroid Build Coastguard Worker int fine_search_interval;
121*77c1e3ccSAndroid Build Coastguard Worker
122*77c1e3ccSAndroid Build Coastguard Worker int is_intra_mode;
123*77c1e3ccSAndroid Build Coastguard Worker
124*77c1e3ccSAndroid Build Coastguard Worker int fast_obmc_search;
125*77c1e3ccSAndroid Build Coastguard Worker
126*77c1e3ccSAndroid Build Coastguard Worker // For calculating mv cost
127*77c1e3ccSAndroid Build Coastguard Worker MV_COST_PARAMS mv_cost_params;
128*77c1e3ccSAndroid Build Coastguard Worker
129*77c1e3ccSAndroid Build Coastguard Worker // Stores the function used to compute the sad. This can be different from the
130*77c1e3ccSAndroid Build Coastguard Worker // sdf in vfp (e.g. downsampled sad and not sad) to allow speed up.
131*77c1e3ccSAndroid Build Coastguard Worker aom_sad_fn_t sdf;
132*77c1e3ccSAndroid Build Coastguard Worker aom_sad_multi_d_fn_t sdx4df;
133*77c1e3ccSAndroid Build Coastguard Worker aom_sad_multi_d_fn_t sdx3df;
134*77c1e3ccSAndroid Build Coastguard Worker } FULLPEL_MOTION_SEARCH_PARAMS;
135*77c1e3ccSAndroid Build Coastguard Worker
136*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
137*77c1e3ccSAndroid Build Coastguard Worker int err_cost;
138*77c1e3ccSAndroid Build Coastguard Worker unsigned int distortion;
139*77c1e3ccSAndroid Build Coastguard Worker unsigned int sse;
140*77c1e3ccSAndroid Build Coastguard Worker } FULLPEL_MV_STATS;
141*77c1e3ccSAndroid Build Coastguard Worker
142*77c1e3ccSAndroid Build Coastguard Worker void av1_init_obmc_buffer(OBMCBuffer *obmc_buffer);
143*77c1e3ccSAndroid Build Coastguard Worker
144*77c1e3ccSAndroid Build Coastguard Worker void av1_make_default_fullpel_ms_params(
145*77c1e3ccSAndroid Build Coastguard Worker FULLPEL_MOTION_SEARCH_PARAMS *ms_params, const struct AV1_COMP *cpi,
146*77c1e3ccSAndroid Build Coastguard Worker MACROBLOCK *x, BLOCK_SIZE bsize, const MV *ref_mv, FULLPEL_MV start_mv,
147*77c1e3ccSAndroid Build Coastguard Worker const search_site_config search_sites[NUM_DISTINCT_SEARCH_METHODS],
148*77c1e3ccSAndroid Build Coastguard Worker SEARCH_METHODS search_method, int fine_search_interval);
149*77c1e3ccSAndroid Build Coastguard Worker
150*77c1e3ccSAndroid Build Coastguard Worker /*! Sets the \ref FULLPEL_MOTION_SEARCH_PARAMS to intra mode. */
151*77c1e3ccSAndroid Build Coastguard Worker void av1_set_ms_to_intra_mode(FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
152*77c1e3ccSAndroid Build Coastguard Worker const IntraBCMVCosts *dv_costs);
153*77c1e3ccSAndroid Build Coastguard Worker
154*77c1e3ccSAndroid Build Coastguard Worker // Sets up configs for firstpass motion search.
155*77c1e3ccSAndroid Build Coastguard Worker void av1_init_motion_fpf(search_site_config *cfg, int stride);
156*77c1e3ccSAndroid Build Coastguard Worker
157*77c1e3ccSAndroid Build Coastguard Worker /*! Function pointer to search site config initialization of different search
158*77c1e3ccSAndroid Build Coastguard Worker * method functions. */
159*77c1e3ccSAndroid Build Coastguard Worker typedef void (*av1_init_search_site_config)(search_site_config *cfg, int stride,
160*77c1e3ccSAndroid Build Coastguard Worker int level);
161*77c1e3ccSAndroid Build Coastguard Worker
162*77c1e3ccSAndroid Build Coastguard Worker /*! Array of function pointers used to set the motion search config. */
163*77c1e3ccSAndroid Build Coastguard Worker extern const av1_init_search_site_config
164*77c1e3ccSAndroid Build Coastguard Worker av1_init_motion_compensation[NUM_DISTINCT_SEARCH_METHODS];
165*77c1e3ccSAndroid Build Coastguard Worker
166*77c1e3ccSAndroid Build Coastguard Worker // Array to inform which all search methods are having
167*77c1e3ccSAndroid Build Coastguard Worker // same candidates and different in number of search steps.
168*77c1e3ccSAndroid Build Coastguard Worker static const SEARCH_METHODS search_method_lookup[NUM_SEARCH_METHODS] = {
169*77c1e3ccSAndroid Build Coastguard Worker DIAMOND, // DIAMOND
170*77c1e3ccSAndroid Build Coastguard Worker NSTEP, // NSTEP
171*77c1e3ccSAndroid Build Coastguard Worker NSTEP_8PT, // NSTEP_8PT
172*77c1e3ccSAndroid Build Coastguard Worker CLAMPED_DIAMOND, // CLAMPED_DIAMOND
173*77c1e3ccSAndroid Build Coastguard Worker HEX, // HEX
174*77c1e3ccSAndroid Build Coastguard Worker BIGDIA, // BIGDIA
175*77c1e3ccSAndroid Build Coastguard Worker SQUARE, // SQUARE
176*77c1e3ccSAndroid Build Coastguard Worker HEX, // FAST_HEX
177*77c1e3ccSAndroid Build Coastguard Worker BIGDIA, // FAST_DIAMOND
178*77c1e3ccSAndroid Build Coastguard Worker BIGDIA, // FAST_BIGDIA
179*77c1e3ccSAndroid Build Coastguard Worker BIGDIA // VFAST_DIAMOND
180*77c1e3ccSAndroid Build Coastguard Worker };
181*77c1e3ccSAndroid Build Coastguard Worker
182*77c1e3ccSAndroid Build Coastguard Worker // Reinitialize the search site config.
av1_refresh_search_site_config(search_site_config * ss_cfg_buf,SEARCH_METHODS search_method,const int ref_stride)183*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_refresh_search_site_config(
184*77c1e3ccSAndroid Build Coastguard Worker search_site_config *ss_cfg_buf, SEARCH_METHODS search_method,
185*77c1e3ccSAndroid Build Coastguard Worker const int ref_stride) {
186*77c1e3ccSAndroid Build Coastguard Worker const int level =
187*77c1e3ccSAndroid Build Coastguard Worker search_method == NSTEP_8PT || search_method == CLAMPED_DIAMOND;
188*77c1e3ccSAndroid Build Coastguard Worker search_method = search_method_lookup[search_method];
189*77c1e3ccSAndroid Build Coastguard Worker av1_init_motion_compensation[search_method](&ss_cfg_buf[search_method],
190*77c1e3ccSAndroid Build Coastguard Worker ref_stride, level);
191*77c1e3ccSAndroid Build Coastguard Worker }
192*77c1e3ccSAndroid Build Coastguard Worker
193*77c1e3ccSAndroid Build Coastguard Worker // Mv beyond the range do not produce new/different prediction block.
av1_set_mv_search_method(FULLPEL_MOTION_SEARCH_PARAMS * ms_params,const search_site_config search_sites[NUM_DISTINCT_SEARCH_METHODS],SEARCH_METHODS search_method)194*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_set_mv_search_method(
195*77c1e3ccSAndroid Build Coastguard Worker FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
196*77c1e3ccSAndroid Build Coastguard Worker const search_site_config search_sites[NUM_DISTINCT_SEARCH_METHODS],
197*77c1e3ccSAndroid Build Coastguard Worker SEARCH_METHODS search_method) {
198*77c1e3ccSAndroid Build Coastguard Worker ms_params->search_method = search_method;
199*77c1e3ccSAndroid Build Coastguard Worker ms_params->search_sites =
200*77c1e3ccSAndroid Build Coastguard Worker &search_sites[search_method_lookup[ms_params->search_method]];
201*77c1e3ccSAndroid Build Coastguard Worker }
202*77c1e3ccSAndroid Build Coastguard Worker
203*77c1e3ccSAndroid Build Coastguard Worker // Set up limit values for MV components.
204*77c1e3ccSAndroid Build Coastguard Worker // Mv beyond the range do not produce new/different prediction block.
av1_set_mv_row_limits(const CommonModeInfoParams * const mi_params,FullMvLimits * mv_limits,int mi_row,int mi_height,int border)205*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_set_mv_row_limits(
206*77c1e3ccSAndroid Build Coastguard Worker const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
207*77c1e3ccSAndroid Build Coastguard Worker int mi_row, int mi_height, int border) {
208*77c1e3ccSAndroid Build Coastguard Worker const int min1 = -(mi_row * MI_SIZE + border - 2 * AOM_INTERP_EXTEND);
209*77c1e3ccSAndroid Build Coastguard Worker const int min2 = -(((mi_row + mi_height) * MI_SIZE) + 2 * AOM_INTERP_EXTEND);
210*77c1e3ccSAndroid Build Coastguard Worker mv_limits->row_min = AOMMAX(min1, min2);
211*77c1e3ccSAndroid Build Coastguard Worker const int max1 = (mi_params->mi_rows - mi_row - mi_height) * MI_SIZE +
212*77c1e3ccSAndroid Build Coastguard Worker border - 2 * AOM_INTERP_EXTEND;
213*77c1e3ccSAndroid Build Coastguard Worker const int max2 =
214*77c1e3ccSAndroid Build Coastguard Worker (mi_params->mi_rows - mi_row) * MI_SIZE + 2 * AOM_INTERP_EXTEND;
215*77c1e3ccSAndroid Build Coastguard Worker mv_limits->row_max = AOMMIN(max1, max2);
216*77c1e3ccSAndroid Build Coastguard Worker }
217*77c1e3ccSAndroid Build Coastguard Worker
av1_set_mv_col_limits(const CommonModeInfoParams * const mi_params,FullMvLimits * mv_limits,int mi_col,int mi_width,int border)218*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_set_mv_col_limits(
219*77c1e3ccSAndroid Build Coastguard Worker const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
220*77c1e3ccSAndroid Build Coastguard Worker int mi_col, int mi_width, int border) {
221*77c1e3ccSAndroid Build Coastguard Worker const int min1 = -(mi_col * MI_SIZE + border - 2 * AOM_INTERP_EXTEND);
222*77c1e3ccSAndroid Build Coastguard Worker const int min2 = -(((mi_col + mi_width) * MI_SIZE) + 2 * AOM_INTERP_EXTEND);
223*77c1e3ccSAndroid Build Coastguard Worker mv_limits->col_min = AOMMAX(min1, min2);
224*77c1e3ccSAndroid Build Coastguard Worker const int max1 = (mi_params->mi_cols - mi_col - mi_width) * MI_SIZE + border -
225*77c1e3ccSAndroid Build Coastguard Worker 2 * AOM_INTERP_EXTEND;
226*77c1e3ccSAndroid Build Coastguard Worker const int max2 =
227*77c1e3ccSAndroid Build Coastguard Worker (mi_params->mi_cols - mi_col) * MI_SIZE + 2 * AOM_INTERP_EXTEND;
228*77c1e3ccSAndroid Build Coastguard Worker mv_limits->col_max = AOMMIN(max1, max2);
229*77c1e3ccSAndroid Build Coastguard Worker }
230*77c1e3ccSAndroid Build Coastguard Worker
av1_set_mv_limits(const CommonModeInfoParams * const mi_params,FullMvLimits * mv_limits,int mi_row,int mi_col,int mi_height,int mi_width,int border)231*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_set_mv_limits(
232*77c1e3ccSAndroid Build Coastguard Worker const CommonModeInfoParams *const mi_params, FullMvLimits *mv_limits,
233*77c1e3ccSAndroid Build Coastguard Worker int mi_row, int mi_col, int mi_height, int mi_width, int border) {
234*77c1e3ccSAndroid Build Coastguard Worker av1_set_mv_row_limits(mi_params, mv_limits, mi_row, mi_height, border);
235*77c1e3ccSAndroid Build Coastguard Worker av1_set_mv_col_limits(mi_params, mv_limits, mi_col, mi_width, border);
236*77c1e3ccSAndroid Build Coastguard Worker }
237*77c1e3ccSAndroid Build Coastguard Worker
238*77c1e3ccSAndroid Build Coastguard Worker void av1_set_mv_search_range(FullMvLimits *mv_limits, const MV *mv);
239*77c1e3ccSAndroid Build Coastguard Worker
240*77c1e3ccSAndroid Build Coastguard Worker int av1_init_search_range(int size);
241*77c1e3ccSAndroid Build Coastguard Worker
242*77c1e3ccSAndroid Build Coastguard Worker int av1_vector_match(const int16_t *ref, const int16_t *src, int bwl,
243*77c1e3ccSAndroid Build Coastguard Worker int search_size, int full_search, int *sad);
244*77c1e3ccSAndroid Build Coastguard Worker
245*77c1e3ccSAndroid Build Coastguard Worker unsigned int av1_int_pro_motion_estimation(
246*77c1e3ccSAndroid Build Coastguard Worker const struct AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int mi_row,
247*77c1e3ccSAndroid Build Coastguard Worker int mi_col, const MV *ref_mv, unsigned int *y_sad_zero,
248*77c1e3ccSAndroid Build Coastguard Worker int me_search_size_col, int me_search_size_row);
249*77c1e3ccSAndroid Build Coastguard Worker
250*77c1e3ccSAndroid Build Coastguard Worker int av1_refining_search_8p_c(const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
251*77c1e3ccSAndroid Build Coastguard Worker const FULLPEL_MV start_mv, FULLPEL_MV *best_mv);
252*77c1e3ccSAndroid Build Coastguard Worker
253*77c1e3ccSAndroid Build Coastguard Worker int av1_full_pixel_search(const FULLPEL_MV start_mv,
254*77c1e3ccSAndroid Build Coastguard Worker const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
255*77c1e3ccSAndroid Build Coastguard Worker const int step_param, int *cost_list,
256*77c1e3ccSAndroid Build Coastguard Worker FULLPEL_MV *best_mv, FULLPEL_MV_STATS *best_mv_stats,
257*77c1e3ccSAndroid Build Coastguard Worker FULLPEL_MV *second_best_mv);
258*77c1e3ccSAndroid Build Coastguard Worker
259*77c1e3ccSAndroid Build Coastguard Worker int av1_intrabc_hash_search(const struct AV1_COMP *cpi, const MACROBLOCKD *xd,
260*77c1e3ccSAndroid Build Coastguard Worker const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
261*77c1e3ccSAndroid Build Coastguard Worker IntraBCHashInfo *intrabc_hash_info,
262*77c1e3ccSAndroid Build Coastguard Worker FULLPEL_MV *best_mv);
263*77c1e3ccSAndroid Build Coastguard Worker
264*77c1e3ccSAndroid Build Coastguard Worker int av1_obmc_full_pixel_search(const FULLPEL_MV start_mv,
265*77c1e3ccSAndroid Build Coastguard Worker const FULLPEL_MOTION_SEARCH_PARAMS *ms_params,
266*77c1e3ccSAndroid Build Coastguard Worker const int step_param, FULLPEL_MV *best_mv);
267*77c1e3ccSAndroid Build Coastguard Worker
av1_is_fullmv_in_range(const FullMvLimits * mv_limits,FULLPEL_MV mv)268*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_is_fullmv_in_range(const FullMvLimits *mv_limits,
269*77c1e3ccSAndroid Build Coastguard Worker FULLPEL_MV mv) {
270*77c1e3ccSAndroid Build Coastguard Worker return (mv.col >= mv_limits->col_min) && (mv.col <= mv_limits->col_max) &&
271*77c1e3ccSAndroid Build Coastguard Worker (mv.row >= mv_limits->row_min) && (mv.row <= mv_limits->row_max);
272*77c1e3ccSAndroid Build Coastguard Worker }
273*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
274*77c1e3ccSAndroid Build Coastguard Worker // Subpixel Motion Search
275*77c1e3ccSAndroid Build Coastguard Worker // =============================================================================
276*77c1e3ccSAndroid Build Coastguard Worker enum {
277*77c1e3ccSAndroid Build Coastguard Worker EIGHTH_PEL,
278*77c1e3ccSAndroid Build Coastguard Worker QUARTER_PEL,
279*77c1e3ccSAndroid Build Coastguard Worker HALF_PEL,
280*77c1e3ccSAndroid Build Coastguard Worker FULL_PEL
281*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(SUBPEL_FORCE_STOP);
282*77c1e3ccSAndroid Build Coastguard Worker
283*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
284*77c1e3ccSAndroid Build Coastguard Worker const aom_variance_fn_ptr_t *vfp;
285*77c1e3ccSAndroid Build Coastguard Worker SUBPEL_SEARCH_TYPE subpel_search_type;
286*77c1e3ccSAndroid Build Coastguard Worker // Source and reference buffers
287*77c1e3ccSAndroid Build Coastguard Worker MSBuffers ms_buffers;
288*77c1e3ccSAndroid Build Coastguard Worker int w, h;
289*77c1e3ccSAndroid Build Coastguard Worker } SUBPEL_SEARCH_VAR_PARAMS;
290*77c1e3ccSAndroid Build Coastguard Worker
291*77c1e3ccSAndroid Build Coastguard Worker // This struct holds subpixel motion search parameters that should be constant
292*77c1e3ccSAndroid Build Coastguard Worker // during the search
293*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
294*77c1e3ccSAndroid Build Coastguard Worker // High level motion search settings
295*77c1e3ccSAndroid Build Coastguard Worker int allow_hp;
296*77c1e3ccSAndroid Build Coastguard Worker const int *cost_list;
297*77c1e3ccSAndroid Build Coastguard Worker SUBPEL_FORCE_STOP forced_stop;
298*77c1e3ccSAndroid Build Coastguard Worker int iters_per_step;
299*77c1e3ccSAndroid Build Coastguard Worker SubpelMvLimits mv_limits;
300*77c1e3ccSAndroid Build Coastguard Worker
301*77c1e3ccSAndroid Build Coastguard Worker // For calculating mv cost
302*77c1e3ccSAndroid Build Coastguard Worker MV_COST_PARAMS mv_cost_params;
303*77c1e3ccSAndroid Build Coastguard Worker
304*77c1e3ccSAndroid Build Coastguard Worker // Distortion calculation params
305*77c1e3ccSAndroid Build Coastguard Worker SUBPEL_SEARCH_VAR_PARAMS var_params;
306*77c1e3ccSAndroid Build Coastguard Worker } SUBPEL_MOTION_SEARCH_PARAMS;
307*77c1e3ccSAndroid Build Coastguard Worker
308*77c1e3ccSAndroid Build Coastguard Worker void av1_make_default_subpel_ms_params(SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
309*77c1e3ccSAndroid Build Coastguard Worker const struct AV1_COMP *cpi,
310*77c1e3ccSAndroid Build Coastguard Worker const MACROBLOCK *x, BLOCK_SIZE bsize,
311*77c1e3ccSAndroid Build Coastguard Worker const MV *ref_mv, const int *cost_list);
312*77c1e3ccSAndroid Build Coastguard Worker
313*77c1e3ccSAndroid Build Coastguard Worker typedef int(fractional_mv_step_fp)(MACROBLOCKD *xd, const AV1_COMMON *const cm,
314*77c1e3ccSAndroid Build Coastguard Worker const SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
315*77c1e3ccSAndroid Build Coastguard Worker MV start_mv,
316*77c1e3ccSAndroid Build Coastguard Worker const FULLPEL_MV_STATS *start_mv_stats,
317*77c1e3ccSAndroid Build Coastguard Worker MV *bestmv, int *distortion,
318*77c1e3ccSAndroid Build Coastguard Worker unsigned int *sse1,
319*77c1e3ccSAndroid Build Coastguard Worker int_mv *last_mv_search_list);
320*77c1e3ccSAndroid Build Coastguard Worker
321*77c1e3ccSAndroid Build Coastguard Worker extern fractional_mv_step_fp av1_find_best_sub_pixel_tree;
322*77c1e3ccSAndroid Build Coastguard Worker extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned;
323*77c1e3ccSAndroid Build Coastguard Worker extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more;
324*77c1e3ccSAndroid Build Coastguard Worker extern fractional_mv_step_fp av1_return_max_sub_pixel_mv;
325*77c1e3ccSAndroid Build Coastguard Worker extern fractional_mv_step_fp av1_return_min_sub_pixel_mv;
326*77c1e3ccSAndroid Build Coastguard Worker extern fractional_mv_step_fp av1_find_best_obmc_sub_pixel_tree_up;
327*77c1e3ccSAndroid Build Coastguard Worker
328*77c1e3ccSAndroid Build Coastguard Worker unsigned int av1_refine_warped_mv(MACROBLOCKD *xd, const AV1_COMMON *const cm,
329*77c1e3ccSAndroid Build Coastguard Worker const SUBPEL_MOTION_SEARCH_PARAMS *ms_params,
330*77c1e3ccSAndroid Build Coastguard Worker BLOCK_SIZE bsize, const int *pts0,
331*77c1e3ccSAndroid Build Coastguard Worker const int *pts_inref0, int total_samples,
332*77c1e3ccSAndroid Build Coastguard Worker WARP_SEARCH_METHOD search_method,
333*77c1e3ccSAndroid Build Coastguard Worker int num_iterations);
334*77c1e3ccSAndroid Build Coastguard Worker
av1_set_fractional_mv(int_mv * fractional_best_mv)335*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_set_fractional_mv(int_mv *fractional_best_mv) {
336*77c1e3ccSAndroid Build Coastguard Worker for (int z = 0; z < 3; z++) {
337*77c1e3ccSAndroid Build Coastguard Worker fractional_best_mv[z].as_int = INVALID_MV;
338*77c1e3ccSAndroid Build Coastguard Worker }
339*77c1e3ccSAndroid Build Coastguard Worker }
340*77c1e3ccSAndroid Build Coastguard Worker
av1_set_subpel_mv_search_range(SubpelMvLimits * subpel_limits,const FullMvLimits * mv_limits,const MV * ref_mv)341*77c1e3ccSAndroid Build Coastguard Worker static inline void av1_set_subpel_mv_search_range(SubpelMvLimits *subpel_limits,
342*77c1e3ccSAndroid Build Coastguard Worker const FullMvLimits *mv_limits,
343*77c1e3ccSAndroid Build Coastguard Worker const MV *ref_mv) {
344*77c1e3ccSAndroid Build Coastguard Worker const int max_mv = GET_MV_SUBPEL(MAX_FULL_PEL_VAL);
345*77c1e3ccSAndroid Build Coastguard Worker int minc = AOMMAX(GET_MV_SUBPEL(mv_limits->col_min), ref_mv->col - max_mv);
346*77c1e3ccSAndroid Build Coastguard Worker int maxc = AOMMIN(GET_MV_SUBPEL(mv_limits->col_max), ref_mv->col + max_mv);
347*77c1e3ccSAndroid Build Coastguard Worker int minr = AOMMAX(GET_MV_SUBPEL(mv_limits->row_min), ref_mv->row - max_mv);
348*77c1e3ccSAndroid Build Coastguard Worker int maxr = AOMMIN(GET_MV_SUBPEL(mv_limits->row_max), ref_mv->row + max_mv);
349*77c1e3ccSAndroid Build Coastguard Worker
350*77c1e3ccSAndroid Build Coastguard Worker maxc = AOMMAX(minc, maxc);
351*77c1e3ccSAndroid Build Coastguard Worker maxr = AOMMAX(minr, maxr);
352*77c1e3ccSAndroid Build Coastguard Worker
353*77c1e3ccSAndroid Build Coastguard Worker subpel_limits->col_min = AOMMAX(MV_LOW + 1, minc);
354*77c1e3ccSAndroid Build Coastguard Worker subpel_limits->col_max = AOMMIN(MV_UPP - 1, maxc);
355*77c1e3ccSAndroid Build Coastguard Worker subpel_limits->row_min = AOMMAX(MV_LOW + 1, minr);
356*77c1e3ccSAndroid Build Coastguard Worker subpel_limits->row_max = AOMMIN(MV_UPP - 1, maxr);
357*77c1e3ccSAndroid Build Coastguard Worker }
358*77c1e3ccSAndroid Build Coastguard Worker
av1_is_subpelmv_in_range(const SubpelMvLimits * mv_limits,MV mv)359*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_is_subpelmv_in_range(const SubpelMvLimits *mv_limits,
360*77c1e3ccSAndroid Build Coastguard Worker MV mv) {
361*77c1e3ccSAndroid Build Coastguard Worker return (mv.col >= mv_limits->col_min) && (mv.col <= mv_limits->col_max) &&
362*77c1e3ccSAndroid Build Coastguard Worker (mv.row >= mv_limits->row_min) && (mv.row <= mv_limits->row_max);
363*77c1e3ccSAndroid Build Coastguard Worker }
364*77c1e3ccSAndroid Build Coastguard Worker
get_offset_from_fullmv(const FULLPEL_MV * mv,int stride)365*77c1e3ccSAndroid Build Coastguard Worker static inline int get_offset_from_fullmv(const FULLPEL_MV *mv, int stride) {
366*77c1e3ccSAndroid Build Coastguard Worker return mv->row * stride + mv->col;
367*77c1e3ccSAndroid Build Coastguard Worker }
368*77c1e3ccSAndroid Build Coastguard Worker
get_buf_from_fullmv(const struct buf_2d * buf,const FULLPEL_MV * mv)369*77c1e3ccSAndroid Build Coastguard Worker static inline const uint8_t *get_buf_from_fullmv(const struct buf_2d *buf,
370*77c1e3ccSAndroid Build Coastguard Worker const FULLPEL_MV *mv) {
371*77c1e3ccSAndroid Build Coastguard Worker return &buf->buf[get_offset_from_fullmv(mv, buf->stride)];
372*77c1e3ccSAndroid Build Coastguard Worker }
373*77c1e3ccSAndroid Build Coastguard Worker
374*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
375*77c1e3ccSAndroid Build Coastguard Worker } // extern "C"
376*77c1e3ccSAndroid Build Coastguard Worker #endif
377*77c1e3ccSAndroid Build Coastguard Worker
378*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_AV1_ENCODER_MCOMP_H_
379