1 /*
2 * Copyright (c) 2020, 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_MOTION_SEARCH_H_
13 #define AOM_AV1_ENCODER_MOTION_SEARCH_H_
14
15 #include "av1/encoder/encoder.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 // TODO(any): rename this struct to something else. There is already another
22 // struct called inter_modes_info, which makes this terribly confusing.
23 typedef struct {
24 int drl_cost;
25 int_mv full_search_mv;
26 int full_mv_rate;
27 int full_mv_bestsme;
28 int skip;
29 } inter_mode_info;
30
31 struct HandleInterModeArgs;
32 void av1_single_motion_search(const AV1_COMP *const cpi, MACROBLOCK *x,
33 BLOCK_SIZE bsize, int ref_idx, int *rate_mv,
34 int search_range, inter_mode_info *mode_info,
35 int_mv *best_mv,
36 struct HandleInterModeArgs *const args);
37
38 int av1_joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
39 BLOCK_SIZE bsize, int_mv *cur_mv,
40 const uint8_t *mask, int mask_stride, int *rate_mv,
41 int allow_second_mv);
42
43 int av1_interinter_compound_motion_search(const AV1_COMP *const cpi,
44 MACROBLOCK *x,
45 const int_mv *const cur_mv,
46 const BLOCK_SIZE bsize,
47 const PREDICTION_MODE this_mode);
48
49 int av1_compound_single_motion_search_interinter(
50 const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int_mv *cur_mv,
51 const uint8_t *mask, int mask_stride, int *rate_mv, int ref_idx);
52
53 int av1_compound_single_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
54 BLOCK_SIZE bsize, MV *this_mv,
55 const uint8_t *second_pred,
56 const uint8_t *mask, int mask_stride,
57 int *rate_mv, int ref_idx);
58
59 // Performs a motion search in SIMPLE_TRANSLATION mode using reference frame
60 // ref. Note that this sets the offset of mbmi, so we will need to reset it
61 // after calling this function.
62 int_mv av1_simple_motion_search(struct AV1_COMP *const cpi, MACROBLOCK *x,
63 int mi_row, int mi_col, BLOCK_SIZE bsize,
64 int ref, FULLPEL_MV start_mv, int num_planes,
65 int use_subpixel);
66
67 // Performs a simple motion search to calculate the sse and var of the residue
68 int_mv av1_simple_motion_sse_var(struct AV1_COMP *cpi, MACROBLOCK *x,
69 int mi_row, int mi_col, BLOCK_SIZE bsize,
70 const FULLPEL_MV start_mv, int use_subpixel,
71 unsigned int *sse, unsigned int *var);
72
av1_get_search_site_config(const AV1_COMP * cpi,MACROBLOCK * x,SEARCH_METHODS search_method)73 static AOM_INLINE const search_site_config *av1_get_search_site_config(
74 const AV1_COMP *cpi, MACROBLOCK *x, SEARCH_METHODS search_method) {
75 const int ref_stride = x->e_mbd.plane[0].pre[0].stride;
76
77 // AV1_COMP::mv_search_params.search_site_config is a compressor level cache
78 // that's shared by multiple threads. In most cases where all frames have the
79 // same resolution, the cache contains the search site config that we need.
80 const MotionVectorSearchParams *mv_search_params = &cpi->mv_search_params;
81 if (ref_stride == mv_search_params->search_site_cfg[SS_CFG_SRC]->stride) {
82 return mv_search_params->search_site_cfg[SS_CFG_SRC];
83 } else if (ref_stride ==
84 mv_search_params->search_site_cfg[SS_CFG_LOOKAHEAD]->stride) {
85 return mv_search_params->search_site_cfg[SS_CFG_LOOKAHEAD];
86 }
87
88 // If the cache does not contain the correct stride, then we will need to rely
89 // on the thread level config MACROBLOCK::search_site_cfg_buf. If even the
90 // thread level config doesn't match, then we need to update it.
91 search_method = search_method_lookup[search_method];
92 assert(search_method_lookup[search_method] == search_method &&
93 "The search_method_lookup table should be idempotent.");
94 if (ref_stride != x->search_site_cfg_buf[search_method].stride) {
95 av1_refresh_search_site_config(x->search_site_cfg_buf, search_method,
96 ref_stride);
97 }
98
99 return x->search_site_cfg_buf;
100 }
101
102 #ifdef __cplusplus
103 } // extern "C"
104 #endif
105
106 #endif // AOM_AV1_ENCODER_MOTION_SEARCH_H_
107