| File: | root/firefox-clang/third_party/aom/av1/encoder/block.h |
| Warning: | line 889, column 16 Excessive padding in 'struct macroblock' (47 padding bytes, where 15 is optimal). Optimal fields order: e_mbd, mbmi_ext_frame, row_ctx, tile_pb_ctx, cb_coef_buff, palette_buffer, tmp_conv_dst, upsample_pred, rb, mv_costs, dv_costs, winner_mode_stats, inter_modes_info, mb_mode_cache, pixel_gradient_info, min_dist_inter_uv, dqcoeff_buf, src_var_info_of_4x4_sub_blocks, sb_stats_cache, sb_fp_stats, tmp_pred_bufs, obmc_buffer, comp_rd_buffer, top_comp_avg_est_rd, top_inter_tx_no_split_rd, plane, txfm_search_info, sb_enc, intrabc_hash_info, comp_rd_stats, qindex, delta_qindex, rdmult_delta_qindex, rdmult_cur_qindex, rdmult, intra_sb_rdmult_modifier, mb_energy, sb_energy_level, errorperbit, sadperbit, seg_skip_block, actual_num_seg1_blocks, actual_num_seg2_blocks, cnt_zeromv, force_zeromv_skip_for_sb, force_zeromv_skip_for_blk, prev_segment_id, nonrd_prune_ref_frame_search, must_find_valid_partition, skip_mode, winner_mode_count, comp_rd_stats_idx, recalc_luma_mc_data, use_mb_mode_cache, color_palette_thresh, force_color_check_block_level, source_variance, block_is_zero_sad, sb_me_partition, sb_me_block, sb_col_scroll, sb_row_scroll, sb_me_mv, sb_force_fixed_part, try_merge_partition, palette_pixels, pix_to_bottom_edge, pix_to_right_edge, best_pred_mv_sad, last_set_offsets_loc, content_state_sb, mv_limits, pred_mv_sad, pred_mv0_sad, pred_mv1_sad, max_mv_context, pred_sse, txfm_search_params, warp_sample_info, mbmi_ext, picked_ref_frames_mask, part_search_info, thresh_freq_fact, search_site_cfg_buf, mode_costs, coeff_costs, cb_offset, rd_model, compound_idx, reuse_inter_pred, is_sb_gradient_cached, color_sensitivity_sb, color_sensitivity_sb_g, color_sensitivity_sb_alt, color_sensitivity, tpl_keep_ref_frame, consider reordering the fields or adding explicit padding members |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved. |
| 3 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | /*! \file |
| 13 | * Declares various structs used to encode the current partition block. |
| 14 | */ |
| 15 | #ifndef AOM_AV1_ENCODER_BLOCK_H_ |
| 16 | #define AOM_AV1_ENCODER_BLOCK_H_ |
| 17 | |
| 18 | #include "av1/common/blockd.h" |
| 19 | #include "av1/common/entropymv.h" |
| 20 | #include "av1/common/entropy.h" |
| 21 | #include "av1/common/enums.h" |
| 22 | #include "av1/common/mvref_common.h" |
| 23 | |
| 24 | #include "av1/encoder/enc_enums.h" |
| 25 | #include "av1/encoder/mcomp_structs.h" |
| 26 | #if !CONFIG_REALTIME_ONLY0 |
| 27 | #include "av1/encoder/partition_cnn_weights.h" |
| 28 | #endif |
| 29 | |
| 30 | #include "av1/encoder/hash_motion.h" |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | //! Minimum linear dimension of a tpl block |
| 37 | #define MIN_TPL_BSIZE_1D16 16 |
| 38 | //! Maximum number of tpl block in a super block |
| 39 | #define MAX_TPL_BLK_IN_SB((1 << 7) / 16) (MAX_SB_SIZE(1 << 7) / MIN_TPL_BSIZE_1D16) |
| 40 | //! Number of txfm hash records kept for the partition block. |
| 41 | #define RD_RECORD_BUFFER_LEN8 8 |
| 42 | |
| 43 | /*! Maximum value taken by transform type probabilities */ |
| 44 | #define MAX_TX_TYPE_PROB1024 1024 |
| 45 | |
| 46 | /*! Maximum value of inter transform RD records. */ |
| 47 | #define TOP_INTER_TX_NO_SPLIT_COUNT4 4 |
| 48 | |
| 49 | //! Compute color sensitivity index for given plane |
| 50 | #define COLOR_SENS_IDX(plane)((plane) - 1) ((plane) - 1) |
| 51 | |
| 52 | //! Enable timer statistics of mode search in non-rd |
| 53 | #define COLLECT_NONRD_PICK_MODE_STAT0 0 |
| 54 | |
| 55 | /*!\cond */ |
| 56 | #if COLLECT_NONRD_PICK_MODE_STAT0 |
| 57 | #include "aom_ports/aom_timer.h" |
| 58 | |
| 59 | typedef struct _mode_search_stat_nonrd { |
| 60 | int32_t num_blocks[BLOCK_SIZES]; |
| 61 | int64_t total_block_times[BLOCK_SIZES]; |
| 62 | int32_t num_searches[BLOCK_SIZES][MB_MODE_COUNT]; |
| 63 | int32_t num_nonskipped_searches[BLOCK_SIZES][MB_MODE_COUNT]; |
| 64 | int64_t search_times[BLOCK_SIZES][MB_MODE_COUNT]; |
| 65 | int64_t nonskipped_search_times[BLOCK_SIZES][MB_MODE_COUNT]; |
| 66 | int64_t ms_time[BLOCK_SIZES][MB_MODE_COUNT]; |
| 67 | int64_t ifs_time[BLOCK_SIZES][MB_MODE_COUNT]; |
| 68 | int64_t model_rd_time[BLOCK_SIZES][MB_MODE_COUNT]; |
| 69 | int64_t txfm_time[BLOCK_SIZES][MB_MODE_COUNT]; |
| 70 | struct aom_usec_timer timer1; |
| 71 | struct aom_usec_timer timer2; |
| 72 | struct aom_usec_timer bsize_timer; |
| 73 | } mode_search_stat_nonrd; |
| 74 | #endif // COLLECT_NONRD_PICK_MODE_STAT |
| 75 | /*!\endcond */ |
| 76 | |
| 77 | /*! \brief Superblock level encoder info |
| 78 | * |
| 79 | * SuperblockEnc stores superblock level information used by the encoder for |
| 80 | * more efficient encoding. Currently this is mostly used to store TPL data |
| 81 | * for the current superblock. |
| 82 | */ |
| 83 | typedef struct { |
| 84 | //! Maximum partition size for the sb. |
| 85 | BLOCK_SIZE min_partition_size; |
| 86 | //! Minimum partition size for the sb. |
| 87 | BLOCK_SIZE max_partition_size; |
| 88 | |
| 89 | /***************************************************************************** |
| 90 | * \name TPL Info |
| 91 | * |
| 92 | * Information gathered from tpl_model at tpl block precision for the |
| 93 | * superblock to speed up the encoding process.. |
| 94 | ****************************************************************************/ |
| 95 | /**@{*/ |
| 96 | //! Number of TPL blocks in this superblock. |
| 97 | int tpl_data_count; |
| 98 | //! TPL's estimate of inter cost for each tpl block. |
| 99 | int64_t tpl_inter_cost[MAX_TPL_BLK_IN_SB((1 << 7) / 16) * MAX_TPL_BLK_IN_SB((1 << 7) / 16)]; |
| 100 | //! TPL's estimate of tpl cost for each tpl block. |
| 101 | int64_t tpl_intra_cost[MAX_TPL_BLK_IN_SB((1 << 7) / 16) * MAX_TPL_BLK_IN_SB((1 << 7) / 16)]; |
| 102 | //! Motion vectors found by TPL model for each tpl block. |
| 103 | int_mv tpl_mv[MAX_TPL_BLK_IN_SB((1 << 7) / 16) * MAX_TPL_BLK_IN_SB((1 << 7) / 16)][INTER_REFS_PER_FRAME]; |
| 104 | //! TPL's stride for the arrays in this struct. |
| 105 | int tpl_stride; |
| 106 | /**@}*/ |
| 107 | } SuperBlockEnc; |
| 108 | |
| 109 | /*! \brief Stores the best performing modes. |
| 110 | */ |
| 111 | typedef struct { |
| 112 | //! The mbmi used to reconstruct the winner mode. |
| 113 | MB_MODE_INFO mbmi; |
| 114 | //! Rdstats of the winner mode. |
| 115 | RD_STATS rd_cost; |
| 116 | //! Rdcost of the winner mode |
| 117 | int64_t rd; |
| 118 | //! Luma rate of the winner mode. |
| 119 | int rate_y; |
| 120 | //! Chroma rate of the winner mode. |
| 121 | int rate_uv; |
| 122 | //! The color map needed to reconstruct palette mode. |
| 123 | uint8_t color_index_map[MAX_SB_SQUARE((1 << 7) * (1 << 7))]; |
| 124 | //! The current winner mode. |
| 125 | THR_MODES mode_index; |
| 126 | } WinnerModeStats; |
| 127 | |
| 128 | /*! \brief Each source plane of the current macroblock |
| 129 | * |
| 130 | * This struct also stores the txfm buffers and quantizer settings. |
| 131 | */ |
| 132 | typedef struct macroblock_plane { |
| 133 | //! Stores source - pred so the txfm can be computed later |
| 134 | int16_t *src_diff; |
| 135 | //! Dequantized coefficients |
| 136 | tran_low_t *dqcoeff; |
| 137 | //! Quantized coefficients |
| 138 | tran_low_t *qcoeff; |
| 139 | //! Transformed coefficients |
| 140 | tran_low_t *coeff; |
| 141 | //! Location of the end of qcoeff (end of block). |
| 142 | uint16_t *eobs; |
| 143 | //! Contexts used to code the transform coefficients. |
| 144 | uint8_t *txb_entropy_ctx; |
| 145 | //! A buffer containing the source frame. |
| 146 | struct buf_2d src; |
| 147 | |
| 148 | /*! \name Quantizer Settings |
| 149 | * |
| 150 | * \attention These are used/accessed only in the quantization process. |
| 151 | * RDO does not and *must not* depend on any of these values. |
| 152 | * All values below share the coefficient scale/shift used in TX. |
| 153 | */ |
| 154 | /**@{*/ |
| 155 | //! Quantization step size used by AV1_XFORM_QUANT_FP. |
| 156 | const int16_t *quant_fp_QTX; |
| 157 | //! Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_FP. |
| 158 | const int16_t *round_fp_QTX; |
| 159 | //! Quantization step size used by AV1_XFORM_QUANT_B. |
| 160 | const int16_t *quant_QTX; |
| 161 | //! Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_B. |
| 162 | const int16_t *round_QTX; |
| 163 | //! Scale factor to shift coefficients toward zero. Only used by QUANT_B. |
| 164 | const int16_t *quant_shift_QTX; |
| 165 | //! Size of the quantization bin around 0. Only Used by QUANT_B |
| 166 | const int16_t *zbin_QTX; |
| 167 | //! Dequantizer |
| 168 | const int16_t *dequant_QTX; |
| 169 | /**@}*/ |
| 170 | } MACROBLOCK_PLANE; |
| 171 | |
| 172 | /*! \brief Costs for encoding the coefficients within a level. |
| 173 | * |
| 174 | * Covers everything including txb_skip, eob, dc_sign, |
| 175 | */ |
| 176 | typedef struct { |
| 177 | //! Cost to skip txfm for the current txfm block. |
| 178 | int txb_skip_cost[TXB_SKIP_CONTEXTS13][2]; |
| 179 | /*! \brief Cost for encoding the base_eob of a level. |
| 180 | * |
| 181 | * Decoder uses base_eob to derive the base_level as base_eob := base_eob+1. |
| 182 | */ |
| 183 | int base_eob_cost[SIG_COEF_CONTEXTS_EOB4][3]; |
| 184 | /*! \brief Cost for encoding the base level of a coefficient. |
| 185 | * |
| 186 | * Decoder derives coeff_base as coeff_base := base_eob + 1. |
| 187 | */ |
| 188 | int base_cost[SIG_COEF_CONTEXTS(26 + 16)][8]; |
| 189 | /*! \brief Cost for encoding the last non-zero coefficient. |
| 190 | * |
| 191 | * Eob is derived from eob_extra at the decoder as eob := eob_extra + 1 |
| 192 | */ |
| 193 | int eob_extra_cost[EOB_COEF_CONTEXTS9][2]; |
| 194 | //! Cost for encoding the dc_sign |
| 195 | int dc_sign_cost[DC_SIGN_CONTEXTS3][2]; |
| 196 | //! Cost for encoding an increment to the coefficient |
| 197 | int lps_cost[LEVEL_CONTEXTS21][COEFF_BASE_RANGE(4 * ((4) - 1)) + 1 + COEFF_BASE_RANGE(4 * ((4) - 1)) + 1]; |
| 198 | } LV_MAP_COEFF_COST; |
| 199 | |
| 200 | /*! \brief Costs for encoding the eob. |
| 201 | */ |
| 202 | typedef struct { |
| 203 | //! eob_cost. |
| 204 | int eob_cost[2][11]; |
| 205 | } LV_MAP_EOB_COST; |
| 206 | |
| 207 | /*! \brief Stores the transforms coefficients for the whole superblock. |
| 208 | */ |
| 209 | typedef struct { |
| 210 | //! The transformed coefficients. |
| 211 | tran_low_t *tcoeff[MAX_MB_PLANE3]; |
| 212 | //! Where the transformed coefficients end. |
| 213 | uint16_t *eobs[MAX_MB_PLANE3]; |
| 214 | /*! \brief Transform block entropy contexts. |
| 215 | * |
| 216 | * Each element is used as a bit field. |
| 217 | * - Bits 0~3: txb_skip_ctx |
| 218 | * - Bits 4~5: dc_sign_ctx. |
| 219 | */ |
| 220 | uint8_t *entropy_ctx[MAX_MB_PLANE3]; |
| 221 | } CB_COEFF_BUFFER; |
| 222 | |
| 223 | /*! \brief Extended mode info derived from mbmi. |
| 224 | */ |
| 225 | typedef struct { |
| 226 | // TODO(angiebird): Reduce the buffer size according to sb_type |
| 227 | //! The reference mv list for the current block. |
| 228 | CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES(REF_FRAMES + (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS))][USABLE_REF_MV_STACK_SIZE4]; |
| 229 | //! The weights used to compute the ref mvs. |
| 230 | uint16_t weight[MODE_CTX_REF_FRAMES(REF_FRAMES + (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS))][USABLE_REF_MV_STACK_SIZE4]; |
| 231 | //! Number of ref mvs in the drl. |
| 232 | uint8_t ref_mv_count[MODE_CTX_REF_FRAMES(REF_FRAMES + (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS))]; |
| 233 | //! Global mvs |
| 234 | int_mv global_mvs[REF_FRAMES]; |
| 235 | //! Context used to encode the current mode. |
| 236 | int16_t mode_context[MODE_CTX_REF_FRAMES(REF_FRAMES + (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS))]; |
| 237 | } MB_MODE_INFO_EXT; |
| 238 | |
| 239 | /*! \brief Stores best extended mode information at frame level. |
| 240 | * |
| 241 | * The frame level in here is used in bitstream preparation stage. The |
| 242 | * information in \ref MB_MODE_INFO_EXT are copied to this struct to save |
| 243 | * memory. |
| 244 | */ |
| 245 | typedef struct { |
| 246 | //! \copydoc MB_MODE_INFO_EXT::ref_mv_stack |
| 247 | CANDIDATE_MV ref_mv_stack[USABLE_REF_MV_STACK_SIZE4]; |
| 248 | //! \copydoc MB_MODE_INFO_EXT::weight |
| 249 | uint16_t weight[USABLE_REF_MV_STACK_SIZE4]; |
| 250 | //! \copydoc MB_MODE_INFO_EXT::ref_mv_count |
| 251 | uint8_t ref_mv_count; |
| 252 | // TODO(Ravi/Remya): Reduce the buffer size of global_mvs |
| 253 | //! \copydoc MB_MODE_INFO_EXT::global_mvs |
| 254 | int_mv global_mvs[REF_FRAMES]; |
| 255 | //! \copydoc MB_MODE_INFO_EXT::mode_context |
| 256 | int16_t mode_context; |
| 257 | //! Offset of current coding block's coeff buffer relative to the sb. |
| 258 | uint16_t cb_offset[PLANE_TYPES]; |
| 259 | } MB_MODE_INFO_EXT_FRAME; |
| 260 | |
| 261 | /*! \brief Inter-mode txfm results for a partition block. |
| 262 | */ |
| 263 | typedef struct { |
| 264 | //! Txfm size used if the current mode is intra mode. |
| 265 | TX_SIZE tx_size; |
| 266 | //! Txfm sizes used if the current mode is inter mode. |
| 267 | TX_SIZE inter_tx_size[INTER_TX_SIZE_BUF_LEN16]; |
| 268 | //! Map showing which txfm block skips the txfm process. |
| 269 | uint8_t blk_skip[MAX_MIB_SIZE(1 << (7 - 2)) * MAX_MIB_SIZE(1 << (7 - 2))]; |
| 270 | //! Map showing the txfm types for each block. |
| 271 | uint8_t tx_type_map[MAX_MIB_SIZE(1 << (7 - 2)) * MAX_MIB_SIZE(1 << (7 - 2))]; |
| 272 | //! Rd_stats for the whole partition block. |
| 273 | RD_STATS rd_stats; |
| 274 | //! Hash value of the current record. |
| 275 | uint32_t hash_value; |
| 276 | } MB_RD_INFO; |
| 277 | |
| 278 | /*! \brief Hash records of the inter-mode transform results |
| 279 | * |
| 280 | * Hash records of the inter-mode transform results for a whole partition block |
| 281 | * based on the residue. Since this operates on the partition block level, this |
| 282 | * can give us a whole txfm partition tree. |
| 283 | */ |
| 284 | typedef struct { |
| 285 | /*! Circular buffer that stores the inter-mode txfm results of a partition |
| 286 | * block. |
| 287 | */ |
| 288 | MB_RD_INFO mb_rd_info[RD_RECORD_BUFFER_LEN8]; |
| 289 | //! Index to insert the newest rd record. |
| 290 | int index_start; |
| 291 | //! Number of info stored in this record. |
| 292 | int num; |
| 293 | //! Hash function |
| 294 | CRC32C crc_calculator; |
| 295 | } MB_RD_RECORD; |
| 296 | |
| 297 | //! Number of compound rd stats |
| 298 | #define MAX_COMP_RD_STATS64 64 |
| 299 | /*! \brief Rdcost stats in compound mode. |
| 300 | */ |
| 301 | typedef struct { |
| 302 | //! Rate of the compound modes. |
| 303 | int32_t rate[COMPOUND_TYPES]; |
| 304 | //! Distortion of the compound modes. |
| 305 | int64_t dist[COMPOUND_TYPES]; |
| 306 | //! Estimated rate of the compound modes. |
| 307 | int32_t model_rate[COMPOUND_TYPES]; |
| 308 | //! Estimated distortion of the compound modes. |
| 309 | int64_t model_dist[COMPOUND_TYPES]; |
| 310 | //! Rate need to send the mask type. |
| 311 | int comp_rs2[COMPOUND_TYPES]; |
| 312 | //! Motion vector for each predictor. |
| 313 | int_mv mv[2]; |
| 314 | //! Ref frame for each predictor. |
| 315 | MV_REFERENCE_FRAME ref_frames[2]; |
| 316 | //! Current prediction mode. |
| 317 | PREDICTION_MODE mode; |
| 318 | //! Current interpolation filter. |
| 319 | int_interpfilters filter; |
| 320 | //! Refmv index in the drl. |
| 321 | int ref_mv_idx; |
| 322 | //! Whether the predictors are GLOBALMV. |
| 323 | int is_global[2]; |
| 324 | //! Current parameters for interinter mode. |
| 325 | INTERINTER_COMPOUND_DATA interinter_comp; |
| 326 | } COMP_RD_STATS; |
| 327 | |
| 328 | /*! \brief Contains buffers used to speed up rdopt for obmc. |
| 329 | * |
| 330 | * See the comments for calc_target_weighted_pred for details. |
| 331 | */ |
| 332 | typedef struct { |
| 333 | /*! \brief A new source weighted with the above and left predictors. |
| 334 | * |
| 335 | * Used to efficiently construct multiple obmc predictors during rdopt. |
| 336 | */ |
| 337 | int32_t *wsrc; |
| 338 | /*! \brief A new mask constructed from the original horz/vert mask. |
| 339 | * |
| 340 | * \copydetails wsrc |
| 341 | */ |
| 342 | int32_t *mask; |
| 343 | /*! \brief Prediction from the up predictor. |
| 344 | * |
| 345 | * Used to build the obmc predictor. |
| 346 | */ |
| 347 | uint8_t *above_pred; |
| 348 | /*! \brief Prediction from the up predictor. |
| 349 | * |
| 350 | * \copydetails above_pred |
| 351 | */ |
| 352 | uint8_t *left_pred; |
| 353 | } OBMCBuffer; |
| 354 | |
| 355 | /*! \brief Contains color maps used in palette mode. |
| 356 | */ |
| 357 | typedef struct { |
| 358 | //! The best color map found. |
| 359 | uint8_t best_palette_color_map[MAX_PALETTE_SQUARE(64 * 64)]; |
| 360 | //! A temporary buffer used for k-means clustering. |
| 361 | int16_t kmeans_data_buf[2 * MAX_PALETTE_SQUARE(64 * 64)]; |
| 362 | } PALETTE_BUFFER; |
| 363 | |
| 364 | /*! \brief Contains buffers used by av1_compound_type_rd() |
| 365 | * |
| 366 | * For sizes and alignment of these arrays, refer to |
| 367 | * alloc_compound_type_rd_buffers() function. |
| 368 | */ |
| 369 | typedef struct { |
| 370 | //! First prediction. |
| 371 | uint8_t *pred0; |
| 372 | //! Second prediction. |
| 373 | uint8_t *pred1; |
| 374 | //! Source - first prediction. |
| 375 | int16_t *residual1; |
| 376 | //! Second prediction - first prediction. |
| 377 | int16_t *diff10; |
| 378 | //! Backup of the best segmentation mask. |
| 379 | uint8_t *tmp_best_mask_buf; |
| 380 | } CompoundTypeRdBuffers; |
| 381 | |
| 382 | /*! \brief Holds some parameters related to partitioning schemes in AV1. |
| 383 | */ |
| 384 | // TODO(chiyotsai@google.com): Consolidate this with SIMPLE_MOTION_DATA_TREE |
| 385 | typedef struct { |
| 386 | #if !CONFIG_REALTIME_ONLY0 |
| 387 | // The following 4 parameters are used for cnn-based partitioning on intra |
| 388 | // frame. |
| 389 | /*! \brief Current index on the partition block quad tree. |
| 390 | * |
| 391 | * Used to index into the cnn buffer for partition decision. |
| 392 | */ |
| 393 | int quad_tree_idx; |
| 394 | //! Whether the CNN buffer contains valid output. |
| 395 | int cnn_output_valid; |
| 396 | //! A buffer used by our segmentation CNN for intra-frame partitioning. |
| 397 | float cnn_buffer[CNN_OUT_BUF_SIZE((((20)) + (((4) * 2 * 2)) + (((20) * 4 * 4)) + (((20) * 8 * 8 ))))]; |
| 398 | //! log of the quantization parameter of the ancestor BLOCK_64X64. |
| 399 | float log_q; |
| 400 | #endif |
| 401 | |
| 402 | /*! \brief Variance of the subblocks in the superblock. |
| 403 | * |
| 404 | * This is used by rt mode for variance based partitioning. |
| 405 | * The indices corresponds to the following block sizes: |
| 406 | * - 0 - 128x128 |
| 407 | * - 1-2 - 128x64 |
| 408 | * - 3-4 - 64x128 |
| 409 | * - 5-8 - 64x64 |
| 410 | * - 9-16 - 64x32 |
| 411 | * - 17-24 - 32x64 |
| 412 | * - 25-40 - 32x32 |
| 413 | * - 41-104 - 16x16 |
| 414 | */ |
| 415 | uint8_t variance_low[105]; |
| 416 | } PartitionSearchInfo; |
| 417 | |
| 418 | /*!\cond */ |
| 419 | enum { |
| 420 | /** |
| 421 | * Do not prune transform depths. |
| 422 | */ |
| 423 | TX_PRUNE_NONE = 0, |
| 424 | /** |
| 425 | * Prune largest transform (depth 0) based on NN model. |
| 426 | */ |
| 427 | TX_PRUNE_LARGEST = 1, |
| 428 | /** |
| 429 | * Prune split transforms (depth>=1) based on NN model. |
| 430 | */ |
| 431 | TX_PRUNE_SPLIT = 2, |
| 432 | } UENUM1BYTE(TX_PRUNE_TYPE); typedef uint8_t TX_PRUNE_TYPE; |
| 433 | /*!\endcond */ |
| 434 | |
| 435 | /*! \brief Defines the parameters used to perform txfm search. |
| 436 | * |
| 437 | * For the most part, this determines how various speed features are used. |
| 438 | */ |
| 439 | typedef struct { |
| 440 | /*! \brief Whether to limit the intra txfm search type to the default txfm. |
| 441 | * |
| 442 | * This could either be a result of either sequence parameter or speed |
| 443 | * features. |
| 444 | */ |
| 445 | int use_default_intra_tx_type; |
| 446 | |
| 447 | /*! Whether to limit the intra transform search type to the ones in the table |
| 448 | * av1_derived_intra_tx_used_flag[INTRA_MODES]. |
| 449 | */ |
| 450 | int use_derived_intra_tx_type_set; |
| 451 | |
| 452 | /*! Probability threshold used for conditionally forcing tx type*/ |
| 453 | int default_inter_tx_type_prob_thresh; |
| 454 | |
| 455 | //! Whether to prune 2d transforms based on 1d transform results. |
| 456 | int prune_2d_txfm_mode; |
| 457 | |
| 458 | /*! \brief Variable from \ref WinnerModeParams based on current eval mode. |
| 459 | * |
| 460 | * See the documentation for \ref WinnerModeParams for more detail. |
| 461 | */ |
| 462 | unsigned int coeff_opt_thresholds[2]; |
| 463 | /*! \copydoc coeff_opt_thresholds */ |
| 464 | unsigned int tx_domain_dist_threshold; |
| 465 | /*! \copydoc coeff_opt_thresholds */ |
| 466 | TX_SIZE_SEARCH_METHOD tx_size_search_method; |
| 467 | /*! \copydoc coeff_opt_thresholds */ |
| 468 | unsigned int use_transform_domain_distortion; |
| 469 | /*! \copydoc coeff_opt_thresholds */ |
| 470 | unsigned int skip_txfm_level; |
| 471 | |
| 472 | /*! \brief How to search for the optimal tx_size |
| 473 | * |
| 474 | * If ONLY_4X4, use TX_4X4; if TX_MODE_LARGEST, use the largest tx_size for |
| 475 | * the current partition block; if TX_MODE_SELECT, search through the whole |
| 476 | * tree. |
| 477 | * |
| 478 | * \attention |
| 479 | * Although this looks suspicious similar to a bitstream element, this |
| 480 | * tx_mode_search_type is only used internally by the encoder, and is *not* |
| 481 | * written to the bitstream. It determines what kind of tx_mode would be |
| 482 | * searched. For example, we might set it to TX_MODE_LARGEST to find a good |
| 483 | * candidate, then code it as TX_MODE_SELECT. |
| 484 | */ |
| 485 | TX_MODE tx_mode_search_type; |
| 486 | |
| 487 | /*! |
| 488 | * Determines whether a block can be predicted as transform skip or DC only |
| 489 | * based on residual mean and variance. |
| 490 | * Type 0 : No skip block or DC only block prediction |
| 491 | * Type 1 : Prediction of skip block based on residual mean and variance |
| 492 | * Type 2 : Prediction of skip block or DC only block based on residual mean |
| 493 | * and variance |
| 494 | */ |
| 495 | unsigned int predict_dc_level; |
| 496 | |
| 497 | /*! |
| 498 | * Whether or not we should use the quantization matrix as weights for PSNR |
| 499 | * during RD search. |
| 500 | */ |
| 501 | int use_qm_dist_metric; |
| 502 | |
| 503 | /*! |
| 504 | * Keep track of previous mode evaluation stage type. This will be used to |
| 505 | * reset mb rd hash record when mode evaluation type changes. |
| 506 | */ |
| 507 | int mode_eval_type; |
| 508 | |
| 509 | #if !CONFIG_REALTIME_ONLY0 |
| 510 | //! Indicates the transform depths for which RD evaluation is skipped. |
| 511 | TX_PRUNE_TYPE nn_prune_depths_for_intra_tx; |
| 512 | |
| 513 | /*! \brief Indicates if NN model should be invoked to prune transform depths. |
| 514 | * |
| 515 | * Used to signal whether NN model should be evaluated to prune the R-D |
| 516 | * evaluation of specific transform depths. |
| 517 | */ |
| 518 | bool_Bool enable_nn_prune_intra_tx_depths; |
| 519 | #endif |
| 520 | } TxfmSearchParams; |
| 521 | |
| 522 | /*!\cond */ |
| 523 | #define MAX_NUM_8X8_TXBS ((MAX_MIB_SIZE(1 << (7 - 2)) >> 1) * (MAX_MIB_SIZE(1 << (7 - 2)) >> 1)) |
| 524 | #define MAX_NUM_16X16_TXBS ((MAX_MIB_SIZE(1 << (7 - 2)) >> 2) * (MAX_MIB_SIZE(1 << (7 - 2)) >> 2)) |
| 525 | #define MAX_NUM_32X32_TXBS ((MAX_MIB_SIZE(1 << (7 - 2)) >> 3) * (MAX_MIB_SIZE(1 << (7 - 2)) >> 3)) |
| 526 | #define MAX_NUM_64X64_TXBS ((MAX_MIB_SIZE(1 << (7 - 2)) >> 4) * (MAX_MIB_SIZE(1 << (7 - 2)) >> 4)) |
| 527 | /*!\endcond */ |
| 528 | |
| 529 | /*! \brief Stores various encoding/search decisions related to txfm search. |
| 530 | * |
| 531 | * This struct contains a cache of previous txfm results, and some buffers for |
| 532 | * the current txfm decision. |
| 533 | */ |
| 534 | typedef struct { |
| 535 | //! Whether to skip transform and quantization on a partition block level. |
| 536 | uint8_t skip_txfm; |
| 537 | |
| 538 | /*! \brief Whether to skip transform and quantization on a txfm block level. |
| 539 | * |
| 540 | * Skips transform and quantization on a transform block level inside the |
| 541 | * current partition block. Each element of this array is used as a bit-field. |
| 542 | * So for example, the we are skipping on the luma plane, then the last bit |
| 543 | * would be set to 1. |
| 544 | */ |
| 545 | uint8_t blk_skip[MAX_MIB_SIZE(1 << (7 - 2)) * MAX_MIB_SIZE(1 << (7 - 2))]; |
| 546 | |
| 547 | /*! \brief Transform types inside the partition block |
| 548 | * |
| 549 | * Keeps a record of what kind of transform to use for each of the transform |
| 550 | * block inside the partition block. |
| 551 | * \attention The buffer here is *never* directly used. Instead, this just |
| 552 | * allocates the memory for MACROBLOCKD::tx_type_map during rdopt on the |
| 553 | * partition block. So if we need to save memory, we could move the allocation |
| 554 | * to pick_sb_mode instead. |
| 555 | */ |
| 556 | uint8_t tx_type_map_[MAX_MIB_SIZE(1 << (7 - 2)) * MAX_MIB_SIZE(1 << (7 - 2))]; |
| 557 | |
| 558 | //! Txfm hash records of inter-modes. |
| 559 | MB_RD_RECORD *mb_rd_record; |
| 560 | |
| 561 | /*! \brief Number of txb splits. |
| 562 | * |
| 563 | * Keep track of how many times we've used split tx partition for transform |
| 564 | * blocks. Somewhat misleadingly, this parameter doesn't actually keep track |
| 565 | * of the count of the current block. Instead, it's a cumulative count across |
| 566 | * of the whole frame. The main usage is that if txb_split_count is zero, then |
| 567 | * we can signal TX_MODE_LARGEST at frame level. |
| 568 | */ |
| 569 | // TODO(chiyotsai@google.com): Move this to a more appropriate location such |
| 570 | // as ThreadData. |
| 571 | unsigned int txb_split_count; |
| 572 | #if CONFIG_SPEED_STATS0 |
| 573 | //! For debugging. Used to check how many txfm searches we are doing. |
| 574 | unsigned int tx_search_count; |
| 575 | #endif // CONFIG_SPEED_STATS |
| 576 | } TxfmSearchInfo; |
| 577 | #undef MAX_NUM_8X8_TXBS |
| 578 | #undef MAX_NUM_16X16_TXBS |
| 579 | #undef MAX_NUM_32X32_TXBS |
| 580 | #undef MAX_NUM_64X64_TXBS |
| 581 | |
| 582 | /*! \brief Holds the entropy costs for various modes sent to the bitstream. |
| 583 | * |
| 584 | * \attention This does not include the costs for mv and transformed |
| 585 | * coefficients. |
| 586 | */ |
| 587 | typedef struct { |
| 588 | /***************************************************************************** |
| 589 | * \name Partition Costs |
| 590 | ****************************************************************************/ |
| 591 | /**@{*/ |
| 592 | //! Cost for coding the partition. |
| 593 | int partition_cost[PARTITION_CONTEXTS(5 * 4)][EXT_PARTITION_TYPES]; |
| 594 | /**@}*/ |
| 595 | |
| 596 | /***************************************************************************** |
| 597 | * \name Intra Costs: General |
| 598 | ****************************************************************************/ |
| 599 | /**@{*/ |
| 600 | //! Luma mode cost for inter frame. |
| 601 | int mbmode_cost[BLOCK_SIZE_GROUPS4][INTRA_MODES]; |
| 602 | //! Luma mode cost for intra frame. |
| 603 | int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; |
| 604 | //! Chroma mode cost |
| 605 | int intra_uv_mode_cost[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES]; |
| 606 | //! filter_intra_cost |
| 607 | int filter_intra_cost[BLOCK_SIZES_ALL][2]; |
| 608 | //! filter_intra_mode_cost |
| 609 | int filter_intra_mode_cost[FILTER_INTRA_MODES]; |
| 610 | //! angle_delta_cost |
| 611 | int angle_delta_cost[DIRECTIONAL_MODES8][2 * MAX_ANGLE_DELTA3 + 1]; |
| 612 | |
| 613 | //! Rate rate associated with each alpha codeword |
| 614 | int cfl_cost[CFL_JOINT_SIGNS(CFL_SIGNS * CFL_SIGNS - 1)][CFL_PRED_PLANES][CFL_ALPHABET_SIZE(1 << 4)]; |
| 615 | /**@}*/ |
| 616 | |
| 617 | /***************************************************************************** |
| 618 | * \name Intra Costs: Screen Contents |
| 619 | ****************************************************************************/ |
| 620 | /**@{*/ |
| 621 | //! intrabc_cost |
| 622 | int intrabc_cost[2]; |
| 623 | |
| 624 | //! palette_y_size_cost |
| 625 | int palette_y_size_cost[PALATTE_BSIZE_CTXS7][PALETTE_SIZES]; |
| 626 | //! palette_uv_size_cost |
| 627 | int palette_uv_size_cost[PALATTE_BSIZE_CTXS7][PALETTE_SIZES]; |
| 628 | //! palette_y_color_cost |
| 629 | int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS5] |
| 630 | [PALETTE_COLORS]; |
| 631 | //! palette_uv_color_cost |
| 632 | int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS5] |
| 633 | [PALETTE_COLORS]; |
| 634 | //! palette_y_mode_cost |
| 635 | int palette_y_mode_cost[PALATTE_BSIZE_CTXS7][PALETTE_Y_MODE_CONTEXTS3][2]; |
| 636 | //! palette_uv_mode_cost |
| 637 | int palette_uv_mode_cost[PALETTE_UV_MODE_CONTEXTS2][2]; |
| 638 | /**@}*/ |
| 639 | |
| 640 | /***************************************************************************** |
| 641 | * \name Inter Costs: MV Modes |
| 642 | ****************************************************************************/ |
| 643 | /**@{*/ |
| 644 | //! skip_mode_cost |
| 645 | int skip_mode_cost[SKIP_MODE_CONTEXTS3][2]; |
| 646 | //! newmv_mode_cost |
| 647 | int newmv_mode_cost[NEWMV_MODE_CONTEXTS6][2]; |
| 648 | //! zeromv_mode_cost |
| 649 | int zeromv_mode_cost[GLOBALMV_MODE_CONTEXTS2][2]; |
| 650 | //! refmv_mode_cost |
| 651 | int refmv_mode_cost[REFMV_MODE_CONTEXTS6][2]; |
| 652 | //! drl_mode_cost0 |
| 653 | int drl_mode_cost0[DRL_MODE_CONTEXTS3][2]; |
| 654 | /**@}*/ |
| 655 | |
| 656 | /***************************************************************************** |
| 657 | * \name Inter Costs: Ref Frame Types |
| 658 | ****************************************************************************/ |
| 659 | /**@{*/ |
| 660 | //! single_ref_cost |
| 661 | int single_ref_cost[REF_CONTEXTS3][SINGLE_REFS - 1][2]; |
| 662 | //! comp_inter_cost |
| 663 | int comp_inter_cost[COMP_INTER_CONTEXTS5][2]; |
| 664 | //! comp_ref_type_cost |
| 665 | int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS5] |
| 666 | [CDF_SIZE(COMP_REFERENCE_TYPES)((COMP_REFERENCE_TYPES) + 1)]; |
| 667 | //! uni_comp_ref_cost |
| 668 | int uni_comp_ref_cost[UNI_COMP_REF_CONTEXTS3][UNIDIR_COMP_REFS - 1] |
| 669 | [CDF_SIZE(2)((2) + 1)]; |
| 670 | /*! \brief Cost for signaling ref_frame[0] in bidir-comp mode |
| 671 | * |
| 672 | * Includes LAST_FRAME, LAST2_FRAME, LAST3_FRAME, and GOLDEN_FRAME. |
| 673 | */ |
| 674 | int comp_ref_cost[REF_CONTEXTS3][FWD_REFS - 1][2]; |
| 675 | /*! \brief Cost for signaling ref_frame[1] in bidir-comp mode |
| 676 | * |
| 677 | * Includes ALTREF_FRAME, ALTREF2_FRAME, and BWDREF_FRAME. |
| 678 | */ |
| 679 | int comp_bwdref_cost[REF_CONTEXTS3][BWD_REFS - 1][2]; |
| 680 | /**@}*/ |
| 681 | |
| 682 | /***************************************************************************** |
| 683 | * \name Inter Costs: Compound Types |
| 684 | ****************************************************************************/ |
| 685 | /**@{*/ |
| 686 | //! intra_inter_cost |
| 687 | int intra_inter_cost[INTRA_INTER_CONTEXTS4][2]; |
| 688 | //! inter_compound_mode_cost |
| 689 | int inter_compound_mode_cost[INTER_MODE_CONTEXTS8][INTER_COMPOUND_MODES(1 + NEW_NEWMV - NEAREST_NEARESTMV)]; |
| 690 | //! compound_type_cost |
| 691 | int compound_type_cost[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES]; |
| 692 | //! wedge_idx_cost |
| 693 | int wedge_idx_cost[BLOCK_SIZES_ALL][16]; |
| 694 | //! interintra_cost |
| 695 | int interintra_cost[BLOCK_SIZE_GROUPS4][2]; |
| 696 | //! wedge_interintra_cost |
| 697 | int wedge_interintra_cost[BLOCK_SIZES_ALL][2]; |
| 698 | //! interintra_mode_cost |
| 699 | int interintra_mode_cost[BLOCK_SIZE_GROUPS4][INTERINTRA_MODES]; |
| 700 | /**@}*/ |
| 701 | |
| 702 | /***************************************************************************** |
| 703 | * \name Inter Costs: Compound Masks |
| 704 | ****************************************************************************/ |
| 705 | /**@{*/ |
| 706 | //! comp_idx_cost |
| 707 | int comp_idx_cost[COMP_INDEX_CONTEXTS6][2]; |
| 708 | //! comp_group_idx_cost |
| 709 | int comp_group_idx_cost[COMP_GROUP_IDX_CONTEXTS6][2]; |
| 710 | /**@}*/ |
| 711 | |
| 712 | /***************************************************************************** |
| 713 | * \name Inter Costs: Motion Modes/Filters |
| 714 | ****************************************************************************/ |
| 715 | /**@{*/ |
| 716 | //! motion_mode_cost |
| 717 | int motion_mode_cost[BLOCK_SIZES_ALL][MOTION_MODES]; |
| 718 | //! motion_mode_cost1 |
| 719 | int motion_mode_cost1[BLOCK_SIZES_ALL][2]; |
| 720 | //! switchable_interp_costs |
| 721 | int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS((SWITCHABLE_FILTERS + 1) * 4)][SWITCHABLE_FILTERS]; |
| 722 | /**@}*/ |
| 723 | |
| 724 | /***************************************************************************** |
| 725 | * \name Txfm Mode Costs |
| 726 | ****************************************************************************/ |
| 727 | /**@{*/ |
| 728 | //! skip_txfm_cost |
| 729 | int skip_txfm_cost[SKIP_CONTEXTS3][2]; |
| 730 | //! tx_size_cost |
| 731 | int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS3][TX_SIZES]; |
| 732 | //! txfm_partition_cost |
| 733 | int txfm_partition_cost[TXFM_PARTITION_CONTEXTS((TX_SIZES - TX_8X8) * 6 - 3)][2]; |
| 734 | //! inter_tx_type_costs |
| 735 | int inter_tx_type_costs[EXT_TX_SETS_INTER4][EXT_TX_SIZES4][TX_TYPES]; |
| 736 | //! intra_tx_type_costs |
| 737 | int intra_tx_type_costs[EXT_TX_SETS_INTRA3][EXT_TX_SIZES4][INTRA_MODES] |
| 738 | [TX_TYPES]; |
| 739 | /**@}*/ |
| 740 | |
| 741 | /***************************************************************************** |
| 742 | * \name Restoration Mode Costs |
| 743 | ****************************************************************************/ |
| 744 | /**@{*/ |
| 745 | //! switchable_restore_cost |
| 746 | int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES]; |
| 747 | //! wiener_restore_cost |
| 748 | int wiener_restore_cost[2]; |
| 749 | //! sgrproj_restore_cost |
| 750 | int sgrproj_restore_cost[2]; |
| 751 | /**@}*/ |
| 752 | |
| 753 | /***************************************************************************** |
| 754 | * \name Segmentation Mode Costs |
| 755 | ****************************************************************************/ |
| 756 | /**@{*/ |
| 757 | //! tmp_pred_cost |
| 758 | int tmp_pred_cost[SEG_TEMPORAL_PRED_CTXS3][2]; |
| 759 | //! spatial_pred_cost |
| 760 | int spatial_pred_cost[SPATIAL_PREDICTION_PROBS3][MAX_SEGMENTS8]; |
| 761 | /**@}*/ |
| 762 | } ModeCosts; |
| 763 | |
| 764 | /*! \brief Holds mv costs for encoding and motion search. |
| 765 | */ |
| 766 | typedef struct { |
| 767 | /***************************************************************************** |
| 768 | * \name Encoding Costs |
| 769 | * Here are the entropy costs needed to encode a given mv. |
| 770 | * \ref nmv_cost_alloc and \ref nmv_cost_hp_alloc are two arrays that holds |
| 771 | * the memory for holding the mv cost. But since the motion vectors can be |
| 772 | * negative, we shift them to the middle and store the resulting pointer in |
| 773 | * \ref nmv_cost and \ref nmv_cost_hp for easier referencing. Finally, \ref |
| 774 | * mv_cost_stack points to the \ref nmv_cost with the mv precision we are |
| 775 | * currently working with. In essence, only \ref mv_cost_stack is needed for |
| 776 | * motion search, the other can be considered private. |
| 777 | ****************************************************************************/ |
| 778 | /**@{*/ |
| 779 | //! Costs for coding the zero components. |
| 780 | int nmv_joint_cost[MV_JOINTS4]; |
| 781 | |
| 782 | //! Allocates memory for 1/4-pel motion vector costs. |
| 783 | int nmv_cost_alloc[2][MV_VALS((((1 << (11 + 1 + 2)) - 1) << 1) + 1)]; |
| 784 | //! Allocates memory for 1/8-pel motion vector costs. |
| 785 | int nmv_cost_hp_alloc[2][MV_VALS((((1 << (11 + 1 + 2)) - 1) << 1) + 1)]; |
| 786 | //! Points to the middle of \ref nmv_cost_alloc |
| 787 | int *nmv_cost[2]; |
| 788 | //! Points to the middle of \ref nmv_cost_hp_alloc |
| 789 | int *nmv_cost_hp[2]; |
| 790 | //! Points to the nmv_cost_hp in use. |
| 791 | int **mv_cost_stack; |
| 792 | /**@}*/ |
| 793 | } MvCosts; |
| 794 | |
| 795 | /*! \brief Holds mv costs for intrabc. |
| 796 | */ |
| 797 | typedef struct { |
| 798 | /*! Costs for coding the joint mv. */ |
| 799 | int joint_mv[MV_JOINTS4]; |
| 800 | |
| 801 | /*! \brief Cost of transmitting the actual motion vector. |
| 802 | * dv_costs_alloc[0][i] is the cost of motion vector with horizontal |
| 803 | * component (mv_row) equal to i - MV_MAX. dv_costs_alloc[1][i] is the cost of |
| 804 | * motion vector with vertical component (mv_col) equal to i - MV_MAX. |
| 805 | */ |
| 806 | int dv_costs_alloc[2][MV_VALS((((1 << (11 + 1 + 2)) - 1) << 1) + 1)]; |
| 807 | |
| 808 | /*! Points to the middle of \ref dv_costs_alloc. */ |
| 809 | int *dv_costs[2]; |
| 810 | } IntraBCMVCosts; |
| 811 | |
| 812 | /*! \brief Holds the costs needed to encode the coefficients |
| 813 | */ |
| 814 | typedef struct { |
| 815 | //! Costs for coding the coefficients. |
| 816 | LV_MAP_COEFF_COST coeff_costs[TX_SIZES][PLANE_TYPES]; |
| 817 | //! Costs for coding the eobs. |
| 818 | LV_MAP_EOB_COST eob_costs[7][2]; |
| 819 | } CoeffCosts; |
| 820 | |
| 821 | /*!\cond */ |
| 822 | // 4: NEAREST, NEW, NEAR, GLOBAL |
| 823 | #define SINGLE_REF_MODES ((REF_FRAMES - 1) * 4) |
| 824 | /*!\endcond */ |
| 825 | struct inter_modes_info; |
| 826 | |
| 827 | /*! \brief Holds the motion samples for warp motion model estimation |
| 828 | */ |
| 829 | typedef struct { |
| 830 | //! Number of samples. |
| 831 | int num; |
| 832 | //! Sample locations in current frame. |
| 833 | int pts[16]; |
| 834 | //! Sample location in the reference frame. |
| 835 | int pts_inref[16]; |
| 836 | } WARP_SAMPLE_INFO; |
| 837 | |
| 838 | /*!\cond */ |
| 839 | typedef enum { |
| 840 | kZeroSad = 0, |
| 841 | kVeryLowSad = 1, |
| 842 | kLowSad = 2, |
| 843 | kMedSad = 3, |
| 844 | kHighSad = 4 |
| 845 | } SOURCE_SAD; |
| 846 | |
| 847 | typedef struct { |
| 848 | //! SAD levels in non-rd path |
| 849 | SOURCE_SAD source_sad_nonrd; |
| 850 | //! SAD levels in rd-path for var-based part qindex thresholds |
| 851 | SOURCE_SAD source_sad_rd; |
| 852 | int lighting_change; |
| 853 | int low_sumdiff; |
| 854 | } CONTENT_STATE_SB; |
| 855 | |
| 856 | // Structure to hold pixel level gradient info. |
| 857 | typedef struct { |
| 858 | uint16_t abs_dx_abs_dy_sum; |
| 859 | int8_t hist_bin_idx; |
| 860 | bool_Bool is_dx_zero; |
| 861 | } PixelLevelGradientInfo; |
| 862 | |
| 863 | // Structure to hold the variance and log(1 + variance) for 4x4 sub-blocks. |
| 864 | typedef struct { |
| 865 | double log_var; |
| 866 | int var; |
| 867 | } Block4x4VarInfo; |
| 868 | |
| 869 | #ifndef NDEBUG |
| 870 | typedef struct SetOffsetsLoc { |
| 871 | int mi_row; |
| 872 | int mi_col; |
| 873 | BLOCK_SIZE bsize; |
| 874 | } SetOffsetsLoc; |
| 875 | #endif // NDEBUG |
| 876 | |
| 877 | /*!\endcond */ |
| 878 | |
| 879 | //! Maximum number of estimated RD Cost records for compound average. |
| 880 | #define TOP_COMP_AVG_EST_RD_COUNT5 5 |
| 881 | |
| 882 | /*! \brief Encoder's parameters related to the current coding block. |
| 883 | * |
| 884 | * This struct contains most of the information the encoder needs to encode the |
| 885 | * current coding block. This includes the src and pred buffer, a copy of the |
| 886 | * decoder's view of the current block, the txfm coefficients. This struct also |
| 887 | * contains various buffers and data used to speed up the encoding process. |
| 888 | */ |
| 889 | typedef struct macroblock { |
Excessive padding in 'struct macroblock' (47 padding bytes, where 15 is optimal). Optimal fields order: e_mbd, mbmi_ext_frame, row_ctx, tile_pb_ctx, cb_coef_buff, palette_buffer, tmp_conv_dst, upsample_pred, rb, mv_costs, dv_costs, winner_mode_stats, inter_modes_info, mb_mode_cache, pixel_gradient_info, min_dist_inter_uv, dqcoeff_buf, src_var_info_of_4x4_sub_blocks, sb_stats_cache, sb_fp_stats, tmp_pred_bufs, obmc_buffer, comp_rd_buffer, top_comp_avg_est_rd, top_inter_tx_no_split_rd, plane, txfm_search_info, sb_enc, intrabc_hash_info, comp_rd_stats, qindex, delta_qindex, rdmult_delta_qindex, rdmult_cur_qindex, rdmult, intra_sb_rdmult_modifier, mb_energy, sb_energy_level, errorperbit, sadperbit, seg_skip_block, actual_num_seg1_blocks, actual_num_seg2_blocks, cnt_zeromv, force_zeromv_skip_for_sb, force_zeromv_skip_for_blk, prev_segment_id, nonrd_prune_ref_frame_search, must_find_valid_partition, skip_mode, winner_mode_count, comp_rd_stats_idx, recalc_luma_mc_data, use_mb_mode_cache, color_palette_thresh, force_color_check_block_level, source_variance, block_is_zero_sad, sb_me_partition, sb_me_block, sb_col_scroll, sb_row_scroll, sb_me_mv, sb_force_fixed_part, try_merge_partition, palette_pixels, pix_to_bottom_edge, pix_to_right_edge, best_pred_mv_sad, last_set_offsets_loc, content_state_sb, mv_limits, pred_mv_sad, pred_mv0_sad, pred_mv1_sad, max_mv_context, pred_sse, txfm_search_params, warp_sample_info, mbmi_ext, picked_ref_frames_mask, part_search_info, thresh_freq_fact, search_site_cfg_buf, mode_costs, coeff_costs, cb_offset, rd_model, compound_idx, reuse_inter_pred, is_sb_gradient_cached, color_sensitivity_sb, color_sensitivity_sb_g, color_sensitivity_sb_alt, color_sensitivity, tpl_keep_ref_frame, consider reordering the fields or adding explicit padding members | |
| 890 | /***************************************************************************** |
| 891 | * \name Source, Buffers and Decoder |
| 892 | ****************************************************************************/ |
| 893 | /**@{*/ |
| 894 | /*! \brief Each of the encoding plane. |
| 895 | * |
| 896 | * An array holding the src buffer for each of plane of the current block. It |
| 897 | * also contains the txfm and quantized txfm coefficients. |
| 898 | */ |
| 899 | struct macroblock_plane plane[MAX_MB_PLANE3]; |
| 900 | |
| 901 | /*! \brief Decoder's view of current coding block. |
| 902 | * |
| 903 | * Contains the encoder's copy of what the decoder sees in the current block. |
| 904 | * Most importantly, this struct contains pointers to mbmi that is used in |
| 905 | * final bitstream packing. |
| 906 | */ |
| 907 | MACROBLOCKD e_mbd; |
| 908 | |
| 909 | /*! \brief Derived coding information. |
| 910 | * |
| 911 | * Contains extra information not transmitted in the bitstream but are |
| 912 | * derived. For example, this contains the stack of ref_mvs. |
| 913 | */ |
| 914 | MB_MODE_INFO_EXT mbmi_ext; |
| 915 | |
| 916 | /*! \brief Finalized mbmi_ext for the whole frame. |
| 917 | * |
| 918 | * Contains the finalized info in mbmi_ext that gets used at the frame level |
| 919 | * for bitstream packing. |
| 920 | */ |
| 921 | MB_MODE_INFO_EXT_FRAME *mbmi_ext_frame; |
| 922 | |
| 923 | //! Entropy context for the current row. |
| 924 | FRAME_CONTEXT *row_ctx; |
| 925 | /*! \brief Entropy context for the current tile. |
| 926 | * |
| 927 | * This context will be used to update color_map_cdf pointer which would be |
| 928 | * used during pack bitstream. For single thread and tile-multithreading case |
| 929 | * this pointer will be same as xd->tile_ctx, but for the case of row-mt: |
| 930 | * xd->tile_ctx will point to a temporary context while tile_pb_ctx will point |
| 931 | * to the accurate tile context. |
| 932 | */ |
| 933 | FRAME_CONTEXT *tile_pb_ctx; |
| 934 | |
| 935 | /*! \brief Buffer of transformed coefficients |
| 936 | * |
| 937 | * Points to cb_coef_buff in the AV1_COMP struct, which contains the finalized |
| 938 | * coefficients. This is here to conveniently copy the best coefficients to |
| 939 | * frame level for bitstream packing. Since CB_COEFF_BUFFER is allocated on a |
| 940 | * superblock level, we need to combine it with cb_offset to get the proper |
| 941 | * position for the current coding block. |
| 942 | */ |
| 943 | CB_COEFF_BUFFER *cb_coef_buff; |
| 944 | //! Offset of current coding block's coeff buffer relative to the sb. |
| 945 | uint16_t cb_offset[PLANE_TYPES]; |
| 946 | |
| 947 | //! Modified source and masks used for fast OBMC search. |
| 948 | OBMCBuffer obmc_buffer; |
| 949 | //! Buffer to store the best palette map. |
| 950 | PALETTE_BUFFER *palette_buffer; |
| 951 | //! Buffer used for compound_type_rd(). |
| 952 | CompoundTypeRdBuffers comp_rd_buffer; |
| 953 | //! Buffer to store convolution during averaging process in compound mode. |
| 954 | CONV_BUF_TYPE *tmp_conv_dst; |
| 955 | |
| 956 | /*! \brief Temporary buffer to hold prediction. |
| 957 | * |
| 958 | * Points to a buffer that is used to hold temporary prediction results. This |
| 959 | * is used in two ways: |
| 960 | * - This is a temporary buffer used to ping-pong the prediction in |
| 961 | * handle_inter_mode. |
| 962 | * - xd->tmp_obmc_bufs also points to this buffer, and is used in ombc |
| 963 | * prediction. |
| 964 | */ |
| 965 | uint8_t *tmp_pred_bufs[2]; |
| 966 | |
| 967 | /*! |
| 968 | * Buffer used for upsampled prediction. |
| 969 | */ |
| 970 | uint8_t *upsample_pred; |
| 971 | /**@}*/ |
| 972 | |
| 973 | /***************************************************************************** |
| 974 | * \name Rdopt Costs |
| 975 | ****************************************************************************/ |
| 976 | /**@{*/ |
| 977 | /*! \brief Quantization index for the current partition block. |
| 978 | * |
| 979 | * This is used to as the index to find quantization parameter for luma and |
| 980 | * chroma transformed coefficients. |
| 981 | */ |
| 982 | int qindex; |
| 983 | |
| 984 | /*! \brief Difference between frame-level qindex and current qindex. |
| 985 | * |
| 986 | * This is used to track whether a non-zero delta for qindex is used at least |
| 987 | * once in the current frame. |
| 988 | */ |
| 989 | int delta_qindex; |
| 990 | |
| 991 | /*! \brief Difference between frame-level qindex and qindex used to |
| 992 | * compute rdmult (lambda). |
| 993 | * |
| 994 | * rdmult_delta_qindex is assigned the same as delta_qindex before qp sweep. |
| 995 | * During qp sweep, delta_qindex is changed and used to calculate the actual |
| 996 | * quant params, while rdmult_delta_qindex remains the same, and is used to |
| 997 | * calculate the rdmult in "set_deltaq_rdmult". |
| 998 | */ |
| 999 | int rdmult_delta_qindex; |
| 1000 | |
| 1001 | /*! \brief Current qindex (before being adjusted by delta_q_res) used to |
| 1002 | * derive rdmult_delta_qindex. |
| 1003 | */ |
| 1004 | int rdmult_cur_qindex; |
| 1005 | |
| 1006 | /*! \brief Rate-distortion multiplier. |
| 1007 | * |
| 1008 | * The rd multiplier used to determine the rate-distortion trade-off. This is |
| 1009 | * roughly proportional to the inverse of q-index for a given frame, but this |
| 1010 | * can be manipulated for better rate-control. For example, in tune_ssim |
| 1011 | * mode, this is scaled by a factor related to the variance of the current |
| 1012 | * block. |
| 1013 | */ |
| 1014 | int rdmult; |
| 1015 | |
| 1016 | //! Intra only, per sb rd adjustment. |
| 1017 | int intra_sb_rdmult_modifier; |
| 1018 | |
| 1019 | //! Superblock level distortion propagation factor. |
| 1020 | double rb; |
| 1021 | |
| 1022 | //! Energy in the current source coding block. Used to calculate \ref rdmult |
| 1023 | int mb_energy; |
| 1024 | //! Energy in the current source superblock. Used to calculate \ref rdmult |
| 1025 | int sb_energy_level; |
| 1026 | |
| 1027 | //! The rate needed to signal a mode to the bitstream. |
| 1028 | ModeCosts mode_costs; |
| 1029 | |
| 1030 | //! The rate needed to encode a new motion vector to the bitstream and some |
| 1031 | //! multipliers for motion search. |
| 1032 | MvCosts *mv_costs; |
| 1033 | |
| 1034 | /*! The rate needed to encode a new motion vector to the bitstream in intrabc |
| 1035 | * mode. |
| 1036 | */ |
| 1037 | IntraBCMVCosts *dv_costs; |
| 1038 | |
| 1039 | //! The rate needed to signal the txfm coefficients to the bitstream. |
| 1040 | CoeffCosts coeff_costs; |
| 1041 | /**@}*/ |
| 1042 | |
| 1043 | /***************************************************************************** |
| 1044 | * \name Rate to Distortion Multipliers |
| 1045 | ****************************************************************************/ |
| 1046 | /**@{*/ |
| 1047 | //! A multiplier that converts mv cost to l2 error. |
| 1048 | int errorperbit; |
| 1049 | //! A multiplier that converts mv cost to l1 error. |
| 1050 | int sadperbit; |
| 1051 | /**@}*/ |
| 1052 | |
| 1053 | /****************************************************************************** |
| 1054 | * \name Segmentation |
| 1055 | *****************************************************************************/ |
| 1056 | /**@{*/ |
| 1057 | /*! \brief Skip mode for the segment |
| 1058 | * |
| 1059 | * A syntax element of the segmentation mode. In skip_block mode, all mvs are |
| 1060 | * set 0 and all txfms are skipped. |
| 1061 | */ |
| 1062 | int seg_skip_block; |
| 1063 | |
| 1064 | /*! \brief Number of segment 1 blocks |
| 1065 | * Actual number of (4x4) blocks that were applied delta-q, |
| 1066 | * for segment 1. |
| 1067 | */ |
| 1068 | int actual_num_seg1_blocks; |
| 1069 | |
| 1070 | /*!\brief Number of segment 2 blocks |
| 1071 | * Actual number of (4x4) blocks that were applied delta-q, |
| 1072 | * for segment 2. |
| 1073 | */ |
| 1074 | int actual_num_seg2_blocks; |
| 1075 | |
| 1076 | /*!\brief Number of zero motion vectors |
| 1077 | */ |
| 1078 | int cnt_zeromv; |
| 1079 | |
| 1080 | /*!\brief Flag to force zeromv-skip at superblock level, for nonrd path. |
| 1081 | * |
| 1082 | * 0/1 imply zeromv-skip is disabled/enabled. 2 implies that the blocks |
| 1083 | * in the superblock may be marked as zeromv-skip at block level. |
| 1084 | */ |
| 1085 | int force_zeromv_skip_for_sb; |
| 1086 | |
| 1087 | /*!\brief Flag to force zeromv-skip at block level, for nonrd path. |
| 1088 | */ |
| 1089 | int force_zeromv_skip_for_blk; |
| 1090 | |
| 1091 | /*! \brief Previous segment id for which qmatrices were updated. |
| 1092 | * This is used to bypass setting of qmatrices if no change in qindex. |
| 1093 | */ |
| 1094 | int prev_segment_id; |
| 1095 | /**@}*/ |
| 1096 | |
| 1097 | /***************************************************************************** |
| 1098 | * \name Superblock |
| 1099 | ****************************************************************************/ |
| 1100 | /**@{*/ |
| 1101 | //! Information on a whole superblock level. |
| 1102 | // TODO(chiyotsai@google.com): Refactor this out of macroblock |
| 1103 | SuperBlockEnc sb_enc; |
| 1104 | |
| 1105 | /*! \brief Characteristics of the current superblock. |
| 1106 | * |
| 1107 | * Characteristics like whether the block has high sad, low sad, etc. This is |
| 1108 | * only used by av1 realtime mode. |
| 1109 | */ |
| 1110 | CONTENT_STATE_SB content_state_sb; |
| 1111 | /**@}*/ |
| 1112 | |
| 1113 | /***************************************************************************** |
| 1114 | * \name Reference Frame Search |
| 1115 | ****************************************************************************/ |
| 1116 | /**@{*/ |
| 1117 | /*! \brief Sum absolute distortion of the predicted mv for each ref frame. |
| 1118 | * |
| 1119 | * This is used to measure how viable a reference frame is. |
| 1120 | */ |
| 1121 | int pred_mv_sad[REF_FRAMES]; |
| 1122 | /*! \brief The minimum of \ref pred_mv_sad. |
| 1123 | * |
| 1124 | * Index 0 stores the minimum \ref pred_mv_sad across past reference frames. |
| 1125 | * Index 1 stores the minimum \ref pred_mv_sad across future reference frames. |
| 1126 | */ |
| 1127 | int best_pred_mv_sad[2]; |
| 1128 | //! The sad of the 1st mv ref (nearest). |
| 1129 | int pred_mv0_sad[REF_FRAMES]; |
| 1130 | //! The sad of the 2nd mv ref (near). |
| 1131 | int pred_mv1_sad[REF_FRAMES]; |
| 1132 | |
| 1133 | /*! \brief Disables certain ref frame pruning based on tpl. |
| 1134 | * |
| 1135 | * Determines whether a given ref frame is "good" based on data from the TPL |
| 1136 | * model. If so, this stops selective_ref frame from pruning the given ref |
| 1137 | * frame at block level. |
| 1138 | */ |
| 1139 | uint8_t tpl_keep_ref_frame[REF_FRAMES]; |
| 1140 | |
| 1141 | /*! \brief Warp motion samples buffer. |
| 1142 | * |
| 1143 | * Store the motion samples used for warp motion. |
| 1144 | */ |
| 1145 | WARP_SAMPLE_INFO warp_sample_info[REF_FRAMES]; |
| 1146 | |
| 1147 | /*! \brief Reference frames picked by the square subblocks in a superblock. |
| 1148 | * |
| 1149 | * Keeps track of ref frames that are selected by square partition blocks |
| 1150 | * within a superblock, in MI resolution. They can be used to prune ref frames |
| 1151 | * for rectangular blocks. |
| 1152 | */ |
| 1153 | int picked_ref_frames_mask[MAX_MIB_SIZE(1 << (7 - 2)) * MAX_MIB_SIZE(1 << (7 - 2))]; |
| 1154 | |
| 1155 | /*! \brief Prune ref frames in real-time mode. |
| 1156 | * |
| 1157 | * Determines whether to prune reference frames in real-time mode. For the |
| 1158 | * most part, this is the same as nonrd_prune_ref_frame_search in |
| 1159 | * cpi->sf.rt_sf.nonrd_prune_ref_frame_search, but this can be selectively |
| 1160 | * turned off if the only frame available is GOLDEN_FRAME. |
| 1161 | */ |
| 1162 | int nonrd_prune_ref_frame_search; |
| 1163 | /**@}*/ |
| 1164 | |
| 1165 | /***************************************************************************** |
| 1166 | * \name Partition Search |
| 1167 | ****************************************************************************/ |
| 1168 | /**@{*/ |
| 1169 | //! Stores some partition-search related buffers. |
| 1170 | PartitionSearchInfo part_search_info; |
| 1171 | |
| 1172 | /*! \brief Whether to disable some features to force a mode in current block. |
| 1173 | * |
| 1174 | * In some cases, our speed features can be overly aggressive and remove all |
| 1175 | * modes search in the superblock. When this happens, we set |
| 1176 | * must_find_valid_partition to 1 to reduce the number of speed features, and |
| 1177 | * recode the superblock again. |
| 1178 | */ |
| 1179 | int must_find_valid_partition; |
| 1180 | /**@}*/ |
| 1181 | |
| 1182 | /***************************************************************************** |
| 1183 | * \name Prediction Mode Search |
| 1184 | ****************************************************************************/ |
| 1185 | /**@{*/ |
| 1186 | /*! \brief Inter skip mode. |
| 1187 | * |
| 1188 | * Skip mode tries to use the closest forward and backward references for |
| 1189 | * inter prediction. Skip here means to skip transmitting the reference |
| 1190 | * frames, not to be confused with skip_txfm. |
| 1191 | */ |
| 1192 | int skip_mode; |
| 1193 | |
| 1194 | /*! \brief Factors used for rd-thresholding. |
| 1195 | * |
| 1196 | * Determines a rd threshold to determine whether to continue searching the |
| 1197 | * current mode. If the current best rd is already <= threshold, then we skip |
| 1198 | * the current mode. |
| 1199 | */ |
| 1200 | int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES]; |
| 1201 | |
| 1202 | /*! \brief Tracks the winner modes in the current coding block. |
| 1203 | * |
| 1204 | * Winner mode is a two-pass strategy to find the best prediction mode. In the |
| 1205 | * first pass, we search the prediction modes with a limited set of txfm |
| 1206 | * options, and keep the top modes. These modes are called the winner modes. |
| 1207 | * In the second pass, we retry the winner modes with more thorough txfm |
| 1208 | * options. |
| 1209 | */ |
| 1210 | WinnerModeStats *winner_mode_stats; |
| 1211 | //! Tracks how many winner modes there are. |
| 1212 | int winner_mode_count; |
| 1213 | |
| 1214 | /*! \brief The model used for rd-estimation to avoid txfm |
| 1215 | * |
| 1216 | * These are for inter_mode_rd_model_estimation, which is another two pass |
| 1217 | * approach. In this speed feature, we collect data in the first couple frames |
| 1218 | * to build an rd model to estimate the rdcost of a prediction model based on |
| 1219 | * the residue error. Once enough data is collected, this speed feature uses |
| 1220 | * the estimated rdcost to find the most performant prediction mode. Then we |
| 1221 | * follow up with a second pass find the best transform for the mode. |
| 1222 | * Determines if one would go with reduced complexity transform block |
| 1223 | * search model to select prediction modes, or full complexity model |
| 1224 | * to select transform kernel. |
| 1225 | */ |
| 1226 | TXFM_RD_MODEL rd_model; |
| 1227 | |
| 1228 | /*! \brief Stores the inter mode information needed to build an rd model. |
| 1229 | * |
| 1230 | * These are for inter_mode_rd_model_estimation, which is another two pass |
| 1231 | * approach. In this speed feature, we collect data in the first couple frames |
| 1232 | * to build an rd model to estimate the rdcost of a prediction model based on |
| 1233 | * the residue error. Once enough data is collected, this speed feature uses |
| 1234 | * the estimated rdcost to find the most performant prediction mode. Then we |
| 1235 | * follow up with a second pass find the best transform for the mode. |
| 1236 | */ |
| 1237 | // TODO(any): try to consolidate this speed feature with winner mode |
| 1238 | // processing. |
| 1239 | struct inter_modes_info *inter_modes_info; |
| 1240 | |
| 1241 | //! How to blend the compound predictions. |
| 1242 | uint8_t compound_idx; |
| 1243 | |
| 1244 | //! A caches of results of compound type search so they can be reused later. |
| 1245 | COMP_RD_STATS comp_rd_stats[MAX_COMP_RD_STATS64]; |
| 1246 | //! The idx for the latest compound mode in the cache \ref comp_rd_stats. |
| 1247 | int comp_rd_stats_idx; |
| 1248 | |
| 1249 | /*! \brief Whether to recompute the luma prediction. |
| 1250 | * |
| 1251 | * In interpolation search, we can usually skip recalculating the luma |
| 1252 | * prediction because it is already calculated by a previous predictor. This |
| 1253 | * flag signifies that some modes might have been skipped, so we need to |
| 1254 | * rebuild the prediction. |
| 1255 | */ |
| 1256 | int recalc_luma_mc_data; |
| 1257 | |
| 1258 | /*! \brief Data structure to speed up intrabc search. |
| 1259 | * |
| 1260 | * Contains the hash table, hash function, and buffer used for intrabc. |
| 1261 | */ |
| 1262 | IntraBCHashInfo intrabc_hash_info; |
| 1263 | |
| 1264 | /*! \brief Whether to reuse the mode stored in mb_mode_cache. */ |
| 1265 | int use_mb_mode_cache; |
| 1266 | /*! \brief The mode to reuse during \ref av1_rd_pick_intra_mode_sb and |
| 1267 | * \ref av1_rd_pick_inter_mode. */ |
| 1268 | const MB_MODE_INFO *mb_mode_cache; |
| 1269 | /*! \brief Pointer to the buffer which caches gradient information. |
| 1270 | * |
| 1271 | * Pointer to the array of structures to store gradient information of each |
| 1272 | * pixel in a superblock. The buffer constitutes of MAX_SB_SQUARE pixel level |
| 1273 | * structures for each of the plane types (PLANE_TYPE_Y and PLANE_TYPE_UV). |
| 1274 | */ |
| 1275 | PixelLevelGradientInfo *pixel_gradient_info; |
| 1276 | /*! \brief Flags indicating the availability of cached gradient info. */ |
| 1277 | bool_Bool is_sb_gradient_cached[PLANE_TYPES]; |
| 1278 | |
| 1279 | /*! \brief Flag to reuse predicted samples of inter block. */ |
| 1280 | bool_Bool reuse_inter_pred; |
| 1281 | /**@}*/ |
| 1282 | |
| 1283 | /***************************************************************************** |
| 1284 | * \name MV Search |
| 1285 | ****************************************************************************/ |
| 1286 | /**@{*/ |
| 1287 | /*! \brief Context used to determine the initial step size in motion search. |
| 1288 | * |
| 1289 | * This context is defined as the \f$l_\inf\f$ norm of the best ref_mvs for |
| 1290 | * each frame. |
| 1291 | */ |
| 1292 | unsigned int max_mv_context[REF_FRAMES]; |
| 1293 | |
| 1294 | /*! \brief Limit for the range of motion vectors. |
| 1295 | * |
| 1296 | * These define limits to motion vector components to prevent them from |
| 1297 | * extending outside the UMV borders |
| 1298 | */ |
| 1299 | FullMvLimits mv_limits; |
| 1300 | |
| 1301 | /*! \brief Buffer for storing the search site config. |
| 1302 | * |
| 1303 | * When resize mode or super resolution mode is on, the stride of the |
| 1304 | * reference frame does not always match what's specified in \ref |
| 1305 | * MotionVectorSearchParams::search_site_cfg. When his happens, we update the |
| 1306 | * search_sine_config buffer here and use it for motion search. |
| 1307 | */ |
| 1308 | search_site_config search_site_cfg_buf[NUM_DISTINCT_SEARCH_METHODS]; |
| 1309 | /**@}*/ |
| 1310 | |
| 1311 | /***************************************************************************** |
| 1312 | * \name Txfm Search |
| 1313 | ****************************************************************************/ |
| 1314 | /**@{*/ |
| 1315 | /*! \brief Parameters that control how motion search is done. |
| 1316 | * |
| 1317 | * Stores various txfm search related parameters such as txfm_type, txfm_size, |
| 1318 | * trellis eob search, etc. |
| 1319 | */ |
| 1320 | TxfmSearchParams txfm_search_params; |
| 1321 | |
| 1322 | /*! \brief Results of the txfm searches that have been done. |
| 1323 | * |
| 1324 | * Caches old txfm search results and keeps the current txfm decisions to |
| 1325 | * facilitate rdopt. |
| 1326 | */ |
| 1327 | TxfmSearchInfo txfm_search_info; |
| 1328 | |
| 1329 | /*! \brief Whether there is a strong color activity. |
| 1330 | * |
| 1331 | * Used in REALTIME coding mode to enhance the visual quality at the boundary |
| 1332 | * of moving color objects. |
| 1333 | */ |
| 1334 | uint8_t color_sensitivity_sb[MAX_MB_PLANE3 - 1]; |
| 1335 | //! Color sensitivity flag for the superblock for golden reference. |
| 1336 | uint8_t color_sensitivity_sb_g[MAX_MB_PLANE3 - 1]; |
| 1337 | //! Color sensitivity flag for the superblock for altref reference. |
| 1338 | uint8_t color_sensitivity_sb_alt[MAX_MB_PLANE3 - 1]; |
| 1339 | //! Color sensitivity flag for the coding block. |
| 1340 | uint8_t color_sensitivity[MAX_MB_PLANE3 - 1]; |
| 1341 | //! Coding block distortion value for uv/color, minimum over the inter modes. |
| 1342 | int64_t min_dist_inter_uv; |
| 1343 | |
| 1344 | //! Threshold on the number of colors for testing palette mode. |
| 1345 | int color_palette_thresh; |
| 1346 | |
| 1347 | //! Used in REALTIME coding mode: flag to indicate if the color_sensitivity |
| 1348 | // should be checked at the coding block level. |
| 1349 | int force_color_check_block_level; |
| 1350 | |
| 1351 | //! The buffer used by search_tx_type() to swap dqcoeff in macroblockd_plane |
| 1352 | // so we can keep dqcoeff of the best tx_type. |
| 1353 | tran_low_t *dqcoeff_buf; |
| 1354 | /**@}*/ |
| 1355 | |
| 1356 | /***************************************************************************** |
| 1357 | * \name Misc |
| 1358 | ****************************************************************************/ |
| 1359 | /**@{*/ |
| 1360 | //! Variance of the source frame. |
| 1361 | unsigned int source_variance; |
| 1362 | //! Flag to indicate coding block is zero sad. |
| 1363 | int block_is_zero_sad; |
| 1364 | //! Flag to indicate superblock ME in variance partition is determined to be |
| 1365 | // good/reliable, and so the superblock MV will be tested in the |
| 1366 | // nonrd_pickmode. This is only used for LAST_FRAME. |
| 1367 | int sb_me_partition; |
| 1368 | //! Flag to indicate to test the superblock MV for the coding block in the |
| 1369 | // nonrd_pickmode. |
| 1370 | int sb_me_block; |
| 1371 | //! Counter for superblock selected column scroll. |
| 1372 | int sb_col_scroll; |
| 1373 | //! Counter for superblock selected row scroll. |
| 1374 | int sb_row_scroll; |
| 1375 | //! Motion vector from superblock MV derived from int_pro_motion() in |
| 1376 | // the variance_partitioning. |
| 1377 | int_mv sb_me_mv; |
| 1378 | //! Flag to indicate if a fixed partition should be used, only if the |
| 1379 | // speed feature rt_sf->use_fast_fixed_part is enabled. |
| 1380 | int sb_force_fixed_part; |
| 1381 | //! SSE of the current predictor. |
| 1382 | unsigned int pred_sse[REF_FRAMES]; |
| 1383 | //! Prediction for ML based partition. |
| 1384 | #if CONFIG_RT_ML_PARTITIONING0 |
| 1385 | DECLARE_ALIGNED(16, uint8_t, est_pred[128 * 128])uint8_t est_pred[128 * 128] __attribute__((aligned(16))); |
| 1386 | #endif |
| 1387 | /**@}*/ |
| 1388 | |
| 1389 | /*! \brief NONE partition evaluated for merge. |
| 1390 | * |
| 1391 | * In variance based partitioning scheme, NONE & SPLIT partitions are |
| 1392 | * evaluated to check the SPLIT can be merged as NONE. This flag signifies the |
| 1393 | * partition is evaluated in the scheme. |
| 1394 | */ |
| 1395 | int try_merge_partition; |
| 1396 | |
| 1397 | /*! \brief Pointer to buffer which caches sub-block variances in a superblock. |
| 1398 | * |
| 1399 | * Pointer to the array of structures to store source variance information of |
| 1400 | * each 4x4 sub-block in a superblock. Block4x4VarInfo structure is used to |
| 1401 | * store source variance and log of source variance of each 4x4 sub-block. |
| 1402 | */ |
| 1403 | Block4x4VarInfo *src_var_info_of_4x4_sub_blocks; |
| 1404 | #ifndef NDEBUG |
| 1405 | /*! \brief A hash to make sure av1_set_offsets is called */ |
| 1406 | SetOffsetsLoc last_set_offsets_loc; |
| 1407 | #endif // NDEBUG |
| 1408 | |
| 1409 | #if COLLECT_NONRD_PICK_MODE_STAT0 |
| 1410 | mode_search_stat_nonrd ms_stat_nonrd; |
| 1411 | #endif // COLLECT_NONRD_PICK_MODE_STAT |
| 1412 | |
| 1413 | /*!\brief Number of pixels in current thread that choose palette mode in the |
| 1414 | * fast encoding stage for screen content tool detemination. |
| 1415 | */ |
| 1416 | int palette_pixels; |
| 1417 | |
| 1418 | /*! \brief Keep records of top no-split RD Costs of transform size search. */ |
| 1419 | int64_t top_inter_tx_no_split_rd[MAX_TX_BLOCKS_IN_MAX_SB(1 << ((7 - (6)) * 2))] |
| 1420 | [TOP_INTER_TX_NO_SPLIT_COUNT4]; |
| 1421 | |
| 1422 | /*!\brief Pointer to the structure which stores the statistics used by |
| 1423 | * sb-level multi-pass encoding. |
| 1424 | */ |
| 1425 | struct SB_FIRST_PASS_STATS *sb_stats_cache; |
| 1426 | |
| 1427 | /*!\brief Pointer to the structure which stores the statistics used by |
| 1428 | * first-pass when superblock is searched twice consecutively. |
| 1429 | */ |
| 1430 | struct SB_FIRST_PASS_STATS *sb_fp_stats; |
| 1431 | |
| 1432 | /*!\brief Array of best estimated RD Costs of compound average. */ |
| 1433 | int64_t top_comp_avg_est_rd[TOP_COMP_AVG_EST_RD_COUNT5]; |
| 1434 | |
| 1435 | #if CONFIG_PARTITION_SEARCH_ORDER0 |
| 1436 | /*!\brief Pointer to RD_STATS structure to be used in |
| 1437 | * av1_rd_partition_search(). |
| 1438 | */ |
| 1439 | RD_STATS *rdcost; |
| 1440 | #endif // CONFIG_PARTITION_SEARCH_ORDER |
| 1441 | |
| 1442 | /*! \brief Distance from bottom edge of the frame in pixels. */ |
| 1443 | int pix_to_bottom_edge; |
| 1444 | |
| 1445 | /*! \brief Distance from right edge of the frame in pixels. */ |
| 1446 | int pix_to_right_edge; |
| 1447 | } MACROBLOCK; |
| 1448 | #undef SINGLE_REF_MODES |
| 1449 | |
| 1450 | /*!\cond */ |
| 1451 | // Zeroes out 'n_stats' elements in the array x->winner_mode_stats. |
| 1452 | // It only zeroes out what is necessary in 'color_index_map' (just the block |
| 1453 | // size, not the whole array). |
| 1454 | static inline void zero_winner_mode_stats(BLOCK_SIZE bsize, int n_stats, |
| 1455 | WinnerModeStats *stats) { |
| 1456 | // When winner mode stats are not required, the memory allocation is avoided |
| 1457 | // for x->winner_mode_stats. The stats pointer will be NULL in such cases. |
| 1458 | if (stats == NULL((void*)0)) return; |
| 1459 | |
| 1460 | const int block_height = block_size_high[bsize]; |
| 1461 | const int block_width = block_size_wide[bsize]; |
| 1462 | for (int i = 0; i < n_stats; ++i) { |
| 1463 | WinnerModeStats *const stat = &stats[i]; |
| 1464 | memset(&stat->mbmi, 0, sizeof(stat->mbmi)); |
| 1465 | memset(&stat->rd_cost, 0, sizeof(stat->rd_cost)); |
| 1466 | memset(&stat->rd, 0, sizeof(stat->rd)); |
| 1467 | memset(&stat->rate_y, 0, sizeof(stat->rate_y)); |
| 1468 | memset(&stat->rate_uv, 0, sizeof(stat->rate_uv)); |
| 1469 | // Do not reset the whole array as it is CPU intensive. |
| 1470 | memset(&stat->color_index_map, 0, |
| 1471 | block_width * block_height * sizeof(stat->color_index_map[0])); |
| 1472 | memset(&stat->mode_index, 0, sizeof(stat->mode_index)); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | static inline int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) { |
| 1477 | static const char LUT[BLOCK_SIZES_ALL] = { |
| 1478 | 0, // BLOCK_4X4 |
| 1479 | 1, // BLOCK_4X8 |
| 1480 | 1, // BLOCK_8X4 |
| 1481 | 0, // BLOCK_8X8 |
| 1482 | 1, // BLOCK_8X16 |
| 1483 | 1, // BLOCK_16X8 |
| 1484 | 0, // BLOCK_16X16 |
| 1485 | 1, // BLOCK_16X32 |
| 1486 | 1, // BLOCK_32X16 |
| 1487 | 0, // BLOCK_32X32 |
| 1488 | 1, // BLOCK_32X64 |
| 1489 | 1, // BLOCK_64X32 |
| 1490 | 0, // BLOCK_64X64 |
| 1491 | 0, // BLOCK_64X128 |
| 1492 | 0, // BLOCK_128X64 |
| 1493 | 0, // BLOCK_128X128 |
| 1494 | 1, // BLOCK_4X16 |
| 1495 | 1, // BLOCK_16X4 |
| 1496 | 1, // BLOCK_8X32 |
| 1497 | 1, // BLOCK_32X8 |
| 1498 | 1, // BLOCK_16X64 |
| 1499 | 1, // BLOCK_64X16 |
| 1500 | }; |
| 1501 | |
| 1502 | return LUT[bsize]; |
| 1503 | } |
| 1504 | |
| 1505 | static inline int is_rect_tx_allowed(const MACROBLOCKD *xd, |
| 1506 | const MB_MODE_INFO *mbmi) { |
| 1507 | return is_rect_tx_allowed_bsize(mbmi->bsize) && |
| 1508 | !xd->lossless[mbmi->segment_id]; |
| 1509 | } |
| 1510 | |
| 1511 | static inline int tx_size_to_depth(TX_SIZE tx_size, BLOCK_SIZE bsize) { |
| 1512 | TX_SIZE ctx_size = max_txsize_rect_lookup[bsize]; |
| 1513 | int depth = 0; |
| 1514 | while (tx_size != ctx_size) { |
| 1515 | depth++; |
| 1516 | ctx_size = sub_tx_size_map[ctx_size]; |
| 1517 | assert(depth <= MAX_TX_DEPTH)((void) sizeof ((depth <= 2) ? 1 : 0), __extension__ ({ if (depth <= 2) ; else __assert_fail ("depth <= MAX_TX_DEPTH" , "/root/firefox-clang/third_party/aom/av1/encoder/block.h", 1517 , __extension__ __PRETTY_FUNCTION__); })); |
| 1518 | } |
| 1519 | return depth; |
| 1520 | } |
| 1521 | |
| 1522 | static inline void set_blk_skip(uint8_t txb_skip[], int plane, int blk_idx, |
| 1523 | int skip) { |
| 1524 | if (skip) |
| 1525 | txb_skip[blk_idx] |= 1UL << plane; |
| 1526 | else |
| 1527 | txb_skip[blk_idx] &= ~(1UL << plane); |
| 1528 | #ifndef NDEBUG |
| 1529 | // Set chroma planes to uninitialized states when luma is set to check if |
| 1530 | // it will be set later |
| 1531 | if (plane == 0) { |
| 1532 | txb_skip[blk_idx] |= 1UL << (1 + 4); |
| 1533 | txb_skip[blk_idx] |= 1UL << (2 + 4); |
| 1534 | } |
| 1535 | |
| 1536 | // Clear the initialization checking bit |
| 1537 | txb_skip[blk_idx] &= ~(1UL << (plane + 4)); |
| 1538 | #endif |
| 1539 | } |
| 1540 | |
| 1541 | static inline int is_blk_skip(uint8_t *txb_skip, int plane, int blk_idx) { |
| 1542 | #ifndef NDEBUG |
| 1543 | // Check if this is initialized |
| 1544 | assert(!(txb_skip[blk_idx] & (1UL << (plane + 4))))((void) sizeof ((!(txb_skip[blk_idx] & (1UL << (plane + 4)))) ? 1 : 0), __extension__ ({ if (!(txb_skip[blk_idx] & (1UL << (plane + 4)))) ; else __assert_fail ("!(txb_skip[blk_idx] & (1UL << (plane + 4)))" , "/root/firefox-clang/third_party/aom/av1/encoder/block.h", 1544 , __extension__ __PRETTY_FUNCTION__); })); |
| 1545 | |
| 1546 | // The magic number is 0x77, this is to test if there is garbage data |
| 1547 | assert((txb_skip[blk_idx] & 0x88) == 0)((void) sizeof (((txb_skip[blk_idx] & 0x88) == 0) ? 1 : 0 ), __extension__ ({ if ((txb_skip[blk_idx] & 0x88) == 0) ; else __assert_fail ("(txb_skip[blk_idx] & 0x88) == 0", "/root/firefox-clang/third_party/aom/av1/encoder/block.h" , 1547, __extension__ __PRETTY_FUNCTION__); })); |
| 1548 | #endif |
| 1549 | return (txb_skip[blk_idx] >> plane) & 1; |
| 1550 | } |
| 1551 | |
| 1552 | /*!\endcond */ |
| 1553 | |
| 1554 | #ifdef __cplusplus |
| 1555 | } // extern "C" |
| 1556 | #endif |
| 1557 | |
| 1558 | #endif // AOM_AV1_ENCODER_BLOCK_H_ |