• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
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.
10  */
11 
12 #ifndef AOM_AV1_ENCODER_MCOMP_H_
13 #define AOM_AV1_ENCODER_MCOMP_H_
14 
15 #include "av1/encoder/block.h"
16 
17 #include "aom_dsp/variance.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 // The maximum number of steps in a step search given the largest
24 // allowed initial step
25 #define MAX_MVSEARCH_STEPS 11
26 // Max full pel mv specified in the unit of full pixel
27 // Enable the use of motion vector in range [-1023, 1023].
28 #define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS - 1)) - 1)
29 // Maximum size of the first step in full pel units
30 #define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS - 1))
31 // Allowed motion vector pixel distance outside image border
32 // for Block_16x16
33 #define BORDER_MV_PIXELS_B16 (16 + AOM_INTERP_EXTEND)
34 
35 #define SEARCH_RANGE_8P 3
36 #define SEARCH_GRID_STRIDE_8P (2 * SEARCH_RANGE_8P + 1)
37 #define SEARCH_GRID_CENTER_8P \
38   (SEARCH_RANGE_8P * SEARCH_GRID_STRIDE_8P + SEARCH_RANGE_8P)
39 
40 // motion search site
41 typedef struct search_site {
42   MV mv;
43   int offset;
44 } search_site;
45 
46 typedef struct search_site_config {
47   search_site ss[8 * MAX_MVSEARCH_STEPS + 1];
48   int ss_count;
49   int searches_per_step;
50 } search_site_config;
51 
52 typedef struct {
53   MV coord;
54   int coord_offset;
55 } search_neighbors;
56 
57 void av1_init_dsmotion_compensation(search_site_config *cfg, int stride);
58 void av1_init3smotion_compensation(search_site_config *cfg, int stride);
59 
60 void av1_set_mv_search_range(MvLimits *mv_limits, const MV *mv);
61 
62 int av1_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost,
63                     int *mvcost[2], int weight);
64 
65 // Utility to compute variance + MV rate cost for a given MV
66 int av1_get_mvpred_var(const MACROBLOCK *x, const MV *best_mv,
67                        const MV *center_mv, const aom_variance_fn_ptr_t *vfp,
68                        int use_mvcost);
69 int av1_get_mvpred_av_var(const MACROBLOCK *x, const MV *best_mv,
70                           const MV *center_mv, const uint8_t *second_pred,
71                           const aom_variance_fn_ptr_t *vfp, int use_mvcost);
72 int av1_get_mvpred_mask_var(const MACROBLOCK *x, const MV *best_mv,
73                             const MV *center_mv, const uint8_t *second_pred,
74                             const uint8_t *mask, int mask_stride,
75                             int invert_mask, const aom_variance_fn_ptr_t *vfp,
76                             int use_mvcost);
77 
78 struct AV1_COMP;
79 struct SPEED_FEATURES;
80 
81 int av1_init_search_range(int size);
82 
83 int av1_refining_search_sad(struct macroblock *x, MV *ref_mv, int sad_per_bit,
84                             int distance, const aom_variance_fn_ptr_t *fn_ptr,
85                             const MV *center_mv);
86 
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,
90                                            const MV *ref_mv);
91 
92 // Runs sequence of diamond searches in smaller steps for RD.
93 int av1_full_pixel_diamond(const struct AV1_COMP *cpi, MACROBLOCK *x,
94                            MV *mvp_full, int step_param, int sadpb,
95                            int further_steps, int do_refine, int *cost_list,
96                            const aom_variance_fn_ptr_t *fn_ptr,
97                            const MV *ref_mv, MV *dst_mv);
98 
99 int av1_hex_search(MACROBLOCK *x, MV *start_mv, int search_param,
100                    int sad_per_bit, int do_init_search, int *cost_list,
101                    const aom_variance_fn_ptr_t *vfp, int use_mvcost,
102                    const MV *center_mv);
103 
104 typedef int(fractional_mv_step_fp)(
105     MACROBLOCK *x, const AV1_COMMON *const cm, int mi_row, int mi_col,
106     const MV *ref_mv, int allow_hp, int error_per_bit,
107     const aom_variance_fn_ptr_t *vfp,
108     int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
109     int iters_per_step, int *cost_list, int *mvjcost, int *mvcost[2],
110     int *distortion, unsigned int *sse1, const uint8_t *second_pred,
111     const uint8_t *mask, int mask_stride, int invert_mask, int w, int h,
112     int use_accurate_subpel_search, const int do_reset_fractional_mv);
113 
114 extern fractional_mv_step_fp av1_find_best_sub_pixel_tree;
115 extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned;
116 extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_more;
117 extern fractional_mv_step_fp av1_find_best_sub_pixel_tree_pruned_evenmore;
118 extern fractional_mv_step_fp av1_return_max_sub_pixel_mv;
119 extern fractional_mv_step_fp av1_return_min_sub_pixel_mv;
120 
121 typedef int (*av1_full_search_fn_t)(const MACROBLOCK *x, const MV *ref_mv,
122                                     int sad_per_bit, int distance,
123                                     const aom_variance_fn_ptr_t *fn_ptr,
124                                     const MV *center_mv, MV *best_mv);
125 
126 typedef int (*av1_diamond_search_fn_t)(
127     MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv,
128     int search_param, int sad_per_bit, int *num00,
129     const aom_variance_fn_ptr_t *fn_ptr, const MV *center_mv);
130 
131 int av1_refining_search_8p_c(MACROBLOCK *x, int error_per_bit, int search_range,
132                              const aom_variance_fn_ptr_t *fn_ptr,
133                              const uint8_t *mask, int mask_stride,
134                              int invert_mask, const MV *center_mv,
135                              const uint8_t *second_pred);
136 
137 int av1_full_pixel_search(const struct AV1_COMP *cpi, MACROBLOCK *x,
138                           BLOCK_SIZE bsize, MV *mvp_full, int step_param,
139                           int method, int run_mesh_search, int error_per_bit,
140                           int *cost_list, const MV *ref_mv, int var_max, int rd,
141                           int x_pos, int y_pos, int intra,
142                           const search_site_config *cfg);
143 
144 int av1_obmc_full_pixel_search(const struct AV1_COMP *cpi, MACROBLOCK *x,
145                                MV *mvp_full, int step_param, int sadpb,
146                                int further_steps, int do_refine,
147                                const aom_variance_fn_ptr_t *fn_ptr,
148                                const MV *ref_mv, MV *dst_mv, int is_second,
149                                const search_site_config *cfg);
150 int av1_find_best_obmc_sub_pixel_tree_up(
151     MACROBLOCK *x, const AV1_COMMON *const cm, int mi_row, int mi_col,
152     MV *bestmv, const MV *ref_mv, int allow_hp, int error_per_bit,
153     const aom_variance_fn_ptr_t *vfp, int forced_stop, int iters_per_step,
154     int *mvjcost, int *mvcost[2], int *distortion, unsigned int *sse1,
155     int is_second, int use_accurate_subpel_search);
156 
157 unsigned int av1_compute_motion_cost(const struct AV1_COMP *cpi,
158                                      MACROBLOCK *const x, BLOCK_SIZE bsize,
159                                      int mi_row, int mi_col, const MV *this_mv);
160 unsigned int av1_refine_warped_mv(const struct AV1_COMP *cpi,
161                                   MACROBLOCK *const x, BLOCK_SIZE bsize,
162                                   int mi_row, int mi_col, int *pts0,
163                                   int *pts_inref0, int total_samples);
164 
165 // Performs a motion search in SIMPLE_TRANSLATION mode using reference frame
166 // ref. Note that this sets the offset of mbmi, so we will need to reset it
167 // after calling this function.
168 void av1_simple_motion_search(struct AV1_COMP *const cpi, MACROBLOCK *x,
169                               int mi_row, int mi_col, BLOCK_SIZE bsize, int ref,
170                               MV ref_mv_full, int num_planes, int use_subpixel);
171 
172 // Performs a simple motion search to calculate the sse and var of the residue
173 void av1_simple_motion_sse_var(struct AV1_COMP *cpi, MACROBLOCK *x, int mi_row,
174                                int mi_col, BLOCK_SIZE bsize,
175                                const MV ref_mv_full, int use_subpixel,
176                                unsigned int *sse, unsigned int *var);
177 
av1_set_fractional_mv(int_mv * fractional_best_mv)178 static INLINE void av1_set_fractional_mv(int_mv *fractional_best_mv) {
179   for (int z = 0; z < 3; z++) {
180     fractional_best_mv[z].as_int = INVALID_MV;
181   }
182 }
183 
184 #ifdef __cplusplus
185 }  // extern "C"
186 #endif
187 
188 #endif  // AOM_AV1_ENCODER_MCOMP_H_
189