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 
     12 #ifndef VP9_ENCODER_VP9_MCOMP_H_
     13 #define VP9_ENCODER_VP9_MCOMP_H_
     14 
     15 #include "vp9/encoder/vp9_block.h"
     16 #include "vpx_dsp/variance.h"
     17 
     18 #ifdef __cplusplus
     19 extern "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
     32 #define BORDER_MV_PIXELS_B16 (16 + VP9_INTERP_EXTEND)
     33 
     34 // motion search site
     35 typedef struct search_site {
     36   MV mv;
     37   int offset;
     38 } search_site;
     39 
     40 typedef 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 
     46 void vp9_init_dsmotion_compensation(search_site_config *cfg, int stride);
     47 void vp9_init3smotion_compensation(search_site_config *cfg,  int stride);
     48 
     49 void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv);
     50 int vp9_mv_bit_cost(const MV *mv, const MV *ref,
     51                     const int *mvjcost, int *mvcost[2], int weight);
     52 
     53 // Utility to compute variance + MV rate cost for a given MV
     54 int vp9_get_mvpred_var(const MACROBLOCK *x,
     55                        const MV *best_mv, const MV *center_mv,
     56                        const vp9_variance_fn_ptr_t *vfp,
     57                        int use_mvcost);
     58 int vp9_get_mvpred_av_var(const MACROBLOCK *x,
     59                           const MV *best_mv, const MV *center_mv,
     60                           const uint8_t *second_pred,
     61                           const vp9_variance_fn_ptr_t *vfp,
     62                           int use_mvcost);
     63 
     64 struct VP9_COMP;
     65 struct SPEED_FEATURES;
     66 
     67 int vp9_init_search_range(int size);
     68 
     69 int vp9_refining_search_sad(const struct macroblock *x,
     70                             struct mv *ref_mv,
     71                             int sad_per_bit, int distance,
     72                             const struct vp9_variance_vtable *fn_ptr,
     73                             const struct mv *center_mv);
     74 
     75 // Perform integral projection based motion estimation.
     76 unsigned int vp9_int_pro_motion_estimation(const struct VP9_COMP *cpi,
     77                                            MACROBLOCK *x,
     78                                            BLOCK_SIZE bsize,
     79                                            int mi_row, int mi_col);
     80 
     81 typedef int (fractional_mv_step_fp) (
     82     const MACROBLOCK *x,
     83     MV *bestmv, const MV *ref_mv,
     84     int allow_hp,
     85     int error_per_bit,
     86     const vp9_variance_fn_ptr_t *vfp,
     87     int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
     88     int iters_per_step,
     89     int *cost_list,
     90     int *mvjcost, int *mvcost[2],
     91     int *distortion, unsigned int *sse1,
     92     const uint8_t *second_pred,
     93     int w, int h);
     94 
     95 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree;
     96 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned;
     97 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_more;
     98 extern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned_evenmore;
     99 
    100 typedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x,
    101                                     const MV *ref_mv, int sad_per_bit,
    102                                     int distance,
    103                                     const vp9_variance_fn_ptr_t *fn_ptr,
    104                                     const MV *center_mv, MV *best_mv);
    105 
    106 typedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x,
    107                                         MV *ref_mv, int sad_per_bit,
    108                                         int distance,
    109                                         const vp9_variance_fn_ptr_t *fn_ptr,
    110                                         const MV *center_mv);
    111 
    112 typedef int (*vp9_diamond_search_fn_t)(const MACROBLOCK *x,
    113                                        const search_site_config *cfg,
    114                                        MV *ref_mv, MV *best_mv,
    115                                        int search_param, int sad_per_bit,
    116                                        int *num00,
    117                                        const vp9_variance_fn_ptr_t *fn_ptr,
    118                                        const MV *center_mv);
    119 
    120 int vp9_refining_search_8p_c(const MACROBLOCK *x,
    121                              MV *ref_mv, int error_per_bit,
    122                              int search_range,
    123                              const vp9_variance_fn_ptr_t *fn_ptr,
    124                              const MV *center_mv, const uint8_t *second_pred);
    125 
    126 struct VP9_COMP;
    127 
    128 int vp9_full_pixel_search(struct VP9_COMP *cpi, MACROBLOCK *x,
    129                           BLOCK_SIZE bsize, MV *mvp_full,
    130                           int step_param, int error_per_bit,
    131                           int *cost_list,
    132                           const MV *ref_mv, MV *tmp_mv,
    133                           int var_max, int rd);
    134 
    135 #ifdef __cplusplus
    136 }  // extern "C"
    137 #endif
    138 
    139 #endif  // VP9_ENCODER_VP9_MCOMP_H_
    140