AOMedia AV1 Codec
block.h
Go to the documentation of this file.
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 
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_ONLY
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 
37 #define MIN_TPL_BSIZE_1D 16
38 #define MAX_TPL_BLK_IN_SB (MAX_SB_SIZE / MIN_TPL_BSIZE_1D)
40 #define RD_RECORD_BUFFER_LEN 8
42 
44 #define MAX_TX_TYPE_PROB 1024
45 
51 typedef struct {
53  BLOCK_SIZE min_partition_size;
55  BLOCK_SIZE max_partition_size;
56 
57  /*****************************************************************************
58  * \name TPL Info
59  *
60  * Information gathered from tpl_model at tpl block precision for the
61  * superblock to speed up the encoding process..
62  ****************************************************************************/
64  int tpl_data_count;
67  int64_t tpl_inter_cost[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
69  int64_t tpl_intra_cost[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB];
71  int_mv tpl_mv[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB][INTER_REFS_PER_FRAME];
76 
79 typedef struct {
83  RD_STATS rd_cost;
85  int64_t rd;
87  int rate_y;
89  int rate_uv;
91  uint8_t color_index_map[MAX_SB_SQUARE];
93  THR_MODES mode_index;
95 
100 typedef struct macroblock_plane {
102  int16_t *src_diff;
104  tran_low_t *dqcoeff;
106  tran_low_t *qcoeff;
108  tran_low_t *coeff;
110  uint16_t *eobs;
112  uint8_t *txb_entropy_ctx;
114  struct buf_2d src;
115 
123  const int16_t *quant_fp_QTX;
126  const int16_t *round_fp_QTX;
128  const int16_t *quant_QTX;
130  const int16_t *round_QTX;
132  const int16_t *quant_shift_QTX;
134  const int16_t *zbin_QTX;
136  const int16_t *dequant_QTX;
139 
144 typedef struct {
146  int txb_skip_cost[TXB_SKIP_CONTEXTS][2];
151  int base_eob_cost[SIG_COEF_CONTEXTS_EOB][3];
156  int base_cost[SIG_COEF_CONTEXTS][8];
161  int eob_extra_cost[EOB_COEF_CONTEXTS][2];
163  int dc_sign_cost[DC_SIGN_CONTEXTS][2];
165  int lps_cost[LEVEL_CONTEXTS][COEFF_BASE_RANGE + 1 + COEFF_BASE_RANGE + 1];
167 
170 typedef struct {
172  int eob_cost[2][11];
174 
177 typedef struct {
179  tran_low_t *tcoeff[MAX_MB_PLANE];
181  uint16_t *eobs[MAX_MB_PLANE];
188  uint8_t *entropy_ctx[MAX_MB_PLANE];
190 
193 typedef struct {
194  // TODO(angiebird): Reduce the buffer size according to sb_type
196  CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE];
198  uint16_t weight[MODE_CTX_REF_FRAMES][USABLE_REF_MV_STACK_SIZE];
200  uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
202  int_mv global_mvs[REF_FRAMES];
204  int16_t mode_context[MODE_CTX_REF_FRAMES];
206 
213 typedef struct {
215  CANDIDATE_MV ref_mv_stack[USABLE_REF_MV_STACK_SIZE];
217  uint16_t weight[USABLE_REF_MV_STACK_SIZE];
219  uint8_t ref_mv_count;
220  // TODO(Ravi/Remya): Reduce the buffer size of global_mvs
222  int_mv global_mvs[REF_FRAMES];
224  int16_t mode_context;
226  uint16_t cb_offset[PLANE_TYPES];
228 
231 typedef struct {
233  TX_SIZE tx_size;
235  TX_SIZE inter_tx_size[INTER_TX_SIZE_BUF_LEN];
237  uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
239  uint8_t tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE];
241  RD_STATS rd_stats;
243  uint32_t hash_value;
244 } MB_RD_INFO;
245 
252 typedef struct {
260  int num;
263 } MB_RD_RECORD;
264 
266 #define MAX_COMP_RD_STATS 64
267 
269 typedef struct {
271  int32_t rate[COMPOUND_TYPES];
273  int64_t dist[COMPOUND_TYPES];
275  int32_t model_rate[COMPOUND_TYPES];
277  int64_t model_dist[COMPOUND_TYPES];
279  int comp_rs2[COMPOUND_TYPES];
281  int_mv mv[2];
283  MV_REFERENCE_FRAME ref_frames[2];
285  PREDICTION_MODE mode;
287  int_interpfilters filter;
291  int is_global[2];
293  INTERINTER_COMPOUND_DATA interinter_comp;
294 } COMP_RD_STATS;
295 
300 typedef struct {
305  int32_t *wsrc;
310  int32_t *mask;
315  uint8_t *above_pred;
320  uint8_t *left_pred;
321 } OBMCBuffer;
322 
325 typedef struct {
327  uint8_t best_palette_color_map[MAX_PALETTE_SQUARE];
329  int kmeans_data_buf[2 * MAX_PALETTE_SQUARE];
331 
337 typedef struct {
339  uint8_t *pred0;
341  uint8_t *pred1;
343  int16_t *residual1;
345  int16_t *diff10;
349 
352 // TODO(chiyotsai@google.com): Consolidate this with SIMPLE_MOTION_DATA_TREE
353 typedef struct {
354 #if !CONFIG_REALTIME_ONLY
355  // The following 4 parameters are used for cnn-based partitioning on intra
356  // frame.
365  float cnn_buffer[CNN_OUT_BUF_SIZE];
367  float log_q;
368 #endif
369 
383  uint8_t variance_low[105];
385 
387 enum {
391  TX_PRUNE_NONE = 0,
395  TX_PRUNE_LARGEST = 1,
399  TX_PRUNE_SPLIT = 2,
400 } UENUM1BYTE(TX_PRUNE_TYPE);
407 typedef struct {
414 
417 
420 
425  unsigned int coeff_opt_thresholds[2];
429  TX_SIZE_SEARCH_METHOD tx_size_search_method;
433  unsigned int skip_txfm_level;
434 
449 
458  unsigned int predict_dc_level;
459 
465 
471 
472 #if !CONFIG_REALTIME_ONLY
473  TX_PRUNE_TYPE nn_prune_depths_for_intra_tx;
475 
482 #endif
484 
486 #define MAX_NUM_8X8_TXBS ((MAX_MIB_SIZE >> 1) * (MAX_MIB_SIZE >> 1))
487 #define MAX_NUM_16X16_TXBS ((MAX_MIB_SIZE >> 2) * (MAX_MIB_SIZE >> 2))
488 #define MAX_NUM_32X32_TXBS ((MAX_MIB_SIZE >> 3) * (MAX_MIB_SIZE >> 3))
489 #define MAX_NUM_64X64_TXBS ((MAX_MIB_SIZE >> 4) * (MAX_MIB_SIZE >> 4))
490 
497 typedef struct {
500 
508  uint8_t blk_skip[MAX_MIB_SIZE * MAX_MIB_SIZE];
509 
519  uint8_t tx_type_map_[MAX_MIB_SIZE * MAX_MIB_SIZE];
520 
523 
532  // TODO(chiyotsai@google.com): Move this to a more appropriate location such
533  // as ThreadData.
534  unsigned int txb_split_count;
535 #if CONFIG_SPEED_STATS
536  unsigned int tx_search_count;
538 #endif // CONFIG_SPEED_STATS
540 #undef MAX_NUM_8X8_TXBS
541 #undef MAX_NUM_16X16_TXBS
542 #undef MAX_NUM_32X32_TXBS
543 #undef MAX_NUM_64X64_TXBS
544 
550 typedef struct {
551  /*****************************************************************************
552  * \name Partition Costs
553  ****************************************************************************/
555  int partition_cost[PARTITION_CONTEXTS][EXT_PARTITION_TYPES];
559  /*****************************************************************************
560  * \name Intra Costs: General
561  ****************************************************************************/
563  int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES];
566  int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
568  int intra_uv_mode_cost[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES];
570  int filter_intra_cost[BLOCK_SIZES_ALL][2];
572  int filter_intra_mode_cost[FILTER_INTRA_MODES];
574  int angle_delta_cost[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1];
575 
577  int cfl_cost[CFL_JOINT_SIGNS][CFL_PRED_PLANES][CFL_ALPHABET_SIZE];
580  /*****************************************************************************
581  * \name Intra Costs: Screen Contents
582  ****************************************************************************/
584  int intrabc_cost[2];
586 
588  int palette_y_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES];
590  int palette_uv_size_cost[PALATTE_BSIZE_CTXS][PALETTE_SIZES];
592  int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
593  [PALETTE_COLORS];
595  int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
596  [PALETTE_COLORS];
598  int palette_y_mode_cost[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS][2];
600  int palette_uv_mode_cost[PALETTE_UV_MODE_CONTEXTS][2];
603  /*****************************************************************************
604  * \name Inter Costs: MV Modes
605  ****************************************************************************/
607  int skip_mode_cost[SKIP_MODE_CONTEXTS][2];
610  int newmv_mode_cost[NEWMV_MODE_CONTEXTS][2];
612  int zeromv_mode_cost[GLOBALMV_MODE_CONTEXTS][2];
614  int refmv_mode_cost[REFMV_MODE_CONTEXTS][2];
616  int drl_mode_cost0[DRL_MODE_CONTEXTS][2];
619  /*****************************************************************************
620  * \name Inter Costs: Ref Frame Types
621  ****************************************************************************/
623  int single_ref_cost[REF_CONTEXTS][SINGLE_REFS - 1][2];
626  int comp_inter_cost[COMP_INTER_CONTEXTS][2];
628  int comp_ref_type_cost[COMP_REF_TYPE_CONTEXTS]
629  [CDF_SIZE(COMP_REFERENCE_TYPES)];
631  int uni_comp_ref_cost[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1]
632  [CDF_SIZE(2)];
637  int comp_ref_cost[REF_CONTEXTS][FWD_REFS - 1][2];
642  int comp_bwdref_cost[REF_CONTEXTS][BWD_REFS - 1][2];
645  /*****************************************************************************
646  * \name Inter Costs: Compound Types
647  ****************************************************************************/
649  int intra_inter_cost[INTRA_INTER_CONTEXTS][2];
652  int inter_compound_mode_cost[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES];
654  int compound_type_cost[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES];
656  int wedge_idx_cost[BLOCK_SIZES_ALL][16];
658  int interintra_cost[BLOCK_SIZE_GROUPS][2];
660  int wedge_interintra_cost[BLOCK_SIZES_ALL][2];
662  int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
665  /*****************************************************************************
666  * \name Inter Costs: Compound Masks
667  ****************************************************************************/
669  int comp_idx_cost[COMP_INDEX_CONTEXTS][2];
672  int comp_group_idx_cost[COMP_GROUP_IDX_CONTEXTS][2];
675  /*****************************************************************************
676  * \name Inter Costs: Motion Modes/Filters
677  ****************************************************************************/
679  int motion_mode_cost[BLOCK_SIZES_ALL][MOTION_MODES];
682  int motion_mode_cost1[BLOCK_SIZES_ALL][2];
684  int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
687  /*****************************************************************************
688  * \name Txfm Mode Costs
689  ****************************************************************************/
691  int skip_txfm_cost[SKIP_CONTEXTS][2];
694  int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES];
696  int txfm_partition_cost[TXFM_PARTITION_CONTEXTS][2];
698  int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES];
700  int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
701  [TX_TYPES];
704  /*****************************************************************************
705  * \name Restoration Mode Costs
706  ****************************************************************************/
708  int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES];
711  int wiener_restore_cost[2];
713  int sgrproj_restore_cost[2];
716  /*****************************************************************************
717  * \name Segmentation Mode Costs
718  ****************************************************************************/
720  int tmp_pred_cost[SEG_TEMPORAL_PRED_CTXS][2];
723  int spatial_pred_cost[SPATIAL_PREDICTION_PROBS][MAX_SEGMENTS];
725 } ModeCosts;
726 
729 typedef struct {
730  /*****************************************************************************
731  * \name Encoding Costs
732  * Here are the entropy costs needed to encode a given mv.
733  * \ref nmv_cost_alloc and \ref nmv_cost_hp_alloc are two arrays that holds
734  * the memory for holding the mv cost. But since the motion vectors can be
735  * negative, we shift them to the middle and store the resulting pointer in
736  * \ref nmv_cost and \ref nmv_cost_hp for easier referencing. Finally, \ref
737  * mv_cost_stack points to the \ref nmv_cost with the mv precision we are
738  * currently working with. In essence, only \ref mv_cost_stack is needed for
739  * motion search, the other can be considered private.
740  ****************************************************************************/
742  int nmv_joint_cost[MV_JOINTS];
744 
746  int nmv_cost_alloc[2][MV_VALS];
748  int nmv_cost_hp_alloc[2][MV_VALS];
750  int *nmv_cost[2];
752  int *nmv_cost_hp[2];
756 } MvCosts;
757 
760 typedef struct {
762  int joint_mv[MV_JOINTS];
763 
769  int dv_costs_alloc[2][MV_VALS];
770 
772  int *dv_costs[2];
774 
777 typedef struct {
779  LV_MAP_COEFF_COST coeff_costs[TX_SIZES][PLANE_TYPES];
781  LV_MAP_EOB_COST eob_costs[7][2];
782 } CoeffCosts;
783 
785 // 4: NEAREST, NEW, NEAR, GLOBAL
786 #define SINGLE_REF_MODES ((REF_FRAMES - 1) * 4)
787 
788 struct inter_modes_info;
789 
792 typedef struct {
794  int num;
796  int pts[16];
798  int pts_inref[16];
800 
802 typedef enum {
803  kZeroSad = 0,
804  kLowSad = 1,
805  kMedSad = 2,
806  kHighSad = 3
807 } SOURCE_SAD;
808 
809 typedef struct {
811  SOURCE_SAD source_sad_nonrd;
813  SOURCE_SAD source_sad_rd;
814  int lighting_change;
815  int low_sumdiff;
816 } CONTENT_STATE_SB;
817 
818 // Structure to hold pixel level gradient info.
819 typedef struct {
820  uint16_t abs_dx_abs_dy_sum;
821  int8_t hist_bin_idx;
822  bool is_dx_zero;
823 } PixelLevelGradientInfo;
824 
825 // Structure to hold the variance and log(1 + variance) for 4x4 sub-blocks.
826 typedef struct {
827  double log_var;
828  int var;
829 } Block4x4VarInfo;
830 
831 #ifndef NDEBUG
832 typedef struct SetOffsetsLoc {
833  int mi_row;
834  int mi_col;
835  BLOCK_SIZE bsize;
836 } SetOffsetsLoc;
837 #endif // NDEBUG
838 
848 typedef struct macroblock {
849  /*****************************************************************************
850  * \name Source, Buffers and Decoder
851  ****************************************************************************/
858  struct macroblock_plane plane[MAX_MB_PLANE];
859 
867 
874 
881 
883  FRAME_CONTEXT *row_ctx;
892  FRAME_CONTEXT *tile_pb_ctx;
893 
904  uint16_t cb_offset[PLANE_TYPES];
905 
913  CONV_BUF_TYPE *tmp_conv_dst;
914 
924  uint8_t *tmp_pred_bufs[2];
927  /*****************************************************************************
928  * \name Rdopt Costs
929  ****************************************************************************/
936  int qindex;
937 
944 
953  int rdmult;
954 
957 
959  double rb;
960 
965 
968 
972 
977 
982  /*****************************************************************************
983  * \name Rate to Distortion Multipliers
984  ****************************************************************************/
986  int errorperbit;
992  /******************************************************************************
993  * \name Segmentation
994  *****************************************************************************/
1002 
1008 
1014 
1018 
1022 
1029  /*****************************************************************************
1030  * \name Superblock
1031  ****************************************************************************/
1033  // TODO(chiyotsai@google.com): Refactor this out of macroblock
1036 
1042  CONTENT_STATE_SB content_state_sb;
1045  /*****************************************************************************
1046  * \name Reference Frame Search
1047  ****************************************************************************/
1053  int pred_mv_sad[REF_FRAMES];
1059  int best_pred_mv_sad[2];
1061  int pred_mv0_sad[REF_FRAMES];
1063  int pred_mv1_sad[REF_FRAMES];
1064 
1071  uint8_t tpl_keep_ref_frame[REF_FRAMES];
1072 
1077  WARP_SAMPLE_INFO warp_sample_info[REF_FRAMES];
1078 
1085  int picked_ref_frames_mask[MAX_MIB_SIZE * MAX_MIB_SIZE];
1086 
1097  /*****************************************************************************
1098  * \name Partition Search
1099  ****************************************************************************/
1101  PartitionSearchInfo part_search_info;
1103 
1114  /*****************************************************************************
1115  * \name Prediction Mode Search
1116  ****************************************************************************/
1125 
1132  int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
1133 
1145 
1158  TXFM_RD_MODEL rd_model;
1159 
1169  // TODO(any): try to consolidate this speed feature with winner mode
1170  // processing.
1172 
1174  uint8_t compound_idx;
1175 
1180 
1189 
1194  IntraBCHashInfo intrabc_hash_info;
1195 
1207  PixelLevelGradientInfo *pixel_gradient_info;
1209  bool is_sb_gradient_cached[PLANE_TYPES];
1212  /*****************************************************************************
1213  * \name MV Search
1214  ****************************************************************************/
1221  unsigned int max_mv_context[REF_FRAMES];
1222 
1228  FullMvLimits mv_limits;
1229 
1237  search_site_config search_site_cfg_buf[NUM_DISTINCT_SEARCH_METHODS];
1240  /*****************************************************************************
1241  * \name Txfm Search
1242  ****************************************************************************/
1250 
1257 
1263  uint8_t color_sensitivity_sb[2];
1265  uint8_t color_sensitivity_sb_g[2];
1267  uint8_t color_sensitivity[2];
1270  /*****************************************************************************
1271  * \name Misc
1272  ****************************************************************************/
1274  unsigned int source_variance;
1277  unsigned int pred_sse[REF_FRAMES];
1279 #if CONFIG_RT_ML_PARTITIONING
1280  DECLARE_ALIGNED(16, uint8_t, est_pred[128 * 128]);
1281 #endif
1282 
1291 
1299 #ifndef NDEBUG
1300 
1301  SetOffsetsLoc last_set_offsets_loc;
1302 #endif // NDEBUG
1303 } MACROBLOCK;
1304 #undef SINGLE_REF_MODES
1305 
1307 // Zeroes out 'n_stats' elements in the array x->winner_mode_stats.
1308 // It only zeroes out what is necessary in 'color_index_map' (just the block
1309 // size, not the whole array).
1310 static INLINE void zero_winner_mode_stats(BLOCK_SIZE bsize, int n_stats,
1311  WinnerModeStats *stats) {
1312  // When winner mode stats are not required, the memory allocation is avoided
1313  // for x->winner_mode_stats. The stats pointer will be NULL in such cases.
1314  if (stats == NULL) return;
1315 
1316  const int block_height = block_size_high[bsize];
1317  const int block_width = block_size_wide[bsize];
1318  for (int i = 0; i < n_stats; ++i) {
1319  WinnerModeStats *const stat = &stats[i];
1320  memset(&stat->mbmi, 0, sizeof(stat->mbmi));
1321  memset(&stat->rd_cost, 0, sizeof(stat->rd_cost));
1322  memset(&stat->rd, 0, sizeof(stat->rd));
1323  memset(&stat->rate_y, 0, sizeof(stat->rate_y));
1324  memset(&stat->rate_uv, 0, sizeof(stat->rate_uv));
1325  // Do not reset the whole array as it is CPU intensive.
1326  memset(&stat->color_index_map, 0,
1327  block_width * block_height * sizeof(stat->color_index_map[0]));
1328  memset(&stat->mode_index, 0, sizeof(stat->mode_index));
1329  }
1330 }
1331 
1332 static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) {
1333  static const char LUT[BLOCK_SIZES_ALL] = {
1334  0, // BLOCK_4X4
1335  1, // BLOCK_4X8
1336  1, // BLOCK_8X4
1337  0, // BLOCK_8X8
1338  1, // BLOCK_8X16
1339  1, // BLOCK_16X8
1340  0, // BLOCK_16X16
1341  1, // BLOCK_16X32
1342  1, // BLOCK_32X16
1343  0, // BLOCK_32X32
1344  1, // BLOCK_32X64
1345  1, // BLOCK_64X32
1346  0, // BLOCK_64X64
1347  0, // BLOCK_64X128
1348  0, // BLOCK_128X64
1349  0, // BLOCK_128X128
1350  1, // BLOCK_4X16
1351  1, // BLOCK_16X4
1352  1, // BLOCK_8X32
1353  1, // BLOCK_32X8
1354  1, // BLOCK_16X64
1355  1, // BLOCK_64X16
1356  };
1357 
1358  return LUT[bsize];
1359 }
1360 
1361 static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd,
1362  const MB_MODE_INFO *mbmi) {
1363  return is_rect_tx_allowed_bsize(mbmi->bsize) &&
1364  !xd->lossless[mbmi->segment_id];
1365 }
1366 
1367 static INLINE int tx_size_to_depth(TX_SIZE tx_size, BLOCK_SIZE bsize) {
1368  TX_SIZE ctx_size = max_txsize_rect_lookup[bsize];
1369  int depth = 0;
1370  while (tx_size != ctx_size) {
1371  depth++;
1372  ctx_size = sub_tx_size_map[ctx_size];
1373  assert(depth <= MAX_TX_DEPTH);
1374  }
1375  return depth;
1376 }
1377 
1378 static INLINE void set_blk_skip(uint8_t txb_skip[], int plane, int blk_idx,
1379  int skip) {
1380  if (skip)
1381  txb_skip[blk_idx] |= 1UL << plane;
1382  else
1383  txb_skip[blk_idx] &= ~(1UL << plane);
1384 #ifndef NDEBUG
1385  // Set chroma planes to uninitialized states when luma is set to check if
1386  // it will be set later
1387  if (plane == 0) {
1388  txb_skip[blk_idx] |= 1UL << (1 + 4);
1389  txb_skip[blk_idx] |= 1UL << (2 + 4);
1390  }
1391 
1392  // Clear the initialization checking bit
1393  txb_skip[blk_idx] &= ~(1UL << (plane + 4));
1394 #endif
1395 }
1396 
1397 static INLINE int is_blk_skip(uint8_t *txb_skip, int plane, int blk_idx) {
1398 #ifndef NDEBUG
1399  // Check if this is initialized
1400  assert(!(txb_skip[blk_idx] & (1UL << (plane + 4))));
1401 
1402  // The magic number is 0x77, this is to test if there is garbage data
1403  assert((txb_skip[blk_idx] & 0x88) == 0);
1404 #endif
1405  return (txb_skip[blk_idx] >> plane) & 1;
1406 }
1407 
1410 #ifdef __cplusplus
1411 } // extern "C"
1412 #endif
1413 
1414 #endif // AOM_AV1_ENCODER_BLOCK_H_
MB_MODE_INFO mbmi
The mbmi used to reconstruct the winner mode.
Definition: block.h:81
int winner_mode_count
Tracks how many winner modes there are.
Definition: block.h:1144
TXFM_RD_MODEL rd_model
The model used for rd-estimation to avoid txfm.
Definition: block.h:1158
CompoundTypeRdBuffers comp_rd_buffer
Buffer used for compound_type_rd().
Definition: block.h:911
int default_inter_tx_type_prob_thresh
Definition: block.h:416
uint8_t * pred1
Second prediction.
Definition: block.h:341
Extended mode info derived from mbmi.
Definition: block.h:193
struct buf_2d src
A buffer containing the source frame.
Definition: block.h:114
Costs for encoding the coefficients within a level.
Definition: block.h:144
Block4x4VarInfo * src_var_info_of_4x4_sub_blocks
Pointer to buffer which caches sub-block variances in a superblock.
Definition: block.h:1298
uint8_t * left_pred
Prediction from the up predictor.
Definition: block.h:320
int sb_energy_level
Energy in the current source superblock. Used to calculate rdmult.
Definition: block.h:964
const int16_t * quant_QTX
Quantization step size used by AV1_XFORM_QUANT_B.
Definition: block.h:128
TX_SIZE_SEARCH_METHOD tx_size_search_method
Variable from WinnerModeParams based on current eval mode.
Definition: block.h:429
SetOffsetsLoc last_set_offsets_loc
A hash to make sure av1_set_offsets is called.
Definition: block.h:1301
Costs for encoding the eob.
Definition: block.h:170
int quad_tree_idx
Current index on the partition block quad tree.
Definition: block.h:361
Holds some parameters related to partitioning schemes in AV1.
Definition: block.h:353
int32_t * mask
A new mask constructed from the original horz/vert mask.
Definition: block.h:310
int64_t rd
Rdcost of the winner mode.
Definition: block.h:85
WinnerModeStats * winner_mode_stats
Tracks the winner modes in the current coding block.
Definition: block.h:1142
int rate_uv
Chroma rate of the winner mode.
Definition: block.h:89
int ref_mv_idx
Refmv index in the drl.
Definition: block.h:289
struct inter_modes_info * inter_modes_info
Stores the inter mode information needed to build an rd model.
Definition: block.h:1171
Contains color maps used in palette mode.
Definition: block.h:325
int num
Number of info stored in this record.
Definition: block.h:260
TX_SIZE tx_size
Txfm size used if the current mode is intra mode.
Definition: block.h:233
int rdmult
Rate-distortion multiplier.
Definition: block.h:953
Stores the transforms coefficients for the whole superblock.
Definition: block.h:177
uint8_t * txb_entropy_ctx
Contexts used to code the transform coefficients.
Definition: block.h:112
uint8_t segment_id
The segment id.
Definition: blockd.h:310
CRC32C crc_calculator
Hash function.
Definition: block.h:262
int16_t * diff10
Second prediction - first prediction.
Definition: block.h:345
const int16_t * round_fp_QTX
Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_FP.
Definition: block.h:126
Holds the entropy costs for various modes sent to the bitstream.
Definition: block.h:550
MvCosts * mv_costs
Definition: block.h:971
THR_MODES mode_index
The current winner mode.
Definition: block.h:93
uint8_t * above_pred
Prediction from the up predictor.
Definition: block.h:315
int num
Number of samples.
Definition: block.h:794
SuperBlockEnc sb_enc
Information on a whole superblock level.
Definition: block.h:1035
Contains buffers used by av1_compound_type_rd()
Definition: block.h:337
int qindex
Quantization index for the current partition block.
Definition: block.h:936
int lossless[8]
Definition: blockd.h:824
MB_MODE_INFO_EXT_FRAME * mbmi_ext_frame
Finalized mbmi_ext for the whole frame.
Definition: block.h:880
int nonrd_prune_ref_frame_search
Prune ref frames in real-time mode.
Definition: block.h:1094
CONTENT_STATE_SB content_state_sb
Characteristics of the current superblock.
Definition: block.h:1042
unsigned int skip_txfm_level
Variable from WinnerModeParams based on current eval mode.
Definition: block.h:433
FRAME_CONTEXT * tile_pb_ctx
Entropy context for the current tile.
Definition: block.h:892
Rdcost stats in compound mode.
Definition: block.h:269
uint32_t hash_value
Hash value of the current record.
Definition: block.h:243
int_interpfilters filter
Current interpolation filter.
Definition: block.h:287
const int16_t * quant_shift_QTX
Scale factor to shift coefficients toward zero. Only used by QUANT_B.
Definition: block.h:132
struct macroblock MACROBLOCK
Encoder&#39;s parameters related to the current coding block.
Defines the parameters used to perform txfm search.
Definition: block.h:407
#define MAX_TPL_BLK_IN_SB
Maximum number of tpl block in a super block.
Definition: block.h:39
Definition: enums.h:602
int intra_sb_rdmult_modifier
Intra only, per sb rd adjustment.
Definition: block.h:956
Struct used to hold inter mode data for fast tx search.
Definition: encoder.h:1238
int delta_qindex
Difference between frame-level qindex and current qindex.
Definition: block.h:943
const int16_t * dequant_QTX
Dequantizer.
Definition: block.h:136
int use_mb_mode_cache
Whether to reuse the mode stored in mb_mode_cache.
Definition: block.h:1197
int32_t * wsrc
A new source weighted with the above and left predictors.
Definition: block.h:305
int16_t * src_diff
Stores source - pred so the txfm can be computed later.
Definition: block.h:102
tran_low_t * dqcoeff
Dequantized coefficients.
Definition: block.h:104
CONV_BUF_TYPE * tmp_conv_dst
Buffer to store convolution during averaging process in compound mode.
Definition: block.h:913
int actual_num_seg2_blocks
Number of segment 2 blocks Actual number of (4x4) blocks that were applied delta-q, for segment 2.
Definition: block.h:1013
FullMvLimits mv_limits
Limit for the range of motion vectors.
Definition: block.h:1228
int comp_rd_stats_idx
The idx for the latest compound mode in the cache comp_rd_stats.
Definition: block.h:1179
PALETTE_BUFFER * palette_buffer
Buffer to store the best palette map.
Definition: block.h:909
uint8_t * pred0
First prediction.
Definition: block.h:339
bool enable_nn_prune_intra_tx_depths
Indicates if NN model should be invoked to prune transform depths.
Definition: block.h:481
Inter-mode txfm results for a partition block.
Definition: block.h:231
Contains buffers used to speed up rdopt for obmc.
Definition: block.h:300
int tpl_stride
TPL&#39;s stride for the arrays in this struct.
Definition: block.h:73
double rb
Superblock level distortion propagation factor.
Definition: block.h:959
CoeffCosts coeff_costs
The rate needed to signal the txfm coefficients to the bitstream.
Definition: block.h:979
tran_low_t * qcoeff
Quantized coefficients.
Definition: block.h:106
unsigned int tx_domain_dist_threshold
Variable from WinnerModeParams based on current eval mode.
Definition: block.h:427
int skip_mode
Inter skip mode.
Definition: block.h:1124
INTERINTER_COMPOUND_DATA interinter_comp
Current parameters for interinter mode.
Definition: block.h:293
int mb_energy
Energy in the current source coding block. Used to calculate rdmult.
Definition: block.h:962
int index_start
Index to insert the newest rd record.
Definition: block.h:258
int must_find_valid_partition
Whether to disable some features to force a mode in current block.
Definition: block.h:1111
int16_t mode_context
Context used to encode the current mode.
Definition: block.h:224
RD_STATS rd_stats
Rd_stats for the whole partition block.
Definition: block.h:241
CB_COEFF_BUFFER * cb_coef_buff
Buffer of transformed coefficients.
Definition: block.h:902
unsigned int use_transform_domain_distortion
Variable from WinnerModeParams based on current eval mode.
Definition: block.h:431
tran_low_t * coeff
Transformed coefficients.
Definition: block.h:108
Holds the motion samples for warp motion model estimation.
Definition: block.h:792
int ** mv_cost_stack
Points to the nmv_cost_hp in use.
Definition: block.h:754
uint8_t color_index_map[MAX_SB_SQUARE]
The color map needed to reconstruct palette mode.
Definition: block.h:91
uint8_t * tmp_best_mask_buf
Backup of the best segmentation mask.
Definition: block.h:347
unsigned int predict_dc_level
Definition: block.h:458
struct macroblock_plane MACROBLOCK_PLANE
Each source plane of the current macroblock.
Holds mv costs for encoding and motion search.
Definition: block.h:729
int prev_segment_id
Previous segment id for which qmatrices were updated. This is used to bypass setting of qmatrices if ...
Definition: block.h:1026
uint8_t ref_mv_count
Number of ref mvs in the drl.
Definition: block.h:219
int sadperbit
A multiplier that converts mv cost to l1 error.
Definition: block.h:989
IntraBCHashInfo intrabc_hash_info
Data structure to speed up intrabc search.
Definition: block.h:1194
BLOCK_SIZE max_partition_size
Minimum partition size for the sb.
Definition: block.h:55
int mode_eval_type
Definition: block.h:470
Variables related to current coding block.
Definition: blockd.h:577
Superblock level encoder info.
Definition: block.h:51
TxfmSearchInfo txfm_search_info
Results of the txfm searches that have been done.
Definition: block.h:1256
ModeCosts mode_costs
The rate needed to signal a mode to the bitstream.
Definition: block.h:967
int use_default_intra_tx_type
Whether to limit the intra txfm search type to the default txfm.
Definition: block.h:413
TX_MODE tx_mode_search_type
How to search for the optimal tx_size.
Definition: block.h:448
Stores the best performing modes.
Definition: block.h:79
Holds mv costs for intrabc.
Definition: block.h:760
uint16_t * eobs
Location of the end of qcoeff (end of block).
Definition: block.h:110
Holds the costs needed to encode the coefficients.
Definition: block.h:777
int actual_num_seg1_blocks
Number of segment 1 blocks Actual number of (4x4) blocks that were applied delta-q, for segment 1.
Definition: block.h:1007
#define RD_RECORD_BUFFER_LEN
Number of txfm hash records kept for the partition block.
Definition: block.h:41
BLOCK_SIZE bsize
The block size of the current coding block.
Definition: blockd.h:228
const int16_t * zbin_QTX
Size of the quantization bin around 0. Only Used by QUANT_B.
Definition: block.h:134
Stores the prediction/txfm mode of the current coding block.
Definition: blockd.h:222
FRAME_CONTEXT * row_ctx
Entropy context for the current row.
Definition: block.h:883
int skip_txfm
Whether to skip transform and quantization on a partition block level.
Definition: block.h:499
unsigned int txb_split_count
Number of txb splits.
Definition: block.h:534
int cnt_zeromv
Number of zero motion vectors.
Definition: block.h:1017
PixelLevelGradientInfo * pixel_gradient_info
Pointer to the buffer which caches gradient information.
Definition: block.h:1207
float log_q
log of the quantization parameter of the ancestor BLOCK_64X64.
Definition: block.h:367
OBMCBuffer obmc_buffer
Modified source and masks used for fast OBMC search.
Definition: block.h:907
int use_qm_dist_metric
Definition: block.h:464
int recalc_luma_mc_data
Whether to recompute the luma prediction.
Definition: block.h:1188
int16_t * residual1
Source - first prediction.
Definition: block.h:343
int try_merge_partition
Prediction for ML based partition.
Definition: block.h:1290
MB_RD_RECORD * mb_rd_record
Txfm hash records of inter-modes.
Definition: block.h:522
Encoder&#39;s parameters related to the current coding block.
Definition: block.h:848
#define MAX_COMP_RD_STATS
Number of compound rd stats.
Definition: block.h:266
int force_zeromv_skip
Flag to force zeromv-skip block, for nonrd path.
Definition: block.h:1021
const int16_t * quant_fp_QTX
Quantization step size used by AV1_XFORM_QUANT_FP.
Definition: block.h:124
Stores various encoding/search decisions related to txfm search.
Definition: block.h:497
BLOCK_SIZE min_partition_size
Maximum partition size for the sb.
Definition: block.h:53
int cnn_output_valid
Whether the CNN buffer contains valid output.
Definition: block.h:363
RD_STATS rd_cost
Rdstats of the winner mode.
Definition: block.h:83
int seg_skip_block
Skip mode for the segment.
Definition: block.h:1001
Each source plane of the current macroblock.
Definition: block.h:100
const int16_t * round_QTX
Offset used for rounding in the quantizer process by AV1_XFORM_QUANT_B.
Definition: block.h:130
int rate_y
Luma rate of the winner mode.
Definition: block.h:87
uint8_t compound_idx
How to blend the compound predictions.
Definition: block.h:1174
const MB_MODE_INFO * mb_mode_cache
The mode to reuse during av1_rd_pick_intra_mode_sb and av1_rd_pick_inter_mode.
Definition: block.h:1200
MB_MODE_INFO_EXT mbmi_ext
Derived coding information.
Definition: block.h:873
Hash records of the inter-mode transform results.
Definition: block.h:252
PREDICTION_MODE mode
Current prediction mode.
Definition: block.h:285
TxfmSearchParams txfm_search_params
Parameters that control how motion search is done.
Definition: block.h:1249
MACROBLOCKD e_mbd
Decoder&#39;s view of current coding block.
Definition: block.h:866
Stores best extended mode information at frame level.
Definition: block.h:213
int prune_2d_txfm_mode
Whether to prune 2d transforms based on 1d transform results.
Definition: block.h:419
IntraBCMVCosts * dv_costs
Definition: block.h:976