blob: eb989e82b0ed424a32b8ec0d1a36a097f805abcb [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_ENCODER_MCOMP_H_
13#define AV1_ENCODER_MCOMP_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include "av1/encoder/block.h"
16#include "aom_dsp/variance.h"
17
18#ifdef __cplusplus
19extern "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 Xuf883b422016-08-30 14:01:10 -070032#define BORDER_MV_PIXELS_B16 (16 + AOM_INTERP_EXTEND)
Yaowu Xuc27fc142016-08-22 16:08:15 -070033
34// motion search site
35typedef struct search_site {
36 MV mv;
37 int offset;
38} search_site;
39
40typedef 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 Xuf883b422016-08-30 14:01:10 -070046void av1_init_dsmotion_compensation(search_site_config *cfg, int stride);
47void av1_init3smotion_compensation(search_site_config *cfg, int stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -070048
Alex Converse0fa0f422017-04-24 12:51:14 -070049void av1_set_mv_search_range(MvLimits *mv_limits, const MV *mv);
Yunqing Wang8e173422017-04-21 09:27:55 -070050
Yaowu Xuf883b422016-08-30 14:01:10 -070051int av1_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost,
52 int *mvcost[2], int weight);
Yaowu Xuc27fc142016-08-22 16:08:15 -070053
54// Utility to compute variance + MV rate cost for a given MV
Yaowu Xuf883b422016-08-30 14:01:10 -070055int 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);
58int 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 Barkerc155e012017-05-11 13:54:54 +010061#if CONFIG_EXT_INTER
62int 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 Xuc27fc142016-08-22 16:08:15 -070068
Yaowu Xuf883b422016-08-30 14:01:10 -070069struct AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -070070struct SPEED_FEATURES;
71
Yaowu Xuf883b422016-08-30 14:01:10 -070072int av1_init_search_range(int size);
Yaowu Xuc27fc142016-08-22 16:08:15 -070073
Yaowu Xuf883b422016-08-30 14:01:10 -070074int 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 Xuc27fc142016-08-22 16:08:15 -070078
79// Runs sequence of diamond searches in smaller steps for RD.
Yaowu Xuf883b422016-08-30 14:01:10 -070080int 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 Xuc27fc142016-08-22 16:08:15 -070085
86// Perform integral projection based motion estimation.
Yaowu Xuf883b422016-08-30 14:01:10 -070087unsigned 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 Xuc27fc142016-08-22 16:08:15 -070090
Yaowu Xuf883b422016-08-30 14:01:10 -070091int 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 Xuc27fc142016-08-22 16:08:15 -070095
96typedef int(fractional_mv_step_fp)(
97 MACROBLOCK *x, const MV *ref_mv, int allow_hp, int error_per_bit,
Yaowu Xuf883b422016-08-30 14:01:10 -070098 const aom_variance_fn_ptr_t *vfp,
Yaowu Xuc27fc142016-08-22 16:08:15 -070099 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 Barkerc155e012017-05-11 13:54:54 +0100101 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 Xuc27fc142016-08-22 16:08:15 -0700106
Yaowu Xuf883b422016-08-30 14:01:10 -0700107extern fractional_mv_step_fp av1_find_best_sub_pixel_tree;
108extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned;
109extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more;
110extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_evenmore;
Yunqing Wangff4fa062017-04-21 10:56:08 -0700111extern fractional_mv_step_fp av1_return_max_sub_pixel_mv;
112extern fractional_mv_step_fp av1_return_min_sub_pixel_mv;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700113
Yaowu Xuf883b422016-08-30 14:01:10 -0700114typedef 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 Xuc27fc142016-08-22 16:08:15 -0700118
Yaowu Xuf883b422016-08-30 14:01:10 -0700119typedef int (*av1_diamond_search_fn_t)(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700120 MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv,
121 int search_param, int sad_per_bit, int *num00,
Yaowu Xuf883b422016-08-30 14:01:10 -0700122 const aom_variance_fn_ptr_t *fn_ptr, const MV *center_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700123
Yaowu Xuf883b422016-08-30 14:01:10 -0700124int av1_refining_search_8p_c(MACROBLOCK *x, int error_per_bit, int search_range,
125 const aom_variance_fn_ptr_t *fn_ptr,
David Barkerc155e012017-05-11 13:54:54 +0100126#if CONFIG_EXT_INTER
127 const uint8_t *mask, int mask_stride,
128 int invert_mask,
129#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700130 const MV *center_mv, const uint8_t *second_pred);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700131
Yaowu Xuf883b422016-08-30 14:01:10 -0700132struct AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700133
Urvang Joshi52648442016-10-13 17:27:51 -0700134int 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 Xuc27fc142016-08-22 16:08:15 -0700138
139#if CONFIG_EXT_INTER
Yaowu Xuf883b422016-08-30 14:01:10 -0700140int av1_find_best_masked_sub_pixel_tree(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700141 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 Xuf883b422016-08-30 14:01:10 -0700143 const aom_variance_fn_ptr_t *vfp, int forced_stop, int iters_per_step,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700144 int *mvjcost, int *mvcost[2], int *distortion, unsigned int *sse1,
145 int is_second);
Yaowu Xuf883b422016-08-30 14:01:10 -0700146int av1_find_best_masked_sub_pixel_tree_up(
Urvang Joshi52648442016-10-13 17:27:51 -0700147 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 Xuf883b422016-08-30 14:01:10 -0700152int 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 Xuc27fc142016-08-22 16:08:15 -0700158#endif // CONFIG_EXT_INTER
159
Yue Chencb60b182016-10-13 15:18:22 -0700160#if CONFIG_MOTION_VAR
Yaowu Xuf883b422016-08-30 14:01:10 -0700161int av1_obmc_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x,
Yaowu Xuf883b422016-08-30 14:01:10 -0700162 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);
166int av1_find_best_obmc_sub_pixel_tree_up(
Urvang Joshi52648442016-10-13 17:27:51 -0700167 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 Chene9638cc2016-10-10 12:37:54 -0700169 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 Chencb60b182016-10-13 15:18:22 -0700172#endif // CONFIG_MOTION_VAR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700173#ifdef __cplusplus
174} // extern "C"
175#endif
176
Yaowu Xuf883b422016-08-30 14:01:10 -0700177#endif // AV1_ENCODER_MCOMP_H_