• 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   if (cpi->active_map.enabled || cpi->active_map.update)
46     for (i = 0;
47          i < cpi->common.mi_params.mi_rows * cpi->common.mi_params.mi_cols; ++i)
48       if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
49         seg_map[i] = AM_SEGMENT_ID_ACTIVE;
50 }
51 
set_mb_mi(CommonModeInfoParams * mi_params,int width,int height)52 static AOM_INLINE void set_mb_mi(CommonModeInfoParams *mi_params, int width,
53                                  int height) {
54   // Ensure that the decoded width and height are both multiples of
55   // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if
56   // subsampling is used).
57   // This simplifies the implementation of various experiments,
58   // eg. cdef, which operates on units of 8x8 luma pixels.
59   const int aligned_width = ALIGN_POWER_OF_TWO(width, 3);
60   const int aligned_height = ALIGN_POWER_OF_TWO(height, 3);
61 
62   mi_params->mi_cols = aligned_width >> MI_SIZE_LOG2;
63   mi_params->mi_rows = aligned_height >> MI_SIZE_LOG2;
64   mi_params->mi_stride = calc_mi_size(mi_params->mi_cols);
65 
66   mi_params->mb_cols = (mi_params->mi_cols + 2) >> 2;
67   mi_params->mb_rows = (mi_params->mi_rows + 2) >> 2;
68   mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols;
69 
70   const int mi_alloc_size_1d = mi_size_wide[mi_params->mi_alloc_bsize];
71   mi_params->mi_alloc_stride =
72       (mi_params->mi_stride + mi_alloc_size_1d - 1) / mi_alloc_size_1d;
73 
74   assert(mi_size_wide[mi_params->mi_alloc_bsize] ==
75          mi_size_high[mi_params->mi_alloc_bsize]);
76 }
77 
enc_free_mi(CommonModeInfoParams * mi_params)78 static AOM_INLINE void enc_free_mi(CommonModeInfoParams *mi_params) {
79   aom_free(mi_params->mi_alloc);
80   mi_params->mi_alloc = NULL;
81   aom_free(mi_params->mi_grid_base);
82   mi_params->mi_grid_base = NULL;
83   mi_params->mi_alloc_size = 0;
84   aom_free(mi_params->tx_type_map);
85   mi_params->tx_type_map = NULL;
86 }
87 
enc_set_mb_mi(CommonModeInfoParams * mi_params,int width,int height)88 static AOM_INLINE void enc_set_mb_mi(CommonModeInfoParams *mi_params, int width,
89                                      int height) {
90   const int is_4k_or_larger = AOMMIN(width, height) >= 2160;
91   mi_params->mi_alloc_bsize = is_4k_or_larger ? BLOCK_8X8 : BLOCK_4X4;
92 
93   set_mb_mi(mi_params, width, height);
94 }
95 
stat_stage_set_mb_mi(CommonModeInfoParams * mi_params,int width,int height)96 static AOM_INLINE void stat_stage_set_mb_mi(CommonModeInfoParams *mi_params,
97                                             int width, int height) {
98   mi_params->mi_alloc_bsize = BLOCK_16X16;
99 
100   set_mb_mi(mi_params, width, height);
101 }
102 
enc_setup_mi(CommonModeInfoParams * mi_params)103 static AOM_INLINE void enc_setup_mi(CommonModeInfoParams *mi_params) {
104   const int mi_grid_size =
105       mi_params->mi_stride * calc_mi_size(mi_params->mi_rows);
106   memset(mi_params->mi_alloc, 0,
107          mi_params->mi_alloc_size * sizeof(*mi_params->mi_alloc));
108   memset(mi_params->mi_grid_base, 0,
109          mi_grid_size * sizeof(*mi_params->mi_grid_base));
110   memset(mi_params->tx_type_map, 0,
111          mi_grid_size * sizeof(*mi_params->tx_type_map));
112 }
113 
init_buffer_indices(ForceIntegerMVInfo * const force_intpel_info,int * const remapped_ref_idx)114 static AOM_INLINE void init_buffer_indices(
115     ForceIntegerMVInfo *const force_intpel_info, int *const remapped_ref_idx) {
116   int fb_idx;
117   for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx)
118     remapped_ref_idx[fb_idx] = fb_idx;
119   force_intpel_info->rate_index = 0;
120   force_intpel_info->rate_size = 0;
121 }
122 
123 #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, JSDAF, JSVAF) \
124   ppi->fn_ptr[BT].sdf = SDF;                                           \
125   ppi->fn_ptr[BT].sdaf = SDAF;                                         \
126   ppi->fn_ptr[BT].vf = VF;                                             \
127   ppi->fn_ptr[BT].svf = SVF;                                           \
128   ppi->fn_ptr[BT].svaf = SVAF;                                         \
129   ppi->fn_ptr[BT].sdx4df = SDX4DF;                                     \
130   ppi->fn_ptr[BT].jsdaf = JSDAF;                                       \
131   ppi->fn_ptr[BT].jsvaf = JSVAF;
132 
133 #define HIGHBD_BFP_WRAPPER(WIDTH, HEIGHT, BD)                                \
134   HIGHBD_BFP(                                                                \
135       BLOCK_##WIDTH##X##HEIGHT, aom_highbd_sad##WIDTH##x##HEIGHT##_bits##BD, \
136       aom_highbd_sad##WIDTH##x##HEIGHT##_avg_bits##BD,                       \
137       aom_highbd_##BD##_variance##WIDTH##x##HEIGHT,                          \
138       aom_highbd_##BD##_sub_pixel_variance##WIDTH##x##HEIGHT,                \
139       aom_highbd_##BD##_sub_pixel_avg_variance##WIDTH##x##HEIGHT,            \
140       aom_highbd_sad##WIDTH##x##HEIGHT##x4d_bits##BD,                        \
141       aom_highbd_dist_wtd_sad##WIDTH##x##HEIGHT##_avg_bits##BD,              \
142       aom_highbd_##BD##_dist_wtd_sub_pixel_avg_variance##WIDTH##x##HEIGHT)
143 
144 #define MAKE_BFP_SAD_WRAPPER(fnname)                                           \
145   static unsigned int fnname##_bits8(const uint8_t *src_ptr,                   \
146                                      int source_stride,                        \
147                                      const uint8_t *ref_ptr, int ref_stride) { \
148     return fnname(src_ptr, source_stride, ref_ptr, ref_stride);                \
149   }                                                                            \
150   static unsigned int fnname##_bits10(                                         \
151       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
152       int ref_stride) {                                                        \
153     return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2;           \
154   }                                                                            \
155   static unsigned int fnname##_bits12(                                         \
156       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
157       int ref_stride) {                                                        \
158     return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4;           \
159   }
160 
161 #define MAKE_BFP_SADAVG_WRAPPER(fnname)                                        \
162   static unsigned int fnname##_bits8(                                          \
163       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
164       int ref_stride, const uint8_t *second_pred) {                            \
165     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred);   \
166   }                                                                            \
167   static unsigned int fnname##_bits10(                                         \
168       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
169       int ref_stride, const uint8_t *second_pred) {                            \
170     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
171            2;                                                                  \
172   }                                                                            \
173   static unsigned int fnname##_bits12(                                         \
174       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,       \
175       int ref_stride, const uint8_t *second_pred) {                            \
176     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
177            4;                                                                  \
178   }
179 
180 #define MAKE_BFP_SAD4D_WRAPPER(fnname)                                        \
181   static void fnname##_bits8(const uint8_t *src_ptr, int source_stride,       \
182                              const uint8_t *const ref_ptr[], int ref_stride,  \
183                              unsigned int *sad_array) {                       \
184     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
185   }                                                                           \
186   static void fnname##_bits10(const uint8_t *src_ptr, int source_stride,      \
187                               const uint8_t *const ref_ptr[], int ref_stride, \
188                               unsigned int *sad_array) {                      \
189     int i;                                                                    \
190     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
191     for (i = 0; i < 4; i++) sad_array[i] >>= 2;                               \
192   }                                                                           \
193   static void fnname##_bits12(const uint8_t *src_ptr, int source_stride,      \
194                               const uint8_t *const ref_ptr[], int ref_stride, \
195                               unsigned int *sad_array) {                      \
196     int i;                                                                    \
197     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
198     for (i = 0; i < 4; i++) sad_array[i] >>= 4;                               \
199   }
200 
201 #define MAKE_BFP_JSADAVG_WRAPPER(fnname)                                    \
202   static unsigned int fnname##_bits8(                                       \
203       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,    \
204       int ref_stride, const uint8_t *second_pred,                           \
205       const DIST_WTD_COMP_PARAMS *jcp_param) {                              \
206     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
207                   jcp_param);                                               \
208   }                                                                         \
209   static unsigned int fnname##_bits10(                                      \
210       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,    \
211       int ref_stride, const uint8_t *second_pred,                           \
212       const DIST_WTD_COMP_PARAMS *jcp_param) {                              \
213     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
214                   jcp_param) >>                                             \
215            2;                                                               \
216   }                                                                         \
217   static unsigned int fnname##_bits12(                                      \
218       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr,    \
219       int ref_stride, const uint8_t *second_pred,                           \
220       const DIST_WTD_COMP_PARAMS *jcp_param) {                              \
221     return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
222                   jcp_param) >>                                             \
223            4;                                                               \
224   }
225 
226 #if CONFIG_AV1_HIGHBITDEPTH
227 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128)
MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)228 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)
229 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d)
230 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64)
231 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg)
232 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d)
233 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128)
234 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg)
235 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d)
236 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16)
237 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg)
238 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d)
239 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32)
240 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg)
241 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d)
242 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32)
243 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg)
244 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d)
245 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64)
246 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg)
247 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d)
248 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32)
249 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg)
250 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d)
251 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64)
252 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg)
253 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d)
254 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16)
255 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg)
256 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d)
257 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8)
258 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg)
259 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d)
260 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16)
261 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg)
262 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d)
263 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8)
264 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg)
265 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d)
266 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4)
267 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg)
268 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d)
269 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8)
270 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg)
271 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d)
272 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4)
273 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg)
274 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d)
275 
276 #if !CONFIG_REALTIME_ONLY
277 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16)
278 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg)
279 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d)
280 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4)
281 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg)
282 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d)
283 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32)
284 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg)
285 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d)
286 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8)
287 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg)
288 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d)
289 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64)
290 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg)
291 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d)
292 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16)
293 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg)
294 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d)
295 #endif
296 
297 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x128_avg)
298 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x64_avg)
299 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x128_avg)
300 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x16_avg)
301 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x32_avg)
302 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x32_avg)
303 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x64_avg)
304 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x32_avg)
305 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x64_avg)
306 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x16_avg)
307 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x8_avg)
308 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x16_avg)
309 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x8_avg)
310 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x4_avg)
311 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x8_avg)
312 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x4_avg)
313 #if !CONFIG_REALTIME_ONLY
314 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x16_avg)
315 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x4_avg)
316 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x32_avg)
317 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x8_avg)
318 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x64_avg)
319 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x16_avg)
320 #endif
321 #endif  // CONFIG_AV1_HIGHBITDEPTH
322 
323 #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \
324   ppi->fn_ptr[BT].msdf = MCSDF;       \
325   ppi->fn_ptr[BT].msvf = MCSVF;
326 
327 #define HIGHBD_MBFP_WRAPPER(WIDTH, HEIGHT, BD)                    \
328   HIGHBD_MBFP(BLOCK_##WIDTH##X##HEIGHT,                           \
329               aom_highbd_masked_sad##WIDTH##x##HEIGHT##_bits##BD, \
330               aom_highbd_##BD##_masked_sub_pixel_variance##WIDTH##x##HEIGHT)
331 
332 #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname)                           \
333   static unsigned int fnname##_bits8(                                    \
334       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
335       int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m,  \
336       int m_stride, int invert_mask) {                                   \
337     return fnname(src_ptr, source_stride, ref_ptr, ref_stride,           \
338                   second_pred_ptr, m, m_stride, invert_mask);            \
339   }                                                                      \
340   static unsigned int fnname##_bits10(                                   \
341       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
342       int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m,  \
343       int m_stride, int invert_mask) {                                   \
344     return fnname(src_ptr, source_stride, ref_ptr, ref_stride,           \
345                   second_pred_ptr, m, m_stride, invert_mask) >>          \
346            2;                                                            \
347   }                                                                      \
348   static unsigned int fnname##_bits12(                                   \
349       const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
350       int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m,  \
351       int m_stride, int invert_mask) {                                   \
352     return fnname(src_ptr, source_stride, ref_ptr, ref_stride,           \
353                   second_pred_ptr, m, m_stride, invert_mask) >>          \
354            4;                                                            \
355   }
356 
357 #if CONFIG_AV1_HIGHBITDEPTH
358 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128)
359 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64)
360 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128)
361 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64)
362 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32)
363 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64)
364 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32)
365 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16)
366 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32)
367 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16)
368 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8)
369 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16)
370 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8)
371 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4)
372 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8)
373 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4)
374 #if !CONFIG_REALTIME_ONLY
375 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16)
376 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4)
377 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32)
378 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8)
379 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64)
380 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16)
381 #endif
382 #endif
383 
384 #define HIGHBD_SDSFP(BT, SDSF, SDSX4DF) \
385   ppi->fn_ptr[BT].sdsf = SDSF;          \
386   ppi->fn_ptr[BT].sdsx4df = SDSX4DF;
387 
388 #define HIGHBD_SDSFP_WRAPPER(WIDTH, HEIGHT, BD)                   \
389   HIGHBD_SDSFP(BLOCK_##WIDTH##X##HEIGHT,                          \
390                aom_highbd_sad_skip_##WIDTH##x##HEIGHT##_bits##BD, \
391                aom_highbd_sad_skip_##WIDTH##x##HEIGHT##x4d##_bits##BD)
392 
393 #define MAKE_SDSF_SKIP_SAD_WRAPPER(fnname)                                  \
394   static unsigned int fnname##_bits8(const uint8_t *src, int src_stride,    \
395                                      const uint8_t *ref, int ref_stride) {  \
396     return fnname(src, src_stride, ref, ref_stride);                        \
397   }                                                                         \
398   static unsigned int fnname##_bits10(const uint8_t *src, int src_stride,   \
399                                       const uint8_t *ref, int ref_stride) { \
400     return fnname(src, src_stride, ref, ref_stride) >> 2;                   \
401   }                                                                         \
402   static unsigned int fnname##_bits12(const uint8_t *src, int src_stride,   \
403                                       const uint8_t *ref, int ref_stride) { \
404     return fnname(src, src_stride, ref, ref_stride) >> 4;                   \
405   }
406 
407 #define MAKE_SDSF_SKIP_SAD_4D_WRAPPER(fnname)                                 \
408   static void fnname##_bits8(const uint8_t *src_ptr, int source_stride,       \
409                              const uint8_t *const ref_ptr[], int ref_stride,  \
410                              unsigned int *sad_array) {                       \
411     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
412   }                                                                           \
413   static void fnname##_bits10(const uint8_t *src_ptr, int source_stride,      \
414                               const uint8_t *const ref_ptr[], int ref_stride, \
415                               unsigned int *sad_array) {                      \
416     int i;                                                                    \
417     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
418     for (i = 0; i < 4; i++) sad_array[i] >>= 2;                               \
419   }                                                                           \
420   static void fnname##_bits12(const uint8_t *src_ptr, int source_stride,      \
421                               const uint8_t *const ref_ptr[], int ref_stride, \
422                               unsigned int *sad_array) {                      \
423     int i;                                                                    \
424     fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array);           \
425     for (i = 0; i < 4; i++) sad_array[i] >>= 4;                               \
426   }
427 
428 #if CONFIG_AV1_HIGHBITDEPTH
429 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_128x128)
430 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_128x64)
431 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x128)
432 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x64)
433 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x32)
434 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x64)
435 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x32)
436 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x16)
437 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x32)
438 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x16)
439 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x8)
440 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x16)
441 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x8)
442 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_4x8)
443 
444 #if !CONFIG_REALTIME_ONLY
445 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x16)
446 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x8)
447 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x64)
448 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_4x16)
449 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x32)
450 #endif
451 
452 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_128x128x4d)
453 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_128x64x4d)
454 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x128x4d)
455 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x64x4d)
456 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x32x4d)
457 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x64x4d)
458 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x32x4d)
459 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x16x4d)
460 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x32x4d)
461 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x16x4d)
462 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x8x4d)
463 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x16x4d)
464 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x8x4d)
465 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_4x8x4d)
466 
467 #if !CONFIG_REALTIME_ONLY
468 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x16x4d)
469 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x8x4d)
470 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x64x4d)
471 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_4x16x4d)
472 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x32x4d)
473 #endif
474 #endif
475 
476 #if !CONFIG_REALTIME_ONLY
477 
478 #if CONFIG_AV1_HIGHBITDEPTH
479 #define HIGHBD_OBFP_WRAPPER_8(WIDTH, HEIGHT)                 \
480   HIGHBD_OBFP(BLOCK_##WIDTH##X##HEIGHT,                      \
481               aom_highbd_obmc_sad##WIDTH##x##HEIGHT##_bits8, \
482               aom_highbd_obmc_variance##WIDTH##x##HEIGHT,    \
483               aom_highbd_obmc_sub_pixel_variance##WIDTH##x##HEIGHT)
484 
485 #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \
486   ppi->fn_ptr[BT].osdf = OSDF;           \
487   ppi->fn_ptr[BT].ovf = OVF;             \
488   ppi->fn_ptr[BT].osvf = OSVF;
489 
490 #define HIGHBD_OBFP_WRAPPER(WIDTH, HEIGHT, BD)                   \
491   HIGHBD_OBFP(BLOCK_##WIDTH##X##HEIGHT,                          \
492               aom_highbd_obmc_sad##WIDTH##x##HEIGHT##_bits##BD,  \
493               aom_highbd_##BD##_obmc_variance##WIDTH##x##HEIGHT, \
494               aom_highbd_##BD##_obmc_sub_pixel_variance##WIDTH##x##HEIGHT)
495 
496 #define MAKE_OBFP_SAD_WRAPPER(fnname)                                     \
497   static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride,  \
498                                      const int32_t *wsrc,                 \
499                                      const int32_t *msk) {                \
500     return fnname(ref, ref_stride, wsrc, msk);                            \
501   }                                                                       \
502   static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \
503                                       const int32_t *wsrc,                \
504                                       const int32_t *msk) {               \
505     return fnname(ref, ref_stride, wsrc, msk) >> 2;                       \
506   }                                                                       \
507   static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \
508                                       const int32_t *wsrc,                \
509                                       const int32_t *msk) {               \
510     return fnname(ref, ref_stride, wsrc, msk) >> 4;                       \
511   }
512 #endif  // CONFIG_AV1_HIGHBITDEPTH
513 #endif  // !CONFIG_REALTIME_ONLY
514 
515 #if CONFIG_AV1_HIGHBITDEPTH
516 #if !CONFIG_REALTIME_ONLY
517 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128)
518 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64)
519 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128)
520 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64)
521 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32)
522 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64)
523 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32)
524 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16)
525 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32)
526 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16)
527 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8)
528 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16)
529 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8)
530 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4)
531 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8)
532 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4)
533 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16)
534 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4)
535 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32)
536 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8)
537 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64)
538 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16)
539 #endif
540 
541 static AOM_INLINE void highbd_set_var_fns(AV1_PRIMARY *const ppi) {
542   SequenceHeader *const seq_params = &ppi->seq_params;
543   if (seq_params->use_highbitdepth) {
544     switch (seq_params->bit_depth) {
545       case AOM_BITS_8:
546 #if !CONFIG_REALTIME_ONLY
547         HIGHBD_BFP_WRAPPER(64, 16, 8)
548         HIGHBD_BFP_WRAPPER(16, 64, 8)
549         HIGHBD_BFP_WRAPPER(32, 8, 8)
550         HIGHBD_BFP_WRAPPER(8, 32, 8)
551         HIGHBD_BFP_WRAPPER(16, 4, 8)
552         HIGHBD_BFP_WRAPPER(4, 16, 8)
553 #endif
554         HIGHBD_BFP_WRAPPER(32, 16, 8)
555         HIGHBD_BFP_WRAPPER(16, 32, 8)
556         HIGHBD_BFP_WRAPPER(64, 32, 8)
557         HIGHBD_BFP_WRAPPER(32, 64, 8)
558         HIGHBD_BFP_WRAPPER(32, 32, 8)
559         HIGHBD_BFP_WRAPPER(64, 64, 8)
560         HIGHBD_BFP_WRAPPER(16, 16, 8)
561         HIGHBD_BFP_WRAPPER(16, 8, 8)
562         HIGHBD_BFP_WRAPPER(8, 16, 8)
563         HIGHBD_BFP_WRAPPER(8, 8, 8)
564         HIGHBD_BFP_WRAPPER(8, 4, 8)
565         HIGHBD_BFP_WRAPPER(4, 8, 8)
566         HIGHBD_BFP_WRAPPER(4, 4, 8)
567         HIGHBD_BFP_WRAPPER(128, 128, 8)
568         HIGHBD_BFP_WRAPPER(128, 64, 8)
569         HIGHBD_BFP_WRAPPER(64, 128, 8)
570 
571         HIGHBD_MBFP_WRAPPER(128, 128, 8)
572         HIGHBD_MBFP_WRAPPER(128, 64, 8)
573         HIGHBD_MBFP_WRAPPER(64, 128, 8)
574         HIGHBD_MBFP_WRAPPER(64, 64, 8)
575         HIGHBD_MBFP_WRAPPER(64, 32, 8)
576         HIGHBD_MBFP_WRAPPER(32, 64, 8)
577         HIGHBD_MBFP_WRAPPER(32, 32, 8)
578         HIGHBD_MBFP_WRAPPER(32, 16, 8)
579         HIGHBD_MBFP_WRAPPER(16, 32, 8)
580         HIGHBD_MBFP_WRAPPER(16, 16, 8)
581         HIGHBD_MBFP_WRAPPER(8, 16, 8)
582         HIGHBD_MBFP_WRAPPER(16, 8, 8)
583         HIGHBD_MBFP_WRAPPER(8, 8, 8)
584         HIGHBD_MBFP_WRAPPER(4, 8, 8)
585         HIGHBD_MBFP_WRAPPER(8, 4, 8)
586         HIGHBD_MBFP_WRAPPER(4, 4, 8)
587 #if !CONFIG_REALTIME_ONLY
588         HIGHBD_MBFP_WRAPPER(64, 16, 8)
589         HIGHBD_MBFP_WRAPPER(16, 64, 8)
590         HIGHBD_MBFP_WRAPPER(32, 8, 8)
591         HIGHBD_MBFP_WRAPPER(8, 32, 8)
592         HIGHBD_MBFP_WRAPPER(16, 4, 8)
593         HIGHBD_MBFP_WRAPPER(4, 16, 8)
594 #endif
595 
596 // OBMC excluded from realtime only build.
597 #if !CONFIG_REALTIME_ONLY
598         HIGHBD_OBFP_WRAPPER_8(128, 128)
599         HIGHBD_OBFP_WRAPPER_8(128, 64)
600         HIGHBD_OBFP_WRAPPER_8(64, 128)
601         HIGHBD_OBFP_WRAPPER_8(64, 64)
602         HIGHBD_OBFP_WRAPPER_8(64, 32)
603         HIGHBD_OBFP_WRAPPER_8(32, 64)
604         HIGHBD_OBFP_WRAPPER_8(32, 32)
605         HIGHBD_OBFP_WRAPPER_8(32, 16)
606         HIGHBD_OBFP_WRAPPER_8(16, 32)
607         HIGHBD_OBFP_WRAPPER_8(16, 16)
608         HIGHBD_OBFP_WRAPPER_8(8, 16)
609         HIGHBD_OBFP_WRAPPER_8(16, 8)
610         HIGHBD_OBFP_WRAPPER_8(8, 8)
611         HIGHBD_OBFP_WRAPPER_8(4, 8)
612         HIGHBD_OBFP_WRAPPER_8(8, 4)
613         HIGHBD_OBFP_WRAPPER_8(4, 4)
614         HIGHBD_OBFP_WRAPPER_8(64, 16)
615         HIGHBD_OBFP_WRAPPER_8(16, 64)
616         HIGHBD_OBFP_WRAPPER_8(32, 8)
617         HIGHBD_OBFP_WRAPPER_8(8, 32)
618         HIGHBD_OBFP_WRAPPER_8(16, 4)
619         HIGHBD_OBFP_WRAPPER_8(4, 16)
620 #endif
621 
622         HIGHBD_SDSFP_WRAPPER(128, 128, 8);
623         HIGHBD_SDSFP_WRAPPER(128, 64, 8);
624         HIGHBD_SDSFP_WRAPPER(64, 128, 8);
625         HIGHBD_SDSFP_WRAPPER(64, 64, 8);
626         HIGHBD_SDSFP_WRAPPER(64, 32, 8);
627         HIGHBD_SDSFP_WRAPPER(32, 64, 8);
628         HIGHBD_SDSFP_WRAPPER(32, 32, 8);
629         HIGHBD_SDSFP_WRAPPER(32, 16, 8);
630         HIGHBD_SDSFP_WRAPPER(16, 32, 8);
631         HIGHBD_SDSFP_WRAPPER(16, 16, 8);
632         HIGHBD_SDSFP_WRAPPER(16, 8, 8);
633         HIGHBD_SDSFP_WRAPPER(8, 16, 8);
634         HIGHBD_SDSFP_WRAPPER(8, 8, 8);
635         HIGHBD_SDSFP_WRAPPER(4, 8, 8);
636 #if !CONFIG_REALTIME_ONLY
637         HIGHBD_SDSFP_WRAPPER(64, 16, 8);
638         HIGHBD_SDSFP_WRAPPER(32, 8, 8);
639         HIGHBD_SDSFP_WRAPPER(16, 64, 8);
640         HIGHBD_SDSFP_WRAPPER(8, 32, 8);
641         HIGHBD_SDSFP_WRAPPER(4, 16, 8);
642 #endif
643         break;
644 
645       case AOM_BITS_10:
646 #if !CONFIG_REALTIME_ONLY
647         HIGHBD_BFP_WRAPPER(64, 16, 10)
648         HIGHBD_BFP_WRAPPER(16, 64, 10)
649         HIGHBD_BFP_WRAPPER(32, 8, 10)
650         HIGHBD_BFP_WRAPPER(8, 32, 10)
651         HIGHBD_BFP_WRAPPER(16, 4, 10)
652         HIGHBD_BFP_WRAPPER(4, 16, 10)
653 #endif
654         HIGHBD_BFP_WRAPPER(32, 16, 10)
655         HIGHBD_BFP_WRAPPER(16, 32, 10)
656         HIGHBD_BFP_WRAPPER(64, 32, 10)
657         HIGHBD_BFP_WRAPPER(32, 64, 10)
658         HIGHBD_BFP_WRAPPER(32, 32, 10)
659         HIGHBD_BFP_WRAPPER(64, 64, 10)
660         HIGHBD_BFP_WRAPPER(16, 16, 10)
661         HIGHBD_BFP_WRAPPER(16, 8, 10)
662         HIGHBD_BFP_WRAPPER(8, 16, 10)
663         HIGHBD_BFP_WRAPPER(8, 8, 10)
664         HIGHBD_BFP_WRAPPER(8, 4, 10)
665         HIGHBD_BFP_WRAPPER(4, 8, 10)
666         HIGHBD_BFP_WRAPPER(4, 4, 10)
667         HIGHBD_BFP_WRAPPER(128, 128, 10)
668         HIGHBD_BFP_WRAPPER(128, 64, 10)
669         HIGHBD_BFP_WRAPPER(64, 128, 10)
670 
671         HIGHBD_MBFP_WRAPPER(128, 128, 10)
672         HIGHBD_MBFP_WRAPPER(128, 64, 10)
673         HIGHBD_MBFP_WRAPPER(64, 128, 10)
674         HIGHBD_MBFP_WRAPPER(64, 64, 10)
675         HIGHBD_MBFP_WRAPPER(64, 32, 10)
676         HIGHBD_MBFP_WRAPPER(32, 64, 10)
677         HIGHBD_MBFP_WRAPPER(32, 32, 10)
678         HIGHBD_MBFP_WRAPPER(32, 16, 10)
679         HIGHBD_MBFP_WRAPPER(16, 32, 10)
680         HIGHBD_MBFP_WRAPPER(16, 16, 10)
681         HIGHBD_MBFP_WRAPPER(8, 16, 10)
682         HIGHBD_MBFP_WRAPPER(16, 8, 10)
683         HIGHBD_MBFP_WRAPPER(8, 8, 10)
684         HIGHBD_MBFP_WRAPPER(4, 8, 10)
685         HIGHBD_MBFP_WRAPPER(8, 4, 10)
686         HIGHBD_MBFP_WRAPPER(4, 4, 10)
687 #if !CONFIG_REALTIME_ONLY
688         HIGHBD_MBFP_WRAPPER(64, 16, 10)
689         HIGHBD_MBFP_WRAPPER(16, 64, 10)
690         HIGHBD_MBFP_WRAPPER(32, 8, 10)
691         HIGHBD_MBFP_WRAPPER(8, 32, 10)
692         HIGHBD_MBFP_WRAPPER(16, 4, 10)
693         HIGHBD_MBFP_WRAPPER(4, 16, 10)
694 #endif
695 
696 // OBMC excluded from realtime only build.
697 #if !CONFIG_REALTIME_ONLY
698         HIGHBD_OBFP_WRAPPER(128, 128, 10)
699         HIGHBD_OBFP_WRAPPER(128, 64, 10)
700         HIGHBD_OBFP_WRAPPER(64, 128, 10)
701         HIGHBD_OBFP_WRAPPER(64, 64, 10)
702         HIGHBD_OBFP_WRAPPER(64, 32, 10)
703         HIGHBD_OBFP_WRAPPER(32, 64, 10)
704         HIGHBD_OBFP_WRAPPER(32, 32, 10)
705         HIGHBD_OBFP_WRAPPER(32, 16, 10)
706         HIGHBD_OBFP_WRAPPER(16, 32, 10)
707         HIGHBD_OBFP_WRAPPER(16, 16, 10)
708         HIGHBD_OBFP_WRAPPER(8, 16, 10)
709         HIGHBD_OBFP_WRAPPER(16, 8, 10)
710         HIGHBD_OBFP_WRAPPER(8, 8, 10)
711         HIGHBD_OBFP_WRAPPER(4, 8, 10)
712         HIGHBD_OBFP_WRAPPER(8, 4, 10)
713         HIGHBD_OBFP_WRAPPER(4, 4, 10)
714         HIGHBD_OBFP_WRAPPER(64, 16, 10)
715         HIGHBD_OBFP_WRAPPER(16, 64, 10)
716         HIGHBD_OBFP_WRAPPER(32, 8, 10)
717         HIGHBD_OBFP_WRAPPER(8, 32, 10)
718         HIGHBD_OBFP_WRAPPER(16, 4, 10)
719         HIGHBD_OBFP_WRAPPER(4, 16, 10)
720 #endif
721 
722         HIGHBD_SDSFP_WRAPPER(128, 128, 10);
723         HIGHBD_SDSFP_WRAPPER(128, 64, 10);
724         HIGHBD_SDSFP_WRAPPER(64, 128, 10);
725         HIGHBD_SDSFP_WRAPPER(64, 64, 10);
726         HIGHBD_SDSFP_WRAPPER(64, 32, 10);
727         HIGHBD_SDSFP_WRAPPER(32, 64, 10);
728         HIGHBD_SDSFP_WRAPPER(32, 32, 10);
729         HIGHBD_SDSFP_WRAPPER(32, 16, 10);
730         HIGHBD_SDSFP_WRAPPER(16, 32, 10);
731         HIGHBD_SDSFP_WRAPPER(16, 16, 10);
732         HIGHBD_SDSFP_WRAPPER(16, 8, 10);
733         HIGHBD_SDSFP_WRAPPER(8, 16, 10);
734         HIGHBD_SDSFP_WRAPPER(8, 8, 10);
735         HIGHBD_SDSFP_WRAPPER(4, 8, 10);
736 
737 #if !CONFIG_REALTIME_ONLY
738         HIGHBD_SDSFP_WRAPPER(64, 16, 10);
739         HIGHBD_SDSFP_WRAPPER(32, 8, 10);
740         HIGHBD_SDSFP_WRAPPER(16, 64, 10);
741         HIGHBD_SDSFP_WRAPPER(8, 32, 10);
742         HIGHBD_SDSFP_WRAPPER(4, 16, 10);
743 #endif
744         break;
745 
746       case AOM_BITS_12:
747 #if !CONFIG_REALTIME_ONLY
748         HIGHBD_BFP_WRAPPER(64, 16, 12)
749         HIGHBD_BFP_WRAPPER(16, 64, 12)
750         HIGHBD_BFP_WRAPPER(32, 8, 12)
751         HIGHBD_BFP_WRAPPER(8, 32, 12)
752         HIGHBD_BFP_WRAPPER(16, 4, 12)
753         HIGHBD_BFP_WRAPPER(4, 16, 12)
754 #endif
755         HIGHBD_BFP_WRAPPER(32, 16, 12)
756         HIGHBD_BFP_WRAPPER(16, 32, 12)
757         HIGHBD_BFP_WRAPPER(64, 32, 12)
758         HIGHBD_BFP_WRAPPER(32, 64, 12)
759         HIGHBD_BFP_WRAPPER(32, 32, 12)
760         HIGHBD_BFP_WRAPPER(64, 64, 12)
761         HIGHBD_BFP_WRAPPER(16, 16, 12)
762         HIGHBD_BFP_WRAPPER(16, 8, 12)
763         HIGHBD_BFP_WRAPPER(8, 16, 12)
764         HIGHBD_BFP_WRAPPER(8, 8, 12)
765         HIGHBD_BFP_WRAPPER(8, 4, 12)
766         HIGHBD_BFP_WRAPPER(4, 8, 12)
767         HIGHBD_BFP_WRAPPER(4, 4, 12)
768         HIGHBD_BFP_WRAPPER(128, 128, 12)
769         HIGHBD_BFP_WRAPPER(128, 64, 12)
770         HIGHBD_BFP_WRAPPER(64, 128, 12)
771 
772         HIGHBD_MBFP_WRAPPER(128, 128, 12)
773         HIGHBD_MBFP_WRAPPER(128, 64, 12)
774         HIGHBD_MBFP_WRAPPER(64, 128, 12)
775         HIGHBD_MBFP_WRAPPER(64, 64, 12)
776         HIGHBD_MBFP_WRAPPER(64, 32, 12)
777         HIGHBD_MBFP_WRAPPER(32, 64, 12)
778         HIGHBD_MBFP_WRAPPER(32, 32, 12)
779         HIGHBD_MBFP_WRAPPER(32, 16, 12)
780         HIGHBD_MBFP_WRAPPER(16, 32, 12)
781         HIGHBD_MBFP_WRAPPER(16, 16, 12)
782         HIGHBD_MBFP_WRAPPER(8, 16, 12)
783         HIGHBD_MBFP_WRAPPER(16, 8, 12)
784         HIGHBD_MBFP_WRAPPER(8, 8, 12)
785         HIGHBD_MBFP_WRAPPER(4, 8, 12)
786         HIGHBD_MBFP_WRAPPER(8, 4, 12)
787         HIGHBD_MBFP_WRAPPER(4, 4, 12)
788 #if !CONFIG_REALTIME_ONLY
789         HIGHBD_MBFP_WRAPPER(64, 16, 12)
790         HIGHBD_MBFP_WRAPPER(16, 64, 12)
791         HIGHBD_MBFP_WRAPPER(32, 8, 12)
792         HIGHBD_MBFP_WRAPPER(8, 32, 12)
793         HIGHBD_MBFP_WRAPPER(16, 4, 12)
794         HIGHBD_MBFP_WRAPPER(4, 16, 12)
795 #endif
796 
797 // OBMC excluded from realtime only build.
798 #if !CONFIG_REALTIME_ONLY
799         HIGHBD_OBFP_WRAPPER(128, 128, 12)
800         HIGHBD_OBFP_WRAPPER(128, 64, 12)
801         HIGHBD_OBFP_WRAPPER(64, 128, 12)
802         HIGHBD_OBFP_WRAPPER(64, 64, 12)
803         HIGHBD_OBFP_WRAPPER(64, 32, 12)
804         HIGHBD_OBFP_WRAPPER(32, 64, 12)
805         HIGHBD_OBFP_WRAPPER(32, 32, 12)
806         HIGHBD_OBFP_WRAPPER(32, 16, 12)
807         HIGHBD_OBFP_WRAPPER(16, 32, 12)
808         HIGHBD_OBFP_WRAPPER(16, 16, 12)
809         HIGHBD_OBFP_WRAPPER(8, 16, 12)
810         HIGHBD_OBFP_WRAPPER(16, 8, 12)
811         HIGHBD_OBFP_WRAPPER(8, 8, 12)
812         HIGHBD_OBFP_WRAPPER(4, 8, 12)
813         HIGHBD_OBFP_WRAPPER(8, 4, 12)
814         HIGHBD_OBFP_WRAPPER(4, 4, 12)
815         HIGHBD_OBFP_WRAPPER(64, 16, 12)
816         HIGHBD_OBFP_WRAPPER(16, 64, 12)
817         HIGHBD_OBFP_WRAPPER(32, 8, 12)
818         HIGHBD_OBFP_WRAPPER(8, 32, 12)
819         HIGHBD_OBFP_WRAPPER(16, 4, 12)
820         HIGHBD_OBFP_WRAPPER(4, 16, 12)
821 #endif
822 
823         HIGHBD_SDSFP_WRAPPER(128, 128, 12);
824         HIGHBD_SDSFP_WRAPPER(128, 64, 12);
825         HIGHBD_SDSFP_WRAPPER(64, 128, 12);
826         HIGHBD_SDSFP_WRAPPER(64, 64, 12);
827         HIGHBD_SDSFP_WRAPPER(64, 32, 12);
828         HIGHBD_SDSFP_WRAPPER(32, 64, 12);
829         HIGHBD_SDSFP_WRAPPER(32, 32, 12);
830         HIGHBD_SDSFP_WRAPPER(32, 16, 12);
831         HIGHBD_SDSFP_WRAPPER(16, 32, 12);
832         HIGHBD_SDSFP_WRAPPER(16, 16, 12);
833         HIGHBD_SDSFP_WRAPPER(16, 8, 12);
834         HIGHBD_SDSFP_WRAPPER(8, 16, 12);
835         HIGHBD_SDSFP_WRAPPER(8, 8, 12);
836         HIGHBD_SDSFP_WRAPPER(4, 8, 12);
837 
838 #if !CONFIG_REALTIME_ONLY
839         HIGHBD_SDSFP_WRAPPER(64, 16, 12);
840         HIGHBD_SDSFP_WRAPPER(32, 8, 12);
841         HIGHBD_SDSFP_WRAPPER(16, 64, 12);
842         HIGHBD_SDSFP_WRAPPER(8, 32, 12);
843         HIGHBD_SDSFP_WRAPPER(4, 16, 12);
844 #endif
845         break;
846 
847       default:
848         assert(0 &&
849                "cm->seq_params->bit_depth should be AOM_BITS_8, "
850                "AOM_BITS_10 or AOM_BITS_12");
851     }
852   }
853 }
854 #endif  // CONFIG_AV1_HIGHBITDEPTH
855 
copy_frame_prob_info(AV1_COMP * cpi)856 static AOM_INLINE void copy_frame_prob_info(AV1_COMP *cpi) {
857   FrameProbInfo *const frame_probs = &cpi->ppi->frame_probs;
858   if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats) {
859     av1_copy(frame_probs->tx_type_probs, default_tx_type_probs);
860   }
861   if (cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 &&
862       cpi->sf.inter_sf.prune_obmc_prob_thresh < INT_MAX) {
863     av1_copy(frame_probs->obmc_probs, default_obmc_probs);
864   }
865   if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0) {
866     av1_copy(frame_probs->warped_probs, default_warped_probs);
867   }
868   if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) {
869     av1_copy(frame_probs->switchable_interp_probs,
870              default_switchable_interp_probs);
871   }
872 }
873 
restore_cdef_coding_context(CdefInfo * const dst,const CdefInfo * const src)874 static AOM_INLINE void restore_cdef_coding_context(CdefInfo *const dst,
875                                                    const CdefInfo *const src) {
876   dst->cdef_bits = src->cdef_bits;
877   dst->cdef_damping = src->cdef_damping;
878   av1_copy(dst->cdef_strengths, src->cdef_strengths);
879   av1_copy(dst->cdef_uv_strengths, src->cdef_uv_strengths);
880   dst->nb_cdef_strengths = src->nb_cdef_strengths;
881 }
882 
883 // Coding context that only needs to be restored when recode loop includes
884 // filtering (deblocking, CDEF, superres post-encode upscale and/or loop
885 // restoraton).
restore_extra_coding_context(AV1_COMP * cpi)886 static AOM_INLINE void restore_extra_coding_context(AV1_COMP *cpi) {
887   CODING_CONTEXT *const cc = &cpi->coding_context;
888   AV1_COMMON *cm = &cpi->common;
889   cm->lf = cc->lf;
890   restore_cdef_coding_context(&cm->cdef_info, &cc->cdef_info);
891   cpi->rc = cc->rc;
892   cpi->ppi->mv_stats = cc->mv_stats;
893 }
894 
equal_dimensions_and_border(const YV12_BUFFER_CONFIG * a,const YV12_BUFFER_CONFIG * b)895 static AOM_INLINE int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a,
896                                                   const YV12_BUFFER_CONFIG *b) {
897   return a->y_height == b->y_height && a->y_width == b->y_width &&
898          a->uv_height == b->uv_height && a->uv_width == b->uv_width &&
899          a->y_stride == b->y_stride && a->uv_stride == b->uv_stride &&
900          a->border == b->border &&
901          (a->flags & YV12_FLAG_HIGHBITDEPTH) ==
902              (b->flags & YV12_FLAG_HIGHBITDEPTH);
903 }
904 
update_entropy(bool * ext_refresh_frame_context,bool * ext_refresh_frame_context_pending,bool update)905 static AOM_INLINE int update_entropy(bool *ext_refresh_frame_context,
906                                      bool *ext_refresh_frame_context_pending,
907                                      bool update) {
908   *ext_refresh_frame_context = update;
909   *ext_refresh_frame_context_pending = 1;
910   return 0;
911 }
912 
913 #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)914 static AOM_INLINE int combine_prior_with_tpl_boost(double min_factor,
915                                                    double max_factor,
916                                                    int prior_boost,
917                                                    int tpl_boost,
918                                                    int frames_to_key) {
919   double factor = sqrt((double)frames_to_key);
920   double range = max_factor - min_factor;
921   factor = AOMMIN(factor, max_factor);
922   factor = AOMMAX(factor, min_factor);
923   factor -= min_factor;
924   int boost =
925       (int)((factor * prior_boost + (range - factor) * tpl_boost) / range);
926   return boost;
927 }
928 #endif
929 
set_size_independent_vars(AV1_COMP * cpi)930 static AOM_INLINE void set_size_independent_vars(AV1_COMP *cpi) {
931   int i;
932   AV1_COMMON *const cm = &cpi->common;
933   for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
934     cm->global_motion[i] = default_warp_params;
935   }
936   cpi->gm_info.search_done = 0;
937 
938   av1_set_speed_features_framesize_independent(cpi, cpi->speed);
939   av1_set_rd_speed_thresholds(cpi);
940   cm->features.interp_filter = SWITCHABLE;
941   cm->features.switchable_motion_mode = 1;
942 }
943 
release_scaled_references(AV1_COMP * cpi)944 static AOM_INLINE void release_scaled_references(AV1_COMP *cpi) {
945   // TODO(isbs): only refresh the necessary frames, rather than all of them
946   for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
947     RefCntBuffer *const buf = cpi->scaled_ref_buf[i];
948     if (buf != NULL) {
949       --buf->ref_count;
950       cpi->scaled_ref_buf[i] = NULL;
951     }
952   }
953 }
954 
restore_all_coding_context(AV1_COMP * cpi)955 static AOM_INLINE void restore_all_coding_context(AV1_COMP *cpi) {
956   restore_extra_coding_context(cpi);
957   if (!frame_is_intra_only(&cpi->common)) release_scaled_references(cpi);
958 }
959 
960 // Refresh reference frame buffers according to refresh_frame_flags.
refresh_reference_frames(AV1_COMP * cpi)961 static AOM_INLINE void refresh_reference_frames(AV1_COMP *cpi) {
962   AV1_COMMON *const cm = &cpi->common;
963   // All buffers are refreshed for shown keyframes and S-frames.
964 
965   for (int ref_frame = 0; ref_frame < REF_FRAMES; ref_frame++) {
966     if (((cm->current_frame.refresh_frame_flags >> ref_frame) & 1) == 1) {
967       assign_frame_buffer_p(&cm->ref_frame_map[ref_frame], cm->cur_frame);
968     }
969   }
970 }
971 
972 void av1_update_film_grain_parameters_seq(struct AV1_PRIMARY *ppi,
973                                           const AV1EncoderConfig *oxcf);
974 void av1_update_film_grain_parameters(struct AV1_COMP *cpi,
975                                       const AV1EncoderConfig *oxcf);
976 
977 void av1_scale_references(AV1_COMP *cpi, const InterpFilter filter,
978                           const int phase, const int use_optimized_scaler);
979 
980 void av1_setup_frame(AV1_COMP *cpi);
981 
982 BLOCK_SIZE av1_select_sb_size(const AV1EncoderConfig *const oxcf, int width,
983                               int height, int number_spatial_layers);
984 
985 void av1_apply_active_map(AV1_COMP *cpi);
986 
987 #if !CONFIG_REALTIME_ONLY
988 uint16_t av1_setup_interp_filter_search_mask(AV1_COMP *cpi);
989 
990 void av1_determine_sc_tools_with_encoding(AV1_COMP *cpi, const int q_orig);
991 #endif
992 
993 void av1_set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index,
994                                  int *top_index);
995 
996 void av1_finalize_encoded_frame(AV1_COMP *const cpi);
997 
998 int av1_is_integer_mv(const YV12_BUFFER_CONFIG *cur_picture,
999                       const YV12_BUFFER_CONFIG *last_picture,
1000                       ForceIntegerMVInfo *const force_intpel_info);
1001 
1002 void av1_set_mb_ssim_rdmult_scaling(AV1_COMP *cpi);
1003 
1004 void av1_save_all_coding_context(AV1_COMP *cpi);
1005 
1006 #if DUMP_RECON_FRAMES == 1
1007 void av1_dump_filtered_recon_frames(AV1_COMP *cpi);
1008 #endif
1009 
1010 #ifdef __cplusplus
1011 }  // extern "C"
1012 #endif
1013 
1014 #endif  // AOM_AV1_ENCODER_ENCODER_UTILS_H_
1015