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