• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTERP_FILTER_SEARCH_H_
13 #define AOM_AV1_ENCODER_INTERP_FILTER_SEARCH_H_
14 
15 #include "av1/encoder/block.h"
16 #include "av1/encoder/encoder.h"
17 #include "av1/encoder/rdopt_utils.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /*!\cond */
24 #define MAX_INTERP_FILTER_STATS 128
25 #define DUAL_FILTER_SET_SIZE (SWITCHABLE_FILTERS * SWITCHABLE_FILTERS)
26 
27 typedef struct {
28   int_interpfilters filters;
29   int_mv mv[2];
30   int8_t ref_frames[2];
31   COMPOUND_TYPE comp_type;
32   int compound_idx;
33   int64_t rd;
34   unsigned int pred_sse;
35 } INTERPOLATION_FILTER_STATS;
36 /*!\endcond */
37 
38 /*!\brief Miscellaneous arguments for inter mode search.
39  */
40 typedef struct HandleInterModeArgs {
41   /*!
42    * Buffer for the above predictor in OBMC
43    */
44   uint8_t *above_pred_buf[MAX_MB_PLANE];
45   /*!
46    * Stride for the above predictor in OBMC
47    */
48   int above_pred_stride[MAX_MB_PLANE];
49   /*!
50    * Buffer for the left predictor in OBMC
51    */
52   uint8_t *left_pred_buf[MAX_MB_PLANE];
53   /*!
54    * Stride for the left predictor in OBMC
55    */
56   int left_pred_stride[MAX_MB_PLANE];
57   /*!
58    * Pointer to the first member in a 2D array which holds
59    * single reference mode motion vectors to be used as a starting
60    * point in the mv search for compound modes. Each array is length REF_FRAMES,
61    * meaning there is a slot for a single reference motion vector for
62    * each possible reference frame. The 2D array consists of N of these arrays,
63    * where N is the length of the reference mv stack computed for the single
64    * reference case for that particular reference frame.
65    */
66   int_mv (*single_newmv)[REF_FRAMES];
67   /*!
68    * Pointer to the first array of a 2D array with the same setup as
69    * single_newmv array above. This is a 2D array to hold the rate
70    * corresponding to each of the single reference mode motion vectors
71    * held in single_newmv.
72    */
73   int (*single_newmv_rate)[REF_FRAMES];
74   /*!
75    * Pointer to the first array of a 2D array with the same setup as
76    * single_newmv array above. This is a 2D array to hold a 0 or 1
77    * validity value corresponding to each of the single reference mode motion
78    * vectors held in single_newmv.
79    */
80   int (*single_newmv_valid)[REF_FRAMES];
81   /*!
82    * Pointer to the first array in a 3D array of predicted rate-distortion.
83    * The dimensions of this structure are:
84    * (number of possible inter modes) X
85    * (number of reference MVs) X
86    * (number of reference frames).
87    */
88   int64_t (*modelled_rd)[MAX_REF_MV_SEARCH][REF_FRAMES];
89   /*!
90    * Holds an estimated entropy cost for picking the current reference frame.
91    * This is used to compute an rd estimate.
92    */
93   int ref_frame_cost;
94   /*!
95    * Holds an estimated entropy cost for picking single or compound
96    * reference. This is used to compute an rd estimate.
97    */
98   int single_comp_cost;
99   /*!
100    * Pointer to the first element in a 3D array holding rd's of
101    * SIMPLE_TRANSLATION used to prune out the motion mode search in single ref
102    * modes used to determine compound ref modes. The full structure is:
103    * (number of inter modes) X (length of refmv list) X (number of ref frames)
104    */
105   int64_t (*simple_rd)[MAX_REF_MV_SEARCH][REF_FRAMES];
106   /*!
107    * An integer value 0 or 1 which indicates whether or not to skip the motion
108    * mode search and default to SIMPLE_TRANSLATION as a speed feature.
109    */
110   int skip_motion_mode;
111   /*!
112    * A pointer to the first element in an array of INTERINTRA_MODE types. This
113    * contains the best inter_intra mode for each reference frame.
114    */
115   INTERINTRA_MODE *inter_intra_mode;
116   /*!
117    * Array of saved interpolation filter stats collected to avoid repeating
118    * an interpolation filter search when the mv and ref_frame are the same
119    * as a previous search.
120    */
121   INTERPOLATION_FILTER_STATS interp_filter_stats[MAX_INTERP_FILTER_STATS];
122   /*!
123    * Index of the last set of saved stats in the interp_filter_stats array.
124    */
125   int interp_filter_stats_idx;
126   /*!
127    * Estimated wedge index.
128    */
129   int wedge_index;
130   /*!
131    * Estimated wedge sign.
132    */
133   int wedge_sign;
134   /*!
135    * Estimated diff wtd index.
136    */
137   int diffwtd_index;
138   /*!
139    * Estimated cmp mode.
140    */
141   int cmp_mode[MODE_CTX_REF_FRAMES];
142   /*!
143    * The best sse during single new_mv search. Note that the sse here comes from
144    * single_motion_search, and not from interpolation_filter_search. This has
145    * two implications:
146    * 1. The mv used to calculate the sse here does not have to be the best sse
147    *    found in handle_inter_mode.
148    * 2. Even if the mvs agree, the sse here can differ from the sse in \ref
149    *    MACROBLOCK::pred_sse due to different interpolation filter used.
150    */
151   unsigned int best_single_sse_in_refs[REF_FRAMES];
152 } HandleInterModeArgs;
153 
154 /*!\cond */
155 static const int_interpfilters filter_sets[DUAL_FILTER_SET_SIZE] = {
156   { 0x00000000 }, { 0x00010000 }, { 0x00020000 },  // y = 0
157   { 0x00000001 }, { 0x00010001 }, { 0x00020001 },  // y = 1
158   { 0x00000002 }, { 0x00010002 }, { 0x00020002 },  // y = 2
159 };
160 
161 int av1_find_interp_filter_match(
162     MB_MODE_INFO *const mbmi, const AV1_COMP *const cpi,
163     const InterpFilter assign_filter, const int need_search,
164     INTERPOLATION_FILTER_STATS *interp_filter_stats,
165     int interp_filter_stats_idx);
166 
167 int64_t av1_interpolation_filter_search(
168     MACROBLOCK *const x, const AV1_COMP *const cpi,
169     const TileDataEnc *tile_data, BLOCK_SIZE bsize,
170     const BUFFER_SET *const tmp_dst, const BUFFER_SET *const orig_dst,
171     int64_t *const rd, int *const switchable_rate, int *skip_build_pred,
172     HandleInterModeArgs *args, int64_t ref_best_rd);
173 
174 /*!\endcond */
175 #ifdef __cplusplus
176 }  // extern "C"
177 #endif
178 
179 #endif  // AOM_AV1_ENCODER_INTERP_FILTER_SEARCH_H_
180