• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   int hybrid_pred_diff;
57   int comp_pred_diff;
58   int single_pred_diff;
59 
60   RD_STATS rd_stats;
61 
62   int rd_mode_is_ready;  // Flag to indicate whether rd pick mode decision has
63                          // been made.
64 #if CONFIG_AV1_TEMPORAL_DENOISING
65   int64_t newmv_sse;
66   int64_t zeromv_sse;
67   int64_t zeromv_lastref_sse;
68   PREDICTION_MODE best_sse_inter_mode;
69   int_mv best_sse_mv;
70   MV_REFERENCE_FRAME best_reference_frame;
71   MV_REFERENCE_FRAME best_zeromv_reference_frame;
72   int sb_skip_denoising;
73 #endif
74 } PICK_MODE_CONTEXT;
75 
76 typedef struct PC_TREE {
77   PARTITION_TYPE partitioning;
78   BLOCK_SIZE block_size;
79   PICK_MODE_CONTEXT *none;
80   PICK_MODE_CONTEXT *horizontal[2];
81   PICK_MODE_CONTEXT *vertical[2];
82   PICK_MODE_CONTEXT *horizontala[3];
83   PICK_MODE_CONTEXT *horizontalb[3];
84   PICK_MODE_CONTEXT *verticala[3];
85   PICK_MODE_CONTEXT *verticalb[3];
86   PICK_MODE_CONTEXT *horizontal4[4];
87   PICK_MODE_CONTEXT *vertical4[4];
88   struct PC_TREE *split[4];
89   int index;
90 } PC_TREE;
91 
92 typedef struct SIMPLE_MOTION_DATA_TREE {
93   BLOCK_SIZE block_size;
94   PARTITION_TYPE partitioning;
95   struct SIMPLE_MOTION_DATA_TREE *split[4];
96 
97   // Simple motion search_features
98   FULLPEL_MV start_mvs[REF_FRAMES];
99   unsigned int sms_none_feat[2];
100   unsigned int sms_rect_feat[8];
101   int sms_none_valid;
102   int sms_rect_valid;
103 } SIMPLE_MOTION_DATA_TREE;
104 
105 void av1_setup_shared_coeff_buffer(const SequenceHeader *const seq_params,
106                                    PC_TREE_SHARED_BUFFERS *shared_bufs,
107                                    struct aom_internal_error_info *error);
108 void av1_free_shared_coeff_buffer(PC_TREE_SHARED_BUFFERS *shared_bufs);
109 
110 PC_TREE *av1_alloc_pc_tree_node(BLOCK_SIZE bsize);
111 void av1_free_pc_tree_recursive(PC_TREE *tree, int num_planes, int keep_best,
112                                 int keep_none);
113 
114 PICK_MODE_CONTEXT *av1_alloc_pmc(const struct AV1_COMP *const cpi,
115                                  BLOCK_SIZE bsize,
116                                  PC_TREE_SHARED_BUFFERS *shared_bufs);
117 void av1_free_pmc(PICK_MODE_CONTEXT *ctx, int num_planes);
118 void av1_copy_tree_context(PICK_MODE_CONTEXT *dst_ctx,
119                            PICK_MODE_CONTEXT *src_ctx);
120 
121 static const BLOCK_SIZE square[MAX_SB_SIZE_LOG2 - 1] = {
122   BLOCK_4X4, BLOCK_8X8, BLOCK_16X16, BLOCK_32X32, BLOCK_64X64, BLOCK_128X128,
123 };
124 
av1_get_pc_tree_nodes(const int is_sb_size_128,int stat_generation_stage)125 static AOM_INLINE int av1_get_pc_tree_nodes(const int is_sb_size_128,
126                                             int stat_generation_stage) {
127   const int tree_nodes_inc = is_sb_size_128 ? 1024 : 0;
128   const int tree_nodes =
129       stat_generation_stage ? 1 : (tree_nodes_inc + 256 + 64 + 16 + 4 + 1);
130   return tree_nodes;
131 }
132 
133 void av1_setup_sms_tree(struct AV1_COMP *const cpi, struct ThreadData *td);
134 void av1_free_sms_tree(struct ThreadData *td);
135 
136 #ifdef __cplusplus
137 }  // extern "C"
138 #endif
139 
140 #endif  // AOM_AV1_ENCODER_CONTEXT_TREE_H_
141