blob: 3f8b3b1fd3fd6bcdd72d64ba0e723b0def2888c5 [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
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_AV1_ENCODER_MCOMP_H_
13#define AOM_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
Yunqing Wange25fdbb2018-03-16 16:36:32 -070024#define MAX_MVSEARCH_STEPS 11
Yaowu Xuc27fc142016-08-22 16:08:15 -070025// Max full pel mv specified in the unit of full pixel
Yunqing Wange25fdbb2018-03-16 16:36:32 -070026// Enable the use of motion vector in range [-1023, 1023].
Yaowu Xuc27fc142016-08-22 16:08:15 -070027#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
Deepa K Gd4febfb2018-08-14 11:33:51 +053034#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 Xuc27fc142016-08-22 16:08:15 -070039// motion search site
40typedef struct search_site {
41 MV mv;
42 int offset;
43} search_site;
44
45typedef 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 Gd4febfb2018-08-14 11:33:51 +053051typedef struct {
52 MV coord;
53 int coord_offset;
54} search_neighbors;
55
Yaowu Xuf883b422016-08-30 14:01:10 -070056void av1_init_dsmotion_compensation(search_site_config *cfg, int stride);
57void av1_init3smotion_compensation(search_site_config *cfg, int stride);
Yaowu Xuc27fc142016-08-22 16:08:15 -070058
Alex Converse0fa0f422017-04-24 12:51:14 -070059void av1_set_mv_search_range(MvLimits *mv_limits, const MV *mv);
Yunqing Wang8e173422017-04-21 09:27:55 -070060
Yaowu Xuf883b422016-08-30 14:01:10 -070061int av1_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost,
62 int *mvcost[2], int weight);
Yaowu Xuc27fc142016-08-22 16:08:15 -070063
64// Utility to compute variance + MV rate cost for a given MV
Yaowu Xuf883b422016-08-30 14:01:10 -070065int 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);
68int 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 Barkerc155e012017-05-11 13:54:54 +010071int 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 Xuc27fc142016-08-22 16:08:15 -070076
Yaowu Xuf883b422016-08-30 14:01:10 -070077struct AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -070078struct SPEED_FEATURES;
79
Yaowu Xuf883b422016-08-30 14:01:10 -070080int av1_init_search_range(int size);
Yaowu Xuc27fc142016-08-22 16:08:15 -070081
Sebastien Alaiwan84ed5f92018-04-25 16:36:53 +020082int 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 Xuc27fc142016-08-22 16:08:15 -070085
Yunqing Wange25fdbb2018-03-16 16:36:32 -070086// Runs sequence of diamond searches in smaller steps for RD.
87int 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 Xuf883b422016-08-30 14:01:10 -070093int 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 Xuc27fc142016-08-22 16:08:15 -070097
98typedef int(fractional_mv_step_fp)(
Urvang Joshi52b62992018-02-02 14:43:07 -080099 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 Xuf883b422016-08-30 14:01:10 -0700101 const aom_variance_fn_ptr_t *vfp,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102 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 Barkerc155e012017-05-11 13:54:54 +0100104 int *distortion, unsigned int *sse1, const uint8_t *second_pred,
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200105 const uint8_t *mask, int mask_stride, int invert_mask, int w, int h,
Venkate846e2b2018-09-21 07:31:14 +0530106 int use_accurate_subpel_search, const int do_reset_fractional_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700107
Yaowu Xuf883b422016-08-30 14:01:10 -0700108extern fractional_mv_step_fp av1_find_best_sub_pixel_tree;
109extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned;
110extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more;
111extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_evenmore;
Yunqing Wangff4fa062017-04-21 10:56:08 -0700112extern fractional_mv_step_fp av1_return_max_sub_pixel_mv;
113extern fractional_mv_step_fp av1_return_min_sub_pixel_mv;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114
Yaowu Xuf883b422016-08-30 14:01:10 -0700115typedef 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 Xuc27fc142016-08-22 16:08:15 -0700119
Yaowu Xuf883b422016-08-30 14:01:10 -0700120typedef int (*av1_diamond_search_fn_t)(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700121 MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv,
122 int search_param, int sad_per_bit, int *num00,
Yaowu Xuf883b422016-08-30 14:01:10 -0700123 const aom_variance_fn_ptr_t *fn_ptr, const MV *center_mv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700124
Yaowu Xuf883b422016-08-30 14:01:10 -0700125int av1_refining_search_8p_c(MACROBLOCK *x, int error_per_bit, int search_range,
126 const aom_variance_fn_ptr_t *fn_ptr,
David Barkerc155e012017-05-11 13:54:54 +0100127 const uint8_t *mask, int mask_stride,
Sebastien Alaiwan0bdea0d2017-10-02 15:15:05 +0200128 int invert_mask, const MV *center_mv,
129 const uint8_t *second_pred);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700130
RogerZhoucc5d35d2017-08-07 22:20:15 -0700131int av1_full_pixel_search(const struct AV1_COMP *cpi, MACROBLOCK *x,
132 BLOCK_SIZE bsize, MV *mvp_full, int step_param,
Hui Su410ca3b2018-08-07 11:57:57 -0700133 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 Xuc27fc142016-08-22 16:08:15 -0700136
Peng Bin235d7152018-09-03 16:40:46 +0800137int 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 Xuf883b422016-08-30 14:01:10 -0700142int av1_find_best_obmc_sub_pixel_tree_up(
Urvang Joshi52b62992018-02-02 14:43:07 -0800143 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 Xuc27fc142016-08-22 16:08:15 -0700148
Yunqing Wang68f3ccd2017-05-23 14:43:54 -0700149unsigned 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 Wang1bc82862017-06-28 15:49:48 -0700152unsigned 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 Wangd3c13e82018-01-02 17:52:56 -0800155 int *pts_inref0, int total_samples);
Peng Bin6e2ced62018-05-08 11:34:36 +0800156
Venkate846e2b2018-09-21 07:31:14 +0530157static 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 Bin6e2ced62018-05-08 11:34:36 +0800163#ifdef __cplusplus
164} // extern "C"
165#endif
166
James Zerne1cbb132018-08-22 14:10:36 -0700167#endif // AOM_AV1_ENCODER_MCOMP_H_