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 #include <limits.h> | 11 #include <limits.h> |
12 #include <math.h> | 12 #include <math.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 | 14 |
15 #include "./vp9_rtcd.h" | 15 #include "./vp9_rtcd.h" |
16 #include "./vpx_config.h" | 16 #include "./vpx_config.h" |
17 | 17 |
18 #include "vpx_ports/vpx_timer.h" | 18 #include "vpx_ports/vpx_timer.h" |
19 | 19 |
20 #include "vp9/common/vp9_common.h" | 20 #include "vp9/common/vp9_common.h" |
21 #include "vp9/common/vp9_entropy.h" | 21 #include "vp9/common/vp9_entropy.h" |
22 #include "vp9/common/vp9_entropymode.h" | 22 #include "vp9/common/vp9_entropymode.h" |
23 #include "vp9/common/vp9_extend.h" | 23 #include "vp9/common/vp9_extend.h" |
24 #include "vp9/common/vp9_findnearmv.h" | 24 #include "vp9/common/vp9_findnearmv.h" |
| 25 #include "vp9/common/vp9_idct.h" |
25 #include "vp9/common/vp9_mvref_common.h" | 26 #include "vp9/common/vp9_mvref_common.h" |
26 #include "vp9/common/vp9_pred_common.h" | 27 #include "vp9/common/vp9_pred_common.h" |
27 #include "vp9/common/vp9_quant_common.h" | 28 #include "vp9/common/vp9_quant_common.h" |
28 #include "vp9/common/vp9_reconintra.h" | 29 #include "vp9/common/vp9_reconintra.h" |
29 #include "vp9/common/vp9_reconinter.h" | 30 #include "vp9/common/vp9_reconinter.h" |
30 #include "vp9/common/vp9_seg_common.h" | 31 #include "vp9/common/vp9_seg_common.h" |
31 #include "vp9/common/vp9_tile_common.h" | 32 #include "vp9/common/vp9_tile_common.h" |
32 | |
33 #include "vp9/encoder/vp9_encodeframe.h" | 33 #include "vp9/encoder/vp9_encodeframe.h" |
34 #include "vp9/encoder/vp9_encodeintra.h" | 34 #include "vp9/encoder/vp9_encodeintra.h" |
35 #include "vp9/encoder/vp9_encodemb.h" | 35 #include "vp9/encoder/vp9_encodemb.h" |
36 #include "vp9/encoder/vp9_encodemv.h" | 36 #include "vp9/encoder/vp9_encodemv.h" |
37 #include "vp9/encoder/vp9_onyx_int.h" | 37 #include "vp9/encoder/vp9_onyx_int.h" |
38 #include "vp9/encoder/vp9_rdopt.h" | 38 #include "vp9/encoder/vp9_rdopt.h" |
39 #include "vp9/encoder/vp9_segmentation.h" | 39 #include "vp9/encoder/vp9_segmentation.h" |
| 40 #include "vp9/common/vp9_systemdependent.h" |
40 #include "vp9/encoder/vp9_tokenize.h" | 41 #include "vp9/encoder/vp9_tokenize.h" |
| 42 #include "vp9/encoder/vp9_vaq.h" |
| 43 |
41 | 44 |
42 #define DBG_PRNT_SEGMAP 0 | 45 #define DBG_PRNT_SEGMAP 0 |
43 | 46 |
44 | 47 |
45 static const TX_SIZE tx_mode_to_biggest_tx_size[TX_MODES] = { | |
46 TX_4X4, // ONLY_4X4 | |
47 TX_8X8, // ONLY_8X8 | |
48 TX_16X16, // ONLY_16X16 | |
49 TX_32X32, // ONLY_32X32 | |
50 TX_32X32, // TX_MODE_SELECT | |
51 }; | |
52 | |
53 // #define ENC_DEBUG | 48 // #define ENC_DEBUG |
54 #ifdef ENC_DEBUG | 49 #ifdef ENC_DEBUG |
55 int enc_debug = 0; | 50 int enc_debug = 0; |
56 #endif | 51 #endif |
57 | 52 |
| 53 static INLINE uint8_t *get_sb_index(MACROBLOCKD *xd, BLOCK_SIZE subsize) { |
| 54 switch (subsize) { |
| 55 case BLOCK_64X64: |
| 56 case BLOCK_64X32: |
| 57 case BLOCK_32X64: |
| 58 case BLOCK_32X32: |
| 59 return &xd->sb_index; |
| 60 case BLOCK_32X16: |
| 61 case BLOCK_16X32: |
| 62 case BLOCK_16X16: |
| 63 return &xd->mb_index; |
| 64 case BLOCK_16X8: |
| 65 case BLOCK_8X16: |
| 66 case BLOCK_8X8: |
| 67 return &xd->b_index; |
| 68 case BLOCK_8X4: |
| 69 case BLOCK_4X8: |
| 70 case BLOCK_4X4: |
| 71 return &xd->ab_index; |
| 72 default: |
| 73 assert(0); |
| 74 return NULL; |
| 75 } |
| 76 } |
| 77 |
58 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, | 78 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
59 int mi_row, int mi_col, BLOCK_SIZE bsize); | 79 int mi_row, int mi_col, BLOCK_SIZE bsize); |
60 | 80 |
61 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); | 81 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); |
62 | 82 |
63 /* activity_avg must be positive, or flat regions could get a zero weight | 83 /* activity_avg must be positive, or flat regions could get a zero weight |
64 * (infinite lambda), which confounds analysis. | 84 * (infinite lambda), which confounds analysis. |
65 * This also avoids the need for divide by zero checks in | 85 * This also avoids the need for divide by zero checks in |
66 * vp9_activity_masking(). | 86 * vp9_activity_masking(). |
67 */ | 87 */ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (act < 8 << 12) | 135 if (act < 8 << 12) |
116 act = act < 5 << 12 ? act : 5 << 12; | 136 act = act < 5 << 12 ? act : 5 << 12; |
117 | 137 |
118 return act; | 138 return act; |
119 } | 139 } |
120 | 140 |
121 // Stub for alternative experimental activity measures. | 141 // Stub for alternative experimental activity measures. |
122 static unsigned int alt_activity_measure(MACROBLOCK *x, int use_dc_pred) { | 142 static unsigned int alt_activity_measure(MACROBLOCK *x, int use_dc_pred) { |
123 return vp9_encode_intra(x, use_dc_pred); | 143 return vp9_encode_intra(x, use_dc_pred); |
124 } | 144 } |
125 DECLARE_ALIGNED(16, static const uint8_t, vp9_64x64_zeros[64*64]) = {0}; | |
126 | 145 |
127 // Measure the activity of the current macroblock | 146 // Measure the activity of the current macroblock |
128 // What we measure here is TBD so abstracted to this function | 147 // What we measure here is TBD so abstracted to this function |
129 #define ALT_ACT_MEASURE 1 | 148 #define ALT_ACT_MEASURE 1 |
130 static unsigned int mb_activity_measure(MACROBLOCK *x, int mb_row, int mb_col) { | 149 static unsigned int mb_activity_measure(MACROBLOCK *x, int mb_row, int mb_col) { |
131 unsigned int mb_activity; | 150 unsigned int mb_activity; |
132 | 151 |
133 if (ALT_ACT_MEASURE) { | 152 if (ALT_ACT_MEASURE) { |
134 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); | 153 int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row); |
135 | 154 |
(...skipping 30 matching lines...) Expand all Loading... |
166 sizeof(unsigned int) * cpi->common.MBs); | 185 sizeof(unsigned int) * cpi->common.MBs); |
167 | 186 |
168 // Ripple each value down to its correct position | 187 // Ripple each value down to its correct position |
169 for (i = 1; i < cpi->common.MBs; i ++) { | 188 for (i = 1; i < cpi->common.MBs; i ++) { |
170 for (j = i; j > 0; j --) { | 189 for (j = i; j > 0; j --) { |
171 if (sortlist[j] < sortlist[j - 1]) { | 190 if (sortlist[j] < sortlist[j - 1]) { |
172 // Swap values | 191 // Swap values |
173 tmp = sortlist[j - 1]; | 192 tmp = sortlist[j - 1]; |
174 sortlist[j - 1] = sortlist[j]; | 193 sortlist[j - 1] = sortlist[j]; |
175 sortlist[j] = tmp; | 194 sortlist[j] = tmp; |
176 } else | 195 } else { |
177 break; | 196 break; |
| 197 } |
178 } | 198 } |
179 } | 199 } |
180 | 200 |
181 // Even number MBs so estimate median as mean of two either side. | 201 // Even number MBs so estimate median as mean of two either side. |
182 median = (1 + sortlist[cpi->common.MBs >> 1] + | 202 median = (1 + sortlist[cpi->common.MBs >> 1] + |
183 sortlist[(cpi->common.MBs >> 1) + 1]) >> 1; | 203 sortlist[(cpi->common.MBs >> 1) + 1]) >> 1; |
184 | 204 |
185 cpi->activity_avg = median; | 205 cpi->activity_avg = median; |
186 | 206 |
187 vpx_free(sortlist); | 207 vpx_free(sortlist); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 #if OUTPUT_NORM_ACT_STATS | 259 #if OUTPUT_NORM_ACT_STATS |
240 fprintf(f, " %6d", *(x->mb_activity_ptr)); | 260 fprintf(f, " %6d", *(x->mb_activity_ptr)); |
241 #endif | 261 #endif |
242 // Increment activity map pointers | 262 // Increment activity map pointers |
243 x->mb_activity_ptr++; | 263 x->mb_activity_ptr++; |
244 } | 264 } |
245 | 265 |
246 #if OUTPUT_NORM_ACT_STATS | 266 #if OUTPUT_NORM_ACT_STATS |
247 fprintf(f, "\n"); | 267 fprintf(f, "\n"); |
248 #endif | 268 #endif |
249 | |
250 } | 269 } |
251 | 270 |
252 #if OUTPUT_NORM_ACT_STATS | 271 #if OUTPUT_NORM_ACT_STATS |
253 fclose(f); | 272 fclose(f); |
254 #endif | 273 #endif |
255 | |
256 } | 274 } |
257 #endif // USE_ACT_INDEX | 275 #endif // USE_ACT_INDEX |
258 | 276 |
259 // Loop through all MBs. Note activity of each, average activity and | 277 // Loop through all MBs. Note activity of each, average activity and |
260 // calculate a normalized activity for each | 278 // calculate a normalized activity for each |
261 static void build_activity_map(VP9_COMP *cpi) { | 279 static void build_activity_map(VP9_COMP *cpi) { |
262 MACROBLOCK * const x = &cpi->mb; | 280 MACROBLOCK * const x = &cpi->mb; |
263 MACROBLOCKD *xd = &x->e_mbd; | 281 MACROBLOCKD *xd = &x->e_mbd; |
264 VP9_COMMON * const cm = &cpi->common; | 282 VP9_COMMON * const cm = &cpi->common; |
265 | 283 |
266 #if ALT_ACT_MEASURE | 284 #if ALT_ACT_MEASURE |
267 YV12_BUFFER_CONFIG *new_yv12 = &cm->yv12_fb[cm->new_fb_idx]; | 285 YV12_BUFFER_CONFIG *new_yv12 = get_frame_new_buffer(cm); |
268 int recon_yoffset; | 286 int recon_yoffset; |
269 int recon_y_stride = new_yv12->y_stride; | 287 int recon_y_stride = new_yv12->y_stride; |
270 #endif | 288 #endif |
271 | 289 |
272 int mb_row, mb_col; | 290 int mb_row, mb_col; |
273 unsigned int mb_activity; | 291 unsigned int mb_activity; |
274 int64_t activity_sum = 0; | 292 int64_t activity_sum = 0; |
275 | 293 |
276 x->mb_activity_ptr = cpi->mb_activity_map; | 294 x->mb_activity_ptr = cpi->mb_activity_map; |
277 | 295 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 x->plane[0].src.buf += 16 * x->plane[0].src.stride - 16 * cm->mb_cols; | 328 x->plane[0].src.buf += 16 * x->plane[0].src.stride - 16 * cm->mb_cols; |
311 } | 329 } |
312 | 330 |
313 // Calculate an "average" MB activity | 331 // Calculate an "average" MB activity |
314 calc_av_activity(cpi, activity_sum); | 332 calc_av_activity(cpi, activity_sum); |
315 | 333 |
316 #if USE_ACT_INDEX | 334 #if USE_ACT_INDEX |
317 // Calculate an activity index number of each mb | 335 // Calculate an activity index number of each mb |
318 calc_activity_index(cpi, x); | 336 calc_activity_index(cpi, x); |
319 #endif | 337 #endif |
320 | |
321 } | 338 } |
322 | 339 |
323 // Macroblock activity masking | 340 // Macroblock activity masking |
324 void vp9_activity_masking(VP9_COMP *cpi, MACROBLOCK *x) { | 341 void vp9_activity_masking(VP9_COMP *cpi, MACROBLOCK *x) { |
325 #if USE_ACT_INDEX | 342 #if USE_ACT_INDEX |
326 x->rdmult += *(x->mb_activity_ptr) * (x->rdmult >> 2); | 343 x->rdmult += *(x->mb_activity_ptr) * (x->rdmult >> 2); |
327 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); | 344 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); |
328 x->errorperbit += (x->errorperbit == 0); | 345 x->errorperbit += (x->errorperbit == 0); |
329 #else | 346 #else |
330 int64_t a; | 347 int64_t a; |
(...skipping 13 matching lines...) Expand all Loading... |
344 adjust_act_zbin(cpi, x); | 361 adjust_act_zbin(cpi, x); |
345 } | 362 } |
346 | 363 |
347 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, | 364 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
348 BLOCK_SIZE bsize, int output_enabled) { | 365 BLOCK_SIZE bsize, int output_enabled) { |
349 int i, x_idx, y; | 366 int i, x_idx, y; |
350 VP9_COMMON *const cm = &cpi->common; | 367 VP9_COMMON *const cm = &cpi->common; |
351 MACROBLOCK *const x = &cpi->mb; | 368 MACROBLOCK *const x = &cpi->mb; |
352 MACROBLOCKD *const xd = &x->e_mbd; | 369 MACROBLOCKD *const xd = &x->e_mbd; |
353 MODE_INFO *mi = &ctx->mic; | 370 MODE_INFO *mi = &ctx->mic; |
354 MB_MODE_INFO * const mbmi = &xd->this_mi->mbmi; | 371 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
355 MODE_INFO *mi_addr = xd->this_mi; | 372 MODE_INFO *mi_addr = xd->mi_8x8[0]; |
356 | 373 |
357 int mb_mode_index = ctx->best_mode_index; | 374 int mb_mode_index = ctx->best_mode_index; |
358 const int mis = cm->mode_info_stride; | 375 const int mis = cm->mode_info_stride; |
359 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 376 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
360 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 377 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
361 | 378 |
362 assert(mi->mbmi.mode < MB_MODE_COUNT); | 379 assert(mi->mbmi.mode < MB_MODE_COUNT); |
363 assert(mb_mode_index < MAX_MODES); | |
364 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); | 380 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); |
365 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); | 381 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); |
366 assert(mi->mbmi.sb_type == bsize); | 382 assert(mi->mbmi.sb_type == bsize); |
367 | 383 |
368 *mi_addr = *mi; | 384 *mi_addr = *mi; |
369 | 385 |
370 // Restore the coding context of the MB to that that was in place | 386 // Restore the coding context of the MB to that that was in place |
371 // when the mode was picked for it | 387 // when the mode was picked for it |
372 for (y = 0; y < mi_height; y++) | 388 for (y = 0; y < mi_height; y++) |
373 for (x_idx = 0; x_idx < mi_width; x_idx++) | 389 for (x_idx = 0; x_idx < mi_width; x_idx++) |
374 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx | 390 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx |
375 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) | 391 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) |
376 xd->mi_8x8[x_idx + y * mis] = mi_addr; | 392 xd->mi_8x8[x_idx + y * mis] = mi_addr; |
377 | 393 |
| 394 if (cpi->sf.variance_adaptive_quantization) { |
| 395 vp9_mb_init_quantizer(cpi, x); |
| 396 } |
| 397 |
378 // FIXME(rbultje) I'm pretty sure this should go to the end of this block | 398 // FIXME(rbultje) I'm pretty sure this should go to the end of this block |
379 // (i.e. after the output_enabled) | 399 // (i.e. after the output_enabled) |
380 if (bsize < BLOCK_32X32) { | 400 if (bsize < BLOCK_32X32) { |
381 if (bsize < BLOCK_16X16) | 401 if (bsize < BLOCK_16X16) |
382 ctx->tx_rd_diff[ALLOW_16X16] = ctx->tx_rd_diff[ALLOW_8X8]; | 402 ctx->tx_rd_diff[ALLOW_16X16] = ctx->tx_rd_diff[ALLOW_8X8]; |
383 ctx->tx_rd_diff[ALLOW_32X32] = ctx->tx_rd_diff[ALLOW_16X16]; | 403 ctx->tx_rd_diff[ALLOW_32X32] = ctx->tx_rd_diff[ALLOW_16X16]; |
384 } | 404 } |
385 | 405 |
386 if (is_inter_block(mbmi) && mbmi->sb_type < BLOCK_8X8) { | 406 if (is_inter_block(mbmi) && mbmi->sb_type < BLOCK_8X8) { |
387 *x->partition_info = ctx->partition_info; | |
388 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; | 407 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; |
389 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; | 408 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; |
390 } | 409 } |
391 | 410 |
392 x->skip = ctx->skip; | 411 x->skip = ctx->skip; |
| 412 vpx_memcpy(x->zcoeff_blk[mbmi->tx_size], ctx->zcoeff_blk, |
| 413 sizeof(uint8_t) * ctx->num_4x4_blk); |
| 414 |
393 if (!output_enabled) | 415 if (!output_enabled) |
394 return; | 416 return; |
395 | 417 |
396 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { | 418 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
397 for (i = 0; i < TX_MODES; i++) | 419 for (i = 0; i < TX_MODES; i++) |
398 cpi->rd_tx_select_diff[i] += ctx->tx_rd_diff[i]; | 420 cpi->rd_tx_select_diff[i] += ctx->tx_rd_diff[i]; |
399 } | 421 } |
400 | 422 |
401 if (cm->frame_type == KEY_FRAME) { | 423 if (frame_is_intra_only(cm)) { |
402 // Restore the coding modes to that held in the coding context | |
403 // if (mb_mode == I4X4_PRED) | |
404 // for (i = 0; i < 16; i++) | |
405 // { | |
406 // xd->block[i].bmi.as_mode = | |
407 // xd->mode_info_context->bmi[i].as_mode; | |
408 // assert(xd->mode_info_context->bmi[i].as_mode < MB_MODE_COUNT); | |
409 // } | |
410 #if CONFIG_INTERNAL_STATS | 424 #if CONFIG_INTERNAL_STATS |
411 static const int kf_mode_index[] = { | 425 static const int kf_mode_index[] = { |
412 THR_DC /*DC_PRED*/, | 426 THR_DC /*DC_PRED*/, |
413 THR_V_PRED /*V_PRED*/, | 427 THR_V_PRED /*V_PRED*/, |
414 THR_H_PRED /*H_PRED*/, | 428 THR_H_PRED /*H_PRED*/, |
415 THR_D45_PRED /*D45_PRED*/, | 429 THR_D45_PRED /*D45_PRED*/, |
416 THR_D135_PRED /*D135_PRED*/, | 430 THR_D135_PRED /*D135_PRED*/, |
417 THR_D117_PRED /*D117_PRED*/, | 431 THR_D117_PRED /*D117_PRED*/, |
418 THR_D153_PRED /*D153_PRED*/, | 432 THR_D153_PRED /*D153_PRED*/, |
419 THR_D207_PRED /*D207_PRED*/, | 433 THR_D207_PRED /*D207_PRED*/, |
420 THR_D63_PRED /*D63_PRED*/, | 434 THR_D63_PRED /*D63_PRED*/, |
421 THR_TM /*TM_PRED*/, | 435 THR_TM /*TM_PRED*/, |
422 THR_B_PRED /*I4X4_PRED*/, | |
423 }; | 436 }; |
424 cpi->mode_chosen_counts[kf_mode_index[mi->mbmi.mode]]++; | 437 cpi->mode_chosen_counts[kf_mode_index[mi->mbmi.mode]]++; |
425 #endif | 438 #endif |
426 } else { | 439 } else { |
427 // Note how often each mode chosen as best | 440 // Note how often each mode chosen as best |
428 cpi->mode_chosen_counts[mb_mode_index]++; | 441 cpi->mode_chosen_counts[mb_mode_index]++; |
429 if (is_inter_block(mbmi) | 442 if (is_inter_block(mbmi) |
430 && (mbmi->sb_type < BLOCK_8X8 || mbmi->mode == NEWMV)) { | 443 && (mbmi->sb_type < BLOCK_8X8 || mbmi->mode == NEWMV)) { |
431 int_mv best_mv, best_second_mv; | 444 int_mv best_mv[2]; |
432 const MV_REFERENCE_FRAME rf1 = mbmi->ref_frame[0]; | 445 const MV_REFERENCE_FRAME rf1 = mbmi->ref_frame[0]; |
433 const MV_REFERENCE_FRAME rf2 = mbmi->ref_frame[1]; | 446 const MV_REFERENCE_FRAME rf2 = mbmi->ref_frame[1]; |
434 best_mv.as_int = ctx->best_ref_mv.as_int; | 447 best_mv[0].as_int = ctx->best_ref_mv.as_int; |
435 best_second_mv.as_int = ctx->second_best_ref_mv.as_int; | 448 best_mv[1].as_int = ctx->second_best_ref_mv.as_int; |
436 if (mbmi->mode == NEWMV) { | 449 if (mbmi->mode == NEWMV) { |
437 best_mv.as_int = mbmi->ref_mvs[rf1][0].as_int; | 450 best_mv[0].as_int = mbmi->ref_mvs[rf1][0].as_int; |
438 best_second_mv.as_int = mbmi->ref_mvs[rf2][0].as_int; | 451 if (rf2 > 0) |
| 452 best_mv[1].as_int = mbmi->ref_mvs[rf2][0].as_int; |
439 } | 453 } |
440 mbmi->best_mv.as_int = best_mv.as_int; | 454 mbmi->best_mv[0].as_int = best_mv[0].as_int; |
441 mbmi->best_second_mv.as_int = best_second_mv.as_int; | 455 mbmi->best_mv[1].as_int = best_mv[1].as_int; |
442 vp9_update_nmv_count(cpi, x, &best_mv, &best_second_mv); | 456 vp9_update_mv_count(cpi, x, best_mv); |
443 } | 457 } |
444 | 458 |
445 if (cm->mcomp_filter_type == SWITCHABLE && is_inter_mode(mbmi->mode)) { | 459 if (cm->mcomp_filter_type == SWITCHABLE && is_inter_mode(mbmi->mode)) { |
446 const int ctx = vp9_get_pred_context_switchable_interp(xd); | 460 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
447 ++cm->counts.switchable_interp[ctx][mbmi->interp_filter]; | 461 ++cm->counts.switchable_interp[ctx][mbmi->interp_filter]; |
448 } | 462 } |
449 | 463 |
450 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; | 464 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; |
451 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; | 465 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; |
452 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; | 466 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; |
453 | 467 |
454 for (i = 0; i <= SWITCHABLE_FILTERS; i++) | 468 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
455 cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; | 469 cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; |
456 } | 470 } |
457 } | 471 } |
458 | 472 |
459 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, | 473 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, |
460 int mb_row, int mb_col) { | 474 int mi_row, int mi_col) { |
461 uint8_t *buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, src | 475 uint8_t *const buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, |
462 ->alpha_buffer}; | 476 src->alpha_buffer}; |
463 int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, src | 477 const int strides[4] = {src->y_stride, src->uv_stride, src->uv_stride, |
464 ->alpha_stride}; | 478 src->alpha_stride}; |
465 int i; | 479 int i; |
466 | 480 |
467 for (i = 0; i < MAX_MB_PLANE; i++) { | 481 for (i = 0; i < MAX_MB_PLANE; i++) |
468 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mb_row, mb_col, | 482 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mi_row, mi_col, |
469 NULL, x->e_mbd.plane[i].subsampling_x, | 483 NULL, x->e_mbd.plane[i].subsampling_x, |
470 x->e_mbd.plane[i].subsampling_y); | 484 x->e_mbd.plane[i].subsampling_y); |
471 } | |
472 } | 485 } |
473 | 486 |
474 static void set_offsets(VP9_COMP *cpi, int mi_row, int mi_col, | 487 static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, |
475 BLOCK_SIZE bsize) { | 488 int mi_row, int mi_col, BLOCK_SIZE bsize) { |
476 MACROBLOCK *const x = &cpi->mb; | 489 MACROBLOCK *const x = &cpi->mb; |
477 VP9_COMMON *const cm = &cpi->common; | 490 VP9_COMMON *const cm = &cpi->common; |
478 MACROBLOCKD *const xd = &x->e_mbd; | 491 MACROBLOCKD *const xd = &x->e_mbd; |
479 MB_MODE_INFO *mbmi; | 492 MB_MODE_INFO *mbmi; |
480 const int dst_fb_idx = cm->new_fb_idx; | 493 const int dst_fb_idx = cm->new_fb_idx; |
481 const int idx_str = xd->mode_info_stride * mi_row + mi_col; | 494 const int idx_str = xd->mode_info_stride * mi_row + mi_col; |
482 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 495 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
483 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 496 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
484 const int mb_row = mi_row >> 1; | 497 const int mb_row = mi_row >> 1; |
485 const int mb_col = mi_col >> 1; | 498 const int mb_col = mi_col >> 1; |
486 const int idx_map = mb_row * cm->mb_cols + mb_col; | 499 const int idx_map = mb_row * cm->mb_cols + mb_col; |
487 const struct segmentation *const seg = &cm->seg; | 500 const struct segmentation *const seg = &cm->seg; |
488 | 501 |
489 set_skip_context(cm, xd, mi_row, mi_col); | 502 set_skip_context(xd, cpi->above_context, cpi->left_context, mi_row, mi_col); |
490 set_partition_seg_context(cm, xd, mi_row, mi_col); | |
491 | 503 |
492 // Activity map pointer | 504 // Activity map pointer |
493 x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; | 505 x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; |
494 x->active_ptr = cpi->active_map + idx_map; | 506 x->active_ptr = cpi->active_map + idx_map; |
495 | 507 |
496 /* pointers to mode info contexts */ | |
497 x->partition_info = x->pi + idx_str; | |
498 | |
499 xd->mi_8x8 = cm->mi_grid_visible + idx_str; | 508 xd->mi_8x8 = cm->mi_grid_visible + idx_str; |
500 xd->prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; | 509 xd->prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; |
501 | 510 |
502 // Special case: if prev_mi is NULL, the previous mode info context | 511 // Special case: if prev_mi is NULL, the previous mode info context |
503 // cannot be used. | 512 // cannot be used. |
504 xd->last_mi = cm->prev_mi ? xd->prev_mi_8x8[0] : NULL; | 513 xd->last_mi = cm->prev_mi ? xd->prev_mi_8x8[0] : NULL; |
505 | 514 |
506 xd->this_mi = | |
507 xd->mi_8x8[0] = cm->mi + idx_str; | 515 xd->mi_8x8[0] = cm->mi + idx_str; |
508 | 516 |
509 mbmi = &xd->this_mi->mbmi; | 517 mbmi = &xd->mi_8x8[0]->mbmi; |
510 | 518 |
511 // Set up destination pointers | 519 // Set up destination pointers |
512 setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col); | 520 setup_dst_planes(xd, &cm->yv12_fb[dst_fb_idx], mi_row, mi_col); |
513 | 521 |
514 // Set up limit values for MV components | 522 // Set up limit values for MV components |
515 // mv beyond the range do not produce new/different prediction block | 523 // mv beyond the range do not produce new/different prediction block |
516 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); | 524 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); |
517 x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); | 525 x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); |
518 x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND; | 526 x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND; |
519 x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND; | 527 x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND; |
520 | 528 |
521 // Set up distance of MB to edge of frame in 1/8th pel units | 529 // Set up distance of MB to edge of frame in 1/8th pel units |
522 assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1))); | 530 assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1))); |
523 set_mi_row_col(cm, xd, mi_row, mi_height, mi_col, mi_width); | 531 set_mi_row_col(xd, tile, mi_row, mi_height, mi_col, mi_width, |
| 532 cm->mi_rows, cm->mi_cols); |
524 | 533 |
525 /* set up source buffers */ | 534 /* set up source buffers */ |
526 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); | 535 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); |
527 | 536 |
528 /* R/D setup */ | 537 /* R/D setup */ |
529 x->rddiv = cpi->RDDIV; | 538 x->rddiv = cpi->RDDIV; |
530 x->rdmult = cpi->RDMULT; | 539 x->rdmult = cpi->RDMULT; |
531 | 540 |
532 /* segment ID */ | 541 /* segment ID */ |
533 if (seg->enabled) { | 542 if (seg->enabled) { |
534 uint8_t *map = seg->update_map ? cpi->segmentation_map | 543 if (!cpi->sf.variance_adaptive_quantization) { |
535 : cm->last_frame_seg_map; | 544 uint8_t *map = seg->update_map ? cpi->segmentation_map |
536 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 545 : cm->last_frame_seg_map; |
537 | 546 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
| 547 } |
538 vp9_mb_init_quantizer(cpi, x); | 548 vp9_mb_init_quantizer(cpi, x); |
539 | 549 |
540 if (seg->enabled && cpi->seg0_cnt > 0 | 550 if (seg->enabled && cpi->seg0_cnt > 0 |
541 && !vp9_segfeature_active(seg, 0, SEG_LVL_REF_FRAME) | 551 && !vp9_segfeature_active(seg, 0, SEG_LVL_REF_FRAME) |
542 && vp9_segfeature_active(seg, 1, SEG_LVL_REF_FRAME)) { | 552 && vp9_segfeature_active(seg, 1, SEG_LVL_REF_FRAME)) { |
543 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; | 553 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; |
544 } else { | 554 } else { |
545 const int y = mb_row & ~3; | 555 const int y = mb_row & ~3; |
546 const int x = mb_col & ~3; | 556 const int x = mb_col & ~3; |
547 const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); | 557 const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); |
548 const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); | 558 const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); |
549 const int tile_progress = cm->cur_tile_mi_col_start * cm->mb_rows >> 1; | 559 const int tile_progress = tile->mi_col_start * cm->mb_rows >> 1; |
550 const int mb_cols = (cm->cur_tile_mi_col_end - cm->cur_tile_mi_col_start) | 560 const int mb_cols = (tile->mi_col_end - tile->mi_col_start) >> 1; |
551 >> 1; | |
552 | 561 |
553 cpi->seg0_progress = ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) | 562 cpi->seg0_progress = ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) |
554 << 16) / cm->MBs; | 563 << 16) / cm->MBs; |
555 } | 564 } |
556 | 565 |
557 x->encode_breakout = cpi->segment_encode_breakout[mbmi->segment_id]; | 566 x->encode_breakout = cpi->segment_encode_breakout[mbmi->segment_id]; |
558 } else { | 567 } else { |
559 mbmi->segment_id = 0; | 568 mbmi->segment_id = 0; |
560 x->encode_breakout = cpi->oxcf.encode_breakout; | 569 x->encode_breakout = cpi->oxcf.encode_breakout; |
561 } | 570 } |
562 } | 571 } |
563 | 572 |
564 static void pick_sb_modes(VP9_COMP *cpi, int mi_row, int mi_col, | 573 static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, |
| 574 int mi_row, int mi_col, |
565 int *totalrate, int64_t *totaldist, | 575 int *totalrate, int64_t *totaldist, |
566 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, | 576 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, |
567 int64_t best_rd) { | 577 int64_t best_rd) { |
568 VP9_COMMON *const cm = &cpi->common; | 578 VP9_COMMON *const cm = &cpi->common; |
569 MACROBLOCK *const x = &cpi->mb; | 579 MACROBLOCK *const x = &cpi->mb; |
570 MACROBLOCKD *const xd = &x->e_mbd; | 580 MACROBLOCKD *const xd = &x->e_mbd; |
| 581 int orig_rdmult = x->rdmult; |
| 582 double rdmult_ratio; |
| 583 |
| 584 vp9_clear_system_state(); // __asm emms; |
| 585 rdmult_ratio = 1.0; // avoid uninitialized warnings |
571 | 586 |
572 // Use the lower precision, but faster, 32x32 fdct for mode selection. | 587 // Use the lower precision, but faster, 32x32 fdct for mode selection. |
573 x->use_lp32x32fdct = 1; | 588 x->use_lp32x32fdct = 1; |
574 | 589 |
575 if (bsize < BLOCK_8X8) { | 590 if (bsize < BLOCK_8X8) { |
576 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 | 591 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
577 // there is nothing to be done. | 592 // there is nothing to be done. |
578 if (xd->ab_index != 0) { | 593 if (xd->ab_index != 0) { |
579 *totalrate = 0; | 594 *totalrate = 0; |
580 *totaldist = 0; | 595 *totaldist = 0; |
581 return; | 596 return; |
582 } | 597 } |
583 } | 598 } |
584 | 599 |
585 set_offsets(cpi, mi_row, mi_col, bsize); | 600 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
586 xd->this_mi->mbmi.sb_type = bsize; | 601 xd->mi_8x8[0]->mbmi.sb_type = bsize; |
587 | 602 |
588 // Set to zero to make sure we do not use the previous encoded frame stats | 603 // Set to zero to make sure we do not use the previous encoded frame stats |
589 xd->this_mi->mbmi.skip_coeff = 0; | 604 xd->mi_8x8[0]->mbmi.skip_coeff = 0; |
590 | 605 |
591 x->source_variance = get_sby_perpixel_variance(cpi, x, bsize); | 606 x->source_variance = get_sby_perpixel_variance(cpi, x, bsize); |
592 | 607 |
| 608 if (cpi->sf.variance_adaptive_quantization) { |
| 609 int energy; |
| 610 if (bsize <= BLOCK_16X16) { |
| 611 energy = x->mb_energy; |
| 612 } else { |
| 613 energy = vp9_block_energy(cpi, x, bsize); |
| 614 } |
| 615 |
| 616 xd->mi_8x8[0]->mbmi.segment_id = vp9_vaq_segment_id(energy); |
| 617 rdmult_ratio = vp9_vaq_rdmult_ratio(energy); |
| 618 vp9_mb_init_quantizer(cpi, x); |
| 619 } |
| 620 |
593 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) | 621 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
594 vp9_activity_masking(cpi, x); | 622 vp9_activity_masking(cpi, x); |
595 | 623 |
| 624 if (cpi->sf.variance_adaptive_quantization) { |
| 625 vp9_clear_system_state(); // __asm emms; |
| 626 x->rdmult = round(x->rdmult * rdmult_ratio); |
| 627 } |
| 628 |
596 // Find best coding mode & reconstruct the MB so it is available | 629 // Find best coding mode & reconstruct the MB so it is available |
597 // as a predictor for MBs that follow in the SB | 630 // as a predictor for MBs that follow in the SB |
598 if (cm->frame_type == KEY_FRAME) | 631 if (frame_is_intra_only(cm)) { |
599 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, | 632 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, |
600 best_rd); | 633 best_rd); |
601 else | 634 } else { |
602 vp9_rd_pick_inter_mode_sb(cpi, x, mi_row, mi_col, totalrate, totaldist, | 635 if (bsize >= BLOCK_8X8) |
603 bsize, ctx, best_rd); | 636 vp9_rd_pick_inter_mode_sb(cpi, x, tile, mi_row, mi_col, |
| 637 totalrate, totaldist, bsize, ctx, best_rd); |
| 638 else |
| 639 vp9_rd_pick_inter_mode_sub8x8(cpi, x, tile, mi_row, mi_col, totalrate, |
| 640 totaldist, bsize, ctx, best_rd); |
| 641 } |
| 642 |
| 643 if (cpi->sf.variance_adaptive_quantization) { |
| 644 x->rdmult = orig_rdmult; |
| 645 if (*totalrate != INT_MAX) { |
| 646 vp9_clear_system_state(); // __asm emms; |
| 647 *totalrate = round(*totalrate * rdmult_ratio); |
| 648 } |
| 649 } |
604 } | 650 } |
605 | 651 |
606 static void update_stats(VP9_COMP *cpi) { | 652 static void update_stats(VP9_COMP *cpi) { |
607 VP9_COMMON *const cm = &cpi->common; | 653 VP9_COMMON *const cm = &cpi->common; |
608 MACROBLOCK *const x = &cpi->mb; | 654 MACROBLOCK *const x = &cpi->mb; |
609 MACROBLOCKD *const xd = &x->e_mbd; | 655 MACROBLOCKD *const xd = &x->e_mbd; |
610 MODE_INFO *mi = xd->this_mi; | 656 MODE_INFO *mi = xd->mi_8x8[0]; |
611 MB_MODE_INFO *const mbmi = &mi->mbmi; | 657 MB_MODE_INFO *const mbmi = &mi->mbmi; |
612 | 658 |
613 if (cm->frame_type != KEY_FRAME) { | 659 if (!frame_is_intra_only(cm)) { |
614 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 660 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
615 SEG_LVL_REF_FRAME); | 661 SEG_LVL_REF_FRAME); |
616 | 662 |
617 if (!seg_ref_active) | 663 if (!seg_ref_active) |
618 cpi->intra_inter_count[vp9_get_pred_context_intra_inter(xd)] | 664 cpi->intra_inter_count[vp9_get_pred_context_intra_inter(xd)] |
619 [is_inter_block(mbmi)]++; | 665 [is_inter_block(mbmi)]++; |
620 | 666 |
621 // If the segment reference feature is enabled we have only a single | 667 // If the segment reference feature is enabled we have only a single |
622 // reference frame allowed for the segment so exclude it from | 668 // reference frame allowed for the segment so exclude it from |
623 // the reference frame counts used to work out probabilities. | 669 // the reference frame counts used to work out probabilities. |
(...skipping 13 matching lines...) Expand all Loading... |
637 [mbmi->ref_frame[0] != GOLDEN_FRAME]++; | 683 [mbmi->ref_frame[0] != GOLDEN_FRAME]++; |
638 } | 684 } |
639 } | 685 } |
640 | 686 |
641 // Count of last ref frame 0,0 usage | 687 // Count of last ref frame 0,0 usage |
642 if (mbmi->mode == ZEROMV && mbmi->ref_frame[0] == LAST_FRAME) | 688 if (mbmi->mode == ZEROMV && mbmi->ref_frame[0] == LAST_FRAME) |
643 cpi->inter_zz_count++; | 689 cpi->inter_zz_count++; |
644 } | 690 } |
645 } | 691 } |
646 | 692 |
647 // TODO(jingning): the variables used here are little complicated. need further | |
648 // refactoring on organizing the temporary buffers, when recursive | |
649 // partition down to 4x4 block size is enabled. | |
650 static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) { | |
651 MACROBLOCKD *const xd = &x->e_mbd; | |
652 | |
653 switch (bsize) { | |
654 case BLOCK_64X64: | |
655 return &x->sb64_context; | |
656 case BLOCK_64X32: | |
657 return &x->sb64x32_context[xd->sb_index]; | |
658 case BLOCK_32X64: | |
659 return &x->sb32x64_context[xd->sb_index]; | |
660 case BLOCK_32X32: | |
661 return &x->sb32_context[xd->sb_index]; | |
662 case BLOCK_32X16: | |
663 return &x->sb32x16_context[xd->sb_index][xd->mb_index]; | |
664 case BLOCK_16X32: | |
665 return &x->sb16x32_context[xd->sb_index][xd->mb_index]; | |
666 case BLOCK_16X16: | |
667 return &x->mb_context[xd->sb_index][xd->mb_index]; | |
668 case BLOCK_16X8: | |
669 return &x->sb16x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | |
670 case BLOCK_8X16: | |
671 return &x->sb8x16_context[xd->sb_index][xd->mb_index][xd->b_index]; | |
672 case BLOCK_8X8: | |
673 return &x->sb8x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | |
674 case BLOCK_8X4: | |
675 return &x->sb8x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | |
676 case BLOCK_4X8: | |
677 return &x->sb4x8_context[xd->sb_index][xd->mb_index][xd->b_index]; | |
678 case BLOCK_4X4: | |
679 return &x->ab4x4_context[xd->sb_index][xd->mb_index][xd->b_index]; | |
680 default: | |
681 assert(0); | |
682 return NULL ; | |
683 } | |
684 } | |
685 | |
686 static BLOCK_SIZE *get_sb_partitioning(MACROBLOCK *x, BLOCK_SIZE bsize) { | 693 static BLOCK_SIZE *get_sb_partitioning(MACROBLOCK *x, BLOCK_SIZE bsize) { |
687 MACROBLOCKD *const xd = &x->e_mbd; | 694 MACROBLOCKD *const xd = &x->e_mbd; |
688 switch (bsize) { | 695 switch (bsize) { |
689 case BLOCK_64X64: | 696 case BLOCK_64X64: |
690 return &x->sb64_partitioning; | 697 return &x->sb64_partitioning; |
691 case BLOCK_32X32: | 698 case BLOCK_32X32: |
692 return &x->sb_partitioning[xd->sb_index]; | 699 return &x->sb_partitioning[xd->sb_index]; |
693 case BLOCK_16X16: | 700 case BLOCK_16X16: |
694 return &x->mb_partitioning[xd->sb_index][xd->mb_index]; | 701 return &x->mb_partitioning[xd->sb_index][xd->mb_index]; |
695 case BLOCK_8X8: | 702 case BLOCK_8X8: |
696 return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; | 703 return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; |
697 default: | 704 default: |
698 assert(0); | 705 assert(0); |
699 return NULL ; | 706 return NULL; |
700 } | 707 } |
701 } | 708 } |
702 | 709 |
703 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, | 710 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, |
704 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 711 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
705 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 712 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
706 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], | 713 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
707 BLOCK_SIZE bsize) { | 714 BLOCK_SIZE bsize) { |
708 VP9_COMMON *const cm = &cpi->common; | |
709 MACROBLOCK *const x = &cpi->mb; | 715 MACROBLOCK *const x = &cpi->mb; |
710 MACROBLOCKD *const xd = &x->e_mbd; | 716 MACROBLOCKD *const xd = &x->e_mbd; |
711 int p; | 717 int p; |
712 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 718 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
713 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 719 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
714 int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 720 int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
715 int mi_height = num_8x8_blocks_high_lookup[bsize]; | 721 int mi_height = num_8x8_blocks_high_lookup[bsize]; |
716 for (p = 0; p < MAX_MB_PLANE; p++) { | 722 for (p = 0; p < MAX_MB_PLANE; p++) { |
717 vpx_memcpy( | 723 vpx_memcpy( |
718 cm->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x), | 724 cpi->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x), |
719 a + num_4x4_blocks_wide * p, | 725 a + num_4x4_blocks_wide * p, |
720 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> | 726 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> |
721 xd->plane[p].subsampling_x); | 727 xd->plane[p].subsampling_x); |
722 vpx_memcpy( | 728 vpx_memcpy( |
723 cm->left_context[p] | 729 cpi->left_context[p] |
724 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), | 730 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), |
725 l + num_4x4_blocks_high * p, | 731 l + num_4x4_blocks_high * p, |
726 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> | 732 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> |
727 xd->plane[p].subsampling_y); | 733 xd->plane[p].subsampling_y); |
728 } | 734 } |
729 vpx_memcpy(cm->above_seg_context + mi_col, sa, | 735 vpx_memcpy(cpi->above_seg_context + mi_col, sa, |
730 sizeof(PARTITION_CONTEXT) * mi_width); | 736 sizeof(*cpi->above_seg_context) * mi_width); |
731 vpx_memcpy(cm->left_seg_context + (mi_row & MI_MASK), sl, | 737 vpx_memcpy(cpi->left_seg_context + (mi_row & MI_MASK), sl, |
732 sizeof(PARTITION_CONTEXT) * mi_height); | 738 sizeof(cpi->left_seg_context[0]) * mi_height); |
733 } | 739 } |
734 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, |
735 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 741 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
736 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 742 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
737 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], | 743 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
738 BLOCK_SIZE bsize) { | 744 BLOCK_SIZE bsize) { |
739 const VP9_COMMON *const cm = &cpi->common; | |
740 const MACROBLOCK *const x = &cpi->mb; | 745 const MACROBLOCK *const x = &cpi->mb; |
741 const MACROBLOCKD *const xd = &x->e_mbd; | 746 const MACROBLOCKD *const xd = &x->e_mbd; |
742 int p; | 747 int p; |
743 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 748 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
744 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 749 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
745 int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 750 int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
746 int mi_height = num_8x8_blocks_high_lookup[bsize]; | 751 int mi_height = num_8x8_blocks_high_lookup[bsize]; |
747 | 752 |
748 // buffer the above/left context information of the block in search. | 753 // buffer the above/left context information of the block in search. |
749 for (p = 0; p < MAX_MB_PLANE; ++p) { | 754 for (p = 0; p < MAX_MB_PLANE; ++p) { |
750 vpx_memcpy( | 755 vpx_memcpy( |
751 a + num_4x4_blocks_wide * p, | 756 a + num_4x4_blocks_wide * p, |
752 cm->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x), | 757 cpi->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x), |
753 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> | 758 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> |
754 xd->plane[p].subsampling_x); | 759 xd->plane[p].subsampling_x); |
755 vpx_memcpy( | 760 vpx_memcpy( |
756 l + num_4x4_blocks_high * p, | 761 l + num_4x4_blocks_high * p, |
757 cm->left_context[p] | 762 cpi->left_context[p] |
758 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), | 763 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), |
759 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> | 764 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> |
760 xd->plane[p].subsampling_y); | 765 xd->plane[p].subsampling_y); |
761 } | 766 } |
762 vpx_memcpy(sa, cm->above_seg_context + mi_col, | 767 vpx_memcpy(sa, cpi->above_seg_context + mi_col, |
763 sizeof(PARTITION_CONTEXT) * mi_width); | 768 sizeof(*cpi->above_seg_context) * mi_width); |
764 vpx_memcpy(sl, cm->left_seg_context + (mi_row & MI_MASK), | 769 vpx_memcpy(sl, cpi->left_seg_context + (mi_row & MI_MASK), |
765 sizeof(PARTITION_CONTEXT) * mi_height); | 770 sizeof(cpi->left_seg_context[0]) * mi_height); |
766 } | 771 } |
767 | 772 |
768 static void encode_b(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, | 773 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, |
| 774 TOKENEXTRA **tp, int mi_row, int mi_col, |
769 int output_enabled, BLOCK_SIZE bsize, int sub_index) { | 775 int output_enabled, BLOCK_SIZE bsize, int sub_index) { |
770 VP9_COMMON * const cm = &cpi->common; | 776 VP9_COMMON * const cm = &cpi->common; |
771 MACROBLOCK * const x = &cpi->mb; | 777 MACROBLOCK * const x = &cpi->mb; |
772 MACROBLOCKD * const xd = &x->e_mbd; | 778 MACROBLOCKD * const xd = &x->e_mbd; |
773 | 779 |
774 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 780 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
775 return; | 781 return; |
776 | 782 |
777 if (sub_index != -1) | 783 if (sub_index != -1) |
778 *get_sb_index(xd, bsize) = sub_index; | 784 *get_sb_index(xd, bsize) = sub_index; |
779 | 785 |
780 if (bsize < BLOCK_8X8) { | 786 if (bsize < BLOCK_8X8) { |
781 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 | 787 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
782 // there is nothing to be done. | 788 // there is nothing to be done. |
783 if (xd->ab_index > 0) | 789 if (xd->ab_index > 0) |
784 return; | 790 return; |
785 } | 791 } |
786 set_offsets(cpi, mi_row, mi_col, bsize); | 792 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
787 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); | 793 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); |
788 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); | 794 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); |
789 | 795 |
790 if (output_enabled) { | 796 if (output_enabled) { |
791 update_stats(cpi); | 797 update_stats(cpi); |
792 | 798 |
793 (*tp)->token = EOSB_TOKEN; | 799 (*tp)->token = EOSB_TOKEN; |
794 (*tp)++; | 800 (*tp)++; |
795 } | 801 } |
796 } | 802 } |
797 | 803 |
798 static void encode_sb(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, | 804 static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, |
| 805 TOKENEXTRA **tp, int mi_row, int mi_col, |
799 int output_enabled, BLOCK_SIZE bsize) { | 806 int output_enabled, BLOCK_SIZE bsize) { |
800 VP9_COMMON * const cm = &cpi->common; | 807 VP9_COMMON * const cm = &cpi->common; |
801 MACROBLOCK * const x = &cpi->mb; | 808 MACROBLOCK * const x = &cpi->mb; |
802 MACROBLOCKD * const xd = &x->e_mbd; | 809 MACROBLOCKD * const xd = &x->e_mbd; |
803 BLOCK_SIZE c1 = BLOCK_8X8; | 810 BLOCK_SIZE c1 = BLOCK_8X8; |
804 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; | 811 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; |
805 int pl = 0; | 812 int pl = 0; |
806 PARTITION_TYPE partition; | 813 PARTITION_TYPE partition; |
807 BLOCK_SIZE subsize; | 814 BLOCK_SIZE subsize; |
808 int i; | 815 int i; |
809 | 816 |
810 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 817 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
811 return; | 818 return; |
812 | 819 |
813 c1 = BLOCK_4X4; | 820 c1 = BLOCK_4X4; |
814 if (bsize >= BLOCK_8X8) { | 821 if (bsize >= BLOCK_8X8) { |
815 set_partition_seg_context(cm, xd, mi_row, mi_col); | 822 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, |
816 pl = partition_plane_context(xd, bsize); | 823 mi_row, mi_col, bsize); |
817 c1 = *(get_sb_partitioning(x, bsize)); | 824 c1 = *(get_sb_partitioning(x, bsize)); |
818 } | 825 } |
819 partition = partition_lookup[bsl][c1]; | 826 partition = partition_lookup[bsl][c1]; |
820 | 827 |
821 switch (partition) { | 828 switch (partition) { |
822 case PARTITION_NONE: | 829 case PARTITION_NONE: |
823 if (output_enabled && bsize >= BLOCK_8X8) | 830 if (output_enabled && bsize >= BLOCK_8X8) |
824 cpi->partition_count[pl][PARTITION_NONE]++; | 831 cpi->partition_count[pl][PARTITION_NONE]++; |
825 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, -1); | 832 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, -1); |
826 break; | 833 break; |
827 case PARTITION_VERT: | 834 case PARTITION_VERT: |
828 if (output_enabled) | 835 if (output_enabled) |
829 cpi->partition_count[pl][PARTITION_VERT]++; | 836 cpi->partition_count[pl][PARTITION_VERT]++; |
830 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); | 837 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); |
831 encode_b(cpi, tp, mi_row, mi_col + bs, output_enabled, c1, 1); | 838 encode_b(cpi, tile, tp, mi_row, mi_col + bs, output_enabled, c1, 1); |
832 break; | 839 break; |
833 case PARTITION_HORZ: | 840 case PARTITION_HORZ: |
834 if (output_enabled) | 841 if (output_enabled) |
835 cpi->partition_count[pl][PARTITION_HORZ]++; | 842 cpi->partition_count[pl][PARTITION_HORZ]++; |
836 encode_b(cpi, tp, mi_row, mi_col, output_enabled, c1, 0); | 843 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); |
837 encode_b(cpi, tp, mi_row + bs, mi_col, output_enabled, c1, 1); | 844 encode_b(cpi, tile, tp, mi_row + bs, mi_col, output_enabled, c1, 1); |
838 break; | 845 break; |
839 case PARTITION_SPLIT: | 846 case PARTITION_SPLIT: |
840 subsize = get_subsize(bsize, PARTITION_SPLIT); | 847 subsize = get_subsize(bsize, PARTITION_SPLIT); |
841 | 848 |
842 if (output_enabled) | 849 if (output_enabled) |
843 cpi->partition_count[pl][PARTITION_SPLIT]++; | 850 cpi->partition_count[pl][PARTITION_SPLIT]++; |
844 | 851 |
845 for (i = 0; i < 4; i++) { | 852 for (i = 0; i < 4; i++) { |
846 const int x_idx = i & 1, y_idx = i >> 1; | 853 const int x_idx = i & 1, y_idx = i >> 1; |
847 | 854 |
848 *get_sb_index(xd, subsize) = i; | 855 *get_sb_index(xd, subsize) = i; |
849 encode_sb(cpi, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, | 856 encode_sb(cpi, tile, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, |
850 output_enabled, subsize); | 857 output_enabled, subsize); |
851 } | 858 } |
852 break; | 859 break; |
853 default: | 860 default: |
854 assert(0); | 861 assert(0); |
855 break; | 862 break; |
856 } | 863 } |
857 | 864 |
858 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) { | 865 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
859 set_partition_seg_context(cm, xd, mi_row, mi_col); | 866 update_partition_context(cpi->above_seg_context, cpi->left_seg_context, |
860 update_partition_context(xd, c1, bsize); | 867 mi_row, mi_col, c1, bsize); |
861 } | |
862 } | 868 } |
863 | 869 |
864 // Check to see if the given partition size is allowed for a specified number | 870 // Check to see if the given partition size is allowed for a specified number |
865 // of 8x8 block rows and columns remaining in the image. | 871 // of 8x8 block rows and columns remaining in the image. |
866 // If not then return the largest allowed partition size | 872 // If not then return the largest allowed partition size |
867 static BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize, | 873 static BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize, |
868 int rows_left, int cols_left, | 874 int rows_left, int cols_left, |
869 int *bh, int *bw) { | 875 int *bh, int *bw) { |
870 if ((rows_left <= 0) || (cols_left <= 0)) { | 876 if ((rows_left <= 0) || (cols_left <= 0)) { |
871 return MIN(bsize, BLOCK_8X8); | 877 return MIN(bsize, BLOCK_8X8); |
872 } else { | 878 } else { |
873 for (; bsize > 0; --bsize) { | 879 for (; bsize > 0; --bsize) { |
874 *bh = num_8x8_blocks_high_lookup[bsize]; | 880 *bh = num_8x8_blocks_high_lookup[bsize]; |
875 *bw = num_8x8_blocks_wide_lookup[bsize]; | 881 *bw = num_8x8_blocks_wide_lookup[bsize]; |
876 if ((*bh <= rows_left) && (*bw <= cols_left)) { | 882 if ((*bh <= rows_left) && (*bw <= cols_left)) { |
877 break; | 883 break; |
878 } | 884 } |
879 } | 885 } |
880 } | 886 } |
881 return bsize; | 887 return bsize; |
882 } | 888 } |
883 | 889 |
884 // This function attempts to set all mode info entries in a given SB64 | 890 // This function attempts to set all mode info entries in a given SB64 |
885 // to the same block partition size. | 891 // to the same block partition size. |
886 // However, at the bottom and right borders of the image the requested size | 892 // However, at the bottom and right borders of the image the requested size |
887 // may not be allowed in which case this code attempts to choose the largest | 893 // may not be allowed in which case this code attempts to choose the largest |
888 // allowable partition. | 894 // allowable partition. |
889 static void set_partitioning(VP9_COMP *cpi, MODE_INFO **mi_8x8, | 895 static void set_partitioning(VP9_COMP *cpi, const TileInfo *const tile, |
890 int mi_row, int mi_col) { | 896 MODE_INFO **mi_8x8, int mi_row, int mi_col) { |
891 VP9_COMMON *const cm = &cpi->common; | 897 VP9_COMMON *const cm = &cpi->common; |
892 BLOCK_SIZE bsize = cpi->sf.always_this_block_size; | 898 BLOCK_SIZE bsize = cpi->sf.always_this_block_size; |
893 const int mis = cm->mode_info_stride; | 899 const int mis = cm->mode_info_stride; |
894 int row8x8_remaining = cm->cur_tile_mi_row_end - mi_row; | 900 int row8x8_remaining = tile->mi_row_end - mi_row; |
895 int col8x8_remaining = cm->cur_tile_mi_col_end - mi_col; | 901 int col8x8_remaining = tile->mi_col_end - mi_col; |
896 int block_row, block_col; | 902 int block_row, block_col; |
897 MODE_INFO * mi_upper_left = cm->mi + mi_row * mis + mi_col; | 903 MODE_INFO * mi_upper_left = cm->mi + mi_row * mis + mi_col; |
898 int bh = num_8x8_blocks_high_lookup[bsize]; | 904 int bh = num_8x8_blocks_high_lookup[bsize]; |
899 int bw = num_8x8_blocks_wide_lookup[bsize]; | 905 int bw = num_8x8_blocks_wide_lookup[bsize]; |
900 | 906 |
901 assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); | 907 assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); |
902 | 908 |
903 // Apply the requested partition size to the SB64 if it is all "in image" | 909 // Apply the requested partition size to the SB64 if it is all "in image" |
904 if ((col8x8_remaining >= MI_BLOCK_SIZE) && | 910 if ((col8x8_remaining >= MI_BLOCK_SIZE) && |
905 (row8x8_remaining >= MI_BLOCK_SIZE)) { | 911 (row8x8_remaining >= MI_BLOCK_SIZE)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 | 946 |
941 if (prev_mi) { | 947 if (prev_mi) { |
942 offset = prev_mi - cm->prev_mi; | 948 offset = prev_mi - cm->prev_mi; |
943 mi_8x8[block_row * mis + block_col] = cm->mi + offset; | 949 mi_8x8[block_row * mis + block_col] = cm->mi + offset; |
944 mi_8x8[block_row * mis + block_col]->mbmi.sb_type = sb_type; | 950 mi_8x8[block_row * mis + block_col]->mbmi.sb_type = sb_type; |
945 } | 951 } |
946 } | 952 } |
947 } | 953 } |
948 } | 954 } |
949 | 955 |
950 static void set_block_size(VP9_COMMON * const cm, MODE_INFO **mi_8x8, | 956 static int sb_has_motion(VP9_COMP *cpi, MODE_INFO **prev_mi_8x8) { |
951 BLOCK_SIZE bsize, int mis, int mi_row, | 957 VP9_COMMON *const cm = &cpi->common; |
952 int mi_col) { | 958 const int mis = cm->mode_info_stride; |
953 int r, c; | 959 int block_row, block_col; |
954 const int bs = MAX(num_8x8_blocks_wide_lookup[bsize], | |
955 num_8x8_blocks_high_lookup[bsize]); | |
956 const int idx_str = mis * mi_row + mi_col; | |
957 MODE_INFO **const mi2 = &mi_8x8[idx_str]; | |
958 | 960 |
959 mi2[0] = cm->mi + idx_str; | 961 if (cm->prev_mi) { |
960 mi2[0]->mbmi.sb_type = bsize; | 962 for (block_row = 0; block_row < 8; ++block_row) { |
961 | 963 for (block_col = 0; block_col < 8; ++block_col) { |
962 for (r = 0; r < bs; r++) | 964 MODE_INFO * prev_mi = prev_mi_8x8[block_row * mis + block_col]; |
963 for (c = 0; c < bs; c++) | 965 if (prev_mi) { |
964 if (mi_row + r < cm->mi_rows && mi_col + c < cm->mi_cols) | 966 if (abs(prev_mi->mbmi.mv[0].as_mv.row) >= 8 || |
965 mi2[r * mis + c] = mi2[0]; | 967 abs(prev_mi->mbmi.mv[0].as_mv.col) >= 8) |
966 } | 968 return 1; |
967 | |
968 typedef struct { | |
969 int64_t sum_square_error; | |
970 int64_t sum_error; | |
971 int count; | |
972 int variance; | |
973 } var; | |
974 | |
975 typedef struct { | |
976 var none; | |
977 var horz[2]; | |
978 var vert[2]; | |
979 } partition_variance; | |
980 | |
981 #define VT(TYPE, BLOCKSIZE) \ | |
982 typedef struct { \ | |
983 partition_variance vt; \ | |
984 BLOCKSIZE split[4]; } TYPE; | |
985 | |
986 VT(v8x8, var) | |
987 VT(v16x16, v8x8) | |
988 VT(v32x32, v16x16) | |
989 VT(v64x64, v32x32) | |
990 | |
991 typedef struct { | |
992 partition_variance *vt; | |
993 var *split[4]; | |
994 } vt_node; | |
995 | |
996 typedef enum { | |
997 V16X16, | |
998 V32X32, | |
999 V64X64, | |
1000 } TREE_LEVEL; | |
1001 | |
1002 static void tree_to_node(void *data, BLOCK_SIZE bsize, vt_node *node) { | |
1003 int i; | |
1004 switch (bsize) { | |
1005 case BLOCK_64X64: { | |
1006 v64x64 *vt = (v64x64 *) data; | |
1007 node->vt = &vt->vt; | |
1008 for (i = 0; i < 4; i++) | |
1009 node->split[i] = &vt->split[i].vt.none; | |
1010 break; | |
1011 } | |
1012 case BLOCK_32X32: { | |
1013 v32x32 *vt = (v32x32 *) data; | |
1014 node->vt = &vt->vt; | |
1015 for (i = 0; i < 4; i++) | |
1016 node->split[i] = &vt->split[i].vt.none; | |
1017 break; | |
1018 } | |
1019 case BLOCK_16X16: { | |
1020 v16x16 *vt = (v16x16 *) data; | |
1021 node->vt = &vt->vt; | |
1022 for (i = 0; i < 4; i++) | |
1023 node->split[i] = &vt->split[i].vt.none; | |
1024 break; | |
1025 } | |
1026 case BLOCK_8X8: { | |
1027 v8x8 *vt = (v8x8 *) data; | |
1028 node->vt = &vt->vt; | |
1029 for (i = 0; i < 4; i++) | |
1030 node->split[i] = &vt->split[i]; | |
1031 break; | |
1032 } | |
1033 default: | |
1034 node->vt = 0; | |
1035 for (i = 0; i < 4; i++) | |
1036 node->split[i] = 0; | |
1037 assert(-1); | |
1038 } | |
1039 } | |
1040 | |
1041 // Set variance values given sum square error, sum error, count. | |
1042 static void fill_variance(var *v, int64_t s2, int64_t s, int c) { | |
1043 v->sum_square_error = s2; | |
1044 v->sum_error = s; | |
1045 v->count = c; | |
1046 if (c > 0) | |
1047 v->variance = (int)(256 | |
1048 * (v->sum_square_error - v->sum_error * v->sum_error / v->count) | |
1049 / v->count); | |
1050 else | |
1051 v->variance = 0; | |
1052 } | |
1053 | |
1054 // Combine 2 variance structures by summing the sum_error, sum_square_error, | |
1055 // and counts and then calculating the new variance. | |
1056 void sum_2_variances(var *r, var *a, var*b) { | |
1057 fill_variance(r, a->sum_square_error + b->sum_square_error, | |
1058 a->sum_error + b->sum_error, a->count + b->count); | |
1059 } | |
1060 | |
1061 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { | |
1062 vt_node node; | |
1063 tree_to_node(data, bsize, &node); | |
1064 sum_2_variances(&node.vt->horz[0], node.split[0], node.split[1]); | |
1065 sum_2_variances(&node.vt->horz[1], node.split[2], node.split[3]); | |
1066 sum_2_variances(&node.vt->vert[0], node.split[0], node.split[2]); | |
1067 sum_2_variances(&node.vt->vert[1], node.split[1], node.split[3]); | |
1068 sum_2_variances(&node.vt->none, &node.vt->vert[0], &node.vt->vert[1]); | |
1069 } | |
1070 | |
1071 #if PERFORM_RANDOM_PARTITIONING | |
1072 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO *m, | |
1073 BLOCK_SIZE block_size, int mi_row, | |
1074 int mi_col, int mi_size) { | |
1075 VP9_COMMON * const cm = &cpi->common; | |
1076 vt_node vt; | |
1077 const int mis = cm->mode_info_stride; | |
1078 int64_t threshold = 4 * cpi->common.base_qindex * cpi->common.base_qindex; | |
1079 | |
1080 tree_to_node(data, block_size, &vt); | |
1081 | |
1082 // split none is available only if we have more than half a block size | |
1083 // in width and height inside the visible image | |
1084 if (mi_col + mi_size < cm->mi_cols && mi_row + mi_size < cm->mi_rows && | |
1085 (rand() & 3) < 1) { | |
1086 set_block_size(cm, m, block_size, mis, mi_row, mi_col); | |
1087 return 1; | |
1088 } | |
1089 | |
1090 // vertical split is available on all but the bottom border | |
1091 if (mi_row + mi_size < cm->mi_rows && vt.vt->vert[0].variance < threshold | |
1092 && (rand() & 3) < 1) { | |
1093 set_block_size(cm, m, get_subsize(block_size, PARTITION_VERT), mis, mi_row, | |
1094 mi_col); | |
1095 return 1; | |
1096 } | |
1097 | |
1098 // horizontal split is available on all but the right border | |
1099 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold | |
1100 && (rand() & 3) < 1) { | |
1101 set_block_size(cm, m, get_subsize(block_size, PARTITION_HORZ), mis, mi_row, | |
1102 mi_col); | |
1103 return 1; | |
1104 } | |
1105 | |
1106 return 0; | |
1107 } | |
1108 | |
1109 #else // !PERFORM_RANDOM_PARTITIONING | |
1110 | |
1111 static int set_vt_partitioning(VP9_COMP *cpi, void *data, MODE_INFO **m, | |
1112 BLOCK_SIZE bsize, int mi_row, | |
1113 int mi_col, int mi_size) { | |
1114 VP9_COMMON * const cm = &cpi->common; | |
1115 vt_node vt; | |
1116 const int mis = cm->mode_info_stride; | |
1117 int64_t threshold = 50 * cpi->common.base_qindex; | |
1118 | |
1119 tree_to_node(data, bsize, &vt); | |
1120 | |
1121 // split none is available only if we have more than half a block size | |
1122 // in width and height inside the visible image | |
1123 if (mi_col + mi_size < cm->mi_cols && mi_row + mi_size < cm->mi_rows | |
1124 && vt.vt->none.variance < threshold) { | |
1125 set_block_size(cm, m, bsize, mis, mi_row, mi_col); | |
1126 return 1; | |
1127 } | |
1128 | |
1129 // vertical split is available on all but the bottom border | |
1130 if (mi_row + mi_size < cm->mi_rows && vt.vt->vert[0].variance < threshold | |
1131 && vt.vt->vert[1].variance < threshold) { | |
1132 set_block_size(cm, m, get_subsize(bsize, PARTITION_VERT), mis, mi_row, | |
1133 mi_col); | |
1134 return 1; | |
1135 } | |
1136 | |
1137 // horizontal split is available on all but the right border | |
1138 if (mi_col + mi_size < cm->mi_cols && vt.vt->horz[0].variance < threshold | |
1139 && vt.vt->horz[1].variance < threshold) { | |
1140 set_block_size(cm, m, get_subsize(bsize, PARTITION_HORZ), mis, mi_row, | |
1141 mi_col); | |
1142 return 1; | |
1143 } | |
1144 | |
1145 return 0; | |
1146 } | |
1147 #endif // PERFORM_RANDOM_PARTITIONING | |
1148 | |
1149 static void choose_partitioning(VP9_COMP *cpi, MODE_INFO **mi_8x8, | |
1150 int mi_row, int mi_col) { | |
1151 VP9_COMMON * const cm = &cpi->common; | |
1152 MACROBLOCK *x = &cpi->mb; | |
1153 MACROBLOCKD *xd = &cpi->mb.e_mbd; | |
1154 const int mis = cm->mode_info_stride; | |
1155 // TODO(JBB): More experimentation or testing of this threshold; | |
1156 int64_t threshold = 4; | |
1157 int i, j, k; | |
1158 v64x64 vt; | |
1159 unsigned char * s; | |
1160 int sp; | |
1161 const unsigned char * d; | |
1162 int dp; | |
1163 int pixels_wide = 64, pixels_high = 64; | |
1164 | |
1165 vp9_zero(vt); | |
1166 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); | |
1167 | |
1168 if (xd->mb_to_right_edge < 0) | |
1169 pixels_wide += (xd->mb_to_right_edge >> 3); | |
1170 | |
1171 if (xd->mb_to_bottom_edge < 0) | |
1172 pixels_high += (xd->mb_to_bottom_edge >> 3); | |
1173 | |
1174 s = x->plane[0].src.buf; | |
1175 sp = x->plane[0].src.stride; | |
1176 | |
1177 // TODO(JBB): Clearly the higher the quantizer the fewer partitions we want | |
1178 // but this needs more experimentation. | |
1179 threshold = threshold * cpi->common.base_qindex * cpi->common.base_qindex; | |
1180 | |
1181 d = vp9_64x64_zeros; | |
1182 dp = 64; | |
1183 if (cm->frame_type != KEY_FRAME) { | |
1184 int_mv nearest_mv, near_mv; | |
1185 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, LAST_FRAME)]; | |
1186 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; | |
1187 YV12_BUFFER_CONFIG *second_ref_fb = NULL; | |
1188 | |
1189 setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, | |
1190 &xd->scale_factor[0]); | |
1191 setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, | |
1192 &xd->scale_factor[1]); | |
1193 | |
1194 xd->this_mi->mbmi.ref_frame[0] = LAST_FRAME; | |
1195 xd->this_mi->mbmi.sb_type = BLOCK_64X64; | |
1196 vp9_find_best_ref_mvs(xd, | |
1197 mi_8x8[0]->mbmi.ref_mvs[mi_8x8[0]->mbmi.ref_frame[0]], | |
1198 &nearest_mv, &near_mv); | |
1199 | |
1200 xd->this_mi->mbmi.mv[0] = nearest_mv; | |
1201 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_64X64); | |
1202 | |
1203 d = xd->plane[0].dst.buf; | |
1204 dp = xd->plane[0].dst.stride; | |
1205 } | |
1206 | |
1207 // Fill in the entire tree of 8x8 variances for splits. | |
1208 for (i = 0; i < 4; i++) { | |
1209 const int x32_idx = ((i & 1) << 5); | |
1210 const int y32_idx = ((i >> 1) << 5); | |
1211 for (j = 0; j < 4; j++) { | |
1212 const int x16_idx = x32_idx + ((j & 1) << 4); | |
1213 const int y16_idx = y32_idx + ((j >> 1) << 4); | |
1214 v16x16 *vst = &vt.split[i].split[j]; | |
1215 for (k = 0; k < 4; k++) { | |
1216 int x_idx = x16_idx + ((k & 1) << 3); | |
1217 int y_idx = y16_idx + ((k >> 1) << 3); | |
1218 unsigned int sse = 0; | |
1219 int sum = 0; | |
1220 if (x_idx < pixels_wide && y_idx < pixels_high) | |
1221 vp9_get_sse_sum_8x8(s + y_idx * sp + x_idx, sp, | |
1222 d + y_idx * dp + x_idx, dp, &sse, &sum); | |
1223 fill_variance(&vst->split[k].vt.none, sse, sum, 64); | |
1224 } | |
1225 } | |
1226 } | |
1227 // Fill the rest of the variance tree by summing the split partition | |
1228 // values. | |
1229 for (i = 0; i < 4; i++) { | |
1230 for (j = 0; j < 4; j++) { | |
1231 fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16); | |
1232 } | |
1233 fill_variance_tree(&vt.split[i], BLOCK_32X32); | |
1234 } | |
1235 fill_variance_tree(&vt, BLOCK_64X64); | |
1236 // Now go through the entire structure, splitting every block size until | |
1237 // we get to one that's got a variance lower than our threshold, or we | |
1238 // hit 8x8. | |
1239 if (!set_vt_partitioning(cpi, &vt, mi_8x8, BLOCK_64X64, mi_row, mi_col, | |
1240 4)) { | |
1241 for (i = 0; i < 4; ++i) { | |
1242 const int x32_idx = ((i & 1) << 2); | |
1243 const int y32_idx = ((i >> 1) << 2); | |
1244 if (!set_vt_partitioning(cpi, &vt.split[i], mi_8x8, BLOCK_32X32, | |
1245 (mi_row + y32_idx), (mi_col + x32_idx), 2)) { | |
1246 for (j = 0; j < 4; ++j) { | |
1247 const int x16_idx = ((j & 1) << 1); | |
1248 const int y16_idx = ((j >> 1) << 1); | |
1249 if (!set_vt_partitioning(cpi, &vt.split[i].split[j], mi_8x8, | |
1250 BLOCK_16X16, | |
1251 (mi_row + y32_idx + y16_idx), | |
1252 (mi_col + x32_idx + x16_idx), 1)) { | |
1253 for (k = 0; k < 4; ++k) { | |
1254 const int x8_idx = (k & 1); | |
1255 const int y8_idx = (k >> 1); | |
1256 set_block_size(cm, mi_8x8, BLOCK_8X8, mis, | |
1257 (mi_row + y32_idx + y16_idx + y8_idx), | |
1258 (mi_col + x32_idx + x16_idx + x8_idx)); | |
1259 } | |
1260 } | |
1261 } | 969 } |
1262 } | 970 } |
1263 } | 971 } |
1264 } | 972 } |
| 973 return 0; |
1265 } | 974 } |
1266 | 975 |
1267 static void rd_use_partition(VP9_COMP *cpi, MODE_INFO **mi_8x8, | 976 static void rd_use_partition(VP9_COMP *cpi, |
| 977 const TileInfo *const tile, |
| 978 MODE_INFO **mi_8x8, |
1268 TOKENEXTRA **tp, int mi_row, int mi_col, | 979 TOKENEXTRA **tp, int mi_row, int mi_col, |
1269 BLOCK_SIZE bsize, int *rate, int64_t *dist, | 980 BLOCK_SIZE bsize, int *rate, int64_t *dist, |
1270 int do_recon) { | 981 int do_recon) { |
1271 VP9_COMMON * const cm = &cpi->common; | 982 VP9_COMMON * const cm = &cpi->common; |
1272 MACROBLOCK * const x = &cpi->mb; | 983 MACROBLOCK * const x = &cpi->mb; |
1273 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 984 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
1274 const int mis = cm->mode_info_stride; | 985 const int mis = cm->mode_info_stride; |
1275 int bsl = b_width_log2(bsize); | 986 int bsl = b_width_log2(bsize); |
1276 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 987 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
1277 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 988 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
(...skipping 30 matching lines...) Expand all Loading... |
1308 if (xd->ab_index != 0) { | 1019 if (xd->ab_index != 0) { |
1309 *rate = 0; | 1020 *rate = 0; |
1310 *dist = 0; | 1021 *dist = 0; |
1311 return; | 1022 return; |
1312 } | 1023 } |
1313 } else { | 1024 } else { |
1314 *(get_sb_partitioning(x, bsize)) = subsize; | 1025 *(get_sb_partitioning(x, bsize)) = subsize; |
1315 } | 1026 } |
1316 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1027 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1317 | 1028 |
| 1029 if (bsize == BLOCK_16X16) { |
| 1030 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1031 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 1032 } |
| 1033 |
1318 x->fast_ms = 0; | 1034 x->fast_ms = 0; |
1319 x->subblock_ref = 0; | 1035 x->subblock_ref = 0; |
1320 | 1036 |
1321 if (cpi->sf.adjust_partitioning_from_last_frame) { | 1037 if (cpi->sf.adjust_partitioning_from_last_frame) { |
1322 // Check if any of the sub blocks are further split. | 1038 // Check if any of the sub blocks are further split. |
1323 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { | 1039 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { |
1324 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); | 1040 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); |
1325 splits_below = 1; | 1041 splits_below = 1; |
1326 for (i = 0; i < 4; i++) { | 1042 for (i = 0; i < 4; i++) { |
1327 int jj = i >> 1, ii = i & 0x01; | 1043 int jj = i >> 1, ii = i & 0x01; |
1328 MODE_INFO * this_mi = mi_8x8[jj * bss * mis + ii * bss]; | 1044 MODE_INFO * this_mi = mi_8x8[jj * bss * mis + ii * bss]; |
1329 if (this_mi && this_mi->mbmi.sb_type >= sub_subsize) { | 1045 if (this_mi && this_mi->mbmi.sb_type >= sub_subsize) { |
1330 splits_below = 0; | 1046 splits_below = 0; |
1331 } | 1047 } |
1332 } | 1048 } |
1333 } | 1049 } |
1334 | 1050 |
1335 // If partition is not none try none unless each of the 4 splits are split | 1051 // If partition is not none try none unless each of the 4 splits are split |
1336 // even further.. | 1052 // even further.. |
1337 if (partition != PARTITION_NONE && !splits_below && | 1053 if (partition != PARTITION_NONE && !splits_below && |
1338 mi_row + (ms >> 1) < cm->mi_rows && | 1054 mi_row + (ms >> 1) < cm->mi_rows && |
1339 mi_col + (ms >> 1) < cm->mi_cols) { | 1055 mi_col + (ms >> 1) < cm->mi_cols) { |
1340 *(get_sb_partitioning(x, bsize)) = bsize; | 1056 *(get_sb_partitioning(x, bsize)) = bsize; |
1341 pick_sb_modes(cpi, mi_row, mi_col, &none_rate, &none_dist, bsize, | 1057 pick_sb_modes(cpi, tile, mi_row, mi_col, &none_rate, &none_dist, bsize, |
1342 get_block_context(x, bsize), INT64_MAX); | 1058 get_block_context(x, bsize), INT64_MAX); |
1343 | 1059 |
1344 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1060 pl = partition_plane_context(cpi->above_seg_context, |
1345 pl = partition_plane_context(xd, bsize); | 1061 cpi->left_seg_context, |
| 1062 mi_row, mi_col, bsize); |
1346 none_rate += x->partition_cost[pl][PARTITION_NONE]; | 1063 none_rate += x->partition_cost[pl][PARTITION_NONE]; |
1347 | 1064 |
1348 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1065 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1349 mi_8x8[0]->mbmi.sb_type = bs_type; | 1066 mi_8x8[0]->mbmi.sb_type = bs_type; |
1350 *(get_sb_partitioning(x, bsize)) = subsize; | 1067 *(get_sb_partitioning(x, bsize)) = subsize; |
1351 } | 1068 } |
1352 } | 1069 } |
1353 | 1070 |
1354 switch (partition) { | 1071 switch (partition) { |
1355 case PARTITION_NONE: | 1072 case PARTITION_NONE: |
1356 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1073 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1357 bsize, get_block_context(x, bsize), INT64_MAX); | 1074 bsize, get_block_context(x, bsize), INT64_MAX); |
1358 break; | 1075 break; |
1359 case PARTITION_HORZ: | 1076 case PARTITION_HORZ: |
1360 *get_sb_index(xd, subsize) = 0; | 1077 *get_sb_index(xd, subsize) = 0; |
1361 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1078 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1362 subsize, get_block_context(x, subsize), INT64_MAX); | 1079 subsize, get_block_context(x, subsize), INT64_MAX); |
1363 if (last_part_rate != INT_MAX && | 1080 if (last_part_rate != INT_MAX && |
1364 bsize >= BLOCK_8X8 && mi_row + (mh >> 1) < cm->mi_rows) { | 1081 bsize >= BLOCK_8X8 && mi_row + (mh >> 1) < cm->mi_rows) { |
1365 int rt = 0; | 1082 int rt = 0; |
1366 int64_t dt = 0; | 1083 int64_t dt = 0; |
1367 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1084 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1368 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1085 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1369 *get_sb_index(xd, subsize) = 1; | 1086 *get_sb_index(xd, subsize) = 1; |
1370 pick_sb_modes(cpi, mi_row + (ms >> 1), mi_col, &rt, &dt, subsize, | 1087 pick_sb_modes(cpi, tile, mi_row + (ms >> 1), mi_col, &rt, &dt, subsize, |
1371 get_block_context(x, subsize), INT64_MAX); | 1088 get_block_context(x, subsize), INT64_MAX); |
1372 if (rt == INT_MAX || dt == INT_MAX) { | 1089 if (rt == INT_MAX || dt == INT_MAX) { |
1373 last_part_rate = INT_MAX; | 1090 last_part_rate = INT_MAX; |
1374 last_part_dist = INT_MAX; | 1091 last_part_dist = INT_MAX; |
1375 break; | 1092 break; |
1376 } | 1093 } |
1377 | 1094 |
1378 last_part_rate += rt; | 1095 last_part_rate += rt; |
1379 last_part_dist += dt; | 1096 last_part_dist += dt; |
1380 } | 1097 } |
1381 break; | 1098 break; |
1382 case PARTITION_VERT: | 1099 case PARTITION_VERT: |
1383 *get_sb_index(xd, subsize) = 0; | 1100 *get_sb_index(xd, subsize) = 0; |
1384 pick_sb_modes(cpi, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1101 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1385 subsize, get_block_context(x, subsize), INT64_MAX); | 1102 subsize, get_block_context(x, subsize), INT64_MAX); |
1386 if (last_part_rate != INT_MAX && | 1103 if (last_part_rate != INT_MAX && |
1387 bsize >= BLOCK_8X8 && mi_col + (ms >> 1) < cm->mi_cols) { | 1104 bsize >= BLOCK_8X8 && mi_col + (ms >> 1) < cm->mi_cols) { |
1388 int rt = 0; | 1105 int rt = 0; |
1389 int64_t dt = 0; | 1106 int64_t dt = 0; |
1390 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1107 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1391 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1108 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1392 *get_sb_index(xd, subsize) = 1; | 1109 *get_sb_index(xd, subsize) = 1; |
1393 pick_sb_modes(cpi, mi_row, mi_col + (ms >> 1), &rt, &dt, subsize, | 1110 pick_sb_modes(cpi, tile, mi_row, mi_col + (ms >> 1), &rt, &dt, subsize, |
1394 get_block_context(x, subsize), INT64_MAX); | 1111 get_block_context(x, subsize), INT64_MAX); |
1395 if (rt == INT_MAX || dt == INT_MAX) { | 1112 if (rt == INT_MAX || dt == INT_MAX) { |
1396 last_part_rate = INT_MAX; | 1113 last_part_rate = INT_MAX; |
1397 last_part_dist = INT_MAX; | 1114 last_part_dist = INT_MAX; |
1398 break; | 1115 break; |
1399 } | 1116 } |
1400 last_part_rate += rt; | 1117 last_part_rate += rt; |
1401 last_part_dist += dt; | 1118 last_part_dist += dt; |
1402 } | 1119 } |
1403 break; | 1120 break; |
1404 case PARTITION_SPLIT: | 1121 case PARTITION_SPLIT: |
1405 // Split partition. | 1122 // Split partition. |
1406 last_part_rate = 0; | 1123 last_part_rate = 0; |
1407 last_part_dist = 0; | 1124 last_part_dist = 0; |
1408 for (i = 0; i < 4; i++) { | 1125 for (i = 0; i < 4; i++) { |
1409 int x_idx = (i & 1) * (ms >> 1); | 1126 int x_idx = (i & 1) * (ms >> 1); |
1410 int y_idx = (i >> 1) * (ms >> 1); | 1127 int y_idx = (i >> 1) * (ms >> 1); |
1411 int jj = i >> 1, ii = i & 0x01; | 1128 int jj = i >> 1, ii = i & 0x01; |
1412 int rt; | 1129 int rt; |
1413 int64_t dt; | 1130 int64_t dt; |
1414 | 1131 |
1415 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | 1132 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
1416 continue; | 1133 continue; |
1417 | 1134 |
1418 *get_sb_index(xd, subsize) = i; | 1135 *get_sb_index(xd, subsize) = i; |
1419 | 1136 |
1420 rd_use_partition(cpi, mi_8x8 + jj * bss * mis + ii * bss, tp, | 1137 rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, |
1421 mi_row + y_idx, mi_col + x_idx, subsize, &rt, &dt, | 1138 mi_row + y_idx, mi_col + x_idx, subsize, &rt, &dt, |
1422 i != 3); | 1139 i != 3); |
1423 if (rt == INT_MAX || dt == INT_MAX) { | 1140 if (rt == INT_MAX || dt == INT_MAX) { |
1424 last_part_rate = INT_MAX; | 1141 last_part_rate = INT_MAX; |
1425 last_part_dist = INT_MAX; | 1142 last_part_dist = INT_MAX; |
1426 break; | 1143 break; |
1427 } | 1144 } |
1428 last_part_rate += rt; | 1145 last_part_rate += rt; |
1429 last_part_dist += dt; | 1146 last_part_dist += dt; |
1430 } | 1147 } |
1431 break; | 1148 break; |
1432 default: | 1149 default: |
1433 assert(0); | 1150 assert(0); |
1434 } | 1151 } |
1435 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1152 |
1436 pl = partition_plane_context(xd, bsize); | 1153 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, |
| 1154 mi_row, mi_col, bsize); |
1437 if (last_part_rate < INT_MAX) | 1155 if (last_part_rate < INT_MAX) |
1438 last_part_rate += x->partition_cost[pl][partition]; | 1156 last_part_rate += x->partition_cost[pl][partition]; |
1439 | 1157 |
1440 if (cpi->sf.adjust_partitioning_from_last_frame | 1158 if (cpi->sf.adjust_partitioning_from_last_frame |
1441 && partition != PARTITION_SPLIT && bsize > BLOCK_8X8 | 1159 && partition != PARTITION_SPLIT && bsize > BLOCK_8X8 |
1442 && (mi_row + ms < cm->mi_rows || mi_row + (ms >> 1) == cm->mi_rows) | 1160 && (mi_row + ms < cm->mi_rows || mi_row + (ms >> 1) == cm->mi_rows) |
1443 && (mi_col + ms < cm->mi_cols || mi_col + (ms >> 1) == cm->mi_cols)) { | 1161 && (mi_col + ms < cm->mi_cols || mi_col + (ms >> 1) == cm->mi_cols)) { |
1444 BLOCK_SIZE split_subsize = get_subsize(bsize, PARTITION_SPLIT); | 1162 BLOCK_SIZE split_subsize = get_subsize(bsize, PARTITION_SPLIT); |
1445 split_rate = 0; | 1163 split_rate = 0; |
1446 split_dist = 0; | 1164 split_dist = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
1458 if ((mi_row + y_idx >= cm->mi_rows) | 1176 if ((mi_row + y_idx >= cm->mi_rows) |
1459 || (mi_col + x_idx >= cm->mi_cols)) | 1177 || (mi_col + x_idx >= cm->mi_cols)) |
1460 continue; | 1178 continue; |
1461 | 1179 |
1462 *get_sb_index(xd, split_subsize) = i; | 1180 *get_sb_index(xd, split_subsize) = i; |
1463 *get_sb_partitioning(x, bsize) = split_subsize; | 1181 *get_sb_partitioning(x, bsize) = split_subsize; |
1464 *get_sb_partitioning(x, split_subsize) = split_subsize; | 1182 *get_sb_partitioning(x, split_subsize) = split_subsize; |
1465 | 1183 |
1466 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1184 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1467 | 1185 |
1468 pick_sb_modes(cpi, mi_row + y_idx, mi_col + x_idx, &rt, &dt, | 1186 pick_sb_modes(cpi, tile, mi_row + y_idx, mi_col + x_idx, &rt, &dt, |
1469 split_subsize, get_block_context(x, split_subsize), | 1187 split_subsize, get_block_context(x, split_subsize), |
1470 INT64_MAX); | 1188 INT64_MAX); |
1471 | 1189 |
1472 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1190 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1473 | 1191 |
1474 if (rt == INT_MAX || dt == INT_MAX) { | 1192 if (rt == INT_MAX || dt == INT_MAX) { |
1475 split_rate = INT_MAX; | 1193 split_rate = INT_MAX; |
1476 split_dist = INT_MAX; | 1194 split_dist = INT_MAX; |
1477 break; | 1195 break; |
1478 } | 1196 } |
1479 | 1197 |
1480 if (i != 3) | 1198 if (i != 3) |
1481 encode_sb(cpi, tp, mi_row + y_idx, mi_col + x_idx, 0, | 1199 encode_sb(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, 0, |
1482 split_subsize); | 1200 split_subsize); |
1483 | 1201 |
1484 split_rate += rt; | 1202 split_rate += rt; |
1485 split_dist += dt; | 1203 split_dist += dt; |
1486 set_partition_seg_context(cm, xd, mi_row + y_idx, mi_col + x_idx); | 1204 pl = partition_plane_context(cpi->above_seg_context, |
1487 pl = partition_plane_context(xd, bsize); | 1205 cpi->left_seg_context, |
| 1206 mi_row + y_idx, mi_col + x_idx, bsize); |
1488 split_rate += x->partition_cost[pl][PARTITION_NONE]; | 1207 split_rate += x->partition_cost[pl][PARTITION_NONE]; |
1489 } | 1208 } |
1490 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1209 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, |
1491 pl = partition_plane_context(xd, bsize); | 1210 mi_row, mi_col, bsize); |
1492 if (split_rate < INT_MAX) { | 1211 if (split_rate < INT_MAX) { |
1493 split_rate += x->partition_cost[pl][PARTITION_SPLIT]; | 1212 split_rate += x->partition_cost[pl][PARTITION_SPLIT]; |
1494 | 1213 |
1495 chosen_rate = split_rate; | 1214 chosen_rate = split_rate; |
1496 chosen_dist = split_dist; | 1215 chosen_dist = split_dist; |
1497 } | 1216 } |
1498 } | 1217 } |
1499 | 1218 |
1500 // If last_part is better set the partitioning to that... | 1219 // If last_part is better set the partitioning to that... |
1501 if (RDCOST(x->rdmult, x->rddiv, last_part_rate, last_part_dist) | 1220 if (RDCOST(x->rdmult, x->rddiv, last_part_rate, last_part_dist) |
(...skipping 14 matching lines...) Expand all Loading... |
1516 } | 1235 } |
1517 | 1236 |
1518 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1237 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1519 | 1238 |
1520 // We must have chosen a partitioning and encoding or we'll fail later on. | 1239 // We must have chosen a partitioning and encoding or we'll fail later on. |
1521 // No other opportunities for success. | 1240 // No other opportunities for success. |
1522 if ( bsize == BLOCK_64X64) | 1241 if ( bsize == BLOCK_64X64) |
1523 assert(chosen_rate < INT_MAX && chosen_dist < INT_MAX); | 1242 assert(chosen_rate < INT_MAX && chosen_dist < INT_MAX); |
1524 | 1243 |
1525 if (do_recon) | 1244 if (do_recon) |
1526 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); | 1245 encode_sb(cpi, tile, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); |
1527 | 1246 |
1528 *rate = chosen_rate; | 1247 *rate = chosen_rate; |
1529 *dist = chosen_dist; | 1248 *dist = chosen_dist; |
1530 } | 1249 } |
1531 | 1250 |
1532 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { | 1251 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { |
1533 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, | 1252 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, |
1534 BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, BLOCK_8X8, | 1253 BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, BLOCK_8X8, |
1535 BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16 | 1254 BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16 |
1536 }; | 1255 }; |
(...skipping 27 matching lines...) Expand all Loading... |
1564 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0; | 1283 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0; |
1565 *min_block_size = MIN(*min_block_size, sb_type); | 1284 *min_block_size = MIN(*min_block_size, sb_type); |
1566 *max_block_size = MAX(*max_block_size, sb_type); | 1285 *max_block_size = MAX(*max_block_size, sb_type); |
1567 } | 1286 } |
1568 index += xd->mode_info_stride; | 1287 index += xd->mode_info_stride; |
1569 } | 1288 } |
1570 } | 1289 } |
1571 | 1290 |
1572 // Look at neighboring blocks and set a min and max partition size based on | 1291 // Look at neighboring blocks and set a min and max partition size based on |
1573 // what they chose. | 1292 // what they chose. |
1574 static void rd_auto_partition_range(VP9_COMP *cpi, int row, int col, | 1293 static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, |
| 1294 int row, int col, |
1575 BLOCK_SIZE *min_block_size, | 1295 BLOCK_SIZE *min_block_size, |
1576 BLOCK_SIZE *max_block_size) { | 1296 BLOCK_SIZE *max_block_size) { |
| 1297 VP9_COMMON * const cm = &cpi->common; |
1577 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 1298 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
1578 MODE_INFO ** mi_8x8 = xd->mi_8x8; | 1299 MODE_INFO ** mi_8x8 = xd->mi_8x8; |
| 1300 MODE_INFO ** prev_mi_8x8 = xd->prev_mi_8x8; |
| 1301 |
1579 const int left_in_image = xd->left_available && mi_8x8[-1]; | 1302 const int left_in_image = xd->left_available && mi_8x8[-1]; |
1580 const int above_in_image = xd->up_available && | 1303 const int above_in_image = xd->up_available && |
1581 mi_8x8[-xd->mode_info_stride]; | 1304 mi_8x8[-xd->mode_info_stride]; |
1582 MODE_INFO ** above_sb64_mi_8x8; | 1305 MODE_INFO ** above_sb64_mi_8x8; |
1583 MODE_INFO ** left_sb64_mi_8x8; | 1306 MODE_INFO ** left_sb64_mi_8x8; |
1584 | 1307 |
1585 // Frequency check | 1308 int row8x8_remaining = tile->mi_row_end - row; |
1586 if (cpi->sf.auto_min_max_partition_count <= 0) { | 1309 int col8x8_remaining = tile->mi_col_end - col; |
1587 cpi->sf.auto_min_max_partition_count = | 1310 int bh, bw; |
1588 cpi->sf.auto_min_max_partition_interval; | 1311 |
| 1312 // Trap case where we do not have a prediction. |
| 1313 if (!left_in_image && !above_in_image && |
| 1314 ((cm->frame_type == KEY_FRAME) || !cm->prev_mi)) { |
1589 *min_block_size = BLOCK_4X4; | 1315 *min_block_size = BLOCK_4X4; |
1590 *max_block_size = BLOCK_64X64; | 1316 *max_block_size = BLOCK_64X64; |
1591 } else { | 1317 } else { |
1592 --cpi->sf.auto_min_max_partition_count; | 1318 // Default "min to max" and "max to min" |
| 1319 *min_block_size = BLOCK_64X64; |
| 1320 *max_block_size = BLOCK_4X4; |
1593 | 1321 |
1594 // Set default values if no left or above neighbour | 1322 // NOTE: each call to get_sb_partition_size_range() uses the previous |
1595 if (!left_in_image && !above_in_image) { | 1323 // passed in values for min and max as a starting point. |
1596 *min_block_size = BLOCK_4X4; | 1324 // |
1597 *max_block_size = BLOCK_64X64; | 1325 // Find the min and max partition used in previous frame at this location |
1598 } else { | 1326 if (cm->prev_mi && (cm->frame_type != KEY_FRAME)) { |
1599 VP9_COMMON *const cm = &cpi->common; | 1327 get_sb_partition_size_range(cpi, prev_mi_8x8, |
1600 int row8x8_remaining = cm->cur_tile_mi_row_end - row; | 1328 min_block_size, max_block_size); |
1601 int col8x8_remaining = cm->cur_tile_mi_col_end - col; | 1329 } |
1602 int bh, bw; | |
1603 | 1330 |
1604 // Default "min to max" and "max to min" | 1331 // Find the min and max partition sizes used in the left SB64 |
1605 *min_block_size = BLOCK_64X64; | 1332 if (left_in_image) { |
1606 *max_block_size = BLOCK_4X4; | 1333 left_sb64_mi_8x8 = &mi_8x8[-MI_BLOCK_SIZE]; |
| 1334 get_sb_partition_size_range(cpi, left_sb64_mi_8x8, |
| 1335 min_block_size, max_block_size); |
| 1336 } |
1607 | 1337 |
1608 // Find the min and max partition sizes used in the left SB64 | 1338 // Find the min and max partition sizes used in the above SB64. |
1609 if (left_in_image) { | 1339 if (above_in_image) { |
1610 left_sb64_mi_8x8 = &mi_8x8[-MI_BLOCK_SIZE]; | 1340 above_sb64_mi_8x8 = &mi_8x8[-xd->mode_info_stride * MI_BLOCK_SIZE]; |
1611 get_sb_partition_size_range(cpi, left_sb64_mi_8x8, | 1341 get_sb_partition_size_range(cpi, above_sb64_mi_8x8, |
1612 min_block_size, max_block_size); | 1342 min_block_size, max_block_size); |
1613 } | |
1614 | |
1615 // Find the min and max partition sizes used in the above SB64 taking | |
1616 // the values found for left as a starting point. | |
1617 if (above_in_image) { | |
1618 above_sb64_mi_8x8 = &mi_8x8[-xd->mode_info_stride * MI_BLOCK_SIZE]; | |
1619 get_sb_partition_size_range(cpi, above_sb64_mi_8x8, | |
1620 min_block_size, max_block_size); | |
1621 } | |
1622 | |
1623 // Give a bit of leaway either side of the observed min and max | |
1624 *min_block_size = min_partition_size[*min_block_size]; | |
1625 *max_block_size = max_partition_size[*max_block_size]; | |
1626 | |
1627 // Check border cases where max and min from neighbours may not be legal. | |
1628 *max_block_size = find_partition_size(*max_block_size, | |
1629 row8x8_remaining, col8x8_remaining, | |
1630 &bh, &bw); | |
1631 *min_block_size = MIN(*min_block_size, *max_block_size); | |
1632 } | 1343 } |
1633 } | 1344 } |
| 1345 |
| 1346 // Give a bit of leaway either side of the observed min and max |
| 1347 *min_block_size = min_partition_size[*min_block_size]; |
| 1348 *max_block_size = max_partition_size[*max_block_size]; |
| 1349 |
| 1350 // Check border cases where max and min from neighbours may not be legal. |
| 1351 *max_block_size = find_partition_size(*max_block_size, |
| 1352 row8x8_remaining, col8x8_remaining, |
| 1353 &bh, &bw); |
| 1354 *min_block_size = MIN(*min_block_size, *max_block_size); |
1634 } | 1355 } |
1635 | 1356 |
1636 static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) { | 1357 static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) { |
1637 VP9_COMMON *const cm = &cpi->common; | 1358 VP9_COMMON *const cm = &cpi->common; |
1638 MACROBLOCK *const x = &cpi->mb; | 1359 MACROBLOCK *const x = &cpi->mb; |
1639 MACROBLOCKD *const xd = &x->e_mbd; | 1360 MACROBLOCKD *const xd = &x->e_mbd; |
1640 | 1361 |
1641 // Only use 8x8 result for non HD videos. | 1362 // Only use 8x8 result for non HD videos. |
1642 // int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0; | 1363 // int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0; |
1643 int use_8x8 = 1; | 1364 int use_8x8 = 1; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); | 1449 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); |
1729 } | 1450 } |
1730 | 1451 |
1731 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { | 1452 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
1732 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); | 1453 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); |
1733 } | 1454 } |
1734 | 1455 |
1735 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 1456 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
1736 // unlikely to be selected depending on previous rate-distortion optimization | 1457 // unlikely to be selected depending on previous rate-distortion optimization |
1737 // results, for encoding speed-up. | 1458 // results, for encoding speed-up. |
1738 static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, | 1459 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, |
| 1460 TOKENEXTRA **tp, int mi_row, |
1739 int mi_col, BLOCK_SIZE bsize, int *rate, | 1461 int mi_col, BLOCK_SIZE bsize, int *rate, |
1740 int64_t *dist, int do_recon, int64_t best_rd) { | 1462 int64_t *dist, int do_recon, int64_t best_rd) { |
1741 VP9_COMMON * const cm = &cpi->common; | 1463 VP9_COMMON * const cm = &cpi->common; |
1742 MACROBLOCK * const x = &cpi->mb; | 1464 MACROBLOCK * const x = &cpi->mb; |
1743 MACROBLOCKD * const xd = &x->e_mbd; | 1465 MACROBLOCKD * const xd = &x->e_mbd; |
1744 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; | 1466 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; |
1745 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1467 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1746 PARTITION_CONTEXT sl[8], sa[8]; | 1468 PARTITION_CONTEXT sl[8], sa[8]; |
1747 TOKENEXTRA *tp_orig = *tp; | 1469 TOKENEXTRA *tp_orig = *tp; |
1748 int i, pl; | 1470 int i, pl; |
(...skipping 18 matching lines...) Expand all Loading... |
1767 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 | 1489 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
1768 // there is nothing to be done. | 1490 // there is nothing to be done. |
1769 if (xd->ab_index != 0) { | 1491 if (xd->ab_index != 0) { |
1770 *rate = 0; | 1492 *rate = 0; |
1771 *dist = 0; | 1493 *dist = 0; |
1772 return; | 1494 return; |
1773 } | 1495 } |
1774 } | 1496 } |
1775 assert(mi_height_log2(bsize) == mi_width_log2(bsize)); | 1497 assert(mi_height_log2(bsize) == mi_width_log2(bsize)); |
1776 | 1498 |
| 1499 if (bsize == BLOCK_16X16) { |
| 1500 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1501 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 1502 } |
| 1503 |
1777 // Determine partition types in search according to the speed features. | 1504 // Determine partition types in search according to the speed features. |
1778 // The threshold set here has to be of square block size. | 1505 // The threshold set here has to be of square block size. |
1779 if (cpi->sf.auto_min_max_partition_size) { | 1506 if (cpi->sf.auto_min_max_partition_size) { |
1780 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && | 1507 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && |
1781 bsize >= cpi->sf.min_partition_size); | 1508 bsize >= cpi->sf.min_partition_size); |
1782 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && | 1509 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && |
1783 bsize > cpi->sf.min_partition_size) || | 1510 bsize > cpi->sf.min_partition_size) || |
1784 force_horz_split); | 1511 force_horz_split); |
1785 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && | 1512 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && |
1786 bsize > cpi->sf.min_partition_size) || | 1513 bsize > cpi->sf.min_partition_size) || |
(...skipping 13 matching lines...) Expand all Loading... |
1800 source_variancey = get_sby_perpixel_variance(cpi, x, bsize); | 1527 source_variancey = get_sby_perpixel_variance(cpi, x, bsize); |
1801 if (source_variancey < cpi->sf.disable_split_var_thresh) { | 1528 if (source_variancey < cpi->sf.disable_split_var_thresh) { |
1802 do_split = 0; | 1529 do_split = 0; |
1803 if (source_variancey < cpi->sf.disable_split_var_thresh / 2) | 1530 if (source_variancey < cpi->sf.disable_split_var_thresh / 2) |
1804 do_rect = 0; | 1531 do_rect = 0; |
1805 } | 1532 } |
1806 } | 1533 } |
1807 | 1534 |
1808 // PARTITION_NONE | 1535 // PARTITION_NONE |
1809 if (partition_none_allowed) { | 1536 if (partition_none_allowed) { |
1810 pick_sb_modes(cpi, mi_row, mi_col, &this_rate, &this_dist, bsize, | 1537 pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rate, &this_dist, bsize, |
1811 get_block_context(x, bsize), best_rd); | 1538 get_block_context(x, bsize), best_rd); |
1812 if (this_rate != INT_MAX) { | 1539 if (this_rate != INT_MAX) { |
1813 if (bsize >= BLOCK_8X8) { | 1540 if (bsize >= BLOCK_8X8) { |
1814 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1541 pl = partition_plane_context(cpi->above_seg_context, |
1815 pl = partition_plane_context(xd, bsize); | 1542 cpi->left_seg_context, |
| 1543 mi_row, mi_col, bsize); |
1816 this_rate += x->partition_cost[pl][PARTITION_NONE]; | 1544 this_rate += x->partition_cost[pl][PARTITION_NONE]; |
1817 } | 1545 } |
1818 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 1546 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
1819 if (sum_rd < best_rd) { | 1547 if (sum_rd < best_rd) { |
1820 int64_t stop_thresh = 2048; | 1548 int64_t stop_thresh = 2048; |
1821 | 1549 |
1822 best_rate = this_rate; | 1550 best_rate = this_rate; |
1823 best_dist = this_dist; | 1551 best_dist = this_dist; |
1824 best_rd = sum_rd; | 1552 best_rd = sum_rd; |
1825 if (bsize >= BLOCK_8X8) | 1553 if (bsize >= BLOCK_8X8) |
(...skipping 27 matching lines...) Expand all Loading... |
1853 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | 1581 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { |
1854 const int x_idx = (i & 1) * ms; | 1582 const int x_idx = (i & 1) * ms; |
1855 const int y_idx = (i >> 1) * ms; | 1583 const int y_idx = (i >> 1) * ms; |
1856 | 1584 |
1857 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 1585 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
1858 continue; | 1586 continue; |
1859 | 1587 |
1860 *get_sb_index(xd, subsize) = i; | 1588 *get_sb_index(xd, subsize) = i; |
1861 if (cpi->sf.adaptive_motion_search) | 1589 if (cpi->sf.adaptive_motion_search) |
1862 load_pred_mv(x, get_block_context(x, bsize)); | 1590 load_pred_mv(x, get_block_context(x, bsize)); |
1863 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, | 1591 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, subsize, |
1864 &this_rate, &this_dist, i != 3, best_rd - sum_rd); | 1592 &this_rate, &this_dist, i != 3, best_rd - sum_rd); |
1865 | 1593 |
1866 if (this_rate == INT_MAX) { | 1594 if (this_rate == INT_MAX) { |
1867 sum_rd = INT64_MAX; | 1595 sum_rd = INT64_MAX; |
1868 } else { | 1596 } else { |
1869 sum_rate += this_rate; | 1597 sum_rate += this_rate; |
1870 sum_dist += this_dist; | 1598 sum_dist += this_dist; |
1871 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1599 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1872 } | 1600 } |
1873 } | 1601 } |
1874 if (sum_rd < best_rd && i == 4) { | 1602 if (sum_rd < best_rd && i == 4) { |
1875 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1603 pl = partition_plane_context(cpi->above_seg_context, |
1876 pl = partition_plane_context(xd, bsize); | 1604 cpi->left_seg_context, |
| 1605 mi_row, mi_col, bsize); |
1877 sum_rate += x->partition_cost[pl][PARTITION_SPLIT]; | 1606 sum_rate += x->partition_cost[pl][PARTITION_SPLIT]; |
1878 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1607 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1879 if (sum_rd < best_rd) { | 1608 if (sum_rd < best_rd) { |
1880 best_rate = sum_rate; | 1609 best_rate = sum_rate; |
1881 best_dist = sum_dist; | 1610 best_dist = sum_dist; |
1882 best_rd = sum_rd; | 1611 best_rd = sum_rd; |
1883 *(get_sb_partitioning(x, bsize)) = subsize; | 1612 *(get_sb_partitioning(x, bsize)) = subsize; |
1884 } else { | |
1885 // skip rectangular partition test when larger block size | |
1886 // gives better rd cost | |
1887 if (cpi->sf.less_rectangular_check) | |
1888 do_rect &= !partition_none_allowed; | |
1889 } | 1613 } |
| 1614 } else { |
| 1615 // skip rectangular partition test when larger block size |
| 1616 // gives better rd cost |
| 1617 if (cpi->sf.less_rectangular_check) |
| 1618 do_rect &= !partition_none_allowed; |
1890 } | 1619 } |
1891 partition_split_done = 1; | 1620 partition_split_done = 1; |
1892 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1621 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1893 } | 1622 } |
1894 | 1623 |
1895 x->fast_ms = 0; | 1624 x->fast_ms = 0; |
1896 x->subblock_ref = 0; | 1625 x->subblock_ref = 0; |
1897 | 1626 |
1898 if (partition_split_done && | 1627 if (partition_split_done && |
1899 cpi->sf.using_small_partition_info) { | 1628 cpi->sf.using_small_partition_info) { |
1900 compute_fast_motion_search_level(cpi, bsize); | 1629 compute_fast_motion_search_level(cpi, bsize); |
1901 } | 1630 } |
1902 | 1631 |
1903 // PARTITION_HORZ | 1632 // PARTITION_HORZ |
1904 if (partition_horz_allowed && do_rect) { | 1633 if (partition_horz_allowed && do_rect) { |
1905 subsize = get_subsize(bsize, PARTITION_HORZ); | 1634 subsize = get_subsize(bsize, PARTITION_HORZ); |
1906 *get_sb_index(xd, subsize) = 0; | 1635 *get_sb_index(xd, subsize) = 0; |
1907 if (cpi->sf.adaptive_motion_search) | 1636 if (cpi->sf.adaptive_motion_search) |
1908 load_pred_mv(x, get_block_context(x, bsize)); | 1637 load_pred_mv(x, get_block_context(x, bsize)); |
1909 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, | 1638 pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
1910 get_block_context(x, subsize), best_rd); | 1639 get_block_context(x, subsize), best_rd); |
1911 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1640 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1912 | 1641 |
1913 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { | 1642 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { |
1914 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1643 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1915 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1644 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1916 | 1645 |
1917 *get_sb_index(xd, subsize) = 1; | 1646 *get_sb_index(xd, subsize) = 1; |
1918 if (cpi->sf.adaptive_motion_search) | 1647 if (cpi->sf.adaptive_motion_search) |
1919 load_pred_mv(x, get_block_context(x, bsize)); | 1648 load_pred_mv(x, get_block_context(x, bsize)); |
1920 pick_sb_modes(cpi, mi_row + ms, mi_col, &this_rate, | 1649 pick_sb_modes(cpi, tile, mi_row + ms, mi_col, &this_rate, |
1921 &this_dist, subsize, get_block_context(x, subsize), | 1650 &this_dist, subsize, get_block_context(x, subsize), |
1922 best_rd - sum_rd); | 1651 best_rd - sum_rd); |
1923 if (this_rate == INT_MAX) { | 1652 if (this_rate == INT_MAX) { |
1924 sum_rd = INT64_MAX; | 1653 sum_rd = INT64_MAX; |
1925 } else { | 1654 } else { |
1926 sum_rate += this_rate; | 1655 sum_rate += this_rate; |
1927 sum_dist += this_dist; | 1656 sum_dist += this_dist; |
1928 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1657 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1929 } | 1658 } |
1930 } | 1659 } |
1931 if (sum_rd < best_rd) { | 1660 if (sum_rd < best_rd) { |
1932 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1661 pl = partition_plane_context(cpi->above_seg_context, |
1933 pl = partition_plane_context(xd, bsize); | 1662 cpi->left_seg_context, |
| 1663 mi_row, mi_col, bsize); |
1934 sum_rate += x->partition_cost[pl][PARTITION_HORZ]; | 1664 sum_rate += x->partition_cost[pl][PARTITION_HORZ]; |
1935 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1665 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1936 if (sum_rd < best_rd) { | 1666 if (sum_rd < best_rd) { |
1937 best_rd = sum_rd; | 1667 best_rd = sum_rd; |
1938 best_rate = sum_rate; | 1668 best_rate = sum_rate; |
1939 best_dist = sum_dist; | 1669 best_dist = sum_dist; |
1940 *(get_sb_partitioning(x, bsize)) = subsize; | 1670 *(get_sb_partitioning(x, bsize)) = subsize; |
1941 } | 1671 } |
1942 } | 1672 } |
1943 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1673 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1944 } | 1674 } |
1945 | 1675 |
1946 // PARTITION_VERT | 1676 // PARTITION_VERT |
1947 if (partition_vert_allowed && do_rect) { | 1677 if (partition_vert_allowed && do_rect) { |
1948 subsize = get_subsize(bsize, PARTITION_VERT); | 1678 subsize = get_subsize(bsize, PARTITION_VERT); |
1949 | 1679 |
1950 *get_sb_index(xd, subsize) = 0; | 1680 *get_sb_index(xd, subsize) = 0; |
1951 if (cpi->sf.adaptive_motion_search) | 1681 if (cpi->sf.adaptive_motion_search) |
1952 load_pred_mv(x, get_block_context(x, bsize)); | 1682 load_pred_mv(x, get_block_context(x, bsize)); |
1953 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, | 1683 pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
1954 get_block_context(x, subsize), best_rd); | 1684 get_block_context(x, subsize), best_rd); |
1955 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1685 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1956 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { | 1686 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { |
1957 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1687 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1958 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1688 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1959 | 1689 |
1960 *get_sb_index(xd, subsize) = 1; | 1690 *get_sb_index(xd, subsize) = 1; |
1961 if (cpi->sf.adaptive_motion_search) | 1691 if (cpi->sf.adaptive_motion_search) |
1962 load_pred_mv(x, get_block_context(x, bsize)); | 1692 load_pred_mv(x, get_block_context(x, bsize)); |
1963 pick_sb_modes(cpi, mi_row, mi_col + ms, &this_rate, | 1693 pick_sb_modes(cpi, tile, mi_row, mi_col + ms, &this_rate, |
1964 &this_dist, subsize, get_block_context(x, subsize), | 1694 &this_dist, subsize, get_block_context(x, subsize), |
1965 best_rd - sum_rd); | 1695 best_rd - sum_rd); |
1966 if (this_rate == INT_MAX) { | 1696 if (this_rate == INT_MAX) { |
1967 sum_rd = INT64_MAX; | 1697 sum_rd = INT64_MAX; |
1968 } else { | 1698 } else { |
1969 sum_rate += this_rate; | 1699 sum_rate += this_rate; |
1970 sum_dist += this_dist; | 1700 sum_dist += this_dist; |
1971 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1701 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1972 } | 1702 } |
1973 } | 1703 } |
1974 if (sum_rd < best_rd) { | 1704 if (sum_rd < best_rd) { |
1975 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1705 pl = partition_plane_context(cpi->above_seg_context, |
1976 pl = partition_plane_context(xd, bsize); | 1706 cpi->left_seg_context, |
| 1707 mi_row, mi_col, bsize); |
1977 sum_rate += x->partition_cost[pl][PARTITION_VERT]; | 1708 sum_rate += x->partition_cost[pl][PARTITION_VERT]; |
1978 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1709 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1979 if (sum_rd < best_rd) { | 1710 if (sum_rd < best_rd) { |
1980 best_rate = sum_rate; | 1711 best_rate = sum_rate; |
1981 best_dist = sum_dist; | 1712 best_dist = sum_dist; |
1982 best_rd = sum_rd; | 1713 best_rd = sum_rd; |
1983 *(get_sb_partitioning(x, bsize)) = subsize; | 1714 *(get_sb_partitioning(x, bsize)) = subsize; |
1984 } | 1715 } |
1985 } | 1716 } |
1986 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1717 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1987 } | 1718 } |
1988 | 1719 |
1989 | 1720 |
1990 *rate = best_rate; | 1721 *rate = best_rate; |
1991 *dist = best_dist; | 1722 *dist = best_dist; |
1992 | 1723 |
1993 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) | 1724 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) |
1994 encode_sb(cpi, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); | 1725 encode_sb(cpi, tile, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); |
1995 if (bsize == BLOCK_64X64) { | 1726 if (bsize == BLOCK_64X64) { |
1996 assert(tp_orig < *tp); | 1727 assert(tp_orig < *tp); |
1997 assert(best_rate < INT_MAX); | 1728 assert(best_rate < INT_MAX); |
1998 assert(best_dist < INT_MAX); | 1729 assert(best_dist < INT_MAX); |
1999 } else { | 1730 } else { |
2000 assert(tp_orig == *tp); | 1731 assert(tp_orig == *tp); |
2001 } | 1732 } |
2002 } | 1733 } |
2003 | 1734 |
2004 // Examines 64x64 block and chooses a best reference frame | 1735 // Examines 64x64 block and chooses a best reference frame |
2005 static void rd_pick_reference_frame(VP9_COMP *cpi, int mi_row, int mi_col) { | 1736 static void rd_pick_reference_frame(VP9_COMP *cpi, const TileInfo *const tile, |
| 1737 int mi_row, int mi_col) { |
2006 VP9_COMMON * const cm = &cpi->common; | 1738 VP9_COMMON * const cm = &cpi->common; |
2007 MACROBLOCK * const x = &cpi->mb; | 1739 MACROBLOCK * const x = &cpi->mb; |
2008 MACROBLOCKD * const xd = &x->e_mbd; | |
2009 int bsl = b_width_log2(BLOCK_64X64), bs = 1 << bsl; | 1740 int bsl = b_width_log2(BLOCK_64X64), bs = 1 << bsl; |
2010 int ms = bs / 2; | 1741 int ms = bs / 2; |
2011 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1742 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
2012 PARTITION_CONTEXT sl[8], sa[8]; | 1743 PARTITION_CONTEXT sl[8], sa[8]; |
2013 int pl; | 1744 int pl; |
2014 int r; | 1745 int r; |
2015 int64_t d; | 1746 int64_t d; |
2016 | 1747 |
2017 save_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); | 1748 save_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); |
2018 | 1749 |
2019 // Default is non mask (all reference frames allowed. | 1750 // Default is non mask (all reference frames allowed. |
2020 cpi->ref_frame_mask = 0; | 1751 cpi->ref_frame_mask = 0; |
2021 | 1752 |
2022 // Do RD search for 64x64. | 1753 // Do RD search for 64x64. |
2023 if ((mi_row + (ms >> 1) < cm->mi_rows) && | 1754 if ((mi_row + (ms >> 1) < cm->mi_rows) && |
2024 (mi_col + (ms >> 1) < cm->mi_cols)) { | 1755 (mi_col + (ms >> 1) < cm->mi_cols)) { |
2025 cpi->set_ref_frame_mask = 1; | 1756 cpi->set_ref_frame_mask = 1; |
2026 pick_sb_modes(cpi, mi_row, mi_col, &r, &d, BLOCK_64X64, | 1757 pick_sb_modes(cpi, tile, mi_row, mi_col, &r, &d, BLOCK_64X64, |
2027 get_block_context(x, BLOCK_64X64), INT64_MAX); | 1758 get_block_context(x, BLOCK_64X64), INT64_MAX); |
2028 set_partition_seg_context(cm, xd, mi_row, mi_col); | 1759 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, |
2029 pl = partition_plane_context(xd, BLOCK_64X64); | 1760 mi_row, mi_col, BLOCK_64X64); |
2030 r += x->partition_cost[pl][PARTITION_NONE]; | 1761 r += x->partition_cost[pl][PARTITION_NONE]; |
2031 | 1762 |
2032 *(get_sb_partitioning(x, BLOCK_64X64)) = BLOCK_64X64; | 1763 *(get_sb_partitioning(x, BLOCK_64X64)) = BLOCK_64X64; |
2033 cpi->set_ref_frame_mask = 0; | 1764 cpi->set_ref_frame_mask = 0; |
2034 } | 1765 } |
2035 | 1766 |
2036 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); | 1767 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); |
2037 } | 1768 } |
2038 | 1769 |
2039 static void encode_sb_row(VP9_COMP *cpi, int mi_row, TOKENEXTRA **tp, | 1770 static void encode_sb_row(VP9_COMP *cpi, const TileInfo *const tile, |
2040 int *totalrate) { | 1771 int mi_row, TOKENEXTRA **tp, int *totalrate) { |
2041 VP9_COMMON * const cm = &cpi->common; | 1772 VP9_COMMON * const cm = &cpi->common; |
2042 int mi_col; | 1773 int mi_col; |
2043 | 1774 |
2044 // Initialize the left context for the new SB row | 1775 // Initialize the left context for the new SB row |
2045 vpx_memset(&cm->left_context, 0, sizeof(cm->left_context)); | 1776 vpx_memset(&cpi->left_context, 0, sizeof(cpi->left_context)); |
2046 vpx_memset(cm->left_seg_context, 0, sizeof(cm->left_seg_context)); | 1777 vpx_memset(cpi->left_seg_context, 0, sizeof(cpi->left_seg_context)); |
2047 | 1778 |
2048 // Code each SB in the row | 1779 // Code each SB in the row |
2049 for (mi_col = cm->cur_tile_mi_col_start; mi_col < cm->cur_tile_mi_col_end; | 1780 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; |
2050 mi_col += MI_BLOCK_SIZE) { | 1781 mi_col += MI_BLOCK_SIZE) { |
2051 int dummy_rate; | 1782 int dummy_rate; |
2052 int64_t dummy_dist; | 1783 int64_t dummy_dist; |
2053 | 1784 |
2054 vpx_memset(cpi->mb.pred_mv, 0, sizeof(cpi->mb.pred_mv)); | 1785 vp9_zero(cpi->mb.pred_mv); |
2055 | 1786 |
2056 if (cpi->sf.reference_masking) | 1787 if (cpi->sf.reference_masking) |
2057 rd_pick_reference_frame(cpi, mi_row, mi_col); | 1788 rd_pick_reference_frame(cpi, tile, mi_row, mi_col); |
2058 | 1789 |
2059 if (cpi->sf.partition_by_variance || cpi->sf.use_lastframe_partitioning || | 1790 if (cpi->sf.use_lastframe_partitioning || |
2060 cpi->sf.use_one_partition_size_always ) { | 1791 cpi->sf.use_one_partition_size_always ) { |
2061 const int idx_str = cm->mode_info_stride * mi_row + mi_col; | 1792 const int idx_str = cm->mode_info_stride * mi_row + mi_col; |
2062 MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; | 1793 MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; |
2063 MODE_INFO **prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; | 1794 MODE_INFO **prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; |
2064 | 1795 |
2065 cpi->mb.source_variance = UINT_MAX; | 1796 cpi->mb.source_variance = UINT_MAX; |
2066 if (cpi->sf.use_one_partition_size_always) { | 1797 if (cpi->sf.use_one_partition_size_always) { |
2067 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); | 1798 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
2068 set_partitioning(cpi, mi_8x8, mi_row, mi_col); | 1799 set_partitioning(cpi, tile, mi_8x8, mi_row, mi_col); |
2069 rd_use_partition(cpi, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 1800 rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, |
2070 &dummy_rate, &dummy_dist, 1); | |
2071 } else if (cpi->sf.partition_by_variance) { | |
2072 choose_partitioning(cpi, cm->mi_grid_visible, mi_row, mi_col); | |
2073 rd_use_partition(cpi, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | |
2074 &dummy_rate, &dummy_dist, 1); | 1801 &dummy_rate, &dummy_dist, 1); |
2075 } else { | 1802 } else { |
2076 if ((cpi->common.current_video_frame | 1803 if ((cpi->common.current_video_frame |
2077 % cpi->sf.last_partitioning_redo_frequency) == 0 | 1804 % cpi->sf.last_partitioning_redo_frequency) == 0 |
2078 || cm->prev_mi == 0 | 1805 || cm->prev_mi == 0 |
2079 || cpi->common.show_frame == 0 | 1806 || cpi->common.show_frame == 0 |
2080 || cpi->common.frame_type == KEY_FRAME | 1807 || cpi->common.frame_type == KEY_FRAME |
2081 || cpi->is_src_frame_alt_ref) { | 1808 || cpi->is_src_frame_alt_ref |
| 1809 || ((cpi->sf.use_lastframe_partitioning == |
| 1810 LAST_FRAME_PARTITION_LOW_MOTION) && |
| 1811 sb_has_motion(cpi, prev_mi_8x8))) { |
2082 // If required set upper and lower partition size limits | 1812 // If required set upper and lower partition size limits |
2083 if (cpi->sf.auto_min_max_partition_size) { | 1813 if (cpi->sf.auto_min_max_partition_size) { |
2084 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); | 1814 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
2085 rd_auto_partition_range(cpi, mi_row, mi_col, | 1815 rd_auto_partition_range(cpi, tile, mi_row, mi_col, |
2086 &cpi->sf.min_partition_size, | 1816 &cpi->sf.min_partition_size, |
2087 &cpi->sf.max_partition_size); | 1817 &cpi->sf.max_partition_size); |
2088 } | 1818 } |
2089 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_64X64, | 1819 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
2090 &dummy_rate, &dummy_dist, 1, INT64_MAX); | 1820 &dummy_rate, &dummy_dist, 1, INT64_MAX); |
2091 } else { | 1821 } else { |
2092 copy_partitioning(cpi, mi_8x8, prev_mi_8x8); | 1822 copy_partitioning(cpi, mi_8x8, prev_mi_8x8); |
2093 rd_use_partition(cpi, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 1823 rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, |
2094 &dummy_rate, &dummy_dist, 1); | 1824 &dummy_rate, &dummy_dist, 1); |
2095 } | 1825 } |
2096 } | 1826 } |
2097 } else { | 1827 } else { |
2098 // If required set upper and lower partition size limits | 1828 // If required set upper and lower partition size limits |
2099 if (cpi->sf.auto_min_max_partition_size) { | 1829 if (cpi->sf.auto_min_max_partition_size) { |
2100 set_offsets(cpi, mi_row, mi_col, BLOCK_64X64); | 1830 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
2101 rd_auto_partition_range(cpi, mi_row, mi_col, | 1831 rd_auto_partition_range(cpi, tile, mi_row, mi_col, |
2102 &cpi->sf.min_partition_size, | 1832 &cpi->sf.min_partition_size, |
2103 &cpi->sf.max_partition_size); | 1833 &cpi->sf.max_partition_size); |
2104 } | 1834 } |
2105 rd_pick_partition(cpi, tp, mi_row, mi_col, BLOCK_64X64, | 1835 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
2106 &dummy_rate, &dummy_dist, 1, INT64_MAX); | 1836 &dummy_rate, &dummy_dist, 1, INT64_MAX); |
2107 } | 1837 } |
2108 } | 1838 } |
2109 } | 1839 } |
2110 | 1840 |
2111 static void init_encode_frame_mb_context(VP9_COMP *cpi) { | 1841 static void init_encode_frame_mb_context(VP9_COMP *cpi) { |
2112 MACROBLOCK *const x = &cpi->mb; | 1842 MACROBLOCK *const x = &cpi->mb; |
2113 VP9_COMMON *const cm = &cpi->common; | 1843 VP9_COMMON *const cm = &cpi->common; |
2114 MACROBLOCKD *const xd = &x->e_mbd; | 1844 MACROBLOCKD *const xd = &x->e_mbd; |
2115 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); | 1845 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); |
2116 | 1846 |
2117 x->act_zbin_adj = 0; | 1847 x->act_zbin_adj = 0; |
2118 cpi->seg0_idx = 0; | 1848 cpi->seg0_idx = 0; |
2119 | 1849 |
2120 xd->mode_info_stride = cm->mode_info_stride; | 1850 xd->mode_info_stride = cm->mode_info_stride; |
2121 | 1851 |
2122 // reset intra mode contexts | 1852 // reset intra mode contexts |
2123 if (cm->frame_type == KEY_FRAME) | 1853 if (frame_is_intra_only(cm)) |
2124 vp9_init_mbmode_probs(cm); | 1854 vp9_init_mbmode_probs(cm); |
2125 | 1855 |
2126 // Copy data over into macro block data structures. | 1856 // Copy data over into macro block data structures. |
2127 vp9_setup_src_planes(x, cpi->Source, 0, 0); | 1857 vp9_setup_src_planes(x, cpi->Source, 0, 0); |
2128 | 1858 |
2129 // TODO(jkoleszar): are these initializations required? | 1859 // TODO(jkoleszar): are these initializations required? |
2130 setup_pre_planes(xd, 0, &cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]], | 1860 setup_pre_planes(xd, 0, &cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]], |
2131 0, 0, NULL); | 1861 0, 0, NULL); |
2132 setup_dst_planes(xd, &cm->yv12_fb[cm->new_fb_idx], 0, 0); | 1862 setup_dst_planes(xd, get_frame_new_buffer(cm), 0, 0); |
2133 | 1863 |
2134 setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); | 1864 setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); |
2135 | 1865 |
2136 xd->this_mi->mbmi.mode = DC_PRED; | 1866 xd->mi_8x8[0]->mbmi.mode = DC_PRED; |
2137 xd->this_mi->mbmi.uv_mode = DC_PRED; | 1867 xd->mi_8x8[0]->mbmi.uv_mode = DC_PRED; |
2138 | 1868 |
2139 vp9_zero(cpi->y_mode_count) | 1869 vp9_zero(cpi->y_mode_count); |
2140 vp9_zero(cpi->y_uv_mode_count) | 1870 vp9_zero(cpi->y_uv_mode_count); |
2141 vp9_zero(cm->counts.inter_mode) | 1871 vp9_zero(cm->counts.inter_mode); |
2142 vp9_zero(cpi->partition_count); | 1872 vp9_zero(cpi->partition_count); |
2143 vp9_zero(cpi->intra_inter_count); | 1873 vp9_zero(cpi->intra_inter_count); |
2144 vp9_zero(cpi->comp_inter_count); | 1874 vp9_zero(cpi->comp_inter_count); |
2145 vp9_zero(cpi->single_ref_count); | 1875 vp9_zero(cpi->single_ref_count); |
2146 vp9_zero(cpi->comp_ref_count); | 1876 vp9_zero(cpi->comp_ref_count); |
2147 vp9_zero(cm->counts.tx); | 1877 vp9_zero(cm->counts.tx); |
2148 vp9_zero(cm->counts.mbskip); | 1878 vp9_zero(cm->counts.mbskip); |
2149 | 1879 |
2150 // Note: this memset assumes above_context[0], [1] and [2] | 1880 // Note: this memset assumes above_context[0], [1] and [2] |
2151 // are allocated as part of the same buffer. | 1881 // are allocated as part of the same buffer. |
2152 vpx_memset(cm->above_context[0], 0, | 1882 vpx_memset(cpi->above_context[0], 0, |
2153 sizeof(ENTROPY_CONTEXT) * 2 * MAX_MB_PLANE * aligned_mi_cols); | 1883 sizeof(*cpi->above_context[0]) * |
2154 vpx_memset(cm->above_seg_context, 0, | 1884 2 * aligned_mi_cols * MAX_MB_PLANE); |
2155 sizeof(PARTITION_CONTEXT) * aligned_mi_cols); | 1885 vpx_memset(cpi->above_seg_context, 0, |
| 1886 sizeof(*cpi->above_seg_context) * aligned_mi_cols); |
2156 } | 1887 } |
2157 | 1888 |
2158 static void switch_lossless_mode(VP9_COMP *cpi, int lossless) { | 1889 static void switch_lossless_mode(VP9_COMP *cpi, int lossless) { |
2159 if (lossless) { | 1890 if (lossless) { |
2160 // printf("Switching to lossless\n"); | 1891 // printf("Switching to lossless\n"); |
2161 cpi->mb.fwd_txm8x4 = vp9_short_walsh8x4; | 1892 cpi->mb.fwd_txm4x4 = vp9_fwht4x4; |
2162 cpi->mb.fwd_txm4x4 = vp9_short_walsh4x4; | 1893 cpi->mb.e_mbd.itxm_add = vp9_iwht4x4_add; |
2163 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_iwalsh4x4_1_add; | |
2164 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_iwalsh4x4_add; | |
2165 cpi->mb.optimize = 0; | 1894 cpi->mb.optimize = 0; |
2166 cpi->common.lf.filter_level = 0; | 1895 cpi->common.lf.filter_level = 0; |
2167 cpi->zbin_mode_boost_enabled = 0; | 1896 cpi->zbin_mode_boost_enabled = 0; |
2168 cpi->common.tx_mode = ONLY_4X4; | 1897 cpi->common.tx_mode = ONLY_4X4; |
2169 } else { | 1898 } else { |
2170 // printf("Not lossless\n"); | 1899 // printf("Not lossless\n"); |
2171 cpi->mb.fwd_txm8x4 = vp9_short_fdct8x4; | 1900 cpi->mb.fwd_txm4x4 = vp9_fdct4x4; |
2172 cpi->mb.fwd_txm4x4 = vp9_short_fdct4x4; | 1901 cpi->mb.e_mbd.itxm_add = vp9_idct4x4_add; |
2173 cpi->mb.e_mbd.inv_txm4x4_1_add = vp9_short_idct4x4_1_add; | |
2174 cpi->mb.e_mbd.inv_txm4x4_add = vp9_short_idct4x4_add; | |
2175 } | 1902 } |
2176 } | 1903 } |
2177 | 1904 |
2178 static void switch_tx_mode(VP9_COMP *cpi) { | 1905 static void switch_tx_mode(VP9_COMP *cpi) { |
2179 if (cpi->sf.tx_size_search_method == USE_LARGESTALL && | 1906 if (cpi->sf.tx_size_search_method == USE_LARGESTALL && |
2180 cpi->common.tx_mode >= ALLOW_32X32) | 1907 cpi->common.tx_mode >= ALLOW_32X32) |
2181 cpi->common.tx_mode = ALLOW_32X32; | 1908 cpi->common.tx_mode = ALLOW_32X32; |
2182 } | 1909 } |
2183 | 1910 |
2184 static void encode_frame_internal(VP9_COMP *cpi) { | 1911 static void encode_frame_internal(VP9_COMP *cpi) { |
(...skipping 16 matching lines...) Expand all Loading... |
2201 fclose(statsfile); | 1928 fclose(statsfile); |
2202 } | 1929 } |
2203 #endif | 1930 #endif |
2204 | 1931 |
2205 totalrate = 0; | 1932 totalrate = 0; |
2206 | 1933 |
2207 // Reset frame count of inter 0,0 motion vector usage. | 1934 // Reset frame count of inter 0,0 motion vector usage. |
2208 cpi->inter_zz_count = 0; | 1935 cpi->inter_zz_count = 0; |
2209 | 1936 |
2210 vp9_zero(cm->counts.switchable_interp); | 1937 vp9_zero(cm->counts.switchable_interp); |
2211 vp9_zero(cpi->txfm_stepdown_count); | 1938 vp9_zero(cpi->tx_stepdown_count); |
2212 | 1939 |
2213 xd->mi_8x8 = cm->mi_grid_visible; | 1940 xd->mi_8x8 = cm->mi_grid_visible; |
2214 // required for vp9_frame_init_quantizer | 1941 // required for vp9_frame_init_quantizer |
2215 xd->this_mi = | |
2216 xd->mi_8x8[0] = cm->mi; | 1942 xd->mi_8x8[0] = cm->mi; |
2217 xd->mic_stream_ptr = cm->mi; | |
2218 | 1943 |
2219 xd->last_mi = cm->prev_mi; | 1944 xd->last_mi = cm->prev_mi; |
2220 | 1945 |
2221 | |
2222 vp9_zero(cpi->NMVcount); | 1946 vp9_zero(cpi->NMVcount); |
2223 vp9_zero(cpi->coef_counts); | 1947 vp9_zero(cpi->coef_counts); |
2224 vp9_zero(cm->counts.eob_branch); | 1948 vp9_zero(cm->counts.eob_branch); |
2225 | 1949 |
2226 cpi->mb.e_mbd.lossless = cm->base_qindex == 0 && cm->y_dc_delta_q == 0 | 1950 cpi->mb.e_mbd.lossless = cm->base_qindex == 0 && cm->y_dc_delta_q == 0 |
2227 && cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; | 1951 && cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; |
2228 switch_lossless_mode(cpi, cpi->mb.e_mbd.lossless); | 1952 switch_lossless_mode(cpi, cpi->mb.e_mbd.lossless); |
2229 | 1953 |
2230 vp9_frame_init_quantizer(cpi); | 1954 vp9_frame_init_quantizer(cpi); |
2231 | 1955 |
2232 vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y_dc_delta_q); | 1956 vp9_initialize_rd_consts(cpi); |
2233 vp9_initialize_me_consts(cpi, cm->base_qindex); | 1957 vp9_initialize_me_consts(cpi, cm->base_qindex); |
2234 switch_tx_mode(cpi); | 1958 switch_tx_mode(cpi); |
2235 | 1959 |
2236 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 1960 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
2237 // Initialize encode frame context. | 1961 // Initialize encode frame context. |
2238 init_encode_frame_mb_context(cpi); | 1962 init_encode_frame_mb_context(cpi); |
2239 | 1963 |
2240 // Build a frame level activity map | 1964 // Build a frame level activity map |
2241 build_activity_map(cpi); | 1965 build_activity_map(cpi); |
2242 } | 1966 } |
(...skipping 13 matching lines...) Expand all Loading... |
2256 vpx_usec_timer_start(&emr_timer); | 1980 vpx_usec_timer_start(&emr_timer); |
2257 | 1981 |
2258 { | 1982 { |
2259 // Take tiles into account and give start/end MB | 1983 // Take tiles into account and give start/end MB |
2260 int tile_col, tile_row; | 1984 int tile_col, tile_row; |
2261 TOKENEXTRA *tp = cpi->tok; | 1985 TOKENEXTRA *tp = cpi->tok; |
2262 const int tile_cols = 1 << cm->log2_tile_cols; | 1986 const int tile_cols = 1 << cm->log2_tile_cols; |
2263 const int tile_rows = 1 << cm->log2_tile_rows; | 1987 const int tile_rows = 1 << cm->log2_tile_rows; |
2264 | 1988 |
2265 for (tile_row = 0; tile_row < tile_rows; tile_row++) { | 1989 for (tile_row = 0; tile_row < tile_rows; tile_row++) { |
2266 vp9_get_tile_row_offsets(cm, tile_row); | |
2267 | |
2268 for (tile_col = 0; tile_col < tile_cols; tile_col++) { | 1990 for (tile_col = 0; tile_col < tile_cols; tile_col++) { |
| 1991 TileInfo tile; |
2269 TOKENEXTRA *tp_old = tp; | 1992 TOKENEXTRA *tp_old = tp; |
2270 | 1993 |
2271 // For each row of SBs in the frame | 1994 // For each row of SBs in the frame |
2272 vp9_get_tile_col_offsets(cm, tile_col); | 1995 vp9_tile_init(&tile, cm, tile_row, tile_col); |
2273 for (mi_row = cm->cur_tile_mi_row_start; | 1996 for (mi_row = tile.mi_row_start; |
2274 mi_row < cm->cur_tile_mi_row_end; mi_row += 8) | 1997 mi_row < tile.mi_row_end; mi_row += 8) |
2275 encode_sb_row(cpi, mi_row, &tp, &totalrate); | 1998 encode_sb_row(cpi, &tile, mi_row, &tp, &totalrate); |
2276 | 1999 |
2277 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); | 2000 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); |
2278 assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); | 2001 assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); |
2279 } | 2002 } |
2280 } | 2003 } |
2281 } | 2004 } |
2282 | 2005 |
2283 vpx_usec_timer_mark(&emr_timer); | 2006 vpx_usec_timer_mark(&emr_timer); |
2284 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); | 2007 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); |
2285 } | 2008 } |
(...skipping 13 matching lines...) Expand all Loading... |
2299 } | 2022 } |
2300 | 2023 |
2301 // 256 rate units to the bit, | 2024 // 256 rate units to the bit, |
2302 // projected_frame_size in units of BYTES | 2025 // projected_frame_size in units of BYTES |
2303 cpi->projected_frame_size = totalrate >> 8; | 2026 cpi->projected_frame_size = totalrate >> 8; |
2304 | 2027 |
2305 #if 0 | 2028 #if 0 |
2306 // Keep record of the total distortion this time around for future use | 2029 // Keep record of the total distortion this time around for future use |
2307 cpi->last_frame_distortion = cpi->frame_distortion; | 2030 cpi->last_frame_distortion = cpi->frame_distortion; |
2308 #endif | 2031 #endif |
2309 | |
2310 } | 2032 } |
2311 | 2033 |
2312 static int check_dual_ref_flags(VP9_COMP *cpi) { | 2034 static int check_dual_ref_flags(VP9_COMP *cpi) { |
2313 const int ref_flags = cpi->ref_frame_flags; | 2035 const int ref_flags = cpi->ref_frame_flags; |
2314 | 2036 |
2315 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { | 2037 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { |
2316 return 0; | 2038 return 0; |
2317 } else { | 2039 } else { |
2318 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) | 2040 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) |
2319 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; | 2041 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; |
(...skipping 20 matching lines...) Expand all Loading... |
2340 for (y = 0; y < ymbs; y++) { | 2062 for (y = 0; y < ymbs; y++) { |
2341 for (x = 0; x < xmbs; x++) | 2063 for (x = 0; x < xmbs; x++) |
2342 mi_8x8[y * mis + x]->mbmi.tx_size = tx_size; | 2064 mi_8x8[y * mis + x]->mbmi.tx_size = tx_size; |
2343 } | 2065 } |
2344 } | 2066 } |
2345 | 2067 |
2346 static void reset_skip_txfm_size_b(VP9_COMP *cpi, MODE_INFO **mi_8x8, | 2068 static void reset_skip_txfm_size_b(VP9_COMP *cpi, MODE_INFO **mi_8x8, |
2347 int mis, TX_SIZE max_tx_size, int bw, int bh, | 2069 int mis, TX_SIZE max_tx_size, int bw, int bh, |
2348 int mi_row, int mi_col, BLOCK_SIZE bsize) { | 2070 int mi_row, int mi_col, BLOCK_SIZE bsize) { |
2349 VP9_COMMON * const cm = &cpi->common; | 2071 VP9_COMMON * const cm = &cpi->common; |
2350 MB_MODE_INFO * const mbmi = &mi_8x8[0]->mbmi; | |
2351 | 2072 |
2352 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 2073 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) { |
2353 return; | 2074 return; |
| 2075 } else { |
| 2076 MB_MODE_INFO * const mbmi = &mi_8x8[0]->mbmi; |
| 2077 if (mbmi->tx_size > max_tx_size) { |
| 2078 const int ymbs = MIN(bh, cm->mi_rows - mi_row); |
| 2079 const int xmbs = MIN(bw, cm->mi_cols - mi_col); |
2354 | 2080 |
2355 if (mbmi->tx_size > max_tx_size) { | 2081 assert(vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) || |
2356 const int ymbs = MIN(bh, cm->mi_rows - mi_row); | 2082 get_skip_flag(mi_8x8, mis, ymbs, xmbs)); |
2357 const int xmbs = MIN(bw, cm->mi_cols - mi_col); | 2083 set_txfm_flag(mi_8x8, mis, ymbs, xmbs, max_tx_size); |
2358 | 2084 } |
2359 assert(vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) || | |
2360 get_skip_flag(mi_8x8, mis, ymbs, xmbs)); | |
2361 set_txfm_flag(mi_8x8, mis, ymbs, xmbs, max_tx_size); | |
2362 } | 2085 } |
2363 } | 2086 } |
2364 | 2087 |
2365 static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO **mi_8x8, | 2088 static void reset_skip_txfm_size_sb(VP9_COMP *cpi, MODE_INFO **mi_8x8, |
2366 TX_SIZE max_tx_size, int mi_row, int mi_col, | 2089 TX_SIZE max_tx_size, int mi_row, int mi_col, |
2367 BLOCK_SIZE bsize) { | 2090 BLOCK_SIZE bsize) { |
2368 VP9_COMMON * const cm = &cpi->common; | 2091 VP9_COMMON * const cm = &cpi->common; |
2369 const int mis = cm->mode_info_stride; | 2092 const int mis = cm->mode_info_stride; |
2370 int bw, bh; | 2093 int bw, bh; |
2371 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; | 2094 const int bs = num_8x8_blocks_wide_lookup[bsize], hbs = bs / 2; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2417 mi_8x8 = mi_ptr; | 2140 mi_8x8 = mi_ptr; |
2418 for (mi_col = 0; mi_col < cm->mi_cols; mi_col += 8, mi_8x8 += 8) { | 2141 for (mi_col = 0; mi_col < cm->mi_cols; mi_col += 8, mi_8x8 += 8) { |
2419 reset_skip_txfm_size_sb(cpi, mi_8x8, txfm_max, mi_row, mi_col, | 2142 reset_skip_txfm_size_sb(cpi, mi_8x8, txfm_max, mi_row, mi_col, |
2420 BLOCK_64X64); | 2143 BLOCK_64X64); |
2421 } | 2144 } |
2422 } | 2145 } |
2423 } | 2146 } |
2424 | 2147 |
2425 static int get_frame_type(VP9_COMP *cpi) { | 2148 static int get_frame_type(VP9_COMP *cpi) { |
2426 int frame_type; | 2149 int frame_type; |
2427 if (cpi->common.frame_type == KEY_FRAME) | 2150 if (frame_is_intra_only(&cpi->common)) |
2428 frame_type = 0; | 2151 frame_type = 0; |
2429 else if (cpi->is_src_frame_alt_ref && cpi->refresh_golden_frame) | 2152 else if (cpi->is_src_frame_alt_ref && cpi->refresh_golden_frame) |
2430 frame_type = 3; | 2153 frame_type = 3; |
2431 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) | 2154 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) |
2432 frame_type = 1; | 2155 frame_type = 1; |
2433 else | 2156 else |
2434 frame_type = 2; | 2157 frame_type = 2; |
2435 return frame_type; | 2158 return frame_type; |
2436 } | 2159 } |
2437 | 2160 |
2438 static void select_tx_mode(VP9_COMP *cpi) { | 2161 static void select_tx_mode(VP9_COMP *cpi) { |
2439 if (cpi->oxcf.lossless) { | 2162 if (cpi->oxcf.lossless) { |
2440 cpi->common.tx_mode = ONLY_4X4; | 2163 cpi->common.tx_mode = ONLY_4X4; |
2441 } else if (cpi->common.current_video_frame == 0) { | 2164 } else if (cpi->common.current_video_frame == 0) { |
2442 cpi->common.tx_mode = TX_MODE_SELECT; | 2165 cpi->common.tx_mode = TX_MODE_SELECT; |
2443 } else { | 2166 } else { |
2444 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { | 2167 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { |
2445 cpi->common.tx_mode = ALLOW_32X32; | 2168 cpi->common.tx_mode = ALLOW_32X32; |
2446 } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { | 2169 } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { |
2447 int frame_type = get_frame_type(cpi); | 2170 int frame_type = get_frame_type(cpi); |
2448 cpi->common.tx_mode = | 2171 cpi->common.tx_mode = |
2449 cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] | 2172 cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] |
2450 > cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? | 2173 > cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? |
2451 ALLOW_32X32 : TX_MODE_SELECT; | 2174 ALLOW_32X32 : TX_MODE_SELECT; |
2452 } else { | 2175 } else { |
2453 unsigned int total = 0; | 2176 unsigned int total = 0; |
2454 int i; | 2177 int i; |
2455 for (i = 0; i < TX_SIZES; ++i) | 2178 for (i = 0; i < TX_SIZES; ++i) |
2456 total += cpi->txfm_stepdown_count[i]; | 2179 total += cpi->tx_stepdown_count[i]; |
2457 if (total) { | 2180 if (total) { |
2458 double fraction = (double)cpi->txfm_stepdown_count[0] / total; | 2181 double fraction = (double)cpi->tx_stepdown_count[0] / total; |
2459 cpi->common.tx_mode = fraction > 0.90 ? ALLOW_32X32 : TX_MODE_SELECT; | 2182 cpi->common.tx_mode = fraction > 0.90 ? ALLOW_32X32 : TX_MODE_SELECT; |
2460 // printf("fraction = %f\n", fraction); | 2183 // printf("fraction = %f\n", fraction); |
2461 } // else keep unchanged | 2184 } // else keep unchanged |
2462 } | 2185 } |
2463 } | 2186 } |
2464 } | 2187 } |
2465 | 2188 |
2466 void vp9_encode_frame(VP9_COMP *cpi) { | 2189 void vp9_encode_frame(VP9_COMP *cpi) { |
2467 VP9_COMMON * const cm = &cpi->common; | 2190 VP9_COMMON * const cm = &cpi->common; |
2468 | 2191 |
2469 // In the longer term the encoder should be generalized to match the | 2192 // In the longer term the encoder should be generalized to match the |
2470 // decoder such that we allow compound where one of the 3 buffers has a | 2193 // decoder such that we allow compound where one of the 3 buffers has a |
2471 // different sign bias and that buffer is then the fixed ref. However, this | 2194 // different sign bias and that buffer is then the fixed ref. However, this |
2472 // requires further work in the rd loop. For now the only supported encoder | 2195 // requires further work in the rd loop. For now the only supported encoder |
2473 // side behavior is where the ALT ref buffer has opposite sign bias to | 2196 // side behavior is where the ALT ref buffer has opposite sign bias to |
2474 // the other two. | 2197 // the other two. |
2475 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] | 2198 if (!frame_is_intra_only(cm)) { |
2476 == cm->ref_frame_sign_bias[GOLDEN_FRAME]) | 2199 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] |
2477 || (cm->ref_frame_sign_bias[ALTREF_FRAME] | 2200 == cm->ref_frame_sign_bias[GOLDEN_FRAME]) |
2478 == cm->ref_frame_sign_bias[LAST_FRAME])) { | 2201 || (cm->ref_frame_sign_bias[ALTREF_FRAME] |
2479 cm->allow_comp_inter_inter = 0; | 2202 == cm->ref_frame_sign_bias[LAST_FRAME])) { |
2480 } else { | 2203 cm->allow_comp_inter_inter = 0; |
2481 cm->allow_comp_inter_inter = 1; | 2204 } else { |
2482 cm->comp_fixed_ref = ALTREF_FRAME; | 2205 cm->allow_comp_inter_inter = 1; |
2483 cm->comp_var_ref[0] = LAST_FRAME; | 2206 cm->comp_fixed_ref = ALTREF_FRAME; |
2484 cm->comp_var_ref[1] = GOLDEN_FRAME; | 2207 cm->comp_var_ref[0] = LAST_FRAME; |
| 2208 cm->comp_var_ref[1] = GOLDEN_FRAME; |
| 2209 } |
2485 } | 2210 } |
2486 | 2211 |
2487 if (cpi->sf.RD) { | 2212 if (cpi->sf.RD) { |
2488 int i, pred_type; | 2213 int i, pred_type; |
2489 INTERPOLATIONFILTERTYPE filter_type; | 2214 INTERPOLATION_TYPE filter_type; |
2490 /* | 2215 /* |
2491 * This code does a single RD pass over the whole frame assuming | 2216 * This code does a single RD pass over the whole frame assuming |
2492 * either compound, single or hybrid prediction as per whatever has | 2217 * either compound, single or hybrid prediction as per whatever has |
2493 * worked best for that type of frame in the past. | 2218 * worked best for that type of frame in the past. |
2494 * It also predicts whether another coding mode would have worked | 2219 * It also predicts whether another coding mode would have worked |
2495 * better that this coding mode. If that is the case, it remembers | 2220 * better that this coding mode. If that is the case, it remembers |
2496 * that for subsequent frames. | 2221 * that for subsequent frames. |
2497 * It does the same analysis for transform size selection also. | 2222 * It does the same analysis for transform size selection also. |
2498 */ | 2223 */ |
2499 int frame_type = get_frame_type(cpi); | 2224 int frame_type = get_frame_type(cpi); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2547 cpi->common.comp_pred_mode = pred_type; | 2272 cpi->common.comp_pred_mode = pred_type; |
2548 cpi->common.mcomp_filter_type = filter_type; | 2273 cpi->common.mcomp_filter_type = filter_type; |
2549 encode_frame_internal(cpi); | 2274 encode_frame_internal(cpi); |
2550 | 2275 |
2551 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { | 2276 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { |
2552 const int diff = (int) (cpi->rd_comp_pred_diff[i] / cpi->common.MBs); | 2277 const int diff = (int) (cpi->rd_comp_pred_diff[i] / cpi->common.MBs); |
2553 cpi->rd_prediction_type_threshes[frame_type][i] += diff; | 2278 cpi->rd_prediction_type_threshes[frame_type][i] += diff; |
2554 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; | 2279 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; |
2555 } | 2280 } |
2556 | 2281 |
2557 for (i = 0; i <= SWITCHABLE_FILTERS; i++) { | 2282 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
2558 const int64_t diff = cpi->rd_filter_diff[i] / cpi->common.MBs; | 2283 const int64_t diff = cpi->rd_filter_diff[i] / cpi->common.MBs; |
2559 cpi->rd_filter_threshes[frame_type][i] = | 2284 cpi->rd_filter_threshes[frame_type][i] = |
2560 (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; | 2285 (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; |
2561 } | 2286 } |
2562 | 2287 |
2563 for (i = 0; i < TX_MODES; ++i) { | 2288 for (i = 0; i < TX_MODES; ++i) { |
2564 int64_t pd = cpi->rd_tx_select_diff[i]; | 2289 int64_t pd = cpi->rd_tx_select_diff[i]; |
2565 int diff; | 2290 int diff; |
2566 if (i == TX_MODE_SELECT) | 2291 if (i == TX_MODE_SELECT) |
2567 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, | 2292 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2620 } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) { | 2345 } else if (count8x8_lp == 0 && count16x16_lp == 0 && count4x4 == 0) { |
2621 cpi->common.tx_mode = ALLOW_32X32; | 2346 cpi->common.tx_mode = ALLOW_32X32; |
2622 } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) { | 2347 } else if (count32x32 == 0 && count8x8_lp == 0 && count4x4 == 0) { |
2623 cpi->common.tx_mode = ALLOW_16X16; | 2348 cpi->common.tx_mode = ALLOW_16X16; |
2624 reset_skip_txfm_size(cpi, TX_16X16); | 2349 reset_skip_txfm_size(cpi, TX_16X16); |
2625 } | 2350 } |
2626 } | 2351 } |
2627 } else { | 2352 } else { |
2628 encode_frame_internal(cpi); | 2353 encode_frame_internal(cpi); |
2629 } | 2354 } |
2630 | |
2631 } | 2355 } |
2632 | 2356 |
2633 static void sum_intra_stats(VP9_COMP *cpi, const MODE_INFO *mi) { | 2357 static void sum_intra_stats(VP9_COMP *cpi, const MODE_INFO *mi) { |
2634 const MB_PREDICTION_MODE y_mode = mi->mbmi.mode; | 2358 const MB_PREDICTION_MODE y_mode = mi->mbmi.mode; |
2635 const MB_PREDICTION_MODE uv_mode = mi->mbmi.uv_mode; | 2359 const MB_PREDICTION_MODE uv_mode = mi->mbmi.uv_mode; |
2636 const BLOCK_SIZE bsize = mi->mbmi.sb_type; | 2360 const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
2637 | 2361 |
2638 ++cpi->y_uv_mode_count[y_mode][uv_mode]; | 2362 ++cpi->y_uv_mode_count[y_mode][uv_mode]; |
2639 | 2363 |
2640 if (bsize < BLOCK_8X8) { | 2364 if (bsize < BLOCK_8X8) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2725 | 2449 |
2726 if (!is_inter_block(mbmi)) { | 2450 if (!is_inter_block(mbmi)) { |
2727 vp9_encode_intra_block_y(x, MAX(bsize, BLOCK_8X8)); | 2451 vp9_encode_intra_block_y(x, MAX(bsize, BLOCK_8X8)); |
2728 vp9_encode_intra_block_uv(x, MAX(bsize, BLOCK_8X8)); | 2452 vp9_encode_intra_block_uv(x, MAX(bsize, BLOCK_8X8)); |
2729 if (output_enabled) | 2453 if (output_enabled) |
2730 sum_intra_stats(cpi, mi); | 2454 sum_intra_stats(cpi, mi); |
2731 } else { | 2455 } else { |
2732 int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[0])]; | 2456 int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[0])]; |
2733 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; | 2457 YV12_BUFFER_CONFIG *ref_fb = &cm->yv12_fb[idx]; |
2734 YV12_BUFFER_CONFIG *second_ref_fb = NULL; | 2458 YV12_BUFFER_CONFIG *second_ref_fb = NULL; |
2735 if (mbmi->ref_frame[1] > 0) { | 2459 if (has_second_ref(mbmi)) { |
2736 idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[1])]; | 2460 idx = cm->ref_frame_map[get_ref_frame_idx(cpi, mbmi->ref_frame[1])]; |
2737 second_ref_fb = &cm->yv12_fb[idx]; | 2461 second_ref_fb = &cm->yv12_fb[idx]; |
2738 } | 2462 } |
2739 | 2463 |
2740 assert(cm->frame_type != KEY_FRAME); | 2464 assert(cm->frame_type != KEY_FRAME); |
2741 | 2465 |
2742 setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, | 2466 setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, |
2743 &xd->scale_factor[0]); | 2467 &xd->scale_factor[0]); |
2744 setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, | 2468 setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, |
2745 &xd->scale_factor[1]); | 2469 &xd->scale_factor[1]); |
2746 | 2470 |
2747 | |
2748 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); | 2471 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
2749 } | 2472 } |
2750 | 2473 |
2751 if (!is_inter_block(mbmi)) { | 2474 if (!is_inter_block(mbmi)) { |
2752 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 2475 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
2753 } else if (!x->skip) { | 2476 } else if (!x->skip) { |
2754 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); | 2477 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); |
2755 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 2478 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
2756 } else { | 2479 } else { |
2757 int mb_skip_context = xd->left_available ? mi_8x8[-1]->mbmi.skip_coeff : 0; | 2480 int mb_skip_context = xd->left_available ? mi_8x8[-1]->mbmi.skip_coeff : 0; |
2758 mb_skip_context += mi_8x8[-mis] ? mi_8x8[-mis]->mbmi.skip_coeff : 0; | 2481 mb_skip_context += mi_8x8[-mis] ? mi_8x8[-mis]->mbmi.skip_coeff : 0; |
2759 | 2482 |
2760 mbmi->skip_coeff = 1; | 2483 mbmi->skip_coeff = 1; |
2761 if (output_enabled) | 2484 if (output_enabled) |
2762 cm->counts.mbskip[mb_skip_context][1]++; | 2485 cm->counts.mbskip[mb_skip_context][1]++; |
2763 reset_skip_context(xd, MAX(bsize, BLOCK_8X8)); | 2486 reset_skip_context(xd, MAX(bsize, BLOCK_8X8)); |
2764 } | 2487 } |
2765 | 2488 |
2766 if (output_enabled) { | 2489 if (output_enabled) { |
2767 if (cm->tx_mode == TX_MODE_SELECT && | 2490 if (cm->tx_mode == TX_MODE_SELECT && |
2768 mbmi->sb_type >= BLOCK_8X8 && | 2491 mbmi->sb_type >= BLOCK_8X8 && |
2769 !(is_inter_block(mbmi) && | 2492 !(is_inter_block(mbmi) && |
2770 (mbmi->skip_coeff || | 2493 (mbmi->skip_coeff || |
2771 vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)))) { | 2494 vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)))) { |
2772 const uint8_t context = vp9_get_pred_context_tx_size(xd); | 2495 const uint8_t context = vp9_get_pred_context_tx_size(xd); |
2773 update_tx_counts(bsize, context, mbmi->tx_size, &cm->counts.tx); | 2496 ++get_tx_counts(bsize, context, &cm->counts.tx)[mbmi->tx_size]; |
2774 } else { | 2497 } else { |
2775 int x, y; | 2498 int x, y; |
2776 TX_SIZE sz = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 2499 TX_SIZE sz = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
2777 assert(sizeof(tx_mode_to_biggest_tx_size) / | 2500 assert(sizeof(tx_mode_to_biggest_tx_size) / |
2778 sizeof(tx_mode_to_biggest_tx_size[0]) == TX_MODES); | 2501 sizeof(tx_mode_to_biggest_tx_size[0]) == TX_MODES); |
2779 // The new intra coding scheme requires no change of transform size | 2502 // The new intra coding scheme requires no change of transform size |
2780 if (is_inter_block(&mi->mbmi)) { | 2503 if (is_inter_block(&mi->mbmi)) { |
2781 if (sz == TX_32X32 && bsize < BLOCK_32X32) | 2504 if (sz == TX_32X32 && bsize < BLOCK_32X32) |
2782 sz = TX_16X16; | 2505 sz = TX_16X16; |
2783 if (sz == TX_16X16 && bsize < BLOCK_16X16) | 2506 if (sz == TX_16X16 && bsize < BLOCK_16X16) |
2784 sz = TX_8X8; | 2507 sz = TX_8X8; |
2785 if (sz == TX_8X8 && bsize < BLOCK_8X8) | 2508 if (sz == TX_8X8 && bsize < BLOCK_8X8) |
2786 sz = TX_4X4; | 2509 sz = TX_4X4; |
2787 } else if (bsize >= BLOCK_8X8) { | 2510 } else if (bsize >= BLOCK_8X8) { |
2788 sz = mbmi->tx_size; | 2511 sz = mbmi->tx_size; |
2789 } else { | 2512 } else { |
2790 sz = TX_4X4; | 2513 sz = TX_4X4; |
2791 } | 2514 } |
2792 | 2515 |
2793 for (y = 0; y < mi_height; y++) | 2516 for (y = 0; y < mi_height; y++) |
2794 for (x = 0; x < mi_width; x++) | 2517 for (x = 0; x < mi_width; x++) |
2795 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 2518 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
2796 mi_8x8[mis * y + x]->mbmi.tx_size = sz; | 2519 mi_8x8[mis * y + x]->mbmi.tx_size = sz; |
2797 } | 2520 } |
2798 } | 2521 } |
2799 } | 2522 } |
OLD | NEW |