16fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org/*
26fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
36fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *
46fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Use of this source code is governed by a BSD-style license
56fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  that can be found in the LICENSE file in the root of the source
66fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  tree. An additional intellectual property rights grant can be found
76fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  in the file PATENTS.  All contributing project authors may
86fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  be found in the AUTHORS file in the root of the source tree.
96fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org */
106fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
116fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
126fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#ifndef VP9_ENCODER_VP9_MCOMP_H_
136fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#define VP9_ENCODER_VP9_MCOMP_H_
146fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
156fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#include "vp9/encoder/vp9_block.h"
166fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#include "vp9/encoder/vp9_variance.h"
176fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
18dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
19dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgextern "C" {
20dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
21dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
2290c5310de3dfbd1b1624502616cbc8aaf9ad25f0johannkoenig@chromium.org// The maximum number of steps in a step search given the largest
2390c5310de3dfbd1b1624502616cbc8aaf9ad25f0johannkoenig@chromium.org// allowed initial step
2490c5310de3dfbd1b1624502616cbc8aaf9ad25f0johannkoenig@chromium.org#define MAX_MVSEARCH_STEPS 11
25d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org// Max full pel mv specified in the unit of full pixel
26d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org// Enable the use of motion vector in range [-1023, 1023].
27d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org#define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS - 1)) - 1)
2890c5310de3dfbd1b1624502616cbc8aaf9ad25f0johannkoenig@chromium.org// Maximum size of the first step in full pel units
2990c5310de3dfbd1b1624502616cbc8aaf9ad25f0johannkoenig@chromium.org#define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS-1))
30ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org// Allowed motion vector pixel distance outside image border
31ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org// for Block_16x16
32ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org#define BORDER_MV_PIXELS_B16 (16 + VP9_INTERP_EXTEND)
33ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org
3477496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org// motion search site
3577496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.orgtypedef struct search_site {
3677496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org  MV mv;
3777496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org  int offset;
3877496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org} search_site;
3977496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org
4077496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.orgtypedef struct search_site_config {
4177496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org  search_site ss[8 * MAX_MVSEARCH_STEPS + 1];
4277496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org  int ss_count;
4377496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org  int searches_per_step;
4477496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org} search_site_config;
4577496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org
4677496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.orgvoid vp9_init_dsmotion_compensation(search_site_config *cfg, int stride);
4777496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.orgvoid vp9_init3smotion_compensation(search_site_config *cfg,  int stride);
486fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
49dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgvoid vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv);
50ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.orgint vp9_mv_bit_cost(const MV *mv, const MV *ref,
51ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org                    const int *mvjcost, int *mvcost[2], int weight);
5293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
5393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org// Utility to compute variance + MV rate cost for a given MV
5493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_get_mvpred_var(const MACROBLOCK *x,
5593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                       const MV *best_mv, const MV *center_mv,
5693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                       const vp9_variance_fn_ptr_t *vfp,
5793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                       int use_mvcost);
5893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_get_mvpred_av_var(const MACROBLOCK *x,
5993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          const MV *best_mv, const MV *center_mv,
6093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          const uint8_t *second_pred,
6193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          const vp9_variance_fn_ptr_t *vfp,
6293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org                          int use_mvcost);
636fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
646fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.orgstruct VP9_COMP;
65810cf1767dc8df4783e02ba8a712072f50ddc99efgalligan@chromium.orgstruct SPEED_FEATURES;
66810cf1767dc8df4783e02ba8a712072f50ddc99efgalligan@chromium.org
6795aa45d73048f952dcaad0037429cc6751b34f2fjohannkoenig@google.comint vp9_init_search_range(int size);
6847265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org
6947265f8fe3a36a426773454ad90d20c9aa616c24johannkoenig@chromium.org// Runs sequence of diamond searches in smaller steps for RD
7093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgint vp9_full_pixel_diamond(const struct VP9_COMP *cpi, MACROBLOCK *x,
71dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org                           MV *mvp_full, int step_param,
726fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org                           int sadpb, int further_steps, int do_refine,
7376e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                           const vp9_variance_fn_ptr_t *fn_ptr,
7476e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                           const MV *ref_mv, MV *dst_mv);
756fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
7693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orgtypedef int (integer_mv_pattern_search_fn) (
7793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    const MACROBLOCK *x,
7893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    MV *ref_mv,
7993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    int search_param,
8093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    int error_per_bit,
8193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    int do_init_search,
82d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org    int *sad_list,
8393a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    const vp9_variance_fn_ptr_t *vf,
8493a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    int use_mvcost,
8593a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    const MV *center_mv,
8693a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org    MV *best_mv);
8793a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.org
8893a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orginteger_mv_pattern_search_fn vp9_hex_search;
8993a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orginteger_mv_pattern_search_fn vp9_bigdia_search;
9093a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orginteger_mv_pattern_search_fn vp9_square_search;
9193a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orginteger_mv_pattern_search_fn vp9_fast_hex_search;
9293a74791c8e808ea76001ee07693aa2a5fdd3500johannkoenig@chromium.orginteger_mv_pattern_search_fn vp9_fast_dia_search;
936fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
9453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.orgtypedef int (fractional_mv_step_fp) (
9576e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org    const MACROBLOCK *x,
96ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org    MV *bestmv, const MV *ref_mv,
97ecee051929d6ced19cf324688774acccc9ad4a0ajohannkoenig@chromium.org    int allow_hp,
9853a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    int error_per_bit,
9953a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    const vp9_variance_fn_ptr_t *vfp,
10053a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    int forced_stop,  // 0 - full, 1 - qtr only, 2 - half only
10153a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    int iters_per_step,
102d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org    int *sad_list,
10353a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    int *mvjcost, int *mvcost[2],
10453a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    int *distortion, unsigned int *sse1,
10553a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    const uint8_t *second_pred,
10653a13f1fa964820f7a8f9d3932a6f3c0433f8bf5fgalligan@chromium.org    int w, int h);
107dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
10895aa45d73048f952dcaad0037429cc6751b34f2fjohannkoenig@google.comextern fractional_mv_step_fp vp9_find_best_sub_pixel_tree;
109d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.orgextern fractional_mv_step_fp vp9_find_best_sub_pixel_tree_pruned;
1106fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
11176e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.orgtypedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x,
11276e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                                    const MV *ref_mv, int sad_per_bit,
11376e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                                    int distance,
11476e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                                    const vp9_variance_fn_ptr_t *fn_ptr,
115411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org                                    const MV *center_mv, MV *best_mv);
1166fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
117dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgtypedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x,
118d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                        MV *ref_mv, int sad_per_bit,
1196fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org                                        int distance,
12076e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                                        const vp9_variance_fn_ptr_t *fn_ptr,
121d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                        const MV *center_mv);
1226fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
12376e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.orgtypedef int (*vp9_diamond_search_fn_t)(const MACROBLOCK *x,
12477496404dc182c2f4a5f86ebabffe1d1ceb81e7ejohannkoenig@chromium.org                                       const search_site_config *cfg,
125d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                       MV *ref_mv, MV *best_mv,
1266fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org                                       int search_param, int sad_per_bit,
1276fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org                                       int *num00,
12876e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                                       const vp9_variance_fn_ptr_t *fn_ptr,
129d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                       const MV *center_mv);
1306fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
131dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgint vp9_refining_search_8p_c(const MACROBLOCK *x,
1328b26fe55f3e4daa2311dbd2d95e8ac2b4e080685johannkoenig@chromium.org                             MV *ref_mv, int error_per_bit,
13376e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                             int search_range,
13476e516e2154f353aa02c504bac88afb0f95fefa7johannkoenig@chromium.org                             const vp9_variance_fn_ptr_t *fn_ptr,
1357765c078fa920ba6c949c15f16b6cc979d8bb95bjohannkoenig@chromium.org                             const MV *center_mv, const uint8_t *second_pred);
13688b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org
13788b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.orgstruct VP9_COMP;
13888b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org
13988b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.orgint vp9_full_pixel_search(struct VP9_COMP *cpi, MACROBLOCK *x,
14088b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org                          BLOCK_SIZE bsize, MV *mvp_full,
14188b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org                          int step_param, int error_per_bit,
142d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org                          int *sad_list,
14388b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org                          const MV *ref_mv, MV *tmp_mv,
14488b47b29cc274dd19cddc37c1ce1834d97df282efgalligan@chromium.org                          int var_max, int rd);
145d95585fb0ec024f6abd96f7b02e0df58019d46afjohannkoenig@chromium.org
146dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
147dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org}  // extern "C"
148dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
149dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
150d348b8d765c019ee7250075d663a83db00c65c08tomfinegan@chromium.org#endif  // VP9_ENCODER_VP9_MCOMP_H_
151