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