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 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_ENCODER_BLOCK_H_ |
| 13 | #define AOM_AV1_ENCODER_BLOCK_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include "av1/common/entropymv.h" |
| 16 | #include "av1/common/entropy.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | #include "av1/common/mvref_common.h" |
chiyotsai | 36035d1 | 2019-06-19 17:39:48 -0700 | [diff] [blame] | 18 | |
Ravi Chaudhary | b61cdea | 2019-07-05 15:01:20 +0530 | [diff] [blame] | 19 | #include "av1/encoder/enc_enums.h" |
chiyotsai | 36035d1 | 2019-06-19 17:39:48 -0700 | [diff] [blame] | 20 | #if !CONFIG_REALTIME_ONLY |
| 21 | #include "av1/encoder/partition_cnn_weights.h" |
| 22 | #endif |
| 23 | |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 24 | #include "av1/encoder/hash.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | |
| 26 | #ifdef __cplusplus |
| 27 | extern "C" { |
| 28 | #endif |
| 29 | |
Yunqing Wang | 61b2eac | 2019-09-24 16:45:16 -0700 | [diff] [blame] | 30 | #define MC_FLOW_BSIZE_1D 16 |
| 31 | #define MC_FLOW_NUM_PELS (MC_FLOW_BSIZE_1D * MC_FLOW_BSIZE_1D) |
| 32 | #define MAX_MC_FLOW_BLK_IN_SB (MAX_SB_SIZE / MC_FLOW_BSIZE_1D) |
Cherma Rajan A | d71ace6 | 2019-11-25 12:58:37 +0530 | [diff] [blame] | 33 | #define MAX_WINNER_MODE_COUNT_INTRA 3 |
| 34 | #define MAX_WINNER_MODE_COUNT_INTER 1 |
chiyotsai | ff73c53 | 2020-04-21 12:50:12 -0700 | [diff] [blame] | 35 | |
| 36 | // SuperblockEnc stores superblock level information used by the encoder for |
| 37 | // more efficient encoding. |
| 38 | typedef struct { |
| 39 | // Below are information gathered from tpl_model used to speed up the encoding |
| 40 | // process. |
| 41 | int tpl_data_count; |
| 42 | int64_t tpl_inter_cost[MAX_MC_FLOW_BLK_IN_SB * MAX_MC_FLOW_BLK_IN_SB]; |
| 43 | int64_t tpl_intra_cost[MAX_MC_FLOW_BLK_IN_SB * MAX_MC_FLOW_BLK_IN_SB]; |
| 44 | int_mv tpl_mv[MAX_MC_FLOW_BLK_IN_SB * MAX_MC_FLOW_BLK_IN_SB] |
| 45 | [INTER_REFS_PER_FRAME]; |
| 46 | int tpl_stride; |
| 47 | } SuperBlockEnc; |
| 48 | |
Cherma Rajan A | 835f7a6 | 2019-09-25 11:04:39 +0530 | [diff] [blame] | 49 | typedef struct { |
| 50 | MB_MODE_INFO mbmi; |
Cherma Rajan A | d71ace6 | 2019-11-25 12:58:37 +0530 | [diff] [blame] | 51 | RD_STATS rd_cost; |
Cherma Rajan A | 835f7a6 | 2019-09-25 11:04:39 +0530 | [diff] [blame] | 52 | int64_t rd; |
Cherma Rajan A | d71ace6 | 2019-11-25 12:58:37 +0530 | [diff] [blame] | 53 | int rate_y; |
| 54 | int rate_uv; |
Cherma Rajan A | 835f7a6 | 2019-09-25 11:04:39 +0530 | [diff] [blame] | 55 | uint8_t color_index_map[64 * 64]; |
Cherma Rajan A | d71ace6 | 2019-11-25 12:58:37 +0530 | [diff] [blame] | 56 | THR_MODES mode_index; |
Cherma Rajan A | 835f7a6 | 2019-09-25 11:04:39 +0530 | [diff] [blame] | 57 | } WinnerModeStats; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 58 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | typedef struct { |
| 60 | unsigned int sse; |
| 61 | int sum; |
| 62 | unsigned int var; |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 63 | } DIFF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | |
Debargha Mukherjee | 8a191ef | 2020-03-24 00:47:21 -0700 | [diff] [blame] | 65 | enum { |
| 66 | NO_TRELLIS_OPT, // No trellis optimization |
| 67 | FULL_TRELLIS_OPT, // Trellis optimization in all stages |
| 68 | FINAL_PASS_TRELLIS_OPT, // Trellis optimization in only the final encode pass |
| 69 | NO_ESTIMATE_YRD_TRELLIS_OPT // Disable trellis in estimate_yrd_for_sb |
| 70 | } UENUM1BYTE(TRELLIS_OPT_TYPE); |
| 71 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | typedef struct macroblock_plane { |
Ravi Chaudhary | d4a5a50 | 2019-06-07 12:13:32 +0530 | [diff] [blame] | 73 | DECLARE_ALIGNED(32, int16_t, src_diff[MAX_SB_SQUARE]); |
Urvang Joshi | 9543ad7 | 2020-04-17 16:59:46 -0700 | [diff] [blame] | 74 | tran_low_t *dqcoeff; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 75 | tran_low_t *qcoeff; |
| 76 | tran_low_t *coeff; |
| 77 | uint16_t *eobs; |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 78 | uint8_t *txb_entropy_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | struct buf_2d src; |
| 80 | |
| 81 | // Quantizer setings |
Monty Montgomery | 125c0fc | 2017-10-26 00:44:35 -0400 | [diff] [blame] | 82 | // These are used/accessed only in the quantization process |
| 83 | // RDO does not / must not depend on any of these values |
| 84 | // All values below share the coefficient scale/shift used in TX |
| 85 | const int16_t *quant_fp_QTX; |
| 86 | const int16_t *round_fp_QTX; |
| 87 | const int16_t *quant_QTX; |
| 88 | const int16_t *quant_shift_QTX; |
| 89 | const int16_t *zbin_QTX; |
| 90 | const int16_t *round_QTX; |
| 91 | const int16_t *dequant_QTX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | } MACROBLOCK_PLANE; |
| 93 | |
Jingning Han | dfd7232 | 2017-08-09 14:04:12 -0700 | [diff] [blame] | 94 | typedef struct { |
| 95 | int txb_skip_cost[TXB_SKIP_CONTEXTS][2]; |
Dake He | 3fe369c | 2017-11-16 17:56:44 -0800 | [diff] [blame] | 96 | int base_eob_cost[SIG_COEF_CONTEXTS_EOB][3]; |
Wenyao Liu | f7e5375 | 2019-01-22 17:34:44 +0800 | [diff] [blame] | 97 | int base_cost[SIG_COEF_CONTEXTS][8]; |
Angie Chiang | 7ab884e | 2017-10-18 15:57:12 -0700 | [diff] [blame] | 98 | int eob_extra_cost[EOB_COEF_CONTEXTS][2]; |
Jingning Han | dfd7232 | 2017-08-09 14:04:12 -0700 | [diff] [blame] | 99 | int dc_sign_cost[DC_SIGN_CONTEXTS][2]; |
Wenyao Liu | f7e5375 | 2019-01-22 17:34:44 +0800 | [diff] [blame] | 100 | 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] | 101 | } LV_MAP_COEFF_COST; |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 102 | |
Johann | b0ef6ff | 2018-02-08 14:32:21 -0800 | [diff] [blame] | 103 | typedef struct { |
| 104 | int eob_cost[2][11]; |
| 105 | } LV_MAP_EOB_COST; |
Dake He | 0db7d0e | 2017-12-21 15:23:20 -0800 | [diff] [blame] | 106 | |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 107 | typedef struct { |
| 108 | tran_low_t tcoeff[MAX_MB_PLANE][MAX_SB_SQUARE]; |
| 109 | uint16_t eobs[MAX_MB_PLANE][MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)]; |
Hui Su | c328ea2 | 2019-10-01 15:01:27 -0700 | [diff] [blame] | 110 | // Transform block entropy contexts. |
| 111 | // Bits 0~3: txb_skip_ctx; bits 4~5: dc_sign_ctx. |
| 112 | uint8_t entropy_ctx[MAX_MB_PLANE] |
| 113 | [MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)]; |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 114 | } CB_COEFF_BUFFER; |
Jingning Han | dfd7232 | 2017-08-09 14:04:12 -0700 | [diff] [blame] | 115 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 116 | typedef struct { |
Angie Chiang | c484abe | 2017-03-20 15:43:11 -0700 | [diff] [blame] | 117 | // TODO(angiebird): Reduce the buffer size according to sb_type |
Ravi Chaudhary | fa73e20 | 2019-08-19 12:41:26 +0530 | [diff] [blame] | 118 | CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE]; |
| 119 | uint16_t weight[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE]; |
Angie Chiang | 4c9b602 | 2018-04-10 16:16:45 -0700 | [diff] [blame] | 120 | int_mv global_mvs[REF_FRAMES]; |
Satish Kumar Suman | 69e9329 | 2018-11-28 16:05:33 +0530 | [diff] [blame] | 121 | int16_t mode_context[MODE_CTX_REF_FRAMES]; |
| 122 | uint8_t ref_mv_count[MODE_CTX_REF_FRAMES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 123 | } MB_MODE_INFO_EXT; |
| 124 | |
Vishesh | d131791 | 2020-04-07 14:39:44 +0530 | [diff] [blame] | 125 | // Structure to store best mode information at frame level. This |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 126 | // frame level information will be used during bitstream preparation stage. |
| 127 | typedef struct { |
Ravi Chaudhary | fa73e20 | 2019-08-19 12:41:26 +0530 | [diff] [blame] | 128 | CANDIDATE_MV ref_mv_stack[USABLE_REF_MV_STACK_SIZE]; |
| 129 | uint16_t weight[USABLE_REF_MV_STACK_SIZE]; |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 130 | // TODO(Ravi/Remya): Reduce the buffer size of global_mvs |
| 131 | int_mv global_mvs[REF_FRAMES]; |
| 132 | int cb_offset; |
| 133 | int16_t mode_context; |
| 134 | uint8_t ref_mv_count; |
| 135 | } MB_MODE_INFO_EXT_FRAME; |
| 136 | |
Alex Converse | 0fa0f42 | 2017-04-24 12:51:14 -0700 | [diff] [blame] | 137 | typedef struct { |
Hui Su | 473cf89 | 2017-11-08 18:14:31 -0800 | [diff] [blame] | 138 | uint8_t best_palette_color_map[MAX_PALETTE_SQUARE]; |
Hui Su | 5891f98 | 2017-12-18 16:18:23 -0800 | [diff] [blame] | 139 | int kmeans_data_buf[2 * MAX_PALETTE_SQUARE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | } PALETTE_BUFFER; |
| 141 | |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 142 | typedef struct { |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 143 | TX_SIZE tx_size; |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 144 | TX_SIZE inter_tx_size[INTER_TX_SIZE_BUF_LEN]; |
Hui Su | f4b79c7 | 2018-03-22 13:14:36 -0700 | [diff] [blame] | 145 | uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE]; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 146 | uint8_t tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE]; |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 147 | RD_STATS rd_stats; |
| 148 | uint32_t hash_value; |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 149 | } MB_RD_INFO; |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 150 | |
| 151 | #define RD_RECORD_BUFFER_LEN 8 |
| 152 | typedef struct { |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 153 | MB_RD_INFO tx_rd_info[RD_RECORD_BUFFER_LEN]; // Circular buffer. |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 154 | int index_start; |
| 155 | int num; |
Peng Bin | 8a204cd | 2018-04-08 13:07:35 +0800 | [diff] [blame] | 156 | CRC32C crc_calculator; // Hash function. |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 157 | } MB_RD_RECORD; |
Hui Su | 1ddf231 | 2017-08-19 15:21:34 -0700 | [diff] [blame] | 158 | |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 159 | typedef struct { |
| 160 | int64_t dist; |
Jingning Han | 73bc2aa | 2018-02-02 14:31:39 -0800 | [diff] [blame] | 161 | int64_t sse; |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 162 | int rate; |
Hui Su | 8c2b913 | 2017-12-09 10:40:15 -0800 | [diff] [blame] | 163 | uint16_t eob; |
Jingning Han | 73bc2aa | 2018-02-02 14:31:39 -0800 | [diff] [blame] | 164 | TX_TYPE tx_type; |
Jingning Han | 45027c6 | 2017-12-11 11:47:15 -0800 | [diff] [blame] | 165 | uint16_t entropy_context; |
Jingning Han | d7e9911 | 2017-12-13 09:47:45 -0800 | [diff] [blame] | 166 | uint8_t txb_entropy_ctx; |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 167 | uint8_t valid; |
Hui Su | 950b912 | 2018-02-03 10:21:40 -0800 | [diff] [blame] | 168 | uint8_t fast; // This is not being used now. |
Sachin Kumar Garg | 4ec28cb | 2019-06-06 19:33:58 +0530 | [diff] [blame] | 169 | uint8_t perform_block_coeff_opt; |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 170 | } TXB_RD_INFO; |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 171 | |
| 172 | #define TX_SIZE_RD_RECORD_BUFFER_LEN 256 |
| 173 | typedef struct { |
| 174 | uint32_t hash_vals[TX_SIZE_RD_RECORD_BUFFER_LEN]; |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 175 | TXB_RD_INFO tx_rd_info[TX_SIZE_RD_RECORD_BUFFER_LEN]; |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 176 | int index_start; |
| 177 | int num; |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 178 | } TXB_RD_RECORD; |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 179 | |
| 180 | typedef struct tx_size_rd_info_node { |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 181 | TXB_RD_INFO *rd_info_array; // Points to array of size TX_TYPES. |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 182 | struct tx_size_rd_info_node *children[4]; |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 183 | } TXB_RD_INFO_NODE; |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 184 | |
Peng Bin | 525e2da | 2018-09-06 11:32:58 +0800 | [diff] [blame] | 185 | // Simple translation rd state for prune_comp_search_by_single_result |
| 186 | typedef struct { |
| 187 | RD_STATS rd_stats; |
| 188 | RD_STATS rd_stats_y; |
| 189 | RD_STATS rd_stats_uv; |
| 190 | uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE]; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 191 | uint8_t tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE]; |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 192 | uint8_t skip_txfm; |
| 193 | uint8_t disable_skip_txfm; |
Peng Bin | 525e2da | 2018-09-06 11:32:58 +0800 | [diff] [blame] | 194 | uint8_t early_skipped; |
| 195 | } SimpleRDState; |
| 196 | |
| 197 | // 4: NEAREST, NEW, NEAR, GLOBAL |
| 198 | #define SINGLE_REF_MODES ((REF_FRAMES - 1) * 4) |
| 199 | |
Ranjit Kumar Tulabandu | a1ebb57 | 2018-12-24 12:13:54 +0530 | [diff] [blame] | 200 | #define MAX_COMP_RD_STATS 64 |
| 201 | typedef struct { |
| 202 | int32_t rate[COMPOUND_TYPES]; |
| 203 | int64_t dist[COMPOUND_TYPES]; |
Venkat | 457e32e | 2019-12-19 17:44:05 +0530 | [diff] [blame] | 204 | int32_t model_rate[COMPOUND_TYPES]; |
| 205 | int64_t model_dist[COMPOUND_TYPES]; |
venkat sanampudi | c88148e | 2020-01-03 12:57:28 +0530 | [diff] [blame] | 206 | int comp_rs2[COMPOUND_TYPES]; |
Ranjit Kumar Tulabandu | a1ebb57 | 2018-12-24 12:13:54 +0530 | [diff] [blame] | 207 | int_mv mv[2]; |
Hui Su | d06ff66 | 2019-01-23 16:53:05 -0800 | [diff] [blame] | 208 | MV_REFERENCE_FRAME ref_frames[2]; |
Ranjit Kumar Tulabandu | a1ebb57 | 2018-12-24 12:13:54 +0530 | [diff] [blame] | 209 | PREDICTION_MODE mode; |
Ravi Chaudhary | 1e4f94b | 2019-06-20 16:19:49 +0530 | [diff] [blame] | 210 | int_interpfilters filter; |
Ranjit Kumar Tulabandu | a1ebb57 | 2018-12-24 12:13:54 +0530 | [diff] [blame] | 211 | int ref_mv_idx; |
| 212 | int is_global[2]; |
venkat sanampudi | c88148e | 2020-01-03 12:57:28 +0530 | [diff] [blame] | 213 | INTERINTER_COMPOUND_DATA interinter_comp; |
Ranjit Kumar Tulabandu | a1ebb57 | 2018-12-24 12:13:54 +0530 | [diff] [blame] | 214 | } COMP_RD_STATS; |
| 215 | |
Satish Kumar Suman | b8983c4 | 2020-01-23 11:06:19 +0530 | [diff] [blame] | 216 | // Struct for buffers used by av1_compound_type_rd() function. |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 217 | // For sizes and alignment of these arrays, refer to |
| 218 | // alloc_compound_type_rd_buffers() function. |
| 219 | typedef struct { |
| 220 | uint8_t *pred0; |
| 221 | uint8_t *pred1; |
| 222 | int16_t *residual1; // src - pred1 |
| 223 | int16_t *diff10; // pred1 - pred0 |
| 224 | uint8_t *tmp_best_mask_buf; // backup of the best segmentation mask |
| 225 | } CompoundTypeRdBuffers; |
| 226 | |
chiyotsai | d2b1221 | 2020-04-28 20:57:19 -0700 | [diff] [blame^] | 227 | // Struct for buffers used to speed up rdopt for obmc. |
| 228 | // See the comments for calc_target_weighted_pred for details. |
| 229 | typedef struct { |
| 230 | // A new source weighted with the above and left predictors for efficient |
| 231 | // rdopt in obmc mode. |
| 232 | int32_t *wsrc; |
| 233 | // A new mask constructed from the original left and horizontal masks for |
| 234 | // fast obmc rdopt. |
| 235 | int32_t *mask; |
| 236 | // Holds a prediction using the above/left predictor. This is used to build |
| 237 | // the obmc predictor. |
| 238 | uint8_t *above_pred; |
| 239 | uint8_t *left_pred; |
| 240 | } OBMCBuffer; |
| 241 | |
chiyotsai | c95e364 | 2020-04-10 13:17:06 -0700 | [diff] [blame] | 242 | typedef struct { |
| 243 | // A multiplier that converts mv cost to l2 error. |
| 244 | int errorperbit; |
| 245 | // A multiplier that converts mv cost to l1 error. |
| 246 | int sadperbit; |
| 247 | |
| 248 | int nmv_joint_cost[MV_JOINTS]; |
| 249 | |
| 250 | // Below are the entropy costs needed to encode a given mv. |
| 251 | // nmv_costs_(hp_)alloc are two arrays that holds the memory |
| 252 | // for holding the mv cost. But since the motion vectors can be negative, we |
| 253 | // shift them to the middle and store the resulting pointer in nmvcost(_hp) |
| 254 | // for easier referencing. Finally, nmv_cost_stack points to the nmvcost array |
| 255 | // with the mv precision we are currently working with. In essence, only |
| 256 | // mv_cost_stack is needed for motion search, the other can be considered |
| 257 | // private. |
| 258 | int nmv_cost_alloc[2][MV_VALS]; |
| 259 | int nmv_cost_hp_alloc[2][MV_VALS]; |
| 260 | int *nmv_cost[2]; |
| 261 | int *nmv_cost_hp[2]; |
| 262 | int **mv_cost_stack; |
| 263 | } MvCostInfo; |
chiyotsai | 9365bff | 2020-01-31 14:40:05 -0800 | [diff] [blame] | 264 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 265 | struct inter_modes_info; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 266 | typedef struct macroblock MACROBLOCK; |
| 267 | struct macroblock { |
| 268 | struct macroblock_plane plane[MAX_MB_PLANE]; |
| 269 | |
Jingning Han | 66965a2 | 2018-01-25 09:53:41 -0800 | [diff] [blame] | 270 | // Determine if one would go with reduced complexity transform block |
| 271 | // search model to select prediction modes, or full complexity model |
| 272 | // to select transform kernel. |
Jingning Han | dd8600f | 2018-01-23 09:06:32 -0800 | [diff] [blame] | 273 | int rd_model; |
| 274 | |
elliottk | dfc5924 | 2019-04-25 16:38:51 -0700 | [diff] [blame] | 275 | // prune_comp_search_by_single_result (3:MAX_REF_MV_SEARCH) |
Peng Bin | 525e2da | 2018-09-06 11:32:58 +0800 | [diff] [blame] | 276 | SimpleRDState simple_rd_state[SINGLE_REF_MODES][3]; |
| 277 | |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 278 | // Inter macroblock RD search info. |
| 279 | MB_RD_RECORD mb_rd_record; |
Alexander Bokov | c5ddf06 | 2017-10-17 16:41:46 -0700 | [diff] [blame] | 280 | |
Hui Su | 6cb17c1 | 2018-03-09 12:56:20 -0800 | [diff] [blame] | 281 | // Inter transform block RD search info. for square TX sizes. |
| 282 | TXB_RD_RECORD txb_rd_record_8X8[(MAX_MIB_SIZE >> 1) * (MAX_MIB_SIZE >> 1)]; |
| 283 | TXB_RD_RECORD txb_rd_record_16X16[(MAX_MIB_SIZE >> 2) * (MAX_MIB_SIZE >> 2)]; |
| 284 | TXB_RD_RECORD txb_rd_record_32X32[(MAX_MIB_SIZE >> 3) * (MAX_MIB_SIZE >> 3)]; |
| 285 | TXB_RD_RECORD txb_rd_record_64X64[(MAX_MIB_SIZE >> 4) * (MAX_MIB_SIZE >> 4)]; |
| 286 | |
| 287 | // Intra transform block RD search info. for square TX sizes. |
| 288 | TXB_RD_RECORD txb_rd_record_intra; |
Hui Su | ec5a1ab | 2018-03-08 15:09:12 -0800 | [diff] [blame] | 289 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 290 | MACROBLOCKD e_mbd; |
| 291 | MB_MODE_INFO_EXT *mbmi_ext; |
Remya | 0cce44c | 2019-08-16 11:57:24 +0530 | [diff] [blame] | 292 | MB_MODE_INFO_EXT_FRAME *mbmi_ext_frame; |
Cherma Rajan A | 835f7a6 | 2019-09-25 11:04:39 +0530 | [diff] [blame] | 293 | // Array of mode stats for winner mode processing |
Cherma Rajan A | d71ace6 | 2019-11-25 12:58:37 +0530 | [diff] [blame] | 294 | WinnerModeStats winner_mode_stats[AOMMAX(MAX_WINNER_MODE_COUNT_INTRA, |
| 295 | MAX_WINNER_MODE_COUNT_INTER)]; |
Cherma Rajan A | 835f7a6 | 2019-09-25 11:04:39 +0530 | [diff] [blame] | 296 | int winner_mode_count; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 297 | int skip_block; |
David Barker | d7d78c8 | 2016-10-24 10:55:35 +0100 | [diff] [blame] | 298 | int qindex; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 299 | |
Urvang Joshi | 69a986c | 2020-04-27 16:13:11 -0700 | [diff] [blame] | 300 | // The difference between the frame-level base qindex and the qindex used for |
| 301 | // the current superblock. This is used to track whether a non-zero delta for |
| 302 | // qindex is used at least once in the current frame. |
| 303 | int delta_qindex; |
| 304 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | int rdmult; |
| 306 | int mb_energy; |
Yue Chen | de73047 | 2018-06-20 10:13:15 -0700 | [diff] [blame] | 307 | int sb_energy_level; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 308 | |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 309 | unsigned int txb_split_count; |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 310 | #if CONFIG_SPEED_STATS |
| 311 | unsigned int tx_search_count; |
| 312 | #endif // CONFIG_SPEED_STATS |
Jingning Han | 9777afc | 2016-10-20 15:17:43 -0700 | [diff] [blame] | 313 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 314 | // These are set to their default values at the beginning, and then adjusted |
| 315 | // further in the encoding process. |
| 316 | BLOCK_SIZE min_partition_size; |
| 317 | BLOCK_SIZE max_partition_size; |
| 318 | |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 319 | unsigned int max_mv_context[REF_FRAMES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 320 | unsigned int source_variance; |
Yue Chen | 4f719c2 | 2019-02-15 15:13:27 -0800 | [diff] [blame] | 321 | unsigned int simple_motion_pred_sse; |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 322 | unsigned int pred_sse[REF_FRAMES]; |
| 323 | int pred_mv_sad[REF_FRAMES]; |
Lokeshwar Reddy B | ce8b759 | 2019-07-09 18:19:55 +0530 | [diff] [blame] | 324 | int best_pred_mv_sad; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 325 | |
chiyotsai | d2b1221 | 2020-04-28 20:57:19 -0700 | [diff] [blame^] | 326 | // Buffers used to hold/create predictions during rdopt |
| 327 | OBMCBuffer obmc_buffer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 328 | PALETTE_BUFFER *palette_buffer; |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 329 | CompoundTypeRdBuffers comp_rd_buffer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 330 | |
chiyotsai | d2b1221 | 2020-04-28 20:57:19 -0700 | [diff] [blame^] | 331 | // A buffer used for convolution during the averaging prediction in compound |
| 332 | // mode. |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 333 | CONV_BUF_TYPE *tmp_conv_dst; |
chiyotsai | 2a897eb | 2020-04-28 19:22:13 -0700 | [diff] [blame] | 334 | |
| 335 | // Points to a buffer that is used to hold temporary prediction results. This |
| 336 | // is used in two ways: |
| 337 | // 1. This is a temporary buffer used to pingpong the prediction in |
| 338 | // handle_inter_mode. |
| 339 | // 2. xd->tmp_obmc_bufs also points to this buffer, and is used in ombc |
chiyotsai | d2b1221 | 2020-04-28 20:57:19 -0700 | [diff] [blame^] | 340 | // prediction. |
chiyotsai | 2a897eb | 2020-04-28 19:22:13 -0700 | [diff] [blame] | 341 | uint8_t *tmp_pred_bufs[2]; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 342 | |
Ravi Chaudhary | e521517 | 2018-12-21 18:47:25 +0530 | [diff] [blame] | 343 | FRAME_CONTEXT *row_ctx; |
Ravi Chaudhary | 982ac04 | 2018-11-02 14:30:29 +0530 | [diff] [blame] | 344 | // This context will be used to update color_map_cdf pointer which would be |
| 345 | // used during pack bitstream. For single thread and tile-multithreading case |
| 346 | // this ponter will be same as xd->tile_ctx, but for the case of row-mt: |
| 347 | // xd->tile_ctx will point to a temporary context while tile_pb_ctx will point |
| 348 | // to the accurate tile context. |
| 349 | FRAME_CONTEXT *tile_pb_ctx; |
Ravi Chaudhary | 84a280a | 2018-09-24 16:09:48 +0530 | [diff] [blame] | 350 | |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 351 | struct inter_modes_info *inter_modes_info; |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 352 | |
chiyotsai | 82f36c9 | 2020-04-09 16:18:02 -0700 | [diff] [blame] | 353 | // Contains the hash table, hash function, and buffer used for intrabc |
| 354 | IntraBCHashInfo intrabc_hash_info; |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 355 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 356 | // These define limits to motion vector components to prevent them |
| 357 | // from extending outside the UMV borders |
chiyotsai | 2ad959b | 2020-02-12 14:29:32 -0800 | [diff] [blame] | 358 | FullMvLimits mv_limits; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 359 | |
chiyotsai | c95e364 | 2020-04-10 13:17:06 -0700 | [diff] [blame] | 360 | // Stores the entropy cost needed to encode a motion vector. |
| 361 | MvCostInfo mv_cost_info; |
| 362 | |
Hui Su | f4b79c7 | 2018-03-22 13:14:36 -0700 | [diff] [blame] | 363 | uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE]; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 364 | uint8_t tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 365 | |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 366 | // Forces the coding block to skip transform and quantization. |
| 367 | int skip_txfm; |
| 368 | int skip_txfm_cost[SKIP_CONTEXTS][2]; |
Zoe Liu | 1eed2df | 2017-10-16 17:13:15 -0700 | [diff] [blame] | 369 | |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 370 | // Skip mode tries to use the closest forward and backward references for |
| 371 | // inter prediction. Skip here means to skip transmitting the reference |
| 372 | // frames, not to be confused with skip_txfm. |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 373 | int skip_mode; // 0: off; 1: on |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 374 | int skip_mode_cost[SKIP_MODE_CONTEXTS][2]; |
Zoe Liu | f40a957 | 2017-10-13 12:37:19 -0700 | [diff] [blame] | 375 | |
Jingning Han | dfd7232 | 2017-08-09 14:04:12 -0700 | [diff] [blame] | 376 | LV_MAP_COEFF_COST coeff_costs[TX_SIZES][PLANE_TYPES]; |
Dake He | 0db7d0e | 2017-12-21 15:23:20 -0800 | [diff] [blame] | 377 | LV_MAP_EOB_COST eob_costs[7][2]; |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 378 | uint16_t cb_offset; |
Jingning Han | dfd7232 | 2017-08-09 14:04:12 -0700 | [diff] [blame] | 379 | |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 380 | // mode costs |
Yue Chen | 170678a | 2017-10-17 13:43:10 -0700 | [diff] [blame] | 381 | int intra_inter_cost[INTRA_INTER_CONTEXTS][2]; |
| 382 | |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 383 | int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES]; |
| 384 | int newmv_mode_cost[NEWMV_MODE_CONTEXTS][2]; |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 385 | int zeromv_mode_cost[GLOBALMV_MODE_CONTEXTS][2]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 386 | int refmv_mode_cost[REFMV_MODE_CONTEXTS][2]; |
| 387 | int drl_mode_cost0[DRL_MODE_CONTEXTS][2]; |
| 388 | |
Hui Su | 9d0c03d | 2017-12-27 16:05:23 -0800 | [diff] [blame] | 389 | int comp_inter_cost[COMP_INTER_CONTEXTS][2]; |
Hui Su | 3d30b4b | 2017-12-27 16:47:59 -0800 | [diff] [blame] | 390 | int single_ref_cost[REF_CONTEXTS][SINGLE_REFS - 1][2]; |
Hui Su | 6b3d1e3 | 2018-01-05 11:25:40 -0800 | [diff] [blame] | 391 | int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS] |
| 392 | [CDF_SIZE(COMP_REFERENCE_TYPES)]; |
Hui Su | a7e3bfe | 2018-01-05 12:14:48 -0800 | [diff] [blame] | 393 | int uni_comp_ref_cost[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1] |
| 394 | [CDF_SIZE(2)]; |
Hui Su | 0bdf5f5 | 2018-01-05 14:54:32 -0800 | [diff] [blame] | 395 | // Cost for signaling ref_frame[0] (LAST_FRAME, LAST2_FRAME, LAST3_FRAME or |
| 396 | // GOLDEN_FRAME) in bidir-comp mode. |
Zoe Liu | 3b35347 | 2018-02-12 13:58:22 -0800 | [diff] [blame] | 397 | int comp_ref_cost[REF_CONTEXTS][FWD_REFS - 1][2]; |
Hui Su | 0bdf5f5 | 2018-01-05 14:54:32 -0800 | [diff] [blame] | 398 | // Cost for signaling ref_frame[1] (ALTREF_FRAME, ALTREF2_FRAME, or |
| 399 | // BWDREF_FRAME) in bidir-comp mode. |
Zoe Liu | 3b35347 | 2018-02-12 13:58:22 -0800 | [diff] [blame] | 400 | int comp_bwdref_cost[REF_CONTEXTS][BWD_REFS - 1][2]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 401 | int inter_compound_mode_cost[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES]; |
Debargha Mukherjee | 54eabb5 | 2019-02-01 16:54:33 -0800 | [diff] [blame] | 402 | int compound_type_cost[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES]; |
Yue Chen | 73335fa | 2017-12-20 23:33:41 -0800 | [diff] [blame] | 403 | int wedge_idx_cost[BLOCK_SIZES_ALL][16]; |
Yue Chen | eaf128a | 2017-10-16 17:01:36 -0700 | [diff] [blame] | 404 | int interintra_cost[BLOCK_SIZE_GROUPS][2]; |
| 405 | int wedge_interintra_cost[BLOCK_SIZES_ALL][2]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 406 | int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 407 | int motion_mode_cost[BLOCK_SIZES_ALL][MOTION_MODES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 408 | int motion_mode_cost1[BLOCK_SIZES_ALL][2]; |
David Michael Barr | cb3a8ef | 2018-01-06 15:48:49 +0900 | [diff] [blame] | 409 | int intra_uv_mode_cost[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 410 | int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; |
Yue Chen | 45dfb79 | 2018-03-01 13:02:40 -0800 | [diff] [blame] | 411 | int filter_intra_cost[BLOCK_SIZES_ALL][2]; |
Yue Chen | 994dba2 | 2017-12-19 15:27:26 -0800 | [diff] [blame] | 412 | int filter_intra_mode_cost[FILTER_INTRA_MODES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 413 | int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; |
Sebastien Alaiwan | a6a486c | 2017-11-07 17:04:27 +0100 | [diff] [blame] | 414 | int partition_cost[PARTITION_CONTEXTS][EXT_PARTITION_TYPES]; |
Hui Su | c1f411b | 2017-12-19 15:58:28 -0800 | [diff] [blame] | 415 | int palette_y_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
| 416 | int palette_uv_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 417 | int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS] |
| 418 | [PALETTE_COLORS]; |
| 419 | int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS] |
| 420 | [PALETTE_COLORS]; |
Hui Su | c1f411b | 2017-12-19 15:58:28 -0800 | [diff] [blame] | 421 | int palette_y_mode_cost[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS][2]; |
Yue Chen | dab2ca9 | 2017-10-16 17:48:48 -0700 | [diff] [blame] | 422 | int palette_uv_mode_cost[PALETTE_UV_MODE_CONTEXTS][2]; |
David Michael Barr | 38e560c | 2017-08-16 21:46:37 +0900 | [diff] [blame] | 423 | // The rate associated with each alpha codeword |
| 424 | int cfl_cost[CFL_JOINT_SIGNS][CFL_PRED_PLANES][CFL_ALPHABET_SIZE]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 425 | int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES]; |
Yue Chen | 171c17d | 2017-10-16 18:08:22 -0700 | [diff] [blame] | 426 | int txfm_partition_cost[TXFM_PARTITION_CONTEXTS][2]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 427 | int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES]; |
| 428 | int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES] |
| 429 | [TX_TYPES]; |
Joe Young | 3ca43bf | 2017-10-06 15:12:46 -0700 | [diff] [blame] | 430 | int angle_delta_cost[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 431 | int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES]; |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 432 | int wiener_restore_cost[2]; |
| 433 | int sgrproj_restore_cost[2]; |
Hui Su | 6c8584f | 2017-09-14 15:37:02 -0700 | [diff] [blame] | 434 | int intrabc_cost[2]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 435 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 436 | // Used to store sub partition's choices. |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 437 | MV pred_mv[REF_FRAMES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 438 | |
Hui Su | 835bbd5 | 2019-03-05 23:18:15 -0800 | [diff] [blame] | 439 | // Ref frames that are selected by square partition blocks within a super- |
| 440 | // block, in MI resolution. They can be used to prune ref frames for |
| 441 | // rectangular blocks. |
| 442 | int picked_ref_frames_mask[32 * 32]; |
| 443 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 444 | // use default transform and skip transform type search for intra modes |
| 445 | int use_default_intra_tx_type; |
| 446 | // use default transform and skip transform type search for inter modes |
| 447 | int use_default_inter_tx_type; |
Cheng Chen | 4697061 | 2017-10-24 14:53:36 -0700 | [diff] [blame] | 448 | int comp_idx_cost[COMP_INDEX_CONTEXTS][2]; |
Cheng Chen | 2ef24ea | 2017-11-29 12:22:24 -0800 | [diff] [blame] | 449 | int comp_group_idx_cost[COMP_GROUP_IDX_CONTEXTS][2]; |
Hui Su | 845a741 | 2018-03-08 12:21:00 -0800 | [diff] [blame] | 450 | int must_find_valid_partition; |
Ranjit Kumar Tulabandu | 8105bf4 | 2018-07-27 14:16:55 +0530 | [diff] [blame] | 451 | int recalc_luma_mc_data; // Flag to indicate recalculation of MC data during |
| 452 | // interpolation filter search |
Cherma Rajan A | 12478f3 | 2019-10-31 10:03:34 +0530 | [diff] [blame] | 453 | int prune_mode; |
Cherma Rajan A | 628efce | 2019-09-18 18:55:12 +0530 | [diff] [blame] | 454 | uint32_t tx_domain_dist_threshold; |
Cherma Rajan A | ba4e156 | 2019-08-29 14:45:22 +0530 | [diff] [blame] | 455 | int use_transform_domain_distortion; |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 456 | // The likelihood of an edge existing in the block (using partial Canny edge |
| 457 | // detection). For reference, 556 is the value returned for a solid |
| 458 | // vertical black/white edge. |
| 459 | uint16_t edge_strength; |
elliottk | 17dd3ea | 2019-02-01 11:59:57 -0800 | [diff] [blame] | 460 | // The strongest edge strength seen along the x/y axis. |
| 461 | uint16_t edge_strength_x; |
| 462 | uint16_t edge_strength_y; |
Remya | 05be56a | 2019-04-15 19:09:08 +0530 | [diff] [blame] | 463 | uint8_t compound_idx; |
Ranjit Kumar Tulabandu | a1ebb57 | 2018-12-24 12:13:54 +0530 | [diff] [blame] | 464 | |
| 465 | // [Saved stat index] |
| 466 | COMP_RD_STATS comp_rd_stats[MAX_COMP_RD_STATS]; |
| 467 | int comp_rd_stats_idx; |
Hui Su | f1b1106 | 2019-04-17 14:18:26 -0700 | [diff] [blame] | 468 | |
| 469 | CB_COEFF_BUFFER *cb_coef_buff; |
chiyotsai | 36035d1 | 2019-06-19 17:39:48 -0700 | [diff] [blame] | 470 | |
Ranjit Kumar Tulabandu | 824f9db | 2019-07-05 15:16:37 +0530 | [diff] [blame] | 471 | // Threshold used to decide the applicability of R-D optimization of |
| 472 | // quantized coeffs |
| 473 | uint32_t coeff_opt_dist_threshold; |
| 474 | |
chiyotsai | 36035d1 | 2019-06-19 17:39:48 -0700 | [diff] [blame] | 475 | #if !CONFIG_REALTIME_ONLY |
| 476 | int quad_tree_idx; |
chiyotsai | 52ac004 | 2019-07-01 09:48:03 -0700 | [diff] [blame] | 477 | int cnn_output_valid; |
chiyotsai | 36035d1 | 2019-06-19 17:39:48 -0700 | [diff] [blame] | 478 | float cnn_buffer[CNN_OUT_BUF_SIZE]; |
| 479 | float log_q; |
| 480 | #endif |
Ravi Chaudhary | b61cdea | 2019-07-05 15:01:20 +0530 | [diff] [blame] | 481 | int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES]; |
Jerome Jiang | a996e77 | 2020-02-25 11:40:13 -0800 | [diff] [blame] | 482 | // 0 - 128x128 |
| 483 | // 1-2 - 128x64 |
| 484 | // 3-4 - 64x128 |
| 485 | // 5-8 - 64x64 |
| 486 | // 9-16 - 64x32 |
| 487 | // 17-24 - 32x64 |
| 488 | // 25-40 - 32x32 |
| 489 | // 41-104 - 16x16 |
Fyodor Kyslov | 59745d9 | 2019-07-30 18:16:54 -0700 | [diff] [blame] | 490 | uint8_t variance_low[105]; |
Marco Paniconi | 1bfbd9f | 2020-02-25 20:05:08 -0800 | [diff] [blame] | 491 | uint8_t content_state_sb; |
Fyodor Kyslov | abef54f | 2019-08-14 14:43:12 -0700 | [diff] [blame] | 492 | // Strong color activity detection. Used in REALTIME coding mode to enhance |
| 493 | // the visual quality at the boundary of moving color objects. |
| 494 | uint8_t color_sensitivity[2]; |
Fyodor Kyslov | 54ebdad | 2020-02-27 12:47:02 -0800 | [diff] [blame] | 495 | int nonrd_prune_ref_frame_search; |
Cherma Rajan A | 3ed030f | 2019-08-16 18:56:00 +0530 | [diff] [blame] | 496 | |
| 497 | // Used to control the tx size search evaluation for mode processing |
| 498 | // (normal/winner mode) |
| 499 | int tx_size_search_method; |
chiyotsai | f271f9f | 2019-11-25 16:44:25 -0800 | [diff] [blame] | 500 | // This tx_mode_search_type is used internally by the encoder, and is not |
| 501 | // written to the bitstream. It determines what kind of tx_mode should be |
| 502 | // searched. For example, we might set it to TX_MODE_LARGEST to find a good |
| 503 | // candidate, then use TX_MODE_SELECT on it |
| 504 | TX_MODE tx_mode_search_type; |
Yunqing Wang | 61b2eac | 2019-09-24 16:45:16 -0700 | [diff] [blame] | 505 | |
Nithya V S | d0276ac | 2019-10-24 11:31:06 +0530 | [diff] [blame] | 506 | // Used to control aggressiveness of skip flag prediction for mode processing |
| 507 | // (normal/winner mode) |
| 508 | unsigned int predict_skip_level; |
| 509 | |
Hui Su | 922db60 | 2020-03-18 13:39:29 -0700 | [diff] [blame] | 510 | uint8_t search_ref_frame[REF_FRAMES]; |
Jingning Han | 185d23b | 2020-03-04 09:12:05 -0800 | [diff] [blame] | 511 | |
chiyotsai | ff73c53 | 2020-04-21 12:50:12 -0700 | [diff] [blame] | 512 | // The information on a whole superblock level. |
| 513 | // TODO(chiyotsai@google.com): Refactor this out of macroblock |
| 514 | SuperBlockEnc sb_enc; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 515 | }; |
| 516 | |
Yunqing Wang | 8317cac | 2019-09-25 10:52:51 -0700 | [diff] [blame] | 517 | // Only consider full SB, MC_FLOW_BSIZE_1D = 16. |
| 518 | static INLINE int tpl_blocks_in_sb(BLOCK_SIZE bsize) { |
| 519 | switch (bsize) { |
| 520 | case BLOCK_64X64: return 16; |
| 521 | case BLOCK_128X128: return 64; |
| 522 | default: assert(0); |
| 523 | } |
| 524 | return -1; |
| 525 | } |
| 526 | |
Frederic Barbier | 0f191da | 2018-01-03 17:29:26 +0100 | [diff] [blame] | 527 | static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) { |
| 528 | static const char LUT[BLOCK_SIZES_ALL] = { |
| 529 | 0, // BLOCK_4X4 |
| 530 | 1, // BLOCK_4X8 |
| 531 | 1, // BLOCK_8X4 |
| 532 | 0, // BLOCK_8X8 |
| 533 | 1, // BLOCK_8X16 |
| 534 | 1, // BLOCK_16X8 |
| 535 | 0, // BLOCK_16X16 |
| 536 | 1, // BLOCK_16X32 |
| 537 | 1, // BLOCK_32X16 |
| 538 | 0, // BLOCK_32X32 |
| 539 | 1, // BLOCK_32X64 |
| 540 | 1, // BLOCK_64X32 |
| 541 | 0, // BLOCK_64X64 |
Frederic Barbier | 0f191da | 2018-01-03 17:29:26 +0100 | [diff] [blame] | 542 | 0, // BLOCK_64X128 |
| 543 | 0, // BLOCK_128X64 |
| 544 | 0, // BLOCK_128X128 |
Frederic Barbier | 0f191da | 2018-01-03 17:29:26 +0100 | [diff] [blame] | 545 | 1, // BLOCK_4X16 |
| 546 | 1, // BLOCK_16X4 |
| 547 | 1, // BLOCK_8X32 |
| 548 | 1, // BLOCK_32X8 |
| 549 | 1, // BLOCK_16X64 |
| 550 | 1, // BLOCK_64X16 |
Frederic Barbier | 0f191da | 2018-01-03 17:29:26 +0100 | [diff] [blame] | 551 | }; |
| 552 | |
| 553 | return LUT[bsize]; |
| 554 | } |
| 555 | |
| 556 | static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd, |
| 557 | const MB_MODE_INFO *mbmi) { |
| 558 | return is_rect_tx_allowed_bsize(mbmi->sb_type) && |
| 559 | !xd->lossless[mbmi->segment_id]; |
| 560 | } |
| 561 | |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 562 | 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] | 563 | TX_SIZE ctx_size = max_txsize_rect_lookup[bsize]; |
Frederic Barbier | 0f191da | 2018-01-03 17:29:26 +0100 | [diff] [blame] | 564 | int depth = 0; |
| 565 | while (tx_size != ctx_size) { |
| 566 | depth++; |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 567 | ctx_size = sub_tx_size_map[ctx_size]; |
Frederic Barbier | 0f191da | 2018-01-03 17:29:26 +0100 | [diff] [blame] | 568 | assert(depth <= MAX_TX_DEPTH); |
| 569 | } |
| 570 | return depth; |
| 571 | } |
| 572 | |
Grant Hsu | 39248c3 | 2018-09-18 10:38:44 +0800 | [diff] [blame] | 573 | static INLINE void set_blk_skip(MACROBLOCK *x, int plane, int blk_idx, |
| 574 | int skip) { |
| 575 | if (skip) |
| 576 | x->blk_skip[blk_idx] |= 1UL << plane; |
| 577 | else |
| 578 | x->blk_skip[blk_idx] &= ~(1UL << plane); |
| 579 | #ifndef NDEBUG |
| 580 | // Set chroma planes to uninitialized states when luma is set to check if |
| 581 | // it will be set later |
| 582 | if (plane == 0) { |
| 583 | x->blk_skip[blk_idx] |= 1UL << (1 + 4); |
| 584 | x->blk_skip[blk_idx] |= 1UL << (2 + 4); |
| 585 | } |
| 586 | |
| 587 | // Clear the initialization checking bit |
| 588 | x->blk_skip[blk_idx] &= ~(1UL << (plane + 4)); |
| 589 | #endif |
| 590 | } |
| 591 | |
| 592 | static INLINE int is_blk_skip(MACROBLOCK *x, int plane, int blk_idx) { |
| 593 | #ifndef NDEBUG |
| 594 | // Check if this is initialized |
| 595 | assert(!(x->blk_skip[blk_idx] & (1UL << (plane + 4)))); |
| 596 | |
| 597 | // The magic number is 0x77, this is to test if there is garbage data |
| 598 | assert((x->blk_skip[blk_idx] & 0x88) == 0); |
| 599 | #endif |
| 600 | return (x->blk_skip[blk_idx] >> plane) & 1; |
| 601 | } |
| 602 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 603 | #ifdef __cplusplus |
| 604 | } // extern "C" |
| 605 | #endif |
| 606 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 607 | #endif // AOM_AV1_ENCODER_BLOCK_H_ |