blob: f72d11a6cb4b44b4bf45cdb607812860a8fbd66e [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
chiyotsaic2f38412020-06-10 16:07:21 -070012/*! \file
13 * Declares various structs used to encode the current partition block.
14 */
James Zerne1cbb132018-08-22 14:10:36 -070015#ifndef AOM_AV1_ENCODER_BLOCK_H_
16#define AOM_AV1_ENCODER_BLOCK_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070017
chiyotsai681e4942020-09-30 11:08:17 -070018#include "av1/common/blockd.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070019#include "av1/common/entropymv.h"
20#include "av1/common/entropy.h"
chiyotsai85d715a2020-05-02 15:10:33 -070021#include "av1/common/enums.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070022#include "av1/common/mvref_common.h"
chiyotsai36035d12019-06-19 17:39:48 -070023
Ravi Chaudharyb61cdea2019-07-05 15:01:20 +053024#include "av1/encoder/enc_enums.h"
chiyotsai36035d12019-06-19 17:39:48 -070025#if !CONFIG_REALTIME_ONLY
26#include "av1/encoder/partition_cnn_weights.h"
27#endif
28
Hui Su1ddf2312017-08-19 15:21:34 -070029#include "av1/encoder/hash.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070030
31#ifdef __cplusplus
32extern "C" {
33#endif
34
Yunqing Wangb17bfa42020-08-14 14:50:33 -070035//! Minimum linear dimension of a tpl block
36#define MIN_TPL_BSIZE_1D 16
37//! Maximum number of tpl block in a super block
38#define MAX_TPL_BLK_IN_SB (MAX_SB_SIZE / MIN_TPL_BSIZE_1D)
chiyotsaic2f38412020-06-10 16:07:21 -070039//! Number of intra winner modes kept
Cherma Rajan Ad71ace62019-11-25 12:58:37 +053040#define MAX_WINNER_MODE_COUNT_INTRA 3
chiyotsaic2f38412020-06-10 16:07:21 -070041//! Number of inter winner modes kept
Cherma Rajan Ad71ace62019-11-25 12:58:37 +053042#define MAX_WINNER_MODE_COUNT_INTER 1
chiyotsaic2f38412020-06-10 16:07:21 -070043//! Number of txfm hash records kept for the partition block.
44#define RD_RECORD_BUFFER_LEN 8
45//! Number of txfm hash records kept for the txfm block.
46#define TX_SIZE_RD_RECORD_BUFFER_LEN 256
chiyotsaiff73c532020-04-21 12:50:12 -070047
chiyotsaic2f38412020-06-10 16:07:21 -070048/*! \brief Superblock level encoder info
49 *
50 * SuperblockEnc stores superblock level information used by the encoder for
51 * more efficient encoding. Currently this is mostly used to store TPL data
52 * for the current superblock.
53 */
chiyotsaiff73c532020-04-21 12:50:12 -070054typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -070055 //! Maximum partition size for the sb.
chiyotsai68eefbe2020-05-01 15:07:58 -070056 BLOCK_SIZE min_partition_size;
chiyotsaic2f38412020-06-10 16:07:21 -070057 //! Minimum partition size for the sb.
chiyotsai68eefbe2020-05-01 15:07:58 -070058 BLOCK_SIZE max_partition_size;
59
chiyotsaic2f38412020-06-10 16:07:21 -070060 /*****************************************************************************
61 * \name TPL Info
62 *
Yunqing Wangb17bfa42020-08-14 14:50:33 -070063 * Information gathered from tpl_model at tpl block precision for the
chiyotsaic2f38412020-06-10 16:07:21 -070064 * superblock to speed up the encoding process..
65 ****************************************************************************/
66 /**@{*/
67 //! Number of TPL blocks in this superblock.
chiyotsaiff73c532020-04-21 12:50:12 -070068 int tpl_data_count;
chiyotsaic2f38412020-06-10 16:07:21 -070069 //! TPL's estimate of inter cost for each tpl block.
Yunqing Wangb17bfa42020-08-14 14:50:33 -070070 int64_t tpl_inter_cost[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
chiyotsaic2f38412020-06-10 16:07:21 -070071 //! TPL's estimate of tpl cost for each tpl block.
Yunqing Wangb17bfa42020-08-14 14:50:33 -070072 int64_t tpl_intra_cost[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
chiyotsaic2f38412020-06-10 16:07:21 -070073 //! Motion vectors found by TPL model for each tpl block.
Yunqing Wangb17bfa42020-08-14 14:50:33 -070074 int_mv tpl_mv[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB][INTER_REFS_PER_FRAME];
chiyotsaic2f38412020-06-10 16:07:21 -070075 //! TPL's stride for the arrays in this struct.
chiyotsaiff73c532020-04-21 12:50:12 -070076 int tpl_stride;
chiyotsaic2f38412020-06-10 16:07:21 -070077 /**@}*/
chiyotsaiff73c532020-04-21 12:50:12 -070078} SuperBlockEnc;
79
chiyotsaic2f38412020-06-10 16:07:21 -070080/*! \brief Stores the best performing modes.
81 */
Cherma Rajan A835f7a62019-09-25 11:04:39 +053082typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -070083 //! The mbmi used to reconstruct the winner mode.
Cherma Rajan A835f7a62019-09-25 11:04:39 +053084 MB_MODE_INFO mbmi;
chiyotsaic2f38412020-06-10 16:07:21 -070085 //! Rdstats of the winner mode.
Cherma Rajan Ad71ace62019-11-25 12:58:37 +053086 RD_STATS rd_cost;
chiyotsaic2f38412020-06-10 16:07:21 -070087 //! Rdcost of the winner mode
Cherma Rajan A835f7a62019-09-25 11:04:39 +053088 int64_t rd;
chiyotsaic2f38412020-06-10 16:07:21 -070089 //! Luma rate of the winner mode.
Cherma Rajan Ad71ace62019-11-25 12:58:37 +053090 int rate_y;
chiyotsaic2f38412020-06-10 16:07:21 -070091 //! Chroma rate of the winner mode.
Cherma Rajan Ad71ace62019-11-25 12:58:37 +053092 int rate_uv;
chiyotsaic2f38412020-06-10 16:07:21 -070093 //! The color map needed to reconstruct palette mode.
94 uint8_t color_index_map[MAX_SB_SQUARE];
95 //! The current winner mode.
Cherma Rajan Ad71ace62019-11-25 12:58:37 +053096 THR_MODES mode_index;
Cherma Rajan A835f7a62019-09-25 11:04:39 +053097} WinnerModeStats;
Yue Chenbd934232019-08-05 14:23:39 -070098
chiyotsaic2f38412020-06-10 16:07:21 -070099/*! \brief Each source plane of the current macroblock
100 *
101 * This struct also stores the txfm buffers and quantizer settings.
102 */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103typedef struct macroblock_plane {
chiyotsaic2f38412020-06-10 16:07:21 -0700104 //! Stores source - pred so the txfm can be computed later
Ravi Chaudharyd4a5a502019-06-07 12:13:32 +0530105 DECLARE_ALIGNED(32, int16_t, src_diff[MAX_SB_SQUARE]);
chiyotsaic2f38412020-06-10 16:07:21 -0700106 //! Dequantized coefficients
Urvang Joshi9543ad72020-04-17 16:59:46 -0700107 tran_low_t *dqcoeff;
chiyotsaic2f38412020-06-10 16:07:21 -0700108 //! Quantized coefficients
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109 tran_low_t *qcoeff;
chiyotsaic2f38412020-06-10 16:07:21 -0700110 //! Transformed coefficients
Yaowu Xuc27fc142016-08-22 16:08:15 -0700111 tran_low_t *coeff;
chiyotsaic2f38412020-06-10 16:07:21 -0700112 //! Location of the end of qcoeff (end of block).
Yaowu Xuc27fc142016-08-22 16:08:15 -0700113 uint16_t *eobs;
chiyotsaic2f38412020-06-10 16:07:21 -0700114 //! Contexts used to code the transform coefficients.
Angie Chiang74e23072017-03-24 14:54:23 -0700115 uint8_t *txb_entropy_ctx;
chiyotsaic2f38412020-06-10 16:07:21 -0700116 //! A buffer containing the source frame.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700117 struct buf_2d src;
118
chiyotsaic2f38412020-06-10 16:07:21 -0700119 /*! \name Quantizer Settings
120 *
121 * \attention These are used/accessed only in the quantization process.
122 * RDO does not and *must not* depend on any of these values.
123 * All values below share the coefficient scale/shift used in TX.
124 */
125 /**@{*/
126 //! Quantization step size used by AV1_XFORM_QUANT_FP.
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400127 const int16_t *quant_fp_QTX;
chiyotsaic2f38412020-06-10 16:07:21 -0700128 //! Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_FP.
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400129 const int16_t *round_fp_QTX;
chiyotsaic2f38412020-06-10 16:07:21 -0700130 //! Quantization step size used by AV1_XFORM_QUANT_B.
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400131 const int16_t *quant_QTX;
chiyotsaic2f38412020-06-10 16:07:21 -0700132 //! Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_B.
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400133 const int16_t *round_QTX;
chiyotsaic2f38412020-06-10 16:07:21 -0700134 //! Scale factor to shift coefficients toward zero. Only used by QUANT_B.
135 const int16_t *quant_shift_QTX;
136 //! Size of the quantization bin around 0. Only Used by QUANT_B
137 const int16_t *zbin_QTX;
138 //! Dequantizer
Monty Montgomery125c0fc2017-10-26 00:44:35 -0400139 const int16_t *dequant_QTX;
chiyotsaic2f38412020-06-10 16:07:21 -0700140 /**@}*/
Yaowu Xuc27fc142016-08-22 16:08:15 -0700141} MACROBLOCK_PLANE;
142
chiyotsaic2f38412020-06-10 16:07:21 -0700143/*! \brief Costs for encoding the coefficients within a level.
144 *
145 * Covers everything including txb_skip, eob, dc_sign,
146 */
Jingning Handfd72322017-08-09 14:04:12 -0700147typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700148 //! Cost to skip txfm for the current txfm block.
Jingning Handfd72322017-08-09 14:04:12 -0700149 int txb_skip_cost[TXB_SKIP_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700150 /*! \brief Cost for encoding the base_eob of a level.
151 *
152 * Decoder uses base_eob to derive the base_level as base_eob := base_eob+1.
153 */
Dake He3fe369c2017-11-16 17:56:44 -0800154 int base_eob_cost[SIG_COEF_CONTEXTS_EOB][3];
chiyotsaic2f38412020-06-10 16:07:21 -0700155 /*! \brief Cost for encoding the base level of a coefficient.
156 *
157 * Decoder derives coeff_base as coeff_base := base_eob + 1.
158 */
Wenyao Liuf7e53752019-01-22 17:34:44 +0800159 int base_cost[SIG_COEF_CONTEXTS][8];
chiyotsaic2f38412020-06-10 16:07:21 -0700160 /*! \brief Cost for encoding the last non-zero coefficient.
161 *
162 * Eob is derived from eob_extra at the decoder as eob := eob_extra + 1
163 */
Angie Chiang7ab884e2017-10-18 15:57:12 -0700164 int eob_extra_cost[EOB_COEF_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700165 //! Cost for encoding the dc_sign
Jingning Handfd72322017-08-09 14:04:12 -0700166 int dc_sign_cost[DC_SIGN_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700167 //! Cost for encoding an increment to the coefficient
Wenyao Liuf7e53752019-01-22 17:34:44 +0800168 int lps_cost[LEVEL_CONTEXTS][COEFF_BASE_RANGE + 1 + COEFF_BASE_RANGE + 1];
Jingning Handfd72322017-08-09 14:04:12 -0700169} LV_MAP_COEFF_COST;
Jingning Hanf5a4d3b2017-08-27 23:01:19 -0700170
chiyotsaic2f38412020-06-10 16:07:21 -0700171/*! \brief Costs for encoding the eob.
172 */
Johannb0ef6ff2018-02-08 14:32:21 -0800173typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700174 //! eob_cost.
Johannb0ef6ff2018-02-08 14:32:21 -0800175 int eob_cost[2][11];
176} LV_MAP_EOB_COST;
Dake He0db7d0e2017-12-21 15:23:20 -0800177
chiyotsaic2f38412020-06-10 16:07:21 -0700178/*! \brief Stores the transforms coefficients for the whole superblock.
179 */
Jingning Hanf5a4d3b2017-08-27 23:01:19 -0700180typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700181 //! The transformed coefficients.
Jayasanker J2350ca32020-09-10 23:49:00 +0530182 tran_low_t *tcoeff[MAX_MB_PLANE];
chiyotsaic2f38412020-06-10 16:07:21 -0700183 //! Where the transformed coefficients end.
Jayasanker J2350ca32020-09-10 23:49:00 +0530184 uint16_t *eobs[MAX_MB_PLANE];
chiyotsaic2f38412020-06-10 16:07:21 -0700185 /*! \brief Transform block entropy contexts.
186 *
187 * Each element is used as a bit field.
188 * - Bits 0~3: txb_skip_ctx
189 * - Bits 4~5: dc_sign_ctx.
190 */
Jayasanker J2350ca32020-09-10 23:49:00 +0530191 uint8_t *entropy_ctx[MAX_MB_PLANE];
Jingning Hanf5a4d3b2017-08-27 23:01:19 -0700192} CB_COEFF_BUFFER;
Jingning Handfd72322017-08-09 14:04:12 -0700193
chiyotsaic2f38412020-06-10 16:07:21 -0700194/*! \brief Extended mode info derived from mbmi.
195 */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196typedef struct {
Angie Chiangc484abe2017-03-20 15:43:11 -0700197 // TODO(angiebird): Reduce the buffer size according to sb_type
chiyotsaic2f38412020-06-10 16:07:21 -0700198 //! The reference mv list for the current block.
Ravi Chaudharyfa73e202019-08-19 12:41:26 +0530199 CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE];
chiyotsaic2f38412020-06-10 16:07:21 -0700200 //! The weights used to compute the ref mvs.
Ravi Chaudharyfa73e202019-08-19 12:41:26 +0530201 uint16_t weight[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE];
chiyotsaic2f38412020-06-10 16:07:21 -0700202 //! Number of ref mvs in the drl.
Satish Kumar Suman69e93292018-11-28 16:05:33 +0530203 uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
chiyotsaic2f38412020-06-10 16:07:21 -0700204 //! Global mvs
205 int_mv global_mvs[REF_FRAMES];
206 //! Context used to encode the current mode.
207 int16_t mode_context[MODE_CTX_REF_FRAMES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700208} MB_MODE_INFO_EXT;
209
chiyotsaic2f38412020-06-10 16:07:21 -0700210/*! \brief Stores best extended mode information at frame level.
211 *
212 * The frame level in here is used in bitstream preparation stage. The
213 * information in \ref MB_MODE_INFO_EXT are copied to this struct to save
214 * memory.
215 */
Remya0cce44c2019-08-16 11:57:24 +0530216typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700217 //! \copydoc MB_MODE_INFO_EXT::ref_mv_stack
Ravi Chaudharyfa73e202019-08-19 12:41:26 +0530218 CANDIDATE_MV ref_mv_stack[USABLE_REF_MV_STACK_SIZE];
chiyotsaic2f38412020-06-10 16:07:21 -0700219 //! \copydoc MB_MODE_INFO_EXT::weight
Ravi Chaudharyfa73e202019-08-19 12:41:26 +0530220 uint16_t weight[USABLE_REF_MV_STACK_SIZE];
chiyotsaic2f38412020-06-10 16:07:21 -0700221 //! \copydoc MB_MODE_INFO_EXT::ref_mv_count
Remya0cce44c2019-08-16 11:57:24 +0530222 uint8_t ref_mv_count;
chiyotsaic2f38412020-06-10 16:07:21 -0700223 // TODO(Ravi/Remya): Reduce the buffer size of global_mvs
224 //! \copydoc MB_MODE_INFO_EXT::global_mvs
225 int_mv global_mvs[REF_FRAMES];
226 //! \copydoc MB_MODE_INFO_EXT::mode_context
227 int16_t mode_context;
228 //! Offset of current coding block's coeff buffer relative to the sb.
Jayasanker J2350ca32020-09-10 23:49:00 +0530229 uint16_t cb_offset[PLANE_TYPES];
Remya0cce44c2019-08-16 11:57:24 +0530230} MB_MODE_INFO_EXT_FRAME;
231
chiyotsaic2f38412020-06-10 16:07:21 -0700232/*! \brief Txfm search results for a partition
233 */
Alex Converse0fa0f422017-04-24 12:51:14 -0700234typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700235 //! Txfm size used if the current mode is intra mode.
Hui Su1ddf2312017-08-19 15:21:34 -0700236 TX_SIZE tx_size;
chiyotsaic2f38412020-06-10 16:07:21 -0700237 //! Txfm sizes used if the current mode is inter mode.
Hui Su7167d952018-02-01 16:33:12 -0800238 TX_SIZE inter_tx_size[INTER_TX_SIZE_BUF_LEN];
chiyotsaic2f38412020-06-10 16:07:21 -0700239 //! Map showing which txfm block skips the txfm process.
Hui Suf4b79c72018-03-22 13:14:36 -0700240 uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
chiyotsaic2f38412020-06-10 16:07:21 -0700241 //! Map showing the txfm types for each blcok.
Hui Su52b7ddc2019-10-10 16:27:16 -0700242 uint8_t tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE];
chiyotsaic2f38412020-06-10 16:07:21 -0700243 //! Rd_stats for the whole partition block.
Hui Su1ddf2312017-08-19 15:21:34 -0700244 RD_STATS rd_stats;
chiyotsaic2f38412020-06-10 16:07:21 -0700245 //! Hash value of the current record.
Hui Su1ddf2312017-08-19 15:21:34 -0700246 uint32_t hash_value;
Hui Su6cb17c12018-03-09 12:56:20 -0800247} MB_RD_INFO;
Hui Su1ddf2312017-08-19 15:21:34 -0700248
chiyotsaic2f38412020-06-10 16:07:21 -0700249/*! \brief Hash records of txfm search results for the partition block.
250 */
Hui Su1ddf2312017-08-19 15:21:34 -0700251typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700252 //! Circular buffer that stores the txfm search results.
Hui Su6cb17c12018-03-09 12:56:20 -0800253 MB_RD_INFO tx_rd_info[RD_RECORD_BUFFER_LEN]; // Circular buffer.
chiyotsaic2f38412020-06-10 16:07:21 -0700254 //! Index to insert the newest \ref TXB_RD_INFO.
Hui Su1ddf2312017-08-19 15:21:34 -0700255 int index_start;
chiyotsaic2f38412020-06-10 16:07:21 -0700256 //! Number of info stored in this record.
Hui Su1ddf2312017-08-19 15:21:34 -0700257 int num;
chiyotsaic2f38412020-06-10 16:07:21 -0700258 //! Hash function
259 CRC32C crc_calculator;
Hui Su6cb17c12018-03-09 12:56:20 -0800260} MB_RD_RECORD;
Hui Su1ddf2312017-08-19 15:21:34 -0700261
chiyotsaic2f38412020-06-10 16:07:21 -0700262/*! \brief Txfm search results for a tx block.
263 */
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700264typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700265 //! Distortion after the txfm process
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700266 int64_t dist;
chiyotsaic2f38412020-06-10 16:07:21 -0700267 //! SSE of the prediction before the txfm process
Jingning Han73bc2aa2018-02-02 14:31:39 -0800268 int64_t sse;
chiyotsaic2f38412020-06-10 16:07:21 -0700269 //! Rate used to encode the txfm.
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700270 int rate;
chiyotsaic2f38412020-06-10 16:07:21 -0700271 //! Location of the end of non-zero entries.
Hui Su8c2b9132017-12-09 10:40:15 -0800272 uint16_t eob;
chiyotsaic2f38412020-06-10 16:07:21 -0700273 //! Transform type used on the current block.
Jingning Han73bc2aa2018-02-02 14:31:39 -0800274 TX_TYPE tx_type;
chiyotsaic2f38412020-06-10 16:07:21 -0700275 //! Unknown usage
Jingning Han45027c62017-12-11 11:47:15 -0800276 uint16_t entropy_context;
chiyotsaic2f38412020-06-10 16:07:21 -0700277 //! Context used to code the coefficients.
Jingning Hand7e99112017-12-13 09:47:45 -0800278 uint8_t txb_entropy_ctx;
chiyotsaic2f38412020-06-10 16:07:21 -0700279 //! Whether the current info block contains valid info
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700280 uint8_t valid;
chiyotsaic2f38412020-06-10 16:07:21 -0700281 //! Unused
282 uint8_t fast;
283 //! Whether trellis optimization is done.
Sachin Kumar Garg4ec28cb2019-06-06 19:33:58 +0530284 uint8_t perform_block_coeff_opt;
Hui Su6cb17c12018-03-09 12:56:20 -0800285} TXB_RD_INFO;
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700286
chiyotsaic2f38412020-06-10 16:07:21 -0700287/*! \brief Hash records of txfm search result for each tx block.
288 */
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700289typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700290 //! The hash values.
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700291 uint32_t hash_vals[TX_SIZE_RD_RECORD_BUFFER_LEN];
chiyotsaic2f38412020-06-10 16:07:21 -0700292 //! The txfm search results
Hui Su6cb17c12018-03-09 12:56:20 -0800293 TXB_RD_INFO tx_rd_info[TX_SIZE_RD_RECORD_BUFFER_LEN];
chiyotsaic2f38412020-06-10 16:07:21 -0700294 //! Index to insert the newest \ref TXB_RD_INFO.
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700295 int index_start;
chiyotsaic2f38412020-06-10 16:07:21 -0700296 //! Number of info stored in this record.
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700297 int num;
Hui Su6cb17c12018-03-09 12:56:20 -0800298} TXB_RD_RECORD;
Alexander Bokovc5ddf062017-10-17 16:41:46 -0700299
chiyotsaic2f38412020-06-10 16:07:21 -0700300//! Number of compound rd stats
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530301#define MAX_COMP_RD_STATS 64
chiyotsaic2f38412020-06-10 16:07:21 -0700302/*! \brief Rdcost stats in compound mode.
303 */
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530304typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700305 //! Rate of the compound modes.
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530306 int32_t rate[COMPOUND_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700307 //! Distortion of the compound modes.
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530308 int64_t dist[COMPOUND_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700309 //! Estimated rate of the compound modes.
Venkat457e32e2019-12-19 17:44:05 +0530310 int32_t model_rate[COMPOUND_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700311 //! Estimated distortion of the compound modes.
Venkat457e32e2019-12-19 17:44:05 +0530312 int64_t model_dist[COMPOUND_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700313 //! Rate need to send the mask type.
venkat sanampudic88148e2020-01-03 12:57:28 +0530314 int comp_rs2[COMPOUND_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700315 //! Motion vector for each predictor.
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530316 int_mv mv[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700317 //! Ref frame for each predictor.
Hui Sud06ff662019-01-23 16:53:05 -0800318 MV_REFERENCE_FRAME ref_frames[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700319 //! Current prediction mode.
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530320 PREDICTION_MODE mode;
chiyotsaic2f38412020-06-10 16:07:21 -0700321 //! Current interpolation filter.
Ravi Chaudhary1e4f94b2019-06-20 16:19:49 +0530322 int_interpfilters filter;
chiyotsaic2f38412020-06-10 16:07:21 -0700323 //! Refmv index in the drl.
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530324 int ref_mv_idx;
chiyotsaic2f38412020-06-10 16:07:21 -0700325 //! Whether the predictors are GLOBALMV.
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530326 int is_global[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700327 //! Current parameters for interinter mode.
venkat sanampudic88148e2020-01-03 12:57:28 +0530328 INTERINTER_COMPOUND_DATA interinter_comp;
Ranjit Kumar Tulabandua1ebb572018-12-24 12:13:54 +0530329} COMP_RD_STATS;
330
chiyotsaic2f38412020-06-10 16:07:21 -0700331/*! \brief Contains buffers used to speed up rdopt for obmc.
332 *
333 * See the comments for calc_target_weighted_pred for details.
334 */
Hui Su38711e72019-06-11 10:49:47 -0700335typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700336 /*! \brief A new source weighted with the above and left predictors.
337 *
338 * Used to efficiently construct multiple obmc predictors during rdopt.
339 */
chiyotsaid2b12212020-04-28 20:57:19 -0700340 int32_t *wsrc;
chiyotsaic2f38412020-06-10 16:07:21 -0700341 /*! \brief A new mask constructed from the original horz/vert mask.
342 *
343 * \copydetails wsrc
344 */
chiyotsaid2b12212020-04-28 20:57:19 -0700345 int32_t *mask;
chiyotsaic2f38412020-06-10 16:07:21 -0700346 /*! \brief Prediction from the up predictor.
347 *
348 * Used to build the obmc predictor.
349 */
chiyotsaid2b12212020-04-28 20:57:19 -0700350 uint8_t *above_pred;
chiyotsaic2f38412020-06-10 16:07:21 -0700351 /*! \brief Prediction from the up predictor.
352 *
353 * \copydetails above_pred
354 */
chiyotsaid2b12212020-04-28 20:57:19 -0700355 uint8_t *left_pred;
356} OBMCBuffer;
357
chiyotsaic2f38412020-06-10 16:07:21 -0700358/*! \brief Contains color maps used in palette mode.
359 */
360typedef struct {
361 //! The best color map found.
362 uint8_t best_palette_color_map[MAX_PALETTE_SQUARE];
363 //! A temporary buffer used for k-means clustering.
364 int kmeans_data_buf[2 * MAX_PALETTE_SQUARE];
365} PALETTE_BUFFER;
366
367/*! \brief Contains buffers used by av1_compound_type_rd()
368 *
369 * For sizes and alignment of these arrays, refer to
370 * alloc_compound_type_rd_buffers() function.
371 */
372typedef struct {
373 //! First prediction.
374 uint8_t *pred0;
375 //! Second prediction.
376 uint8_t *pred1;
377 //! Source - first prediction.
378 int16_t *residual1;
379 //! Second prediction - first prediction.
380 int16_t *diff10;
381 //! Backup of the best segmentation mask.
382 uint8_t *tmp_best_mask_buf;
383} CompoundTypeRdBuffers;
384
385/*! \brief Holds some parameters related to partitioning schemes in AV1.
386 */
chiyotsai68eefbe2020-05-01 15:07:58 -0700387// TODO(chiyotsai@google.com): Consolidate this with SIMPLE_MOTION_DATA_TREE
388typedef struct {
389#if !CONFIG_REALTIME_ONLY
390 // The following 4 parameters are used for cnn-based partitioning on intra
391 // frame.
chiyotsaic2f38412020-06-10 16:07:21 -0700392 /*! \brief Current index on the partition block quad tree.
393 *
394 * Used to index into the cnn buffer for partition decision.
395 */
chiyotsai68eefbe2020-05-01 15:07:58 -0700396 int quad_tree_idx;
chiyotsaic2f38412020-06-10 16:07:21 -0700397 //! Whether the CNN buffer contains valid output.
chiyotsai68eefbe2020-05-01 15:07:58 -0700398 int cnn_output_valid;
chiyotsaic2f38412020-06-10 16:07:21 -0700399 //! A buffer used by our segmentation CNN for intra-frame partitioning.
chiyotsai68eefbe2020-05-01 15:07:58 -0700400 float cnn_buffer[CNN_OUT_BUF_SIZE];
chiyotsaic2f38412020-06-10 16:07:21 -0700401 //! log of the quantization parameter of the ancestor BLOCK_64X64.
chiyotsai68eefbe2020-05-01 15:07:58 -0700402 float log_q;
403#endif
404
chiyotsaic2f38412020-06-10 16:07:21 -0700405 /*! \brief Variance of the subblocks in the superblock.
406 *
407 * This is used by rt mode for variance based partitioning.
408 * The indices corresponds to the following block sizes:
409 * - 0 - 128x128
410 * - 1-2 - 128x64
411 * - 3-4 - 64x128
412 * - 5-8 - 64x64
413 * - 9-16 - 64x32
414 * - 17-24 - 32x64
415 * - 25-40 - 32x32
416 * - 41-104 - 16x16
417 */
chiyotsai68eefbe2020-05-01 15:07:58 -0700418 uint8_t variance_low[105];
419} PartitionSearchInfo;
420
chiyotsaic2f38412020-06-10 16:07:21 -0700421/*! \brief Defines the parameters used to perform txfm search.
422 *
423 * For the most part, this determines how various speed features are used.
424 */
chiyotsaia36d9002020-04-29 16:48:21 -0700425typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700426 /*! \brief Whether to limit the intra txfm search type to the default txfm.
427 *
428 * This could either be a result of either sequence parameter or speed
429 * features.
430 */
chiyotsaia36d9002020-04-29 16:48:21 -0700431 int use_default_intra_tx_type;
chiyotsaic2f38412020-06-10 16:07:21 -0700432 /*! \brief Whether to limit the inter txfm search type to the default txfm.
433 *
434 * \copydetails use_default_intra_tx_type
435 */
chiyotsaia36d9002020-04-29 16:48:21 -0700436 int use_default_inter_tx_type;
437
chiyotsaic2f38412020-06-10 16:07:21 -0700438 //! Whether to prune 2d transforms based on 1d transform results.
chiyotsaia36d9002020-04-29 16:48:21 -0700439 int prune_2d_txfm_mode;
440
chiyotsaic2f38412020-06-10 16:07:21 -0700441 /*! \brief Variable from \ref WinnerModeParams based on current eval mode.
442 *
443 * See the documentation for \ref WinnerModeParams for more detail.
444 */
Akshata Jadhavbd0eb432021-01-13 14:33:47 +0530445 unsigned int coeff_opt_thresholds[2];
446 /*! \copydoc coeff_opt_thresholds */
chiyotsaia36d9002020-04-29 16:48:21 -0700447 unsigned int tx_domain_dist_threshold;
Akshata Jadhavbd0eb432021-01-13 14:33:47 +0530448 /*! \copydoc coeff_opt_thresholds */
chiyotsaia36d9002020-04-29 16:48:21 -0700449 TX_SIZE_SEARCH_METHOD tx_size_search_method;
Akshata Jadhavbd0eb432021-01-13 14:33:47 +0530450 /*! \copydoc coeff_opt_thresholds */
chiyotsaia36d9002020-04-29 16:48:21 -0700451 unsigned int use_transform_domain_distortion;
Akshata Jadhavbd0eb432021-01-13 14:33:47 +0530452 /*! \copydoc coeff_opt_thresholds */
chiyotsaia36d9002020-04-29 16:48:21 -0700453 unsigned int skip_txfm_level;
454
chiyotsaic2f38412020-06-10 16:07:21 -0700455 /*! \brief How to search for the optimal tx_size
456 *
457 * If ONLY_4X4, use TX_4X4; if TX_MODE_LARGEST, use the largest tx_size for
458 * the current partition block; if TX_MODE_SELECT, search through the whole
459 * tree.
460 *
461 * \attention
462 * Although this looks suspicious similar to a bitstream element, this
463 * tx_mode_search_type is only used internally by the encoder, and is *not*
464 * written to the bitstream. It determines what kind of tx_mode would be
465 * searched. For example, we might set it to TX_MODE_LARGEST to find a good
466 * candidate, then code it as TX_MODE_SELECT.
467 */
chiyotsaia36d9002020-04-29 16:48:21 -0700468 TX_MODE tx_mode_search_type;
Ravi Chaudhary6eaea622020-08-28 10:28:24 +0530469
470 /*!
471 * Flag to enable/disable DC block prediction.
472 */
473 unsigned int predict_dc_level;
chiyotsaia36d9002020-04-29 16:48:21 -0700474} TxfmSearchParams;
475
chiyotsaic2f38412020-06-10 16:07:21 -0700476/*!\cond */
chiyotsai4c1e5c62020-04-30 17:54:14 -0700477#define MAX_NUM_8X8_TXBS ((MAX_MIB_SIZE >> 1) * (MAX_MIB_SIZE >> 1))
478#define MAX_NUM_16X16_TXBS ((MAX_MIB_SIZE >> 2) * (MAX_MIB_SIZE >> 2))
479#define MAX_NUM_32X32_TXBS ((MAX_MIB_SIZE >> 3) * (MAX_MIB_SIZE >> 3))
480#define MAX_NUM_64X64_TXBS ((MAX_MIB_SIZE >> 4) * (MAX_MIB_SIZE >> 4))
chiyotsaic2f38412020-06-10 16:07:21 -0700481/*!\endcond */
chiyotsai4c1e5c62020-04-30 17:54:14 -0700482
Fyodor Kyslov677cc012021-01-27 18:35:07 -0800483/*! \brief Txfm hash records
484 *
485 * Hash records of the transform search results based on the residue. There
486 * are two main types here:
487 * - MB_RD_RECORD: records a whole *partition block*'s inter-mode txfm result.
488 * Since this operates on the partition block level, this can give us a
489 * whole txfm partition tree.
490 * - TXB_RD_RECORD: records a txfm search result within a transform blcok
491 * itself. This operates on txb level only and onlyt appplies to square
492 * txfms.
493 */
494typedef struct {
495 /*****************************************************************************
496 * \name TXB RD Record
497 ****************************************************************************/
498 /**@{*/
499 //! Txfm hash record for the whole coding block.
500 MB_RD_RECORD mb_rd_record;
501
502 //! Inter mode txfm hash record for TX_8X8 blocks.
503 TXB_RD_RECORD txb_rd_record_8X8[MAX_NUM_8X8_TXBS];
504 //! Inter mode txfm hash record for TX_16X16 blocks.
505 TXB_RD_RECORD txb_rd_record_16X16[MAX_NUM_16X16_TXBS];
506 //! Inter mode txfm hash record for TX_32X32 blocks.
507 TXB_RD_RECORD txb_rd_record_32X32[MAX_NUM_32X32_TXBS];
508 //! Inter mode txfm hash record for TX_64X64 blocks.
509 TXB_RD_RECORD txb_rd_record_64X64[MAX_NUM_64X64_TXBS];
510 //! Intra mode txfm hash record for square tx blocks.
511 TXB_RD_RECORD txb_rd_record_intra;
512 /**@}*/
513} TxbRdRecords;
514
chiyotsaic2f38412020-06-10 16:07:21 -0700515/*! \brief Stores various encoding/search decisions related to txfm search.
516 *
517 * This struct contains a cache of previous txfm results, and some buffers for
518 * the current txfm decision.
519 */
chiyotsai4c1e5c62020-04-30 17:54:14 -0700520typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700521 //! Whether to skip transform and quantization on a partition block level.
chiyotsai4c1e5c62020-04-30 17:54:14 -0700522 int skip_txfm;
523
chiyotsaic2f38412020-06-10 16:07:21 -0700524 /*! \brief Whether to skip transform and quantization on a txfm block level.
525 *
526 * Skips transform and quantization on a transform block level inside the
527 * current partition block. Each element of this array is used as a bit-field.
528 * So for example, the we are skipping on the luma plane, then the last bit
529 * would be set to 1.
530 */
chiyotsai4c1e5c62020-04-30 17:54:14 -0700531 uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
532
chiyotsaic2f38412020-06-10 16:07:21 -0700533 /*! \brief Transform types inside the partition block
534 *
535 * Keeps a record of what kind of transform to use for each of the transform
536 * block inside the partition block.
537 * \attention The buffer here is *never* directly used. Instead, this just
538 * allocates the memory for MACROBLOCKD::tx_type_map during rdopt on the
539 * partition block. So if we need to save memory, we could move the allocation
540 * to pick_sb_mode instead.
541 */
chiyotsai4c1e5c62020-04-30 17:54:14 -0700542 uint8_t tx_type_map_[MAX_MIB_SIZE * MAX_MIB_SIZE];
543
Fyodor Kyslov677cc012021-01-27 18:35:07 -0800544 /*! \brief Txfm hash records
545 *
chiyotsaic2f38412020-06-10 16:07:21 -0700546 * Hash records of the transform search results based on the residue. There
547 * are two main types here:
548 * - MB_RD_RECORD: records a whole *partition block*'s inter-mode txfm result.
549 * Since this operates on the partition block level, this can give us a
550 * whole txfm partition tree.
551 * - TXB_RD_RECORD: records a txfm search result within a transform blcok
552 * itself. This operates on txb level only and onlyt appplies to square
553 * txfms.
554 */
Fyodor Kyslov677cc012021-01-27 18:35:07 -0800555 TxbRdRecords *txb_rd_records;
chiyotsai4c1e5c62020-04-30 17:54:14 -0700556
chiyotsaic2f38412020-06-10 16:07:21 -0700557 /*! \brief Number of txb splits.
558 *
559 * Keep track of how many times we've used split tx partition for transform
560 * blocks. Somewhat misleadingly, this parameter doesn't actually keep track
561 * of the count of the current block. Instead, it's a cumulative count across
562 * of the whole frame. The main usage is that if txb_split_count is zero, then
563 * we can signal TX_MODE_LARGEST at frame level.
564 */
chiyotsai4c1e5c62020-04-30 17:54:14 -0700565 // TODO(chiyotsai@google.com): Move this to a more appropriate location such
566 // as ThreadData.
567 unsigned int txb_split_count;
568#if CONFIG_SPEED_STATS
chiyotsaic2f38412020-06-10 16:07:21 -0700569 //! For debugging. Used to check how many txfm searches we are doing.
chiyotsai4c1e5c62020-04-30 17:54:14 -0700570 unsigned int tx_search_count;
571#endif // CONFIG_SPEED_STATS
572} TxfmSearchInfo;
chiyotsaic2f38412020-06-10 16:07:21 -0700573#undef MAX_NUM_8X8_TXBS
574#undef MAX_NUM_16X16_TXBS
575#undef MAX_NUM_32X32_TXBS
576#undef MAX_NUM_64X64_TXBS
chiyotsai4c1e5c62020-04-30 17:54:14 -0700577
chiyotsaic2f38412020-06-10 16:07:21 -0700578/*! \brief Holds the entropy costs for various modes sent to the bitstream.
579 *
580 * \attention This does not include the costs for mv and transformed
581 * coefficients.
582 */
chiyotsai9a06d182020-05-01 17:12:12 -0700583typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700584 /*****************************************************************************
585 * \name Partition Costs
586 ****************************************************************************/
587 /**@{*/
588 //! Cost for coding the partition.
chiyotsai9a06d182020-05-01 17:12:12 -0700589 int partition_cost[PARTITION_CONTEXTS][EXT_PARTITION_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700590 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700591
chiyotsaic2f38412020-06-10 16:07:21 -0700592 /*****************************************************************************
593 * \name Intra Costs: General
594 ****************************************************************************/
595 /**@{*/
596 //! Luma mode cost for inter frame.
597 int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES];
598 //! Luma mode cost for intra frame.
599 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
600 //! Chroma mode cost
chiyotsai9a06d182020-05-01 17:12:12 -0700601 int intra_uv_mode_cost[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES];
chiyotsaic2f38412020-06-10 16:07:21 -0700602 //! filter_intra_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700603 int filter_intra_cost[BLOCK_SIZES_ALL][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700604 //! filter_intra_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700605 int filter_intra_mode_cost[FILTER_INTRA_MODES];
chiyotsaic2f38412020-06-10 16:07:21 -0700606 //! angle_delta_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700607 int angle_delta_cost[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1];
608
chiyotsaic2f38412020-06-10 16:07:21 -0700609 //! Rate rate associated with each alpha codeword
610 int cfl_cost[CFL_JOINT_SIGNS][CFL_PRED_PLANES][CFL_ALPHABET_SIZE];
611 /**@}*/
612
613 /*****************************************************************************
614 * \name Intra Costs: Screen Contents
615 ****************************************************************************/
616 /**@{*/
617 //! intrabc_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700618 int intrabc_cost[2];
619
chiyotsaic2f38412020-06-10 16:07:21 -0700620 //! palette_y_size_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700621 int palette_y_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES];
chiyotsaic2f38412020-06-10 16:07:21 -0700622 //! palette_uv_size_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700623 int palette_uv_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES];
chiyotsaic2f38412020-06-10 16:07:21 -0700624 //! palette_y_color_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700625 int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
626 [PALETTE_COLORS];
chiyotsaic2f38412020-06-10 16:07:21 -0700627 //! palette_uv_color_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700628 int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
629 [PALETTE_COLORS];
chiyotsaic2f38412020-06-10 16:07:21 -0700630 //! palette_y_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700631 int palette_y_mode_cost[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700632 //! palette_uv_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700633 int palette_uv_mode_cost[PALETTE_UV_MODE_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700634 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700635
chiyotsaic2f38412020-06-10 16:07:21 -0700636 /*****************************************************************************
637 * \name Inter Costs: MV Modes
638 ****************************************************************************/
639 /**@{*/
640 //! skip_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700641 int skip_mode_cost[SKIP_MODE_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700642 //! newmv_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700643 int newmv_mode_cost[NEWMV_MODE_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700644 //! zeromv_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700645 int zeromv_mode_cost[GLOBALMV_MODE_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700646 //! refmv_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700647 int refmv_mode_cost[REFMV_MODE_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700648 //! drl_mode_cost0
chiyotsai9a06d182020-05-01 17:12:12 -0700649 int drl_mode_cost0[DRL_MODE_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700650 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700651
chiyotsaic2f38412020-06-10 16:07:21 -0700652 /*****************************************************************************
653 * \name Inter Costs: Ref Frame Types
654 ****************************************************************************/
655 /**@{*/
656 //! single_ref_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700657 int single_ref_cost[REF_CONTEXTS][SINGLE_REFS - 1][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700658 //! comp_inter_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700659 int comp_inter_cost[COMP_INTER_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700660 //! comp_ref_type_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700661 int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS]
662 [CDF_SIZE(COMP_REFERENCE_TYPES)];
chiyotsaic2f38412020-06-10 16:07:21 -0700663 //! uni_comp_ref_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700664 int uni_comp_ref_cost[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]
665 [CDF_SIZE(2)];
chiyotsaic2f38412020-06-10 16:07:21 -0700666 /*! \brief Cost for signaling ref_frame[0] in bidir-comp mode
667 *
668 * Includes LAST_FRAME, LAST2_FRAME, LAST3_FRAME, and GOLDEN_FRAME.
669 */
chiyotsai9a06d182020-05-01 17:12:12 -0700670 int comp_ref_cost[REF_CONTEXTS][FWD_REFS - 1][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700671 /*! \brief Cost for signaling ref_frame[1] in bidir-comp mode
672 *
673 * Includes ALTREF_FRAME, ALTREF2_FRAME, and BWDREF_FRAME.
674 */
chiyotsai9a06d182020-05-01 17:12:12 -0700675 int comp_bwdref_cost[REF_CONTEXTS][BWD_REFS - 1][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700676 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700677
chiyotsaic2f38412020-06-10 16:07:21 -0700678 /*****************************************************************************
679 * \name Inter Costs: Compound Types
680 ****************************************************************************/
681 /**@{*/
682 //! intra_inter_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700683 int intra_inter_cost[INTRA_INTER_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700684 //! inter_compound_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700685 int inter_compound_mode_cost[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES];
chiyotsaic2f38412020-06-10 16:07:21 -0700686 //! compound_type_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700687 int compound_type_cost[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700688 //! wedge_idx_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700689 int wedge_idx_cost[BLOCK_SIZES_ALL][16];
chiyotsaic2f38412020-06-10 16:07:21 -0700690 //! interintra_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700691 int interintra_cost[BLOCK_SIZE_GROUPS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700692 //! wedge_interintra_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700693 int wedge_interintra_cost[BLOCK_SIZES_ALL][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700694 //! interintra_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700695 int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
chiyotsaic2f38412020-06-10 16:07:21 -0700696 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700697
chiyotsaic2f38412020-06-10 16:07:21 -0700698 /*****************************************************************************
699 * \name Inter Costs: Compound Masks
700 ****************************************************************************/
701 /**@{*/
702 //! comp_idx_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700703 int comp_idx_cost[COMP_INDEX_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700704 //! comp_group_idx_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700705 int comp_group_idx_cost[COMP_GROUP_IDX_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700706 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700707
chiyotsaic2f38412020-06-10 16:07:21 -0700708 /*****************************************************************************
709 * \name Inter Costs: Motion Modes/Filters
710 ****************************************************************************/
711 /**@{*/
712 //! motion_mode_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700713 int motion_mode_cost[BLOCK_SIZES_ALL][MOTION_MODES];
chiyotsaic2f38412020-06-10 16:07:21 -0700714 //! motion_mode_cost1
chiyotsai9a06d182020-05-01 17:12:12 -0700715 int motion_mode_cost1[BLOCK_SIZES_ALL][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700716 //! switchable_interp_costs
chiyotsai9a06d182020-05-01 17:12:12 -0700717 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
chiyotsaic2f38412020-06-10 16:07:21 -0700718 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700719
chiyotsaic2f38412020-06-10 16:07:21 -0700720 /*****************************************************************************
721 * \name Txfm Mode Costs
722 ****************************************************************************/
723 /**@{*/
724 //! skip_txfm_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700725 int skip_txfm_cost[SKIP_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700726 //! tx_size_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700727 int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES];
chiyotsaic2f38412020-06-10 16:07:21 -0700728 //! txfm_partition_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700729 int txfm_partition_cost[TXFM_PARTITION_CONTEXTS][2];
chiyotsaic2f38412020-06-10 16:07:21 -0700730 //! inter_tx_type_costs
chiyotsai9a06d182020-05-01 17:12:12 -0700731 int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700732 //! intra_tx_type_costs
chiyotsai9a06d182020-05-01 17:12:12 -0700733 int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
734 [TX_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700735 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700736
chiyotsaic2f38412020-06-10 16:07:21 -0700737 /*****************************************************************************
738 * \name Restoration Mode Costs
739 ****************************************************************************/
740 /**@{*/
741 //! switchable_restore_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700742 int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700743 //! wiener_restore_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700744 int wiener_restore_cost[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700745 //! sgrproj_restore_cost
chiyotsai9a06d182020-05-01 17:12:12 -0700746 int sgrproj_restore_cost[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700747 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700748} ModeCosts;
749
chiyotsaic2f38412020-06-10 16:07:21 -0700750/*! \brief Holds mv costs for encoding and motion search.
751 */
chiyotsai9a06d182020-05-01 17:12:12 -0700752typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700753 /*****************************************************************************
chiyotsaic2f38412020-06-10 16:07:21 -0700754 * \name Encoding Costs
755 * Here are the entropy costs needed to encode a given mv.
756 * \ref nmv_cost_alloc and \ref nmv_cost_hp_alloc are two arrays that holds
757 * the memory for holding the mv cost. But since the motion vectors can be
758 * negative, we shift them to the middle and store the resulting pointer in
759 * \ref nmv_cost and \ref nmv_cost_hp for easier referencing. Finally, \ref
760 * mv_cost_stack points to the \ref nmv_cost with the mv precision we are
761 * currently working with. In essence, only \ref mv_cost_stack is needed for
762 * motion search, the other can be considered private.
763 ****************************************************************************/
764 /**@{*/
765 //! Costs for coding the zero components.
chiyotsai9a06d182020-05-01 17:12:12 -0700766 int nmv_joint_cost[MV_JOINTS];
767
chiyotsaic2f38412020-06-10 16:07:21 -0700768 //! Allocates memory for 1/4-pel motion vector costs.
chiyotsai9a06d182020-05-01 17:12:12 -0700769 int nmv_cost_alloc[2][MV_VALS];
chiyotsaic2f38412020-06-10 16:07:21 -0700770 //! Allocates memory for 1/8-pel motion vector costs.
chiyotsai9a06d182020-05-01 17:12:12 -0700771 int nmv_cost_hp_alloc[2][MV_VALS];
chiyotsaic2f38412020-06-10 16:07:21 -0700772 //! Points to the middle of \ref nmv_cost_alloc
chiyotsai9a06d182020-05-01 17:12:12 -0700773 int *nmv_cost[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700774 //! Points to the middle of \ref nmv_cost_hp_alloc
chiyotsai9a06d182020-05-01 17:12:12 -0700775 int *nmv_cost_hp[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700776 //! Points to the nmv_cost_hp in use.
chiyotsai9a06d182020-05-01 17:12:12 -0700777 int **mv_cost_stack;
chiyotsaic2f38412020-06-10 16:07:21 -0700778 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700779} MvCosts;
780
chiyotsaic2f38412020-06-10 16:07:21 -0700781/*! \brief Holds the costs needed to encode the coefficients
782 */
chiyotsai9a06d182020-05-01 17:12:12 -0700783typedef struct {
chiyotsaic2f38412020-06-10 16:07:21 -0700784 //! Costs for coding the coefficients.
chiyotsai9a06d182020-05-01 17:12:12 -0700785 LV_MAP_COEFF_COST coeff_costs[TX_SIZES][PLANE_TYPES];
chiyotsaic2f38412020-06-10 16:07:21 -0700786 //! Costs for coding the eobs.
chiyotsai9a06d182020-05-01 17:12:12 -0700787 LV_MAP_EOB_COST eob_costs[7][2];
788} CoeffCosts;
789
chiyotsaic2f38412020-06-10 16:07:21 -0700790/*!\cond */
791// 4: NEAREST, NEW, NEAR, GLOBAL
792#define SINGLE_REF_MODES ((REF_FRAMES - 1) * 4)
793/*!\endcond */
Ravi Chaudhary5d970f42018-09-25 11:25:32 +0530794struct inter_modes_info;
chiyotsaic2f38412020-06-10 16:07:21 -0700795
Hui Su69af3f52020-10-06 16:28:57 -0700796/*! \brief Holds the motion samples for warp motion model estimation
797 */
798typedef struct {
799 //! Number of samples.
800 int num;
801 //! Sample locations in current frame.
802 int pts[16];
803 //! Sample location in the reference frame.
804 int pts_inref[16];
805} WARP_SAMPLE_INFO;
806
Marco Paniconi988b34a2020-11-09 12:41:13 -0800807/*!\cond */
808typedef enum {
809 kInvalid = 0,
810 kLowSad = 1,
811 kMedSad = 2,
812 kHighSad = 3
813} SOURCE_SAD;
814
815typedef struct {
816 SOURCE_SAD source_sad;
817 int lighting_change;
818 int low_sumdiff;
819} CONTENT_STATE_SB;
820/*!\endcond */
821
chiyotsaic2f38412020-06-10 16:07:21 -0700822/*! \brief Encoder's parameters related to the current coding block.
823 *
824 * This struct contains most of the information the encoder needs to encode the
825 * current coding block. This includes the src and pred buffer, a copy of the
826 * decoder's view of the current block, the txfm coefficients. This struct also
827 * contains various buffers and data used to speed up the encoding process.
828 */
829typedef struct macroblock {
830 /*****************************************************************************
831 * \name Source, Buffers and Decoder
832 ****************************************************************************/
833 /**@{*/
834 /*! \brief Each of the encoding plane.
835 *
836 * An array holding the src buffer for each of plane of the current block. It
837 * also contains the txfm and quantized txfm coefficients.
838 */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700839 struct macroblock_plane plane[MAX_MB_PLANE];
840
chiyotsaic2f38412020-06-10 16:07:21 -0700841 /*! \brief Decoder's view of current coding block.
842 *
843 * Contains the encoder's copy of what the decoder sees in the current block.
844 * Most importantly, this struct contains pointers to mbmi that is used in
845 * final bitstream packing.
846 */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700847 MACROBLOCKD e_mbd;
chiyotsai85d715a2020-05-02 15:10:33 -0700848
chiyotsaic2f38412020-06-10 16:07:21 -0700849 /*! \brief Derived coding information.
850 *
851 * Contains extra information not transmitted in the bitstream but are
852 * derived. For example, this contains the stack of ref_mvs.
853 */
chiyotsai0b90c412020-09-29 14:48:16 -0700854 MB_MODE_INFO_EXT mbmi_ext;
chiyotsai85d715a2020-05-02 15:10:33 -0700855
chiyotsaic2f38412020-06-10 16:07:21 -0700856 /*! \brief Finalized mbmi_ext for the whole frame.
857 *
858 * Contains the finalized info in mbmi_ext that gets used at the frame level
859 * for bitstream packing.
860 */
Remya0cce44c2019-08-16 11:57:24 +0530861 MB_MODE_INFO_EXT_FRAME *mbmi_ext_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700862
chiyotsaic2f38412020-06-10 16:07:21 -0700863 //! Entropy context for the current row.
chiyotsai85d715a2020-05-02 15:10:33 -0700864 FRAME_CONTEXT *row_ctx;
chiyotsaic2f38412020-06-10 16:07:21 -0700865 /*! \brief Entropy context for the current tile.
866 *
867 * This context will be used to update color_map_cdf pointer which would be
868 * used during pack bitstream. For single thread and tile-multithreading case
869 * this pointer will be same as xd->tile_ctx, but for the case of row-mt:
870 * xd->tile_ctx will point to a temporary context while tile_pb_ctx will point
871 * to the accurate tile context.
872 */
chiyotsai85d715a2020-05-02 15:10:33 -0700873 FRAME_CONTEXT *tile_pb_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700874
chiyotsaic2f38412020-06-10 16:07:21 -0700875 /*! \brief Buffer of transformed coefficients
876 *
877 * Points to cb_coef_buff in the AV1_COMP struct, which contains the finalized
878 * coefficients. This is here to conveniently copy the best coefficients to
879 * frame level for bitstream packing. Since CB_COEFF_BUFFER is allocated on a
880 * superblock level, we need to combine it with cb_offset to get the proper
881 * position for the current coding block.
882 */
chiyotsai85d715a2020-05-02 15:10:33 -0700883 CB_COEFF_BUFFER *cb_coef_buff;
chiyotsaic2f38412020-06-10 16:07:21 -0700884 //! Offset of current coding block's coeff buffer relative to the sb.
Jayasanker J2350ca32020-09-10 23:49:00 +0530885 uint16_t cb_offset[PLANE_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700886
chiyotsaic2f38412020-06-10 16:07:21 -0700887 //! Modified source and masks used for fast OBMC search.
chiyotsaid2b12212020-04-28 20:57:19 -0700888 OBMCBuffer obmc_buffer;
chiyotsaic2f38412020-06-10 16:07:21 -0700889 //! Buffer to store the best palette map.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700890 PALETTE_BUFFER *palette_buffer;
chiyotsaic2f38412020-06-10 16:07:21 -0700891 //! Buffer used for compound_type_rd().
Hui Su38711e72019-06-11 10:49:47 -0700892 CompoundTypeRdBuffers comp_rd_buffer;
chiyotsaic2f38412020-06-10 16:07:21 -0700893 //! Buffer to store convolution during averaging process in compound mode.
Urvang Joshi0a4cfad2018-09-07 11:10:39 -0700894 CONV_BUF_TYPE *tmp_conv_dst;
chiyotsai2a897eb2020-04-28 19:22:13 -0700895
chiyotsaic2f38412020-06-10 16:07:21 -0700896 /*! \brief Temporary buffer to hold prediction.
897 *
898 * Points to a buffer that is used to hold temporary prediction results. This
899 * is used in two ways:
900 * - This is a temporary buffer used to pingpong the prediction in
901 * handle_inter_mode.
902 * - xd->tmp_obmc_bufs also points to this buffer, and is used in ombc
903 * prediction.
904 */
chiyotsai2a897eb2020-04-28 19:22:13 -0700905 uint8_t *tmp_pred_bufs[2];
chiyotsaic2f38412020-06-10 16:07:21 -0700906 /**@}*/
Urvang Joshi0a4cfad2018-09-07 11:10:39 -0700907
chiyotsaic2f38412020-06-10 16:07:21 -0700908 /*****************************************************************************
909 * \name Rdopt Costs
910 ****************************************************************************/
911 /**@{*/
912 /*! \brief Quantization index for the current partition block.
913 *
914 * This is used to as the index to find quantization parameter for luma and
915 * chroma transformed coefficients.
916 */
chiyotsai9a06d182020-05-01 17:12:12 -0700917 int qindex;
918
chiyotsaic2f38412020-06-10 16:07:21 -0700919 /*! \brief Difference between frame-level qindex and current qindex.
920 *
921 * This is used to track whether a non-zero delta for qindex is used at least
922 * once in the current frame.
923 */
chiyotsai9a06d182020-05-01 17:12:12 -0700924 int delta_qindex;
925
chiyotsaic2f38412020-06-10 16:07:21 -0700926 /*! \brief Rate-distortion multiplier.
927 *
928 * The rd multiplier used to determine the rate-distortion trade-off. This is
929 * roughly proportional to the inverse of q-index for a given frame, but this
930 * can be manipulated for better rate-control. For example, in tune_ssim
931 * mode, this is scaled by a factor related to the variance of the current
932 * block.
933 */
chiyotsai9a06d182020-05-01 17:12:12 -0700934 int rdmult;
935
chiyotsaic2f38412020-06-10 16:07:21 -0700936 //! Energy in the current source coding block. Used to calculate \ref rdmult
chiyotsai85d715a2020-05-02 15:10:33 -0700937 int mb_energy;
chiyotsaic2f38412020-06-10 16:07:21 -0700938 //! Energy in the current source superblock. Used to calculate \ref rdmult
chiyotsai85d715a2020-05-02 15:10:33 -0700939 int sb_energy_level;
940
chiyotsaic2f38412020-06-10 16:07:21 -0700941 //! The rate needed to signal a mode to the bitstream.
chiyotsai9a06d182020-05-01 17:12:12 -0700942 ModeCosts mode_costs;
943
chiyotsaic2f38412020-06-10 16:07:21 -0700944 //! The rate needed to encode a new motion vector to the bitstream and some
945 //! multipliers for motion search.
Fyodor Kyslov648c6502021-02-02 18:41:10 -0800946 MvCosts *mv_costs;
chiyotsai9a06d182020-05-01 17:12:12 -0700947
chiyotsaic2f38412020-06-10 16:07:21 -0700948 //! The rate needed to signal the txfm coefficients to the bitstream.
chiyotsai9a06d182020-05-01 17:12:12 -0700949 CoeffCosts coeff_costs;
chiyotsaic2f38412020-06-10 16:07:21 -0700950 /**@}*/
chiyotsai9a06d182020-05-01 17:12:12 -0700951
Fyodor Kyslov648c6502021-02-02 18:41:10 -0800952 /*****************************************************************************
953 * \name Rate to Distortion Multipliers
954 ****************************************************************************/
955 /**@{*/
956 //! A multiplier that converts mv cost to l2 error.
957 int errorperbit;
958 //! A multiplier that converts mv cost to l1 error.
959 int sadperbit;
960 /**@}*/
961
chiyotsaic2f38412020-06-10 16:07:21 -0700962 /******************************************************************************
963 * \name Segmentation
964 *****************************************************************************/
965 /**@{*/
966 /*! \brief Skip mode for the segment
967 *
968 * A syntax element of the segmentation mode. In skip_block mode, all mvs are
969 * set 0 and all txfms are skipped.
970 */
chiyotsai85d715a2020-05-02 15:10:33 -0700971 int seg_skip_block;
chiyotsaic2f38412020-06-10 16:07:21 -0700972 /**@}*/
chiyotsai85d715a2020-05-02 15:10:33 -0700973
chiyotsaic2f38412020-06-10 16:07:21 -0700974 /*****************************************************************************
975 * \name Superblock
976 ****************************************************************************/
977 /**@{*/
978 //! Information on a whole superblock level.
chiyotsai85d715a2020-05-02 15:10:33 -0700979 // TODO(chiyotsai@google.com): Refactor this out of macroblock
980 SuperBlockEnc sb_enc;
981
chiyotsaic2f38412020-06-10 16:07:21 -0700982 /*! \brief Characteristics of the current superblock.
983 *
984 * Characteristics like whether the block has high sad, low sad, etc. This is
985 * only used by av1 realtime mode.
986 */
Marco Paniconi988b34a2020-11-09 12:41:13 -0800987 CONTENT_STATE_SB content_state_sb;
chiyotsaic2f38412020-06-10 16:07:21 -0700988 /**@}*/
chiyotsai85d715a2020-05-02 15:10:33 -0700989
chiyotsaic2f38412020-06-10 16:07:21 -0700990 /*****************************************************************************
chiyotsai3afb03e2020-09-08 13:30:12 -0700991 * \name Reference Frame Search
chiyotsaic2f38412020-06-10 16:07:21 -0700992 ****************************************************************************/
993 /**@{*/
994 /*! \brief Sum absolute distortion of the predicted mv for each ref frame.
995 *
996 * This is used to measure how viable a reference frame is.
997 */
chiyotsai85d715a2020-05-02 15:10:33 -0700998 int pred_mv_sad[REF_FRAMES];
chiyotsaic2f38412020-06-10 16:07:21 -0700999 //! The minimum of \ref pred_mv_sad.
chiyotsai85d715a2020-05-02 15:10:33 -07001000 int best_pred_mv_sad;
1001
chiyotsaic2f38412020-06-10 16:07:21 -07001002 /*! \brief Disables certain ref frame pruning based on tpl.
1003 *
1004 * Determines whether a given ref frame is "good" based on data from the TPL
1005 * model. If so, this stops selective_ref frame from pruning the given ref
1006 * frame at block level.
1007 */
chiyotsai85d715a2020-05-02 15:10:33 -07001008 uint8_t tpl_keep_ref_frame[REF_FRAMES];
1009
Hui Su69af3f52020-10-06 16:28:57 -07001010 /*! \brief Warp motion samples buffer.
1011 *
1012 * Store the motion samples used for warp motion.
1013 */
1014 WARP_SAMPLE_INFO warp_sample_info[REF_FRAMES];
1015
chiyotsaic2f38412020-06-10 16:07:21 -07001016 /*! \brief Reference frames picked by the square subblocks in a superblock.
1017 *
1018 * Keeps track of ref frames that are selected by square partition blocks
1019 * within a superblock, in MI resolution. They can be used to prune ref frames
1020 * for rectangular blocks.
1021 */
chiyotsai85d715a2020-05-02 15:10:33 -07001022 int picked_ref_frames_mask[MAX_MIB_SIZE * MAX_MIB_SIZE];
1023
chiyotsaic2f38412020-06-10 16:07:21 -07001024 /*! \brief Prune ref frames in real-time mode.
1025 *
1026 * Determines whether to prune reference frames in real-time mode. For the
1027 * most part, this is the same as nonrd_prune_ref_frame_search in
1028 * cpi->sf.rt_sf.nonrd_prune_ref_frame_search, but this can be selectively
1029 * turned off if the only frame available is GOLDEN_FRAME.
1030 */
chiyotsai85d715a2020-05-02 15:10:33 -07001031 int nonrd_prune_ref_frame_search;
chiyotsaic2f38412020-06-10 16:07:21 -07001032 /**@}*/
chiyotsai85d715a2020-05-02 15:10:33 -07001033
chiyotsaic2f38412020-06-10 16:07:21 -07001034 /*****************************************************************************
1035 * \name Partition Search
1036 ****************************************************************************/
1037 /**@{*/
1038 //! Stores some partition-search related buffers.
chiyotsai68eefbe2020-05-01 15:07:58 -07001039 PartitionSearchInfo part_search_info;
1040
chiyotsaic2f38412020-06-10 16:07:21 -07001041 /*! \brief Whether to disable some features to force a mode in current block.
1042 *
1043 * In some cases, our speed features can be overly aggressive and remove all
1044 * modes search in the superblock. When this happens, we set
1045 * must_find_valid_partition to 1 to reduce the number of speed features, and
1046 * recode the superblock again.
1047 */
chiyotsai85d715a2020-05-02 15:10:33 -07001048 int must_find_valid_partition;
chiyotsaic2f38412020-06-10 16:07:21 -07001049 /**@}*/
chiyotsai85d715a2020-05-02 15:10:33 -07001050
chiyotsaic2f38412020-06-10 16:07:21 -07001051 /*****************************************************************************
1052 * \name Prediction Mode Search
1053 ****************************************************************************/
1054 /**@{*/
1055 /*! \brief Inter skip mode.
1056 *
1057 * Skip mode tries to use the closest forward and backward references for
1058 * inter prediction. Skip here means to skip transmitting the reference
1059 * frames, not to be confused with skip_txfm.
1060 */
chiyotsai85d715a2020-05-02 15:10:33 -07001061 int skip_mode;
1062
chiyotsaic2f38412020-06-10 16:07:21 -07001063 /*! \brief Factors used for rd-thresholding.
1064 *
1065 * Determines a rd threshold to determine whether to continue searching the
1066 * current mode. If the current best rd is already <= threshold, then we skip
1067 * the current mode.
1068 */
chiyotsai85d715a2020-05-02 15:10:33 -07001069 int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
1070
chiyotsaic2f38412020-06-10 16:07:21 -07001071 /*! \brief Tracks the winner modes in the current coding block.
1072 *
1073 * Winner mode is a two-pass strategy to find the best prediction mode. In the
1074 * first pass, we search the prediction modes with a limited set of txfm
1075 * options, and keep the top modes. These modes are called the winner modes.
1076 * In the second pass, we retry the winner modes with more thorough txfm
1077 * options.
1078 */
chiyotsai85d715a2020-05-02 15:10:33 -07001079 WinnerModeStats winner_mode_stats[AOMMAX(MAX_WINNER_MODE_COUNT_INTRA,
1080 MAX_WINNER_MODE_COUNT_INTER)];
chiyotsaic2f38412020-06-10 16:07:21 -07001081 //! Tracks how many winner modes there are.
chiyotsai85d715a2020-05-02 15:10:33 -07001082 int winner_mode_count;
1083
chiyotsaic2f38412020-06-10 16:07:21 -07001084 /*! \brief The model used for rd-estimation to avoid txfm
1085 *
1086 * These are for inter_mode_rd_model_estimation, which is another two pass
1087 * approach. In this speed feature, we collect data in the first couple frames
1088 * to build an rd model to estimate the rdcost of a prediction model based on
1089 * the residue error. Once enough data is collected, this speed feature uses
1090 * the estimated rdcost to find the most performant prediction mode. Then we
1091 * follow up with a second pass find the best transform for the mode.
1092 * Determines if one would go with reduced complexity transform block
1093 * search model to select prediction modes, or full complexity model
1094 * to select transform kernel.
1095 */
chiyotsai85d715a2020-05-02 15:10:33 -07001096 TXFM_RD_MODEL rd_model;
1097
chiyotsaic2f38412020-06-10 16:07:21 -07001098 /*! \brief Stores the inter mode information needed to build an rd model.
1099 *
1100 * These are for inter_mode_rd_model_estimation, which is another two pass
1101 * approach. In this speed feature, we collect data in the first couple frames
1102 * to build an rd model to estimate the rdcost of a prediction model based on
1103 * the residue error. Once enough data is collected, this speed feature uses
1104 * the estimated rdcost to find the most performant prediction mode. Then we
1105 * follow up with a second pass find the best transform for the mode.
1106 */
chiyotsai85d715a2020-05-02 15:10:33 -07001107 // TODO(any): try to consolidate this speed feature with winner mode
1108 // processing.
1109 struct inter_modes_info *inter_modes_info;
1110
chiyotsaic2f38412020-06-10 16:07:21 -07001111 //! How to blend the compound predictions.
chiyotsai85d715a2020-05-02 15:10:33 -07001112 uint8_t compound_idx;
1113
chiyotsaic2f38412020-06-10 16:07:21 -07001114 //! A caches of results of compound type search so they can be reused later.
chiyotsai85d715a2020-05-02 15:10:33 -07001115 COMP_RD_STATS comp_rd_stats[MAX_COMP_RD_STATS];
chiyotsaic2f38412020-06-10 16:07:21 -07001116 //! The idx for the latest compound mode in the cache \ref comp_rd_stats.
chiyotsai85d715a2020-05-02 15:10:33 -07001117 int comp_rd_stats_idx;
1118
chiyotsaic2f38412020-06-10 16:07:21 -07001119 /*! \brief Whether to recompute the luma prediction.
1120 *
1121 * In interpolation search, we can usually skip recalculating the luma
1122 * prediction because it is already calculated by a previous predictor. This
1123 * flag signifies that some modes might have been skipped, so we need to
1124 * rebuild the prediction.
1125 */
chiyotsai85d715a2020-05-02 15:10:33 -07001126 int recalc_luma_mc_data;
1127
chiyotsaic2f38412020-06-10 16:07:21 -07001128 /*! \brief Data structure to speed up intrabc search.
1129 *
1130 * Contains the hash table, hash function, and buffer used for intrabc.
1131 */
1132 IntraBCHashInfo intrabc_hash_info;
chiyotsai3afb03e2020-09-08 13:30:12 -07001133
1134 /*! \brief Whether to reuse the mode stored in intermode_cache. */
1135 int use_intermode_cache;
Jingning Hane9eb8c02020-11-11 14:47:53 -08001136 /*! \brief The mode to reuse during \ref av1_rd_pick_inter_mode. */
chiyotsai681e4942020-09-30 11:08:17 -07001137 const MB_MODE_INFO *intermode_cache;
chiyotsaic2f38412020-06-10 16:07:21 -07001138 /**@}*/
1139
1140 /*****************************************************************************
1141 * \name MV Search
1142 ****************************************************************************/
1143 /**@{*/
1144 /*! \brief Context used to determine the initial step size in motion search.
1145 *
1146 * This context is defined as the \f$l_\inf\f$ norm of the best ref_mvs for
1147 * each frame.
1148 */
1149 unsigned int max_mv_context[REF_FRAMES];
1150
1151 /*! \brief Limit for the range of motion vectors.
1152 *
1153 * These define limits to motion vector components to prevent them from
1154 * extending outside the UMV borders
1155 */
1156 FullMvLimits mv_limits;
1157 /**@}*/
1158
1159 /*****************************************************************************
1160 * \name Txfm Search
1161 ****************************************************************************/
1162 /**@{*/
1163 /*! \brief Parameters that control how motion search is done.
1164 *
1165 * Stores various txfm search related parameters such as txfm_type, txfm_size,
1166 * trellis eob search, etc.
1167 */
chiyotsaia36d9002020-04-29 16:48:21 -07001168 TxfmSearchParams txfm_search_params;
Nithya V Sd0276ac2019-10-24 11:31:06 +05301169
chiyotsaic2f38412020-06-10 16:07:21 -07001170 /*! \brief Results of the txfm searches that have been done.
1171 *
1172 * Caches old txfm search results and keeps the current txfm decisions to
1173 * facilitate rdopt.
1174 */
chiyotsai4c1e5c62020-04-30 17:54:14 -07001175 TxfmSearchInfo txfm_search_info;
1176
chiyotsaic2f38412020-06-10 16:07:21 -07001177 /*! \brief Whether there is a strong color activity.
1178 *
1179 * Used in REALTIME coding mode to enhance the visual quality at the boundary
1180 * of moving color objects.
1181 */
chiyotsai85d715a2020-05-02 15:10:33 -07001182 uint8_t color_sensitivity[2];
chiyotsaic2f38412020-06-10 16:07:21 -07001183 /**@}*/
Jingning Han185d23b2020-03-04 09:12:05 -08001184
chiyotsaic2f38412020-06-10 16:07:21 -07001185 /*****************************************************************************
1186 * \name Misc
1187 ****************************************************************************/
1188 /**@{*/
1189 //! Variance of the source frame.
chiyotsai85d715a2020-05-02 15:10:33 -07001190 unsigned int source_variance;
chiyotsaic2f38412020-06-10 16:07:21 -07001191 //! SSE of the current predictor.
chiyotsai85d715a2020-05-02 15:10:33 -07001192 unsigned int pred_sse[REF_FRAMES];
Fyodor Kyslov28af7872020-09-25 18:41:45 -07001193 //! Prediction for ML based partition.
Fyodor Kyslov2c528682021-01-25 11:03:31 -08001194#if CONFIG_RT_ML_PARTITIONING
Fyodor Kyslov28af7872020-09-25 18:41:45 -07001195 DECLARE_ALIGNED(16, uint8_t, est_pred[128 * 128]);
Fyodor Kyslov2c528682021-01-25 11:03:31 -08001196#endif
chiyotsaic2f38412020-06-10 16:07:21 -07001197 /**@}*/
chiyotsaic2f38412020-06-10 16:07:21 -07001198} MACROBLOCK;
1199#undef SINGLE_REF_MODES
Yaowu Xuc27fc142016-08-22 16:08:15 -07001200
chiyotsaic2f38412020-06-10 16:07:21 -07001201/*!\cond */
Frederic Barbier0f191da2018-01-03 17:29:26 +01001202static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) {
1203 static const char LUT[BLOCK_SIZES_ALL] = {
1204 0, // BLOCK_4X4
1205 1, // BLOCK_4X8
1206 1, // BLOCK_8X4
1207 0, // BLOCK_8X8
1208 1, // BLOCK_8X16
1209 1, // BLOCK_16X8
1210 0, // BLOCK_16X16
1211 1, // BLOCK_16X32
1212 1, // BLOCK_32X16
1213 0, // BLOCK_32X32
1214 1, // BLOCK_32X64
1215 1, // BLOCK_64X32
1216 0, // BLOCK_64X64
Frederic Barbier0f191da2018-01-03 17:29:26 +01001217 0, // BLOCK_64X128
1218 0, // BLOCK_128X64
1219 0, // BLOCK_128X128
Frederic Barbier0f191da2018-01-03 17:29:26 +01001220 1, // BLOCK_4X16
1221 1, // BLOCK_16X4
1222 1, // BLOCK_8X32
1223 1, // BLOCK_32X8
1224 1, // BLOCK_16X64
1225 1, // BLOCK_64X16
Frederic Barbier0f191da2018-01-03 17:29:26 +01001226 };
1227
1228 return LUT[bsize];
1229}
1230
1231static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd,
1232 const MB_MODE_INFO *mbmi) {
chiyotsai0f5cd052020-08-27 14:37:44 -07001233 return is_rect_tx_allowed_bsize(mbmi->bsize) &&
Frederic Barbier0f191da2018-01-03 17:29:26 +01001234 !xd->lossless[mbmi->segment_id];
1235}
1236
Frederic Barbier4b56b102018-03-30 16:09:34 +02001237static INLINE int tx_size_to_depth(TX_SIZE tx_size, BLOCK_SIZE bsize) {
Urvang Joshidd0376f2018-05-02 16:37:25 -07001238 TX_SIZE ctx_size = max_txsize_rect_lookup[bsize];
Frederic Barbier0f191da2018-01-03 17:29:26 +01001239 int depth = 0;
1240 while (tx_size != ctx_size) {
1241 depth++;
Frederic Barbier4b56b102018-03-30 16:09:34 +02001242 ctx_size = sub_tx_size_map[ctx_size];
Frederic Barbier0f191da2018-01-03 17:29:26 +01001243 assert(depth <= MAX_TX_DEPTH);
1244 }
1245 return depth;
1246}
1247
chiyotsai4c1e5c62020-04-30 17:54:14 -07001248static INLINE void set_blk_skip(uint8_t txb_skip[], int plane, int blk_idx,
Grant Hsu39248c32018-09-18 10:38:44 +08001249 int skip) {
1250 if (skip)
chiyotsai4c1e5c62020-04-30 17:54:14 -07001251 txb_skip[blk_idx] |= 1UL << plane;
Grant Hsu39248c32018-09-18 10:38:44 +08001252 else
chiyotsai4c1e5c62020-04-30 17:54:14 -07001253 txb_skip[blk_idx] &= ~(1UL << plane);
Grant Hsu39248c32018-09-18 10:38:44 +08001254#ifndef NDEBUG
1255 // Set chroma planes to uninitialized states when luma is set to check if
1256 // it will be set later
1257 if (plane == 0) {
chiyotsai4c1e5c62020-04-30 17:54:14 -07001258 txb_skip[blk_idx] |= 1UL << (1 + 4);
1259 txb_skip[blk_idx] |= 1UL << (2 + 4);
Grant Hsu39248c32018-09-18 10:38:44 +08001260 }
1261
1262 // Clear the initialization checking bit
chiyotsai4c1e5c62020-04-30 17:54:14 -07001263 txb_skip[blk_idx] &= ~(1UL << (plane + 4));
Grant Hsu39248c32018-09-18 10:38:44 +08001264#endif
1265}
1266
chiyotsai4c1e5c62020-04-30 17:54:14 -07001267static INLINE int is_blk_skip(uint8_t *txb_skip, int plane, int blk_idx) {
Grant Hsu39248c32018-09-18 10:38:44 +08001268#ifndef NDEBUG
1269 // Check if this is initialized
chiyotsai4c1e5c62020-04-30 17:54:14 -07001270 assert(!(txb_skip[blk_idx] & (1UL << (plane + 4))));
Grant Hsu39248c32018-09-18 10:38:44 +08001271
1272 // The magic number is 0x77, this is to test if there is garbage data
chiyotsai4c1e5c62020-04-30 17:54:14 -07001273 assert((txb_skip[blk_idx] & 0x88) == 0);
Grant Hsu39248c32018-09-18 10:38:44 +08001274#endif
chiyotsai4c1e5c62020-04-30 17:54:14 -07001275 return (txb_skip[blk_idx] >> plane) & 1;
Grant Hsu39248c32018-09-18 10:38:44 +08001276}
1277
chiyotsaic2f38412020-06-10 16:07:21 -07001278/*!\endcond */
1279
Yaowu Xuc27fc142016-08-22 16:08:15 -07001280#ifdef __cplusplus
1281} // extern "C"
1282#endif
1283
James Zerne1cbb132018-08-22 14:10:36 -07001284#endif // AOM_AV1_ENCODER_BLOCK_H_