OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef VP9_ENCODER_VP9_BLOCK_H_ | 11 #ifndef VP9_ENCODER_VP9_BLOCK_H_ |
12 #define VP9_ENCODER_VP9_BLOCK_H_ | 12 #define VP9_ENCODER_VP9_BLOCK_H_ |
13 | 13 |
14 #include "vp9/common/vp9_onyx.h" | 14 #include "vp9/common/vp9_onyx.h" |
15 #include "vp9/common/vp9_entropymv.h" | 15 #include "vp9/common/vp9_entropymv.h" |
16 #include "vp9/common/vp9_entropy.h" | 16 #include "vp9/common/vp9_entropy.h" |
17 #include "vpx_ports/mem.h" | 17 #include "vpx_ports/mem.h" |
18 #include "vp9/common/vp9_onyxc_int.h" | 18 #include "vp9/common/vp9_onyxc_int.h" |
19 | 19 |
20 // motion search site | 20 // motion search site |
21 typedef struct { | 21 typedef struct { |
22 MV mv; | 22 MV mv; |
23 int offset; | 23 int offset; |
24 } search_site; | 24 } search_site; |
25 | 25 |
26 // Structure to hold snapshot of coding context during the mode picking process | 26 // Structure to hold snapshot of coding context during the mode picking process |
27 typedef struct { | 27 typedef struct { |
28 MODE_INFO mic; | 28 MODE_INFO mic; |
29 uint8_t *zcoeff_blk; | 29 uint8_t *zcoeff_blk; |
| 30 int16_t *coeff[MAX_MB_PLANE][3]; |
| 31 int16_t *qcoeff[MAX_MB_PLANE][3]; |
| 32 int16_t *dqcoeff[MAX_MB_PLANE][3]; |
| 33 uint16_t *eobs[MAX_MB_PLANE][3]; |
| 34 |
| 35 // dual buffer pointers, 0: in use, 1: best in store |
| 36 int16_t *coeff_pbuf[MAX_MB_PLANE][3]; |
| 37 int16_t *qcoeff_pbuf[MAX_MB_PLANE][3]; |
| 38 int16_t *dqcoeff_pbuf[MAX_MB_PLANE][3]; |
| 39 uint16_t *eobs_pbuf[MAX_MB_PLANE][3]; |
| 40 |
| 41 int is_coded; |
30 int num_4x4_blk; | 42 int num_4x4_blk; |
31 int skip; | 43 int skip; |
32 int_mv best_ref_mv; | 44 int_mv best_ref_mv; |
33 int_mv second_best_ref_mv; | 45 int_mv second_best_ref_mv; |
34 int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; | 46 int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; |
35 int rate; | 47 int rate; |
36 int distortion; | 48 int distortion; |
37 int64_t intra_error; | 49 int64_t intra_error; |
38 int best_mode_index; | 50 int best_mode_index; |
39 int rddiv; | 51 int rddiv; |
40 int rdmult; | 52 int rdmult; |
41 int hybrid_pred_diff; | 53 int hybrid_pred_diff; |
42 int comp_pred_diff; | 54 int comp_pred_diff; |
43 int single_pred_diff; | 55 int single_pred_diff; |
44 int64_t tx_rd_diff[TX_MODES]; | 56 int64_t tx_rd_diff[TX_MODES]; |
45 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; | 57 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; |
46 | 58 |
47 // motion vector cache for adaptive motion search control in partition | 59 // motion vector cache for adaptive motion search control in partition |
48 // search loop | 60 // search loop |
49 int_mv pred_mv[MAX_REF_FRAMES]; | 61 int_mv pred_mv[MAX_REF_FRAMES]; |
| 62 int pred_filter_type; |
50 | 63 |
51 // Bit flag for each mode whether it has high error in comparison to others. | 64 // Bit flag for each mode whether it has high error in comparison to others. |
52 unsigned int modes_with_high_error; | 65 unsigned int modes_with_high_error; |
53 | 66 |
54 // Bit flag for each ref frame whether it has high error compared to others. | 67 // Bit flag for each ref frame whether it has high error compared to others. |
55 unsigned int frames_with_high_error; | 68 unsigned int frames_with_high_error; |
56 } PICK_MODE_CONTEXT; | 69 } PICK_MODE_CONTEXT; |
57 | 70 |
58 struct macroblock_plane { | 71 struct macroblock_plane { |
59 DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]); | 72 DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]); |
60 DECLARE_ALIGNED(16, int16_t, coeff[64 * 64]); | 73 int16_t *qcoeff; |
| 74 int16_t *coeff; |
| 75 uint16_t *eobs; |
61 struct buf_2d src; | 76 struct buf_2d src; |
62 | 77 |
63 // Quantizer setings | 78 // Quantizer setings |
64 int16_t *quant; | 79 int16_t *quant; |
65 int16_t *quant_shift; | 80 int16_t *quant_shift; |
66 int16_t *zbin; | 81 int16_t *zbin; |
67 int16_t *round; | 82 int16_t *round; |
68 | 83 |
69 // Zbin Over Quant value | 84 // Zbin Over Quant value |
70 int16_t zbin_extra; | 85 int16_t zbin_extra; |
71 }; | 86 }; |
72 | 87 |
73 /* The [2] dimension is for whether we skip the EOB node (i.e. if previous | 88 /* The [2] dimension is for whether we skip the EOB node (i.e. if previous |
74 * coefficient in this block was zero) or not. */ | 89 * coefficient in this block was zero) or not. */ |
75 typedef unsigned int vp9_coeff_cost[BLOCK_TYPES][REF_TYPES][COEF_BANDS][2] | 90 typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2] |
76 [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS]; | 91 [COEFF_CONTEXTS][ENTROPY_TOKENS]; |
77 | 92 |
78 typedef struct macroblock MACROBLOCK; | 93 typedef struct macroblock MACROBLOCK; |
79 struct macroblock { | 94 struct macroblock { |
80 struct macroblock_plane plane[MAX_MB_PLANE]; | 95 struct macroblock_plane plane[MAX_MB_PLANE]; |
81 | 96 |
82 MACROBLOCKD e_mbd; | 97 MACROBLOCKD e_mbd; |
83 int skip_block; | 98 int skip_block; |
| 99 int select_txfm_size; |
| 100 int skip_recode; |
| 101 int skip_optimize; |
| 102 int q_index; |
84 | 103 |
85 search_site *ss; | 104 search_site *ss; |
86 int ss_count; | 105 int ss_count; |
87 int searches_per_step; | 106 int searches_per_step; |
88 | 107 |
89 int errorperbit; | 108 int errorperbit; |
90 int sadperbit16; | 109 int sadperbit16; |
91 int sadperbit4; | 110 int sadperbit4; |
92 int rddiv; | 111 int rddiv; |
93 int rdmult; | 112 int rdmult; |
(...skipping 19 matching lines...) Loading... |
113 int nmvsadcosts_hp[2][MV_VALS]; | 132 int nmvsadcosts_hp[2][MV_VALS]; |
114 int *nmvsadcost_hp[2]; | 133 int *nmvsadcost_hp[2]; |
115 int **mvsadcost; | 134 int **mvsadcost; |
116 | 135 |
117 int mbmode_cost[MB_MODE_COUNT]; | 136 int mbmode_cost[MB_MODE_COUNT]; |
118 unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES]; | 137 unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES]; |
119 int intra_uv_mode_cost[2][MB_MODE_COUNT]; | 138 int intra_uv_mode_cost[2][MB_MODE_COUNT]; |
120 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; | 139 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; |
121 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; | 140 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; |
122 | 141 |
| 142 unsigned char sb_index; // index of 32x32 block inside the 64x64 block |
| 143 unsigned char mb_index; // index of 16x16 block inside the 32x32 block |
| 144 unsigned char b_index; // index of 8x8 block inside the 16x16 block |
| 145 unsigned char ab_index; // index of 4x4 block inside the 8x8 block |
| 146 |
123 // These define limits to motion vector components to prevent them | 147 // These define limits to motion vector components to prevent them |
124 // from extending outside the UMV borders | 148 // from extending outside the UMV borders |
125 int mv_col_min; | 149 int mv_col_min; |
126 int mv_col_max; | 150 int mv_col_max; |
127 int mv_row_min; | 151 int mv_row_min; |
128 int mv_row_max; | 152 int mv_row_max; |
129 | 153 |
130 uint8_t zcoeff_blk[TX_SIZES][256]; | 154 uint8_t zcoeff_blk[TX_SIZES][256]; |
131 int skip; | 155 int skip; |
132 | 156 |
133 int encode_breakout; | 157 int encode_breakout; |
134 | 158 |
135 unsigned char *active_ptr; | 159 unsigned char *active_ptr; |
136 | 160 |
137 // note that token_costs is the cost when eob node is skipped | 161 // note that token_costs is the cost when eob node is skipped |
138 vp9_coeff_cost token_costs[TX_SIZES]; | 162 vp9_coeff_cost token_costs[TX_SIZES]; |
139 uint8_t token_cache[1024]; | 163 DECLARE_ALIGNED(16, uint8_t, token_cache[1024]); |
140 | 164 |
141 int optimize; | 165 int optimize; |
142 | 166 |
143 // indicate if it is in the rd search loop or encoding process | 167 // indicate if it is in the rd search loop or encoding process |
144 int use_lp32x32fdct; | 168 int use_lp32x32fdct; |
145 int skip_encode; | 169 int skip_encode; |
146 | 170 |
147 // Used to store sub partition's choices. | 171 // Used to store sub partition's choices. |
148 int fast_ms; | 172 int fast_ms; |
149 int_mv pred_mv[MAX_REF_FRAMES]; | 173 int_mv pred_mv[MAX_REF_FRAMES]; |
(...skipping 22 matching lines...) Loading... |
172 BLOCK_SIZE sb_partitioning[4]; | 196 BLOCK_SIZE sb_partitioning[4]; |
173 BLOCK_SIZE sb64_partitioning; | 197 BLOCK_SIZE sb64_partitioning; |
174 | 198 |
175 void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride); | 199 void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride); |
176 }; | 200 }; |
177 | 201 |
178 // TODO(jingning): the variables used here are little complicated. need further | 202 // TODO(jingning): the variables used here are little complicated. need further |
179 // refactoring on organizing the temporary buffers, when recursive | 203 // refactoring on organizing the temporary buffers, when recursive |
180 // partition down to 4x4 block size is enabled. | 204 // partition down to 4x4 block size is enabled. |
181 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) { | 205 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) { |
182 MACROBLOCKD *const xd = &x->e_mbd; | |
183 | |
184 switch (bsize) { | 206 switch (bsize) { |
185 case BLOCK_64X64: | 207 case BLOCK_64X64: |
186 return &x->sb64_context; | 208 return &x->sb64_context; |
187 case BLOCK_64X32: | 209 case BLOCK_64X32: |
188 return &x->sb64x32_context[xd->sb_index]; | 210 return &x->sb64x32_context[x->sb_index]; |
189 case BLOCK_32X64: | 211 case BLOCK_32X64: |
190 return &x->sb32x64_context[xd->sb_index]; | 212 return &x->sb32x64_context[x->sb_index]; |
191 case BLOCK_32X32: | 213 case BLOCK_32X32: |
192 return &x->sb32_context[xd->sb_index]; | 214 return &x->sb32_context[x->sb_index]; |
193 case BLOCK_32X16: | 215 case BLOCK_32X16: |
194 return &x->sb32x16_context[xd->sb_index][xd->mb_index]; | 216 return &x->sb32x16_context[x->sb_index][x->mb_index]; |
195 case BLOCK_16X32: | 217 case BLOCK_16X32: |
196 return &x->sb16x32_context[xd->sb_index][xd->mb_index]; | 218 return &x->sb16x32_context[x->sb_index][x->mb_index]; |
197 case BLOCK_16X16: | 219 case BLOCK_16X16: |
198 return &x->mb_context[xd->sb_index][xd->mb_index]; | 220 return &x->mb_context[x->sb_index][x->mb_index]; |
199 case BLOCK_16X8: | 221 case BLOCK_16X8: |
200 return &x->sb16x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 222 return &x->sb16x8_context[x->sb_index][x->mb_index][x->b_index]; |
201 case BLOCK_8X16: | 223 case BLOCK_8X16: |
202 return &x->sb8x16_context[xd->sb_index][xd->mb_index][xd->b_index]; | 224 return &x->sb8x16_context[x->sb_index][x->mb_index][x->b_index]; |
203 case BLOCK_8X8: | 225 case BLOCK_8X8: |
204 return &x->sb8x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 226 return &x->sb8x8_context[x->sb_index][x->mb_index][x->b_index]; |
205 case BLOCK_8X4: | 227 case BLOCK_8X4: |
206 return &x->sb8x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | 228 return &x->sb8x4_context[x->sb_index][x->mb_index][x->b_index]; |
207 case BLOCK_4X8: | 229 case BLOCK_4X8: |
208 return &x->sb4x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 230 return &x->sb4x8_context[x->sb_index][x->mb_index][x->b_index]; |
209 case BLOCK_4X4: | 231 case BLOCK_4X4: |
210 return &x->ab4x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | 232 return &x->ab4x4_context[x->sb_index][x->mb_index][x->b_index]; |
211 default: | 233 default: |
212 assert(0); | 234 assert(0); |
213 return NULL; | 235 return NULL; |
214 } | 236 } |
215 } | 237 } |
216 | 238 |
217 struct rdcost_block_args { | 239 struct rdcost_block_args { |
218 MACROBLOCK *x; | 240 MACROBLOCK *x; |
219 ENTROPY_CONTEXT t_above[16]; | 241 ENTROPY_CONTEXT t_above[16]; |
220 ENTROPY_CONTEXT t_left[16]; | 242 ENTROPY_CONTEXT t_left[16]; |
221 TX_SIZE tx_size; | 243 TX_SIZE tx_size; |
222 int bw; | 244 int bw; |
223 int bh; | 245 int bh; |
224 int rate; | 246 int rate; |
225 int64_t dist; | 247 int64_t dist; |
226 int64_t sse; | 248 int64_t sse; |
227 int this_rate; | 249 int this_rate; |
228 int64_t this_dist; | 250 int64_t this_dist; |
229 int64_t this_sse; | 251 int64_t this_sse; |
230 int64_t this_rd; | 252 int64_t this_rd; |
231 int64_t best_rd; | 253 int64_t best_rd; |
232 int skip; | 254 int skip; |
233 const int16_t *scan, *nb; | 255 const int16_t *scan, *nb; |
234 }; | 256 }; |
235 | 257 |
236 #endif // VP9_ENCODER_VP9_BLOCK_H_ | 258 #endif // VP9_ENCODER_VP9_BLOCK_H_ |
OLD | NEW |