blob: 87760c9ada6debe20de46794d5170da8a3dc59cd [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 +010061int av1_get_mvpred_mask_var(const MACROBLOCK *x, const MV *best_mv,
62 const MV *center_mv, const uint8_t *second_pred,
63 const uint8_t *mask, int mask_stride,
64 int invert_mask, const aom_variance_fn_ptr_t *vfp,
65 int use_mvcost);
Yaowu Xuc27fc142016-08-22 16:08:15 -070066
Yaowu Xuf883b422016-08-30 14:01:10 -070067struct AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -070068struct SPEED_FEATURES;
69
Yaowu Xuf883b422016-08-30 14:01:10 -070070int av1_init_search_range(int size);
Yaowu Xuc27fc142016-08-22 16:08:15 -070071
Yaowu Xuf883b422016-08-30 14:01:10 -070072int av1_refining_search_sad(struct macroblock *x, struct mv *ref_mv,
73 int sad_per_bit, int distance,
74 const aom_variance_fn_ptr_t *fn_ptr,
75 const struct mv *center_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -070076
77// Runs sequence of diamond searches in smaller steps for RD.
Yaowu Xuf883b422016-08-30 14:01:10 -070078int av1_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x,
79 MV *mvp_full, int step_param, int sadpb,
80 int further_steps, int do_refine, int *cost_list,
81 const aom_variance_fn_ptr_t *fn_ptr,
82 const MV *ref_mv, MV *dst_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -070083
84// Perform integral projection based motion estimation.
Yaowu Xuf883b422016-08-30 14:01:10 -070085unsigned int av1_int_pro_motion_estimation(const struct AV1_COMP *cpi,
86 MACROBLOCK *x, BLOCK_SIZE bsize,
87 int mi_row, int mi_col);
Yaowu Xuc27fc142016-08-22 16:08:15 -070088
Yaowu Xuf883b422016-08-30 14:01:10 -070089int av1_hex_search(MACROBLOCK *x, MV *start_mv, int search_param,
90 int sad_per_bit, int do_init_search, int *cost_list,
91 const aom_variance_fn_ptr_t *vfp, int use_mvcost,
92 const MV *center_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -070093
94typedef int(fractional_mv_step_fp)(
95 MACROBLOCK *x, const MV *ref_mv, int allow_hp, int error_per_bit,
Yaowu Xuf883b422016-08-30 14:01:10 -070096 const aom_variance_fn_ptr_t *vfp,
Yaowu Xuc27fc142016-08-22 16:08:15 -070097 int forced_stop, // 0 - full, 1 - qtr only, 2 - half only
98 int iters_per_step, int *cost_list, int *mvjcost, int *mvcost[2],
David Barkerc155e012017-05-11 13:54:54 +010099 int *distortion, unsigned int *sse1, const uint8_t *second_pred,
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200100 const uint8_t *mask, int mask_stride, int invert_mask, int w, int h,
101 int use_upsampled_ref);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102
Yaowu Xuf883b422016-08-30 14:01:10 -0700103extern fractional_mv_step_fp av1_find_best_sub_pixel_tree;
104extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned;
105extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more;
106extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_evenmore;
Yunqing Wangff4fa062017-04-21 10:56:08 -0700107extern fractional_mv_step_fp av1_return_max_sub_pixel_mv;
108extern fractional_mv_step_fp av1_return_min_sub_pixel_mv;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109
Yaowu Xuf883b422016-08-30 14:01:10 -0700110typedef int (*av1_full_search_fn_t)(const MACROBLOCK *x, const MV *ref_mv,
111 int sad_per_bit, int distance,
112 const aom_variance_fn_ptr_t *fn_ptr,
113 const MV *center_mv, MV *best_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114
Yaowu Xuf883b422016-08-30 14:01:10 -0700115typedef int (*av1_diamond_search_fn_t)(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700116 MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv,
117 int search_param, int sad_per_bit, int *num00,
Yaowu Xuf883b422016-08-30 14:01:10 -0700118 const aom_variance_fn_ptr_t *fn_ptr, const MV *center_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700119
Yaowu Xuf883b422016-08-30 14:01:10 -0700120int av1_refining_search_8p_c(MACROBLOCK *x, int error_per_bit, int search_range,
121 const aom_variance_fn_ptr_t *fn_ptr,
David Barkerc155e012017-05-11 13:54:54 +0100122 const uint8_t *mask, int mask_stride,
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200123 int invert_mask, const MV *center_mv,
124 const uint8_t *second_pred);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700125
Yaowu Xuf883b422016-08-30 14:01:10 -0700126struct AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700127
RogerZhoucc5d35d2017-08-07 22:20:15 -0700128#if CONFIG_HASH_ME
129int av1_full_pixel_search(const struct AV1_COMP *cpi, MACROBLOCK *x,
130 BLOCK_SIZE bsize, MV *mvp_full, int step_param,
131 int error_per_bit, int *cost_list, const MV *ref_mv,
RogerZhoud15e7c12017-09-26 08:49:28 -0700132 int var_max, int rd, int x_pos, int y_pos, int intra);
RogerZhoucc5d35d2017-08-07 22:20:15 -0700133#else
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);
RogerZhoucc5d35d2017-08-07 22:20:15 -0700138#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700139
Yaowu Xuf883b422016-08-30 14:01:10 -0700140int av1_obmc_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x,
Yaowu Xuf883b422016-08-30 14:01:10 -0700141 MV *mvp_full, int step_param, int sadpb,
142 int further_steps, int do_refine,
143 const aom_variance_fn_ptr_t *fn_ptr,
144 const MV *ref_mv, MV *dst_mv, int is_second);
145int av1_find_best_obmc_sub_pixel_tree_up(
Timothy B. Terriberry5d24b6f2017-06-15 13:39:35 -0700146 MACROBLOCK *x, MV *bestmv, const MV *ref_mv, int allow_hp,
147 int error_per_bit, const aom_variance_fn_ptr_t *vfp, int forced_stop,
148 int iters_per_step, int *mvjcost, int *mvcost[2], int *distortion,
149 unsigned int *sse1, int is_second, int use_upsampled_ref);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700150#ifdef __cplusplus
151} // extern "C"
152#endif
153
Yunqing Wang68f3ccd2017-05-23 14:43:54 -0700154unsigned int av1_compute_motion_cost(const struct AV1_COMP *cpi,
155 MACROBLOCK *const x, BLOCK_SIZE bsize,
156 int mi_row, int mi_col, const MV *this_mv);
Yunqing Wang97d6a372017-10-09 14:15:15 -0700157#if CONFIG_EXT_WARPED_MOTION
Yunqing Wang1bc82862017-06-28 15:49:48 -0700158unsigned int av1_refine_warped_mv(const struct AV1_COMP *cpi,
159 MACROBLOCK *const x, BLOCK_SIZE bsize,
160 int mi_row, int mi_col, int *pts0,
161 int *pts_inref0, int *pts_mv0,
162 int total_samples);
163#else
Yunqing Wang68f3ccd2017-05-23 14:43:54 -0700164unsigned int av1_refine_warped_mv(const struct AV1_COMP *cpi,
165 MACROBLOCK *const x, BLOCK_SIZE bsize,
166 int mi_row, int mi_col, int *pts,
167 int *pts_inref);
Yunqing Wang97d6a372017-10-09 14:15:15 -0700168#endif // CONFIG_EXT_WARPED_MOTION
Yunqing Wang68f3ccd2017-05-23 14:43:54 -0700169
Yaowu Xuf883b422016-08-30 14:01:10 -0700170#endif // AV1_ENCODER_MCOMP_H_