blob: e3b4e373428a18d01f4b7249fd7a5021b283c03e [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_ENCODER_BLOCK_H_
13#define AV1_ENCODER_BLOCK_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include "av1/common/entropymv.h"
16#include "av1/common/entropy.h"
17#if CONFIG_REF_MV
18#include "av1/common/mvref_common.h"
19#endif
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25typedef struct {
26 unsigned int sse;
27 int sum;
28 unsigned int var;
29} diff;
30
31typedef struct macroblock_plane {
32 DECLARE_ALIGNED(16, int16_t, src_diff[MAX_SB_SQUARE]);
33 tran_low_t *qcoeff;
34 tran_low_t *coeff;
35 uint16_t *eobs;
36 struct buf_2d src;
37
38 // Quantizer setings
39 const int16_t *quant_fp;
40 const int16_t *round_fp;
41 const int16_t *quant;
42 const int16_t *quant_shift;
43 const int16_t *zbin;
44 const int16_t *round;
45#if CONFIG_NEW_QUANT
46 const cuml_bins_type_nuq *cuml_bins_nuq[QUANT_PROFILES];
47#endif // CONFIG_NEW_QUANT
48
49 int64_t quant_thred[2];
50} MACROBLOCK_PLANE;
51
52/* The [2] dimension is for whether we skip the EOB node (i.e. if previous
53 * coefficient in this block was zero) or not. */
Yaowu Xuf883b422016-08-30 14:01:10 -070054typedef unsigned int av1_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
55 [COEFF_CONTEXTS][ENTROPY_TOKENS];
Yaowu Xuc27fc142016-08-22 16:08:15 -070056
57typedef struct {
58 int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
59 int16_t mode_context[MODE_CTX_REF_FRAMES];
60#if CONFIG_REF_MV
61 uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
62 CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
63#if CONFIG_EXT_INTER
64 int16_t compound_mode_context[MODE_CTX_REF_FRAMES];
65#endif // CONFIG_EXT_INTER
66#endif
67} MB_MODE_INFO_EXT;
68
69typedef struct {
70 uint8_t best_palette_color_map[MAX_SB_SQUARE];
71 float kmeans_data_buf[2 * MAX_SB_SQUARE];
72} PALETTE_BUFFER;
73
74typedef struct macroblock MACROBLOCK;
75struct macroblock {
76 struct macroblock_plane plane[MAX_MB_PLANE];
77
78 MACROBLOCKD e_mbd;
79 MB_MODE_INFO_EXT *mbmi_ext;
80 int skip_block;
81 int select_tx_size;
82 int skip_optimize;
83 int q_index;
84
85 // The equivalent error at the current rdmult of one whole bit (not one
86 // bitcost unit).
87 int errorperbit;
88 // The equivalend SAD error of one (whole) bit at the current quantizer
89 // for large blocks.
90 int sadperbit16;
91 // The equivalend SAD error of one (whole) bit at the current quantizer
92 // for sub-8x8 blocks.
93 int sadperbit4;
94 int rddiv;
95 int rdmult;
96 int mb_energy;
97 int *m_search_count_ptr;
98 int *ex_search_count_ptr;
99
100 // These are set to their default values at the beginning, and then adjusted
101 // further in the encoding process.
102 BLOCK_SIZE min_partition_size;
103 BLOCK_SIZE max_partition_size;
104
105 int mv_best_ref_index[TOTAL_REFS_PER_FRAME];
106 unsigned int max_mv_context[TOTAL_REFS_PER_FRAME];
107 unsigned int source_variance;
108 unsigned int recon_variance;
109 unsigned int pred_sse[TOTAL_REFS_PER_FRAME];
110 int pred_mv_sad[TOTAL_REFS_PER_FRAME];
111
112#if CONFIG_REF_MV
113 int *nmvjointcost;
114 int nmv_vec_cost[NMV_CONTEXTS][MV_JOINTS];
115 int *nmvcost[NMV_CONTEXTS][2];
116 int *nmvcost_hp[NMV_CONTEXTS][2];
117 int **mv_cost_stack[NMV_CONTEXTS];
118 int *nmvjointsadcost;
119 int zero_rmv_cost[NMV_CONTEXTS][2];
120 int comp_rmv_cost[2];
121#else
122 int nmvjointcost[MV_JOINTS];
123 int *nmvcost[2];
124 int *nmvcost_hp[2];
125 int nmvjointsadcost[MV_JOINTS];
126#endif
127
128 int **mvcost;
129 int *nmvsadcost[2];
130 int *nmvsadcost_hp[2];
131 int **mvsadcost;
132
133 PALETTE_BUFFER *palette_buffer;
134
135 // These define limits to motion vector components to prevent them
136 // from extending outside the UMV borders
137 int mv_col_min;
138 int mv_col_max;
139 int mv_row_min;
140 int mv_row_max;
141
142#if CONFIG_VAR_TX
143 uint8_t blk_skip[MAX_MB_PLANE][MAX_MIB_SIZE * MAX_MIB_SIZE * 4];
144#if CONFIG_REF_MV
145 uint8_t blk_skip_drl[MAX_MB_PLANE][MAX_MIB_SIZE * MAX_MIB_SIZE * 4];
146#endif
147#endif
148
149 int skip;
150
151 int encode_breakout;
152
153 // note that token_costs is the cost when eob node is skipped
Yaowu Xuf883b422016-08-30 14:01:10 -0700154 av1_coeff_cost token_costs[TX_SIZES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700155
156 int optimize;
157
158 // indicate if it is in the rd search loop or encoding process
159 int use_lp32x32fdct;
160
161 // Used to store sub partition's choices.
162 MV pred_mv[TOTAL_REFS_PER_FRAME];
163
164 // Store the best motion vector during motion search
165 int_mv best_mv;
166 // Store the second best motion vector during full-pixel motion search
167 int_mv second_best_mv;
168
169 // Strong color activity detection. Used in RTC coding mode to enhance
170 // the visual quality at the boundary of moving color objects.
171 uint8_t color_sensitivity[2];
172
173 // use default transform and skip transform type search for intra modes
174 int use_default_intra_tx_type;
175 // use default transform and skip transform type search for inter modes
176 int use_default_inter_tx_type;
177};
178
179#ifdef __cplusplus
180} // extern "C"
181#endif
182
Yaowu Xuf883b422016-08-30 14:01:10 -0700183#endif // AV1_ENCODER_BLOCK_H_