tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

encoder_utils.h (46906B)


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