xref: /aosp_15_r20/external/libaom/av1/encoder/block.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker /*! \file
13*77c1e3ccSAndroid Build Coastguard Worker  * Declares various structs used to encode the current partition block.
14*77c1e3ccSAndroid Build Coastguard Worker  */
15*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_ENCODER_BLOCK_H_
16*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_ENCODER_BLOCK_H_
17*77c1e3ccSAndroid Build Coastguard Worker 
18*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/blockd.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/entropymv.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/entropy.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/enums.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/mvref_common.h"
23*77c1e3ccSAndroid Build Coastguard Worker 
24*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/enc_enums.h"
25*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/mcomp_structs.h"
26*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
27*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/partition_cnn_weights.h"
28*77c1e3ccSAndroid Build Coastguard Worker #endif
29*77c1e3ccSAndroid Build Coastguard Worker 
30*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/hash_motion.h"
31*77c1e3ccSAndroid Build Coastguard Worker 
32*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
33*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
34*77c1e3ccSAndroid Build Coastguard Worker #endif
35*77c1e3ccSAndroid Build Coastguard Worker 
36*77c1e3ccSAndroid Build Coastguard Worker //! Minimum linear dimension of a tpl block
37*77c1e3ccSAndroid Build Coastguard Worker #define MIN_TPL_BSIZE_1D 16
38*77c1e3ccSAndroid Build Coastguard Worker //! Maximum number of tpl block in a super block
39*77c1e3ccSAndroid Build Coastguard Worker #define MAX_TPL_BLK_IN_SB (MAX_SB_SIZE / MIN_TPL_BSIZE_1D)
40*77c1e3ccSAndroid Build Coastguard Worker //! Number of txfm hash records kept for the partition block.
41*77c1e3ccSAndroid Build Coastguard Worker #define RD_RECORD_BUFFER_LEN 8
42*77c1e3ccSAndroid Build Coastguard Worker 
43*77c1e3ccSAndroid Build Coastguard Worker /*! Maximum value taken by transform type probabilities */
44*77c1e3ccSAndroid Build Coastguard Worker #define MAX_TX_TYPE_PROB 1024
45*77c1e3ccSAndroid Build Coastguard Worker 
46*77c1e3ccSAndroid Build Coastguard Worker //! Compute color sensitivity index for given plane
47*77c1e3ccSAndroid Build Coastguard Worker #define COLOR_SENS_IDX(plane) ((plane)-1)
48*77c1e3ccSAndroid Build Coastguard Worker 
49*77c1e3ccSAndroid Build Coastguard Worker //! Enable timer statistics of mode search in non-rd
50*77c1e3ccSAndroid Build Coastguard Worker #define COLLECT_NONRD_PICK_MODE_STAT 0
51*77c1e3ccSAndroid Build Coastguard Worker 
52*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
53*77c1e3ccSAndroid Build Coastguard Worker #if COLLECT_NONRD_PICK_MODE_STAT
54*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/aom_timer.h"
55*77c1e3ccSAndroid Build Coastguard Worker 
56*77c1e3ccSAndroid Build Coastguard Worker typedef struct _mode_search_stat_nonrd {
57*77c1e3ccSAndroid Build Coastguard Worker   int32_t num_blocks[BLOCK_SIZES];
58*77c1e3ccSAndroid Build Coastguard Worker   int64_t total_block_times[BLOCK_SIZES];
59*77c1e3ccSAndroid Build Coastguard Worker   int32_t num_searches[BLOCK_SIZES][MB_MODE_COUNT];
60*77c1e3ccSAndroid Build Coastguard Worker   int32_t num_nonskipped_searches[BLOCK_SIZES][MB_MODE_COUNT];
61*77c1e3ccSAndroid Build Coastguard Worker   int64_t search_times[BLOCK_SIZES][MB_MODE_COUNT];
62*77c1e3ccSAndroid Build Coastguard Worker   int64_t nonskipped_search_times[BLOCK_SIZES][MB_MODE_COUNT];
63*77c1e3ccSAndroid Build Coastguard Worker   int64_t ms_time[BLOCK_SIZES][MB_MODE_COUNT];
64*77c1e3ccSAndroid Build Coastguard Worker   int64_t ifs_time[BLOCK_SIZES][MB_MODE_COUNT];
65*77c1e3ccSAndroid Build Coastguard Worker   int64_t model_rd_time[BLOCK_SIZES][MB_MODE_COUNT];
66*77c1e3ccSAndroid Build Coastguard Worker   int64_t txfm_time[BLOCK_SIZES][MB_MODE_COUNT];
67*77c1e3ccSAndroid Build Coastguard Worker   struct aom_usec_timer timer1;
68*77c1e3ccSAndroid Build Coastguard Worker   struct aom_usec_timer timer2;
69*77c1e3ccSAndroid Build Coastguard Worker   struct aom_usec_timer bsize_timer;
70*77c1e3ccSAndroid Build Coastguard Worker } mode_search_stat_nonrd;
71*77c1e3ccSAndroid Build Coastguard Worker #endif  // COLLECT_NONRD_PICK_MODE_STAT
72*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
73*77c1e3ccSAndroid Build Coastguard Worker 
74*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Superblock level encoder info
75*77c1e3ccSAndroid Build Coastguard Worker  *
76*77c1e3ccSAndroid Build Coastguard Worker  * SuperblockEnc stores superblock level information used by the encoder for
77*77c1e3ccSAndroid Build Coastguard Worker  * more efficient encoding. Currently this is mostly used to store TPL data
78*77c1e3ccSAndroid Build Coastguard Worker  * for the current superblock.
79*77c1e3ccSAndroid Build Coastguard Worker  */
80*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
81*77c1e3ccSAndroid Build Coastguard Worker   //! Maximum partition size for the sb.
82*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_SIZE min_partition_size;
83*77c1e3ccSAndroid Build Coastguard Worker   //! Minimum partition size for the sb.
84*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_SIZE max_partition_size;
85*77c1e3ccSAndroid Build Coastguard Worker 
86*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
87*77c1e3ccSAndroid Build Coastguard Worker    * \name TPL Info
88*77c1e3ccSAndroid Build Coastguard Worker    *
89*77c1e3ccSAndroid Build Coastguard Worker    * Information gathered from tpl_model at tpl block precision for the
90*77c1e3ccSAndroid Build Coastguard Worker    * superblock to speed up the encoding process..
91*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
92*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
93*77c1e3ccSAndroid Build Coastguard Worker   //! Number of TPL blocks in this superblock.
94*77c1e3ccSAndroid Build Coastguard Worker   int tpl_data_count;
95*77c1e3ccSAndroid Build Coastguard Worker   //! TPL's estimate of inter cost for each tpl block.
96*77c1e3ccSAndroid Build Coastguard Worker   int64_t tpl_inter_cost[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
97*77c1e3ccSAndroid Build Coastguard Worker   //! TPL's estimate of tpl cost for each tpl block.
98*77c1e3ccSAndroid Build Coastguard Worker   int64_t tpl_intra_cost[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
99*77c1e3ccSAndroid Build Coastguard Worker   //! Motion vectors found by TPL model for each tpl block.
100*77c1e3ccSAndroid Build Coastguard Worker   int_mv tpl_mv[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB][INTER_REFS_PER_FRAME];
101*77c1e3ccSAndroid Build Coastguard Worker   //! TPL's stride for the arrays in this struct.
102*77c1e3ccSAndroid Build Coastguard Worker   int tpl_stride;
103*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
104*77c1e3ccSAndroid Build Coastguard Worker } SuperBlockEnc;
105*77c1e3ccSAndroid Build Coastguard Worker 
106*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Stores the best performing modes.
107*77c1e3ccSAndroid Build Coastguard Worker  */
108*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
109*77c1e3ccSAndroid Build Coastguard Worker   //! The mbmi used to reconstruct the winner mode.
110*77c1e3ccSAndroid Build Coastguard Worker   MB_MODE_INFO mbmi;
111*77c1e3ccSAndroid Build Coastguard Worker   //! Rdstats of the winner mode.
112*77c1e3ccSAndroid Build Coastguard Worker   RD_STATS rd_cost;
113*77c1e3ccSAndroid Build Coastguard Worker   //! Rdcost of the winner mode
114*77c1e3ccSAndroid Build Coastguard Worker   int64_t rd;
115*77c1e3ccSAndroid Build Coastguard Worker   //! Luma rate of the winner mode.
116*77c1e3ccSAndroid Build Coastguard Worker   int rate_y;
117*77c1e3ccSAndroid Build Coastguard Worker   //! Chroma rate of the winner mode.
118*77c1e3ccSAndroid Build Coastguard Worker   int rate_uv;
119*77c1e3ccSAndroid Build Coastguard Worker   //! The color map needed to reconstruct palette mode.
120*77c1e3ccSAndroid Build Coastguard Worker   uint8_t color_index_map[MAX_SB_SQUARE];
121*77c1e3ccSAndroid Build Coastguard Worker   //! The current winner mode.
122*77c1e3ccSAndroid Build Coastguard Worker   THR_MODES mode_index;
123*77c1e3ccSAndroid Build Coastguard Worker } WinnerModeStats;
124*77c1e3ccSAndroid Build Coastguard Worker 
125*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Each source plane of the current macroblock
126*77c1e3ccSAndroid Build Coastguard Worker  *
127*77c1e3ccSAndroid Build Coastguard Worker  * This struct also stores the txfm buffers and quantizer settings.
128*77c1e3ccSAndroid Build Coastguard Worker  */
129*77c1e3ccSAndroid Build Coastguard Worker typedef struct macroblock_plane {
130*77c1e3ccSAndroid Build Coastguard Worker   //! Stores source - pred so the txfm can be computed later
131*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_diff;
132*77c1e3ccSAndroid Build Coastguard Worker   //! Dequantized coefficients
133*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *dqcoeff;
134*77c1e3ccSAndroid Build Coastguard Worker   //! Quantized coefficients
135*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *qcoeff;
136*77c1e3ccSAndroid Build Coastguard Worker   //! Transformed coefficients
137*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *coeff;
138*77c1e3ccSAndroid Build Coastguard Worker   //! Location of the end of qcoeff (end of block).
139*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *eobs;
140*77c1e3ccSAndroid Build Coastguard Worker   //! Contexts used to code the transform coefficients.
141*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *txb_entropy_ctx;
142*77c1e3ccSAndroid Build Coastguard Worker   //! A buffer containing the source frame.
143*77c1e3ccSAndroid Build Coastguard Worker   struct buf_2d src;
144*77c1e3ccSAndroid Build Coastguard Worker 
145*77c1e3ccSAndroid Build Coastguard Worker   /*! \name Quantizer Settings
146*77c1e3ccSAndroid Build Coastguard Worker    *
147*77c1e3ccSAndroid Build Coastguard Worker    * \attention These are used/accessed only in the quantization process.
148*77c1e3ccSAndroid Build Coastguard Worker    * RDO does not and *must not* depend on any of these values.
149*77c1e3ccSAndroid Build Coastguard Worker    * All values below share the coefficient scale/shift used in TX.
150*77c1e3ccSAndroid Build Coastguard Worker    */
151*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
152*77c1e3ccSAndroid Build Coastguard Worker   //! Quantization step size used by AV1_XFORM_QUANT_FP.
153*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *quant_fp_QTX;
154*77c1e3ccSAndroid Build Coastguard Worker   //! Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_FP.
155*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *round_fp_QTX;
156*77c1e3ccSAndroid Build Coastguard Worker   //! Quantization step size used by AV1_XFORM_QUANT_B.
157*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *quant_QTX;
158*77c1e3ccSAndroid Build Coastguard Worker   //! Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_B.
159*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *round_QTX;
160*77c1e3ccSAndroid Build Coastguard Worker   //! Scale factor to shift coefficients toward zero. Only used by QUANT_B.
161*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *quant_shift_QTX;
162*77c1e3ccSAndroid Build Coastguard Worker   //! Size of the quantization bin around 0. Only Used by QUANT_B
163*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *zbin_QTX;
164*77c1e3ccSAndroid Build Coastguard Worker   //! Dequantizer
165*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *dequant_QTX;
166*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
167*77c1e3ccSAndroid Build Coastguard Worker } MACROBLOCK_PLANE;
168*77c1e3ccSAndroid Build Coastguard Worker 
169*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Costs for encoding the coefficients within a level.
170*77c1e3ccSAndroid Build Coastguard Worker  *
171*77c1e3ccSAndroid Build Coastguard Worker  * Covers everything including txb_skip, eob, dc_sign,
172*77c1e3ccSAndroid Build Coastguard Worker  */
173*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
174*77c1e3ccSAndroid Build Coastguard Worker   //! Cost to skip txfm for the current txfm block.
175*77c1e3ccSAndroid Build Coastguard Worker   int txb_skip_cost[TXB_SKIP_CONTEXTS][2];
176*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Cost for encoding the base_eob of a level.
177*77c1e3ccSAndroid Build Coastguard Worker    *
178*77c1e3ccSAndroid Build Coastguard Worker    * Decoder uses base_eob to derive the base_level as base_eob := base_eob+1.
179*77c1e3ccSAndroid Build Coastguard Worker    */
180*77c1e3ccSAndroid Build Coastguard Worker   int base_eob_cost[SIG_COEF_CONTEXTS_EOB][3];
181*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Cost for encoding the base level of a coefficient.
182*77c1e3ccSAndroid Build Coastguard Worker    *
183*77c1e3ccSAndroid Build Coastguard Worker    * Decoder derives coeff_base as coeff_base := base_eob + 1.
184*77c1e3ccSAndroid Build Coastguard Worker    */
185*77c1e3ccSAndroid Build Coastguard Worker   int base_cost[SIG_COEF_CONTEXTS][8];
186*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Cost for encoding the last non-zero coefficient.
187*77c1e3ccSAndroid Build Coastguard Worker    *
188*77c1e3ccSAndroid Build Coastguard Worker    * Eob is derived from eob_extra at the decoder as eob := eob_extra + 1
189*77c1e3ccSAndroid Build Coastguard Worker    */
190*77c1e3ccSAndroid Build Coastguard Worker   int eob_extra_cost[EOB_COEF_CONTEXTS][2];
191*77c1e3ccSAndroid Build Coastguard Worker   //! Cost for encoding the dc_sign
192*77c1e3ccSAndroid Build Coastguard Worker   int dc_sign_cost[DC_SIGN_CONTEXTS][2];
193*77c1e3ccSAndroid Build Coastguard Worker   //! Cost for encoding an increment to the coefficient
194*77c1e3ccSAndroid Build Coastguard Worker   int lps_cost[LEVEL_CONTEXTS][COEFF_BASE_RANGE + 1 + COEFF_BASE_RANGE + 1];
195*77c1e3ccSAndroid Build Coastguard Worker } LV_MAP_COEFF_COST;
196*77c1e3ccSAndroid Build Coastguard Worker 
197*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Costs for encoding the eob.
198*77c1e3ccSAndroid Build Coastguard Worker  */
199*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
200*77c1e3ccSAndroid Build Coastguard Worker   //! eob_cost.
201*77c1e3ccSAndroid Build Coastguard Worker   int eob_cost[2][11];
202*77c1e3ccSAndroid Build Coastguard Worker } LV_MAP_EOB_COST;
203*77c1e3ccSAndroid Build Coastguard Worker 
204*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Stores the transforms coefficients for the whole superblock.
205*77c1e3ccSAndroid Build Coastguard Worker  */
206*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
207*77c1e3ccSAndroid Build Coastguard Worker   //! The transformed coefficients.
208*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *tcoeff[MAX_MB_PLANE];
209*77c1e3ccSAndroid Build Coastguard Worker   //! Where the transformed coefficients end.
210*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *eobs[MAX_MB_PLANE];
211*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Transform block entropy contexts.
212*77c1e3ccSAndroid Build Coastguard Worker    *
213*77c1e3ccSAndroid Build Coastguard Worker    * Each element is used as a bit field.
214*77c1e3ccSAndroid Build Coastguard Worker    * - Bits 0~3: txb_skip_ctx
215*77c1e3ccSAndroid Build Coastguard Worker    * - Bits 4~5: dc_sign_ctx.
216*77c1e3ccSAndroid Build Coastguard Worker    */
217*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *entropy_ctx[MAX_MB_PLANE];
218*77c1e3ccSAndroid Build Coastguard Worker } CB_COEFF_BUFFER;
219*77c1e3ccSAndroid Build Coastguard Worker 
220*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Extended mode info derived from mbmi.
221*77c1e3ccSAndroid Build Coastguard Worker  */
222*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
223*77c1e3ccSAndroid Build Coastguard Worker   // TODO(angiebird): Reduce the buffer size according to sb_type
224*77c1e3ccSAndroid Build Coastguard Worker   //! The reference mv list for the current block.
225*77c1e3ccSAndroid Build Coastguard Worker   CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE];
226*77c1e3ccSAndroid Build Coastguard Worker   //! The weights used to compute the ref mvs.
227*77c1e3ccSAndroid Build Coastguard Worker   uint16_t weight[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE];
228*77c1e3ccSAndroid Build Coastguard Worker   //! Number of ref mvs in the drl.
229*77c1e3ccSAndroid Build Coastguard Worker   uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
230*77c1e3ccSAndroid Build Coastguard Worker   //! Global mvs
231*77c1e3ccSAndroid Build Coastguard Worker   int_mv global_mvs[REF_FRAMES];
232*77c1e3ccSAndroid Build Coastguard Worker   //! Context used to encode the current mode.
233*77c1e3ccSAndroid Build Coastguard Worker   int16_t mode_context[MODE_CTX_REF_FRAMES];
234*77c1e3ccSAndroid Build Coastguard Worker } MB_MODE_INFO_EXT;
235*77c1e3ccSAndroid Build Coastguard Worker 
236*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Stores best extended mode information at frame level.
237*77c1e3ccSAndroid Build Coastguard Worker  *
238*77c1e3ccSAndroid Build Coastguard Worker  * The frame level in here is used in bitstream preparation stage. The
239*77c1e3ccSAndroid Build Coastguard Worker  * information in \ref MB_MODE_INFO_EXT are copied to this struct to save
240*77c1e3ccSAndroid Build Coastguard Worker  * memory.
241*77c1e3ccSAndroid Build Coastguard Worker  */
242*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
243*77c1e3ccSAndroid Build Coastguard Worker   //! \copydoc MB_MODE_INFO_EXT::ref_mv_stack
244*77c1e3ccSAndroid Build Coastguard Worker   CANDIDATE_MV ref_mv_stack[USABLE_REF_MV_STACK_SIZE];
245*77c1e3ccSAndroid Build Coastguard Worker   //! \copydoc MB_MODE_INFO_EXT::weight
246*77c1e3ccSAndroid Build Coastguard Worker   uint16_t weight[USABLE_REF_MV_STACK_SIZE];
247*77c1e3ccSAndroid Build Coastguard Worker   //! \copydoc MB_MODE_INFO_EXT::ref_mv_count
248*77c1e3ccSAndroid Build Coastguard Worker   uint8_t ref_mv_count;
249*77c1e3ccSAndroid Build Coastguard Worker   // TODO(Ravi/Remya): Reduce the buffer size of global_mvs
250*77c1e3ccSAndroid Build Coastguard Worker   //! \copydoc MB_MODE_INFO_EXT::global_mvs
251*77c1e3ccSAndroid Build Coastguard Worker   int_mv global_mvs[REF_FRAMES];
252*77c1e3ccSAndroid Build Coastguard Worker   //! \copydoc MB_MODE_INFO_EXT::mode_context
253*77c1e3ccSAndroid Build Coastguard Worker   int16_t mode_context;
254*77c1e3ccSAndroid Build Coastguard Worker   //! Offset of current coding block's coeff buffer relative to the sb.
255*77c1e3ccSAndroid Build Coastguard Worker   uint16_t cb_offset[PLANE_TYPES];
256*77c1e3ccSAndroid Build Coastguard Worker } MB_MODE_INFO_EXT_FRAME;
257*77c1e3ccSAndroid Build Coastguard Worker 
258*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Inter-mode txfm results for a partition block.
259*77c1e3ccSAndroid Build Coastguard Worker  */
260*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
261*77c1e3ccSAndroid Build Coastguard Worker   //! Txfm size used if the current mode is intra mode.
262*77c1e3ccSAndroid Build Coastguard Worker   TX_SIZE tx_size;
263*77c1e3ccSAndroid Build Coastguard Worker   //! Txfm sizes used if the current mode is inter mode.
264*77c1e3ccSAndroid Build Coastguard Worker   TX_SIZE inter_tx_size[INTER_TX_SIZE_BUF_LEN];
265*77c1e3ccSAndroid Build Coastguard Worker   //! Map showing which txfm block skips the txfm process.
266*77c1e3ccSAndroid Build Coastguard Worker   uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
267*77c1e3ccSAndroid Build Coastguard Worker   //! Map showing the txfm types for each block.
268*77c1e3ccSAndroid Build Coastguard Worker   uint8_t tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE];
269*77c1e3ccSAndroid Build Coastguard Worker   //! Rd_stats for the whole partition block.
270*77c1e3ccSAndroid Build Coastguard Worker   RD_STATS rd_stats;
271*77c1e3ccSAndroid Build Coastguard Worker   //! Hash value of the current record.
272*77c1e3ccSAndroid Build Coastguard Worker   uint32_t hash_value;
273*77c1e3ccSAndroid Build Coastguard Worker } MB_RD_INFO;
274*77c1e3ccSAndroid Build Coastguard Worker 
275*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Hash records of the inter-mode transform results
276*77c1e3ccSAndroid Build Coastguard Worker  *
277*77c1e3ccSAndroid Build Coastguard Worker  * Hash records of the inter-mode transform results for a whole partition block
278*77c1e3ccSAndroid Build Coastguard Worker  * based on the residue. Since this operates on the partition block level, this
279*77c1e3ccSAndroid Build Coastguard Worker  * can give us a whole txfm partition tree.
280*77c1e3ccSAndroid Build Coastguard Worker  */
281*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
282*77c1e3ccSAndroid Build Coastguard Worker   /*! Circular buffer that stores the inter-mode txfm results of a partition
283*77c1e3ccSAndroid Build Coastguard Worker    *  block.
284*77c1e3ccSAndroid Build Coastguard Worker    */
285*77c1e3ccSAndroid Build Coastguard Worker   MB_RD_INFO mb_rd_info[RD_RECORD_BUFFER_LEN];
286*77c1e3ccSAndroid Build Coastguard Worker   //! Index to insert the newest rd record.
287*77c1e3ccSAndroid Build Coastguard Worker   int index_start;
288*77c1e3ccSAndroid Build Coastguard Worker   //! Number of info stored in this record.
289*77c1e3ccSAndroid Build Coastguard Worker   int num;
290*77c1e3ccSAndroid Build Coastguard Worker   //! Hash function
291*77c1e3ccSAndroid Build Coastguard Worker   CRC32C crc_calculator;
292*77c1e3ccSAndroid Build Coastguard Worker } MB_RD_RECORD;
293*77c1e3ccSAndroid Build Coastguard Worker 
294*77c1e3ccSAndroid Build Coastguard Worker //! Number of compound rd stats
295*77c1e3ccSAndroid Build Coastguard Worker #define MAX_COMP_RD_STATS 64
296*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Rdcost stats in compound mode.
297*77c1e3ccSAndroid Build Coastguard Worker  */
298*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
299*77c1e3ccSAndroid Build Coastguard Worker   //! Rate of the compound modes.
300*77c1e3ccSAndroid Build Coastguard Worker   int32_t rate[COMPOUND_TYPES];
301*77c1e3ccSAndroid Build Coastguard Worker   //! Distortion of the compound modes.
302*77c1e3ccSAndroid Build Coastguard Worker   int64_t dist[COMPOUND_TYPES];
303*77c1e3ccSAndroid Build Coastguard Worker   //! Estimated rate of the compound modes.
304*77c1e3ccSAndroid Build Coastguard Worker   int32_t model_rate[COMPOUND_TYPES];
305*77c1e3ccSAndroid Build Coastguard Worker   //! Estimated distortion of the compound modes.
306*77c1e3ccSAndroid Build Coastguard Worker   int64_t model_dist[COMPOUND_TYPES];
307*77c1e3ccSAndroid Build Coastguard Worker   //! Rate need to send the mask type.
308*77c1e3ccSAndroid Build Coastguard Worker   int comp_rs2[COMPOUND_TYPES];
309*77c1e3ccSAndroid Build Coastguard Worker   //! Motion vector for each predictor.
310*77c1e3ccSAndroid Build Coastguard Worker   int_mv mv[2];
311*77c1e3ccSAndroid Build Coastguard Worker   //! Ref frame for each predictor.
312*77c1e3ccSAndroid Build Coastguard Worker   MV_REFERENCE_FRAME ref_frames[2];
313*77c1e3ccSAndroid Build Coastguard Worker   //! Current prediction mode.
314*77c1e3ccSAndroid Build Coastguard Worker   PREDICTION_MODE mode;
315*77c1e3ccSAndroid Build Coastguard Worker   //! Current interpolation filter.
316*77c1e3ccSAndroid Build Coastguard Worker   int_interpfilters filter;
317*77c1e3ccSAndroid Build Coastguard Worker   //! Refmv index in the drl.
318*77c1e3ccSAndroid Build Coastguard Worker   int ref_mv_idx;
319*77c1e3ccSAndroid Build Coastguard Worker   //! Whether the predictors are GLOBALMV.
320*77c1e3ccSAndroid Build Coastguard Worker   int is_global[2];
321*77c1e3ccSAndroid Build Coastguard Worker   //! Current parameters for interinter mode.
322*77c1e3ccSAndroid Build Coastguard Worker   INTERINTER_COMPOUND_DATA interinter_comp;
323*77c1e3ccSAndroid Build Coastguard Worker } COMP_RD_STATS;
324*77c1e3ccSAndroid Build Coastguard Worker 
325*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Contains buffers used to speed up rdopt for obmc.
326*77c1e3ccSAndroid Build Coastguard Worker  *
327*77c1e3ccSAndroid Build Coastguard Worker  * See the comments for calc_target_weighted_pred for details.
328*77c1e3ccSAndroid Build Coastguard Worker  */
329*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
330*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief A new source weighted with the above and left predictors.
331*77c1e3ccSAndroid Build Coastguard Worker    *
332*77c1e3ccSAndroid Build Coastguard Worker    * Used to efficiently construct multiple obmc predictors during rdopt.
333*77c1e3ccSAndroid Build Coastguard Worker    */
334*77c1e3ccSAndroid Build Coastguard Worker   int32_t *wsrc;
335*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief A new mask constructed from the original horz/vert mask.
336*77c1e3ccSAndroid Build Coastguard Worker    *
337*77c1e3ccSAndroid Build Coastguard Worker    * \copydetails wsrc
338*77c1e3ccSAndroid Build Coastguard Worker    */
339*77c1e3ccSAndroid Build Coastguard Worker   int32_t *mask;
340*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Prediction from the up predictor.
341*77c1e3ccSAndroid Build Coastguard Worker    *
342*77c1e3ccSAndroid Build Coastguard Worker    * Used to build the obmc predictor.
343*77c1e3ccSAndroid Build Coastguard Worker    */
344*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *above_pred;
345*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Prediction from the up predictor.
346*77c1e3ccSAndroid Build Coastguard Worker    *
347*77c1e3ccSAndroid Build Coastguard Worker    * \copydetails above_pred
348*77c1e3ccSAndroid Build Coastguard Worker    */
349*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *left_pred;
350*77c1e3ccSAndroid Build Coastguard Worker } OBMCBuffer;
351*77c1e3ccSAndroid Build Coastguard Worker 
352*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Contains color maps used in palette mode.
353*77c1e3ccSAndroid Build Coastguard Worker  */
354*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
355*77c1e3ccSAndroid Build Coastguard Worker   //! The best color map found.
356*77c1e3ccSAndroid Build Coastguard Worker   uint8_t best_palette_color_map[MAX_PALETTE_SQUARE];
357*77c1e3ccSAndroid Build Coastguard Worker   //! A temporary buffer used for k-means clustering.
358*77c1e3ccSAndroid Build Coastguard Worker   int16_t kmeans_data_buf[2 * MAX_PALETTE_SQUARE];
359*77c1e3ccSAndroid Build Coastguard Worker } PALETTE_BUFFER;
360*77c1e3ccSAndroid Build Coastguard Worker 
361*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Contains buffers used by av1_compound_type_rd()
362*77c1e3ccSAndroid Build Coastguard Worker  *
363*77c1e3ccSAndroid Build Coastguard Worker  * For sizes and alignment of these arrays, refer to
364*77c1e3ccSAndroid Build Coastguard Worker  * alloc_compound_type_rd_buffers() function.
365*77c1e3ccSAndroid Build Coastguard Worker  */
366*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
367*77c1e3ccSAndroid Build Coastguard Worker   //! First prediction.
368*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *pred0;
369*77c1e3ccSAndroid Build Coastguard Worker   //! Second prediction.
370*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *pred1;
371*77c1e3ccSAndroid Build Coastguard Worker   //! Source - first prediction.
372*77c1e3ccSAndroid Build Coastguard Worker   int16_t *residual1;
373*77c1e3ccSAndroid Build Coastguard Worker   //! Second prediction - first prediction.
374*77c1e3ccSAndroid Build Coastguard Worker   int16_t *diff10;
375*77c1e3ccSAndroid Build Coastguard Worker   //! Backup of the best segmentation mask.
376*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *tmp_best_mask_buf;
377*77c1e3ccSAndroid Build Coastguard Worker } CompoundTypeRdBuffers;
378*77c1e3ccSAndroid Build Coastguard Worker 
379*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Holds some parameters related to partitioning schemes in AV1.
380*77c1e3ccSAndroid Build Coastguard Worker  */
381*77c1e3ccSAndroid Build Coastguard Worker // TODO([email protected]): Consolidate this with SIMPLE_MOTION_DATA_TREE
382*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
383*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
384*77c1e3ccSAndroid Build Coastguard Worker   // The following 4 parameters are used for cnn-based partitioning on intra
385*77c1e3ccSAndroid Build Coastguard Worker   // frame.
386*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Current index on the partition block quad tree.
387*77c1e3ccSAndroid Build Coastguard Worker    *
388*77c1e3ccSAndroid Build Coastguard Worker    * Used to index into the cnn buffer for partition decision.
389*77c1e3ccSAndroid Build Coastguard Worker    */
390*77c1e3ccSAndroid Build Coastguard Worker   int quad_tree_idx;
391*77c1e3ccSAndroid Build Coastguard Worker   //! Whether the CNN buffer contains valid output.
392*77c1e3ccSAndroid Build Coastguard Worker   int cnn_output_valid;
393*77c1e3ccSAndroid Build Coastguard Worker   //! A buffer used by our segmentation CNN for intra-frame partitioning.
394*77c1e3ccSAndroid Build Coastguard Worker   float cnn_buffer[CNN_OUT_BUF_SIZE];
395*77c1e3ccSAndroid Build Coastguard Worker   //! log of the quantization parameter of the ancestor BLOCK_64X64.
396*77c1e3ccSAndroid Build Coastguard Worker   float log_q;
397*77c1e3ccSAndroid Build Coastguard Worker #endif
398*77c1e3ccSAndroid Build Coastguard Worker 
399*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Variance of the subblocks in the superblock.
400*77c1e3ccSAndroid Build Coastguard Worker    *
401*77c1e3ccSAndroid Build Coastguard Worker    * This is used by rt mode for variance based partitioning.
402*77c1e3ccSAndroid Build Coastguard Worker    * The indices corresponds to the following block sizes:
403*77c1e3ccSAndroid Build Coastguard Worker    * -   0    - 128x128
404*77c1e3ccSAndroid Build Coastguard Worker    * -  1-2   - 128x64
405*77c1e3ccSAndroid Build Coastguard Worker    * -  3-4   -  64x128
406*77c1e3ccSAndroid Build Coastguard Worker    * -  5-8   -  64x64
407*77c1e3ccSAndroid Build Coastguard Worker    * -  9-16  -  64x32
408*77c1e3ccSAndroid Build Coastguard Worker    * - 17-24  -  32x64
409*77c1e3ccSAndroid Build Coastguard Worker    * - 25-40  -  32x32
410*77c1e3ccSAndroid Build Coastguard Worker    * - 41-104 -  16x16
411*77c1e3ccSAndroid Build Coastguard Worker    */
412*77c1e3ccSAndroid Build Coastguard Worker   uint8_t variance_low[105];
413*77c1e3ccSAndroid Build Coastguard Worker } PartitionSearchInfo;
414*77c1e3ccSAndroid Build Coastguard Worker 
415*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
416*77c1e3ccSAndroid Build Coastguard Worker enum {
417*77c1e3ccSAndroid Build Coastguard Worker   /**
418*77c1e3ccSAndroid Build Coastguard Worker    * Do not prune transform depths.
419*77c1e3ccSAndroid Build Coastguard Worker    */
420*77c1e3ccSAndroid Build Coastguard Worker   TX_PRUNE_NONE = 0,
421*77c1e3ccSAndroid Build Coastguard Worker   /**
422*77c1e3ccSAndroid Build Coastguard Worker    * Prune largest transform (depth 0) based on NN model.
423*77c1e3ccSAndroid Build Coastguard Worker    */
424*77c1e3ccSAndroid Build Coastguard Worker   TX_PRUNE_LARGEST = 1,
425*77c1e3ccSAndroid Build Coastguard Worker   /**
426*77c1e3ccSAndroid Build Coastguard Worker    * Prune split transforms (depth>=1) based on NN model.
427*77c1e3ccSAndroid Build Coastguard Worker    */
428*77c1e3ccSAndroid Build Coastguard Worker   TX_PRUNE_SPLIT = 2,
429*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(TX_PRUNE_TYPE);
430*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
431*77c1e3ccSAndroid Build Coastguard Worker 
432*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Defines the parameters used to perform txfm search.
433*77c1e3ccSAndroid Build Coastguard Worker  *
434*77c1e3ccSAndroid Build Coastguard Worker  * For the most part, this determines how various speed features are used.
435*77c1e3ccSAndroid Build Coastguard Worker  */
436*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
437*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Whether to limit the intra txfm search type to the default txfm.
438*77c1e3ccSAndroid Build Coastguard Worker    *
439*77c1e3ccSAndroid Build Coastguard Worker    * This could either be a result of either sequence parameter or speed
440*77c1e3ccSAndroid Build Coastguard Worker    * features.
441*77c1e3ccSAndroid Build Coastguard Worker    */
442*77c1e3ccSAndroid Build Coastguard Worker   int use_default_intra_tx_type;
443*77c1e3ccSAndroid Build Coastguard Worker 
444*77c1e3ccSAndroid Build Coastguard Worker   /*! Probability threshold used for conditionally forcing tx type*/
445*77c1e3ccSAndroid Build Coastguard Worker   int default_inter_tx_type_prob_thresh;
446*77c1e3ccSAndroid Build Coastguard Worker 
447*77c1e3ccSAndroid Build Coastguard Worker   //! Whether to prune 2d transforms based on 1d transform results.
448*77c1e3ccSAndroid Build Coastguard Worker   int prune_2d_txfm_mode;
449*77c1e3ccSAndroid Build Coastguard Worker 
450*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Variable from \ref WinnerModeParams based on current eval mode.
451*77c1e3ccSAndroid Build Coastguard Worker    *
452*77c1e3ccSAndroid Build Coastguard Worker    * See the documentation for \ref WinnerModeParams for more detail.
453*77c1e3ccSAndroid Build Coastguard Worker    */
454*77c1e3ccSAndroid Build Coastguard Worker   unsigned int coeff_opt_thresholds[2];
455*77c1e3ccSAndroid Build Coastguard Worker   /*! \copydoc coeff_opt_thresholds */
456*77c1e3ccSAndroid Build Coastguard Worker   unsigned int tx_domain_dist_threshold;
457*77c1e3ccSAndroid Build Coastguard Worker   /*! \copydoc coeff_opt_thresholds */
458*77c1e3ccSAndroid Build Coastguard Worker   TX_SIZE_SEARCH_METHOD tx_size_search_method;
459*77c1e3ccSAndroid Build Coastguard Worker   /*! \copydoc coeff_opt_thresholds */
460*77c1e3ccSAndroid Build Coastguard Worker   unsigned int use_transform_domain_distortion;
461*77c1e3ccSAndroid Build Coastguard Worker   /*! \copydoc coeff_opt_thresholds */
462*77c1e3ccSAndroid Build Coastguard Worker   unsigned int skip_txfm_level;
463*77c1e3ccSAndroid Build Coastguard Worker 
464*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief How to search for the optimal tx_size
465*77c1e3ccSAndroid Build Coastguard Worker    *
466*77c1e3ccSAndroid Build Coastguard Worker    * If ONLY_4X4, use TX_4X4; if TX_MODE_LARGEST, use the largest tx_size for
467*77c1e3ccSAndroid Build Coastguard Worker    * the current partition block; if TX_MODE_SELECT, search through the whole
468*77c1e3ccSAndroid Build Coastguard Worker    * tree.
469*77c1e3ccSAndroid Build Coastguard Worker    *
470*77c1e3ccSAndroid Build Coastguard Worker    * \attention
471*77c1e3ccSAndroid Build Coastguard Worker    * Although this looks suspicious similar to a bitstream element, this
472*77c1e3ccSAndroid Build Coastguard Worker    * tx_mode_search_type is only used internally by the encoder, and is *not*
473*77c1e3ccSAndroid Build Coastguard Worker    * written to the bitstream. It determines what kind of tx_mode would be
474*77c1e3ccSAndroid Build Coastguard Worker    * searched. For example, we might set it to TX_MODE_LARGEST to find a good
475*77c1e3ccSAndroid Build Coastguard Worker    * candidate, then code it as TX_MODE_SELECT.
476*77c1e3ccSAndroid Build Coastguard Worker    */
477*77c1e3ccSAndroid Build Coastguard Worker   TX_MODE tx_mode_search_type;
478*77c1e3ccSAndroid Build Coastguard Worker 
479*77c1e3ccSAndroid Build Coastguard Worker   /*!
480*77c1e3ccSAndroid Build Coastguard Worker    * Determines whether a block can be predicted as transform skip or DC only
481*77c1e3ccSAndroid Build Coastguard Worker    * based on residual mean and variance.
482*77c1e3ccSAndroid Build Coastguard Worker    * Type 0 : No skip block or DC only block prediction
483*77c1e3ccSAndroid Build Coastguard Worker    * Type 1 : Prediction of skip block based on residual mean and variance
484*77c1e3ccSAndroid Build Coastguard Worker    * Type 2 : Prediction of skip block or DC only block based on residual mean
485*77c1e3ccSAndroid Build Coastguard Worker    * and variance
486*77c1e3ccSAndroid Build Coastguard Worker    */
487*77c1e3ccSAndroid Build Coastguard Worker   unsigned int predict_dc_level;
488*77c1e3ccSAndroid Build Coastguard Worker 
489*77c1e3ccSAndroid Build Coastguard Worker   /*!
490*77c1e3ccSAndroid Build Coastguard Worker    * Whether or not we should use the quantization matrix as weights for PSNR
491*77c1e3ccSAndroid Build Coastguard Worker    * during RD search.
492*77c1e3ccSAndroid Build Coastguard Worker    */
493*77c1e3ccSAndroid Build Coastguard Worker   int use_qm_dist_metric;
494*77c1e3ccSAndroid Build Coastguard Worker 
495*77c1e3ccSAndroid Build Coastguard Worker   /*!
496*77c1e3ccSAndroid Build Coastguard Worker    * Keep track of previous mode evaluation stage type. This will be used to
497*77c1e3ccSAndroid Build Coastguard Worker    * reset mb rd hash record when mode evaluation type changes.
498*77c1e3ccSAndroid Build Coastguard Worker    */
499*77c1e3ccSAndroid Build Coastguard Worker   int mode_eval_type;
500*77c1e3ccSAndroid Build Coastguard Worker 
501*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
502*77c1e3ccSAndroid Build Coastguard Worker   //! Indicates the transform depths for which RD evaluation is skipped.
503*77c1e3ccSAndroid Build Coastguard Worker   TX_PRUNE_TYPE nn_prune_depths_for_intra_tx;
504*77c1e3ccSAndroid Build Coastguard Worker 
505*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Indicates if NN model should be invoked to prune transform depths.
506*77c1e3ccSAndroid Build Coastguard Worker    *
507*77c1e3ccSAndroid Build Coastguard Worker    * Used to signal whether NN model should be evaluated to prune the R-D
508*77c1e3ccSAndroid Build Coastguard Worker    * evaluation of specific transform depths.
509*77c1e3ccSAndroid Build Coastguard Worker    */
510*77c1e3ccSAndroid Build Coastguard Worker   bool enable_nn_prune_intra_tx_depths;
511*77c1e3ccSAndroid Build Coastguard Worker #endif
512*77c1e3ccSAndroid Build Coastguard Worker } TxfmSearchParams;
513*77c1e3ccSAndroid Build Coastguard Worker 
514*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
515*77c1e3ccSAndroid Build Coastguard Worker #define MAX_NUM_8X8_TXBS ((MAX_MIB_SIZE >> 1) * (MAX_MIB_SIZE >> 1))
516*77c1e3ccSAndroid Build Coastguard Worker #define MAX_NUM_16X16_TXBS ((MAX_MIB_SIZE >> 2) * (MAX_MIB_SIZE >> 2))
517*77c1e3ccSAndroid Build Coastguard Worker #define MAX_NUM_32X32_TXBS ((MAX_MIB_SIZE >> 3) * (MAX_MIB_SIZE >> 3))
518*77c1e3ccSAndroid Build Coastguard Worker #define MAX_NUM_64X64_TXBS ((MAX_MIB_SIZE >> 4) * (MAX_MIB_SIZE >> 4))
519*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
520*77c1e3ccSAndroid Build Coastguard Worker 
521*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Stores various encoding/search decisions related to txfm search.
522*77c1e3ccSAndroid Build Coastguard Worker  *
523*77c1e3ccSAndroid Build Coastguard Worker  * This struct contains a cache of previous txfm results, and some buffers for
524*77c1e3ccSAndroid Build Coastguard Worker  * the current txfm decision.
525*77c1e3ccSAndroid Build Coastguard Worker  */
526*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
527*77c1e3ccSAndroid Build Coastguard Worker   //! Whether to skip transform and quantization on a partition block level.
528*77c1e3ccSAndroid Build Coastguard Worker   uint8_t skip_txfm;
529*77c1e3ccSAndroid Build Coastguard Worker 
530*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Whether to skip transform and quantization on a txfm block level.
531*77c1e3ccSAndroid Build Coastguard Worker    *
532*77c1e3ccSAndroid Build Coastguard Worker    * Skips transform and quantization on a transform block level inside the
533*77c1e3ccSAndroid Build Coastguard Worker    * current partition block. Each element of this array is used as a bit-field.
534*77c1e3ccSAndroid Build Coastguard Worker    * So for example, the we are skipping on the luma plane, then the last bit
535*77c1e3ccSAndroid Build Coastguard Worker    * would be set to 1.
536*77c1e3ccSAndroid Build Coastguard Worker    */
537*77c1e3ccSAndroid Build Coastguard Worker   uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
538*77c1e3ccSAndroid Build Coastguard Worker 
539*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Transform types inside the partition block
540*77c1e3ccSAndroid Build Coastguard Worker    *
541*77c1e3ccSAndroid Build Coastguard Worker    * Keeps a record of what kind of transform to use for each of the transform
542*77c1e3ccSAndroid Build Coastguard Worker    * block inside the partition block.
543*77c1e3ccSAndroid Build Coastguard Worker    * \attention The buffer here is *never* directly used. Instead, this just
544*77c1e3ccSAndroid Build Coastguard Worker    * allocates the memory for MACROBLOCKD::tx_type_map during rdopt on the
545*77c1e3ccSAndroid Build Coastguard Worker    * partition block. So if we need to save memory, we could move the allocation
546*77c1e3ccSAndroid Build Coastguard Worker    * to pick_sb_mode instead.
547*77c1e3ccSAndroid Build Coastguard Worker    */
548*77c1e3ccSAndroid Build Coastguard Worker   uint8_t tx_type_map_[MAX_MIB_SIZE * MAX_MIB_SIZE];
549*77c1e3ccSAndroid Build Coastguard Worker 
550*77c1e3ccSAndroid Build Coastguard Worker   //! Txfm hash records of inter-modes.
551*77c1e3ccSAndroid Build Coastguard Worker   MB_RD_RECORD *mb_rd_record;
552*77c1e3ccSAndroid Build Coastguard Worker 
553*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Number of txb splits.
554*77c1e3ccSAndroid Build Coastguard Worker    *
555*77c1e3ccSAndroid Build Coastguard Worker    * Keep track of how many times we've used split tx partition for transform
556*77c1e3ccSAndroid Build Coastguard Worker    * blocks. Somewhat misleadingly, this parameter doesn't actually keep track
557*77c1e3ccSAndroid Build Coastguard Worker    * of the count of the current block. Instead, it's a cumulative count across
558*77c1e3ccSAndroid Build Coastguard Worker    * of the whole frame. The main usage is that if txb_split_count is zero, then
559*77c1e3ccSAndroid Build Coastguard Worker    * we can signal TX_MODE_LARGEST at frame level.
560*77c1e3ccSAndroid Build Coastguard Worker    */
561*77c1e3ccSAndroid Build Coastguard Worker   // TODO([email protected]): Move this to a more appropriate location such
562*77c1e3ccSAndroid Build Coastguard Worker   // as ThreadData.
563*77c1e3ccSAndroid Build Coastguard Worker   unsigned int txb_split_count;
564*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_SPEED_STATS
565*77c1e3ccSAndroid Build Coastguard Worker   //! For debugging. Used to check how many txfm searches we are doing.
566*77c1e3ccSAndroid Build Coastguard Worker   unsigned int tx_search_count;
567*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_SPEED_STATS
568*77c1e3ccSAndroid Build Coastguard Worker } TxfmSearchInfo;
569*77c1e3ccSAndroid Build Coastguard Worker #undef MAX_NUM_8X8_TXBS
570*77c1e3ccSAndroid Build Coastguard Worker #undef MAX_NUM_16X16_TXBS
571*77c1e3ccSAndroid Build Coastguard Worker #undef MAX_NUM_32X32_TXBS
572*77c1e3ccSAndroid Build Coastguard Worker #undef MAX_NUM_64X64_TXBS
573*77c1e3ccSAndroid Build Coastguard Worker 
574*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Holds the entropy costs for various modes sent to the bitstream.
575*77c1e3ccSAndroid Build Coastguard Worker  *
576*77c1e3ccSAndroid Build Coastguard Worker  * \attention This does not include the costs for mv and transformed
577*77c1e3ccSAndroid Build Coastguard Worker  * coefficients.
578*77c1e3ccSAndroid Build Coastguard Worker  */
579*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
580*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
581*77c1e3ccSAndroid Build Coastguard Worker    * \name Partition Costs
582*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
583*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
584*77c1e3ccSAndroid Build Coastguard Worker   //! Cost for coding the partition.
585*77c1e3ccSAndroid Build Coastguard Worker   int partition_cost[PARTITION_CONTEXTS][EXT_PARTITION_TYPES];
586*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
587*77c1e3ccSAndroid Build Coastguard Worker 
588*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
589*77c1e3ccSAndroid Build Coastguard Worker    * \name Intra Costs: General
590*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
591*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
592*77c1e3ccSAndroid Build Coastguard Worker   //! Luma mode cost for inter frame.
593*77c1e3ccSAndroid Build Coastguard Worker   int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES];
594*77c1e3ccSAndroid Build Coastguard Worker   //! Luma mode cost for intra frame.
595*77c1e3ccSAndroid Build Coastguard Worker   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
596*77c1e3ccSAndroid Build Coastguard Worker   //! Chroma mode cost
597*77c1e3ccSAndroid Build Coastguard Worker   int intra_uv_mode_cost[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES];
598*77c1e3ccSAndroid Build Coastguard Worker   //! filter_intra_cost
599*77c1e3ccSAndroid Build Coastguard Worker   int filter_intra_cost[BLOCK_SIZES_ALL][2];
600*77c1e3ccSAndroid Build Coastguard Worker   //! filter_intra_mode_cost
601*77c1e3ccSAndroid Build Coastguard Worker   int filter_intra_mode_cost[FILTER_INTRA_MODES];
602*77c1e3ccSAndroid Build Coastguard Worker   //! angle_delta_cost
603*77c1e3ccSAndroid Build Coastguard Worker   int angle_delta_cost[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1];
604*77c1e3ccSAndroid Build Coastguard Worker 
605*77c1e3ccSAndroid Build Coastguard Worker   //! Rate rate associated with each alpha codeword
606*77c1e3ccSAndroid Build Coastguard Worker   int cfl_cost[CFL_JOINT_SIGNS][CFL_PRED_PLANES][CFL_ALPHABET_SIZE];
607*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
608*77c1e3ccSAndroid Build Coastguard Worker 
609*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
610*77c1e3ccSAndroid Build Coastguard Worker    * \name Intra Costs: Screen Contents
611*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
612*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
613*77c1e3ccSAndroid Build Coastguard Worker   //! intrabc_cost
614*77c1e3ccSAndroid Build Coastguard Worker   int intrabc_cost[2];
615*77c1e3ccSAndroid Build Coastguard Worker 
616*77c1e3ccSAndroid Build Coastguard Worker   //! palette_y_size_cost
617*77c1e3ccSAndroid Build Coastguard Worker   int palette_y_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES];
618*77c1e3ccSAndroid Build Coastguard Worker   //! palette_uv_size_cost
619*77c1e3ccSAndroid Build Coastguard Worker   int palette_uv_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES];
620*77c1e3ccSAndroid Build Coastguard Worker   //! palette_y_color_cost
621*77c1e3ccSAndroid Build Coastguard Worker   int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
622*77c1e3ccSAndroid Build Coastguard Worker                           [PALETTE_COLORS];
623*77c1e3ccSAndroid Build Coastguard Worker   //! palette_uv_color_cost
624*77c1e3ccSAndroid Build Coastguard Worker   int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
625*77c1e3ccSAndroid Build Coastguard Worker                            [PALETTE_COLORS];
626*77c1e3ccSAndroid Build Coastguard Worker   //! palette_y_mode_cost
627*77c1e3ccSAndroid Build Coastguard Worker   int palette_y_mode_cost[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS][2];
628*77c1e3ccSAndroid Build Coastguard Worker   //! palette_uv_mode_cost
629*77c1e3ccSAndroid Build Coastguard Worker   int palette_uv_mode_cost[PALETTE_UV_MODE_CONTEXTS][2];
630*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
631*77c1e3ccSAndroid Build Coastguard Worker 
632*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
633*77c1e3ccSAndroid Build Coastguard Worker    * \name Inter Costs: MV Modes
634*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
635*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
636*77c1e3ccSAndroid Build Coastguard Worker   //! skip_mode_cost
637*77c1e3ccSAndroid Build Coastguard Worker   int skip_mode_cost[SKIP_MODE_CONTEXTS][2];
638*77c1e3ccSAndroid Build Coastguard Worker   //! newmv_mode_cost
639*77c1e3ccSAndroid Build Coastguard Worker   int newmv_mode_cost[NEWMV_MODE_CONTEXTS][2];
640*77c1e3ccSAndroid Build Coastguard Worker   //! zeromv_mode_cost
641*77c1e3ccSAndroid Build Coastguard Worker   int zeromv_mode_cost[GLOBALMV_MODE_CONTEXTS][2];
642*77c1e3ccSAndroid Build Coastguard Worker   //! refmv_mode_cost
643*77c1e3ccSAndroid Build Coastguard Worker   int refmv_mode_cost[REFMV_MODE_CONTEXTS][2];
644*77c1e3ccSAndroid Build Coastguard Worker   //! drl_mode_cost0
645*77c1e3ccSAndroid Build Coastguard Worker   int drl_mode_cost0[DRL_MODE_CONTEXTS][2];
646*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
647*77c1e3ccSAndroid Build Coastguard Worker 
648*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
649*77c1e3ccSAndroid Build Coastguard Worker    * \name Inter Costs: Ref Frame Types
650*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
651*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
652*77c1e3ccSAndroid Build Coastguard Worker   //! single_ref_cost
653*77c1e3ccSAndroid Build Coastguard Worker   int single_ref_cost[REF_CONTEXTS][SINGLE_REFS - 1][2];
654*77c1e3ccSAndroid Build Coastguard Worker   //! comp_inter_cost
655*77c1e3ccSAndroid Build Coastguard Worker   int comp_inter_cost[COMP_INTER_CONTEXTS][2];
656*77c1e3ccSAndroid Build Coastguard Worker   //! comp_ref_type_cost
657*77c1e3ccSAndroid Build Coastguard Worker   int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS]
658*77c1e3ccSAndroid Build Coastguard Worker                         [CDF_SIZE(COMP_REFERENCE_TYPES)];
659*77c1e3ccSAndroid Build Coastguard Worker   //! uni_comp_ref_cost
660*77c1e3ccSAndroid Build Coastguard Worker   int uni_comp_ref_cost[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]
661*77c1e3ccSAndroid Build Coastguard Worker                        [CDF_SIZE(2)];
662*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Cost for signaling ref_frame[0] in bidir-comp mode
663*77c1e3ccSAndroid Build Coastguard Worker    *
664*77c1e3ccSAndroid Build Coastguard Worker    * Includes LAST_FRAME, LAST2_FRAME, LAST3_FRAME, and GOLDEN_FRAME.
665*77c1e3ccSAndroid Build Coastguard Worker    */
666*77c1e3ccSAndroid Build Coastguard Worker   int comp_ref_cost[REF_CONTEXTS][FWD_REFS - 1][2];
667*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Cost for signaling ref_frame[1] in bidir-comp mode
668*77c1e3ccSAndroid Build Coastguard Worker    *
669*77c1e3ccSAndroid Build Coastguard Worker    * Includes ALTREF_FRAME, ALTREF2_FRAME, and BWDREF_FRAME.
670*77c1e3ccSAndroid Build Coastguard Worker    */
671*77c1e3ccSAndroid Build Coastguard Worker   int comp_bwdref_cost[REF_CONTEXTS][BWD_REFS - 1][2];
672*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
673*77c1e3ccSAndroid Build Coastguard Worker 
674*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
675*77c1e3ccSAndroid Build Coastguard Worker    * \name Inter Costs: Compound Types
676*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
677*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
678*77c1e3ccSAndroid Build Coastguard Worker   //! intra_inter_cost
679*77c1e3ccSAndroid Build Coastguard Worker   int intra_inter_cost[INTRA_INTER_CONTEXTS][2];
680*77c1e3ccSAndroid Build Coastguard Worker   //! inter_compound_mode_cost
681*77c1e3ccSAndroid Build Coastguard Worker   int inter_compound_mode_cost[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES];
682*77c1e3ccSAndroid Build Coastguard Worker   //! compound_type_cost
683*77c1e3ccSAndroid Build Coastguard Worker   int compound_type_cost[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES];
684*77c1e3ccSAndroid Build Coastguard Worker   //! wedge_idx_cost
685*77c1e3ccSAndroid Build Coastguard Worker   int wedge_idx_cost[BLOCK_SIZES_ALL][16];
686*77c1e3ccSAndroid Build Coastguard Worker   //! interintra_cost
687*77c1e3ccSAndroid Build Coastguard Worker   int interintra_cost[BLOCK_SIZE_GROUPS][2];
688*77c1e3ccSAndroid Build Coastguard Worker   //! wedge_interintra_cost
689*77c1e3ccSAndroid Build Coastguard Worker   int wedge_interintra_cost[BLOCK_SIZES_ALL][2];
690*77c1e3ccSAndroid Build Coastguard Worker   //! interintra_mode_cost
691*77c1e3ccSAndroid Build Coastguard Worker   int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
692*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
693*77c1e3ccSAndroid Build Coastguard Worker 
694*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
695*77c1e3ccSAndroid Build Coastguard Worker    * \name Inter Costs: Compound Masks
696*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
697*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
698*77c1e3ccSAndroid Build Coastguard Worker   //! comp_idx_cost
699*77c1e3ccSAndroid Build Coastguard Worker   int comp_idx_cost[COMP_INDEX_CONTEXTS][2];
700*77c1e3ccSAndroid Build Coastguard Worker   //! comp_group_idx_cost
701*77c1e3ccSAndroid Build Coastguard Worker   int comp_group_idx_cost[COMP_GROUP_IDX_CONTEXTS][2];
702*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
703*77c1e3ccSAndroid Build Coastguard Worker 
704*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
705*77c1e3ccSAndroid Build Coastguard Worker    * \name Inter Costs: Motion Modes/Filters
706*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
707*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
708*77c1e3ccSAndroid Build Coastguard Worker   //! motion_mode_cost
709*77c1e3ccSAndroid Build Coastguard Worker   int motion_mode_cost[BLOCK_SIZES_ALL][MOTION_MODES];
710*77c1e3ccSAndroid Build Coastguard Worker   //! motion_mode_cost1
711*77c1e3ccSAndroid Build Coastguard Worker   int motion_mode_cost1[BLOCK_SIZES_ALL][2];
712*77c1e3ccSAndroid Build Coastguard Worker   //! switchable_interp_costs
713*77c1e3ccSAndroid Build Coastguard Worker   int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
714*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
715*77c1e3ccSAndroid Build Coastguard Worker 
716*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
717*77c1e3ccSAndroid Build Coastguard Worker    * \name Txfm Mode Costs
718*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
719*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
720*77c1e3ccSAndroid Build Coastguard Worker   //! skip_txfm_cost
721*77c1e3ccSAndroid Build Coastguard Worker   int skip_txfm_cost[SKIP_CONTEXTS][2];
722*77c1e3ccSAndroid Build Coastguard Worker   //! tx_size_cost
723*77c1e3ccSAndroid Build Coastguard Worker   int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES];
724*77c1e3ccSAndroid Build Coastguard Worker   //! txfm_partition_cost
725*77c1e3ccSAndroid Build Coastguard Worker   int txfm_partition_cost[TXFM_PARTITION_CONTEXTS][2];
726*77c1e3ccSAndroid Build Coastguard Worker   //! inter_tx_type_costs
727*77c1e3ccSAndroid Build Coastguard Worker   int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES];
728*77c1e3ccSAndroid Build Coastguard Worker   //! intra_tx_type_costs
729*77c1e3ccSAndroid Build Coastguard Worker   int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
730*77c1e3ccSAndroid Build Coastguard Worker                          [TX_TYPES];
731*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
732*77c1e3ccSAndroid Build Coastguard Worker 
733*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
734*77c1e3ccSAndroid Build Coastguard Worker    * \name Restoration Mode Costs
735*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
736*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
737*77c1e3ccSAndroid Build Coastguard Worker   //! switchable_restore_cost
738*77c1e3ccSAndroid Build Coastguard Worker   int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES];
739*77c1e3ccSAndroid Build Coastguard Worker   //! wiener_restore_cost
740*77c1e3ccSAndroid Build Coastguard Worker   int wiener_restore_cost[2];
741*77c1e3ccSAndroid Build Coastguard Worker   //! sgrproj_restore_cost
742*77c1e3ccSAndroid Build Coastguard Worker   int sgrproj_restore_cost[2];
743*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
744*77c1e3ccSAndroid Build Coastguard Worker 
745*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
746*77c1e3ccSAndroid Build Coastguard Worker    * \name Segmentation Mode Costs
747*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
748*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
749*77c1e3ccSAndroid Build Coastguard Worker   //! tmp_pred_cost
750*77c1e3ccSAndroid Build Coastguard Worker   int tmp_pred_cost[SEG_TEMPORAL_PRED_CTXS][2];
751*77c1e3ccSAndroid Build Coastguard Worker   //! spatial_pred_cost
752*77c1e3ccSAndroid Build Coastguard Worker   int spatial_pred_cost[SPATIAL_PREDICTION_PROBS][MAX_SEGMENTS];
753*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
754*77c1e3ccSAndroid Build Coastguard Worker } ModeCosts;
755*77c1e3ccSAndroid Build Coastguard Worker 
756*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Holds mv costs for encoding and motion search.
757*77c1e3ccSAndroid Build Coastguard Worker  */
758*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
759*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
760*77c1e3ccSAndroid Build Coastguard Worker    * \name Encoding Costs
761*77c1e3ccSAndroid Build Coastguard Worker    * Here are the entropy costs needed to encode a given mv.
762*77c1e3ccSAndroid Build Coastguard Worker    * \ref nmv_cost_alloc and \ref nmv_cost_hp_alloc are two arrays that holds
763*77c1e3ccSAndroid Build Coastguard Worker    * the memory for holding the mv cost. But since the motion vectors can be
764*77c1e3ccSAndroid Build Coastguard Worker    * negative, we shift them to the middle and store the resulting pointer in
765*77c1e3ccSAndroid Build Coastguard Worker    * \ref nmv_cost and \ref nmv_cost_hp for easier referencing. Finally, \ref
766*77c1e3ccSAndroid Build Coastguard Worker    * mv_cost_stack points to the \ref nmv_cost with the mv precision we are
767*77c1e3ccSAndroid Build Coastguard Worker    * currently working with. In essence, only \ref mv_cost_stack is needed for
768*77c1e3ccSAndroid Build Coastguard Worker    * motion search, the other can be considered private.
769*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
770*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
771*77c1e3ccSAndroid Build Coastguard Worker   //! Costs for coding the zero components.
772*77c1e3ccSAndroid Build Coastguard Worker   int nmv_joint_cost[MV_JOINTS];
773*77c1e3ccSAndroid Build Coastguard Worker 
774*77c1e3ccSAndroid Build Coastguard Worker   //! Allocates memory for 1/4-pel motion vector costs.
775*77c1e3ccSAndroid Build Coastguard Worker   int nmv_cost_alloc[2][MV_VALS];
776*77c1e3ccSAndroid Build Coastguard Worker   //! Allocates memory for 1/8-pel motion vector costs.
777*77c1e3ccSAndroid Build Coastguard Worker   int nmv_cost_hp_alloc[2][MV_VALS];
778*77c1e3ccSAndroid Build Coastguard Worker   //! Points to the middle of \ref nmv_cost_alloc
779*77c1e3ccSAndroid Build Coastguard Worker   int *nmv_cost[2];
780*77c1e3ccSAndroid Build Coastguard Worker   //! Points to the middle of \ref nmv_cost_hp_alloc
781*77c1e3ccSAndroid Build Coastguard Worker   int *nmv_cost_hp[2];
782*77c1e3ccSAndroid Build Coastguard Worker   //! Points to the nmv_cost_hp in use.
783*77c1e3ccSAndroid Build Coastguard Worker   int **mv_cost_stack;
784*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
785*77c1e3ccSAndroid Build Coastguard Worker } MvCosts;
786*77c1e3ccSAndroid Build Coastguard Worker 
787*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Holds mv costs for intrabc.
788*77c1e3ccSAndroid Build Coastguard Worker  */
789*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
790*77c1e3ccSAndroid Build Coastguard Worker   /*! Costs for coding the joint mv. */
791*77c1e3ccSAndroid Build Coastguard Worker   int joint_mv[MV_JOINTS];
792*77c1e3ccSAndroid Build Coastguard Worker 
793*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Cost of transmitting the actual motion vector.
794*77c1e3ccSAndroid Build Coastguard Worker    *  dv_costs_alloc[0][i] is the cost of motion vector with horizontal
795*77c1e3ccSAndroid Build Coastguard Worker    * component (mv_row) equal to i - MV_MAX. dv_costs_alloc[1][i] is the cost of
796*77c1e3ccSAndroid Build Coastguard Worker    * motion vector with vertical component (mv_col) equal to i - MV_MAX.
797*77c1e3ccSAndroid Build Coastguard Worker    */
798*77c1e3ccSAndroid Build Coastguard Worker   int dv_costs_alloc[2][MV_VALS];
799*77c1e3ccSAndroid Build Coastguard Worker 
800*77c1e3ccSAndroid Build Coastguard Worker   /*! Points to the middle of \ref dv_costs_alloc. */
801*77c1e3ccSAndroid Build Coastguard Worker   int *dv_costs[2];
802*77c1e3ccSAndroid Build Coastguard Worker } IntraBCMVCosts;
803*77c1e3ccSAndroid Build Coastguard Worker 
804*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Holds the costs needed to encode the coefficients
805*77c1e3ccSAndroid Build Coastguard Worker  */
806*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
807*77c1e3ccSAndroid Build Coastguard Worker   //! Costs for coding the coefficients.
808*77c1e3ccSAndroid Build Coastguard Worker   LV_MAP_COEFF_COST coeff_costs[TX_SIZES][PLANE_TYPES];
809*77c1e3ccSAndroid Build Coastguard Worker   //! Costs for coding the eobs.
810*77c1e3ccSAndroid Build Coastguard Worker   LV_MAP_EOB_COST eob_costs[7][2];
811*77c1e3ccSAndroid Build Coastguard Worker } CoeffCosts;
812*77c1e3ccSAndroid Build Coastguard Worker 
813*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
814*77c1e3ccSAndroid Build Coastguard Worker // 4: NEAREST, NEW, NEAR, GLOBAL
815*77c1e3ccSAndroid Build Coastguard Worker #define SINGLE_REF_MODES ((REF_FRAMES - 1) * 4)
816*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
817*77c1e3ccSAndroid Build Coastguard Worker struct inter_modes_info;
818*77c1e3ccSAndroid Build Coastguard Worker 
819*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Holds the motion samples for warp motion model estimation
820*77c1e3ccSAndroid Build Coastguard Worker  */
821*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
822*77c1e3ccSAndroid Build Coastguard Worker   //! Number of samples.
823*77c1e3ccSAndroid Build Coastguard Worker   int num;
824*77c1e3ccSAndroid Build Coastguard Worker   //! Sample locations in current frame.
825*77c1e3ccSAndroid Build Coastguard Worker   int pts[16];
826*77c1e3ccSAndroid Build Coastguard Worker   //! Sample location in the reference frame.
827*77c1e3ccSAndroid Build Coastguard Worker   int pts_inref[16];
828*77c1e3ccSAndroid Build Coastguard Worker } WARP_SAMPLE_INFO;
829*77c1e3ccSAndroid Build Coastguard Worker 
830*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
831*77c1e3ccSAndroid Build Coastguard Worker typedef enum {
832*77c1e3ccSAndroid Build Coastguard Worker   kZeroSad = 0,
833*77c1e3ccSAndroid Build Coastguard Worker   kVeryLowSad = 1,
834*77c1e3ccSAndroid Build Coastguard Worker   kLowSad = 2,
835*77c1e3ccSAndroid Build Coastguard Worker   kMedSad = 3,
836*77c1e3ccSAndroid Build Coastguard Worker   kHighSad = 4
837*77c1e3ccSAndroid Build Coastguard Worker } SOURCE_SAD;
838*77c1e3ccSAndroid Build Coastguard Worker 
839*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
840*77c1e3ccSAndroid Build Coastguard Worker   //! SAD levels in non-rd path
841*77c1e3ccSAndroid Build Coastguard Worker   SOURCE_SAD source_sad_nonrd;
842*77c1e3ccSAndroid Build Coastguard Worker   //! SAD levels in rd-path for var-based part qindex thresholds
843*77c1e3ccSAndroid Build Coastguard Worker   SOURCE_SAD source_sad_rd;
844*77c1e3ccSAndroid Build Coastguard Worker   int lighting_change;
845*77c1e3ccSAndroid Build Coastguard Worker   int low_sumdiff;
846*77c1e3ccSAndroid Build Coastguard Worker } CONTENT_STATE_SB;
847*77c1e3ccSAndroid Build Coastguard Worker 
848*77c1e3ccSAndroid Build Coastguard Worker // Structure to hold pixel level gradient info.
849*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
850*77c1e3ccSAndroid Build Coastguard Worker   uint16_t abs_dx_abs_dy_sum;
851*77c1e3ccSAndroid Build Coastguard Worker   int8_t hist_bin_idx;
852*77c1e3ccSAndroid Build Coastguard Worker   bool is_dx_zero;
853*77c1e3ccSAndroid Build Coastguard Worker } PixelLevelGradientInfo;
854*77c1e3ccSAndroid Build Coastguard Worker 
855*77c1e3ccSAndroid Build Coastguard Worker // Structure to hold the variance and log(1 + variance) for 4x4 sub-blocks.
856*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
857*77c1e3ccSAndroid Build Coastguard Worker   double log_var;
858*77c1e3ccSAndroid Build Coastguard Worker   int var;
859*77c1e3ccSAndroid Build Coastguard Worker } Block4x4VarInfo;
860*77c1e3ccSAndroid Build Coastguard Worker 
861*77c1e3ccSAndroid Build Coastguard Worker #ifndef NDEBUG
862*77c1e3ccSAndroid Build Coastguard Worker typedef struct SetOffsetsLoc {
863*77c1e3ccSAndroid Build Coastguard Worker   int mi_row;
864*77c1e3ccSAndroid Build Coastguard Worker   int mi_col;
865*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_SIZE bsize;
866*77c1e3ccSAndroid Build Coastguard Worker } SetOffsetsLoc;
867*77c1e3ccSAndroid Build Coastguard Worker #endif  // NDEBUG
868*77c1e3ccSAndroid Build Coastguard Worker 
869*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
870*77c1e3ccSAndroid Build Coastguard Worker 
871*77c1e3ccSAndroid Build Coastguard Worker /*! \brief Encoder's parameters related to the current coding block.
872*77c1e3ccSAndroid Build Coastguard Worker  *
873*77c1e3ccSAndroid Build Coastguard Worker  * This struct contains most of the information the encoder needs to encode the
874*77c1e3ccSAndroid Build Coastguard Worker  * current coding block. This includes the src and pred buffer, a copy of the
875*77c1e3ccSAndroid Build Coastguard Worker  * decoder's view of the current block, the txfm coefficients. This struct also
876*77c1e3ccSAndroid Build Coastguard Worker  * contains various buffers and data used to speed up the encoding process.
877*77c1e3ccSAndroid Build Coastguard Worker  */
878*77c1e3ccSAndroid Build Coastguard Worker typedef struct macroblock {
879*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
880*77c1e3ccSAndroid Build Coastguard Worker    * \name Source, Buffers and Decoder
881*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
882*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
883*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Each of the encoding plane.
884*77c1e3ccSAndroid Build Coastguard Worker    *
885*77c1e3ccSAndroid Build Coastguard Worker    * An array holding the src buffer for each of plane of the current block. It
886*77c1e3ccSAndroid Build Coastguard Worker    * also contains the txfm and quantized txfm coefficients.
887*77c1e3ccSAndroid Build Coastguard Worker    */
888*77c1e3ccSAndroid Build Coastguard Worker   struct macroblock_plane plane[MAX_MB_PLANE];
889*77c1e3ccSAndroid Build Coastguard Worker 
890*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Decoder's view of current coding block.
891*77c1e3ccSAndroid Build Coastguard Worker    *
892*77c1e3ccSAndroid Build Coastguard Worker    * Contains the encoder's copy of what the decoder sees in the current block.
893*77c1e3ccSAndroid Build Coastguard Worker    * Most importantly, this struct contains pointers to mbmi that is used in
894*77c1e3ccSAndroid Build Coastguard Worker    * final bitstream packing.
895*77c1e3ccSAndroid Build Coastguard Worker    */
896*77c1e3ccSAndroid Build Coastguard Worker   MACROBLOCKD e_mbd;
897*77c1e3ccSAndroid Build Coastguard Worker 
898*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Derived coding information.
899*77c1e3ccSAndroid Build Coastguard Worker    *
900*77c1e3ccSAndroid Build Coastguard Worker    * Contains extra information not transmitted in the bitstream but are
901*77c1e3ccSAndroid Build Coastguard Worker    * derived. For example, this contains the stack of ref_mvs.
902*77c1e3ccSAndroid Build Coastguard Worker    */
903*77c1e3ccSAndroid Build Coastguard Worker   MB_MODE_INFO_EXT mbmi_ext;
904*77c1e3ccSAndroid Build Coastguard Worker 
905*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Finalized mbmi_ext for the whole frame.
906*77c1e3ccSAndroid Build Coastguard Worker    *
907*77c1e3ccSAndroid Build Coastguard Worker    * Contains the finalized info in mbmi_ext that gets used at the frame level
908*77c1e3ccSAndroid Build Coastguard Worker    * for bitstream packing.
909*77c1e3ccSAndroid Build Coastguard Worker    */
910*77c1e3ccSAndroid Build Coastguard Worker   MB_MODE_INFO_EXT_FRAME *mbmi_ext_frame;
911*77c1e3ccSAndroid Build Coastguard Worker 
912*77c1e3ccSAndroid Build Coastguard Worker   //! Entropy context for the current row.
913*77c1e3ccSAndroid Build Coastguard Worker   FRAME_CONTEXT *row_ctx;
914*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Entropy context for the current tile.
915*77c1e3ccSAndroid Build Coastguard Worker    *
916*77c1e3ccSAndroid Build Coastguard Worker    * This context will be used to update color_map_cdf pointer which would be
917*77c1e3ccSAndroid Build Coastguard Worker    * used during pack bitstream. For single thread and tile-multithreading case
918*77c1e3ccSAndroid Build Coastguard Worker    * this pointer will be same as xd->tile_ctx, but for the case of row-mt:
919*77c1e3ccSAndroid Build Coastguard Worker    * xd->tile_ctx will point to a temporary context while tile_pb_ctx will point
920*77c1e3ccSAndroid Build Coastguard Worker    * to the accurate tile context.
921*77c1e3ccSAndroid Build Coastguard Worker    */
922*77c1e3ccSAndroid Build Coastguard Worker   FRAME_CONTEXT *tile_pb_ctx;
923*77c1e3ccSAndroid Build Coastguard Worker 
924*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Buffer of transformed coefficients
925*77c1e3ccSAndroid Build Coastguard Worker    *
926*77c1e3ccSAndroid Build Coastguard Worker    * Points to cb_coef_buff in the AV1_COMP struct, which contains the finalized
927*77c1e3ccSAndroid Build Coastguard Worker    * coefficients. This is here to conveniently copy the best coefficients to
928*77c1e3ccSAndroid Build Coastguard Worker    * frame level for bitstream packing. Since CB_COEFF_BUFFER is allocated on a
929*77c1e3ccSAndroid Build Coastguard Worker    * superblock level, we need to combine it with cb_offset to get the proper
930*77c1e3ccSAndroid Build Coastguard Worker    * position for the current coding block.
931*77c1e3ccSAndroid Build Coastguard Worker    */
932*77c1e3ccSAndroid Build Coastguard Worker   CB_COEFF_BUFFER *cb_coef_buff;
933*77c1e3ccSAndroid Build Coastguard Worker   //! Offset of current coding block's coeff buffer relative to the sb.
934*77c1e3ccSAndroid Build Coastguard Worker   uint16_t cb_offset[PLANE_TYPES];
935*77c1e3ccSAndroid Build Coastguard Worker 
936*77c1e3ccSAndroid Build Coastguard Worker   //! Modified source and masks used for fast OBMC search.
937*77c1e3ccSAndroid Build Coastguard Worker   OBMCBuffer obmc_buffer;
938*77c1e3ccSAndroid Build Coastguard Worker   //! Buffer to store the best palette map.
939*77c1e3ccSAndroid Build Coastguard Worker   PALETTE_BUFFER *palette_buffer;
940*77c1e3ccSAndroid Build Coastguard Worker   //! Buffer used for compound_type_rd().
941*77c1e3ccSAndroid Build Coastguard Worker   CompoundTypeRdBuffers comp_rd_buffer;
942*77c1e3ccSAndroid Build Coastguard Worker   //! Buffer to store convolution during averaging process in compound mode.
943*77c1e3ccSAndroid Build Coastguard Worker   CONV_BUF_TYPE *tmp_conv_dst;
944*77c1e3ccSAndroid Build Coastguard Worker 
945*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Temporary buffer to hold prediction.
946*77c1e3ccSAndroid Build Coastguard Worker    *
947*77c1e3ccSAndroid Build Coastguard Worker    * Points to a buffer that is used to hold temporary prediction results. This
948*77c1e3ccSAndroid Build Coastguard Worker    * is used in two ways:
949*77c1e3ccSAndroid Build Coastguard Worker    * - This is a temporary buffer used to ping-pong the prediction in
950*77c1e3ccSAndroid Build Coastguard Worker    *   handle_inter_mode.
951*77c1e3ccSAndroid Build Coastguard Worker    * - xd->tmp_obmc_bufs also points to this buffer, and is used in ombc
952*77c1e3ccSAndroid Build Coastguard Worker    *   prediction.
953*77c1e3ccSAndroid Build Coastguard Worker    */
954*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *tmp_pred_bufs[2];
955*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
956*77c1e3ccSAndroid Build Coastguard Worker 
957*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
958*77c1e3ccSAndroid Build Coastguard Worker    * \name Rdopt Costs
959*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
960*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
961*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Quantization index for the current partition block.
962*77c1e3ccSAndroid Build Coastguard Worker    *
963*77c1e3ccSAndroid Build Coastguard Worker    * This is used to as the index to find quantization parameter for luma and
964*77c1e3ccSAndroid Build Coastguard Worker    * chroma transformed coefficients.
965*77c1e3ccSAndroid Build Coastguard Worker    */
966*77c1e3ccSAndroid Build Coastguard Worker   int qindex;
967*77c1e3ccSAndroid Build Coastguard Worker 
968*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Difference between frame-level qindex and current qindex.
969*77c1e3ccSAndroid Build Coastguard Worker    *
970*77c1e3ccSAndroid Build Coastguard Worker    *  This is used to track whether a non-zero delta for qindex is used at least
971*77c1e3ccSAndroid Build Coastguard Worker    *  once in the current frame.
972*77c1e3ccSAndroid Build Coastguard Worker    */
973*77c1e3ccSAndroid Build Coastguard Worker   int delta_qindex;
974*77c1e3ccSAndroid Build Coastguard Worker 
975*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Difference between frame-level qindex and qindex used to
976*77c1e3ccSAndroid Build Coastguard Worker    * compute rdmult (lambda).
977*77c1e3ccSAndroid Build Coastguard Worker    *
978*77c1e3ccSAndroid Build Coastguard Worker    * rdmult_delta_qindex is assigned the same as delta_qindex before qp sweep.
979*77c1e3ccSAndroid Build Coastguard Worker    * During qp sweep, delta_qindex is changed and used to calculate the actual
980*77c1e3ccSAndroid Build Coastguard Worker    * quant params, while rdmult_delta_qindex remains the same, and is used to
981*77c1e3ccSAndroid Build Coastguard Worker    * calculate the rdmult in "set_deltaq_rdmult".
982*77c1e3ccSAndroid Build Coastguard Worker    */
983*77c1e3ccSAndroid Build Coastguard Worker   int rdmult_delta_qindex;
984*77c1e3ccSAndroid Build Coastguard Worker 
985*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Current qindex (before being adjusted by delta_q_res) used to
986*77c1e3ccSAndroid Build Coastguard Worker    * derive rdmult_delta_qindex.
987*77c1e3ccSAndroid Build Coastguard Worker    */
988*77c1e3ccSAndroid Build Coastguard Worker   int rdmult_cur_qindex;
989*77c1e3ccSAndroid Build Coastguard Worker 
990*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Rate-distortion multiplier.
991*77c1e3ccSAndroid Build Coastguard Worker    *
992*77c1e3ccSAndroid Build Coastguard Worker    * The rd multiplier used to determine the rate-distortion trade-off. This is
993*77c1e3ccSAndroid Build Coastguard Worker    * roughly proportional to the inverse of q-index for a given frame, but this
994*77c1e3ccSAndroid Build Coastguard Worker    * can be manipulated for better rate-control. For example, in tune_ssim
995*77c1e3ccSAndroid Build Coastguard Worker    * mode, this is scaled by a factor related to the variance of the current
996*77c1e3ccSAndroid Build Coastguard Worker    * block.
997*77c1e3ccSAndroid Build Coastguard Worker    */
998*77c1e3ccSAndroid Build Coastguard Worker   int rdmult;
999*77c1e3ccSAndroid Build Coastguard Worker 
1000*77c1e3ccSAndroid Build Coastguard Worker   //! Intra only, per sb rd adjustment.
1001*77c1e3ccSAndroid Build Coastguard Worker   int intra_sb_rdmult_modifier;
1002*77c1e3ccSAndroid Build Coastguard Worker 
1003*77c1e3ccSAndroid Build Coastguard Worker   //! Superblock level distortion propagation factor.
1004*77c1e3ccSAndroid Build Coastguard Worker   double rb;
1005*77c1e3ccSAndroid Build Coastguard Worker 
1006*77c1e3ccSAndroid Build Coastguard Worker   //! Energy in the current source coding block. Used to calculate \ref rdmult
1007*77c1e3ccSAndroid Build Coastguard Worker   int mb_energy;
1008*77c1e3ccSAndroid Build Coastguard Worker   //! Energy in the current source superblock. Used to calculate \ref rdmult
1009*77c1e3ccSAndroid Build Coastguard Worker   int sb_energy_level;
1010*77c1e3ccSAndroid Build Coastguard Worker 
1011*77c1e3ccSAndroid Build Coastguard Worker   //! The rate needed to signal a mode to the bitstream.
1012*77c1e3ccSAndroid Build Coastguard Worker   ModeCosts mode_costs;
1013*77c1e3ccSAndroid Build Coastguard Worker 
1014*77c1e3ccSAndroid Build Coastguard Worker   //! The rate needed to encode a new motion vector to the bitstream and some
1015*77c1e3ccSAndroid Build Coastguard Worker   //! multipliers for motion search.
1016*77c1e3ccSAndroid Build Coastguard Worker   MvCosts *mv_costs;
1017*77c1e3ccSAndroid Build Coastguard Worker 
1018*77c1e3ccSAndroid Build Coastguard Worker   /*! The rate needed to encode a new motion vector to the bitstream in intrabc
1019*77c1e3ccSAndroid Build Coastguard Worker    *  mode.
1020*77c1e3ccSAndroid Build Coastguard Worker    */
1021*77c1e3ccSAndroid Build Coastguard Worker   IntraBCMVCosts *dv_costs;
1022*77c1e3ccSAndroid Build Coastguard Worker 
1023*77c1e3ccSAndroid Build Coastguard Worker   //! The rate needed to signal the txfm coefficients to the bitstream.
1024*77c1e3ccSAndroid Build Coastguard Worker   CoeffCosts coeff_costs;
1025*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1026*77c1e3ccSAndroid Build Coastguard Worker 
1027*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1028*77c1e3ccSAndroid Build Coastguard Worker    * \name Rate to Distortion Multipliers
1029*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1030*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1031*77c1e3ccSAndroid Build Coastguard Worker   //! A multiplier that converts mv cost to l2 error.
1032*77c1e3ccSAndroid Build Coastguard Worker   int errorperbit;
1033*77c1e3ccSAndroid Build Coastguard Worker   //! A multiplier that converts mv cost to l1 error.
1034*77c1e3ccSAndroid Build Coastguard Worker   int sadperbit;
1035*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1036*77c1e3ccSAndroid Build Coastguard Worker 
1037*77c1e3ccSAndroid Build Coastguard Worker   /******************************************************************************
1038*77c1e3ccSAndroid Build Coastguard Worker    * \name Segmentation
1039*77c1e3ccSAndroid Build Coastguard Worker    *****************************************************************************/
1040*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1041*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Skip mode for the segment
1042*77c1e3ccSAndroid Build Coastguard Worker    *
1043*77c1e3ccSAndroid Build Coastguard Worker    * A syntax element of the segmentation mode. In skip_block mode, all mvs are
1044*77c1e3ccSAndroid Build Coastguard Worker    * set 0 and all txfms are skipped.
1045*77c1e3ccSAndroid Build Coastguard Worker    */
1046*77c1e3ccSAndroid Build Coastguard Worker   int seg_skip_block;
1047*77c1e3ccSAndroid Build Coastguard Worker 
1048*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Number of segment 1 blocks
1049*77c1e3ccSAndroid Build Coastguard Worker    * Actual number of (4x4) blocks that were applied delta-q,
1050*77c1e3ccSAndroid Build Coastguard Worker    * for segment 1.
1051*77c1e3ccSAndroid Build Coastguard Worker    */
1052*77c1e3ccSAndroid Build Coastguard Worker   int actual_num_seg1_blocks;
1053*77c1e3ccSAndroid Build Coastguard Worker 
1054*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Number of segment 2 blocks
1055*77c1e3ccSAndroid Build Coastguard Worker    * Actual number of (4x4) blocks that were applied delta-q,
1056*77c1e3ccSAndroid Build Coastguard Worker    * for segment 2.
1057*77c1e3ccSAndroid Build Coastguard Worker    */
1058*77c1e3ccSAndroid Build Coastguard Worker   int actual_num_seg2_blocks;
1059*77c1e3ccSAndroid Build Coastguard Worker 
1060*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Number of zero motion vectors
1061*77c1e3ccSAndroid Build Coastguard Worker    */
1062*77c1e3ccSAndroid Build Coastguard Worker   int cnt_zeromv;
1063*77c1e3ccSAndroid Build Coastguard Worker 
1064*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Flag to force zeromv-skip at superblock level, for nonrd path.
1065*77c1e3ccSAndroid Build Coastguard Worker    *
1066*77c1e3ccSAndroid Build Coastguard Worker    * 0/1 imply zeromv-skip is disabled/enabled. 2 implies that the blocks
1067*77c1e3ccSAndroid Build Coastguard Worker    * in the superblock may be marked as zeromv-skip at block level.
1068*77c1e3ccSAndroid Build Coastguard Worker    */
1069*77c1e3ccSAndroid Build Coastguard Worker   int force_zeromv_skip_for_sb;
1070*77c1e3ccSAndroid Build Coastguard Worker 
1071*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Flag to force zeromv-skip at block level, for nonrd path.
1072*77c1e3ccSAndroid Build Coastguard Worker    */
1073*77c1e3ccSAndroid Build Coastguard Worker   int force_zeromv_skip_for_blk;
1074*77c1e3ccSAndroid Build Coastguard Worker 
1075*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Previous segment id for which qmatrices were updated.
1076*77c1e3ccSAndroid Build Coastguard Worker    * This is used to bypass setting of qmatrices if no change in qindex.
1077*77c1e3ccSAndroid Build Coastguard Worker    */
1078*77c1e3ccSAndroid Build Coastguard Worker   int prev_segment_id;
1079*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1080*77c1e3ccSAndroid Build Coastguard Worker 
1081*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1082*77c1e3ccSAndroid Build Coastguard Worker    * \name Superblock
1083*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1084*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1085*77c1e3ccSAndroid Build Coastguard Worker   //! Information on a whole superblock level.
1086*77c1e3ccSAndroid Build Coastguard Worker   // TODO([email protected]): Refactor this out of macroblock
1087*77c1e3ccSAndroid Build Coastguard Worker   SuperBlockEnc sb_enc;
1088*77c1e3ccSAndroid Build Coastguard Worker 
1089*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Characteristics of the current superblock.
1090*77c1e3ccSAndroid Build Coastguard Worker    *
1091*77c1e3ccSAndroid Build Coastguard Worker    *  Characteristics like whether the block has high sad, low sad, etc. This is
1092*77c1e3ccSAndroid Build Coastguard Worker    *  only used by av1 realtime mode.
1093*77c1e3ccSAndroid Build Coastguard Worker    */
1094*77c1e3ccSAndroid Build Coastguard Worker   CONTENT_STATE_SB content_state_sb;
1095*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1096*77c1e3ccSAndroid Build Coastguard Worker 
1097*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1098*77c1e3ccSAndroid Build Coastguard Worker    * \name Reference Frame Search
1099*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1100*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1101*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Sum absolute distortion of the predicted mv for each ref frame.
1102*77c1e3ccSAndroid Build Coastguard Worker    *
1103*77c1e3ccSAndroid Build Coastguard Worker    * This is used to measure how viable a reference frame is.
1104*77c1e3ccSAndroid Build Coastguard Worker    */
1105*77c1e3ccSAndroid Build Coastguard Worker   int pred_mv_sad[REF_FRAMES];
1106*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief The minimum of \ref pred_mv_sad.
1107*77c1e3ccSAndroid Build Coastguard Worker    *
1108*77c1e3ccSAndroid Build Coastguard Worker    * Index 0 stores the minimum \ref pred_mv_sad across past reference frames.
1109*77c1e3ccSAndroid Build Coastguard Worker    * Index 1 stores the minimum \ref pred_mv_sad across future reference frames.
1110*77c1e3ccSAndroid Build Coastguard Worker    */
1111*77c1e3ccSAndroid Build Coastguard Worker   int best_pred_mv_sad[2];
1112*77c1e3ccSAndroid Build Coastguard Worker   //! The sad of the 1st mv ref (nearest).
1113*77c1e3ccSAndroid Build Coastguard Worker   int pred_mv0_sad[REF_FRAMES];
1114*77c1e3ccSAndroid Build Coastguard Worker   //! The sad of the 2nd mv ref (near).
1115*77c1e3ccSAndroid Build Coastguard Worker   int pred_mv1_sad[REF_FRAMES];
1116*77c1e3ccSAndroid Build Coastguard Worker 
1117*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Disables certain ref frame pruning based on tpl.
1118*77c1e3ccSAndroid Build Coastguard Worker    *
1119*77c1e3ccSAndroid Build Coastguard Worker    * Determines whether a given ref frame is "good" based on data from the TPL
1120*77c1e3ccSAndroid Build Coastguard Worker    * model. If so, this stops selective_ref frame from pruning the given ref
1121*77c1e3ccSAndroid Build Coastguard Worker    * frame at block level.
1122*77c1e3ccSAndroid Build Coastguard Worker    */
1123*77c1e3ccSAndroid Build Coastguard Worker   uint8_t tpl_keep_ref_frame[REF_FRAMES];
1124*77c1e3ccSAndroid Build Coastguard Worker 
1125*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Warp motion samples buffer.
1126*77c1e3ccSAndroid Build Coastguard Worker    *
1127*77c1e3ccSAndroid Build Coastguard Worker    * Store the motion samples used for warp motion.
1128*77c1e3ccSAndroid Build Coastguard Worker    */
1129*77c1e3ccSAndroid Build Coastguard Worker   WARP_SAMPLE_INFO warp_sample_info[REF_FRAMES];
1130*77c1e3ccSAndroid Build Coastguard Worker 
1131*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Reference frames picked by the square subblocks in a superblock.
1132*77c1e3ccSAndroid Build Coastguard Worker    *
1133*77c1e3ccSAndroid Build Coastguard Worker    * Keeps track of ref frames that are selected by square partition blocks
1134*77c1e3ccSAndroid Build Coastguard Worker    * within a superblock, in MI resolution. They can be used to prune ref frames
1135*77c1e3ccSAndroid Build Coastguard Worker    * for rectangular blocks.
1136*77c1e3ccSAndroid Build Coastguard Worker    */
1137*77c1e3ccSAndroid Build Coastguard Worker   int picked_ref_frames_mask[MAX_MIB_SIZE * MAX_MIB_SIZE];
1138*77c1e3ccSAndroid Build Coastguard Worker 
1139*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Prune ref frames in real-time mode.
1140*77c1e3ccSAndroid Build Coastguard Worker    *
1141*77c1e3ccSAndroid Build Coastguard Worker    * Determines whether to prune reference frames in real-time mode. For the
1142*77c1e3ccSAndroid Build Coastguard Worker    * most part, this is the same as nonrd_prune_ref_frame_search in
1143*77c1e3ccSAndroid Build Coastguard Worker    * cpi->sf.rt_sf.nonrd_prune_ref_frame_search, but this can be selectively
1144*77c1e3ccSAndroid Build Coastguard Worker    * turned off if the only frame available is GOLDEN_FRAME.
1145*77c1e3ccSAndroid Build Coastguard Worker    */
1146*77c1e3ccSAndroid Build Coastguard Worker   int nonrd_prune_ref_frame_search;
1147*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1148*77c1e3ccSAndroid Build Coastguard Worker 
1149*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1150*77c1e3ccSAndroid Build Coastguard Worker    * \name Partition Search
1151*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1152*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1153*77c1e3ccSAndroid Build Coastguard Worker   //! Stores some partition-search related buffers.
1154*77c1e3ccSAndroid Build Coastguard Worker   PartitionSearchInfo part_search_info;
1155*77c1e3ccSAndroid Build Coastguard Worker 
1156*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Whether to disable some features to force a mode in current block.
1157*77c1e3ccSAndroid Build Coastguard Worker    *
1158*77c1e3ccSAndroid Build Coastguard Worker    * In some cases, our speed features can be overly aggressive and remove all
1159*77c1e3ccSAndroid Build Coastguard Worker    * modes search in the superblock. When this happens, we set
1160*77c1e3ccSAndroid Build Coastguard Worker    * must_find_valid_partition to 1 to reduce the number of speed features, and
1161*77c1e3ccSAndroid Build Coastguard Worker    * recode the superblock again.
1162*77c1e3ccSAndroid Build Coastguard Worker    */
1163*77c1e3ccSAndroid Build Coastguard Worker   int must_find_valid_partition;
1164*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1165*77c1e3ccSAndroid Build Coastguard Worker 
1166*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1167*77c1e3ccSAndroid Build Coastguard Worker    * \name Prediction Mode Search
1168*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1169*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1170*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Inter skip mode.
1171*77c1e3ccSAndroid Build Coastguard Worker    *
1172*77c1e3ccSAndroid Build Coastguard Worker    * Skip mode tries to use the closest forward and backward references for
1173*77c1e3ccSAndroid Build Coastguard Worker    * inter prediction. Skip here means to skip transmitting the reference
1174*77c1e3ccSAndroid Build Coastguard Worker    * frames, not to be confused with skip_txfm.
1175*77c1e3ccSAndroid Build Coastguard Worker    */
1176*77c1e3ccSAndroid Build Coastguard Worker   int skip_mode;
1177*77c1e3ccSAndroid Build Coastguard Worker 
1178*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Factors used for rd-thresholding.
1179*77c1e3ccSAndroid Build Coastguard Worker    *
1180*77c1e3ccSAndroid Build Coastguard Worker    * Determines a rd threshold to determine whether to continue searching the
1181*77c1e3ccSAndroid Build Coastguard Worker    * current mode. If the current best rd is already <= threshold, then we skip
1182*77c1e3ccSAndroid Build Coastguard Worker    * the current mode.
1183*77c1e3ccSAndroid Build Coastguard Worker    */
1184*77c1e3ccSAndroid Build Coastguard Worker   int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
1185*77c1e3ccSAndroid Build Coastguard Worker 
1186*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Tracks the winner modes in the current coding block.
1187*77c1e3ccSAndroid Build Coastguard Worker    *
1188*77c1e3ccSAndroid Build Coastguard Worker    * Winner mode is a two-pass strategy to find the best prediction mode. In the
1189*77c1e3ccSAndroid Build Coastguard Worker    * first pass, we search the prediction modes with a limited set of txfm
1190*77c1e3ccSAndroid Build Coastguard Worker    * options, and keep the top modes. These modes are called the winner modes.
1191*77c1e3ccSAndroid Build Coastguard Worker    * In the second pass, we retry the winner modes with more thorough txfm
1192*77c1e3ccSAndroid Build Coastguard Worker    * options.
1193*77c1e3ccSAndroid Build Coastguard Worker    */
1194*77c1e3ccSAndroid Build Coastguard Worker   WinnerModeStats *winner_mode_stats;
1195*77c1e3ccSAndroid Build Coastguard Worker   //! Tracks how many winner modes there are.
1196*77c1e3ccSAndroid Build Coastguard Worker   int winner_mode_count;
1197*77c1e3ccSAndroid Build Coastguard Worker 
1198*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief The model used for rd-estimation to avoid txfm
1199*77c1e3ccSAndroid Build Coastguard Worker    *
1200*77c1e3ccSAndroid Build Coastguard Worker    * These are for inter_mode_rd_model_estimation, which is another two pass
1201*77c1e3ccSAndroid Build Coastguard Worker    * approach. In this speed feature, we collect data in the first couple frames
1202*77c1e3ccSAndroid Build Coastguard Worker    * to build an rd model to estimate the rdcost of a prediction model based on
1203*77c1e3ccSAndroid Build Coastguard Worker    * the residue error. Once enough data is collected, this speed feature uses
1204*77c1e3ccSAndroid Build Coastguard Worker    * the estimated rdcost to find the most performant prediction mode. Then we
1205*77c1e3ccSAndroid Build Coastguard Worker    * follow up with a second pass find the best transform for the mode.
1206*77c1e3ccSAndroid Build Coastguard Worker    * Determines if one would go with reduced complexity transform block
1207*77c1e3ccSAndroid Build Coastguard Worker    * search model to select prediction modes, or full complexity model
1208*77c1e3ccSAndroid Build Coastguard Worker    * to select transform kernel.
1209*77c1e3ccSAndroid Build Coastguard Worker    */
1210*77c1e3ccSAndroid Build Coastguard Worker   TXFM_RD_MODEL rd_model;
1211*77c1e3ccSAndroid Build Coastguard Worker 
1212*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Stores the inter mode information needed to build an rd model.
1213*77c1e3ccSAndroid Build Coastguard Worker    *
1214*77c1e3ccSAndroid Build Coastguard Worker    * These are for inter_mode_rd_model_estimation, which is another two pass
1215*77c1e3ccSAndroid Build Coastguard Worker    * approach. In this speed feature, we collect data in the first couple frames
1216*77c1e3ccSAndroid Build Coastguard Worker    * to build an rd model to estimate the rdcost of a prediction model based on
1217*77c1e3ccSAndroid Build Coastguard Worker    * the residue error. Once enough data is collected, this speed feature uses
1218*77c1e3ccSAndroid Build Coastguard Worker    * the estimated rdcost to find the most performant prediction mode. Then we
1219*77c1e3ccSAndroid Build Coastguard Worker    * follow up with a second pass find the best transform for the mode.
1220*77c1e3ccSAndroid Build Coastguard Worker    */
1221*77c1e3ccSAndroid Build Coastguard Worker   // TODO(any): try to consolidate this speed feature with winner mode
1222*77c1e3ccSAndroid Build Coastguard Worker   // processing.
1223*77c1e3ccSAndroid Build Coastguard Worker   struct inter_modes_info *inter_modes_info;
1224*77c1e3ccSAndroid Build Coastguard Worker 
1225*77c1e3ccSAndroid Build Coastguard Worker   //! How to blend the compound predictions.
1226*77c1e3ccSAndroid Build Coastguard Worker   uint8_t compound_idx;
1227*77c1e3ccSAndroid Build Coastguard Worker 
1228*77c1e3ccSAndroid Build Coastguard Worker   //! A caches of results of compound type search so they can be reused later.
1229*77c1e3ccSAndroid Build Coastguard Worker   COMP_RD_STATS comp_rd_stats[MAX_COMP_RD_STATS];
1230*77c1e3ccSAndroid Build Coastguard Worker   //! The idx for the latest compound mode in the cache \ref comp_rd_stats.
1231*77c1e3ccSAndroid Build Coastguard Worker   int comp_rd_stats_idx;
1232*77c1e3ccSAndroid Build Coastguard Worker 
1233*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Whether to recompute the luma prediction.
1234*77c1e3ccSAndroid Build Coastguard Worker    *
1235*77c1e3ccSAndroid Build Coastguard Worker    * In interpolation search, we can usually skip recalculating the luma
1236*77c1e3ccSAndroid Build Coastguard Worker    * prediction because it is already calculated by a previous predictor. This
1237*77c1e3ccSAndroid Build Coastguard Worker    * flag signifies that some modes might have been skipped, so we need to
1238*77c1e3ccSAndroid Build Coastguard Worker    * rebuild the prediction.
1239*77c1e3ccSAndroid Build Coastguard Worker    */
1240*77c1e3ccSAndroid Build Coastguard Worker   int recalc_luma_mc_data;
1241*77c1e3ccSAndroid Build Coastguard Worker 
1242*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Data structure to speed up intrabc search.
1243*77c1e3ccSAndroid Build Coastguard Worker    *
1244*77c1e3ccSAndroid Build Coastguard Worker    * Contains the hash table, hash function, and buffer used for intrabc.
1245*77c1e3ccSAndroid Build Coastguard Worker    */
1246*77c1e3ccSAndroid Build Coastguard Worker   IntraBCHashInfo intrabc_hash_info;
1247*77c1e3ccSAndroid Build Coastguard Worker 
1248*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Whether to reuse the mode stored in mb_mode_cache. */
1249*77c1e3ccSAndroid Build Coastguard Worker   int use_mb_mode_cache;
1250*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief The mode to reuse during \ref av1_rd_pick_intra_mode_sb and
1251*77c1e3ccSAndroid Build Coastguard Worker    *  \ref av1_rd_pick_inter_mode. */
1252*77c1e3ccSAndroid Build Coastguard Worker   const MB_MODE_INFO *mb_mode_cache;
1253*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Pointer to the buffer which caches gradient information.
1254*77c1e3ccSAndroid Build Coastguard Worker    *
1255*77c1e3ccSAndroid Build Coastguard Worker    * Pointer to the array of structures to store gradient information of each
1256*77c1e3ccSAndroid Build Coastguard Worker    * pixel in a superblock. The buffer constitutes of MAX_SB_SQUARE pixel level
1257*77c1e3ccSAndroid Build Coastguard Worker    * structures for each of the plane types (PLANE_TYPE_Y and PLANE_TYPE_UV).
1258*77c1e3ccSAndroid Build Coastguard Worker    */
1259*77c1e3ccSAndroid Build Coastguard Worker   PixelLevelGradientInfo *pixel_gradient_info;
1260*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Flags indicating the availability of cached gradient info. */
1261*77c1e3ccSAndroid Build Coastguard Worker   bool is_sb_gradient_cached[PLANE_TYPES];
1262*77c1e3ccSAndroid Build Coastguard Worker 
1263*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Flag to reuse predicted samples of inter block. */
1264*77c1e3ccSAndroid Build Coastguard Worker   bool reuse_inter_pred;
1265*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1266*77c1e3ccSAndroid Build Coastguard Worker 
1267*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1268*77c1e3ccSAndroid Build Coastguard Worker    * \name MV Search
1269*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1270*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1271*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Context used to determine the initial step size in motion search.
1272*77c1e3ccSAndroid Build Coastguard Worker    *
1273*77c1e3ccSAndroid Build Coastguard Worker    * This context is defined as the \f$l_\inf\f$ norm of the best ref_mvs for
1274*77c1e3ccSAndroid Build Coastguard Worker    * each frame.
1275*77c1e3ccSAndroid Build Coastguard Worker    */
1276*77c1e3ccSAndroid Build Coastguard Worker   unsigned int max_mv_context[REF_FRAMES];
1277*77c1e3ccSAndroid Build Coastguard Worker 
1278*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Limit for the range of motion vectors.
1279*77c1e3ccSAndroid Build Coastguard Worker    *
1280*77c1e3ccSAndroid Build Coastguard Worker    * These define limits to motion vector components to prevent them from
1281*77c1e3ccSAndroid Build Coastguard Worker    * extending outside the UMV borders
1282*77c1e3ccSAndroid Build Coastguard Worker    */
1283*77c1e3ccSAndroid Build Coastguard Worker   FullMvLimits mv_limits;
1284*77c1e3ccSAndroid Build Coastguard Worker 
1285*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Buffer for storing the search site config.
1286*77c1e3ccSAndroid Build Coastguard Worker    *
1287*77c1e3ccSAndroid Build Coastguard Worker    * When resize mode or super resolution mode is on, the stride of the
1288*77c1e3ccSAndroid Build Coastguard Worker    * reference frame does not always match what's specified in \ref
1289*77c1e3ccSAndroid Build Coastguard Worker    * MotionVectorSearchParams::search_site_cfg. When his happens, we update the
1290*77c1e3ccSAndroid Build Coastguard Worker    * search_sine_config buffer here and use it for motion search.
1291*77c1e3ccSAndroid Build Coastguard Worker    */
1292*77c1e3ccSAndroid Build Coastguard Worker   search_site_config search_site_cfg_buf[NUM_DISTINCT_SEARCH_METHODS];
1293*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1294*77c1e3ccSAndroid Build Coastguard Worker 
1295*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1296*77c1e3ccSAndroid Build Coastguard Worker    * \name Txfm Search
1297*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1298*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1299*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Parameters that control how motion search is done.
1300*77c1e3ccSAndroid Build Coastguard Worker    *
1301*77c1e3ccSAndroid Build Coastguard Worker    * Stores various txfm search related parameters such as txfm_type, txfm_size,
1302*77c1e3ccSAndroid Build Coastguard Worker    * trellis eob search, etc.
1303*77c1e3ccSAndroid Build Coastguard Worker    */
1304*77c1e3ccSAndroid Build Coastguard Worker   TxfmSearchParams txfm_search_params;
1305*77c1e3ccSAndroid Build Coastguard Worker 
1306*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Results of the txfm searches that have been done.
1307*77c1e3ccSAndroid Build Coastguard Worker    *
1308*77c1e3ccSAndroid Build Coastguard Worker    * Caches old txfm search results and keeps the current txfm decisions to
1309*77c1e3ccSAndroid Build Coastguard Worker    * facilitate rdopt.
1310*77c1e3ccSAndroid Build Coastguard Worker    */
1311*77c1e3ccSAndroid Build Coastguard Worker   TxfmSearchInfo txfm_search_info;
1312*77c1e3ccSAndroid Build Coastguard Worker 
1313*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Whether there is a strong color activity.
1314*77c1e3ccSAndroid Build Coastguard Worker    *
1315*77c1e3ccSAndroid Build Coastguard Worker    * Used in REALTIME coding mode to enhance the visual quality at the boundary
1316*77c1e3ccSAndroid Build Coastguard Worker    * of moving color objects.
1317*77c1e3ccSAndroid Build Coastguard Worker    */
1318*77c1e3ccSAndroid Build Coastguard Worker   uint8_t color_sensitivity_sb[MAX_MB_PLANE - 1];
1319*77c1e3ccSAndroid Build Coastguard Worker   //! Color sensitivity flag for the superblock for golden reference.
1320*77c1e3ccSAndroid Build Coastguard Worker   uint8_t color_sensitivity_sb_g[MAX_MB_PLANE - 1];
1321*77c1e3ccSAndroid Build Coastguard Worker   //! Color sensitivity flag for the superblock for altref reference.
1322*77c1e3ccSAndroid Build Coastguard Worker   uint8_t color_sensitivity_sb_alt[MAX_MB_PLANE - 1];
1323*77c1e3ccSAndroid Build Coastguard Worker   //! Color sensitivity flag for the coding block.
1324*77c1e3ccSAndroid Build Coastguard Worker   uint8_t color_sensitivity[MAX_MB_PLANE - 1];
1325*77c1e3ccSAndroid Build Coastguard Worker   //! Coding block distortion value for uv/color, minimum over the inter modes.
1326*77c1e3ccSAndroid Build Coastguard Worker   int64_t min_dist_inter_uv;
1327*77c1e3ccSAndroid Build Coastguard Worker 
1328*77c1e3ccSAndroid Build Coastguard Worker   //! Threshold on the number of colors for testing palette mode.
1329*77c1e3ccSAndroid Build Coastguard Worker   int color_palette_thresh;
1330*77c1e3ccSAndroid Build Coastguard Worker 
1331*77c1e3ccSAndroid Build Coastguard Worker   //! The buffer used by search_tx_type() to swap dqcoeff in macroblockd_plane
1332*77c1e3ccSAndroid Build Coastguard Worker   // so we can keep dqcoeff of the best tx_type.
1333*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *dqcoeff_buf;
1334*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1335*77c1e3ccSAndroid Build Coastguard Worker 
1336*77c1e3ccSAndroid Build Coastguard Worker   /*****************************************************************************
1337*77c1e3ccSAndroid Build Coastguard Worker    * \name Misc
1338*77c1e3ccSAndroid Build Coastguard Worker    ****************************************************************************/
1339*77c1e3ccSAndroid Build Coastguard Worker   /**@{*/
1340*77c1e3ccSAndroid Build Coastguard Worker   //! Variance of the source frame.
1341*77c1e3ccSAndroid Build Coastguard Worker   unsigned int source_variance;
1342*77c1e3ccSAndroid Build Coastguard Worker   //! Flag to indicate coding block is zero sad.
1343*77c1e3ccSAndroid Build Coastguard Worker   int block_is_zero_sad;
1344*77c1e3ccSAndroid Build Coastguard Worker   //! Flag to indicate superblock ME in variance partition is determined to be
1345*77c1e3ccSAndroid Build Coastguard Worker   // good/reliable, and so the superblock MV will be tested in the
1346*77c1e3ccSAndroid Build Coastguard Worker   // nonrd_pickmode. This is only used for LAST_FRAME.
1347*77c1e3ccSAndroid Build Coastguard Worker   int sb_me_partition;
1348*77c1e3ccSAndroid Build Coastguard Worker   //! Flag to indicate to test the superblock MV for the coding block in the
1349*77c1e3ccSAndroid Build Coastguard Worker   // nonrd_pickmode.
1350*77c1e3ccSAndroid Build Coastguard Worker   int sb_me_block;
1351*77c1e3ccSAndroid Build Coastguard Worker   //! Motion vector from superblock MV derived from int_pro_motion() in
1352*77c1e3ccSAndroid Build Coastguard Worker   // the variance_partitioning.
1353*77c1e3ccSAndroid Build Coastguard Worker   int_mv sb_me_mv;
1354*77c1e3ccSAndroid Build Coastguard Worker   //! Flag to indicate if a fixed partition should be used, only if the
1355*77c1e3ccSAndroid Build Coastguard Worker   // speed feature rt_sf->use_fast_fixed_part is enabled.
1356*77c1e3ccSAndroid Build Coastguard Worker   int sb_force_fixed_part;
1357*77c1e3ccSAndroid Build Coastguard Worker   //! SSE of the current predictor.
1358*77c1e3ccSAndroid Build Coastguard Worker   unsigned int pred_sse[REF_FRAMES];
1359*77c1e3ccSAndroid Build Coastguard Worker   //! Prediction for ML based partition.
1360*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_RT_ML_PARTITIONING
1361*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(16, uint8_t, est_pred[128 * 128]);
1362*77c1e3ccSAndroid Build Coastguard Worker #endif
1363*77c1e3ccSAndroid Build Coastguard Worker   /**@}*/
1364*77c1e3ccSAndroid Build Coastguard Worker 
1365*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief NONE partition evaluated for merge.
1366*77c1e3ccSAndroid Build Coastguard Worker    *
1367*77c1e3ccSAndroid Build Coastguard Worker    * In variance based partitioning scheme, NONE & SPLIT partitions are
1368*77c1e3ccSAndroid Build Coastguard Worker    * evaluated to check the SPLIT can be merged as NONE. This flag signifies the
1369*77c1e3ccSAndroid Build Coastguard Worker    * partition is evaluated in the scheme.
1370*77c1e3ccSAndroid Build Coastguard Worker    */
1371*77c1e3ccSAndroid Build Coastguard Worker   int try_merge_partition;
1372*77c1e3ccSAndroid Build Coastguard Worker 
1373*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief Pointer to buffer which caches sub-block variances in a superblock.
1374*77c1e3ccSAndroid Build Coastguard Worker    *
1375*77c1e3ccSAndroid Build Coastguard Worker    *  Pointer to the array of structures to store source variance information of
1376*77c1e3ccSAndroid Build Coastguard Worker    *  each 4x4 sub-block in a superblock. Block4x4VarInfo structure is used to
1377*77c1e3ccSAndroid Build Coastguard Worker    *  store source variance and log of source variance of each 4x4 sub-block.
1378*77c1e3ccSAndroid Build Coastguard Worker    */
1379*77c1e3ccSAndroid Build Coastguard Worker   Block4x4VarInfo *src_var_info_of_4x4_sub_blocks;
1380*77c1e3ccSAndroid Build Coastguard Worker #ifndef NDEBUG
1381*77c1e3ccSAndroid Build Coastguard Worker   /*! \brief A hash to make sure av1_set_offsets is called */
1382*77c1e3ccSAndroid Build Coastguard Worker   SetOffsetsLoc last_set_offsets_loc;
1383*77c1e3ccSAndroid Build Coastguard Worker #endif  // NDEBUG
1384*77c1e3ccSAndroid Build Coastguard Worker 
1385*77c1e3ccSAndroid Build Coastguard Worker #if COLLECT_NONRD_PICK_MODE_STAT
1386*77c1e3ccSAndroid Build Coastguard Worker   mode_search_stat_nonrd ms_stat_nonrd;
1387*77c1e3ccSAndroid Build Coastguard Worker #endif  // COLLECT_NONRD_PICK_MODE_STAT
1388*77c1e3ccSAndroid Build Coastguard Worker 
1389*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Number of pixels in current thread that choose palette mode in the
1390*77c1e3ccSAndroid Build Coastguard Worker    * fast encoding stage for screen content tool detemination.
1391*77c1e3ccSAndroid Build Coastguard Worker    */
1392*77c1e3ccSAndroid Build Coastguard Worker   int palette_pixels;
1393*77c1e3ccSAndroid Build Coastguard Worker 
1394*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Pointer to the structure which stores the statistics used by
1395*77c1e3ccSAndroid Build Coastguard Worker    * sb-level multi-pass encoding.
1396*77c1e3ccSAndroid Build Coastguard Worker    */
1397*77c1e3ccSAndroid Build Coastguard Worker   struct SB_FIRST_PASS_STATS *sb_stats_cache;
1398*77c1e3ccSAndroid Build Coastguard Worker 
1399*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Pointer to the structure which stores the statistics used by
1400*77c1e3ccSAndroid Build Coastguard Worker    * first-pass when superblock is searched twice consecutively.
1401*77c1e3ccSAndroid Build Coastguard Worker    */
1402*77c1e3ccSAndroid Build Coastguard Worker   struct SB_FIRST_PASS_STATS *sb_fp_stats;
1403*77c1e3ccSAndroid Build Coastguard Worker 
1404*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_PARTITION_SEARCH_ORDER
1405*77c1e3ccSAndroid Build Coastguard Worker   /*!\brief Pointer to RD_STATS structure to be used in
1406*77c1e3ccSAndroid Build Coastguard Worker    * av1_rd_partition_search().
1407*77c1e3ccSAndroid Build Coastguard Worker    */
1408*77c1e3ccSAndroid Build Coastguard Worker   RD_STATS *rdcost;
1409*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_PARTITION_SEARCH_ORDER
1410*77c1e3ccSAndroid Build Coastguard Worker } MACROBLOCK;
1411*77c1e3ccSAndroid Build Coastguard Worker #undef SINGLE_REF_MODES
1412*77c1e3ccSAndroid Build Coastguard Worker 
1413*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
1414*77c1e3ccSAndroid Build Coastguard Worker // Zeroes out 'n_stats' elements in the array x->winner_mode_stats.
1415*77c1e3ccSAndroid Build Coastguard Worker // It only zeroes out what is necessary in 'color_index_map' (just the block
1416*77c1e3ccSAndroid Build Coastguard Worker // size, not the whole array).
zero_winner_mode_stats(BLOCK_SIZE bsize,int n_stats,WinnerModeStats * stats)1417*77c1e3ccSAndroid Build Coastguard Worker static inline void zero_winner_mode_stats(BLOCK_SIZE bsize, int n_stats,
1418*77c1e3ccSAndroid Build Coastguard Worker                                           WinnerModeStats *stats) {
1419*77c1e3ccSAndroid Build Coastguard Worker   // When winner mode stats are not required, the memory allocation is avoided
1420*77c1e3ccSAndroid Build Coastguard Worker   // for x->winner_mode_stats. The stats pointer will be NULL in such cases.
1421*77c1e3ccSAndroid Build Coastguard Worker   if (stats == NULL) return;
1422*77c1e3ccSAndroid Build Coastguard Worker 
1423*77c1e3ccSAndroid Build Coastguard Worker   const int block_height = block_size_high[bsize];
1424*77c1e3ccSAndroid Build Coastguard Worker   const int block_width = block_size_wide[bsize];
1425*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < n_stats; ++i) {
1426*77c1e3ccSAndroid Build Coastguard Worker     WinnerModeStats *const stat = &stats[i];
1427*77c1e3ccSAndroid Build Coastguard Worker     memset(&stat->mbmi, 0, sizeof(stat->mbmi));
1428*77c1e3ccSAndroid Build Coastguard Worker     memset(&stat->rd_cost, 0, sizeof(stat->rd_cost));
1429*77c1e3ccSAndroid Build Coastguard Worker     memset(&stat->rd, 0, sizeof(stat->rd));
1430*77c1e3ccSAndroid Build Coastguard Worker     memset(&stat->rate_y, 0, sizeof(stat->rate_y));
1431*77c1e3ccSAndroid Build Coastguard Worker     memset(&stat->rate_uv, 0, sizeof(stat->rate_uv));
1432*77c1e3ccSAndroid Build Coastguard Worker     // Do not reset the whole array as it is CPU intensive.
1433*77c1e3ccSAndroid Build Coastguard Worker     memset(&stat->color_index_map, 0,
1434*77c1e3ccSAndroid Build Coastguard Worker            block_width * block_height * sizeof(stat->color_index_map[0]));
1435*77c1e3ccSAndroid Build Coastguard Worker     memset(&stat->mode_index, 0, sizeof(stat->mode_index));
1436*77c1e3ccSAndroid Build Coastguard Worker   }
1437*77c1e3ccSAndroid Build Coastguard Worker }
1438*77c1e3ccSAndroid Build Coastguard Worker 
is_rect_tx_allowed_bsize(BLOCK_SIZE bsize)1439*77c1e3ccSAndroid Build Coastguard Worker static inline int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) {
1440*77c1e3ccSAndroid Build Coastguard Worker   static const char LUT[BLOCK_SIZES_ALL] = {
1441*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_4X4
1442*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_4X8
1443*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_8X4
1444*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_8X8
1445*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_8X16
1446*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_16X8
1447*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_16X16
1448*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_16X32
1449*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_32X16
1450*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_32X32
1451*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_32X64
1452*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_64X32
1453*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_64X64
1454*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_64X128
1455*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_128X64
1456*77c1e3ccSAndroid Build Coastguard Worker     0,  // BLOCK_128X128
1457*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_4X16
1458*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_16X4
1459*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_8X32
1460*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_32X8
1461*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_16X64
1462*77c1e3ccSAndroid Build Coastguard Worker     1,  // BLOCK_64X16
1463*77c1e3ccSAndroid Build Coastguard Worker   };
1464*77c1e3ccSAndroid Build Coastguard Worker 
1465*77c1e3ccSAndroid Build Coastguard Worker   return LUT[bsize];
1466*77c1e3ccSAndroid Build Coastguard Worker }
1467*77c1e3ccSAndroid Build Coastguard Worker 
is_rect_tx_allowed(const MACROBLOCKD * xd,const MB_MODE_INFO * mbmi)1468*77c1e3ccSAndroid Build Coastguard Worker static inline int is_rect_tx_allowed(const MACROBLOCKD *xd,
1469*77c1e3ccSAndroid Build Coastguard Worker                                      const MB_MODE_INFO *mbmi) {
1470*77c1e3ccSAndroid Build Coastguard Worker   return is_rect_tx_allowed_bsize(mbmi->bsize) &&
1471*77c1e3ccSAndroid Build Coastguard Worker          !xd->lossless[mbmi->segment_id];
1472*77c1e3ccSAndroid Build Coastguard Worker }
1473*77c1e3ccSAndroid Build Coastguard Worker 
tx_size_to_depth(TX_SIZE tx_size,BLOCK_SIZE bsize)1474*77c1e3ccSAndroid Build Coastguard Worker static inline int tx_size_to_depth(TX_SIZE tx_size, BLOCK_SIZE bsize) {
1475*77c1e3ccSAndroid Build Coastguard Worker   TX_SIZE ctx_size = max_txsize_rect_lookup[bsize];
1476*77c1e3ccSAndroid Build Coastguard Worker   int depth = 0;
1477*77c1e3ccSAndroid Build Coastguard Worker   while (tx_size != ctx_size) {
1478*77c1e3ccSAndroid Build Coastguard Worker     depth++;
1479*77c1e3ccSAndroid Build Coastguard Worker     ctx_size = sub_tx_size_map[ctx_size];
1480*77c1e3ccSAndroid Build Coastguard Worker     assert(depth <= MAX_TX_DEPTH);
1481*77c1e3ccSAndroid Build Coastguard Worker   }
1482*77c1e3ccSAndroid Build Coastguard Worker   return depth;
1483*77c1e3ccSAndroid Build Coastguard Worker }
1484*77c1e3ccSAndroid Build Coastguard Worker 
set_blk_skip(uint8_t txb_skip[],int plane,int blk_idx,int skip)1485*77c1e3ccSAndroid Build Coastguard Worker static inline void set_blk_skip(uint8_t txb_skip[], int plane, int blk_idx,
1486*77c1e3ccSAndroid Build Coastguard Worker                                 int skip) {
1487*77c1e3ccSAndroid Build Coastguard Worker   if (skip)
1488*77c1e3ccSAndroid Build Coastguard Worker     txb_skip[blk_idx] |= 1UL << plane;
1489*77c1e3ccSAndroid Build Coastguard Worker   else
1490*77c1e3ccSAndroid Build Coastguard Worker     txb_skip[blk_idx] &= ~(1UL << plane);
1491*77c1e3ccSAndroid Build Coastguard Worker #ifndef NDEBUG
1492*77c1e3ccSAndroid Build Coastguard Worker   // Set chroma planes to uninitialized states when luma is set to check if
1493*77c1e3ccSAndroid Build Coastguard Worker   // it will be set later
1494*77c1e3ccSAndroid Build Coastguard Worker   if (plane == 0) {
1495*77c1e3ccSAndroid Build Coastguard Worker     txb_skip[blk_idx] |= 1UL << (1 + 4);
1496*77c1e3ccSAndroid Build Coastguard Worker     txb_skip[blk_idx] |= 1UL << (2 + 4);
1497*77c1e3ccSAndroid Build Coastguard Worker   }
1498*77c1e3ccSAndroid Build Coastguard Worker 
1499*77c1e3ccSAndroid Build Coastguard Worker   // Clear the initialization checking bit
1500*77c1e3ccSAndroid Build Coastguard Worker   txb_skip[blk_idx] &= ~(1UL << (plane + 4));
1501*77c1e3ccSAndroid Build Coastguard Worker #endif
1502*77c1e3ccSAndroid Build Coastguard Worker }
1503*77c1e3ccSAndroid Build Coastguard Worker 
is_blk_skip(uint8_t * txb_skip,int plane,int blk_idx)1504*77c1e3ccSAndroid Build Coastguard Worker static inline int is_blk_skip(uint8_t *txb_skip, int plane, int blk_idx) {
1505*77c1e3ccSAndroid Build Coastguard Worker #ifndef NDEBUG
1506*77c1e3ccSAndroid Build Coastguard Worker   // Check if this is initialized
1507*77c1e3ccSAndroid Build Coastguard Worker   assert(!(txb_skip[blk_idx] & (1UL << (plane + 4))));
1508*77c1e3ccSAndroid Build Coastguard Worker 
1509*77c1e3ccSAndroid Build Coastguard Worker   // The magic number is 0x77, this is to test if there is garbage data
1510*77c1e3ccSAndroid Build Coastguard Worker   assert((txb_skip[blk_idx] & 0x88) == 0);
1511*77c1e3ccSAndroid Build Coastguard Worker #endif
1512*77c1e3ccSAndroid Build Coastguard Worker   return (txb_skip[blk_idx] >> plane) & 1;
1513*77c1e3ccSAndroid Build Coastguard Worker }
1514*77c1e3ccSAndroid Build Coastguard Worker 
1515*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
1516*77c1e3ccSAndroid Build Coastguard Worker 
1517*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
1518*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
1519*77c1e3ccSAndroid Build Coastguard Worker #endif
1520*77c1e3ccSAndroid Build Coastguard Worker 
1521*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AV1_ENCODER_BLOCK_H_
1522