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