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 #ifndef AOM_AV1_ENCODER_CONTEXT_TREE_H_
13 #define AOM_AV1_ENCODER_CONTEXT_TREE_H_
14
15 #include "config/aom_config.h"
16
17 #include "av1/common/blockd.h"
18 #include "av1/encoder/block.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 struct AV1_PRIMARY;
25 struct AV1_COMP;
26 struct AV1Common;
27 struct ThreadData;
28
29 typedef struct {
30 tran_low_t *coeff_buf[MAX_MB_PLANE];
31 tran_low_t *qcoeff_buf[MAX_MB_PLANE];
32 tran_low_t *dqcoeff_buf[MAX_MB_PLANE];
33 } PC_TREE_SHARED_BUFFERS;
34
35 // Structure to hold snapshot of coding context during the mode picking process
36 typedef struct PICK_MODE_CONTEXT {
37 MB_MODE_INFO mic;
38 MB_MODE_INFO_EXT_FRAME mbmi_ext_best;
39 uint8_t *color_index_map[2];
40 uint8_t *blk_skip;
41
42 tran_low_t *coeff[MAX_MB_PLANE];
43 tran_low_t *qcoeff[MAX_MB_PLANE];
44 tran_low_t *dqcoeff[MAX_MB_PLANE];
45 uint16_t *eobs[MAX_MB_PLANE];
46 uint8_t *txb_entropy_ctx[MAX_MB_PLANE];
47 uint8_t *tx_type_map;
48
49 int num_4x4_blk;
50 // For current partition, only if all Y, U, and V transform blocks'
51 // coefficients are quantized to 0, skippable is set to 1.
52 int skippable;
53 #if CONFIG_INTERNAL_STATS
54 THR_MODES best_mode_index;
55 #endif // CONFIG_INTERNAL_STATS
56 RD_STATS rd_stats;
57
58 int rd_mode_is_ready; // Flag to indicate whether rd pick mode decision has
59 // been made.
60 #if CONFIG_AV1_TEMPORAL_DENOISING
61 int64_t newmv_sse;
62 int64_t zeromv_sse;
63 int64_t zeromv_lastref_sse;
64 PREDICTION_MODE best_sse_inter_mode;
65 int_mv best_sse_mv;
66 MV_REFERENCE_FRAME best_reference_frame;
67 MV_REFERENCE_FRAME best_zeromv_reference_frame;
68 int sb_skip_denoising;
69 #endif
70 } PICK_MODE_CONTEXT;
71
72 typedef struct PC_TREE {
73 PARTITION_TYPE partitioning;
74 BLOCK_SIZE block_size;
75 PICK_MODE_CONTEXT *none;
76 PICK_MODE_CONTEXT *horizontal[2];
77 PICK_MODE_CONTEXT *vertical[2];
78 #if !CONFIG_REALTIME_ONLY
79 PICK_MODE_CONTEXT *horizontala[3];
80 PICK_MODE_CONTEXT *horizontalb[3];
81 PICK_MODE_CONTEXT *verticala[3];
82 PICK_MODE_CONTEXT *verticalb[3];
83 PICK_MODE_CONTEXT *horizontal4[4];
84 PICK_MODE_CONTEXT *vertical4[4];
85 #endif
86 struct PC_TREE *split[4];
87 int index;
88 } PC_TREE;
89
90 typedef struct SIMPLE_MOTION_DATA_TREE {
91 BLOCK_SIZE block_size;
92 PARTITION_TYPE partitioning;
93 struct SIMPLE_MOTION_DATA_TREE *split[4];
94
95 // Simple motion search_features
96 FULLPEL_MV start_mvs[REF_FRAMES];
97 unsigned int sms_none_feat[2];
98 unsigned int sms_rect_feat[8];
99 int sms_none_valid;
100 int sms_rect_valid;
101 } SIMPLE_MOTION_DATA_TREE;
102
103 void av1_setup_shared_coeff_buffer(const SequenceHeader *const seq_params,
104 PC_TREE_SHARED_BUFFERS *shared_bufs,
105 struct aom_internal_error_info *error);
106 void av1_free_shared_coeff_buffer(PC_TREE_SHARED_BUFFERS *shared_bufs);
107
108 PC_TREE *av1_alloc_pc_tree_node(BLOCK_SIZE bsize);
109 void av1_free_pc_tree_recursive(PC_TREE *tree, int num_planes, int keep_best,
110 int keep_none);
111
112 PICK_MODE_CONTEXT *av1_alloc_pmc(const struct AV1_COMP *const cpi,
113 BLOCK_SIZE bsize,
114 PC_TREE_SHARED_BUFFERS *shared_bufs);
115 void av1_reset_pmc(PICK_MODE_CONTEXT *ctx);
116 void av1_free_pmc(PICK_MODE_CONTEXT *ctx, int num_planes);
117 void av1_copy_tree_context(PICK_MODE_CONTEXT *dst_ctx,
118 PICK_MODE_CONTEXT *src_ctx);
119
120 static const BLOCK_SIZE square[MAX_SB_SIZE_LOG2 - 1] = {
121 BLOCK_4X4, BLOCK_8X8, BLOCK_16X16, BLOCK_32X32, BLOCK_64X64, BLOCK_128X128,
122 };
123
av1_get_pc_tree_nodes(const int is_sb_size_128,int stat_generation_stage)124 static AOM_INLINE int av1_get_pc_tree_nodes(const int is_sb_size_128,
125 int stat_generation_stage) {
126 const int tree_nodes_inc = is_sb_size_128 ? 1024 : 0;
127 const int tree_nodes =
128 stat_generation_stage ? 1 : (tree_nodes_inc + 256 + 64 + 16 + 4 + 1);
129 return tree_nodes;
130 }
131
132 void av1_setup_sms_tree(struct AV1_COMP *const cpi, struct ThreadData *td);
133 void av1_free_sms_tree(struct ThreadData *td);
134
135 #ifdef __cplusplus
136 } // extern "C"
137 #endif
138
139 #endif // AOM_AV1_ENCODER_CONTEXT_TREE_H_
140