2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef VP9_ENCODER_VP9_BLOCK_H_
12 #define VP9_ENCODER_VP9_BLOCK_H_
14 #include "vp9/common/vp9_onyx.h"
15 #include "vp9/common/vp9_entropymv.h"
16 #include "vp9/common/vp9_entropy.h"
17 #include "vpx_ports/mem.h"
18 #include "vp9/common/vp9_onyxc_int.h"
30 // Structure to hold snapshot of coding context during the mode picking process
34 int16_t *coeff[MAX_MB_PLANE][3];
35 int16_t *qcoeff[MAX_MB_PLANE][3];
36 int16_t *dqcoeff[MAX_MB_PLANE][3];
37 uint16_t *eobs[MAX_MB_PLANE][3];
39 // dual buffer pointers, 0: in use, 1: best in store
40 int16_t *coeff_pbuf[MAX_MB_PLANE][3];
41 int16_t *qcoeff_pbuf[MAX_MB_PLANE][3];
42 int16_t *dqcoeff_pbuf[MAX_MB_PLANE][3];
43 uint16_t *eobs_pbuf[MAX_MB_PLANE][3];
48 int_mv best_ref_mv[2];
49 int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
59 int64_t tx_rd_diff[TX_MODES];
60 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
62 // motion vector cache for adaptive motion search control in partition
64 int_mv pred_mv[MAX_REF_FRAMES];
65 INTERP_FILTER pred_interp_filter;
67 // Bit flag for each mode whether it has high error in comparison to others.
68 unsigned int modes_with_high_error;
71 struct macroblock_plane {
72 DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
84 // Zbin Over Quant value
88 /* The [2] dimension is for whether we skip the EOB node (i.e. if previous
89 * coefficient in this block was zero) or not. */
90 typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
91 [COEFF_CONTEXTS][ENTROPY_TOKENS];
93 typedef struct macroblock MACROBLOCK;
95 struct macroblock_plane plane[MAX_MB_PLANE];
106 int searches_per_step;
113 unsigned int mb_energy;
114 unsigned int *mb_activity_ptr;
115 int *mb_norm_activity_ptr;
116 signed int act_zbin_adj;
118 int mv_best_ref_index[MAX_REF_FRAMES];
119 unsigned int max_mv_context[MAX_REF_FRAMES];
120 unsigned int source_variance;
121 unsigned int pred_sse[MAX_REF_FRAMES];
122 int pred_mv_sad[MAX_REF_FRAMES];
123 int mode_sad[MAX_REF_FRAMES][INTER_MODES + 1];
125 int nmvjointcost[MV_JOINTS];
126 int nmvcosts[2][MV_VALS];
128 int nmvcosts_hp[2][MV_VALS];
132 int nmvjointsadcost[MV_JOINTS];
133 int nmvsadcosts[2][MV_VALS];
135 int nmvsadcosts_hp[2][MV_VALS];
136 int *nmvsadcost_hp[2];
139 int mbmode_cost[MB_MODE_COUNT];
140 unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
141 int intra_uv_mode_cost[2][MB_MODE_COUNT];
142 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
143 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
145 unsigned char sb_index; // index of 32x32 block inside the 64x64 block
146 unsigned char mb_index; // index of 16x16 block inside the 32x32 block
147 unsigned char b_index; // index of 8x8 block inside the 16x16 block
148 unsigned char ab_index; // index of 4x4 block inside the 8x8 block
150 // These define limits to motion vector components to prevent them
151 // from extending outside the UMV borders
157 uint8_t zcoeff_blk[TX_SIZES][256];
162 unsigned char *active_ptr;
164 // note that token_costs is the cost when eob node is skipped
165 vp9_coeff_cost token_costs[TX_SIZES];
166 DECLARE_ALIGNED(16, uint8_t, token_cache[1024]);
170 // indicate if it is in the rd search loop or encoding process
174 // Used to store sub partition's choices.
175 int_mv pred_mv[MAX_REF_FRAMES];
177 // TODO(jingning): Need to refactor the structure arrays that buffers the
178 // coding mode decisions of each partition type.
179 PICK_MODE_CONTEXT ab4x4_context[4][4][4];
180 PICK_MODE_CONTEXT sb8x4_context[4][4][4];
181 PICK_MODE_CONTEXT sb4x8_context[4][4][4];
182 PICK_MODE_CONTEXT sb8x8_context[4][4][4];
183 PICK_MODE_CONTEXT sb8x16_context[4][4][2];
184 PICK_MODE_CONTEXT sb16x8_context[4][4][2];
185 PICK_MODE_CONTEXT mb_context[4][4];
186 PICK_MODE_CONTEXT sb32x16_context[4][2];
187 PICK_MODE_CONTEXT sb16x32_context[4][2];
188 // when 4 MBs share coding parameters:
189 PICK_MODE_CONTEXT sb32_context[4];
190 PICK_MODE_CONTEXT sb32x64_context[2];
191 PICK_MODE_CONTEXT sb64x32_context[2];
192 PICK_MODE_CONTEXT sb64_context;
193 int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
195 BLOCK_SIZE b_partitioning[4][4][4];
196 BLOCK_SIZE mb_partitioning[4][4];
197 BLOCK_SIZE sb_partitioning[4];
198 BLOCK_SIZE sb64_partitioning;
200 void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride);
203 // TODO(jingning): the variables used here are little complicated. need further
204 // refactoring on organizing the temporary buffers, when recursive
205 // partition down to 4x4 block size is enabled.
206 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) {
209 return &x->sb64_context;
211 return &x->sb64x32_context[x->sb_index];
213 return &x->sb32x64_context[x->sb_index];
215 return &x->sb32_context[x->sb_index];
217 return &x->sb32x16_context[x->sb_index][x->mb_index];
219 return &x->sb16x32_context[x->sb_index][x->mb_index];
221 return &x->mb_context[x->sb_index][x->mb_index];
223 return &x->sb16x8_context[x->sb_index][x->mb_index][x->b_index];
225 return &x->sb8x16_context[x->sb_index][x->mb_index][x->b_index];
227 return &x->sb8x8_context[x->sb_index][x->mb_index][x->b_index];
229 return &x->sb8x4_context[x->sb_index][x->mb_index][x->b_index];
231 return &x->sb4x8_context[x->sb_index][x->mb_index][x->b_index];
233 return &x->ab4x4_context[x->sb_index][x->mb_index][x->b_index];
244 #endif // VP9_ENCODER_VP9_BLOCK_H_