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