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 | |
12 #include "./vpx_config.h" | 11 #include "./vpx_config.h" |
13 #include "./vp9_rtcd.h" | 12 #include "./vp9_rtcd.h" |
14 #include "vp9/encoder/vp9_encodeframe.h" | 13 #include "vp9/encoder/vp9_encodeframe.h" |
15 #include "vp9/encoder/vp9_encodemb.h" | 14 #include "vp9/encoder/vp9_encodemb.h" |
16 #include "vp9/encoder/vp9_encodemv.h" | 15 #include "vp9/encoder/vp9_encodemv.h" |
17 #include "vp9/common/vp9_common.h" | 16 #include "vp9/common/vp9_common.h" |
18 #include "vp9/encoder/vp9_onyx_int.h" | 17 #include "vp9/encoder/vp9_onyx_int.h" |
19 #include "vp9/common/vp9_extend.h" | 18 #include "vp9/common/vp9_extend.h" |
20 #include "vp9/common/vp9_entropy.h" | 19 #include "vp9/common/vp9_entropy.h" |
21 #include "vp9/common/vp9_entropymode.h" | 20 #include "vp9/common/vp9_entropymode.h" |
(...skipping 17 matching lines...) Expand all Loading... |
39 | 38 |
40 #define DBG_PRNT_SEGMAP 0 | 39 #define DBG_PRNT_SEGMAP 0 |
41 | 40 |
42 // #define ENC_DEBUG | 41 // #define ENC_DEBUG |
43 #ifdef ENC_DEBUG | 42 #ifdef ENC_DEBUG |
44 int enc_debug = 0; | 43 int enc_debug = 0; |
45 #endif | 44 #endif |
46 | 45 |
47 void vp9_select_interp_filter_type(VP9_COMP *cpi); | 46 void vp9_select_interp_filter_type(VP9_COMP *cpi); |
48 | 47 |
49 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, | 48 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
50 int output_enabled, int mi_row, int mi_col, | 49 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize); |
51 BLOCK_SIZE_TYPE bsize); | |
52 | 50 |
53 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); | 51 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); |
54 | 52 |
55 /* activity_avg must be positive, or flat regions could get a zero weight | 53 /* activity_avg must be positive, or flat regions could get a zero weight |
56 * (infinite lambda), which confounds analysis. | 54 * (infinite lambda), which confounds analysis. |
57 * This also avoids the need for divide by zero checks in | 55 * This also avoids the need for divide by zero checks in |
58 * vp9_activity_masking(). | 56 * vp9_activity_masking(). |
59 */ | 57 */ |
60 #define VP9_ACTIVITY_AVG_MIN (64) | 58 #define VP9_ACTIVITY_AVG_MIN (64) |
61 | 59 |
62 /* This is used as a reference when computing the source variance for the | 60 /* This is used as a reference when computing the source variance for the |
63 * purposes of activity masking. | 61 * purposes of activity masking. |
64 * Eventually this should be replaced by custom no-reference routines, | 62 * Eventually this should be replaced by custom no-reference routines, |
65 * which will be faster. | 63 * which will be faster. |
66 */ | 64 */ |
67 static const uint8_t VP9_VAR_OFFS[16] = { | 65 static const uint8_t VP9_VAR_OFFS[16] = {128, 128, 128, 128, 128, 128, 128, 128, |
68 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 | 66 128, 128, 128, 128, 128, 128, 128, 128}; |
69 }; | |
70 | |
71 | 67 |
72 // Original activity measure from Tim T's code. | 68 // Original activity measure from Tim T's code. |
73 static unsigned int tt_activity_measure(VP9_COMP *cpi, MACROBLOCK *x) { | 69 static unsigned int tt_activity_measure(VP9_COMP *cpi, MACROBLOCK *x) { |
74 unsigned int act; | 70 unsigned int act; |
75 unsigned int sse; | 71 unsigned int sse; |
76 /* TODO: This could also be done over smaller areas (8x8), but that would | 72 /* TODO: This could also be done over smaller areas (8x8), but that would |
77 * require extensive changes elsewhere, as lambda is assumed to be fixed | 73 * require extensive changes elsewhere, as lambda is assumed to be fixed |
78 * over an entire MB in most of the code. | 74 * over an entire MB in most of the code. |
79 * Another option is to compute four 8x8 variances, and pick a single | 75 * Another option is to compute four 8x8 variances, and pick a single |
80 * lambda using a non-linear combination (e.g., the smallest, or second | 76 * lambda using a non-linear combination (e.g., the smallest, or second |
81 * smallest, etc.). | 77 * smallest, etc.). |
82 */ | 78 */ |
83 act = vp9_variance16x16(x->plane[0].src.buf, x->plane[0].src.stride, | 79 act = vp9_variance16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
84 VP9_VAR_OFFS, 0, &sse); | 80 VP9_VAR_OFFS, 0, &sse); |
85 act <<= 4; | 81 act <<= 4; |
86 | 82 |
87 /* If the region is flat, lower the activity some more. */ | 83 /* If the region is flat, lower the activity some more. */ |
88 if (act < 8 << 12) | 84 if (act < 8 << 12) |
89 act = act < 5 << 12 ? act : 5 << 12; | 85 act = act < 5 << 12 ? act : 5 << 12; |
90 | 86 |
91 return act; | 87 return act; |
92 } | 88 } |
93 | 89 |
94 // Stub for alternative experimental activity measures. | 90 // Stub for alternative experimental activity measures. |
95 static unsigned int alt_activity_measure(VP9_COMP *cpi, | 91 static unsigned int alt_activity_measure(VP9_COMP *cpi, MACROBLOCK *x, |
96 MACROBLOCK *x, int use_dc_pred) { | 92 int use_dc_pred) { |
97 return vp9_encode_intra(cpi, x, use_dc_pred); | 93 return vp9_encode_intra(cpi, x, use_dc_pred); |
98 } | 94 } |
99 | 95 DECLARE_ALIGNED(16, static const uint8_t, vp9_64x64_zeros[64*64]) = {0}; |
100 DECLARE_ALIGNED(16, static const uint8_t, vp9_64x64_zeros[64*64]) = { 0 }; | |
101 | |
102 | 96 |
103 // Measure the activity of the current macroblock | 97 // Measure the activity of the current macroblock |
104 // What we measure here is TBD so abstracted to this function | 98 // What we measure here is TBD so abstracted to this function |
105 #define ALT_ACT_MEASURE 1 | 99 #define ALT_ACT_MEASURE 1 |
106 static unsigned int mb_activity_measure(VP9_COMP *cpi, MACROBLOCK *x, | 100 static unsigned int mb_activity_measure(VP9_COMP *cpi, MACROBLOCK *x, |
107 int mb_row, int mb_col) { | 101 int mb_row, int mb_col) { |
108 unsigned int mb_activity; | 102 unsigned int mb_activity; |
109 | 103 |
110 if (ALT_ACT_MEASURE) { | 104 if (ALT_ACT_MEASURE) { |
111 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); | 105 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); |
(...skipping 17 matching lines...) Expand all Loading... |
129 #if ACT_MEDIAN | 123 #if ACT_MEDIAN |
130 // Find median: Simple n^2 algorithm for experimentation | 124 // Find median: Simple n^2 algorithm for experimentation |
131 { | 125 { |
132 unsigned int median; | 126 unsigned int median; |
133 unsigned int i, j; | 127 unsigned int i, j; |
134 unsigned int *sortlist; | 128 unsigned int *sortlist; |
135 unsigned int tmp; | 129 unsigned int tmp; |
136 | 130 |
137 // Create a list to sort to | 131 // Create a list to sort to |
138 CHECK_MEM_ERROR(sortlist, | 132 CHECK_MEM_ERROR(sortlist, |
139 vpx_calloc(sizeof(unsigned int), | 133 vpx_calloc(sizeof(unsigned int), |
140 cpi->common.MBs)); | 134 cpi->common.MBs)); |
141 | 135 |
142 // Copy map to sort list | 136 // Copy map to sort list |
143 vpx_memcpy(sortlist, cpi->mb_activity_map, | 137 vpx_memcpy(sortlist, cpi->mb_activity_map, |
144 sizeof(unsigned int) * cpi->common.MBs); | 138 sizeof(unsigned int) * cpi->common.MBs); |
145 | |
146 | 139 |
147 // Ripple each value down to its correct position | 140 // Ripple each value down to its correct position |
148 for (i = 1; i < cpi->common.MBs; i ++) { | 141 for (i = 1; i < cpi->common.MBs; i ++) { |
149 for (j = i; j > 0; j --) { | 142 for (j = i; j > 0; j --) { |
150 if (sortlist[j] < sortlist[j - 1]) { | 143 if (sortlist[j] < sortlist[j - 1]) { |
151 // Swap values | 144 // Swap values |
152 tmp = sortlist[j - 1]; | 145 tmp = sortlist[j - 1]; |
153 sortlist[j - 1] = sortlist[j]; | 146 sortlist[j - 1] = sortlist[j]; |
154 sortlist[j] = tmp; | 147 sortlist[j] = tmp; |
155 } else | 148 } else |
156 break; | 149 break; |
157 } | 150 } |
158 } | 151 } |
159 | 152 |
160 // Even number MBs so estimate median as mean of two either side. | 153 // Even number MBs so estimate median as mean of two either side. |
161 median = (1 + sortlist[cpi->common.MBs >> 1] + | 154 median = (1 + sortlist[cpi->common.MBs >> 1] + |
162 sortlist[(cpi->common.MBs >> 1) + 1]) >> 1; | 155 sortlist[(cpi->common.MBs >> 1) + 1]) >> 1; |
163 | 156 |
164 cpi->activity_avg = median; | 157 cpi->activity_avg = median; |
165 | 158 |
166 vpx_free(sortlist); | 159 vpx_free(sortlist); |
167 } | 160 } |
168 #else | 161 #else |
169 // Simple mean for now | 162 // Simple mean for now |
170 cpi->activity_avg = (unsigned int)(activity_sum / cpi->common.MBs); | 163 cpi->activity_avg = (unsigned int) (activity_sum / cpi->common.MBs); |
171 #endif | 164 #endif |
172 | 165 |
173 if (cpi->activity_avg < VP9_ACTIVITY_AVG_MIN) | 166 if (cpi->activity_avg < VP9_ACTIVITY_AVG_MIN) |
174 cpi->activity_avg = VP9_ACTIVITY_AVG_MIN; | 167 cpi->activity_avg = VP9_ACTIVITY_AVG_MIN; |
175 | 168 |
176 // Experimental code: return fixed value normalized for several clips | 169 // Experimental code: return fixed value normalized for several clips |
177 if (ALT_ACT_MEASURE) | 170 if (ALT_ACT_MEASURE) |
178 cpi->activity_avg = 100000; | 171 cpi->activity_avg = 100000; |
179 } | 172 } |
180 | 173 |
(...skipping 23 matching lines...) Expand all Loading... |
204 // for each macroblock col in image | 197 // for each macroblock col in image |
205 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { | 198 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { |
206 // Read activity from the map | 199 // Read activity from the map |
207 act = *(x->mb_activity_ptr); | 200 act = *(x->mb_activity_ptr); |
208 | 201 |
209 // Calculate a normalized activity number | 202 // Calculate a normalized activity number |
210 a = act + 4 * cpi->activity_avg; | 203 a = act + 4 * cpi->activity_avg; |
211 b = 4 * act + cpi->activity_avg; | 204 b = 4 * act + cpi->activity_avg; |
212 | 205 |
213 if (b >= a) | 206 if (b >= a) |
214 *(x->activity_ptr) = (int)((b + (a >> 1)) / a) - 1; | 207 *(x->activity_ptr) = (int)((b + (a >> 1)) / a) - 1; |
215 else | 208 else |
216 *(x->activity_ptr) = 1 - (int)((a + (b >> 1)) / b); | 209 *(x->activity_ptr) = 1 - (int)((a + (b >> 1)) / b); |
217 | 210 |
218 #if OUTPUT_NORM_ACT_STATS | 211 #if OUTPUT_NORM_ACT_STATS |
219 fprintf(f, " %6d", *(x->mb_activity_ptr)); | 212 fprintf(f, " %6d", *(x->mb_activity_ptr)); |
220 #endif | 213 #endif |
221 // Increment activity map pointers | 214 // Increment activity map pointers |
222 x->mb_activity_ptr++; | 215 x->mb_activity_ptr++; |
223 } | 216 } |
224 | 217 |
225 #if OUTPUT_NORM_ACT_STATS | 218 #if OUTPUT_NORM_ACT_STATS |
226 fprintf(f, "\n"); | 219 fprintf(f, "\n"); |
227 #endif | 220 #endif |
228 | 221 |
229 } | 222 } |
230 | 223 |
231 #if OUTPUT_NORM_ACT_STATS | 224 #if OUTPUT_NORM_ACT_STATS |
232 fclose(f); | 225 fclose(f); |
233 #endif | 226 #endif |
234 | 227 |
235 } | 228 } |
236 #endif | 229 #endif |
237 | 230 |
238 // Loop through all MBs. Note activity of each, average activity and | 231 // Loop through all MBs. Note activity of each, average activity and |
239 // calculate a normalized activity for each | 232 // calculate a normalized activity for each |
240 static void build_activity_map(VP9_COMP *cpi) { | 233 static void build_activity_map(VP9_COMP *cpi) { |
241 MACROBLOCK *const x = &cpi->mb; | 234 MACROBLOCK * const x = &cpi->mb; |
242 MACROBLOCKD *xd = &x->e_mbd; | 235 MACROBLOCKD *xd = &x->e_mbd; |
243 VP9_COMMON *const cm = &cpi->common; | 236 VP9_COMMON * const cm = &cpi->common; |
244 | 237 |
245 #if ALT_ACT_MEASURE | 238 #if ALT_ACT_MEASURE |
246 YV12_BUFFER_CONFIG *new_yv12 = &cm->yv12_fb[cm->new_fb_idx]; | 239 YV12_BUFFER_CONFIG *new_yv12 = &cm->yv12_fb[cm->new_fb_idx]; |
247 int recon_yoffset; | 240 int recon_yoffset; |
248 int recon_y_stride = new_yv12->y_stride; | 241 int recon_y_stride = new_yv12->y_stride; |
249 #endif | 242 #endif |
250 | 243 |
251 int mb_row, mb_col; | 244 int mb_row, mb_col; |
252 unsigned int mb_activity; | 245 unsigned int mb_activity; |
253 int64_t activity_sum = 0; | 246 int64_t activity_sum = 0; |
(...skipping 24 matching lines...) Expand all Loading... |
278 // Store MB level activity details. | 271 // Store MB level activity details. |
279 *x->mb_activity_ptr = mb_activity; | 272 *x->mb_activity_ptr = mb_activity; |
280 | 273 |
281 // Increment activity map pointer | 274 // Increment activity map pointer |
282 x->mb_activity_ptr++; | 275 x->mb_activity_ptr++; |
283 | 276 |
284 // adjust to the next column of source macroblocks | 277 // adjust to the next column of source macroblocks |
285 x->plane[0].src.buf += 16; | 278 x->plane[0].src.buf += 16; |
286 } | 279 } |
287 | 280 |
288 | |
289 // adjust to the next row of mbs | 281 // adjust to the next row of mbs |
290 x->plane[0].src.buf += 16 * x->plane[0].src.stride - 16 * cm->mb_cols; | 282 x->plane[0].src.buf += 16 * x->plane[0].src.stride - 16 * cm->mb_cols; |
291 } | 283 } |
292 | 284 |
293 // Calculate an "average" MB activity | 285 // Calculate an "average" MB activity |
294 calc_av_activity(cpi, activity_sum); | 286 calc_av_activity(cpi, activity_sum); |
295 | 287 |
296 #if USE_ACT_INDEX | 288 #if USE_ACT_INDEX |
297 // Calculate an activity index number of each mb | 289 // Calculate an activity index number of each mb |
298 calc_activity_index(cpi, x); | 290 calc_activity_index(cpi, x); |
299 #endif | 291 #endif |
300 | 292 |
301 } | 293 } |
302 | 294 |
303 // Macroblock activity masking | 295 // Macroblock activity masking |
304 void vp9_activity_masking(VP9_COMP *cpi, MACROBLOCK *x) { | 296 void vp9_activity_masking(VP9_COMP *cpi, MACROBLOCK *x) { |
305 #if USE_ACT_INDEX | 297 #if USE_ACT_INDEX |
306 x->rdmult += *(x->mb_activity_ptr) * (x->rdmult >> 2); | 298 x->rdmult += *(x->mb_activity_ptr) * (x->rdmult >> 2); |
307 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); | 299 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); |
308 x->errorperbit += (x->errorperbit == 0); | 300 x->errorperbit += (x->errorperbit == 0); |
309 #else | 301 #else |
310 int64_t a; | 302 int64_t a; |
311 int64_t b; | 303 int64_t b; |
312 int64_t act = *(x->mb_activity_ptr); | 304 int64_t act = *(x->mb_activity_ptr); |
313 | 305 |
314 // Apply the masking to the RD multiplier. | 306 // Apply the masking to the RD multiplier. |
315 a = act + (2 * cpi->activity_avg); | 307 a = act + (2 * cpi->activity_avg); |
316 b = (2 * act) + cpi->activity_avg; | 308 b = (2 * act) + cpi->activity_avg; |
317 | 309 |
318 x->rdmult = (unsigned int)(((int64_t)x->rdmult * b + (a >> 1)) / a); | 310 x->rdmult = (unsigned int) (((int64_t) x->rdmult * b + (a >> 1)) / a); |
319 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); | 311 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); |
320 x->errorperbit += (x->errorperbit == 0); | 312 x->errorperbit += (x->errorperbit == 0); |
321 #endif | 313 #endif |
322 | 314 |
323 // Activity based Zbin adjustment | 315 // Activity based Zbin adjustment |
324 adjust_act_zbin(cpi, x); | 316 adjust_act_zbin(cpi, x); |
325 } | 317 } |
326 | 318 |
327 static void update_state(VP9_COMP *cpi, | 319 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
328 PICK_MODE_CONTEXT *ctx, | 320 BLOCK_SIZE_TYPE bsize, int output_enabled) { |
329 BLOCK_SIZE_TYPE bsize, | |
330 int output_enabled) { | |
331 int i, x_idx, y; | 321 int i, x_idx, y; |
332 MACROBLOCK *const x = &cpi->mb; | 322 MACROBLOCK * const x = &cpi->mb; |
333 MACROBLOCKD *const xd = &x->e_mbd; | 323 MACROBLOCKD * const xd = &x->e_mbd; |
334 MODE_INFO *mi = &ctx->mic; | 324 MODE_INFO *mi = &ctx->mic; |
335 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; | 325 MB_MODE_INFO * const mbmi = &xd->mode_info_context->mbmi; |
336 #if CONFIG_DEBUG || CONFIG_INTERNAL_STATS | 326 #if CONFIG_DEBUG || CONFIG_INTERNAL_STATS |
337 MB_PREDICTION_MODE mb_mode = mi->mbmi.mode; | 327 MB_PREDICTION_MODE mb_mode = mi->mbmi.mode; |
338 #endif | 328 #endif |
339 int mb_mode_index = ctx->best_mode_index; | 329 int mb_mode_index = ctx->best_mode_index; |
340 const int mis = cpi->common.mode_info_stride; | 330 const int mis = cpi->common.mode_info_stride; |
341 const int bh = 1 << mi_height_log2(bsize), bw = 1 << mi_width_log2(bsize); | 331 const int bh = 1 << mi_height_log2(bsize), bw = 1 << mi_width_log2(bsize); |
342 | 332 |
343 #if CONFIG_DEBUG | 333 #if CONFIG_DEBUG |
344 assert(mb_mode < MB_MODE_COUNT); | 334 assert(mb_mode < MB_MODE_COUNT); |
345 assert(mb_mode_index < MAX_MODES); | 335 assert(mb_mode_index < MAX_MODES); |
346 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); | 336 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); |
347 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); | 337 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); |
348 #endif | 338 #endif |
349 | 339 |
350 assert(mi->mbmi.sb_type == bsize); | 340 assert(mi->mbmi.sb_type == bsize); |
351 // Restore the coding context of the MB to that that was in place | 341 // Restore the coding context of the MB to that that was in place |
352 // when the mode was picked for it | 342 // when the mode was picked for it |
353 for (y = 0; y < bh; y++) { | 343 for (y = 0; y < bh; y++) { |
354 for (x_idx = 0; x_idx < bw; x_idx++) { | 344 for (x_idx = 0; x_idx < bw; x_idx++) { |
355 if ((xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE)) + bw > x_idx && | 345 if ((xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE)) + bw > x_idx |
356 (xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE)) + bh > y) { | 346 && (xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE)) + bh > y) { |
357 MODE_INFO *mi_addr = xd->mode_info_context + x_idx + y * mis; | 347 MODE_INFO *mi_addr = xd->mode_info_context + x_idx + y * mis; |
358 *mi_addr = *mi; | 348 *mi_addr = *mi; |
359 } | 349 } |
360 } | 350 } |
361 } | 351 } |
362 if (bsize < BLOCK_SIZE_SB32X32) { | 352 if (bsize < BLOCK_SIZE_SB32X32) { |
363 if (bsize < BLOCK_SIZE_MB16X16) | 353 if (bsize < BLOCK_SIZE_MB16X16) |
364 ctx->txfm_rd_diff[ALLOW_16X16] = ctx->txfm_rd_diff[ALLOW_8X8]; | 354 ctx->txfm_rd_diff[ALLOW_16X16] = ctx->txfm_rd_diff[ALLOW_8X8]; |
365 ctx->txfm_rd_diff[ALLOW_32X32] = ctx->txfm_rd_diff[ALLOW_16X16]; | 355 ctx->txfm_rd_diff[ALLOW_32X32] = ctx->txfm_rd_diff[ALLOW_16X16]; |
366 } | 356 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 THR_D153_PRED /*D153_PRED*/, | 391 THR_D153_PRED /*D153_PRED*/, |
402 THR_D27_PRED /*D27_PRED*/, | 392 THR_D27_PRED /*D27_PRED*/, |
403 THR_D63_PRED /*D63_PRED*/, | 393 THR_D63_PRED /*D63_PRED*/, |
404 THR_TM /*TM_PRED*/, | 394 THR_TM /*TM_PRED*/, |
405 THR_B_PRED /*I4X4_PRED*/, | 395 THR_B_PRED /*I4X4_PRED*/, |
406 }; | 396 }; |
407 cpi->mode_chosen_counts[kf_mode_index[mb_mode]]++; | 397 cpi->mode_chosen_counts[kf_mode_index[mb_mode]]++; |
408 #endif | 398 #endif |
409 } else { | 399 } else { |
410 /* | 400 /* |
411 // Reduce the activation RD thresholds for the best choice mode | 401 // Reduce the activation RD thresholds for the best choice mode |
412 if ((cpi->rd_baseline_thresh[mb_mode_index] > 0) && | 402 if ((cpi->rd_baseline_thresh[mb_mode_index] > 0) && |
413 (cpi->rd_baseline_thresh[mb_mode_index] < (INT_MAX >> 2))) | 403 (cpi->rd_baseline_thresh[mb_mode_index] < (INT_MAX >> 2))) |
414 { | 404 { |
415 int best_adjustment = (cpi->rd_thresh_mult[mb_mode_index] >> 2); | 405 int best_adjustment = (cpi->rd_thresh_mult[mb_mode_index] >> 2); |
416 | 406 |
417 cpi->rd_thresh_mult[mb_mode_index] = | 407 cpi->rd_thresh_mult[mb_mode_index] = |
418 (cpi->rd_thresh_mult[mb_mode_index] | 408 (cpi->rd_thresh_mult[mb_mode_index] |
419 >= (MIN_THRESHMULT + best_adjustment)) ? | 409 >= (MIN_THRESHMULT + best_adjustment)) ? |
420 cpi->rd_thresh_mult[mb_mode_index] - best_adjust
ment : | 410 cpi->rd_thresh_mult[mb_mode_index] - best_adjustment : |
421 MIN_THRESHMULT; | 411 MIN_THRESHMULT; |
422 cpi->rd_threshes[mb_mode_index] = | 412 cpi->rd_threshes[mb_mode_index] = |
423 (cpi->rd_baseline_thresh[mb_mode_index] >> 7) | 413 (cpi->rd_baseline_thresh[mb_mode_index] >> 7) |
424 * cpi->rd_thresh_mult[mb_mode_index]; | 414 * cpi->rd_thresh_mult[mb_mode_index]; |
425 | 415 |
426 } | 416 } |
427 */ | 417 */ |
428 // Note how often each mode chosen as best | 418 // Note how often each mode chosen as best |
429 cpi->mode_chosen_counts[mb_mode_index]++; | 419 cpi->mode_chosen_counts[mb_mode_index]++; |
430 if (mbmi->ref_frame[0] != INTRA_FRAME && | 420 if (mbmi->ref_frame[0] != INTRA_FRAME |
431 (mbmi->sb_type < BLOCK_SIZE_SB8X8 || mbmi->mode == NEWMV)) { | 421 && (mbmi->sb_type < BLOCK_SIZE_SB8X8 || mbmi->mode == NEWMV)) { |
432 int_mv best_mv, best_second_mv; | 422 int_mv best_mv, best_second_mv; |
433 const MV_REFERENCE_FRAME rf1 = mbmi->ref_frame[0]; | 423 const MV_REFERENCE_FRAME rf1 = mbmi->ref_frame[0]; |
434 const MV_REFERENCE_FRAME rf2 = mbmi->ref_frame[1]; | 424 const MV_REFERENCE_FRAME rf2 = mbmi->ref_frame[1]; |
435 best_mv.as_int = ctx->best_ref_mv.as_int; | 425 best_mv.as_int = ctx->best_ref_mv.as_int; |
436 best_second_mv.as_int = ctx->second_best_ref_mv.as_int; | 426 best_second_mv.as_int = ctx->second_best_ref_mv.as_int; |
437 if (mbmi->mode == NEWMV) { | 427 if (mbmi->mode == NEWMV) { |
438 best_mv.as_int = mbmi->ref_mvs[rf1][0].as_int; | 428 best_mv.as_int = mbmi->ref_mvs[rf1][0].as_int; |
439 best_second_mv.as_int = mbmi->ref_mvs[rf2][0].as_int; | 429 best_second_mv.as_int = mbmi->ref_mvs[rf2][0].as_int; |
440 } | 430 } |
441 mbmi->best_mv.as_int = best_mv.as_int; | 431 mbmi->best_mv.as_int = best_mv.as_int; |
442 mbmi->best_second_mv.as_int = best_second_mv.as_int; | 432 mbmi->best_second_mv.as_int = best_second_mv.as_int; |
443 vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv); | 433 vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv); |
444 } | 434 } |
445 | 435 |
446 if (bsize > BLOCK_SIZE_SB8X8 && mbmi->mode == NEWMV) { | 436 if (bsize > BLOCK_SIZE_SB8X8 && mbmi->mode == NEWMV) { |
447 int i, j; | 437 int i, j; |
448 for (j = 0; j < bh; ++j) | 438 for (j = 0; j < bh; ++j) |
449 for (i = 0; i < bw; ++i) | 439 for (i = 0; i < bw; ++i) |
450 if ((xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE)) + bw > i && | 440 if ((xd->mb_to_right_edge >> (3 + LOG2_MI_SIZE)) + bw > i |
451 (xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE)) + bh > j) | 441 && (xd->mb_to_bottom_edge >> (3 + LOG2_MI_SIZE)) + bh > j) |
452 xd->mode_info_context[mis * j + i].mbmi = *mbmi; | 442 xd->mode_info_context[mis * j + i].mbmi = *mbmi; |
453 } | 443 } |
454 | 444 |
455 if (cpi->common.mcomp_filter_type == SWITCHABLE && | 445 if (cpi->common.mcomp_filter_type == SWITCHABLE |
456 is_inter_mode(mbmi->mode)) { | 446 && is_inter_mode(mbmi->mode)) { |
457 ++cpi->common.fc.switchable_interp_count | 447 ++cpi->common.fc.switchable_interp_count[vp9_get_pred_context( |
458 [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)] | 448 &cpi->common, xd, PRED_SWITCHABLE_INTERP)][vp9_switchable_interp_map[m
bmi |
459 [vp9_switchable_interp_map[mbmi->interp_filter]]; | 449 ->interp_filter]]; |
460 } | 450 } |
461 | 451 |
462 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; | 452 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; |
463 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; | 453 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; |
464 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; | 454 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; |
465 } | 455 } |
466 } | 456 } |
467 | 457 |
468 static unsigned find_seg_id(VP9_COMMON *cm, uint8_t *buf, BLOCK_SIZE_TYPE bsize, | 458 static unsigned find_seg_id(VP9_COMMON *cm, uint8_t *buf, BLOCK_SIZE_TYPE bsize, |
469 int start_y, int height, int start_x, int width) { | 459 int start_y, int height, int start_x, int width) { |
470 const int bw = 1 << mi_width_log2(bsize), bh = 1 << mi_height_log2(bsize); | 460 const int bw = 1 << mi_width_log2(bsize), bh = 1 << mi_height_log2(bsize); |
471 const int end_x = MIN(start_x + bw, width); | 461 const int end_x = MIN(start_x + bw, width); |
472 const int end_y = MIN(start_y + bh, height); | 462 const int end_y = MIN(start_y + bh, height); |
473 int x, y; | 463 int x, y; |
474 unsigned seg_id = -1; | 464 unsigned seg_id = -1; |
475 | 465 |
476 buf += width * start_y; | 466 buf += width * start_y; |
477 assert(start_y < cm->mi_rows && start_x < cm->cur_tile_mi_col_end); | 467 assert(start_y < cm->mi_rows && start_x < cm->cur_tile_mi_col_end); |
478 for (y = start_y; y < end_y; y++, buf += width) { | 468 for (y = start_y; y < end_y; y++, buf += width) { |
479 for (x = start_x; x < end_x; x++) { | 469 for (x = start_x; x < end_x; x++) { |
480 seg_id = MIN(seg_id, buf[x]); | 470 seg_id = MIN(seg_id, buf[x]); |
481 } | 471 } |
482 } | 472 } |
483 | 473 |
484 return seg_id; | 474 return seg_id; |
485 } | 475 } |
486 | 476 |
487 void vp9_setup_src_planes(MACROBLOCK *x, | 477 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, |
488 const YV12_BUFFER_CONFIG *src, | |
489 int mb_row, int mb_col) { | 478 int mb_row, int mb_col) { |
490 uint8_t *buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, | 479 uint8_t *buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, src |
491 src->alpha_buffer}; | 480 ->alpha_buffer}; |
492 int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, | 481 int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, src |
493 src->alpha_stride}; | 482 ->alpha_stride}; |
494 int i; | 483 int i; |
495 | 484 |
496 for (i = 0; i < MAX_MB_PLANE; i++) { | 485 for (i = 0; i < MAX_MB_PLANE; i++) { |
497 setup_pred_plane(&x->plane[i].src, | 486 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mb_row, mb_col, |
498 buffers[i], strides[i], | 487 NULL, x->e_mbd.plane[i].subsampling_x, |
499 mb_row, mb_col, NULL, | |
500 x->e_mbd.plane[i].subsampling_x, | |
501 x->e_mbd.plane[i].subsampling_y); | 488 x->e_mbd.plane[i].subsampling_y); |
502 } | 489 } |
503 } | 490 } |
504 | 491 |
505 static void set_offsets(VP9_COMP *cpi, | 492 static void set_offsets(VP9_COMP *cpi, int mi_row, int mi_col, |
506 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize) { | 493 BLOCK_SIZE_TYPE bsize) { |
507 MACROBLOCK *const x = &cpi->mb; | 494 MACROBLOCK * const x = &cpi->mb; |
508 VP9_COMMON *const cm = &cpi->common; | 495 VP9_COMMON * const cm = &cpi->common; |
509 MACROBLOCKD *const xd = &x->e_mbd; | 496 MACROBLOCKD * const xd = &x->e_mbd; |
510 MB_MODE_INFO *mbmi; | 497 MB_MODE_INFO *mbmi; |
511 const int dst_fb_idx = cm->new_fb_idx; | 498 const int dst_fb_idx = cm->new_fb_idx; |
512 const int idx_str = xd->mode_info_stride * mi_row + mi_col; | 499 const int idx_str = xd->mode_info_stride * mi_row + mi_col; |
513 const int bw = 1 << mi_width_log2(bsize), bh = 1 << mi_height_log2(bsize); | 500 const int bw = 1 << mi_width_log2(bsize), bh = 1 << mi_height_log2(bsize); |
514 const int mb_row = mi_row >> 1; | 501 const int mb_row = mi_row >> 1; |
515 const int mb_col = mi_col >> 1; | 502 const int mb_col = mi_col >> 1; |
516 const int idx_map = mb_row * cm->mb_cols + mb_col; | 503 const int idx_map = mb_row * cm->mb_cols + mb_col; |
517 int i; | 504 int i; |
518 | 505 |
519 // entropy context structures | 506 // entropy context structures |
520 for (i = 0; i < MAX_MB_PLANE; i++) { | 507 for (i = 0; i < MAX_MB_PLANE; i++) { |
521 xd->plane[i].above_context = cm->above_context[i] + | 508 xd->plane[i].above_context = cm->above_context[i] |
522 (mi_col * 2 >> xd->plane[i].subsampling_x); | 509 + (mi_col * 2 >> xd->plane[i].subsampling_x); |
523 xd->plane[i].left_context = cm->left_context[i] + | 510 xd->plane[i].left_context = cm->left_context[i] |
524 (((mi_row * 2) & 15) >> xd->plane[i].subsampling_y); | 511 + (((mi_row * 2) & 15) >> xd->plane[i].subsampling_y); |
525 } | 512 } |
526 | 513 |
527 // partition contexts | 514 // partition contexts |
528 set_partition_seg_context(cm, xd, mi_row, mi_col); | 515 set_partition_seg_context(cm, xd, mi_row, mi_col); |
529 | 516 |
530 // Activity map pointer | 517 // Activity map pointer |
531 x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; | 518 x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; |
532 x->active_ptr = cpi->active_map + idx_map; | 519 x->active_ptr = cpi->active_map + idx_map; |
533 | 520 |
534 /* pointers to mode info contexts */ | 521 /* pointers to mode info contexts */ |
535 x->partition_info = x->pi + idx_str; | 522 x->partition_info = x->pi + idx_str; |
536 xd->mode_info_context = cm->mi + idx_str; | 523 xd->mode_info_context = cm->mi + idx_str; |
537 mbmi = &xd->mode_info_context->mbmi; | 524 mbmi = &xd->mode_info_context->mbmi; |
538 // Special case: if prev_mi is NULL, the previous mode info context | 525 // Special case: if prev_mi is NULL, the previous mode info context |
539 // cannot be used. | 526 // cannot be used. |
540 xd->prev_mode_info_context = cm->prev_mi ? | 527 xd->prev_mode_info_context = cm->prev_mi ? cm->prev_mi + idx_str : NULL; |
541 cm->prev_mi + idx_str : NULL; | |
542 | 528 |
543 // Set up destination pointers | 529 // Set up destination pointers |
544 setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col); | 530 setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col); |
545 | 531 |
546 /* Set up limit values for MV components to prevent them from | 532 /* Set up limit values for MV components to prevent them from |
547 * extending beyond the UMV borders assuming 16x16 block size */ | 533 * extending beyond the UMV borders assuming 16x16 block size */ |
548 x->mv_row_min = -((mi_row * MI_SIZE) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | 534 x->mv_row_min = -((mi_row * MI_SIZE)+ VP9BORDERINPIXELS - VP9_INTERP_EXTEND); |
549 x->mv_col_min = -((mi_col * MI_SIZE) + VP9BORDERINPIXELS - VP9_INTERP_EXTEND); | 535 x->mv_col_min = -((mi_col * MI_SIZE)+ VP9BORDERINPIXELS - VP9_INTERP_EXTEND); |
550 x->mv_row_max = ((cm->mi_rows - mi_row) * MI_SIZE + | 536 x->mv_row_max = ((cm->mi_rows - mi_row) * MI_SIZE |
551 (VP9BORDERINPIXELS - MI_SIZE * bh - VP9_INTERP_EXTEND)); | 537 + (VP9BORDERINPIXELS - MI_SIZE * bh - VP9_INTERP_EXTEND)); |
552 x->mv_col_max = ((cm->mi_cols - mi_col) * MI_SIZE + | 538 x->mv_col_max = ((cm->mi_cols - mi_col) * MI_SIZE |
553 (VP9BORDERINPIXELS - MI_SIZE * bw - VP9_INTERP_EXTEND)); | 539 + (VP9BORDERINPIXELS - MI_SIZE * bw - VP9_INTERP_EXTEND)); |
554 | 540 |
555 // Set up distance of MB to edge of frame in 1/8th pel units | 541 // Set up distance of MB to edge of frame in 1/8th pel units |
556 assert(!(mi_col & (bw - 1)) && !(mi_row & (bh - 1))); | 542 assert(!(mi_col & (bw - 1)) && !(mi_row & (bh - 1))); |
557 set_mi_row_col(cm, xd, mi_row, bh, mi_col, bw); | 543 set_mi_row_col(cm, xd, mi_row, bh, mi_col, bw); |
558 | 544 |
559 /* set up source buffers */ | 545 /* set up source buffers */ |
560 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); | 546 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); |
561 | 547 |
562 /* R/D setup */ | 548 /* R/D setup */ |
563 x->rddiv = cpi->RDDIV; | 549 x->rddiv = cpi->RDDIV; |
564 x->rdmult = cpi->RDMULT; | 550 x->rdmult = cpi->RDMULT; |
565 | 551 |
566 /* segment ID */ | 552 /* segment ID */ |
567 if (xd->segmentation_enabled) { | 553 if (xd->segmentation_enabled) { |
568 uint8_t *map = xd->update_mb_segmentation_map ? cpi->segmentation_map | 554 uint8_t *map = |
569 : cm->last_frame_seg_map; | 555 xd->update_mb_segmentation_map ? |
570 mbmi->segment_id = find_seg_id(cm, map, bsize, mi_row, | 556 cpi->segmentation_map : cm->last_frame_seg_map; |
571 cm->mi_rows, mi_col, cm->mi_cols); | 557 mbmi->segment_id = find_seg_id(cm, map, bsize, mi_row, cm->mi_rows, mi_col, |
| 558 cm->mi_cols); |
572 | 559 |
573 assert(mbmi->segment_id <= (MAX_MB_SEGMENTS-1)); | 560 assert(mbmi->segment_id <= (MAX_MB_SEGMENTS-1)); |
574 vp9_mb_init_quantizer(cpi, x); | 561 vp9_mb_init_quantizer(cpi, x); |
575 | 562 |
576 if (xd->segmentation_enabled && cpi->seg0_cnt > 0 && | 563 if (xd->segmentation_enabled && cpi->seg0_cnt > 0 |
577 !vp9_segfeature_active(xd, 0, SEG_LVL_REF_FRAME) && | 564 && !vp9_segfeature_active(xd, 0, SEG_LVL_REF_FRAME) |
578 vp9_segfeature_active(xd, 1, SEG_LVL_REF_FRAME)) { | 565 && vp9_segfeature_active(xd, 1, SEG_LVL_REF_FRAME)) { |
579 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; | 566 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; |
580 } else { | 567 } else { |
581 const int y = mb_row & ~3; | 568 const int y = mb_row & ~3; |
582 const int x = mb_col & ~3; | 569 const int x = mb_col & ~3; |
583 const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); | 570 const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); |
584 const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); | 571 const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); |
585 const int tile_progress = | 572 const int tile_progress = cm->cur_tile_mi_col_start * cm->mb_rows >> 1; |
586 cm->cur_tile_mi_col_start * cm->mb_rows >> 1; | 573 const int mb_cols = (cm->cur_tile_mi_col_end - cm->cur_tile_mi_col_start) |
587 const int mb_cols = | 574 >> 1; |
588 (cm->cur_tile_mi_col_end - cm->cur_tile_mi_col_start) >> 1; | |
589 | 575 |
590 cpi->seg0_progress = | 576 cpi->seg0_progress = ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) |
591 ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) << 16) / cm->MBs; | 577 << 16) / cm->MBs; |
592 } | 578 } |
593 } else { | 579 } else { |
594 mbmi->segment_id = 0; | 580 mbmi->segment_id = 0; |
595 } | 581 } |
596 } | 582 } |
597 | 583 |
598 static void pick_sb_modes(VP9_COMP *cpi, int mi_row, int mi_col, | 584 static void pick_sb_modes(VP9_COMP *cpi, int mi_row, int mi_col, |
599 TOKENEXTRA **tp, int *totalrate, int *totaldist, | 585 TOKENEXTRA **tp, int *totalrate, int *totaldist, |
600 BLOCK_SIZE_TYPE bsize, PICK_MODE_CONTEXT *ctx) { | 586 BLOCK_SIZE_TYPE bsize, PICK_MODE_CONTEXT *ctx) { |
601 VP9_COMMON *const cm = &cpi->common; | 587 VP9_COMMON * const cm = &cpi->common; |
602 MACROBLOCK *const x = &cpi->mb; | 588 MACROBLOCK * const x = &cpi->mb; |
603 MACROBLOCKD *const xd = &x->e_mbd; | 589 MACROBLOCKD * const xd = &x->e_mbd; |
604 | 590 |
605 x->rd_search = 1; | 591 x->rd_search = 1; |
606 | 592 |
607 if (bsize < BLOCK_SIZE_SB8X8) | 593 if (bsize < BLOCK_SIZE_SB8X8) |
608 if (xd->ab_index != 0) | 594 if (xd->ab_index != 0) |
609 return; | 595 return; |
610 | 596 |
611 set_offsets(cpi, mi_row, mi_col, bsize); | 597 set_offsets(cpi, mi_row, mi_col, bsize); |
612 xd->mode_info_context->mbmi.sb_type = bsize; | 598 xd->mode_info_context->mbmi.sb_type = bsize; |
613 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) | 599 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
614 vp9_activity_masking(cpi, x); | 600 vp9_activity_masking(cpi, x); |
615 | 601 |
616 /* Find best coding mode & reconstruct the MB so it is available | 602 /* Find best coding mode & reconstruct the MB so it is available |
617 * as a predictor for MBs that follow in the SB */ | 603 * as a predictor for MBs that follow in the SB */ |
618 if (cm->frame_type == KEY_FRAME) { | 604 if (cm->frame_type == KEY_FRAME) { |
619 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx); | 605 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx); |
620 } else { | 606 } else { |
621 vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist, | 607 vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist, |
622 bsize, ctx); | 608 bsize, ctx); |
623 } | 609 } |
624 } | 610 } |
625 | 611 |
626 static void update_stats(VP9_COMP *cpi, int mi_row, int mi_col) { | 612 static void update_stats(VP9_COMP *cpi, int mi_row, int mi_col) { |
627 VP9_COMMON *const cm = &cpi->common; | 613 VP9_COMMON * const cm = &cpi->common; |
628 MACROBLOCK *const x = &cpi->mb; | 614 MACROBLOCK * const x = &cpi->mb; |
629 MACROBLOCKD *const xd = &x->e_mbd; | 615 MACROBLOCKD * const xd = &x->e_mbd; |
630 MODE_INFO *mi = xd->mode_info_context; | 616 MODE_INFO *mi = xd->mode_info_context; |
631 MB_MODE_INFO *const mbmi = &mi->mbmi; | 617 MB_MODE_INFO * const mbmi = &mi->mbmi; |
632 | 618 |
633 if (cm->frame_type != KEY_FRAME) { | 619 if (cm->frame_type != KEY_FRAME) { |
634 int segment_id, seg_ref_active; | 620 int segment_id, seg_ref_active; |
635 | 621 |
636 segment_id = mbmi->segment_id; | 622 segment_id = mbmi->segment_id; |
637 seg_ref_active = vp9_segfeature_active(xd, segment_id, | 623 seg_ref_active = vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME); |
638 SEG_LVL_REF_FRAME); | |
639 | 624 |
640 if (!seg_ref_active) | 625 if (!seg_ref_active) |
641 cpi->intra_inter_count[vp9_get_pred_context(cm, xd, PRED_INTRA_INTER)] | 626 cpi->intra_inter_count[vp9_get_pred_context(cm, xd, PRED_INTRA_INTER)][mbm
i |
642 [mbmi->ref_frame[0] > INTRA_FRAME]++; | 627 ->ref_frame[0] > INTRA_FRAME]++; |
643 | 628 |
644 // If the segment reference feature is enabled we have only a single | 629 // If the segment reference feature is enabled we have only a single |
645 // reference frame allowed for the segment so exclude it from | 630 // reference frame allowed for the segment so exclude it from |
646 // the reference frame counts used to work out probabilities. | 631 // the reference frame counts used to work out probabilities. |
647 if ((mbmi->ref_frame[0] > INTRA_FRAME) && !seg_ref_active) { | 632 if ((mbmi->ref_frame[0] > INTRA_FRAME) && !seg_ref_active) { |
648 if (cm->comp_pred_mode == HYBRID_PREDICTION) | 633 if (cm->comp_pred_mode == HYBRID_PREDICTION) |
649 cpi->comp_inter_count[vp9_get_pred_context(cm, xd, | 634 cpi->comp_inter_count[vp9_get_pred_context(cm, xd, |
650 PRED_COMP_INTER_INTER)] | 635 PRED_COMP_INTER_INTER)][mbmi |
651 [mbmi->ref_frame[1] > INTRA_FRAME]++; | 636 ->ref_frame[1] > INTRA_FRAME]++; |
652 | 637 |
653 if (mbmi->ref_frame[1] > INTRA_FRAME) { | 638 if (mbmi->ref_frame[1] > INTRA_FRAME) { |
654 cpi->comp_ref_count[vp9_get_pred_context(cm, xd, PRED_COMP_REF_P)] | 639 cpi->comp_ref_count[vp9_get_pred_context(cm, xd, PRED_COMP_REF_P)][mbmi |
655 [mbmi->ref_frame[0] == GOLDEN_FRAME]++; | 640 ->ref_frame[0] == GOLDEN_FRAME]++; |
656 } else { | 641 } else { |
657 cpi->single_ref_count[vp9_get_pred_context(cm, xd, PRED_SINGLE_REF_P1)] | 642 cpi->single_ref_count[vp9_get_pred_context(cm, xd, PRED_SINGLE_REF_P1)][
0][mbmi |
658 [0][mbmi->ref_frame[0] != LAST_FRAME]++; | 643 ->ref_frame[0] != LAST_FRAME]++; |
659 if (mbmi->ref_frame[0] != LAST_FRAME) | 644 if (mbmi->ref_frame[0] != LAST_FRAME) |
660 cpi->single_ref_count[vp9_get_pred_context(cm, xd, | 645 cpi->single_ref_count[vp9_get_pred_context(cm, xd, PRED_SINGLE_REF_P2)
][1][mbmi |
661 PRED_SINGLE_REF_P2)] | 646 ->ref_frame[0] != GOLDEN_FRAME]++; |
662 [1][mbmi->ref_frame[0] != GOLDEN_FRAME]++; | |
663 } | 647 } |
664 } | 648 } |
665 // Count of last ref frame 0,0 usage | 649 // Count of last ref frame 0,0 usage |
666 if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame[0] == LAST_FRAME)) | 650 if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame[0] == LAST_FRAME)) |
667 cpi->inter_zz_count++; | 651 cpi->inter_zz_count++; |
668 } | 652 } |
669 } | 653 } |
670 | 654 |
671 // TODO(jingning): the variables used here are little complicated. need further | 655 // TODO(jingning): the variables used here are little complicated. need further |
672 // refactoring on organizing the the temporary buffers, when recursive | 656 // refactoring on organizing the the temporary buffers, when recursive |
673 // partition down to 4x4 block size is enabled. | 657 // partition down to 4x4 block size is enabled. |
674 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, | 658 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, |
675 BLOCK_SIZE_TYPE bsize) { | 659 BLOCK_SIZE_TYPE bsize) { |
676 MACROBLOCKD *const xd = &x->e_mbd; | 660 MACROBLOCKD * const xd = &x->e_mbd; |
677 | 661 |
678 switch (bsize) { | 662 switch (bsize) { |
679 case BLOCK_SIZE_SB64X64: | 663 case BLOCK_SIZE_SB64X64: |
680 return &x->sb64_context; | 664 return &x->sb64_context; |
681 case BLOCK_SIZE_SB64X32: | 665 case BLOCK_SIZE_SB64X32: |
682 return &x->sb64x32_context[xd->sb_index]; | 666 return &x->sb64x32_context[xd->sb_index]; |
683 case BLOCK_SIZE_SB32X64: | 667 case BLOCK_SIZE_SB32X64: |
684 return &x->sb32x64_context[xd->sb_index]; | 668 return &x->sb32x64_context[xd->sb_index]; |
685 case BLOCK_SIZE_SB32X32: | 669 case BLOCK_SIZE_SB32X32: |
686 return &x->sb32_context[xd->sb_index]; | 670 return &x->sb32_context[xd->sb_index]; |
(...skipping 10 matching lines...) Expand all Loading... |
697 case BLOCK_SIZE_SB8X8: | 681 case BLOCK_SIZE_SB8X8: |
698 return &x->sb8x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 682 return &x->sb8x8_context[xd->sb_index][xd->mb_index][xd->b_index]; |
699 case BLOCK_SIZE_SB8X4: | 683 case BLOCK_SIZE_SB8X4: |
700 return &x->sb8x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | 684 return &x->sb8x4_context[xd->sb_index][xd->mb_index][xd->b_index]; |
701 case BLOCK_SIZE_SB4X8: | 685 case BLOCK_SIZE_SB4X8: |
702 return &x->sb4x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | 686 return &x->sb4x8_context[xd->sb_index][xd->mb_index][xd->b_index]; |
703 case BLOCK_SIZE_AB4X4: | 687 case BLOCK_SIZE_AB4X4: |
704 return &x->ab4x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | 688 return &x->ab4x4_context[xd->sb_index][xd->mb_index][xd->b_index]; |
705 default: | 689 default: |
706 assert(0); | 690 assert(0); |
707 return NULL; | 691 return NULL ; |
708 } | 692 } |
709 } | 693 } |
710 | 694 |
711 static BLOCK_SIZE_TYPE *get_sb_partitioning(MACROBLOCK *x, | 695 static BLOCK_SIZE_TYPE *get_sb_partitioning(MACROBLOCK *x, |
712 BLOCK_SIZE_TYPE bsize) { | 696 BLOCK_SIZE_TYPE bsize) { |
713 MACROBLOCKD *xd = &x->e_mbd; | 697 MACROBLOCKD *xd = &x->e_mbd; |
714 switch (bsize) { | 698 switch (bsize) { |
715 case BLOCK_SIZE_SB64X64: | 699 case BLOCK_SIZE_SB64X64: |
716 return &x->sb64_partitioning; | 700 return &x->sb64_partitioning; |
717 case BLOCK_SIZE_SB32X32: | 701 case BLOCK_SIZE_SB32X32: |
718 return &x->sb_partitioning[xd->sb_index]; | 702 return &x->sb_partitioning[xd->sb_index]; |
719 case BLOCK_SIZE_MB16X16: | 703 case BLOCK_SIZE_MB16X16: |
720 return &x->mb_partitioning[xd->sb_index][xd->mb_index]; | 704 return &x->mb_partitioning[xd->sb_index][xd->mb_index]; |
721 case BLOCK_SIZE_SB8X8: | 705 case BLOCK_SIZE_SB8X8: |
722 return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; | 706 return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; |
723 default: | 707 default: |
724 assert(0); | 708 assert(0); |
725 return NULL; | 709 return NULL ; |
726 } | 710 } |
727 } | 711 } |
728 | 712 |
729 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, | 713 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, |
730 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 714 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
731 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 715 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
732 PARTITION_CONTEXT sa[8], | 716 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
733 PARTITION_CONTEXT sl[8], | |
734 BLOCK_SIZE_TYPE bsize) { | 717 BLOCK_SIZE_TYPE bsize) { |
735 VP9_COMMON *const cm = &cpi->common; | 718 VP9_COMMON * const cm = &cpi->common; |
736 MACROBLOCK *const x = &cpi->mb; | 719 MACROBLOCK * const x = &cpi->mb; |
737 MACROBLOCKD *const xd = &x->e_mbd; | 720 MACROBLOCKD * const xd = &x->e_mbd; |
738 int p; | 721 int p; |
739 int bwl = b_width_log2(bsize), bw = 1 << bwl; | 722 int bwl = b_width_log2(bsize), bw = 1 << bwl; |
740 int bhl = b_height_log2(bsize), bh = 1 << bhl; | 723 int bhl = b_height_log2(bsize), bh = 1 << bhl; |
741 int mwl = mi_width_log2(bsize), mw = 1 << mwl; | 724 int mwl = mi_width_log2(bsize), mw = 1 << mwl; |
742 int mhl = mi_height_log2(bsize), mh = 1 << mhl; | 725 int mhl = mi_height_log2(bsize), mh = 1 << mhl; |
743 for (p = 0; p < MAX_MB_PLANE; p++) { | 726 for (p = 0; p < MAX_MB_PLANE; p++) { |
744 vpx_memcpy(cm->above_context[p] + | 727 vpx_memcpy( |
745 ((mi_col * 2) >> xd->plane[p].subsampling_x), | 728 cm->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x), |
746 a + bw * p, | 729 a + bw * p, sizeof(ENTROPY_CONTEXT) * bw >> xd->plane[p].subsampling_x); |
747 sizeof(ENTROPY_CONTEXT) * bw >> xd->plane[p].subsampling_x); | 730 vpx_memcpy( |
748 vpx_memcpy(cm->left_context[p] + | 731 cm->left_context[p] |
749 ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), | 732 + ((mi_row & MI_MASK)* 2 >> xd->plane[p].subsampling_y),l + bh * p, |
750 l + bh * p, | 733 sizeof(ENTROPY_CONTEXT) * bh >> xd->plane[p].subsampling_y); |
751 sizeof(ENTROPY_CONTEXT) * bh >> xd->plane[p].subsampling_y); | 734 } |
752 } | |
753 vpx_memcpy(cm->above_seg_context + mi_col, sa, | 735 vpx_memcpy(cm->above_seg_context + mi_col, sa, |
754 sizeof(PARTITION_CONTEXT) * mw); | 736 sizeof(PARTITION_CONTEXT) * mw); |
755 vpx_memcpy(cm->left_seg_context + (mi_row & MI_MASK), sl, | 737 vpx_memcpy(cm->left_seg_context + (mi_row & MI_MASK), sl, |
756 sizeof(PARTITION_CONTEXT) * mh); | 738 sizeof(PARTITION_CONTEXT) * mh) |
757 } | 739 ;} |
758 static void save_context(VP9_COMP *cpi, int mi_row, int mi_col, | 740 static void save_context(VP9_COMP *cpi, int mi_row, int mi_col, |
759 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 741 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
760 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 742 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
761 PARTITION_CONTEXT sa[8], | 743 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
762 PARTITION_CONTEXT sl[8], | 744 BLOCK_SIZE_TYPE bsize) { |
763 BLOCK_SIZE_TYPE bsize) { | 745 VP9_COMMON * const cm = &cpi->common; |
764 VP9_COMMON *const cm = &cpi->common; | 746 MACROBLOCK * const x = &cpi->mb; |
765 MACROBLOCK *const x = &cpi->mb; | 747 MACROBLOCKD * const xd = &x->e_mbd; |
766 MACROBLOCKD *const xd = &x->e_mbd; | |
767 int p; | 748 int p; |
768 int bwl = b_width_log2(bsize), bw = 1 << bwl; | 749 int bwl = b_width_log2(bsize), bw = 1 << bwl; |
769 int bhl = b_height_log2(bsize), bh = 1 << bhl; | 750 int bhl = b_height_log2(bsize), bh = 1 << bhl; |
770 int mwl = mi_width_log2(bsize), mw = 1 << mwl; | 751 int mwl = mi_width_log2(bsize), mw = 1 << mwl; |
771 int mhl = mi_height_log2(bsize), mh = 1 << mhl; | 752 int mhl = mi_height_log2(bsize), mh = 1 << mhl; |
772 | 753 |
773 // buffer the above/left context information of the block in search. | 754 // buffer the above/left context information of the block in search. |
774 for (p = 0; p < MAX_MB_PLANE; ++p) { | 755 for (p = 0; p < MAX_MB_PLANE; ++p) { |
775 vpx_memcpy(a + bw * p, cm->above_context[p] + | 756 vpx_memcpy( |
776 (mi_col * 2 >> xd->plane[p].subsampling_x), | 757 a + bw * p, |
777 sizeof(ENTROPY_CONTEXT) * bw >> xd->plane[p].subsampling_x); | 758 cm->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x), |
778 vpx_memcpy(l + bh * p, cm->left_context[p] + | 759 sizeof(ENTROPY_CONTEXT) * bw >> xd->plane[p].subsampling_x); |
779 ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), | 760 vpx_memcpy( |
780 sizeof(ENTROPY_CONTEXT) * bh >> xd->plane[p].subsampling_y); | 761 l + bh * p, |
781 } | 762 cm->left_context[p] |
| 763 + ((mi_row & MI_MASK)* 2 >> xd->plane[p].subsampling_y),sizeof(ENTRO
PY_CONTEXT) * bh >> xd->plane[p].subsampling_y); |
| 764 } |
782 vpx_memcpy(sa, cm->above_seg_context + mi_col, | 765 vpx_memcpy(sa, cm->above_seg_context + mi_col, |
783 sizeof(PARTITION_CONTEXT) * mw); | 766 sizeof(PARTITION_CONTEXT) * mw); |
784 vpx_memcpy(sl, cm->left_seg_context + (mi_row & MI_MASK), | 767 vpx_memcpy(sl, cm->left_seg_context + (mi_row & MI_MASK), |
785 sizeof(PARTITION_CONTEXT) * mh); | 768 sizeof(PARTITION_CONTEXT) * mh) |
786 } | 769 ;} |
787 | 770 |
788 static void encode_b(VP9_COMP *cpi, TOKENEXTRA **tp, | 771 static void encode_b(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, |
789 int mi_row, int mi_col, int output_enabled, | 772 int output_enabled, BLOCK_SIZE_TYPE bsize, int sub_index) { |
790 BLOCK_SIZE_TYPE bsize, int sub_index) { | 773 VP9_COMMON * const cm = &cpi->common; |
791 VP9_COMMON *const cm = &cpi->common; | 774 MACROBLOCK * const x = &cpi->mb; |
792 MACROBLOCK *const x = &cpi->mb; | 775 MACROBLOCKD * const xd = &x->e_mbd; |
793 MACROBLOCKD *const xd = &x->e_mbd; | |
794 | 776 |
795 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 777 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
796 return; | 778 return; |
797 | 779 |
798 if (sub_index != -1) | 780 if (sub_index != -1) |
799 *(get_sb_index(xd, bsize)) = sub_index; | 781 *(get_sb_index(xd, bsize)) = sub_index; |
800 | 782 |
801 if (bsize < BLOCK_SIZE_SB8X8) | 783 if (bsize < BLOCK_SIZE_SB8X8) |
802 if (xd->ab_index > 0) | 784 if (xd->ab_index > 0) |
803 return; | 785 return; |
804 set_offsets(cpi, mi_row, mi_col, bsize); | 786 set_offsets(cpi, mi_row, mi_col, bsize); |
805 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); | 787 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); |
806 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); | 788 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); |
807 | 789 |
808 if (output_enabled) { | 790 if (output_enabled) { |
809 update_stats(cpi, mi_row, mi_col); | 791 update_stats(cpi, mi_row, mi_col); |
810 | 792 |
811 (*tp)->token = EOSB_TOKEN; | 793 (*tp)->token = EOSB_TOKEN; |
812 (*tp)++; | 794 (*tp)++; |
813 } | 795 } |
814 } | 796 } |
815 | 797 |
816 static void encode_sb(VP9_COMP *cpi, TOKENEXTRA **tp, | 798 static void encode_sb(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, |
817 int mi_row, int mi_col, int output_enabled, | 799 int output_enabled, BLOCK_SIZE_TYPE bsize) { |
818 BLOCK_SIZE_TYPE bsize) { | 800 VP9_COMMON * const cm = &cpi->common; |
819 VP9_COMMON *const cm = &cpi->common; | 801 MACROBLOCK * const x = &cpi->mb; |
820 MACROBLOCK *const x = &cpi->mb; | 802 MACROBLOCKD * const xd = &x->e_mbd; |
821 MACROBLOCKD *const xd = &x->e_mbd; | |
822 BLOCK_SIZE_TYPE c1 = BLOCK_SIZE_SB8X8; | 803 BLOCK_SIZE_TYPE c1 = BLOCK_SIZE_SB8X8; |
823 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; | 804 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; |
824 int bwl, bhl; | 805 int bwl, bhl; |
825 int UNINITIALIZED_IS_SAFE(pl); | 806 int UNINITIALIZED_IS_SAFE(pl); |
826 | 807 |
827 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 808 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
828 return; | 809 return; |
829 | 810 |
830 c1 = BLOCK_SIZE_AB4X4; | 811 c1 = BLOCK_SIZE_AB4X4; |
831 if (bsize >= BLOCK_SIZE_SB8X8) { | 812 if (bsize >= BLOCK_SIZE_SB8X8) { |
832 set_partition_seg_context(cm, xd, mi_row, mi_col); | 813 set_partition_seg_context(cm, xd, mi_row, mi_col); |
833 pl = partition_plane_context(xd, bsize); | 814 pl = partition_plane_context(xd, bsize); |
834 c1 = *(get_sb_partitioning(x, bsize)); | 815 c1 = *(get_sb_partitioning(x, bsize)); |
835 } | 816 } |
836 | 817 |
837 bwl = b_width_log2(c1), bhl = b_height_log2(c1); | 818 bwl = b_width_log2(c1), bhl = b_height_log2(c1); |
838 | 819 |
839 if (bsl == bwl && bsl == bhl) { | 820 if (bsl == bwl && bsl == bhl) { |
840 if (output_enabled && bsize >= BLOCK_SIZE_SB8X8) | 821 if (output_enabled && bsize >= BLOCK_SIZE_SB8X8) |
841 cpi->partition_count[pl][PARTITION_NONE]++; | 822 cpi->partition_count[pl][PARTITION_NONE]++; |
842 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, -1); | 823 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, -1); |
843 } else if (bsl == bhl && bsl > bwl) { | 824 } else if (bsl == bhl && bsl > bwl) { |
844 if (output_enabled) | 825 if (output_enabled) |
845 cpi->partition_count[pl][PARTITION_VERT]++; | 826 cpi->partition_count[pl][PARTITION_VERT]++; |
846 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); | 827 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); |
847 encode_b(cpi, tp, mi_row, mi_col + bs, output_enabled, c1, 1); | 828 encode_b(cpi, tp, mi_row, mi_col + bs, output_enabled, c1, 1); |
848 } else if (bsl == bwl && bsl > bhl) { | 829 } else if (bsl == bwl && bsl > bhl) { |
849 if (output_enabled) | 830 if (output_enabled) |
850 cpi->partition_count[pl][PARTITION_HORZ]++; | 831 cpi->partition_count[pl][PARTITION_HORZ]++; |
851 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); | 832 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); |
852 encode_b(cpi, tp, mi_row + bs, mi_col, output_enabled, c1, 1); | 833 encode_b(cpi, tp, mi_row + bs, mi_col, output_enabled, c1, 1); |
853 } else { | 834 } else { |
854 BLOCK_SIZE_TYPE subsize; | 835 BLOCK_SIZE_TYPE subsize; |
855 int i; | 836 int i; |
856 | 837 |
857 assert(bwl < bsl && bhl < bsl); | 838 assert(bwl < bsl && bhl < bsl); |
858 subsize = get_subsize(bsize, PARTITION_SPLIT); | 839 subsize = get_subsize(bsize, PARTITION_SPLIT); |
859 | 840 |
860 if (output_enabled) | 841 if (output_enabled) |
861 cpi->partition_count[pl][PARTITION_SPLIT]++; | 842 cpi->partition_count[pl][PARTITION_SPLIT]++; |
862 | 843 |
863 for (i = 0; i < 4; i++) { | 844 for (i = 0; i < 4; i++) { |
864 const int x_idx = i & 1, y_idx = i >> 1; | 845 const int x_idx = i & 1, y_idx = i >> 1; |
865 | 846 |
866 *(get_sb_index(xd, subsize)) = i; | 847 *(get_sb_index(xd, subsize)) = i; |
867 encode_sb(cpi, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, | 848 encode_sb(cpi, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, |
868 output_enabled, subsize); | 849 output_enabled, subsize); |
869 } | 850 } |
870 } | 851 } |
871 | 852 |
872 if (bsize >= BLOCK_SIZE_SB8X8 && | 853 if (bsize >= BLOCK_SIZE_SB8X8 |
873 (bsize == BLOCK_SIZE_SB8X8 || bsl == bwl || bsl == bhl)) { | 854 && (bsize == BLOCK_SIZE_SB8X8 || bsl == bwl || bsl == bhl)) { |
874 set_partition_seg_context(cm, xd, mi_row, mi_col); | 855 set_partition_seg_context(cm, xd, mi_row, mi_col); |
875 update_partition_context(xd, c1, bsize); | 856 update_partition_context(xd, c1, bsize); |
876 } | 857 } |
877 } | 858 } |
878 | 859 |
879 static void set_partitioning(VP9_COMP *cpi, MODE_INFO *m, | 860 static void set_partitioning(VP9_COMP *cpi, MODE_INFO *m, |
880 BLOCK_SIZE_TYPE bsize) { | 861 BLOCK_SIZE_TYPE bsize) { |
881 VP9_COMMON *const cm = &cpi->common; | 862 VP9_COMMON *const cm = &cpi->common; |
882 const int mis = cm->mode_info_stride; | 863 const int mis = cm->mode_info_stride; |
883 int bsl = b_width_log2(bsize); | |
884 int bs = (1 << bsl) / 2; // | |
885 int block_row, block_col; | 864 int block_row, block_col; |
886 int row, col; | 865 for (block_row = 0; block_row < 8; ++block_row) { |
887 | 866 for (block_col = 0; block_col < 8; ++block_col) { |
888 // this test function sets the entire macroblock to the same bsize | 867 m[block_row * mis + block_col].mbmi.sb_type = bsize; |
889 for (block_row = 0; block_row < 8; block_row += bs) { | 868 } |
890 for (block_col = 0; block_col < 8; block_col += bs) { | 869 } |
891 for (row = 0; row < bs; row++) { | 870 } |
892 for (col = 0; col < bs; col++) { | 871 static void copy_partitioning(VP9_COMP *cpi, MODE_INFO *m, MODE_INFO *p) { |
893 m[(block_row+row)*mis + block_col+col].mbmi.sb_type = bsize; | 872 VP9_COMMON *const cm = &cpi->common; |
894 } | 873 const int mis = cm->mode_info_stride; |
895 } | 874 int block_row, block_col; |
| 875 for (block_row = 0; block_row < 8; ++block_row) { |
| 876 for (block_col = 0; block_col < 8; ++block_col) { |
| 877 m[block_row * mis + block_col].mbmi.sb_type = |
| 878 p[block_row * mis + block_col].mbmi.sb_type; |
896 } | 879 } |
897 } | 880 } |
898 } | 881 } |
899 | 882 |
900 static void set_block_size(VP9_COMMON *const cm, | 883 static void set_block_size(VP9_COMMON * const cm, MODE_INFO *m, |
901 MODE_INFO *m, BLOCK_SIZE_TYPE bsize, int mis, | 884 BLOCK_SIZE_TYPE bsize, int mis, int mi_row, |
902 int mi_row, int mi_col) { | 885 int mi_col) { |
903 int row, col; | 886 int row, col; |
904 int bwl = b_width_log2(bsize); | 887 int bwl = b_width_log2(bsize); |
905 int bhl = b_height_log2(bsize); | 888 int bhl = b_height_log2(bsize); |
906 int bsl = (bwl > bhl ? bwl : bhl); | 889 int bsl = (bwl > bhl ? bwl : bhl); |
907 | 890 |
908 int bs = (1 << bsl) / 2; // | 891 int bs = (1 << bsl) / 2; // |
909 MODE_INFO *m2 = m + mi_row * mis + mi_col; | 892 MODE_INFO *m2 = m + mi_row * mis + mi_col; |
910 for (row = 0; row < bs; row++) { | 893 for (row = 0; row < bs; row++) { |
911 for (col = 0; col < bs; col++) { | 894 for (col = 0; col < bs; col++) { |
912 if (mi_row + row >= cm->mi_rows || mi_col + col >= cm->mi_cols) | 895 if (mi_row + row >= cm->mi_rows || mi_col + col >= cm->mi_cols) |
913 continue; | 896 continue; |
914 m2[row*mis+col].mbmi.sb_type = bsize; | 897 m2[row * mis + col].mbmi.sb_type = bsize; |
915 } | 898 } |
916 } | 899 } |
917 } | 900 } |
| 901 |
918 typedef struct { | 902 typedef struct { |
919 int64_t sum_square_error; | 903 int64_t sum_square_error; |
920 int64_t sum_error; | 904 int64_t sum_error; |
921 int count; | 905 int count; |
922 int variance; | 906 int variance; |
923 } var; | 907 } var; |
924 | 908 |
| 909 typedef struct { |
| 910 var none; |
| 911 var horz[2]; |
| 912 var vert[2]; |
| 913 } partition_variance; |
| 914 |
925 #define VT(TYPE, BLOCKSIZE) \ | 915 #define VT(TYPE, BLOCKSIZE) \ |
926 typedef struct { \ | 916 typedef struct { \ |
927 var none; \ | 917 partition_variance vt; \ |
928 var horz[2]; \ | |
929 var vert[2]; \ | |
930 BLOCKSIZE split[4]; } TYPE; | 918 BLOCKSIZE split[4]; } TYPE; |
931 | 919 |
932 VT(v8x8, var) | 920 VT(v8x8, var) |
933 VT(v16x16, v8x8) | 921 VT(v16x16, v8x8) |
934 VT(v32x32, v16x16) | 922 VT(v32x32, v16x16) |
935 VT(v64x64, v32x32) | 923 VT(v64x64, v32x32) |
936 | 924 |
| 925 typedef struct { |
| 926 partition_variance *vt; |
| 927 var *split[4]; |
| 928 } vt_node; |
| 929 |
937 typedef enum { | 930 typedef enum { |
938 V16X16, | 931 V16X16, |
939 V32X32, | 932 V32X32, |
940 V64X64, | 933 V64X64, |
941 } TREE_LEVEL; | 934 } TREE_LEVEL; |
942 | 935 |
| 936 static void tree_to_node(void *data, BLOCK_SIZE_TYPE block_size, vt_node *node)
{ |
| 937 int i; |
| 938 switch (block_size) { |
| 939 case BLOCK_SIZE_SB64X64: { |
| 940 v64x64 *vt = (v64x64 *) data; |
| 941 node->vt = &vt->vt; |
| 942 for (i = 0; i < 4; i++) |
| 943 node->split[i] = &vt->split[i].vt.none; |
| 944 break; |
| 945 } |
| 946 case BLOCK_SIZE_SB32X32: { |
| 947 v32x32 *vt = (v32x32 *) data; |
| 948 node->vt = &vt->vt; |
| 949 for (i = 0; i < 4; i++) |
| 950 node->split[i] = &vt->split[i].vt.none; |
| 951 break; |
| 952 } |
| 953 case BLOCK_SIZE_MB16X16: { |
| 954 v16x16 *vt = (v16x16 *) data; |
| 955 node->vt = &vt->vt; |
| 956 for (i = 0; i < 4; i++) |
| 957 node->split[i] = &vt->split[i].vt.none; |
| 958 break; |
| 959 } |
| 960 case BLOCK_SIZE_SB8X8: { |
| 961 v8x8 *vt = (v8x8 *) data; |
| 962 node->vt = &vt->vt; |
| 963 for (i = 0; i < 4; i++) |
| 964 node->split[i] = &vt->split[i]; |
| 965 break; |
| 966 } |
| 967 default: |
| 968 node->vt = 0; |
| 969 for (i = 0; i < 4; i++) |
| 970 node->split[i] = 0; |
| 971 assert(-1); |
| 972 } |
| 973 } |
| 974 |
943 // Set variance values given sum square error, sum error, count. | 975 // Set variance values given sum square error, sum error, count. |
944 static void fill_variance(var *v, int64_t s2, int64_t s, int c) { | 976 static void fill_variance(var *v, int64_t s2, int64_t s, int c) { |
945 v->sum_square_error = s2; | 977 v->sum_square_error = s2; |
946 v->sum_error = s; | 978 v->sum_error = s; |
947 v->count = c; | 979 v->count = c; |
948 v->variance = 256 | 980 if (c > 0) |
949 * (v->sum_square_error - v->sum_error * v->sum_error / v->count) | 981 v->variance = 256 |
950 / v->count; | 982 * (v->sum_square_error - v->sum_error * v->sum_error / v->count) |
| 983 / v->count; |
| 984 else |
| 985 v->variance = 0; |
951 } | 986 } |
952 | 987 |
953 // Combine 2 variance structures by summing the sum_error, sum_square_error, | 988 // Combine 2 variance structures by summing the sum_error, sum_square_error, |
954 // and counts and then calculating the new variance. | 989 // and counts and then calculating the new variance. |
955 void sum_2_variances(var *r, var *a, var*b) { | 990 void sum_2_variances(var *r, var *a, var*b) { |
956 fill_variance(r, a->sum_square_error + b->sum_square_error, | 991 fill_variance(r, a->sum_square_error + b->sum_square_error, |
957 a->sum_error + b->sum_error, a->count + b->count); | 992 a->sum_error + b->sum_error, a->count + b->count); |
958 } | 993 } |
959 // Fill one level of our variance tree, by summing the split sums into each of | |
960 // the horizontal, vertical and none from split and recalculating variance. | |
961 #define fill_variance_tree(VT) \ | |
962 sum_2_variances(VT.horz[0], VT.split[0].none, VT.split[1].none); \ | |
963 sum_2_variances(VT.horz[1], VT.split[2].none, VT.split[3].none); \ | |
964 sum_2_variances(VT.vert[0], VT.split[0].none, VT.split[2].none); \ | |
965 sum_2_variances(VT.vert[1], VT.split[1].none, VT.split[3].none); \ | |
966 sum_2_variances(VT.none, VT.vert[0], VT.vert[1]); | |
967 | 994 |
968 // Set the blocksize in the macroblock info structure if the variance is less | 995 static void fill_variance_tree(void *data, BLOCK_SIZE_TYPE block_size) { |
969 // than our threshold to one of none, horz, vert. | 996 vt_node node; |
970 #define set_vt_size(VT, BLOCKSIZE, R, C, ACTION) \ | 997 tree_to_node(data, block_size, &node); |
971 if (VT.none.variance < threshold) { \ | 998 sum_2_variances(&node.vt->horz[0], node.split[0], node.split[1]); |
972 set_block_size(cm, m, BLOCKSIZE, mis, R, C); \ | 999 sum_2_variances(&node.vt->horz[1], node.split[2], node.split[3]); |
973 ACTION; \ | 1000 sum_2_variances(&node.vt->vert[0], node.split[0], node.split[2]); |
974 } \ | 1001 sum_2_variances(&node.vt->vert[1], node.split[1], node.split[3]); |
975 if (VT.horz[0].variance < threshold && VT.horz[1].variance < threshold ) { \ | 1002 sum_2_variances(&node.vt->none, &node.vt->vert[0], &node.vt->vert[1]); |
976 set_block_size(cm, m, get_subsize(BLOCKSIZE, PARTITION_HORZ), mis, R, C); \ | 1003 } |
977 ACTION; \ | 1004 |
978 } \ | 1005 #if PERFORM_RANDOM_PARTITIONING |
979 if (VT.vert[0].variance < threshold && VT.vert[1].variance < threshold ) { \ | 1006 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO *m, |
980 set_block_size(cm, m, get_subsize(BLOCKSIZE, PARTITION_VERT), mis, R, C); \ | 1007 BLOCK_SIZE_TYPE block_size, int mi_row, |
981 ACTION; \ | 1008 int mi_col, int mi_size) { |
| 1009 VP9_COMMON * const cm = &cpi->common; |
| 1010 vt_node vt; |
| 1011 const int mis = cm->mode_info_stride; |
| 1012 int64_t threshold = 4 * cpi->common.base_qindex * cpi->common.base_qindex; |
| 1013 |
| 1014 tree_to_node(data, block_size, &vt); |
| 1015 |
| 1016 // split none is available only if we have more than half a block size |
| 1017 // in width and height inside the visible image |
| 1018 if (mi_col + mi_size < cm->mi_cols && mi_row + mi_size < cm->mi_rows && |
| 1019 (rand() & 3) < 1) { |
| 1020 set_block_size(cm, m, block_size, mis, mi_row, mi_col); |
| 1021 return 1; |
982 } | 1022 } |
983 | 1023 |
| 1024 // vertical split is available on all but the bottom border |
| 1025 if (mi_row + mi_size < cm->mi_rows && vt.vt->vert[0].variance < threshold |
| 1026 && (rand() & 3) < 1) { |
| 1027 set_block_size(cm, m, get_subsize(block_size, PARTITION_VERT), mis, mi_row, |
| 1028 mi_col); |
| 1029 return 1; |
| 1030 } |
| 1031 |
| 1032 // horizontal split is available on all but the right border |
| 1033 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold |
| 1034 && (rand() & 3) < 1) { |
| 1035 set_block_size(cm, m, get_subsize(block_size, PARTITION_HORZ), mis, mi_row, |
| 1036 mi_col); |
| 1037 return 1; |
| 1038 } |
| 1039 |
| 1040 return 0; |
| 1041 } |
| 1042 |
| 1043 #else |
| 1044 |
| 1045 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO *m, |
| 1046 BLOCK_SIZE_TYPE block_size, int mi_row, |
| 1047 int mi_col, int mi_size) { |
| 1048 VP9_COMMON * const cm = &cpi->common; |
| 1049 vt_node vt; |
| 1050 const int mis = cm->mode_info_stride; |
| 1051 int64_t threshold = 50 * cpi->common.base_qindex; |
| 1052 |
| 1053 tree_to_node(data, block_size, &vt); |
| 1054 |
| 1055 // split none is available only if we have more than half a block size |
| 1056 // in width and height inside the visible image |
| 1057 if (mi_col + mi_size < cm->mi_cols && mi_row + mi_size < cm->mi_rows |
| 1058 && vt.vt->none.variance < threshold) { |
| 1059 set_block_size(cm, m, block_size, mis, mi_row, mi_col); |
| 1060 return 1; |
| 1061 } |
| 1062 |
| 1063 // vertical split is available on all but the bottom border |
| 1064 if (mi_row + mi_size < cm->mi_rows && vt.vt->vert[0].variance < threshold |
| 1065 && vt.vt->vert[1].variance < threshold) { |
| 1066 set_block_size(cm, m, get_subsize(block_size, PARTITION_VERT), mis, mi_row, |
| 1067 mi_col); |
| 1068 return 1; |
| 1069 } |
| 1070 |
| 1071 // horizontal split is available on all but the right border |
| 1072 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold |
| 1073 && vt.vt->horz[1].variance < threshold) { |
| 1074 set_block_size(cm, m, get_subsize(block_size, PARTITION_HORZ), mis, mi_row, |
| 1075 mi_col); |
| 1076 return 1; |
| 1077 } |
| 1078 |
| 1079 return 0; |
| 1080 } |
| 1081 #endif |
| 1082 |
984 static void choose_partitioning(VP9_COMP *cpi, MODE_INFO *m, int mi_row, | 1083 static void choose_partitioning(VP9_COMP *cpi, MODE_INFO *m, int mi_row, |
985 int mi_col) { | 1084 int mi_col) { |
986 VP9_COMMON * const cm = &cpi->common; | 1085 VP9_COMMON * const cm = &cpi->common; |
987 MACROBLOCK *x = &cpi->mb; | 1086 MACROBLOCK *x = &cpi->mb; |
988 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 1087 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
989 const int mis = cm->mode_info_stride; | 1088 const int mis = cm->mode_info_stride; |
990 // TODO(JBB): More experimentation or testing of this threshold; | 1089 // TODO(JBB): More experimentation or testing of this threshold; |
991 int64_t threshold = 4; | 1090 int64_t threshold = 4; |
992 int i, j, k; | 1091 int i, j, k; |
993 v64x64 vt; | 1092 v64x64 vt; |
994 unsigned char * s; | 1093 unsigned char * s; |
995 int sp; | 1094 int sp; |
996 const unsigned char * d = xd->plane[0].pre->buf; | 1095 const unsigned char * d; |
997 int dp = xd->plane[0].pre->stride; | 1096 int dp; |
998 int pixels_wide = 64, pixels_high = 64; | 1097 int pixels_wide = 64, pixels_high = 64; |
999 | 1098 |
1000 vpx_memset(&vt, 0, sizeof(vt)); | 1099 vpx_memset(&vt, 0, sizeof(vt)); |
1001 | 1100 |
1002 set_offsets(cpi, mi_row, mi_col, BLOCK_SIZE_SB64X64); | 1101 set_offsets(cpi, mi_row, mi_col, BLOCK_SIZE_SB64X64); |
1003 | 1102 |
1004 if (xd->mb_to_right_edge < 0) | 1103 if (xd->mb_to_right_edge < 0) |
1005 pixels_wide += (xd->mb_to_right_edge >> 3); | 1104 pixels_wide += (xd->mb_to_right_edge >> 3); |
1006 | 1105 |
1007 if (xd->mb_to_bottom_edge < 0) | 1106 if (xd->mb_to_bottom_edge < 0) |
1008 pixels_high += (xd->mb_to_bottom_edge >> 3); | 1107 pixels_high += (xd->mb_to_bottom_edge >> 3); |
1009 | 1108 |
1010 s = x->plane[0].src.buf; | 1109 s = x->plane[0].src.buf; |
1011 sp = x->plane[0].src.stride; | 1110 sp = x->plane[0].src.stride; |
1012 | 1111 |
1013 // TODO(JBB): Clearly the higher the quantizer the fewer partitions we want | 1112 // TODO(JBB): Clearly the higher the quantizer the fewer partitions we want |
1014 // but this needs more experimentation. | 1113 // but this needs more experimentation. |
1015 threshold = threshold * cpi->common.base_qindex * cpi->common.base_qindex; | 1114 threshold = threshold * cpi->common.base_qindex * cpi->common.base_qindex; |
1016 | 1115 |
1017 // if ( cm->frame_type == KEY_FRAME ) { | |
1018 d = vp9_64x64_zeros; | 1116 d = vp9_64x64_zeros; |
1019 dp = 64; | 1117 dp = 64; |
1020 // } | 1118 if (cm->frame_type != KEY_FRAME) { |
| 1119 int_mv nearest, near; |
| 1120 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[0]; |
| 1121 YV12_BUFFER_CONFIG *second_ref_fb = NULL; |
| 1122 |
| 1123 setup_pre_planes(xd, ref_fb, second_ref_fb, mi_row, mi_col, |
| 1124 xd->scale_factor, xd->scale_factor_uv); |
| 1125 xd->mode_info_context->mbmi.ref_frame[0] = LAST_FRAME; |
| 1126 xd->mode_info_context->mbmi.sb_type = BLOCK_SIZE_SB64X64; |
| 1127 vp9_find_best_ref_mvs(xd, m->mbmi.ref_mvs[m->mbmi.ref_frame[0]], &nearest, |
| 1128 &near); |
| 1129 |
| 1130 xd->mode_info_context->mbmi.mv[0] = nearest; |
| 1131 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_SIZE_SB64X64); |
| 1132 d = xd->plane[0].dst.buf; |
| 1133 dp = xd->plane[0].dst.stride; |
| 1134 |
| 1135 } |
1021 | 1136 |
1022 // Fill in the entire tree of 8x8 variances for splits. | 1137 // Fill in the entire tree of 8x8 variances for splits. |
1023 for (i = 0; i < 4; i++) { | 1138 for (i = 0; i < 4; i++) { |
1024 const int x32_idx = ((i & 1) << 5); | 1139 const int x32_idx = ((i & 1) << 5); |
1025 const int y32_idx = ((i >> 1) << 5); | 1140 const int y32_idx = ((i >> 1) << 5); |
1026 for (j = 0; j < 4; j++) { | 1141 for (j = 0; j < 4; j++) { |
1027 const int x_idx = x32_idx + ((j & 1) << 4); | 1142 const int x16_idx = x32_idx + ((j & 1) << 4); |
1028 const int y_idx = y32_idx + ((j >> 1) << 4); | 1143 const int y16_idx = y32_idx + ((j >> 1) << 4); |
1029 const uint8_t *st = s + y_idx * sp + x_idx; | |
1030 const uint8_t *dt = d + y_idx * dp + x_idx; | |
1031 unsigned int sse = 0; | |
1032 int sum = 0; | |
1033 v16x16 *vst = &vt.split[i].split[j]; | 1144 v16x16 *vst = &vt.split[i].split[j]; |
1034 sse = sum = 0; | 1145 for (k = 0; k < 4; k++) { |
1035 if (x_idx < pixels_wide && y_idx < pixels_high) | 1146 int x_idx = x16_idx + ((k & 1) << 3); |
1036 vp9_get_sse_sum_8x8(st, sp, dt, dp, &sse, &sum); | 1147 int y_idx = y16_idx + ((k >> 1) << 3); |
1037 fill_variance(&vst->split[0].none, sse, sum, 64); | 1148 unsigned int sse = 0; |
1038 sse = sum = 0; | 1149 int sum = 0; |
1039 if (x_idx + 8 < pixels_wide && y_idx < pixels_high) | 1150 if (x_idx < pixels_wide && y_idx < pixels_high) |
1040 vp9_get_sse_sum_8x8(st + 8, sp, dt + 8, dp, &sse, &sum); | 1151 vp9_get_sse_sum_8x8(s + y_idx * sp + x_idx, sp, |
1041 fill_variance(&vst->split[1].none, sse, sum, 64); | 1152 d + y_idx * dp + x_idx, dp, &sse, &sum); |
1042 sse = sum = 0; | 1153 fill_variance(&vst->split[k].vt.none, sse, sum, 64); |
1043 if (x_idx < pixels_wide && y_idx + 8 < pixels_high) | 1154 } |
1044 vp9_get_sse_sum_8x8(st + 8 * sp, sp, dt + 8 * dp, dp, &sse, &sum); | |
1045 fill_variance(&vst->split[2].none, sse, sum, 64); | |
1046 sse = sum = 0; | |
1047 if (x_idx + 8 < pixels_wide && y_idx + 8 < pixels_high) | |
1048 vp9_get_sse_sum_8x8(st + 8 * sp + 8, sp, dt + 8 + 8 * dp, dp, &sse, | |
1049 &sum); | |
1050 fill_variance(&vst->split[3].none, sse, sum, 64); | |
1051 } | 1155 } |
1052 } | 1156 } |
1053 // Fill the rest of the variance tree by summing the split partition | 1157 // Fill the rest of the variance tree by summing the split partition |
1054 // values. | 1158 // values. |
1055 for (i = 0; i < 4; i++) { | 1159 for (i = 0; i < 4; i++) { |
1056 for (j = 0; j < 4; j++) { | 1160 for (j = 0; j < 4; j++) { |
1057 fill_variance_tree(&vt.split[i].split[j]) | 1161 fill_variance_tree(&vt.split[i].split[j], BLOCK_SIZE_MB16X16); |
1058 } | 1162 } |
1059 fill_variance_tree(&vt.split[i]) | 1163 fill_variance_tree(&vt.split[i], BLOCK_SIZE_SB32X32); |
1060 } | 1164 } |
1061 fill_variance_tree(&vt) | 1165 fill_variance_tree(&vt, BLOCK_SIZE_SB64X64); |
1062 | 1166 // Now go through the entire structure, splitting every block size until |
1063 // Now go through the entire structure, splitting every blocksize until | |
1064 // we get to one that's got a variance lower than our threshold, or we | 1167 // we get to one that's got a variance lower than our threshold, or we |
1065 // hit 8x8. | 1168 // hit 8x8. |
1066 set_vt_size( vt, BLOCK_SIZE_SB64X64, mi_row, mi_col, return); | 1169 if (!set_vt_partitioning(cpi, &vt, m, BLOCK_SIZE_SB64X64, mi_row, mi_col, |
1067 for (i = 0; i < 4; ++i) { | 1170 4)) { |
1068 const int x32_idx = ((i & 1) << 2); | 1171 for (i = 0; i < 4; ++i) { |
1069 const int y32_idx = ((i >> 1) << 2); | 1172 const int x32_idx = ((i & 1) << 2); |
1070 set_vt_size(vt, BLOCK_SIZE_SB32X32, mi_row + y32_idx, mi_col + x32_idx, | 1173 const int y32_idx = ((i >> 1) << 2); |
1071 continue); | 1174 if (!set_vt_partitioning(cpi, &vt.split[i], m, BLOCK_SIZE_SB32X32, |
1072 | 1175 (mi_row + y32_idx), (mi_col + x32_idx), 2)) { |
1073 for (j = 0; j < 4; ++j) { | 1176 for (j = 0; j < 4; ++j) { |
1074 const int x16_idx = ((j & 1) << 1); | 1177 const int x16_idx = ((j & 1) << 1); |
1075 const int y16_idx = ((j >> 1) << 1); | 1178 const int y16_idx = ((j >> 1) << 1); |
1076 set_vt_size(vt, BLOCK_SIZE_MB16X16, mi_row + y32_idx + y16_idx, | 1179 if (!set_vt_partitioning(cpi, &vt.split[i].split[j], m, |
1077 mi_col+x32_idx+x16_idx, continue); | 1180 BLOCK_SIZE_MB16X16, |
1078 | 1181 (mi_row + y32_idx + y16_idx), |
1079 for (k = 0; k < 4; ++k) { | 1182 (mi_col + x32_idx + x16_idx), 1)) { |
1080 const int x8_idx = (k & 1); | 1183 for (k = 0; k < 4; ++k) { |
1081 const int y8_idx = (k >> 1); | 1184 const int x8_idx = (k & 1); |
1082 set_block_size(cm, m, BLOCK_SIZE_SB8X8, mis, | 1185 const int y8_idx = (k >> 1); |
1083 mi_row + y32_idx + y16_idx + y8_idx, | 1186 set_block_size(cm, m, BLOCK_SIZE_SB8X8, mis, |
1084 mi_col + x32_idx + x16_idx + x8_idx); | 1187 (mi_row + y32_idx + y16_idx + y8_idx), |
| 1188 (mi_col + x32_idx + x16_idx + x8_idx)); |
| 1189 } |
| 1190 } |
| 1191 } |
1085 } | 1192 } |
1086 } | 1193 } |
1087 } | 1194 } |
1088 } | 1195 } |
1089 static void rd_use_partition(VP9_COMP *cpi, MODE_INFO *m, TOKENEXTRA **tp, | 1196 static void rd_use_partition(VP9_COMP *cpi, MODE_INFO *m, TOKENEXTRA **tp, |
1090 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize, | 1197 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize, |
1091 int *rate, int *dist) { | 1198 int *rate, int *dist) { |
1092 VP9_COMMON * const cm = &cpi->common; | 1199 VP9_COMMON * const cm = &cpi->common; |
1093 MACROBLOCK * const x = &cpi->mb; | 1200 MACROBLOCK * const x = &cpi->mb; |
1094 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 1201 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
1095 const int mis = cm->mode_info_stride; | 1202 const int mis = cm->mode_info_stride; |
1096 int bwl = b_width_log2(m->mbmi.sb_type); | 1203 int bwl = b_width_log2(m->mbmi.sb_type); |
1097 int bhl = b_height_log2(m->mbmi.sb_type); | 1204 int bhl = b_height_log2(m->mbmi.sb_type); |
1098 int bsl = b_width_log2(bsize); | 1205 int bsl = b_width_log2(bsize); |
1099 int bh = (1 << bhl); | 1206 int bh = (1 << bhl); |
1100 int bs = (1 << bsl); | 1207 int bs = (1 << bsl); |
1101 int bss = (1 << bsl)/4; | 1208 int bss = (1 << bsl) / 4; |
1102 int i, pl; | 1209 int i, pl; |
1103 PARTITION_TYPE partition; | 1210 PARTITION_TYPE partition; |
1104 BLOCK_SIZE_TYPE subsize; | 1211 BLOCK_SIZE_TYPE subsize; |
1105 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1212 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1106 PARTITION_CONTEXT sl[8], sa[8]; | 1213 PARTITION_CONTEXT sl[8], sa[8]; |
1107 int r = 0, d = 0; | 1214 int r = 0, d = 0; |
1108 | 1215 |
1109 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 1216 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
1110 return; | 1217 return; |
1111 | 1218 |
1112 | |
1113 // parse the partition type | 1219 // parse the partition type |
1114 if ((bwl == bsl) && (bhl == bsl)) | 1220 if ((bwl == bsl) && (bhl == bsl)) |
1115 partition = PARTITION_NONE; | 1221 partition = PARTITION_NONE; |
1116 else if ((bwl == bsl) && (bhl < bsl)) | 1222 else if ((bwl == bsl) && (bhl < bsl)) |
1117 partition = PARTITION_HORZ; | 1223 partition = PARTITION_HORZ; |
1118 else if ((bwl < bsl) && (bhl == bsl)) | 1224 else if ((bwl < bsl) && (bhl == bsl)) |
1119 partition = PARTITION_VERT; | 1225 partition = PARTITION_VERT; |
1120 else if ((bwl < bsl) && (bhl < bsl)) | 1226 else if ((bwl < bsl) && (bhl < bsl)) |
1121 partition = PARTITION_SPLIT; | 1227 partition = PARTITION_SPLIT; |
1122 else | 1228 else |
1123 assert(0); | 1229 assert(0); |
1124 | 1230 |
1125 subsize = get_subsize(bsize, partition); | 1231 subsize = get_subsize(bsize, partition); |
1126 | 1232 |
1127 // TODO(JBB): this restriction is here because pick_sb_modes can return | 1233 if (bsize < BLOCK_SIZE_SB8X8) { |
1128 // r's that are INT_MAX meaning we can't select a mode / mv for this block. | 1234 if (xd->ab_index != 0) { |
1129 // when the code is made to work for less than sb8x8 we need to come up with | 1235 *rate = 0; |
1130 // a solution to this problem. | 1236 *dist = 0; |
1131 assert(subsize >= BLOCK_SIZE_SB8X8); | 1237 return; |
1132 | 1238 } |
1133 if (bsize >= BLOCK_SIZE_SB8X8) { | 1239 } else { |
1134 xd->left_seg_context = cm->left_seg_context + (mi_row & MI_MASK); | |
1135 xd->above_seg_context = cm->above_seg_context + mi_col; | |
1136 *(get_sb_partitioning(x, bsize)) = subsize; | 1240 *(get_sb_partitioning(x, bsize)) = subsize; |
1137 } | 1241 } |
1138 | |
1139 pl = partition_plane_context(xd, bsize); | 1242 pl = partition_plane_context(xd, bsize); |
1140 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1243 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1141 switch (partition) { | 1244 switch (partition) { |
1142 case PARTITION_NONE: | 1245 case PARTITION_NONE: |
1143 pick_sb_modes(cpi, mi_row, mi_col, tp, &r, &d, bsize, | 1246 pick_sb_modes(cpi, mi_row, mi_col, tp, &r, &d, bsize, |
1144 get_block_context(x, bsize)); | 1247 get_block_context(x, bsize)); |
1145 r += x->partition_cost[pl][PARTITION_NONE]; | 1248 r += x->partition_cost[pl][PARTITION_NONE]; |
1146 break; | 1249 break; |
1147 case PARTITION_HORZ: | 1250 case PARTITION_HORZ: |
1148 *(get_sb_index(xd, subsize)) = 0; | 1251 *(get_sb_index(xd, subsize)) = 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 d += dt; | 1302 d += dt; |
1200 } | 1303 } |
1201 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1304 set_partition_seg_context(cm, xd, mi_row, mi_col); |
1202 pl = partition_plane_context(xd, bsize); | 1305 pl = partition_plane_context(xd, bsize); |
1203 r += x->partition_cost[pl][PARTITION_SPLIT]; | 1306 r += x->partition_cost[pl][PARTITION_SPLIT]; |
1204 break; | 1307 break; |
1205 default: | 1308 default: |
1206 assert(0); | 1309 assert(0); |
1207 } | 1310 } |
1208 | 1311 |
1209 // update partition context | |
1210 #if CONFIG_AB4X4 | |
1211 if (bsize >= BLOCK_SIZE_SB8X8 && | |
1212 (bsize == BLOCK_SIZE_SB8X8 || partition != PARTITION_SPLIT)) { | |
1213 #else | |
1214 if (bsize > BLOCK_SIZE_SB8X8 | |
1215 && (bsize == BLOCK_SIZE_MB16X16 || partition != PARTITION_SPLIT)) { | |
1216 #endif | |
1217 set_partition_seg_context(cm, xd, mi_row, mi_col); | |
1218 update_partition_context(xd, subsize, bsize); | |
1219 } | |
1220 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1312 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1221 | 1313 |
1222 if (r < INT_MAX && d < INT_MAX) | 1314 if (r < INT_MAX && d < INT_MAX) |
1223 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_SIZE_SB64X64, bsize); | 1315 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_SIZE_SB64X64, bsize); |
1224 *rate = r; | 1316 *rate = r; |
1225 *dist = d; | 1317 *dist = d; |
1226 } | 1318 } |
1227 | 1319 |
1228 | 1320 |
1229 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 1321 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
1230 // unlikely to be selected depending on previously rate-distortion optimization | 1322 // unlikely to be selected depending on previously rate-distortion optimization |
1231 // results, for encoding speed-up. | 1323 // results, for encoding speed-up. |
1232 static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, | 1324 static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, |
1233 int mi_row, int mi_col, | 1325 int mi_col, BLOCK_SIZE_TYPE bsize, int *rate, |
1234 BLOCK_SIZE_TYPE bsize, | 1326 int *dist) { |
1235 int *rate, int *dist) { | 1327 VP9_COMMON * const cm = &cpi->common; |
1236 VP9_COMMON *const cm = &cpi->common; | 1328 MACROBLOCK * const x = &cpi->mb; |
1237 MACROBLOCK *const x = &cpi->mb; | 1329 MACROBLOCKD * const xd = &x->e_mbd; |
1238 MACROBLOCKD *const xd = &x->e_mbd; | |
1239 int bsl = b_width_log2(bsize), bs = 1 << bsl; | 1330 int bsl = b_width_log2(bsize), bs = 1 << bsl; |
1240 int ms = bs / 2; | 1331 int ms = bs / 2; |
1241 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1332 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1242 PARTITION_CONTEXT sl[8], sa[8]; | 1333 PARTITION_CONTEXT sl[8], sa[8]; |
1243 TOKENEXTRA *tp_orig = *tp; | 1334 TOKENEXTRA *tp_orig = *tp; |
1244 int i, pl; | 1335 int i, pl; |
1245 BLOCK_SIZE_TYPE subsize; | 1336 BLOCK_SIZE_TYPE subsize; |
1246 int srate = INT_MAX, sdist = INT_MAX; | 1337 int srate = INT_MAX, sdist = INT_MAX; |
1247 | 1338 |
1248 if (bsize < BLOCK_SIZE_SB8X8) | 1339 if (bsize < BLOCK_SIZE_SB8X8) |
1249 if (xd->ab_index != 0) { | 1340 if (xd->ab_index != 0) { |
1250 *rate = 0; | 1341 *rate = 0; |
1251 *dist = 0; | 1342 *dist = 0; |
1252 return; | 1343 return; |
1253 } | 1344 } |
1254 assert(mi_height_log2(bsize) == mi_width_log2(bsize)); | 1345 assert(mi_height_log2(bsize) == mi_width_log2(bsize)); |
1255 | 1346 |
1256 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1347 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1257 | 1348 |
1258 // PARTITION_SPLIT | 1349 // PARTITION_SPLIT |
1259 if (bsize >= BLOCK_SIZE_SB8X8) { | 1350 if (!cpi->sf.use_partitions_greater_than |
1260 int r4 = 0, d4 = 0; | 1351 || (cpi->sf.use_partitions_greater_than |
1261 subsize = get_subsize(bsize, PARTITION_SPLIT); | 1352 && bsize > cpi->sf.greater_than_block_size)) { |
1262 *(get_sb_partitioning(x, bsize)) = subsize; | 1353 if (bsize >= BLOCK_SIZE_SB8X8) { |
| 1354 int r4 = 0, d4 = 0; |
| 1355 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 1356 *(get_sb_partitioning(x, bsize)) = subsize; |
1263 | 1357 |
1264 for (i = 0; i < 4; ++i) { | 1358 for (i = 0; i < 4; ++i) { |
1265 int x_idx = (i & 1) * (ms >> 1); | 1359 int x_idx = (i & 1) * (ms >> 1); |
1266 int y_idx = (i >> 1) * (ms >> 1); | 1360 int y_idx = (i >> 1) * (ms >> 1); |
1267 int r = 0, d = 0; | 1361 int r = 0, d = 0; |
1268 | 1362 |
1269 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | 1363 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
1270 continue; | 1364 continue; |
1271 | 1365 |
1272 *(get_sb_index(xd, subsize)) = i; | 1366 *(get_sb_index(xd, subsize)) = i; |
1273 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, | 1367 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, &r, |
1274 &r, &d); | 1368 &d); |
1275 | 1369 |
1276 r4 += r; | 1370 r4 += r; |
1277 d4 += d; | 1371 d4 += d; |
1278 } | 1372 } |
1279 set_partition_seg_context(cm, xd, mi_row, mi_col); | |
1280 pl = partition_plane_context(xd, bsize); | |
1281 if (r4 < INT_MAX) | |
1282 r4 += x->partition_cost[pl][PARTITION_SPLIT]; | |
1283 assert(r4 >= 0); | |
1284 assert(d4 >= 0); | |
1285 srate = r4; | |
1286 sdist = d4; | |
1287 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | |
1288 } | |
1289 | |
1290 // PARTITION_HORZ | |
1291 if (bsize >= BLOCK_SIZE_SB8X8 && mi_col + (ms >> 1) < cm->mi_cols) { | |
1292 int r2, d2; | |
1293 int r = 0, d = 0; | |
1294 subsize = get_subsize(bsize, PARTITION_HORZ); | |
1295 *(get_sb_index(xd, subsize)) = 0; | |
1296 pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize, | |
1297 get_block_context(x, subsize)); | |
1298 | |
1299 if (mi_row + (ms >> 1) < cm->mi_rows) { | |
1300 update_state(cpi, get_block_context(x, subsize), subsize, 0); | |
1301 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | |
1302 | |
1303 *(get_sb_index(xd, subsize)) = 1; | |
1304 pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, tp, &r, &d, subsize, | |
1305 get_block_context(x, subsize)); | |
1306 r2 += r; | |
1307 d2 += d; | |
1308 } | |
1309 set_partition_seg_context(cm, xd, mi_row, mi_col); | |
1310 pl = partition_plane_context(xd, bsize); | |
1311 if (r2 < INT_MAX) | |
1312 r2 += x->partition_cost[pl][PARTITION_HORZ]; | |
1313 if (RDCOST(x->rdmult, x->rddiv, r2, d2) < | |
1314 RDCOST(x->rdmult, x->rddiv, srate, sdist)) { | |
1315 srate = r2; | |
1316 sdist = d2; | |
1317 *(get_sb_partitioning(x, bsize)) = subsize; | |
1318 } | |
1319 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | |
1320 } | |
1321 | |
1322 // PARTITION_VERT | |
1323 if (bsize >= BLOCK_SIZE_SB8X8 && mi_row + (ms >> 1) < cm->mi_rows) { | |
1324 int r2, d2; | |
1325 subsize = get_subsize(bsize, PARTITION_VERT); | |
1326 *(get_sb_index(xd, subsize)) = 0; | |
1327 pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize, | |
1328 get_block_context(x, subsize)); | |
1329 if (mi_col + (ms >> 1) < cm->mi_cols) { | |
1330 int r = 0, d = 0; | |
1331 update_state(cpi, get_block_context(x, subsize), subsize, 0); | |
1332 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | |
1333 | |
1334 *(get_sb_index(xd, subsize)) = 1; | |
1335 pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), tp, &r, &d, subsize, | |
1336 get_block_context(x, subsize)); | |
1337 r2 += r; | |
1338 d2 += d; | |
1339 } | |
1340 set_partition_seg_context(cm, xd, mi_row, mi_col); | |
1341 pl = partition_plane_context(xd, bsize); | |
1342 if (r2 < INT_MAX) | |
1343 r2 += x->partition_cost[pl][PARTITION_VERT]; | |
1344 if (RDCOST(x->rdmult, x->rddiv, r2, d2) < | |
1345 RDCOST(x->rdmult, x->rddiv, srate, sdist)) { | |
1346 srate = r2; | |
1347 sdist = d2; | |
1348 *(get_sb_partitioning(x, bsize)) = subsize; | |
1349 } | |
1350 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | |
1351 } | |
1352 | |
1353 // PARTITION_NONE | |
1354 if ((mi_row + (ms >> 1) < cm->mi_rows) && | |
1355 (mi_col + (ms >> 1) < cm->mi_cols)) { | |
1356 int r, d; | |
1357 pick_sb_modes(cpi, mi_row, mi_col, tp, &r, &d, bsize, | |
1358 get_block_context(x, bsize)); | |
1359 if (bsize >= BLOCK_SIZE_SB8X8) { | |
1360 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1373 set_partition_seg_context(cm, xd, mi_row, mi_col); |
1361 pl = partition_plane_context(xd, bsize); | 1374 pl = partition_plane_context(xd, bsize); |
1362 r += x->partition_cost[pl][PARTITION_NONE]; | 1375 if (r4 < INT_MAX) |
| 1376 r4 += x->partition_cost[pl][PARTITION_SPLIT]; |
| 1377 assert(r4 >= 0); |
| 1378 assert(d4 >= 0); |
| 1379 srate = r4; |
| 1380 sdist = d4; |
| 1381 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1382 } |
| 1383 } |
| 1384 if (!cpi->sf.use_partitions_less_than |
| 1385 || (cpi->sf.use_partitions_less_than |
| 1386 && bsize <= cpi->sf.less_than_block_size)) { |
| 1387 // PARTITION_HORZ |
| 1388 if (bsize >= BLOCK_SIZE_SB8X8 && mi_col + (ms >> 1) < cm->mi_cols) { |
| 1389 int r2, d2; |
| 1390 int r = 0, d = 0; |
| 1391 subsize = get_subsize(bsize, PARTITION_HORZ); |
| 1392 *(get_sb_index(xd, subsize)) = 0; |
| 1393 pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize, |
| 1394 get_block_context(x, subsize)); |
| 1395 |
| 1396 if (mi_row + (ms >> 1) < cm->mi_rows) { |
| 1397 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
| 1398 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
| 1399 |
| 1400 *(get_sb_index(xd, subsize)) = 1; |
| 1401 pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, tp, &r, &d, subsize, |
| 1402 get_block_context(x, subsize)); |
| 1403 r2 += r; |
| 1404 d2 += d; |
| 1405 } |
| 1406 set_partition_seg_context(cm, xd, mi_row, mi_col); |
| 1407 pl = partition_plane_context(xd, bsize); |
| 1408 if (r2 < INT_MAX) |
| 1409 r2 += x->partition_cost[pl][PARTITION_HORZ]; |
| 1410 if (RDCOST(x->rdmult, x->rddiv, r2, d2) |
| 1411 < RDCOST(x->rdmult, x->rddiv, srate, sdist)) { |
| 1412 srate = r2; |
| 1413 sdist = d2; |
| 1414 *(get_sb_partitioning(x, bsize)) = subsize; |
| 1415 } |
| 1416 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1363 } | 1417 } |
1364 | 1418 |
1365 if (RDCOST(x->rdmult, x->rddiv, r, d) < | 1419 // PARTITION_VERT |
1366 RDCOST(x->rdmult, x->rddiv, srate, sdist)) { | 1420 if (bsize >= BLOCK_SIZE_SB8X8 && mi_row + (ms >> 1) < cm->mi_rows) { |
1367 srate = r; | 1421 int r2, d2; |
1368 sdist = d; | 1422 subsize = get_subsize(bsize, PARTITION_VERT); |
1369 if (bsize >= BLOCK_SIZE_SB8X8) | 1423 *(get_sb_index(xd, subsize)) = 0; |
1370 *(get_sb_partitioning(x, bsize)) = bsize; | 1424 pick_sb_modes(cpi, mi_row, mi_col, tp, &r2, &d2, subsize, |
| 1425 get_block_context(x, subsize)); |
| 1426 if (mi_col + (ms >> 1) < cm->mi_cols) { |
| 1427 int r = 0, d = 0; |
| 1428 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
| 1429 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
| 1430 |
| 1431 *(get_sb_index(xd, subsize)) = 1; |
| 1432 pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), tp, &r, &d, subsize, |
| 1433 get_block_context(x, subsize)); |
| 1434 r2 += r; |
| 1435 d2 += d; |
| 1436 } |
| 1437 set_partition_seg_context(cm, xd, mi_row, mi_col); |
| 1438 pl = partition_plane_context(xd, bsize); |
| 1439 if (r2 < INT_MAX) |
| 1440 r2 += x->partition_cost[pl][PARTITION_VERT]; |
| 1441 if (RDCOST(x->rdmult, x->rddiv, r2, d2) |
| 1442 < RDCOST(x->rdmult, x->rddiv, srate, sdist)) { |
| 1443 srate = r2; |
| 1444 sdist = d2; |
| 1445 *(get_sb_partitioning(x, bsize)) = subsize; |
| 1446 } |
| 1447 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1448 } |
| 1449 |
| 1450 // PARTITION_NONE |
| 1451 if ((mi_row + (ms >> 1) < cm->mi_rows) && |
| 1452 (mi_col + (ms >> 1) < cm->mi_cols)) { |
| 1453 int r, d; |
| 1454 pick_sb_modes(cpi, mi_row, mi_col, tp, &r, &d, bsize, |
| 1455 get_block_context(x, bsize)); |
| 1456 if (bsize >= BLOCK_SIZE_SB8X8) { |
| 1457 set_partition_seg_context(cm, xd, mi_row, mi_col); |
| 1458 pl = partition_plane_context(xd, bsize); |
| 1459 r += x->partition_cost[pl][PARTITION_NONE]; |
| 1460 } |
| 1461 |
| 1462 if (RDCOST(x->rdmult, x->rddiv, r, d) |
| 1463 < RDCOST(x->rdmult, x->rddiv, srate, sdist)) { |
| 1464 srate = r; |
| 1465 sdist = d; |
| 1466 if (bsize >= BLOCK_SIZE_SB8X8) |
| 1467 *(get_sb_partitioning(x, bsize)) = bsize; |
| 1468 } |
1371 } | 1469 } |
1372 } | 1470 } |
1373 | |
1374 *rate = srate; | 1471 *rate = srate; |
1375 *dist = sdist; | 1472 *dist = sdist; |
1376 | 1473 |
1377 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1474 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1378 | 1475 |
1379 if (srate < INT_MAX && sdist < INT_MAX) | 1476 if (srate < INT_MAX && sdist < INT_MAX) |
1380 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_SIZE_SB64X64, bsize); | 1477 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_SIZE_SB64X64, bsize); |
1381 | 1478 |
1382 if (bsize == BLOCK_SIZE_SB64X64) { | 1479 if (bsize == BLOCK_SIZE_SB64X64) { |
1383 assert(tp_orig < *tp); | 1480 assert(tp_orig < *tp); |
1384 assert(srate < INT_MAX); | 1481 assert(srate < INT_MAX); |
1385 assert(sdist < INT_MAX); | 1482 assert(sdist < INT_MAX); |
1386 } else { | 1483 } else { |
1387 assert(tp_orig == *tp); | 1484 assert(tp_orig == *tp); |
1388 } | 1485 } |
1389 } | 1486 } |
1390 | 1487 |
1391 static void encode_sb_row(VP9_COMP *cpi, int mi_row, | 1488 static void encode_sb_row(VP9_COMP *cpi, int mi_row, TOKENEXTRA **tp, |
1392 TOKENEXTRA **tp, int *totalrate) { | 1489 int *totalrate) { |
1393 VP9_COMMON *const cm = &cpi->common; | 1490 VP9_COMMON * const cm = &cpi->common; |
1394 int mi_col; | 1491 int mi_col; |
1395 | 1492 |
1396 // Initialize the left context for the new SB row | 1493 // Initialize the left context for the new SB row |
1397 vpx_memset(&cm->left_context, 0, sizeof(cm->left_context)); | 1494 vpx_memset(&cm->left_context, 0, sizeof(cm->left_context)); |
1398 vpx_memset(cm->left_seg_context, 0, sizeof(cm->left_seg_context)); | 1495 vpx_memset(cm->left_seg_context, 0, sizeof(cm->left_seg_context)); |
1399 | 1496 |
1400 // Code each SB in the row | 1497 // Code each SB in the row |
1401 for (mi_col = cm->cur_tile_mi_col_start; | 1498 for (mi_col = cm->cur_tile_mi_col_start; mi_col < cm->cur_tile_mi_col_end; |
1402 mi_col < cm->cur_tile_mi_col_end; mi_col += 64 / MI_SIZE) { | 1499 mi_col += 64 / MI_SIZE) { |
1403 int dummy_rate, dummy_dist; | 1500 int dummy_rate, dummy_dist; |
1404 if (cpi->speed < 5) { | 1501 if (cpi->sf.partition_by_variance || cpi->sf.use_lastframe_partitioning || |
| 1502 cpi->sf.use_one_partition_size_always ) { |
| 1503 const int idx_str = cm->mode_info_stride * mi_row + mi_col; |
| 1504 MODE_INFO *m = cm->mi + idx_str; |
| 1505 MODE_INFO *p = cm->prev_mi + idx_str; |
| 1506 |
| 1507 if (cpi->sf.use_one_partition_size_always) { |
| 1508 set_offsets(cpi, mi_row, mi_col, BLOCK_SIZE_SB64X64); |
| 1509 set_partitioning(cpi, m, cpi->sf.always_this_block_size); |
| 1510 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, |
| 1511 &dummy_rate, &dummy_dist); |
| 1512 } else if (cpi->sf.partition_by_variance) { |
| 1513 choose_partitioning(cpi, cm->mi, mi_row, mi_col); |
| 1514 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, |
| 1515 &dummy_rate, &dummy_dist); |
| 1516 } else { |
| 1517 if ((cpi->common.current_video_frame & 1) == 0 || cm->prev_mi == 0 |
| 1518 || cpi->common.show_frame == 0 |
| 1519 || cpi->common.frame_type == KEY_FRAME |
| 1520 || cpi->is_src_frame_alt_ref) { |
| 1521 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, |
| 1522 &dummy_rate, &dummy_dist); |
| 1523 } else { |
| 1524 copy_partitioning(cpi, m, p); |
| 1525 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, |
| 1526 &dummy_rate, &dummy_dist); |
| 1527 } |
| 1528 } |
| 1529 } else { |
1405 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, | 1530 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, |
1406 &dummy_rate, &dummy_dist); | 1531 &dummy_rate, &dummy_dist); |
1407 } else { | |
1408 const int idx_str = cm->mode_info_stride * mi_row + mi_col; | |
1409 MODE_INFO *m = cm->mi + idx_str; | |
1410 // set_partitioning(cpi, m, BLOCK_SIZE_SB64X64); | |
1411 choose_partitioning(cpi, cm->mi, mi_row, mi_col); | |
1412 rd_use_partition(cpi, m, tp, mi_row, mi_col, BLOCK_SIZE_SB64X64, | |
1413 &dummy_rate, &dummy_dist); | |
1414 } | 1532 } |
1415 } | 1533 } |
1416 } | 1534 } |
1417 | 1535 |
1418 static void init_encode_frame_mb_context(VP9_COMP *cpi) { | 1536 static void init_encode_frame_mb_context(VP9_COMP *cpi) { |
1419 MACROBLOCK *const x = &cpi->mb; | 1537 MACROBLOCK * const x = &cpi->mb; |
1420 VP9_COMMON *const cm = &cpi->common; | 1538 VP9_COMMON * const cm = &cpi->common; |
1421 MACROBLOCKD *const xd = &x->e_mbd; | 1539 MACROBLOCKD * const xd = &x->e_mbd; |
1422 | 1540 |
1423 x->act_zbin_adj = 0; | 1541 x->act_zbin_adj = 0; |
1424 cpi->seg0_idx = 0; | 1542 cpi->seg0_idx = 0; |
1425 | 1543 |
1426 xd->mode_info_stride = cm->mode_info_stride; | 1544 xd->mode_info_stride = cm->mode_info_stride; |
1427 xd->frame_type = cm->frame_type; | 1545 xd->frame_type = cm->frame_type; |
1428 | 1546 |
1429 xd->frames_since_golden = cm->frames_since_golden; | 1547 xd->frames_since_golden = cm->frames_since_golden; |
1430 xd->frames_till_alt_ref_frame = cm->frames_till_alt_ref_frame; | 1548 xd->frames_till_alt_ref_frame = cm->frames_till_alt_ref_frame; |
1431 | 1549 |
1432 // reset intra mode contexts | 1550 // reset intra mode contexts |
1433 if (cm->frame_type == KEY_FRAME) | 1551 if (cm->frame_type == KEY_FRAME) |
1434 vp9_init_mbmode_probs(cm); | 1552 vp9_init_mbmode_probs(cm); |
1435 | 1553 |
1436 // Copy data over into macro block data structures. | 1554 // Copy data over into macro block data structures. |
1437 vp9_setup_src_planes(x, cpi->Source, 0, 0); | 1555 vp9_setup_src_planes(x, cpi->Source, 0, 0); |
1438 | 1556 |
1439 // TODO(jkoleszar): are these initializations required? | 1557 // TODO(jkoleszar): are these initializations required? |
1440 setup_pre_planes(xd, &cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]], NULL, | 1558 setup_pre_planes(xd, &cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]], NULL, |
1441 0, 0, NULL, NULL); | 1559 0, 0, NULL, NULL ); |
1442 setup_dst_planes(xd, &cm->yv12_fb[cm->new_fb_idx], 0, 0); | 1560 setup_dst_planes(xd, &cm->yv12_fb[cm->new_fb_idx], 0, 0); |
1443 | 1561 |
1444 vp9_build_block_offsets(x); | 1562 vp9_build_block_offsets(x); |
1445 | 1563 |
1446 vp9_setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); | 1564 vp9_setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); |
1447 | 1565 |
1448 xd->mode_info_context->mbmi.mode = DC_PRED; | 1566 xd->mode_info_context->mbmi.mode = DC_PRED; |
1449 xd->mode_info_context->mbmi.uv_mode = DC_PRED; | 1567 xd->mode_info_context->mbmi.uv_mode = DC_PRED; |
1450 | 1568 |
1451 vp9_zero(cpi->y_mode_count) | 1569 vp9_zero(cpi->y_mode_count) |
1452 vp9_zero(cpi->y_uv_mode_count) | 1570 vp9_zero(cpi->y_uv_mode_count) |
1453 vp9_zero(cm->fc.inter_mode_counts) | 1571 vp9_zero(cm->fc.inter_mode_counts) |
1454 vp9_zero(cpi->partition_count); | 1572 vp9_zero(cpi->partition_count); |
1455 vp9_zero(cpi->intra_inter_count); | 1573 vp9_zero(cpi->intra_inter_count); |
1456 vp9_zero(cpi->comp_inter_count); | 1574 vp9_zero(cpi->comp_inter_count); |
1457 vp9_zero(cpi->single_ref_count); | 1575 vp9_zero(cpi->single_ref_count); |
1458 vp9_zero(cpi->comp_ref_count); | 1576 vp9_zero(cpi->comp_ref_count); |
1459 vp9_zero(cm->fc.tx_count_32x32p); | 1577 vp9_zero(cm->fc.tx_count_32x32p); |
1460 vp9_zero(cm->fc.tx_count_16x16p); | 1578 vp9_zero(cm->fc.tx_count_16x16p); |
1461 vp9_zero(cm->fc.tx_count_8x8p); | 1579 vp9_zero(cm->fc.tx_count_8x8p); |
1462 vp9_zero(cm->fc.mbskip_count); | 1580 vp9_zero(cm->fc.mbskip_count); |
1463 | 1581 |
1464 // Note: this memset assumes above_context[0], [1] and [2] | 1582 // Note: this memset assumes above_context[0], [1] and [2] |
1465 // are allocated as part of the same buffer. | 1583 // are allocated as part of the same buffer. |
1466 vpx_memset(cm->above_context[0], 0, sizeof(ENTROPY_CONTEXT) * 2 * | 1584 vpx_memset( |
1467 MAX_MB_PLANE * mi_cols_aligned_to_sb(cm)); | 1585 cm->above_context[0], 0, |
1468 vpx_memset(cm->above_seg_context, 0, sizeof(PARTITION_CONTEXT) * | 1586 sizeof(ENTROPY_CONTEXT) * 2 * MAX_MB_PLANE * mi_cols_aligned_to_sb(cm)); |
1469 mi_cols_aligned_to_sb(cm)); | 1587 vpx_memset(cm->above_seg_context, 0, |
| 1588 sizeof(PARTITION_CONTEXT) * mi_cols_aligned_to_sb(cm)); |
1470 } | 1589 } |
1471 | 1590 |
1472 static void switch_lossless_mode(VP9_COMP *cpi, int lossless) { | 1591 static void switch_lossless_mode(VP9_COMP *cpi, int lossless) { |
1473 if (lossless) { | 1592 if (lossless) { |
1474 cpi->mb.fwd_txm8x4 = vp9_short_walsh8x4; | 1593 cpi->mb.fwd_txm8x4 = vp9_short_walsh8x4; |
1475 cpi->mb.fwd_txm4x4 = vp9_short_walsh4x4; | 1594 cpi->mb.fwd_txm4x4 = vp9_short_walsh4x4; |
1476 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_iwalsh4x4_1_add; | 1595 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_iwalsh4x4_1_add; |
1477 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_iwalsh4x4_add; | 1596 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_iwalsh4x4_add; |
1478 cpi->mb.optimize = 0; | 1597 cpi->mb.optimize = 0; |
1479 cpi->common.filter_level = 0; | 1598 cpi->common.filter_level = 0; |
1480 cpi->zbin_mode_boost_enabled = 0; | 1599 cpi->zbin_mode_boost_enabled = 0; |
1481 cpi->common.txfm_mode = ONLY_4X4; | 1600 cpi->common.txfm_mode = ONLY_4X4; |
1482 } else { | 1601 } else { |
1483 cpi->mb.fwd_txm8x4 = vp9_short_fdct8x4; | 1602 cpi->mb.fwd_txm8x4 = vp9_short_fdct8x4; |
1484 cpi->mb.fwd_txm4x4 = vp9_short_fdct4x4; | 1603 cpi->mb.fwd_txm4x4 = vp9_short_fdct4x4; |
1485 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_idct4x4_1_add; | 1604 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_idct4x4_1_add; |
1486 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_idct4x4_add; | 1605 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_idct4x4_add; |
1487 } | 1606 } |
1488 } | 1607 } |
1489 | 1608 |
1490 | |
1491 static void encode_frame_internal(VP9_COMP *cpi) { | 1609 static void encode_frame_internal(VP9_COMP *cpi) { |
1492 int mi_row; | 1610 int mi_row; |
1493 MACROBLOCK *const x = &cpi->mb; | 1611 MACROBLOCK * const x = &cpi->mb; |
1494 VP9_COMMON *const cm = &cpi->common; | 1612 VP9_COMMON * const cm = &cpi->common; |
1495 MACROBLOCKD *const xd = &x->e_mbd; | 1613 MACROBLOCKD * const xd = &x->e_mbd; |
1496 int totalrate; | 1614 int totalrate; |
1497 | 1615 |
1498 // fprintf(stderr, "encode_frame_internal frame %d (%d) type %d\n", | 1616 // fprintf(stderr, "encode_frame_internal frame %d (%d) type %d\n", |
1499 // cpi->common.current_video_frame, cpi->common.show_frame, | 1617 // cpi->common.current_video_frame, cpi->common.show_frame, |
1500 // cm->frame_type); | 1618 // cm->frame_type); |
1501 | 1619 |
1502 // debug output | 1620 // debug output |
1503 #if DBG_PRNT_SEGMAP | 1621 #if DBG_PRNT_SEGMAP |
1504 { | 1622 { |
1505 FILE *statsfile; | 1623 FILE *statsfile; |
(...skipping 11 matching lines...) Expand all Loading... |
1517 vp9_zero(cm->fc.switchable_interp_count); | 1635 vp9_zero(cm->fc.switchable_interp_count); |
1518 vp9_zero(cpi->best_switchable_interp_count); | 1636 vp9_zero(cpi->best_switchable_interp_count); |
1519 | 1637 |
1520 xd->mode_info_context = cm->mi; | 1638 xd->mode_info_context = cm->mi; |
1521 xd->prev_mode_info_context = cm->prev_mi; | 1639 xd->prev_mode_info_context = cm->prev_mi; |
1522 | 1640 |
1523 vp9_zero(cpi->NMVcount); | 1641 vp9_zero(cpi->NMVcount); |
1524 vp9_zero(cpi->coef_counts); | 1642 vp9_zero(cpi->coef_counts); |
1525 vp9_zero(cm->fc.eob_branch_counts); | 1643 vp9_zero(cm->fc.eob_branch_counts); |
1526 | 1644 |
1527 cpi->mb.e_mbd.lossless = cm->base_qindex == 0 && | 1645 cpi->mb.e_mbd.lossless = cm->base_qindex == 0 && cm->y_dc_delta_q == 0 |
1528 cm->y_dc_delta_q == 0 && | 1646 && cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; |
1529 cm->uv_dc_delta_q == 0 && | |
1530 cm->uv_ac_delta_q == 0; | |
1531 switch_lossless_mode(cpi, cpi->mb.e_mbd.lossless); | 1647 switch_lossless_mode(cpi, cpi->mb.e_mbd.lossless); |
1532 | 1648 |
1533 vp9_frame_init_quantizer(cpi); | 1649 vp9_frame_init_quantizer(cpi); |
1534 | 1650 |
1535 vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y_dc_delta_q); | 1651 vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y_dc_delta_q); |
1536 vp9_initialize_me_consts(cpi, cm->base_qindex); | 1652 vp9_initialize_me_consts(cpi, cm->base_qindex); |
1537 | 1653 |
1538 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 1654 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
1539 // Initialize encode frame context. | 1655 // Initialize encode frame context. |
1540 init_encode_frame_mb_context(cpi); | 1656 init_encode_frame_mb_context(cpi); |
1541 | 1657 |
1542 // Build a frame level activity map | 1658 // Build a frame level activity map |
1543 build_activity_map(cpi); | 1659 build_activity_map(cpi); |
1544 } | 1660 } |
1545 | 1661 |
1546 // re-initencode frame context. | 1662 // re-initencode frame context. |
1547 init_encode_frame_mb_context(cpi); | 1663 init_encode_frame_mb_context(cpi); |
1548 | 1664 |
1549 vpx_memset(cpi->rd_comp_pred_diff, 0, sizeof(cpi->rd_comp_pred_diff)); | 1665 vpx_memset(cpi->rd_comp_pred_diff, 0, sizeof(cpi->rd_comp_pred_diff)); |
1550 vpx_memset(cpi->rd_tx_select_diff, 0, sizeof(cpi->rd_tx_select_diff)); | 1666 vpx_memset(cpi->rd_tx_select_diff, 0, sizeof(cpi->rd_tx_select_diff)); |
1551 vpx_memset(cpi->rd_tx_select_threshes, 0, sizeof(cpi->rd_tx_select_threshes)); | 1667 vpx_memset(cpi->rd_tx_select_threshes, 0, sizeof(cpi->rd_tx_select_threshes)); |
1552 | 1668 |
1553 set_prev_mi(cm); | 1669 set_prev_mi(cm); |
1554 | 1670 |
1555 { | 1671 { |
1556 struct vpx_usec_timer emr_timer; | 1672 struct vpx_usec_timer emr_timer; |
1557 vpx_usec_timer_start(&emr_timer); | 1673 vpx_usec_timer_start(&emr_timer); |
1558 | 1674 |
1559 { | 1675 { |
1560 // Take tiles into account and give start/end MB | 1676 // Take tiles into account and give start/end MB |
1561 int tile_col, tile_row; | 1677 int tile_col, tile_row; |
1562 TOKENEXTRA *tp = cpi->tok; | 1678 TOKENEXTRA *tp = cpi->tok; |
1563 | 1679 |
1564 for (tile_row = 0; tile_row < cm->tile_rows; tile_row++) { | 1680 for (tile_row = 0; tile_row < cm->tile_rows; tile_row++) { |
1565 vp9_get_tile_row_offsets(cm, tile_row); | 1681 vp9_get_tile_row_offsets(cm, tile_row); |
1566 | 1682 |
1567 for (tile_col = 0; tile_col < cm->tile_columns; tile_col++) { | 1683 for (tile_col = 0; tile_col < cm->tile_columns; tile_col++) { |
1568 TOKENEXTRA *tp_old = tp; | 1684 TOKENEXTRA *tp_old = tp; |
1569 | 1685 |
1570 // For each row of SBs in the frame | 1686 // For each row of SBs in the frame |
1571 vp9_get_tile_col_offsets(cm, tile_col); | 1687 vp9_get_tile_col_offsets(cm, tile_col); |
1572 for (mi_row = cm->cur_tile_mi_row_start; | 1688 for (mi_row = cm->cur_tile_mi_row_start; |
1573 mi_row < cm->cur_tile_mi_row_end; | 1689 mi_row < cm->cur_tile_mi_row_end; mi_row += 8) |
1574 mi_row += 8) | |
1575 encode_sb_row(cpi, mi_row, &tp, &totalrate); | 1690 encode_sb_row(cpi, mi_row, &tp, &totalrate); |
| 1691 |
1576 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); | 1692 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); |
1577 assert(tp - cpi->tok <= | 1693 assert(tp - cpi->tok <= |
1578 get_token_alloc(cm->mb_rows, cm->mb_cols)); | 1694 get_token_alloc(cm->mb_rows, cm->mb_cols)); |
1579 } | 1695 } |
1580 } | 1696 } |
1581 } | 1697 } |
1582 | 1698 |
1583 vpx_usec_timer_mark(&emr_timer); | 1699 vpx_usec_timer_mark(&emr_timer); |
1584 cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer); | 1700 cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer); |
1585 } | 1701 } |
1586 | 1702 |
1587 // 256 rate units to the bit, | 1703 // 256 rate units to the bit, |
1588 // projected_frame_size in units of BYTES | 1704 // projected_frame_size in units of BYTES |
1589 cpi->projected_frame_size = totalrate >> 8; | 1705 cpi->projected_frame_size = totalrate >> 8; |
1590 | 1706 |
1591 #if 0 | 1707 #if 0 |
1592 // Keep record of the total distortion this time around for future use | 1708 // Keep record of the total distortion this time around for future use |
1593 cpi->last_frame_distortion = cpi->frame_distortion; | 1709 cpi->last_frame_distortion = cpi->frame_distortion; |
1594 #endif | 1710 #endif |
1595 | 1711 |
1596 } | 1712 } |
1597 | 1713 |
1598 static int check_dual_ref_flags(VP9_COMP *cpi) { | 1714 static int check_dual_ref_flags(VP9_COMP *cpi) { |
1599 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 1715 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
1600 int ref_flags = cpi->ref_frame_flags; | 1716 int ref_flags = cpi->ref_frame_flags; |
1601 | 1717 |
1602 if (vp9_segfeature_active(xd, 1, SEG_LVL_REF_FRAME)) { | 1718 if (vp9_segfeature_active(xd, 1, SEG_LVL_REF_FRAME)) { |
1603 return 0; | 1719 return 0; |
1604 } else { | 1720 } else { |
1605 return (!!(ref_flags & VP9_GOLD_FLAG) + | 1721 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) |
1606 !!(ref_flags & VP9_LAST_FLAG) + | 1722 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; |
1607 !!(ref_flags & VP9_ALT_FLAG)) >= 2; | |
1608 } | 1723 } |
1609 } | 1724 } |
1610 | 1725 |
1611 static int get_skip_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs) { | 1726 static int get_skip_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs) { |
1612 int x, y; | 1727 int x, y; |
1613 | 1728 |
1614 for (y = 0; y < ymbs; y++) { | 1729 for (y = 0; y < ymbs; y++) { |
1615 for (x = 0; x < xmbs; x++) { | 1730 for (x = 0; x < xmbs; x++) { |
1616 if (!mi[y * mis + x].mbmi.mb_skip_coeff) | 1731 if (!mi[y * mis + x].mbmi.mb_skip_coeff) |
1617 return 0; | 1732 return 0; |
1618 } | 1733 } |
1619 } | 1734 } |
1620 | 1735 |
1621 return 1; | 1736 return 1; |
1622 } | 1737 } |
1623 | 1738 |
1624 static void set_txfm_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs, | 1739 static void set_txfm_flag(MODE_INFO *mi, int mis, int ymbs, int xmbs, |
1625 TX_SIZE txfm_size) { | 1740 TX_SIZE txfm_size) { |
1626 int x, y; | 1741 int x, y; |
1627 | 1742 |
1628 for (y = 0; y < ymbs; y++) { | 1743 for (y = 0; y < ymbs; y++) { |
1629 for (x = 0; x < xmbs; x++) | 1744 for (x = 0; x < xmbs; x++) |
1630 mi[y * mis + x].mbmi.txfm_size = txfm_size; | 1745 mi[y * mis + x].mbmi.txfm_size = txfm_size; |
1631 } | 1746 } |
1632 } | 1747 } |
1633 | 1748 |
1634 static void reset_skip_txfm_size_b(VP9_COMP *cpi, MODE_INFO *mi, | 1749 static void reset_skip_txfm_size_b(VP9_COMP *cpi, MODE_INFO *mi, int mis, |
1635 int mis, TX_SIZE txfm_max, | 1750 TX_SIZE txfm_max, int bw, int bh, int mi_row, |
1636 int bw, int bh, int mi_row, int mi_col, | 1751 int mi_col, BLOCK_SIZE_TYPE bsize) { |
1637 BLOCK_SIZE_TYPE bsize) { | 1752 VP9_COMMON * const cm = &cpi->common; |
1638 VP9_COMMON *const cm = &cpi->common; | 1753 MB_MODE_INFO * const mbmi = &mi->mbmi; |
1639 MB_MODE_INFO *const mbmi = &mi->mbmi; | |
1640 | 1754 |
1641 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 1755 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
1642 return; | 1756 return; |
1643 | 1757 |
1644 if (mbmi->txfm_size > txfm_max) { | 1758 if (mbmi->txfm_size > txfm_max) { |
1645 MACROBLOCK *const x = &cpi->mb; | 1759 MACROBLOCK * const x = &cpi->mb; |
1646 MACROBLOCKD *const xd = &x->e_mbd; | 1760 MACROBLOCKD * const xd = &x->e_mbd; |
1647 const int segment_id = mbmi->segment_id; | 1761 const int segment_id = mbmi->segment_id; |
1648 const int ymbs = MIN(bh, cm->mi_rows - mi_row); | 1762 const int ymbs = MIN(bh, cm->mi_rows - mi_row); |
1649 const int xmbs = MIN(bw, cm->mi_cols - mi_col); | 1763 const int xmbs = MIN(bw, cm->mi_cols - mi_col); |
1650 | 1764 |
1651 xd->mode_info_context = mi; | 1765 xd->mode_info_context = mi; |
1652 assert(vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP) || | 1766 assert( |
1653 get_skip_flag(mi, mis, ymbs, xmbs)); | 1767 vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP) || get_skip_flag(mi,
mis, ymbs, xmbs)); |
1654 set_txfm_flag(mi, mis, ymbs, xmbs, txfm_max); | 1768 set_txfm_flag(mi, mis, ymbs, xmbs, txfm_max); |
1655 } | 1769 } |
1656 } | 1770 } |
1657 | 1771 |
1658 static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO *mi, | 1772 static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO *mi, |
1659 TX_SIZE txfm_max, | 1773 TX_SIZE txfm_max, int mi_row, int mi_col, |
1660 int mi_row, int mi_col, | |
1661 BLOCK_SIZE_TYPE bsize) { | 1774 BLOCK_SIZE_TYPE bsize) { |
1662 VP9_COMMON *const cm = &cpi->common; | 1775 VP9_COMMON * const cm = &cpi->common; |
1663 const int mis = cm->mode_info_stride; | 1776 const int mis = cm->mode_info_stride; |
1664 int bwl, bhl; | 1777 int bwl, bhl; |
1665 const int bsl = mi_width_log2(bsize), bs = 1 << (bsl - 1); | 1778 const int bsl = mi_width_log2(bsize), bs = 1 << (bsl - 1); |
1666 | 1779 |
1667 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 1780 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
1668 return; | 1781 return; |
1669 | 1782 |
1670 bwl = mi_width_log2(mi->mbmi.sb_type); | 1783 bwl = mi_width_log2(mi->mbmi.sb_type); |
1671 bhl = mi_height_log2(mi->mbmi.sb_type); | 1784 bhl = mi_height_log2(mi->mbmi.sb_type); |
1672 | 1785 |
1673 if (bwl == bsl && bhl == bsl) { | 1786 if (bwl == bsl && bhl == bsl) { |
1674 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, 1 << bsl, 1 << bsl, | 1787 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, 1 << bsl, 1 << bsl, mi_row, |
1675 mi_row, mi_col, bsize); | 1788 mi_col, bsize); |
1676 } else if (bwl == bsl && bhl < bsl) { | 1789 } else if (bwl == bsl && bhl < bsl) { |
1677 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, 1 << bsl, bs, | 1790 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, 1 << bsl, bs, mi_row, mi_col, |
1678 mi_row, mi_col, bsize); | 1791 bsize); |
1679 reset_skip_txfm_size_b(cpi, mi + bs * mis, mis, txfm_max, 1 << bsl, bs, | 1792 reset_skip_txfm_size_b(cpi, mi + bs * mis, mis, txfm_max, 1 << bsl, bs, |
1680 mi_row + bs, mi_col, bsize); | 1793 mi_row + bs, mi_col, bsize); |
1681 } else if (bwl < bsl && bhl == bsl) { | 1794 } else if (bwl < bsl && bhl == bsl) { |
1682 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, bs, 1 << bsl, | 1795 reset_skip_txfm_size_b(cpi, mi, mis, txfm_max, bs, 1 << bsl, mi_row, mi_col, |
1683 mi_row, mi_col, bsize); | 1796 bsize); |
1684 reset_skip_txfm_size_b(cpi, mi + bs, mis, txfm_max, bs, 1 << bsl, | 1797 reset_skip_txfm_size_b(cpi, mi + bs, mis, txfm_max, bs, 1 << bsl, mi_row, |
1685 mi_row, mi_col + bs, bsize); | 1798 mi_col + bs, bsize); |
1686 } else { | 1799 } else { |
1687 BLOCK_SIZE_TYPE subsize; | 1800 BLOCK_SIZE_TYPE subsize; |
1688 int n; | 1801 int n; |
1689 | 1802 |
1690 assert(bwl < bsl && bhl < bsl); | 1803 assert(bwl < bsl && bhl < bsl); |
1691 if (bsize == BLOCK_SIZE_SB64X64) { | 1804 if (bsize == BLOCK_SIZE_SB64X64) { |
1692 subsize = BLOCK_SIZE_SB32X32; | 1805 subsize = BLOCK_SIZE_SB32X32; |
1693 } else if (bsize == BLOCK_SIZE_SB32X32) { | 1806 } else if (bsize == BLOCK_SIZE_SB32X32) { |
1694 subsize = BLOCK_SIZE_MB16X16; | 1807 subsize = BLOCK_SIZE_MB16X16; |
1695 } else { | 1808 } else { |
1696 assert(bsize == BLOCK_SIZE_MB16X16); | 1809 assert(bsize == BLOCK_SIZE_MB16X16); |
1697 subsize = BLOCK_SIZE_SB8X8; | 1810 subsize = BLOCK_SIZE_SB8X8; |
1698 } | 1811 } |
1699 | 1812 |
1700 for (n = 0; n < 4; n++) { | 1813 for (n = 0; n < 4; n++) { |
1701 const int y_idx = n >> 1, x_idx = n & 0x01; | 1814 const int y_idx = n >> 1, x_idx = n & 0x01; |
1702 | 1815 |
1703 reset_skip_txfm_size_sb(cpi, mi + y_idx * bs * mis + x_idx * bs, | 1816 reset_skip_txfm_size_sb(cpi, mi + y_idx * bs * mis + x_idx * bs, txfm_max, |
1704 txfm_max, mi_row + y_idx * bs, | 1817 mi_row + y_idx * bs, mi_col + x_idx * bs, |
1705 mi_col + x_idx * bs, subsize); | 1818 subsize); |
1706 } | 1819 } |
1707 } | 1820 } |
1708 } | 1821 } |
1709 | 1822 |
1710 static void reset_skip_txfm_size(VP9_COMP *cpi, TX_SIZE txfm_max) { | 1823 static void reset_skip_txfm_size(VP9_COMP *cpi, TX_SIZE txfm_max) { |
1711 VP9_COMMON *const cm = &cpi->common; | 1824 VP9_COMMON * const cm = &cpi->common; |
1712 int mi_row, mi_col; | 1825 int mi_row, mi_col; |
1713 const int mis = cm->mode_info_stride; | 1826 const int mis = cm->mode_info_stride; |
1714 MODE_INFO *mi, *mi_ptr = cm->mi; | 1827 MODE_INFO *mi, *mi_ptr = cm->mi; |
1715 | 1828 |
1716 for (mi_row = 0; mi_row < cm->mi_rows; | 1829 for (mi_row = 0; mi_row < cm->mi_rows; mi_row += 8, mi_ptr += 8 * mis) { |
1717 mi_row += 8, mi_ptr += 8 * mis) { | |
1718 mi = mi_ptr; | 1830 mi = mi_ptr; |
1719 for (mi_col = 0; mi_col < cm->mi_cols; | 1831 for (mi_col = 0; mi_col < cm->mi_cols; mi_col += 8, mi += 8) { |
1720 mi_col += 8, mi += 8) { | 1832 reset_skip_txfm_size_sb(cpi, mi, txfm_max, mi_row, mi_col, |
1721 reset_skip_txfm_size_sb(cpi, mi, txfm_max, | 1833 BLOCK_SIZE_SB64X64); |
1722 mi_row, mi_col, BLOCK_SIZE_SB64X64); | |
1723 } | 1834 } |
1724 } | 1835 } |
1725 } | 1836 } |
1726 | 1837 |
1727 void vp9_encode_frame(VP9_COMP *cpi) { | 1838 void vp9_encode_frame(VP9_COMP *cpi) { |
1728 VP9_COMMON *const cm = &cpi->common; | 1839 VP9_COMMON * const cm = &cpi->common; |
1729 | 1840 |
1730 // In the longer term the encoder should be generalized to match the | 1841 // In the longer term the encoder should be generalized to match the |
1731 // decoder such that we allow compound where one of the 3 buffers has a | 1842 // decoder such that we allow compound where one of the 3 buffers has a |
1732 // differnt sign bias and that buffer is then the fixed ref. However, this | 1843 // differnt sign bias and that buffer is then the fixed ref. However, this |
1733 // requires further work in the rd loop. For now the only supported encoder | 1844 // requires further work in the rd loop. For now the only supported encoder |
1734 // side behaviour is where the ALT ref buffer has oppositie sign bias to | 1845 // side behaviour is where the ALT ref buffer has oppositie sign bias to |
1735 // the other two. | 1846 // the other two. |
1736 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] == | 1847 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] |
1737 cm->ref_frame_sign_bias[GOLDEN_FRAME]) || | 1848 == cm->ref_frame_sign_bias[GOLDEN_FRAME]) |
1738 (cm->ref_frame_sign_bias[ALTREF_FRAME] == | 1849 || (cm->ref_frame_sign_bias[ALTREF_FRAME] |
1739 cm->ref_frame_sign_bias[LAST_FRAME])) { | 1850 == cm->ref_frame_sign_bias[LAST_FRAME])) { |
1740 cm->allow_comp_inter_inter = 0; | 1851 cm->allow_comp_inter_inter = 0; |
1741 } else { | 1852 } else { |
1742 cm->allow_comp_inter_inter = 1; | 1853 cm->allow_comp_inter_inter = 1; |
1743 cm->comp_fixed_ref = ALTREF_FRAME; | 1854 cm->comp_fixed_ref = ALTREF_FRAME; |
1744 cm->comp_var_ref[0] = LAST_FRAME; | 1855 cm->comp_var_ref[0] = LAST_FRAME; |
1745 cm->comp_var_ref[1] = GOLDEN_FRAME; | 1856 cm->comp_var_ref[1] = GOLDEN_FRAME; |
1746 } | 1857 } |
1747 | 1858 |
1748 if (cpi->sf.RD) { | 1859 if (cpi->sf.RD) { |
1749 int i, frame_type, pred_type; | 1860 int i, frame_type, pred_type; |
(...skipping 13 matching lines...) Expand all Loading... |
1763 else if (cpi->is_src_frame_alt_ref && cpi->refresh_golden_frame) | 1874 else if (cpi->is_src_frame_alt_ref && cpi->refresh_golden_frame) |
1764 frame_type = 3; | 1875 frame_type = 3; |
1765 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) | 1876 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) |
1766 frame_type = 1; | 1877 frame_type = 1; |
1767 else | 1878 else |
1768 frame_type = 2; | 1879 frame_type = 2; |
1769 | 1880 |
1770 /* prediction (compound, single or hybrid) mode selection */ | 1881 /* prediction (compound, single or hybrid) mode selection */ |
1771 if (frame_type == 3 || !cm->allow_comp_inter_inter) | 1882 if (frame_type == 3 || !cm->allow_comp_inter_inter) |
1772 pred_type = SINGLE_PREDICTION_ONLY; | 1883 pred_type = SINGLE_PREDICTION_ONLY; |
1773 else if (cpi->rd_prediction_type_threshes[frame_type][1] > | 1884 else if (cpi->rd_prediction_type_threshes[frame_type][1] |
1774 cpi->rd_prediction_type_threshes[frame_type][0] && | 1885 > cpi->rd_prediction_type_threshes[frame_type][0] |
1775 cpi->rd_prediction_type_threshes[frame_type][1] > | 1886 && cpi->rd_prediction_type_threshes[frame_type][1] |
1776 cpi->rd_prediction_type_threshes[frame_type][2] && | 1887 > cpi->rd_prediction_type_threshes[frame_type][2] |
1777 check_dual_ref_flags(cpi) && cpi->static_mb_pct == 100) | 1888 && check_dual_ref_flags(cpi) && cpi->static_mb_pct == 100) |
1778 pred_type = COMP_PREDICTION_ONLY; | 1889 pred_type = COMP_PREDICTION_ONLY; |
1779 else if (cpi->rd_prediction_type_threshes[frame_type][0] > | 1890 else if (cpi->rd_prediction_type_threshes[frame_type][0] |
1780 cpi->rd_prediction_type_threshes[frame_type][2]) | 1891 > cpi->rd_prediction_type_threshes[frame_type][2]) |
1781 pred_type = SINGLE_PREDICTION_ONLY; | 1892 pred_type = SINGLE_PREDICTION_ONLY; |
1782 else | 1893 else |
1783 pred_type = HYBRID_PREDICTION; | 1894 pred_type = HYBRID_PREDICTION; |
1784 | 1895 |
1785 /* transform size (4x4, 8x8, 16x16 or select-per-mb) selection */ | 1896 /* transform size (4x4, 8x8, 16x16 or select-per-mb) selection */ |
1786 | 1897 |
1787 cpi->mb.e_mbd.lossless = 0; | 1898 cpi->mb.e_mbd.lossless = 0; |
1788 if (cpi->oxcf.lossless) { | 1899 if (cpi->oxcf.lossless) { |
1789 txfm_type = ONLY_4X4; | 1900 txfm_type = ONLY_4X4; |
1790 cpi->mb.e_mbd.lossless = 1; | 1901 cpi->mb.e_mbd.lossless = 1; |
1791 } else | 1902 } else |
1792 #if 0 | 1903 #if 0 |
1793 /* FIXME (rbultje): this code is disabled until we support cost updates | 1904 /* FIXME (rbultje): this code is disabled until we support cost updates |
1794 * while a frame is being encoded; the problem is that each time we | 1905 * while a frame is being encoded; the problem is that each time we |
1795 * "revert" to 4x4 only (or even 8x8 only), the coefficient probabilities | 1906 * "revert" to 4x4 only (or even 8x8 only), the coefficient probabilities |
1796 * for 16x16 (and 8x8) start lagging behind, thus leading to them lagging | 1907 * for 16x16 (and 8x8) start lagging behind, thus leading to them lagging |
1797 * further behind and not being chosen for subsequent frames either. This | 1908 * further behind and not being chosen for subsequent frames either. This |
1798 * is essentially a local minimum problem that we can probably fix by | 1909 * is essentially a local minimum problem that we can probably fix by |
1799 * estimating real costs more closely within a frame, perhaps by re- | 1910 * estimating real costs more closely within a frame, perhaps by re- |
1800 * calculating costs on-the-fly as frame encoding progresses. */ | 1911 * calculating costs on-the-fly as frame encoding progresses. */ |
1801 if (cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] > | 1912 if (cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] > |
1802 cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] && | 1913 cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] && |
1803 cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] > | 1914 cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] > |
1804 cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] && | 1915 cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] && |
1805 cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] > | 1916 cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] > |
1806 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8]) { | 1917 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8]) { |
1807 txfm_type = TX_MODE_SELECT; | 1918 txfm_type = TX_MODE_SELECT; |
1808 } else if (cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] > | 1919 } else if (cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] > |
1809 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8] | 1920 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8] |
1810 && cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] > | 1921 && cpi->rd_tx_select_threshes[frame_type][ONLY_4X4] > |
1811 cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] | 1922 cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] |
1812 ) { | 1923 ) { |
1813 txfm_type = ONLY_4X4; | 1924 txfm_type = ONLY_4X4; |
1814 } else if (cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] >= | 1925 } else if (cpi->rd_tx_select_threshes[frame_type][ALLOW_16X16] >= |
1815 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8]) { | 1926 cpi->rd_tx_select_threshes[frame_type][ALLOW_8X8]) { |
1816 txfm_type = ALLOW_16X16; | 1927 txfm_type = ALLOW_16X16; |
1817 } else | 1928 } else |
1818 txfm_type = ALLOW_8X8; | 1929 txfm_type = ALLOW_8X8; |
1819 #else | 1930 #else |
1820 txfm_type = cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] > | 1931 txfm_type = |
1821 cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? | 1932 cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] |
1822 ALLOW_32X32 : TX_MODE_SELECT; | 1933 > cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? |
| 1934 ALLOW_32X32 : TX_MODE_SELECT; |
1823 #endif | 1935 #endif |
1824 cpi->common.txfm_mode = txfm_type; | 1936 cpi->common.txfm_mode = txfm_type; |
1825 cpi->common.comp_pred_mode = pred_type; | 1937 cpi->common.comp_pred_mode = pred_type; |
1826 encode_frame_internal(cpi); | 1938 encode_frame_internal(cpi); |
1827 | 1939 |
1828 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { | 1940 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { |
1829 const int diff = (int)(cpi->rd_comp_pred_diff[i] / cpi->common.MBs); | 1941 const int diff = (int) (cpi->rd_comp_pred_diff[i] / cpi->common.MBs); |
1830 cpi->rd_prediction_type_threshes[frame_type][i] += diff; | 1942 cpi->rd_prediction_type_threshes[frame_type][i] += diff; |
1831 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; | 1943 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; |
1832 } | 1944 } |
1833 | 1945 |
1834 for (i = 0; i < NB_TXFM_MODES; ++i) { | 1946 for (i = 0; i < NB_TXFM_MODES; ++i) { |
1835 int64_t pd = cpi->rd_tx_select_diff[i]; | 1947 int64_t pd = cpi->rd_tx_select_diff[i]; |
1836 int diff; | 1948 int diff; |
1837 if (i == TX_MODE_SELECT) | 1949 if (i == TX_MODE_SELECT) |
1838 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, | 1950 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, |
1839 2048 * (TX_SIZE_MAX_SB - 1), 0); | 1951 2048 * (TX_SIZE_MAX_SB - 1), 0); |
1840 diff = (int)(pd / cpi->common.MBs); | 1952 diff = (int) (pd / cpi->common.MBs); |
1841 cpi->rd_tx_select_threshes[frame_type][i] += diff; | 1953 cpi->rd_tx_select_threshes[frame_type][i] += diff; |
1842 cpi->rd_tx_select_threshes[frame_type][i] /= 2; | 1954 cpi->rd_tx_select_threshes[frame_type][i] /= 2; |
1843 } | 1955 } |
1844 | 1956 |
1845 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { | 1957 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { |
1846 int single_count_zero = 0; | 1958 int single_count_zero = 0; |
1847 int comp_count_zero = 0; | 1959 int comp_count_zero = 0; |
1848 | 1960 |
1849 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { | 1961 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { |
1850 single_count_zero += cpi->comp_inter_count[i][0]; | 1962 single_count_zero += cpi->comp_inter_count[i][0]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 | 1995 |
1884 for (i = 0; i < TX_SIZE_CONTEXTS; i++) | 1996 for (i = 0; i < TX_SIZE_CONTEXTS; i++) |
1885 count16x16_16x16p += cm->fc.tx_count_16x16p[i][TX_16X16]; | 1997 count16x16_16x16p += cm->fc.tx_count_16x16p[i][TX_16X16]; |
1886 | 1998 |
1887 for (i = 0; i < TX_SIZE_CONTEXTS; i++) | 1999 for (i = 0; i < TX_SIZE_CONTEXTS; i++) |
1888 count16x16_lp += cm->fc.tx_count_32x32p[i][TX_16X16]; | 2000 count16x16_lp += cm->fc.tx_count_32x32p[i][TX_16X16]; |
1889 | 2001 |
1890 for (i = 0; i < TX_SIZE_CONTEXTS; i++) | 2002 for (i = 0; i < TX_SIZE_CONTEXTS; i++) |
1891 count32x32 += cm->fc.tx_count_32x32p[i][TX_32X32]; | 2003 count32x32 += cm->fc.tx_count_32x32p[i][TX_32X32]; |
1892 | 2004 |
1893 if (count4x4 == 0 && count16x16_lp == 0 && count16x16_16x16p == 0 && | 2005 if (count4x4 == 0 && count16x16_lp == 0 && count16x16_16x16p == 0 |
1894 count32x32 == 0) { | 2006 && count32x32 == 0) { |
1895 cpi->common.txfm_mode = ALLOW_8X8; | 2007 cpi->common.txfm_mode = ALLOW_8X8; |
1896 reset_skip_txfm_size(cpi, TX_8X8); | 2008 reset_skip_txfm_size(cpi, TX_8X8); |
1897 } else if (count8x8_8x8p == 0 && count16x16_16x16p == 0 && | 2009 } else if (count8x8_8x8p == 0 && count16x16_16x16p == 0 |
1898 count8x8_lp == 0 && count16x16_lp == 0 && count32x32 == 0) { | 2010 && count8x8_lp == 0 && count16x16_lp == 0 && count32x32 == 0) { |
1899 cpi->common.txfm_mode = ONLY_4X4; | 2011 cpi->common.txfm_mode = ONLY_4X4; |
1900 reset_skip_txfm_size(cpi, TX_4X4); | 2012 reset_skip_txfm_size(cpi, TX_4X4); |
1901 } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) { | 2013 } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) { |
1902 cpi->common.txfm_mode = ALLOW_32X32; | 2014 cpi->common.txfm_mode = ALLOW_32X32; |
1903 } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) { | 2015 } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) { |
1904 cpi->common.txfm_mode = ALLOW_16X16; | 2016 cpi->common.txfm_mode = ALLOW_16X16; |
1905 reset_skip_txfm_size(cpi, TX_16X16); | 2017 reset_skip_txfm_size(cpi, TX_16X16); |
1906 } | 2018 } |
1907 } | 2019 } |
1908 | 2020 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 #else | 2062 #else |
1951 int64_t a; | 2063 int64_t a; |
1952 int64_t b; | 2064 int64_t b; |
1953 int64_t act = *(x->mb_activity_ptr); | 2065 int64_t act = *(x->mb_activity_ptr); |
1954 | 2066 |
1955 // Apply the masking to the RD multiplier. | 2067 // Apply the masking to the RD multiplier. |
1956 a = act + 4 * cpi->activity_avg; | 2068 a = act + 4 * cpi->activity_avg; |
1957 b = 4 * act + cpi->activity_avg; | 2069 b = 4 * act + cpi->activity_avg; |
1958 | 2070 |
1959 if (act > cpi->activity_avg) | 2071 if (act > cpi->activity_avg) |
1960 x->act_zbin_adj = (int)(((int64_t)b + (a >> 1)) / a) - 1; | 2072 x->act_zbin_adj = (int) (((int64_t) b + (a >> 1)) / a) - 1; |
1961 else | 2073 else |
1962 x->act_zbin_adj = 1 - (int)(((int64_t)a + (b >> 1)) / b); | 2074 x->act_zbin_adj = 1 - (int) (((int64_t) a + (b >> 1)) / b); |
1963 #endif | 2075 #endif |
1964 } | 2076 } |
1965 | 2077 |
1966 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, | 2078 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
1967 int output_enabled, int mi_row, int mi_col, | 2079 int mi_row, int mi_col, BLOCK_SIZE_TYPE bsize) { |
1968 BLOCK_SIZE_TYPE bsize) { | 2080 VP9_COMMON * const cm = &cpi->common; |
1969 VP9_COMMON *const cm = &cpi->common; | 2081 MACROBLOCK * const x = &cpi->mb; |
1970 MACROBLOCK *const x = &cpi->mb; | 2082 MACROBLOCKD * const xd = &x->e_mbd; |
1971 MACROBLOCKD *const xd = &x->e_mbd; | |
1972 int n; | 2083 int n; |
1973 MODE_INFO *mi = xd->mode_info_context; | 2084 MODE_INFO *mi = xd->mode_info_context; |
1974 MB_MODE_INFO *mbmi = &mi->mbmi; | 2085 MB_MODE_INFO *mbmi = &mi->mbmi; |
1975 unsigned int segment_id = mbmi->segment_id; | 2086 unsigned int segment_id = mbmi->segment_id; |
1976 const int mis = cm->mode_info_stride; | 2087 const int mis = cm->mode_info_stride; |
1977 const int bwl = mi_width_log2(bsize); | 2088 const int bwl = mi_width_log2(bsize); |
1978 const int bw = 1 << bwl, bh = 1 << mi_height_log2(bsize); | 2089 const int bw = 1 << bwl, bh = 1 << mi_height_log2(bsize); |
1979 x->rd_search = 0; | 2090 x->rd_search = 0; |
1980 | 2091 |
1981 if (cm->frame_type == KEY_FRAME) { | 2092 if (cm->frame_type == KEY_FRAME) { |
(...skipping 26 matching lines...) Expand all Loading... |
2008 } | 2119 } |
2009 } else { | 2120 } else { |
2010 cpi->zbin_mode_boost = INTRA_ZBIN_BOOST; | 2121 cpi->zbin_mode_boost = INTRA_ZBIN_BOOST; |
2011 } | 2122 } |
2012 } | 2123 } |
2013 | 2124 |
2014 vp9_update_zbin_extra(cpi, x); | 2125 vp9_update_zbin_extra(cpi, x); |
2015 } | 2126 } |
2016 | 2127 |
2017 if (mbmi->ref_frame[0] == INTRA_FRAME) { | 2128 if (mbmi->ref_frame[0] == INTRA_FRAME) { |
2018 vp9_encode_intra_block_y(cm, x, (bsize < BLOCK_SIZE_SB8X8) ? | 2129 vp9_encode_intra_block_y( |
2019 BLOCK_SIZE_SB8X8 : bsize); | 2130 cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); |
2020 vp9_encode_intra_block_uv(cm, x, (bsize < BLOCK_SIZE_SB8X8) ? | 2131 vp9_encode_intra_block_uv( |
2021 BLOCK_SIZE_SB8X8 : bsize); | 2132 cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); |
2022 if (output_enabled) | 2133 if (output_enabled) |
2023 sum_intra_stats(cpi, x); | 2134 sum_intra_stats(cpi, x); |
2024 } else { | 2135 } else { |
2025 int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[0])]; | 2136 int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[0])]; |
2026 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; | 2137 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; |
2027 YV12_BUFFER_CONFIG *second_ref_fb = NULL; | 2138 YV12_BUFFER_CONFIG *second_ref_fb = NULL; |
2028 if (mbmi->ref_frame[1] > 0) { | 2139 if (mbmi->ref_frame[1] > 0) { |
2029 idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[1])]; | 2140 idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[1])]; |
2030 second_ref_fb = &cm->yv12_fb[idx]; | 2141 second_ref_fb = &cm->yv12_fb[idx]; |
2031 } | 2142 } |
2032 | 2143 |
2033 assert(cm->frame_type != KEY_FRAME); | 2144 assert(cm->frame_type != KEY_FRAME); |
2034 | 2145 |
2035 setup_pre_planes(xd, ref_fb, second_ref_fb, | 2146 setup_pre_planes(xd, ref_fb, second_ref_fb, mi_row, mi_col, |
2036 mi_row, mi_col, xd->scale_factor, xd->scale_factor_uv); | 2147 xd->scale_factor, xd->scale_factor_uv); |
2037 | 2148 |
2038 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, | 2149 vp9_build_inter_predictors_sb( |
2039 bsize < BLOCK_SIZE_SB8X8 ? BLOCK_SIZE_SB8X8 | 2150 xd, mi_row, mi_col, |
2040 : bsize); | 2151 bsize < BLOCK_SIZE_SB8X8 ? BLOCK_SIZE_SB8X8 : bsize); |
2041 } | 2152 } |
2042 | 2153 |
2043 if (xd->mode_info_context->mbmi.ref_frame[0] == INTRA_FRAME) { | 2154 if (xd->mode_info_context->mbmi.ref_frame[0] == INTRA_FRAME) { |
2044 vp9_tokenize_sb(cpi, xd, t, !output_enabled, | 2155 vp9_tokenize_sb(cpi, xd, t, !output_enabled, |
2045 (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | 2156 (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); |
2046 } else if (!x->skip) { | 2157 } else if (!x->skip) { |
2047 vp9_encode_sb(cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | 2158 vp9_encode_sb(cm, x, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); |
2048 vp9_tokenize_sb(cpi, xd, t, !output_enabled, | 2159 vp9_tokenize_sb(cpi, xd, t, !output_enabled, |
2049 (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | 2160 (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); |
2050 } else { | 2161 } else { |
2051 // FIXME(rbultje): not tile-aware (mi - 1) | 2162 // FIXME(rbultje): not tile-aware (mi - 1) |
2052 int mb_skip_context = | 2163 int mb_skip_context = (mi - 1)->mbmi.mb_skip_coeff |
2053 (mi - 1)->mbmi.mb_skip_coeff + (mi - mis)->mbmi.mb_skip_coeff; | 2164 + (mi - mis)->mbmi.mb_skip_coeff; |
2054 | 2165 |
2055 mbmi->mb_skip_coeff = 1; | 2166 mbmi->mb_skip_coeff = 1; |
2056 if (output_enabled) | 2167 if (output_enabled) |
2057 cm->fc.mbskip_count[mb_skip_context][1]++; | 2168 cm->fc.mbskip_count[mb_skip_context][1]++; |
2058 vp9_reset_sb_tokens_context(xd, | 2169 vp9_reset_sb_tokens_context( |
2059 (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); | 2170 xd, (bsize < BLOCK_SIZE_SB8X8) ? BLOCK_SIZE_SB8X8 : bsize); |
2060 } | 2171 } |
2061 | 2172 |
2062 // copy skip flag on all mb_mode_info contexts in this SB | 2173 // copy skip flag on all mb_mode_info contexts in this SB |
2063 // if this was a skip at this txfm size | 2174 // if this was a skip at this txfm size |
2064 for (n = 1; n < bw * bh; n++) { | 2175 for (n = 1; n < bw * bh; n++) { |
2065 const int x_idx = n & (bw - 1), y_idx = n >> bwl; | 2176 const int x_idx = n & (bw - 1), y_idx = n >> bwl; |
2066 if (mi_col + x_idx < cm->mi_cols && mi_row + y_idx < cm->mi_rows) | 2177 if (mi_col + x_idx < cm->mi_cols && mi_row + y_idx < cm->mi_rows) |
2067 mi[x_idx + y_idx * mis].mbmi.mb_skip_coeff = mi->mbmi.mb_skip_coeff; | 2178 mi[x_idx + y_idx * mis].mbmi.mb_skip_coeff = mi->mbmi.mb_skip_coeff; |
2068 } | 2179 } |
2069 | 2180 |
2070 if (output_enabled) { | 2181 if (output_enabled) { |
2071 if (cm->txfm_mode == TX_MODE_SELECT && | 2182 if (cm->txfm_mode == TX_MODE_SELECT && mbmi->sb_type >= BLOCK_SIZE_SB8X8 |
2072 mbmi->sb_type >= BLOCK_SIZE_SB8X8 && | 2183 && !(mbmi->ref_frame[0] != INTRA_FRAME |
2073 !(mbmi->ref_frame[0] != INTRA_FRAME && (mbmi->mb_skip_coeff || | 2184 && (mbmi->mb_skip_coeff |
2074 vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP)))) { | 2185 || vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP)))) { |
2075 const int context = vp9_get_pred_context(cm, xd, PRED_TX_SIZE); | 2186 const int context = vp9_get_pred_context(cm, xd, PRED_TX_SIZE); |
2076 if (bsize >= BLOCK_SIZE_SB32X32) { | 2187 if (bsize >= BLOCK_SIZE_SB32X32) { |
2077 cm->fc.tx_count_32x32p[context][mbmi->txfm_size]++; | 2188 cm->fc.tx_count_32x32p[context][mbmi->txfm_size]++; |
2078 } else if (bsize >= BLOCK_SIZE_MB16X16) { | 2189 } else if (bsize >= BLOCK_SIZE_MB16X16) { |
2079 cm->fc.tx_count_16x16p[context][mbmi->txfm_size]++; | 2190 cm->fc.tx_count_16x16p[context][mbmi->txfm_size]++; |
2080 } else { | 2191 } else { |
2081 cm->fc.tx_count_8x8p[context][mbmi->txfm_size]++; | 2192 cm->fc.tx_count_8x8p[context][mbmi->txfm_size]++; |
2082 } | 2193 } |
2083 } else { | 2194 } else { |
2084 int x, y; | 2195 int x, y; |
2085 TX_SIZE sz = (cm->txfm_mode == TX_MODE_SELECT) ? TX_32X32 : cm->txfm_mode; | 2196 TX_SIZE sz = (cm->txfm_mode == TX_MODE_SELECT) ? TX_32X32 : cm->txfm_mode; |
2086 // The new intra coding scheme requires no change of transform size | 2197 // The new intra coding scheme requires no change of transform size |
2087 if (mi->mbmi.ref_frame[0] != INTRA_FRAME) { | 2198 if (mi->mbmi.ref_frame[0] != INTRA_FRAME) { |
2088 if (sz == TX_32X32 && bsize < BLOCK_SIZE_SB32X32) | 2199 if (sz == TX_32X32 && bsize < BLOCK_SIZE_SB32X32) |
2089 sz = TX_16X16; | 2200 sz = TX_16X16; |
2090 if (sz == TX_16X16 && bsize < BLOCK_SIZE_MB16X16) | 2201 if (sz == TX_16X16 && bsize < BLOCK_SIZE_MB16X16) |
2091 sz = TX_8X8; | 2202 sz = TX_8X8; |
2092 if (sz == TX_8X8 && bsize < BLOCK_SIZE_SB8X8) | 2203 if (sz == TX_8X8 && bsize < BLOCK_SIZE_SB8X8) |
2093 sz = TX_4X4; | 2204 sz = TX_4X4; |
2094 } else if (bsize >= BLOCK_SIZE_SB8X8) { | 2205 } else if (bsize >= BLOCK_SIZE_SB8X8) { |
2095 sz = mbmi->txfm_size; | 2206 sz = mbmi->txfm_size; |
2096 } else { | 2207 } else { |
2097 sz = TX_4X4; | 2208 sz = TX_4X4; |
2098 } | 2209 } |
2099 | 2210 |
2100 for (y = 0; y < bh; y++) { | 2211 for (y = 0; y < bh; y++) { |
2101 for (x = 0; x < bw; x++) { | 2212 for (x = 0; x < bw; x++) { |
2102 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) { | 2213 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) { |
2103 mi[mis * y + x].mbmi.txfm_size = sz; | 2214 mi[mis * y + x].mbmi.txfm_size = sz; |
2104 } | 2215 } |
2105 } | 2216 } |
2106 } | 2217 } |
2107 } | 2218 } |
2108 } | 2219 } |
2109 } | 2220 } |
OLD | NEW |