• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef VP9_ENCODER_VP9_MCOMP_H_
12 #define VP9_ENCODER_VP9_MCOMP_H_
13 
14 #include "vp9/encoder/vp9_block.h"
15 #include "vpx_dsp/variance.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 // The maximum number of steps in a step search given the largest
22 // allowed initial step
23 #define MAX_MVSEARCH_STEPS 11
24 // Max full pel mv specified in the unit of full pixel
25 // Enable the use of motion vector in range [-1023, 1023].
26 #define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS - 1)) - 1)
27 // Maximum size of the first step in full pel units
28 #define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS - 1))
29 // Allowed motion vector pixel distance outside image border
30 // for Block_16x16
31 #define BORDER_MV_PIXELS_B16 (16 + VP9_INTERP_EXTEND)
32 
33 typedef struct search_site_config {
34   // motion search sites
35   MV ss_mv[8 * MAX_MVSEARCH_STEPS];        // Motion vector
36   intptr_t ss_os[8 * MAX_MVSEARCH_STEPS];  // Offset
37   int searches_per_step;
38   int total_steps;
39 } search_site_config;
40 
41 void vp9_init_dsmotion_compensation(search_site_config *cfg, int stride);
42 void vp9_init3smotion_compensation(search_site_config *cfg, int stride);
43 
44 void vp9_set_mv_search_range(MvLimits *mv_limits, const MV *mv);
45 int vp9_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost,
46                     int *mvcost[2], int weight);
47 
48 // Utility to compute variance + MV rate cost for a given MV
49 int vp9_get_mvpred_var(const MACROBLOCK *x, const MV *best_mv,
50                        const MV *center_mv, const vp9_variance_fn_ptr_t *vfp,
51                        int use_mvcost);
52 int vp9_get_mvpred_av_var(const MACROBLOCK *x, const MV *best_mv,
53                           const MV *center_mv, const uint8_t *second_pred,
54                           const vp9_variance_fn_ptr_t *vfp, int use_mvcost);
55 
56 struct VP9_COMP;
57 struct SPEED_FEATURES;
58 
59 int vp9_init_search_range(int size);
60 
61 int vp9_refining_search_sad(const struct macroblock *x, struct mv *ref_mv,
62                             int sad_per_bit, int distance,
63                             const struct vp9_variance_vtable *fn_ptr,
64                             const struct mv *center_mv);
65 
66 // Perform integral projection based motion estimation.
67 unsigned int vp9_int_pro_motion_estimation(const struct VP9_COMP *cpi,
68                                            MACROBLOCK *x, BLOCK_SIZE bsize,
69                                            int mi_row, int mi_col);
70 
71 typedef uint32_t(fractional_mv_step_fp)(
72     const MACROBLOCK *x, MV *bestmv, const MV *ref_mv, int allow_hp,
73     int error_per_bit, const vp9_variance_fn_ptr_t *vfp,
74     int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
75     int iters_per_step, int *cost_list, int *mvjcost, int *mvcost[2],
76     uint32_t *distortion, uint32_t *sse1, const uint8_t *second_pred, int w,
77     int h);
78 
79 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree;
80 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned;
81 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_more;
82 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_evenmore;
83 extern fractional_mv_step_fp vp9_skip_sub_pixel_tree;
84 extern fractional_mv_step_fp vp9_return_max_sub_pixel_mv;
85 extern fractional_mv_step_fp vp9_return_min_sub_pixel_mv;
86 
87 typedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x, const MV *ref_mv,
88                                     int sad_per_bit, int distance,
89                                     const vp9_variance_fn_ptr_t *fn_ptr,
90                                     const MV *center_mv, MV *best_mv);
91 
92 typedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x, MV *ref_mv,
93                                         int sad_per_bit, int distance,
94                                         const vp9_variance_fn_ptr_t *fn_ptr,
95                                         const MV *center_mv);
96 
97 typedef int (*vp9_diamond_search_fn_t)(
98     const MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv,
99     int search_param, int sad_per_bit, int *num00,
100     const vp9_variance_fn_ptr_t *fn_ptr, const MV *center_mv);
101 
102 int vp9_refining_search_8p_c(const MACROBLOCK *x, MV *ref_mv, int error_per_bit,
103                              int search_range,
104                              const vp9_variance_fn_ptr_t *fn_ptr,
105                              const MV *center_mv, const uint8_t *second_pred);
106 
107 struct VP9_COMP;
108 
109 int vp9_full_pixel_search(struct VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
110                           MV *mvp_full, int step_param, int search_method,
111                           int error_per_bit, int *cost_list, const MV *ref_mv,
112                           MV *tmp_mv, int var_max, int rd);
113 
114 void vp9_set_subpel_mv_search_range(MvLimits *subpel_mv_limits,
115                                     const MvLimits *umv_window_limits,
116                                     const MV *ref_mv);
117 
118 #ifdef __cplusplus
119 }  // extern "C"
120 #endif
121 
122 #endif  // VP9_ENCODER_VP9_MCOMP_H_
123