• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AV1_ENCODER_ENCODER_UTILS_H_
13 #define AOM_AV1_ENCODER_ENCODER_UTILS_H_
14 
15 #include "config/aom_dsp_rtcd.h"
16 #include "config/aom_scale_rtcd.h"
17 
18 #include "av1/encoder/encoder.h"
19 #include "av1/encoder/encodetxb.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define AM_SEGMENT_ID_INACTIVE 7
26 #define AM_SEGMENT_ID_ACTIVE 0
27 #define DUMP_RECON_FRAMES 0
28 
29 extern const int default_tx_type_probs[FRAME_UPDATE_TYPES][TX_SIZES_ALL]
30                                       [TX_TYPES];
31 
32 extern const int default_obmc_probs[FRAME_UPDATE_TYPES][BLOCK_SIZES_ALL];
33 
34 extern const int default_warped_probs[FRAME_UPDATE_TYPES];
35 
36 extern const int default_switchable_interp_probs[FRAME_UPDATE_TYPES]
37                                                 [SWITCHABLE_FILTER_CONTEXTS]
38                                                 [SWITCHABLE_FILTERS];
39 
40 // Mark all inactive blocks as active. Other segmentation features may be set
41 // so memset cannot be used, instead only inactive blocks should be reset.
suppress_active_map(AV1_COMP * cpi)42 static AOM_INLINE void suppress_active_map(AV1_COMP *cpi) {
43   unsigned char *const seg_map = cpi->enc_seg.map;
44   int i;
45   const int num_mis =
46       cpi->common.mi_params.mi_rows * cpi->common.mi_params.mi_cols;
47   if (cpi->active_map.enabled || cpi->active_map.update)
48     for (i = 0; i < num_mis; ++i)
49       if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
50         seg_map[i] = AM_SEGMENT_ID_ACTIVE;
51 }
52 
53 // Returns 'size' in the number of Mode Info (MI) units. 'size' is either the
54 // width or height.
size_in_mi(int size)55 static AOM_INLINE int size_in_mi(int size) {
56   // Ensure that the decoded width and height are both multiples of
57   // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if
58   // subsampling is used).
59   // This simplifies the implementation of various experiments,
60   // eg. cdef, which operates on units of 8x8 luma pixels.
61   const int aligned_size = ALIGN_POWER_OF_TWO(size, 3);
62   return aligned_size >> MI_SIZE_LOG2;
63 }
64 
set_mb_mi(CommonModeInfoParams * mi_params,int width,int height)65 static AOM_INLINE void set_mb_mi(CommonModeInfoParams *mi_params, int width,
66                                  int height) {
67   mi_params->mi_cols = size_in_mi(width);
68   mi_params->mi_rows = size_in_mi(height);
69   mi_params->mi_stride = calc_mi_size(mi_params->mi_cols);
70 
71   mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2);
72   mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2);
73   mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols;
74 
75   const int mi_alloc_size_1d = mi_size_wide[mi_params->mi_alloc_bsize];
76   mi_params->mi_alloc_stride =
77       (mi_params->mi_stride + mi_alloc_size_1d - 1) / mi_alloc_size_1d;
78 
79   assert(mi_size_wide[mi_params->mi_alloc_bsize] ==
80          mi_size_high[mi_params->mi_alloc_bsize]);
81 }
82 
enc_free_mi(CommonModeInfoParams * mi_params)83 static AOM_INLINE void enc_free_mi(CommonModeInfoParams *mi_params) {
84   aom_free(mi_params->mi_alloc);
85   mi_params->mi_alloc = NULL;
86   mi_params->mi_alloc_size = 0;
87   aom_free(mi_params->mi_grid_base);
88   mi_params->mi_grid_base = NULL;
89   mi_params->mi_grid_size = 0;
90   aom_free(mi_params->tx_type_map);
91   mi_params->tx_type_map = NULL;
92 }
93 
enc_set_mb_mi(CommonModeInfoParams * mi_params,int width,int height,BLOCK_SIZE min_partition_size)94 static AOM_INLINE void enc_set_mb_mi(CommonModeInfoParams *mi_params, int width,
95                                      int height,
96                                      BLOCK_SIZE min_partition_size) {
97   mi_params->mi_alloc_bsize = min_partition_size;
98 
99   set_mb_mi(mi_params, width, height);
100 }
101 
stat_stage_set_mb_mi(CommonModeInfoParams * mi_params,int width,int height,BLOCK_SIZE min_partition_size)102 static AOM_INLINE void stat_stage_set_mb_mi(CommonModeInfoParams *mi_params,
103                                             int width, int height,
104                                             BLOCK_SIZE min_partition_size) {
105   (void)min_partition_size;
106   mi_params->mi_alloc_bsize = BLOCK_16X16;
107 
108   set_mb_mi(mi_params, width, height);
109 }
110 
enc_setup_mi(CommonModeInfoParams * mi_params)111 static AOM_INLINE void enc_setup_mi(CommonModeInfoParams *mi_params) {
112   const int mi_grid_size =
113       mi_params->mi_stride * calc_mi_size(mi_params->mi_rows);
114   memset(mi_params->mi_alloc, 0,
115          mi_params->mi_alloc_size * sizeof(*mi_params->mi_alloc));
116   memset(mi_params->mi_grid_base, 0,
117          mi_grid_size * sizeof(*mi_params->mi_grid_base));
118   memset(mi_params->tx_type_map, 0,
119          mi_grid_size * sizeof(*mi_params->tx_type_map));
120 }
121 
init_buffer_indices(ForceIntegerMVInfo * const force_intpel_info,int * const remapped_ref_idx)122 static AOM_INLINE void init_buffer_indices(
123     ForceIntegerMVInfo *const force_intpel_info, int *const remapped_ref_idx) {
124   int fb_idx;
125   for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx)
126     remapped_ref_idx[fb_idx] = fb_idx;
127   force_intpel_info->rate_index = 0;
128   force_intpel_info->rate_size = 0;
129 }
130 
131 #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, SDX3DF, JSDAF, JSVAF) \
132   ppi->fn_ptr[BT].sdf = SDF;                                                   \
133   ppi->fn_ptr[BT].sdaf = SDAF;                                                 \
134   ppi->fn_ptr[BT].vf = VF;                                                     \
135   ppi->fn_ptr[BT].svf = SVF;                                                   \
136   ppi->fn_ptr[BT].svaf = SVAF;                                                 \
137   ppi->fn_ptr[BT].sdx4df = SDX4DF;                                             \
138   ppi->fn_ptr[BT].sdx3df = SDX3DF;                                             \
139   ppi->fn_ptr[BT].jsdaf = JSDAF;                                               \
140   ppi->fn_ptr[BT].jsvaf = JSVAF;
141 
142 #define HIGHBD_BFP_WRAPPER(WIDTH, HEIGHT, BD)                                \
143   HIGHBD_BFP(                                                                \
144       BLOCK_##WIDTH##X##HEIGHT, aom_highbd_sad##WIDTH##x##HEIGHT##_bits##BD, \
145       aom_highbd_sad##WIDTH##x##HEIGHT##_avg_bits##BD,                       \
146       aom_highbd_##BD##_variance##WIDTH##x##HEIGHT,                          \
147       aom_highbd_##BD##_sub_pixel_variance##WIDTH##x##HEIGHT,                \
148       aom_highbd_##BD##_sub_pixel_avg_variance##WIDTH##x##HEIGHT,            \
149       aom_highbd_sad##WIDTH##x##HEIGHT##x4d_bits##BD,                        \
150       aom_highbd_sad##WIDTH##x##HEIGHT##x3d_bits##BD,                        \
151       aom_highbd_dist_wtd_sad##WIDTH##x##HEIGHT##_avg_bits##BD,              \
152       aom_highbd_##BD##_dist_wtd_sub_pixel_avg_variance##WIDTH##x##HEIGHT)
153 
154 #define MAKE_BFP_SAD_WRAPPER(fnname)                                           \
155   static unsigned int fnname##_bits8(const uint8_t *src_ptr,                   \
156                                      int source_stride,                        \
157                                      const uint8_t *ref_ptr, int ref_stride) { \
158     return fnname(src_ptr, source_stride, ref_ptr, ref_stride);                \
159   }                                                                            \
160   static unsigned int fnname##_bits10(                                         \
161       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
162       int ref_stride) {                                                        \
163     return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2;           \
164   }                                                                            \
165   static unsigned int fnname##_bits12(                                         \
166       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
167       int ref_stride) {                                                        \
168     return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4;           \
169   }
170 
171 #define MAKE_BFP_SADAVG_WRAPPER(fnname)                                        \
172   static unsigned int fnname##_bits8(                                          \
173       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
174       int ref_stride, const uint8_t *second_pred) {                            \
175     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred);   \
176   }                                                                            \
177   static unsigned int fnname##_bits10(                                         \
178       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
179       int ref_stride, const uint8_t *second_pred) {                            \
180     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
181            2;                                                                  \
182   }                                                                            \
183   static unsigned int fnname##_bits12(                                         \
184       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
185       int ref_stride, const uint8_t *second_pred) {                            \
186     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
187            4;                                                                  \
188   }
189 
190 #define MAKE_BFP_SAD4D_WRAPPER(fnname)                                        \
191   static void fnname##_bits8(const uint8_t *src_ptr, int source_stride,       \
192                              const uint8_t *const ref_ptr[], int ref_stride,  \
193                              unsigned int *sad_array) {                       \
194     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
195   }                                                                           \
196   static void fnname##_bits10(const uint8_t *src_ptr, int source_stride,      \
197                               const uint8_t *const ref_ptr[], int ref_stride, \
198                               unsigned int *sad_array) {                      \
199     int i;                                                                    \
200     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
201     for (i = 0; i < 4; i++) sad_array[i] >>= 2;                               \
202   }                                                                           \
203   static void fnname##_bits12(const uint8_t *src_ptr, int source_stride,      \
204                               const uint8_t *const ref_ptr[], int ref_stride, \
205                               unsigned int *sad_array) {                      \
206     int i;                                                                    \
207     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
208     for (i = 0; i < 4; i++) sad_array[i] >>= 4;                               \
209   }
210 
211 #define MAKE_BFP_JSADAVG_WRAPPER(fnname)                                    \
212   static unsigned int fnname##_bits8(                                       \
213       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,    \
214       int ref_stride, const uint8_t *second_pred,                           \
215       const DIST_WTD_COMP_PARAMS *jcp_param) {                              \
216     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
217                   jcp_param);                                               \
218   }                                                                         \
219   static unsigned int fnname##_bits10(                                      \
220       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,    \
221       int ref_stride, const uint8_t *second_pred,                           \
222       const DIST_WTD_COMP_PARAMS *jcp_param) {                              \
223     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
224                   jcp_param) >>                                             \
225            2;                                                               \
226   }                                                                         \
227   static unsigned int fnname##_bits12(                                      \
228       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,    \
229       int ref_stride, const uint8_t *second_pred,                           \
230       const DIST_WTD_COMP_PARAMS *jcp_param) {                              \
231     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
232                   jcp_param) >>                                             \
233            4;                                                               \
234   }
235 
236 #if CONFIG_AV1_HIGHBITDEPTH
237 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128)
MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)238 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)
239 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d)
240 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x3d)
241 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64)
242 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg)
243 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d)
244 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x3d)
245 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128)
246 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg)
247 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d)
248 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x3d)
249 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16)
250 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg)
251 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d)
252 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x3d)
253 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32)
254 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg)
255 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d)
256 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x3d)
257 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32)
258 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg)
259 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d)
260 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x3d)
261 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64)
262 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg)
263 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d)
264 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x3d)
265 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32)
266 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg)
267 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d)
268 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x3d)
269 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64)
270 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg)
271 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d)
272 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x3d)
273 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16)
274 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg)
275 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d)
276 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x3d)
277 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8)
278 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg)
279 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d)
280 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x3d)
281 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16)
282 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg)
283 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d)
284 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x3d)
285 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8)
286 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg)
287 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d)
288 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x3d)
289 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4)
290 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg)
291 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d)
292 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x3d)
293 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8)
294 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg)
295 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d)
296 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x3d)
297 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4)
298 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg)
299 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d)
300 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x3d)
301 
302 #if !CONFIG_REALTIME_ONLY
303 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16)
304 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg)
305 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d)
306 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x3d)
307 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4)
308 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg)
309 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d)
310 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x3d)
311 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32)
312 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg)
313 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d)
314 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x3d)
315 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8)
316 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg)
317 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d)
318 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x3d)
319 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64)
320 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg)
321 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d)
322 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x3d)
323 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16)
324 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg)
325 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d)
326 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x3d)
327 #endif
328 
329 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x128_avg)
330 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x64_avg)
331 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x128_avg)
332 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x16_avg)
333 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x32_avg)
334 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x32_avg)
335 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x64_avg)
336 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x32_avg)
337 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x64_avg)
338 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x16_avg)
339 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x8_avg)
340 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x16_avg)
341 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x8_avg)
342 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x4_avg)
343 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x8_avg)
344 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x4_avg)
345 #if !CONFIG_REALTIME_ONLY
346 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x16_avg)
347 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x4_avg)
348 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x32_avg)
349 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x8_avg)
350 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x64_avg)
351 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x16_avg)
352 #endif
353 #endif  // CONFIG_AV1_HIGHBITDEPTH
354 
355 #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \
356   ppi->fn_ptr[BT].msdf = MCSDF;       \
357   ppi->fn_ptr[BT].msvf = MCSVF;
358 
359 #define HIGHBD_MBFP_WRAPPER(WIDTH, HEIGHT, BD)                    \
360   HIGHBD_MBFP(BLOCK_##WIDTH##X##HEIGHT,                           \
361               aom_highbd_masked_sad##WIDTH##x##HEIGHT##_bits##BD, \
362               aom_highbd_##BD##_masked_sub_pixel_variance##WIDTH##x##HEIGHT)
363 
364 #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname)                           \
365   static unsigned int fnname##_bits8(                                    \
366       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
367       int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m,  \
368       int m_stride, int invert_mask) {                                   \
369     return fnname(src_ptr, source_stride, ref_ptr, ref_stride,           \
370                   second_pred_ptr, m, m_stride, invert_mask);            \
371   }                                                                      \
372   static unsigned int fnname##_bits10(                                   \
373       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
374       int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m,  \
375       int m_stride, int invert_mask) {                                   \
376     return fnname(src_ptr, source_stride, ref_ptr, ref_stride,           \
377                   second_pred_ptr, m, m_stride, invert_mask) >>          \
378            2;                                                            \
379   }                                                                      \
380   static unsigned int fnname##_bits12(                                   \
381       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
382       int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m,  \
383       int m_stride, int invert_mask) {                                   \
384     return fnname(src_ptr, source_stride, ref_ptr, ref_stride,           \
385                   second_pred_ptr, m, m_stride, invert_mask) >>          \
386            4;                                                            \
387   }
388 
389 #if CONFIG_AV1_HIGHBITDEPTH
390 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128)
391 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64)
392 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128)
393 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64)
394 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32)
395 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64)
396 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32)
397 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16)
398 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32)
399 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16)
400 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8)
401 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16)
402 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8)
403 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4)
404 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8)
405 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4)
406 #if !CONFIG_REALTIME_ONLY
407 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16)
408 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4)
409 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32)
410 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8)
411 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64)
412 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16)
413 #endif
414 #endif
415 
416 #define HIGHBD_SDSFP(BT, SDSF, SDSX4DF) \
417   ppi->fn_ptr[BT].sdsf = SDSF;          \
418   ppi->fn_ptr[BT].sdsx4df = SDSX4DF;
419 
420 #define HIGHBD_SDSFP_WRAPPER(WIDTH, HEIGHT, BD)                   \
421   HIGHBD_SDSFP(BLOCK_##WIDTH##X##HEIGHT,                          \
422                aom_highbd_sad_skip_##WIDTH##x##HEIGHT##_bits##BD, \
423                aom_highbd_sad_skip_##WIDTH##x##HEIGHT##x4d##_bits##BD)
424 
425 #define MAKE_SDSF_SKIP_SAD_WRAPPER(fnname)                                  \
426   static unsigned int fnname##_bits8(const uint8_t *src, int src_stride,    \
427                                      const uint8_t *ref, int ref_stride) {  \
428     return fnname(src, src_stride, ref, ref_stride);                        \
429   }                                                                         \
430   static unsigned int fnname##_bits10(const uint8_t *src, int src_stride,   \
431                                       const uint8_t *ref, int ref_stride) { \
432     return fnname(src, src_stride, ref, ref_stride) >> 2;                   \
433   }                                                                         \
434   static unsigned int fnname##_bits12(const uint8_t *src, int src_stride,   \
435                                       const uint8_t *ref, int ref_stride) { \
436     return fnname(src, src_stride, ref, ref_stride) >> 4;                   \
437   }
438 
439 #define MAKE_SDSF_SKIP_SAD_4D_WRAPPER(fnname)                                 \
440   static void fnname##_bits8(const uint8_t *src_ptr, int source_stride,       \
441                              const uint8_t *const ref_ptr[], int ref_stride,  \
442                              unsigned int *sad_array) {                       \
443     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
444   }                                                                           \
445   static void fnname##_bits10(const uint8_t *src_ptr, int source_stride,      \
446                               const uint8_t *const ref_ptr[], int ref_stride, \
447                               unsigned int *sad_array) {                      \
448     int i;                                                                    \
449     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
450     for (i = 0; i < 4; i++) sad_array[i] >>= 2;                               \
451   }                                                                           \
452   static void fnname##_bits12(const uint8_t *src_ptr, int source_stride,      \
453                               const uint8_t *const ref_ptr[], int ref_stride, \
454                               unsigned int *sad_array) {                      \
455     int i;                                                                    \
456     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
457     for (i = 0; i < 4; i++) sad_array[i] >>= 4;                               \
458   }
459 
460 #if CONFIG_AV1_HIGHBITDEPTH
461 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_128x128)
462 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_128x64)
463 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x128)
464 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x64)
465 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x32)
466 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x64)
467 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x32)
468 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x16)
469 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x32)
470 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x16)
471 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x8)
472 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x16)
473 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x8)
474 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_4x8)
475 
476 #if !CONFIG_REALTIME_ONLY
477 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x16)
478 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x8)
479 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x64)
480 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_4x16)
481 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x32)
482 #endif
483 
484 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_128x128x4d)
485 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_128x64x4d)
486 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x128x4d)
487 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x64x4d)
488 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x32x4d)
489 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x64x4d)
490 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x32x4d)
491 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x16x4d)
492 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x32x4d)
493 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x16x4d)
494 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x8x4d)
495 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x16x4d)
496 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x8x4d)
497 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_4x8x4d)
498 
499 #if !CONFIG_REALTIME_ONLY
500 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x16x4d)
501 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x8x4d)
502 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x64x4d)
503 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_4x16x4d)
504 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x32x4d)
505 #endif
506 #endif
507 
508 #if !CONFIG_REALTIME_ONLY
509 
510 #if CONFIG_AV1_HIGHBITDEPTH
511 #define HIGHBD_OBFP_WRAPPER_8(WIDTH, HEIGHT)                 \
512   HIGHBD_OBFP(BLOCK_##WIDTH##X##HEIGHT,                      \
513               aom_highbd_obmc_sad##WIDTH##x##HEIGHT##_bits8, \
514               aom_highbd_8_obmc_variance##WIDTH##x##HEIGHT,  \
515               aom_highbd_8_obmc_sub_pixel_variance##WIDTH##x##HEIGHT)
516 
517 #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \
518   ppi->fn_ptr[BT].osdf = OSDF;           \
519   ppi->fn_ptr[BT].ovf = OVF;             \
520   ppi->fn_ptr[BT].osvf = OSVF;
521 
522 #define HIGHBD_OBFP_WRAPPER(WIDTH, HEIGHT, BD)                   \
523   HIGHBD_OBFP(BLOCK_##WIDTH##X##HEIGHT,                          \
524               aom_highbd_obmc_sad##WIDTH##x##HEIGHT##_bits##BD,  \
525               aom_highbd_##BD##_obmc_variance##WIDTH##x##HEIGHT, \
526               aom_highbd_##BD##_obmc_sub_pixel_variance##WIDTH##x##HEIGHT)
527 
528 #define MAKE_OBFP_SAD_WRAPPER(fnname)                                     \
529   static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride,  \
530                                      const int32_t *wsrc,                 \
531                                      const int32_t *msk) {                \
532     return fnname(ref, ref_stride, wsrc, msk);                            \
533   }                                                                       \
534   static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \
535                                       const int32_t *wsrc,                \
536                                       const int32_t *msk) {               \
537     return fnname(ref, ref_stride, wsrc, msk) >> 2;                       \
538   }                                                                       \
539   static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \
540                                       const int32_t *wsrc,                \
541                                       const int32_t *msk) {               \
542     return fnname(ref, ref_stride, wsrc, msk) >> 4;                       \
543   }
544 #endif  // CONFIG_AV1_HIGHBITDEPTH
545 #endif  // !CONFIG_REALTIME_ONLY
546 
547 #if CONFIG_AV1_HIGHBITDEPTH
548 #if !CONFIG_REALTIME_ONLY
549 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128)
550 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64)
551 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128)
552 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64)
553 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32)
554 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64)
555 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32)
556 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16)
557 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32)
558 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16)
559 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8)
560 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16)
561 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8)
562 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4)
563 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8)
564 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4)
565 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16)
566 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4)
567 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32)
568 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8)
569 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64)
570 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16)
571 #endif
572 
573 static AOM_INLINE void highbd_set_var_fns(AV1_PRIMARY *const ppi) {
574   SequenceHeader *const seq_params = &ppi->seq_params;
575   if (seq_params->use_highbitdepth) {
576     switch (seq_params->bit_depth) {
577       case AOM_BITS_8:
578 #if !CONFIG_REALTIME_ONLY
579         HIGHBD_BFP_WRAPPER(64, 16, 8)
580         HIGHBD_BFP_WRAPPER(16, 64, 8)
581         HIGHBD_BFP_WRAPPER(32, 8, 8)
582         HIGHBD_BFP_WRAPPER(8, 32, 8)
583         HIGHBD_BFP_WRAPPER(16, 4, 8)
584         HIGHBD_BFP_WRAPPER(4, 16, 8)
585 #endif
586         HIGHBD_BFP_WRAPPER(32, 16, 8)
587         HIGHBD_BFP_WRAPPER(16, 32, 8)
588         HIGHBD_BFP_WRAPPER(64, 32, 8)
589         HIGHBD_BFP_WRAPPER(32, 64, 8)
590         HIGHBD_BFP_WRAPPER(32, 32, 8)
591         HIGHBD_BFP_WRAPPER(64, 64, 8)
592         HIGHBD_BFP_WRAPPER(16, 16, 8)
593         HIGHBD_BFP_WRAPPER(16, 8, 8)
594         HIGHBD_BFP_WRAPPER(8, 16, 8)
595         HIGHBD_BFP_WRAPPER(8, 8, 8)
596         HIGHBD_BFP_WRAPPER(8, 4, 8)
597         HIGHBD_BFP_WRAPPER(4, 8, 8)
598         HIGHBD_BFP_WRAPPER(4, 4, 8)
599         HIGHBD_BFP_WRAPPER(128, 128, 8)
600         HIGHBD_BFP_WRAPPER(128, 64, 8)
601         HIGHBD_BFP_WRAPPER(64, 128, 8)
602 
603         HIGHBD_MBFP_WRAPPER(128, 128, 8)
604         HIGHBD_MBFP_WRAPPER(128, 64, 8)
605         HIGHBD_MBFP_WRAPPER(64, 128, 8)
606         HIGHBD_MBFP_WRAPPER(64, 64, 8)
607         HIGHBD_MBFP_WRAPPER(64, 32, 8)
608         HIGHBD_MBFP_WRAPPER(32, 64, 8)
609         HIGHBD_MBFP_WRAPPER(32, 32, 8)
610         HIGHBD_MBFP_WRAPPER(32, 16, 8)
611         HIGHBD_MBFP_WRAPPER(16, 32, 8)
612         HIGHBD_MBFP_WRAPPER(16, 16, 8)
613         HIGHBD_MBFP_WRAPPER(8, 16, 8)
614         HIGHBD_MBFP_WRAPPER(16, 8, 8)
615         HIGHBD_MBFP_WRAPPER(8, 8, 8)
616         HIGHBD_MBFP_WRAPPER(4, 8, 8)
617         HIGHBD_MBFP_WRAPPER(8, 4, 8)
618         HIGHBD_MBFP_WRAPPER(4, 4, 8)
619 #if !CONFIG_REALTIME_ONLY
620         HIGHBD_MBFP_WRAPPER(64, 16, 8)
621         HIGHBD_MBFP_WRAPPER(16, 64, 8)
622         HIGHBD_MBFP_WRAPPER(32, 8, 8)
623         HIGHBD_MBFP_WRAPPER(8, 32, 8)
624         HIGHBD_MBFP_WRAPPER(16, 4, 8)
625         HIGHBD_MBFP_WRAPPER(4, 16, 8)
626 #endif
627 
628 // OBMC excluded from realtime only build.
629 #if !CONFIG_REALTIME_ONLY
630         HIGHBD_OBFP_WRAPPER_8(128, 128)
631         HIGHBD_OBFP_WRAPPER_8(128, 64)
632         HIGHBD_OBFP_WRAPPER_8(64, 128)
633         HIGHBD_OBFP_WRAPPER_8(64, 64)
634         HIGHBD_OBFP_WRAPPER_8(64, 32)
635         HIGHBD_OBFP_WRAPPER_8(32, 64)
636         HIGHBD_OBFP_WRAPPER_8(32, 32)
637         HIGHBD_OBFP_WRAPPER_8(32, 16)
638         HIGHBD_OBFP_WRAPPER_8(16, 32)
639         HIGHBD_OBFP_WRAPPER_8(16, 16)
640         HIGHBD_OBFP_WRAPPER_8(8, 16)
641         HIGHBD_OBFP_WRAPPER_8(16, 8)
642         HIGHBD_OBFP_WRAPPER_8(8, 8)
643         HIGHBD_OBFP_WRAPPER_8(4, 8)
644         HIGHBD_OBFP_WRAPPER_8(8, 4)
645         HIGHBD_OBFP_WRAPPER_8(4, 4)
646         HIGHBD_OBFP_WRAPPER_8(64, 16)
647         HIGHBD_OBFP_WRAPPER_8(16, 64)
648         HIGHBD_OBFP_WRAPPER_8(32, 8)
649         HIGHBD_OBFP_WRAPPER_8(8, 32)
650         HIGHBD_OBFP_WRAPPER_8(16, 4)
651         HIGHBD_OBFP_WRAPPER_8(4, 16)
652 #endif
653 
654         HIGHBD_SDSFP_WRAPPER(128, 128, 8)
655         HIGHBD_SDSFP_WRAPPER(128, 64, 8)
656         HIGHBD_SDSFP_WRAPPER(64, 128, 8)
657         HIGHBD_SDSFP_WRAPPER(64, 64, 8)
658         HIGHBD_SDSFP_WRAPPER(64, 32, 8)
659         HIGHBD_SDSFP_WRAPPER(32, 64, 8)
660         HIGHBD_SDSFP_WRAPPER(32, 32, 8)
661         HIGHBD_SDSFP_WRAPPER(32, 16, 8)
662         HIGHBD_SDSFP_WRAPPER(16, 32, 8)
663         HIGHBD_SDSFP_WRAPPER(16, 16, 8)
664         HIGHBD_SDSFP_WRAPPER(16, 8, 8)
665         HIGHBD_SDSFP_WRAPPER(8, 16, 8)
666         HIGHBD_SDSFP_WRAPPER(8, 8, 8)
667         HIGHBD_SDSFP_WRAPPER(4, 8, 8)
668 #if !CONFIG_REALTIME_ONLY
669         HIGHBD_SDSFP_WRAPPER(64, 16, 8)
670         HIGHBD_SDSFP_WRAPPER(32, 8, 8)
671         HIGHBD_SDSFP_WRAPPER(16, 64, 8)
672         HIGHBD_SDSFP_WRAPPER(8, 32, 8)
673         HIGHBD_SDSFP_WRAPPER(4, 16, 8)
674 #endif
675         break;
676 
677       case AOM_BITS_10:
678 #if !CONFIG_REALTIME_ONLY
679         HIGHBD_BFP_WRAPPER(64, 16, 10)
680         HIGHBD_BFP_WRAPPER(16, 64, 10)
681         HIGHBD_BFP_WRAPPER(32, 8, 10)
682         HIGHBD_BFP_WRAPPER(8, 32, 10)
683         HIGHBD_BFP_WRAPPER(16, 4, 10)
684         HIGHBD_BFP_WRAPPER(4, 16, 10)
685 #endif
686         HIGHBD_BFP_WRAPPER(32, 16, 10)
687         HIGHBD_BFP_WRAPPER(16, 32, 10)
688         HIGHBD_BFP_WRAPPER(64, 32, 10)
689         HIGHBD_BFP_WRAPPER(32, 64, 10)
690         HIGHBD_BFP_WRAPPER(32, 32, 10)
691         HIGHBD_BFP_WRAPPER(64, 64, 10)
692         HIGHBD_BFP_WRAPPER(16, 16, 10)
693         HIGHBD_BFP_WRAPPER(16, 8, 10)
694         HIGHBD_BFP_WRAPPER(8, 16, 10)
695         HIGHBD_BFP_WRAPPER(8, 8, 10)
696         HIGHBD_BFP_WRAPPER(8, 4, 10)
697         HIGHBD_BFP_WRAPPER(4, 8, 10)
698         HIGHBD_BFP_WRAPPER(4, 4, 10)
699         HIGHBD_BFP_WRAPPER(128, 128, 10)
700         HIGHBD_BFP_WRAPPER(128, 64, 10)
701         HIGHBD_BFP_WRAPPER(64, 128, 10)
702 
703         HIGHBD_MBFP_WRAPPER(128, 128, 10)
704         HIGHBD_MBFP_WRAPPER(128, 64, 10)
705         HIGHBD_MBFP_WRAPPER(64, 128, 10)
706         HIGHBD_MBFP_WRAPPER(64, 64, 10)
707         HIGHBD_MBFP_WRAPPER(64, 32, 10)
708         HIGHBD_MBFP_WRAPPER(32, 64, 10)
709         HIGHBD_MBFP_WRAPPER(32, 32, 10)
710         HIGHBD_MBFP_WRAPPER(32, 16, 10)
711         HIGHBD_MBFP_WRAPPER(16, 32, 10)
712         HIGHBD_MBFP_WRAPPER(16, 16, 10)
713         HIGHBD_MBFP_WRAPPER(8, 16, 10)
714         HIGHBD_MBFP_WRAPPER(16, 8, 10)
715         HIGHBD_MBFP_WRAPPER(8, 8, 10)
716         HIGHBD_MBFP_WRAPPER(4, 8, 10)
717         HIGHBD_MBFP_WRAPPER(8, 4, 10)
718         HIGHBD_MBFP_WRAPPER(4, 4, 10)
719 #if !CONFIG_REALTIME_ONLY
720         HIGHBD_MBFP_WRAPPER(64, 16, 10)
721         HIGHBD_MBFP_WRAPPER(16, 64, 10)
722         HIGHBD_MBFP_WRAPPER(32, 8, 10)
723         HIGHBD_MBFP_WRAPPER(8, 32, 10)
724         HIGHBD_MBFP_WRAPPER(16, 4, 10)
725         HIGHBD_MBFP_WRAPPER(4, 16, 10)
726 #endif
727 
728 // OBMC excluded from realtime only build.
729 #if !CONFIG_REALTIME_ONLY
730         HIGHBD_OBFP_WRAPPER(128, 128, 10)
731         HIGHBD_OBFP_WRAPPER(128, 64, 10)
732         HIGHBD_OBFP_WRAPPER(64, 128, 10)
733         HIGHBD_OBFP_WRAPPER(64, 64, 10)
734         HIGHBD_OBFP_WRAPPER(64, 32, 10)
735         HIGHBD_OBFP_WRAPPER(32, 64, 10)
736         HIGHBD_OBFP_WRAPPER(32, 32, 10)
737         HIGHBD_OBFP_WRAPPER(32, 16, 10)
738         HIGHBD_OBFP_WRAPPER(16, 32, 10)
739         HIGHBD_OBFP_WRAPPER(16, 16, 10)
740         HIGHBD_OBFP_WRAPPER(8, 16, 10)
741         HIGHBD_OBFP_WRAPPER(16, 8, 10)
742         HIGHBD_OBFP_WRAPPER(8, 8, 10)
743         HIGHBD_OBFP_WRAPPER(4, 8, 10)
744         HIGHBD_OBFP_WRAPPER(8, 4, 10)
745         HIGHBD_OBFP_WRAPPER(4, 4, 10)
746         HIGHBD_OBFP_WRAPPER(64, 16, 10)
747         HIGHBD_OBFP_WRAPPER(16, 64, 10)
748         HIGHBD_OBFP_WRAPPER(32, 8, 10)
749         HIGHBD_OBFP_WRAPPER(8, 32, 10)
750         HIGHBD_OBFP_WRAPPER(16, 4, 10)
751         HIGHBD_OBFP_WRAPPER(4, 16, 10)
752 #endif
753 
754         HIGHBD_SDSFP_WRAPPER(128, 128, 10)
755         HIGHBD_SDSFP_WRAPPER(128, 64, 10)
756         HIGHBD_SDSFP_WRAPPER(64, 128, 10)
757         HIGHBD_SDSFP_WRAPPER(64, 64, 10)
758         HIGHBD_SDSFP_WRAPPER(64, 32, 10)
759         HIGHBD_SDSFP_WRAPPER(32, 64, 10)
760         HIGHBD_SDSFP_WRAPPER(32, 32, 10)
761         HIGHBD_SDSFP_WRAPPER(32, 16, 10)
762         HIGHBD_SDSFP_WRAPPER(16, 32, 10)
763         HIGHBD_SDSFP_WRAPPER(16, 16, 10)
764         HIGHBD_SDSFP_WRAPPER(16, 8, 10)
765         HIGHBD_SDSFP_WRAPPER(8, 16, 10)
766         HIGHBD_SDSFP_WRAPPER(8, 8, 10)
767         HIGHBD_SDSFP_WRAPPER(4, 8, 10)
768 
769 #if !CONFIG_REALTIME_ONLY
770         HIGHBD_SDSFP_WRAPPER(64, 16, 10)
771         HIGHBD_SDSFP_WRAPPER(32, 8, 10)
772         HIGHBD_SDSFP_WRAPPER(16, 64, 10)
773         HIGHBD_SDSFP_WRAPPER(8, 32, 10)
774         HIGHBD_SDSFP_WRAPPER(4, 16, 10)
775 #endif
776         break;
777 
778       case AOM_BITS_12:
779 #if !CONFIG_REALTIME_ONLY
780         HIGHBD_BFP_WRAPPER(64, 16, 12)
781         HIGHBD_BFP_WRAPPER(16, 64, 12)
782         HIGHBD_BFP_WRAPPER(32, 8, 12)
783         HIGHBD_BFP_WRAPPER(8, 32, 12)
784         HIGHBD_BFP_WRAPPER(16, 4, 12)
785         HIGHBD_BFP_WRAPPER(4, 16, 12)
786 #endif
787         HIGHBD_BFP_WRAPPER(32, 16, 12)
788         HIGHBD_BFP_WRAPPER(16, 32, 12)
789         HIGHBD_BFP_WRAPPER(64, 32, 12)
790         HIGHBD_BFP_WRAPPER(32, 64, 12)
791         HIGHBD_BFP_WRAPPER(32, 32, 12)
792         HIGHBD_BFP_WRAPPER(64, 64, 12)
793         HIGHBD_BFP_WRAPPER(16, 16, 12)
794         HIGHBD_BFP_WRAPPER(16, 8, 12)
795         HIGHBD_BFP_WRAPPER(8, 16, 12)
796         HIGHBD_BFP_WRAPPER(8, 8, 12)
797         HIGHBD_BFP_WRAPPER(8, 4, 12)
798         HIGHBD_BFP_WRAPPER(4, 8, 12)
799         HIGHBD_BFP_WRAPPER(4, 4, 12)
800         HIGHBD_BFP_WRAPPER(128, 128, 12)
801         HIGHBD_BFP_WRAPPER(128, 64, 12)
802         HIGHBD_BFP_WRAPPER(64, 128, 12)
803 
804         HIGHBD_MBFP_WRAPPER(128, 128, 12)
805         HIGHBD_MBFP_WRAPPER(128, 64, 12)
806         HIGHBD_MBFP_WRAPPER(64, 128, 12)
807         HIGHBD_MBFP_WRAPPER(64, 64, 12)
808         HIGHBD_MBFP_WRAPPER(64, 32, 12)
809         HIGHBD_MBFP_WRAPPER(32, 64, 12)
810         HIGHBD_MBFP_WRAPPER(32, 32, 12)
811         HIGHBD_MBFP_WRAPPER(32, 16, 12)
812         HIGHBD_MBFP_WRAPPER(16, 32, 12)
813         HIGHBD_MBFP_WRAPPER(16, 16, 12)
814         HIGHBD_MBFP_WRAPPER(8, 16, 12)
815         HIGHBD_MBFP_WRAPPER(16, 8, 12)
816         HIGHBD_MBFP_WRAPPER(8, 8, 12)
817         HIGHBD_MBFP_WRAPPER(4, 8, 12)
818         HIGHBD_MBFP_WRAPPER(8, 4, 12)
819         HIGHBD_MBFP_WRAPPER(4, 4, 12)
820 #if !CONFIG_REALTIME_ONLY
821         HIGHBD_MBFP_WRAPPER(64, 16, 12)
822         HIGHBD_MBFP_WRAPPER(16, 64, 12)
823         HIGHBD_MBFP_WRAPPER(32, 8, 12)
824         HIGHBD_MBFP_WRAPPER(8, 32, 12)
825         HIGHBD_MBFP_WRAPPER(16, 4, 12)
826         HIGHBD_MBFP_WRAPPER(4, 16, 12)
827 #endif
828 
829 // OBMC excluded from realtime only build.
830 #if !CONFIG_REALTIME_ONLY
831         HIGHBD_OBFP_WRAPPER(128, 128, 12)
832         HIGHBD_OBFP_WRAPPER(128, 64, 12)
833         HIGHBD_OBFP_WRAPPER(64, 128, 12)
834         HIGHBD_OBFP_WRAPPER(64, 64, 12)
835         HIGHBD_OBFP_WRAPPER(64, 32, 12)
836         HIGHBD_OBFP_WRAPPER(32, 64, 12)
837         HIGHBD_OBFP_WRAPPER(32, 32, 12)
838         HIGHBD_OBFP_WRAPPER(32, 16, 12)
839         HIGHBD_OBFP_WRAPPER(16, 32, 12)
840         HIGHBD_OBFP_WRAPPER(16, 16, 12)
841         HIGHBD_OBFP_WRAPPER(8, 16, 12)
842         HIGHBD_OBFP_WRAPPER(16, 8, 12)
843         HIGHBD_OBFP_WRAPPER(8, 8, 12)
844         HIGHBD_OBFP_WRAPPER(4, 8, 12)
845         HIGHBD_OBFP_WRAPPER(8, 4, 12)
846         HIGHBD_OBFP_WRAPPER(4, 4, 12)
847         HIGHBD_OBFP_WRAPPER(64, 16, 12)
848         HIGHBD_OBFP_WRAPPER(16, 64, 12)
849         HIGHBD_OBFP_WRAPPER(32, 8, 12)
850         HIGHBD_OBFP_WRAPPER(8, 32, 12)
851         HIGHBD_OBFP_WRAPPER(16, 4, 12)
852         HIGHBD_OBFP_WRAPPER(4, 16, 12)
853 #endif
854 
855         HIGHBD_SDSFP_WRAPPER(128, 128, 12)
856         HIGHBD_SDSFP_WRAPPER(128, 64, 12)
857         HIGHBD_SDSFP_WRAPPER(64, 128, 12)
858         HIGHBD_SDSFP_WRAPPER(64, 64, 12)
859         HIGHBD_SDSFP_WRAPPER(64, 32, 12)
860         HIGHBD_SDSFP_WRAPPER(32, 64, 12)
861         HIGHBD_SDSFP_WRAPPER(32, 32, 12)
862         HIGHBD_SDSFP_WRAPPER(32, 16, 12)
863         HIGHBD_SDSFP_WRAPPER(16, 32, 12)
864         HIGHBD_SDSFP_WRAPPER(16, 16, 12)
865         HIGHBD_SDSFP_WRAPPER(16, 8, 12)
866         HIGHBD_SDSFP_WRAPPER(8, 16, 12)
867         HIGHBD_SDSFP_WRAPPER(8, 8, 12)
868         HIGHBD_SDSFP_WRAPPER(4, 8, 12)
869 
870 #if !CONFIG_REALTIME_ONLY
871         HIGHBD_SDSFP_WRAPPER(64, 16, 12)
872         HIGHBD_SDSFP_WRAPPER(32, 8, 12)
873         HIGHBD_SDSFP_WRAPPER(16, 64, 12)
874         HIGHBD_SDSFP_WRAPPER(8, 32, 12)
875         HIGHBD_SDSFP_WRAPPER(4, 16, 12)
876 #endif
877         break;
878 
879       default:
880         assert(0 &&
881                "cm->seq_params->bit_depth should be AOM_BITS_8, "
882                "AOM_BITS_10 or AOM_BITS_12");
883     }
884   }
885 }
886 #endif  // CONFIG_AV1_HIGHBITDEPTH
887 
copy_frame_prob_info(AV1_COMP * cpi)888 static AOM_INLINE void copy_frame_prob_info(AV1_COMP *cpi) {
889   FrameProbInfo *const frame_probs = &cpi->ppi->frame_probs;
890   if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats) {
891     av1_copy(frame_probs->tx_type_probs, default_tx_type_probs);
892   }
893   if (cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 &&
894       cpi->sf.inter_sf.prune_obmc_prob_thresh < INT_MAX) {
895     av1_copy(frame_probs->obmc_probs, default_obmc_probs);
896   }
897   if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0) {
898     av1_copy(frame_probs->warped_probs, default_warped_probs);
899   }
900   if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) {
901     av1_copy(frame_probs->switchable_interp_probs,
902              default_switchable_interp_probs);
903   }
904 
905 #if CONFIG_FPMT_TEST
906   if (cpi->ppi->fpmt_unit_test_cfg == PARALLEL_SIMULATION_ENCODE) {
907     FrameProbInfo *const temp_frame_probs = &cpi->ppi->temp_frame_probs;
908     if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats) {
909       av1_copy(temp_frame_probs->tx_type_probs, default_tx_type_probs);
910     }
911     if (cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 &&
912         cpi->sf.inter_sf.prune_obmc_prob_thresh < INT_MAX) {
913       av1_copy(temp_frame_probs->obmc_probs, default_obmc_probs);
914     }
915     if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0) {
916       av1_copy(temp_frame_probs->warped_probs, default_warped_probs);
917     }
918     if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) {
919       av1_copy(temp_frame_probs->switchable_interp_probs,
920                default_switchable_interp_probs);
921     }
922 
923     FrameProbInfo *const temp_frame_probs_simulation =
924         &cpi->ppi->temp_frame_probs_simulation;
925     if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats) {
926       av1_copy(temp_frame_probs_simulation->tx_type_probs,
927                default_tx_type_probs);
928     }
929     if (cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 &&
930         cpi->sf.inter_sf.prune_obmc_prob_thresh < INT_MAX) {
931       av1_copy(temp_frame_probs_simulation->obmc_probs, default_obmc_probs);
932     }
933     if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0) {
934       av1_copy(temp_frame_probs_simulation->warped_probs, default_warped_probs);
935     }
936     if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) {
937       av1_copy(temp_frame_probs_simulation->switchable_interp_probs,
938                default_switchable_interp_probs);
939     }
940   }
941 #endif
942 }
943 
restore_cdef_coding_context(CdefInfo * const dst,const CdefInfo * const src)944 static AOM_INLINE void restore_cdef_coding_context(CdefInfo *const dst,
945                                                    const CdefInfo *const src) {
946   dst->cdef_bits = src->cdef_bits;
947   dst->cdef_damping = src->cdef_damping;
948   av1_copy(dst->cdef_strengths, src->cdef_strengths);
949   av1_copy(dst->cdef_uv_strengths, src->cdef_uv_strengths);
950   dst->nb_cdef_strengths = src->nb_cdef_strengths;
951 }
952 
953 // Coding context that only needs to be restored when recode loop includes
954 // filtering (deblocking, CDEF, superres post-encode upscale and/or loop
955 // restoraton).
restore_extra_coding_context(AV1_COMP * cpi)956 static AOM_INLINE void restore_extra_coding_context(AV1_COMP *cpi) {
957   CODING_CONTEXT *const cc = &cpi->coding_context;
958   AV1_COMMON *cm = &cpi->common;
959   cm->lf = cc->lf;
960   restore_cdef_coding_context(&cm->cdef_info, &cc->cdef_info);
961   cpi->rc = cc->rc;
962   cpi->ppi->mv_stats = cc->mv_stats;
963 }
964 
equal_dimensions_and_border(const YV12_BUFFER_CONFIG * a,const YV12_BUFFER_CONFIG * b)965 static AOM_INLINE int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a,
966                                                   const YV12_BUFFER_CONFIG *b) {
967   return a->y_height == b->y_height && a->y_width == b->y_width &&
968          a->uv_height == b->uv_height && a->uv_width == b->uv_width &&
969          a->y_stride == b->y_stride && a->uv_stride == b->uv_stride &&
970          a->border == b->border &&
971          (a->flags & YV12_FLAG_HIGHBITDEPTH) ==
972              (b->flags & YV12_FLAG_HIGHBITDEPTH);
973 }
974 
update_entropy(bool * ext_refresh_frame_context,bool * ext_refresh_frame_context_pending,bool update)975 static AOM_INLINE int update_entropy(bool *ext_refresh_frame_context,
976                                      bool *ext_refresh_frame_context_pending,
977                                      bool update) {
978   *ext_refresh_frame_context = update;
979   *ext_refresh_frame_context_pending = 1;
980   return 0;
981 }
982 
983 #if !CONFIG_REALTIME_ONLY
combine_prior_with_tpl_boost(double min_factor,double max_factor,int prior_boost,int tpl_boost,int frames_to_key)984 static AOM_INLINE int combine_prior_with_tpl_boost(double min_factor,
985                                                    double max_factor,
986                                                    int prior_boost,
987                                                    int tpl_boost,
988                                                    int frames_to_key) {
989   double factor = sqrt((double)frames_to_key);
990   double range = max_factor - min_factor;
991   factor = AOMMIN(factor, max_factor);
992   factor = AOMMAX(factor, min_factor);
993   factor -= min_factor;
994   int boost =
995       (int)((factor * prior_boost + (range - factor) * tpl_boost) / range);
996   return boost;
997 }
998 #endif
999 
set_size_independent_vars(AV1_COMP * cpi)1000 static AOM_INLINE void set_size_independent_vars(AV1_COMP *cpi) {
1001   int i;
1002   AV1_COMMON *const cm = &cpi->common;
1003   FeatureFlags *const features = &cm->features;
1004   for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
1005     cm->global_motion[i] = default_warp_params;
1006   }
1007   cpi->gm_info.search_done = 0;
1008 
1009   av1_set_speed_features_framesize_independent(cpi, cpi->speed);
1010   av1_set_rd_speed_thresholds(cpi);
1011   features->interp_filter = SWITCHABLE;
1012   features->switchable_motion_mode = is_switchable_motion_mode_allowed(
1013       features->allow_warped_motion, cpi->oxcf.motion_mode_cfg.enable_obmc);
1014 }
1015 
release_scaled_references(AV1_COMP * cpi)1016 static AOM_INLINE void release_scaled_references(AV1_COMP *cpi) {
1017   // Scaled references should only need to be released under certain conditions:
1018   // if the reference will be updated, or if the scaled reference has same
1019   // resolution. For now only apply this to Golden for non-svc RTC mode.
1020   AV1_COMMON *const cm = &cpi->common;
1021   const bool refresh_golden = (cpi->refresh_frame.golden_frame) ? 1 : 0;
1022   bool release_golden = true;
1023   for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
1024     RefCntBuffer *const buf = cpi->scaled_ref_buf[i];
1025     const int golden_ref = (i == GOLDEN_FRAME - 1);
1026     if (golden_ref && is_one_pass_rt_params(cpi) && !cpi->ppi->use_svc &&
1027         buf != NULL) {
1028       const RefCntBuffer *const ref = get_ref_frame_buf(cm, GOLDEN_FRAME);
1029       const bool same_resoln = buf->buf.y_crop_width == ref->buf.y_crop_width &&
1030                                buf->buf.y_crop_height == ref->buf.y_crop_height;
1031       release_golden = refresh_golden || same_resoln;
1032     }
1033     if (buf != NULL && (!golden_ref || (golden_ref && release_golden))) {
1034       --buf->ref_count;
1035       cpi->scaled_ref_buf[i] = NULL;
1036     }
1037   }
1038 }
1039 
restore_all_coding_context(AV1_COMP * cpi)1040 static AOM_INLINE void restore_all_coding_context(AV1_COMP *cpi) {
1041   restore_extra_coding_context(cpi);
1042   if (!frame_is_intra_only(&cpi->common)) release_scaled_references(cpi);
1043 }
1044 
reduce_num_ref_buffers(const AV1_COMP * cpi)1045 static AOM_INLINE int reduce_num_ref_buffers(const AV1_COMP *cpi) {
1046   const SequenceHeader *const seq_params = cpi->common.seq_params;
1047   return is_one_pass_rt_params(cpi) &&
1048          use_rtc_reference_structure_one_layer(cpi) &&
1049          (seq_params->order_hint_info.enable_order_hint == 0) &&
1050          cpi->rt_reduce_num_ref_buffers;
1051 }
1052 
1053 // Refresh reference frame buffers according to refresh_frame_flags.
refresh_reference_frames(AV1_COMP * cpi)1054 static AOM_INLINE void refresh_reference_frames(AV1_COMP *cpi) {
1055   AV1_COMMON *const cm = &cpi->common;
1056   // All buffers are refreshed for shown keyframes and S-frames.
1057   // In case of RT, golden frame refreshes the 6th slot and other reference
1058   // frames refresh slots 0 to 5. Slot 7 is not refreshed by any reference
1059   // frame. Thus, only 7 buffers are refreshed for keyframes and S-frames
1060   // instead of 8.
1061   int num_ref_buffers = REF_FRAMES;
1062   if (reduce_num_ref_buffers(cpi)) {
1063     const int refresh_all_bufs =
1064         (cpi->ppi->gf_group.refbuf_state[cpi->gf_frame_index] == REFBUF_RESET ||
1065          frame_is_sframe(cm));
1066     assert(IMPLIES(((cm->current_frame.refresh_frame_flags >> 7) & 1) == 1,
1067                    refresh_all_bufs));
1068     (void)refresh_all_bufs;
1069     num_ref_buffers--;
1070   }
1071 
1072   for (int ref_frame = 0; ref_frame < num_ref_buffers; ref_frame++) {
1073     if (((cm->current_frame.refresh_frame_flags >> ref_frame) & 1) == 1) {
1074       assign_frame_buffer_p(&cm->ref_frame_map[ref_frame], cm->cur_frame);
1075     }
1076   }
1077 }
1078 
1079 void av1_update_film_grain_parameters_seq(struct AV1_PRIMARY *ppi,
1080                                           const AV1EncoderConfig *oxcf);
1081 void av1_update_film_grain_parameters(struct AV1_COMP *cpi,
1082                                       const AV1EncoderConfig *oxcf);
1083 
1084 void av1_scale_references(AV1_COMP *cpi, const InterpFilter filter,
1085                           const int phase, const int use_optimized_scaler);
1086 
1087 void av1_setup_frame(AV1_COMP *cpi);
1088 
1089 BLOCK_SIZE av1_select_sb_size(const AV1EncoderConfig *const oxcf, int width,
1090                               int height, int number_spatial_layers);
1091 
1092 void av1_apply_active_map(AV1_COMP *cpi);
1093 
1094 #if !CONFIG_REALTIME_ONLY
1095 uint16_t av1_setup_interp_filter_search_mask(AV1_COMP *cpi);
1096 
1097 void av1_determine_sc_tools_with_encoding(AV1_COMP *cpi, const int q_orig);
1098 #endif
1099 
1100 void av1_set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index,
1101                                  int *top_index);
1102 
1103 void av1_finalize_encoded_frame(AV1_COMP *const cpi);
1104 
1105 int av1_is_integer_mv(const YV12_BUFFER_CONFIG *cur_picture,
1106                       const YV12_BUFFER_CONFIG *last_picture,
1107                       ForceIntegerMVInfo *const force_intpel_info);
1108 
1109 void av1_set_mb_ssim_rdmult_scaling(AV1_COMP *cpi);
1110 
1111 void av1_save_all_coding_context(AV1_COMP *cpi);
1112 
1113 #if DUMP_RECON_FRAMES == 1
1114 void av1_dump_filtered_recon_frames(AV1_COMP *cpi);
1115 #endif
1116 
av1_get_enc_border_size(bool resize,bool all_intra,BLOCK_SIZE sb_size)1117 static AOM_INLINE int av1_get_enc_border_size(bool resize, bool all_intra,
1118                                               BLOCK_SIZE sb_size) {
1119   // For allintra encoding mode, inter-frame motion search is not applicable and
1120   // the intraBC motion vectors are restricted within the tile boundaries. Hence
1121   // a smaller frame border size (AOM_ENC_ALLINTRA_BORDER) is used in this case.
1122   if (resize) {
1123     return AOM_BORDER_IN_PIXELS;
1124   }
1125   if (all_intra) {
1126     return AOM_ENC_ALLINTRA_BORDER;
1127   }
1128   return block_size_wide[sb_size] + 32;
1129 }
1130 
av1_is_resize_needed(const AV1EncoderConfig * oxcf)1131 static AOM_INLINE bool av1_is_resize_needed(const AV1EncoderConfig *oxcf) {
1132   const ResizeCfg *resize_cfg = &oxcf->resize_cfg;
1133   const SuperResCfg *superres_cfg = &oxcf->superres_cfg;
1134   return resize_cfg->resize_mode || superres_cfg->superres_mode;
1135 }
1136 
1137 #ifdef __cplusplus
1138 }  // extern "C"
1139 #endif
1140 
1141 #endif  // AOM_AV1_ENCODER_ENCODER_UTILS_H_
1142