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 | |
| 15 | #include "av1/encoder/block.h" |
| 16 | #include "aom_dsp/variance.h" |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | // The maximum number of steps in a step search given the largest |
| 23 | // allowed initial step |
Yunqing Wang | e25fdbb | 2018-03-16 16:36:32 -0700 | [diff] [blame] | 24 | #define MAX_MVSEARCH_STEPS 11 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | // Max full pel mv specified in the unit of full pixel |
Yunqing Wang | e25fdbb | 2018-03-16 16:36:32 -0700 | [diff] [blame] | 26 | // Enable the use of motion vector in range [-1023, 1023]. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | #define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS - 1)) - 1) |
| 28 | // Maximum size of the first step in full pel units |
| 29 | #define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS - 1)) |
| 30 | // Allowed motion vector pixel distance outside image border |
| 31 | // for Block_16x16 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 32 | #define BORDER_MV_PIXELS_B16 (16 + AOM_INTERP_EXTEND) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | |
Deepa K G | d4febfb | 2018-08-14 11:33:51 +0530 | [diff] [blame] | 34 | #define SEARCH_RANGE_8P 3 |
| 35 | #define SEARCH_GRID_STRIDE_8P (2 * SEARCH_RANGE_8P + 1) |
| 36 | #define SEARCH_GRID_CENTER_8P \ |
| 37 | (SEARCH_RANGE_8P * SEARCH_GRID_STRIDE_8P + SEARCH_RANGE_8P) |
| 38 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | // motion search site |
| 40 | typedef struct search_site { |
| 41 | MV mv; |
| 42 | int offset; |
| 43 | } search_site; |
| 44 | |
| 45 | typedef struct search_site_config { |
| 46 | search_site ss[8 * MAX_MVSEARCH_STEPS + 1]; |
| 47 | int ss_count; |
| 48 | int searches_per_step; |
| 49 | } search_site_config; |
| 50 | |
Deepa K G | d4febfb | 2018-08-14 11:33:51 +0530 | [diff] [blame] | 51 | typedef struct { |
| 52 | MV coord; |
| 53 | int coord_offset; |
| 54 | } search_neighbors; |
| 55 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 56 | void av1_init_dsmotion_compensation(search_site_config *cfg, int stride); |
| 57 | void av1_init3smotion_compensation(search_site_config *cfg, int stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | |
Alex Converse | 0fa0f42 | 2017-04-24 12:51:14 -0700 | [diff] [blame] | 59 | void av1_set_mv_search_range(MvLimits *mv_limits, const MV *mv); |
Yunqing Wang | 8e17342 | 2017-04-21 09:27:55 -0700 | [diff] [blame] | 60 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 61 | int av1_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost, |
| 62 | int *mvcost[2], int weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | |
| 64 | // Utility to compute variance + MV rate cost for a given MV |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 65 | int av1_get_mvpred_var(const MACROBLOCK *x, const MV *best_mv, |
| 66 | const MV *center_mv, const aom_variance_fn_ptr_t *vfp, |
| 67 | int use_mvcost); |
| 68 | int av1_get_mvpred_av_var(const MACROBLOCK *x, const MV *best_mv, |
| 69 | const MV *center_mv, const uint8_t *second_pred, |
| 70 | const aom_variance_fn_ptr_t *vfp, int use_mvcost); |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 71 | int av1_get_mvpred_mask_var(const MACROBLOCK *x, const MV *best_mv, |
| 72 | const MV *center_mv, const uint8_t *second_pred, |
| 73 | const uint8_t *mask, int mask_stride, |
| 74 | int invert_mask, const aom_variance_fn_ptr_t *vfp, |
| 75 | int use_mvcost); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 76 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 77 | struct AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | struct SPEED_FEATURES; |
| 79 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 80 | int av1_init_search_range(int size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 81 | |
Sebastien Alaiwan | 84ed5f9 | 2018-04-25 16:36:53 +0200 | [diff] [blame] | 82 | int av1_refining_search_sad(struct macroblock *x, MV *ref_mv, int sad_per_bit, |
| 83 | int distance, const aom_variance_fn_ptr_t *fn_ptr, |
| 84 | const MV *center_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 85 | |
Yunqing Wang | e25fdbb | 2018-03-16 16:36:32 -0700 | [diff] [blame] | 86 | // Runs sequence of diamond searches in smaller steps for RD. |
| 87 | int av1_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x, |
| 88 | MV *mvp_full, int step_param, int sadpb, |
| 89 | int further_steps, int do_refine, int *cost_list, |
| 90 | const aom_variance_fn_ptr_t *fn_ptr, |
| 91 | const MV *ref_mv, MV *dst_mv); |
| 92 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | int av1_hex_search(MACROBLOCK *x, MV *start_mv, int search_param, |
| 94 | int sad_per_bit, int do_init_search, int *cost_list, |
| 95 | const aom_variance_fn_ptr_t *vfp, int use_mvcost, |
| 96 | const MV *center_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 97 | |
| 98 | typedef int(fractional_mv_step_fp)( |
Urvang Joshi | 52b6299 | 2018-02-02 14:43:07 -0800 | [diff] [blame] | 99 | MACROBLOCK *x, const AV1_COMMON *const cm, int mi_row, int mi_col, |
| 100 | const MV *ref_mv, int allow_hp, int error_per_bit, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 101 | const aom_variance_fn_ptr_t *vfp, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 102 | int forced_stop, // 0 - full, 1 - qtr only, 2 - half only |
| 103 | int iters_per_step, int *cost_list, int *mvjcost, int *mvcost[2], |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 104 | int *distortion, unsigned int *sse1, const uint8_t *second_pred, |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 105 | const uint8_t *mask, int mask_stride, int invert_mask, int w, int h, |
Venkat | e846e2b | 2018-09-21 07:31:14 +0530 | [diff] [blame] | 106 | int use_accurate_subpel_search, const int do_reset_fractional_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 107 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 108 | extern fractional_mv_step_fp av1_find_best_sub_pixel_tree; |
| 109 | extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned; |
| 110 | extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more; |
| 111 | extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_evenmore; |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 112 | extern fractional_mv_step_fp av1_return_max_sub_pixel_mv; |
| 113 | extern fractional_mv_step_fp av1_return_min_sub_pixel_mv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 114 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 115 | typedef int (*av1_full_search_fn_t)(const MACROBLOCK *x, const MV *ref_mv, |
| 116 | int sad_per_bit, int distance, |
| 117 | const aom_variance_fn_ptr_t *fn_ptr, |
| 118 | const MV *center_mv, MV *best_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 119 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 120 | typedef int (*av1_diamond_search_fn_t)( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 121 | MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv, |
| 122 | int search_param, int sad_per_bit, int *num00, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 123 | const aom_variance_fn_ptr_t *fn_ptr, const MV *center_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 124 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | int av1_refining_search_8p_c(MACROBLOCK *x, int error_per_bit, int search_range, |
| 126 | const aom_variance_fn_ptr_t *fn_ptr, |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 127 | const uint8_t *mask, int mask_stride, |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 128 | int invert_mask, const MV *center_mv, |
| 129 | const uint8_t *second_pred); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 130 | |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 131 | int av1_full_pixel_search(const struct AV1_COMP *cpi, MACROBLOCK *x, |
| 132 | BLOCK_SIZE bsize, MV *mvp_full, int step_param, |
Hui Su | 410ca3b | 2018-08-07 11:57:57 -0700 | [diff] [blame] | 133 | int method, int run_mesh_search, int error_per_bit, |
| 134 | int *cost_list, const MV *ref_mv, int var_max, int rd, |
| 135 | int x_pos, int y_pos, int intra); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 136 | |
Peng Bin | 235d715 | 2018-09-03 16:40:46 +0800 | [diff] [blame] | 137 | int av1_obmc_full_pixel_search(const struct AV1_COMP *cpi, MACROBLOCK *x, |
| 138 | MV *mvp_full, int step_param, int sadpb, |
| 139 | int further_steps, int do_refine, |
| 140 | const aom_variance_fn_ptr_t *fn_ptr, |
| 141 | const MV *ref_mv, MV *dst_mv, int is_second); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 142 | int av1_find_best_obmc_sub_pixel_tree_up( |
Urvang Joshi | 52b6299 | 2018-02-02 14:43:07 -0800 | [diff] [blame] | 143 | MACROBLOCK *x, const AV1_COMMON *const cm, int mi_row, int mi_col, |
| 144 | MV *bestmv, const MV *ref_mv, int allow_hp, int error_per_bit, |
| 145 | const aom_variance_fn_ptr_t *vfp, int forced_stop, int iters_per_step, |
| 146 | int *mvjcost, int *mvcost[2], int *distortion, unsigned int *sse1, |
| 147 | int is_second, int use_accurate_subpel_search); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 148 | |
Yunqing Wang | 68f3ccd | 2017-05-23 14:43:54 -0700 | [diff] [blame] | 149 | unsigned int av1_compute_motion_cost(const struct AV1_COMP *cpi, |
| 150 | MACROBLOCK *const x, BLOCK_SIZE bsize, |
| 151 | int mi_row, int mi_col, const MV *this_mv); |
Yunqing Wang | 1bc8286 | 2017-06-28 15:49:48 -0700 | [diff] [blame] | 152 | unsigned int av1_refine_warped_mv(const struct AV1_COMP *cpi, |
| 153 | MACROBLOCK *const x, BLOCK_SIZE bsize, |
| 154 | int mi_row, int mi_col, int *pts0, |
Yunqing Wang | d3c13e8 | 2018-01-02 17:52:56 -0800 | [diff] [blame] | 155 | int *pts_inref0, int total_samples); |
Peng Bin | 6e2ced6 | 2018-05-08 11:34:36 +0800 | [diff] [blame] | 156 | |
Venkat | e846e2b | 2018-09-21 07:31:14 +0530 | [diff] [blame] | 157 | static INLINE void av1_set_fractional_mv(int_mv *fractional_best_mv) { |
| 158 | for (int z = 0; z < 3; z++) { |
| 159 | fractional_best_mv[z].as_int = INVALID_MV; |
| 160 | } |
| 161 | } |
| 162 | |
Peng Bin | 6e2ced6 | 2018-05-08 11:34:36 +0800 | [diff] [blame] | 163 | #ifdef __cplusplus |
| 164 | } // extern "C" |
| 165 | #endif |
| 166 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 167 | #endif // AOM_AV1_ENCODER_MCOMP_H_ |