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 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_ENCODER_MCOMP_H_ |
| 13 | #define 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 |
| 24 | #define MAX_MVSEARCH_STEPS 11 |
| 25 | // Max full pel mv specified in the unit of full pixel |
| 26 | // Enable the use of motion vector in range [-1023, 1023]. |
| 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 | |
| 34 | // motion search site |
| 35 | typedef struct search_site { |
| 36 | MV mv; |
| 37 | int offset; |
| 38 | } search_site; |
| 39 | |
| 40 | typedef struct search_site_config { |
| 41 | search_site ss[8 * MAX_MVSEARCH_STEPS + 1]; |
| 42 | int ss_count; |
| 43 | int searches_per_step; |
| 44 | } search_site_config; |
| 45 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 46 | void av1_init_dsmotion_compensation(search_site_config *cfg, int stride); |
| 47 | void av1_init3smotion_compensation(search_site_config *cfg, int stride); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | |
Alex Converse | 0fa0f42 | 2017-04-24 12:51:14 -0700 | [diff] [blame] | 49 | void av1_set_mv_search_range(MvLimits *mv_limits, const MV *mv); |
Yunqing Wang | 8e17342 | 2017-04-21 09:27:55 -0700 | [diff] [blame] | 50 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 51 | int av1_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost, |
| 52 | int *mvcost[2], int weight); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | |
| 54 | // Utility to compute variance + MV rate cost for a given MV |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 55 | int av1_get_mvpred_var(const MACROBLOCK *x, const MV *best_mv, |
| 56 | const MV *center_mv, const aom_variance_fn_ptr_t *vfp, |
| 57 | int use_mvcost); |
| 58 | int av1_get_mvpred_av_var(const MACROBLOCK *x, const MV *best_mv, |
| 59 | const MV *center_mv, const uint8_t *second_pred, |
| 60 | const aom_variance_fn_ptr_t *vfp, int use_mvcost); |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame^] | 61 | #if CONFIG_EXT_INTER |
| 62 | int av1_get_mvpred_mask_var(const MACROBLOCK *x, const MV *best_mv, |
| 63 | const MV *center_mv, const uint8_t *second_pred, |
| 64 | const uint8_t *mask, int mask_stride, |
| 65 | int invert_mask, const aom_variance_fn_ptr_t *vfp, |
| 66 | int use_mvcost); |
| 67 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | struct AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 70 | struct SPEED_FEATURES; |
| 71 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 72 | int av1_init_search_range(int size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 74 | int av1_refining_search_sad(struct macroblock *x, struct mv *ref_mv, |
| 75 | int sad_per_bit, int distance, |
| 76 | const aom_variance_fn_ptr_t *fn_ptr, |
| 77 | const struct mv *center_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | |
| 79 | // Runs sequence of diamond searches in smaller steps for RD. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 80 | int av1_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x, |
| 81 | MV *mvp_full, int step_param, int sadpb, |
| 82 | int further_steps, int do_refine, int *cost_list, |
| 83 | const aom_variance_fn_ptr_t *fn_ptr, |
| 84 | const MV *ref_mv, MV *dst_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 85 | |
| 86 | // Perform integral projection based motion estimation. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | unsigned int av1_int_pro_motion_estimation(const struct AV1_COMP *cpi, |
| 88 | MACROBLOCK *x, BLOCK_SIZE bsize, |
| 89 | int mi_row, int mi_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 91 | int av1_hex_search(MACROBLOCK *x, MV *start_mv, int search_param, |
| 92 | int sad_per_bit, int do_init_search, int *cost_list, |
| 93 | const aom_variance_fn_ptr_t *vfp, int use_mvcost, |
| 94 | const MV *center_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 95 | |
| 96 | typedef int(fractional_mv_step_fp)( |
| 97 | MACROBLOCK *x, const MV *ref_mv, int allow_hp, int error_per_bit, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 98 | const aom_variance_fn_ptr_t *vfp, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 99 | int forced_stop, // 0 - full, 1 - qtr only, 2 - half only |
| 100 | int iters_per_step, int *cost_list, int *mvjcost, int *mvcost[2], |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame^] | 101 | int *distortion, unsigned int *sse1, const uint8_t *second_pred, |
| 102 | #if CONFIG_EXT_INTER |
| 103 | const uint8_t *mask, int mask_stride, int invert_mask, |
| 104 | #endif |
| 105 | int w, int h, int use_upsampled_ref); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 106 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 107 | extern fractional_mv_step_fp av1_find_best_sub_pixel_tree; |
| 108 | extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned; |
| 109 | extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more; |
| 110 | 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] | 111 | extern fractional_mv_step_fp av1_return_max_sub_pixel_mv; |
| 112 | extern fractional_mv_step_fp av1_return_min_sub_pixel_mv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 113 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 114 | typedef int (*av1_full_search_fn_t)(const MACROBLOCK *x, const MV *ref_mv, |
| 115 | int sad_per_bit, int distance, |
| 116 | const aom_variance_fn_ptr_t *fn_ptr, |
| 117 | const MV *center_mv, MV *best_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 118 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 119 | typedef int (*av1_diamond_search_fn_t)( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 120 | MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv, |
| 121 | int search_param, int sad_per_bit, int *num00, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 122 | const aom_variance_fn_ptr_t *fn_ptr, const MV *center_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 123 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | int av1_refining_search_8p_c(MACROBLOCK *x, int error_per_bit, int search_range, |
| 125 | const aom_variance_fn_ptr_t *fn_ptr, |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame^] | 126 | #if CONFIG_EXT_INTER |
| 127 | const uint8_t *mask, int mask_stride, |
| 128 | int invert_mask, |
| 129 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 130 | const MV *center_mv, const uint8_t *second_pred); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 131 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 132 | struct AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 133 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 134 | int av1_full_pixel_search(const struct AV1_COMP *cpi, MACROBLOCK *x, |
| 135 | BLOCK_SIZE bsize, MV *mvp_full, int step_param, |
| 136 | int error_per_bit, int *cost_list, const MV *ref_mv, |
| 137 | int var_max, int rd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 138 | |
| 139 | #if CONFIG_EXT_INTER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 140 | int av1_find_best_masked_sub_pixel_tree( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 141 | const MACROBLOCK *x, const uint8_t *mask, int mask_stride, MV *bestmv, |
| 142 | const MV *ref_mv, int allow_hp, int error_per_bit, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 143 | const aom_variance_fn_ptr_t *vfp, int forced_stop, int iters_per_step, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 144 | int *mvjcost, int *mvcost[2], int *distortion, unsigned int *sse1, |
| 145 | int is_second); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 146 | int av1_find_best_masked_sub_pixel_tree_up( |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 147 | const struct AV1_COMP *cpi, MACROBLOCK *x, const uint8_t *mask, |
| 148 | int mask_stride, int mi_row, int mi_col, MV *bestmv, const MV *ref_mv, |
| 149 | int allow_hp, int error_per_bit, const aom_variance_fn_ptr_t *vfp, |
| 150 | int forced_stop, int iters_per_step, int *mvjcost, int *mvcost[2], |
| 151 | int *distortion, unsigned int *sse1, int is_second, int use_upsampled_ref); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 152 | int av1_masked_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x, |
| 153 | const uint8_t *mask, int mask_stride, |
| 154 | MV *mvp_full, int step_param, int sadpb, |
| 155 | int further_steps, int do_refine, |
| 156 | const aom_variance_fn_ptr_t *fn_ptr, |
| 157 | const MV *ref_mv, MV *dst_mv, int is_second); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 158 | #endif // CONFIG_EXT_INTER |
| 159 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 160 | #if CONFIG_MOTION_VAR |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 161 | int av1_obmc_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 162 | MV *mvp_full, int step_param, int sadpb, |
| 163 | int further_steps, int do_refine, |
| 164 | const aom_variance_fn_ptr_t *fn_ptr, |
| 165 | const MV *ref_mv, MV *dst_mv, int is_second); |
| 166 | int av1_find_best_obmc_sub_pixel_tree_up( |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 167 | const struct AV1_COMP *cpi, MACROBLOCK *x, int mi_row, int mi_col, |
| 168 | MV *bestmv, const MV *ref_mv, int allow_hp, int error_per_bit, |
Yue Chen | e9638cc | 2016-10-10 12:37:54 -0700 | [diff] [blame] | 169 | const aom_variance_fn_ptr_t *vfp, int forced_stop, int iters_per_step, |
| 170 | int *mvjcost, int *mvcost[2], int *distortion, unsigned int *sse1, |
| 171 | int is_second, int use_upsampled_ref); |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 172 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 173 | #ifdef __cplusplus |
| 174 | } // extern "C" |
| 175 | #endif |
| 176 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 177 | #endif // AV1_ENCODER_MCOMP_H_ |