Home | History | Annotate | Download | only in encoder
      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 VPX_VP9_ENCODER_VP9_MCOMP_H_
     12 #define VPX_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 error_per_bit, int search_range,
     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                                            const MV *ref_mv);
     71 
     72 typedef uint32_t(fractional_mv_step_fp)(
     73     const MACROBLOCK *x, MV *bestmv, const MV *ref_mv, int allow_hp,
     74     int error_per_bit, const vp9_variance_fn_ptr_t *vfp,
     75     int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
     76     int iters_per_step, int *cost_list, int *mvjcost, int *mvcost[2],
     77     uint32_t *distortion, uint32_t *sse1, const uint8_t *second_pred, int w,
     78     int h, int use_accurate_subpel_search);
     79 
     80 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree;
     81 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned;
     82 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_more;
     83 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_evenmore;
     84 extern fractional_mv_step_fp vp9_skip_sub_pixel_tree;
     85 extern fractional_mv_step_fp vp9_return_max_sub_pixel_mv;
     86 extern fractional_mv_step_fp vp9_return_min_sub_pixel_mv;
     87 
     88 typedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x, const MV *ref_mv,
     89                                     int sad_per_bit, int distance,
     90                                     const vp9_variance_fn_ptr_t *fn_ptr,
     91                                     const MV *center_mv, MV *best_mv);
     92 
     93 typedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x, MV *ref_mv,
     94                                         int sad_per_bit, int distance,
     95                                         const vp9_variance_fn_ptr_t *fn_ptr,
     96                                         const MV *center_mv);
     97 
     98 typedef int (*vp9_diamond_search_fn_t)(
     99     const MACROBLOCK *x, const search_site_config *cfg, MV *ref_mv, MV *best_mv,
    100     int search_param, int sad_per_bit, int *num00,
    101     const vp9_variance_fn_ptr_t *fn_ptr, const MV *center_mv);
    102 
    103 int vp9_refining_search_8p_c(const MACROBLOCK *x, MV *ref_mv, int error_per_bit,
    104                              int search_range,
    105                              const vp9_variance_fn_ptr_t *fn_ptr,
    106                              const MV *center_mv, const uint8_t *second_pred);
    107 
    108 struct VP9_COMP;
    109 
    110 // "mvp_full" is the MV search starting point;
    111 // "ref_mv" is the context reference MV;
    112 // "tmp_mv" is the searched best MV.
    113 int vp9_full_pixel_search(struct VP9_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
    114                           MV *mvp_full, int step_param, int search_method,
    115                           int error_per_bit, int *cost_list, const MV *ref_mv,
    116                           MV *tmp_mv, int var_max, int rd);
    117 
    118 void vp9_set_subpel_mv_search_range(MvLimits *subpel_mv_limits,
    119                                     const MvLimits *umv_window_limits,
    120                                     const MV *ref_mv);
    121 
    122 #if CONFIG_NON_GREEDY_MV
    123 #define NB_MVS_NUM 4
    124 struct TplDepStats;
    125 double vp9_refining_search_sad_new(const MACROBLOCK *x, MV *best_full_mv,
    126                                    double *best_mv_dist, double *best_mv_cost,
    127                                    double lambda, int search_range,
    128                                    const vp9_variance_fn_ptr_t *fn_ptr,
    129                                    const int_mv *nb_full_mvs, int full_mv_num);
    130 
    131 double vp9_full_pixel_diamond_new(const struct VP9_COMP *cpi, MACROBLOCK *x,
    132                                   MV *mvp_full, int step_param, double lambda,
    133                                   int do_refine,
    134                                   const vp9_variance_fn_ptr_t *fn_ptr,
    135                                   const int_mv *nb_full_mvs, int full_mv_num,
    136                                   MV *best_mv, double *best_mv_dist,
    137                                   double *best_mv_cost);
    138 
    139 double vp9_nb_mvs_inconsistency(const MV *mv, const int_mv *nb_mvs, int mv_num);
    140 static INLINE MV get_full_mv(const MV *mv) {
    141   MV out_mv;
    142   out_mv.row = mv->row >> 3;
    143   out_mv.col = mv->col >> 3;
    144   return out_mv;
    145 }
    146 
    147 struct TplDepFrame;
    148 void vp9_prepare_nb_full_mvs(const struct TplDepFrame *tpl_frame, int mi_row,
    149                              int mi_col, int rf_idx, BLOCK_SIZE bsize,
    150                              int_mv *nb_full_mvs);
    151 #endif  // CONFIG_NON_GREEDY_MV
    152 #ifdef __cplusplus
    153 }  // extern "C"
    154 #endif
    155 
    156 #endif  // VPX_VP9_ENCODER_VP9_MCOMP_H_
    157