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" | |
24 #include "vp9/common/vp9_findnearmv.h" | 23 #include "vp9/common/vp9_findnearmv.h" |
25 #include "vp9/common/vp9_idct.h" | 24 #include "vp9/common/vp9_idct.h" |
26 #include "vp9/common/vp9_mvref_common.h" | 25 #include "vp9/common/vp9_mvref_common.h" |
27 #include "vp9/common/vp9_pred_common.h" | 26 #include "vp9/common/vp9_pred_common.h" |
28 #include "vp9/common/vp9_quant_common.h" | 27 #include "vp9/common/vp9_quant_common.h" |
29 #include "vp9/common/vp9_reconintra.h" | 28 #include "vp9/common/vp9_reconintra.h" |
30 #include "vp9/common/vp9_reconinter.h" | 29 #include "vp9/common/vp9_reconinter.h" |
31 #include "vp9/common/vp9_seg_common.h" | 30 #include "vp9/common/vp9_seg_common.h" |
32 #include "vp9/common/vp9_tile_common.h" | 31 #include "vp9/common/vp9_tile_common.h" |
33 #include "vp9/encoder/vp9_encodeframe.h" | 32 #include "vp9/encoder/vp9_encodeframe.h" |
34 #include "vp9/encoder/vp9_encodeintra.h" | |
35 #include "vp9/encoder/vp9_encodemb.h" | 33 #include "vp9/encoder/vp9_encodemb.h" |
36 #include "vp9/encoder/vp9_encodemv.h" | 34 #include "vp9/encoder/vp9_encodemv.h" |
| 35 #include "vp9/encoder/vp9_extend.h" |
37 #include "vp9/encoder/vp9_onyx_int.h" | 36 #include "vp9/encoder/vp9_onyx_int.h" |
38 #include "vp9/encoder/vp9_rdopt.h" | 37 #include "vp9/encoder/vp9_rdopt.h" |
39 #include "vp9/encoder/vp9_segmentation.h" | 38 #include "vp9/encoder/vp9_segmentation.h" |
40 #include "vp9/common/vp9_systemdependent.h" | 39 #include "vp9/common/vp9_systemdependent.h" |
41 #include "vp9/encoder/vp9_tokenize.h" | 40 #include "vp9/encoder/vp9_tokenize.h" |
42 #include "vp9/encoder/vp9_vaq.h" | 41 #include "vp9/encoder/vp9_vaq.h" |
43 | 42 |
44 | 43 |
45 #define DBG_PRNT_SEGMAP 0 | 44 #define DBG_PRNT_SEGMAP 0 |
46 | 45 |
47 | 46 |
48 // #define ENC_DEBUG | 47 // #define ENC_DEBUG |
49 #ifdef ENC_DEBUG | 48 #ifdef ENC_DEBUG |
50 int enc_debug = 0; | 49 int enc_debug = 0; |
51 #endif | 50 #endif |
52 | 51 |
53 static INLINE uint8_t *get_sb_index(MACROBLOCKD *xd, BLOCK_SIZE subsize) { | 52 static INLINE uint8_t *get_sb_index(MACROBLOCK *x, BLOCK_SIZE subsize) { |
54 switch (subsize) { | 53 switch (subsize) { |
55 case BLOCK_64X64: | 54 case BLOCK_64X64: |
56 case BLOCK_64X32: | 55 case BLOCK_64X32: |
57 case BLOCK_32X64: | 56 case BLOCK_32X64: |
58 case BLOCK_32X32: | 57 case BLOCK_32X32: |
59 return &xd->sb_index; | 58 return &x->sb_index; |
60 case BLOCK_32X16: | 59 case BLOCK_32X16: |
61 case BLOCK_16X32: | 60 case BLOCK_16X32: |
62 case BLOCK_16X16: | 61 case BLOCK_16X16: |
63 return &xd->mb_index; | 62 return &x->mb_index; |
64 case BLOCK_16X8: | 63 case BLOCK_16X8: |
65 case BLOCK_8X16: | 64 case BLOCK_8X16: |
66 case BLOCK_8X8: | 65 case BLOCK_8X8: |
67 return &xd->b_index; | 66 return &x->b_index; |
68 case BLOCK_8X4: | 67 case BLOCK_8X4: |
69 case BLOCK_4X8: | 68 case BLOCK_4X8: |
70 case BLOCK_4X4: | 69 case BLOCK_4X4: |
71 return &xd->ab_index; | 70 return &x->ab_index; |
72 default: | 71 default: |
73 assert(0); | 72 assert(0); |
74 return NULL; | 73 return NULL; |
75 } | 74 } |
76 } | 75 } |
77 | 76 |
78 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, | 77 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
79 int mi_row, int mi_col, BLOCK_SIZE bsize); | 78 int mi_row, int mi_col, BLOCK_SIZE bsize); |
80 | 79 |
81 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); | 80 static void adjust_act_zbin(VP9_COMP *cpi, MACROBLOCK *x); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 353 |
355 x->rdmult = (unsigned int) (((int64_t) x->rdmult * b + (a >> 1)) / a); | 354 x->rdmult = (unsigned int) (((int64_t) x->rdmult * b + (a >> 1)) / a); |
356 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); | 355 x->errorperbit = x->rdmult * 100 / (110 * x->rddiv); |
357 x->errorperbit += (x->errorperbit == 0); | 356 x->errorperbit += (x->errorperbit == 0); |
358 #endif | 357 #endif |
359 | 358 |
360 // Activity based Zbin adjustment | 359 // Activity based Zbin adjustment |
361 adjust_act_zbin(cpi, x); | 360 adjust_act_zbin(cpi, x); |
362 } | 361 } |
363 | 362 |
| 363 // Select a segment for the current SB64 |
| 364 static void select_in_frame_q_segment(VP9_COMP *cpi, |
| 365 int mi_row, int mi_col, |
| 366 int output_enabled, int projected_rate) { |
| 367 VP9_COMMON * const cm = &cpi->common; |
| 368 int target_rate = cpi->rc.sb64_target_rate << 8; // convert to bits << 8 |
| 369 |
| 370 const int mi_offset = mi_row * cm->mi_cols + mi_col; |
| 371 const int bw = 1 << mi_width_log2(BLOCK_64X64); |
| 372 const int bh = 1 << mi_height_log2(BLOCK_64X64); |
| 373 const int xmis = MIN(cm->mi_cols - mi_col, bw); |
| 374 const int ymis = MIN(cm->mi_rows - mi_row, bh); |
| 375 int complexity_metric = 64; |
| 376 int x, y; |
| 377 |
| 378 unsigned char segment; |
| 379 |
| 380 if (!output_enabled) { |
| 381 segment = 0; |
| 382 } else { |
| 383 // Rate depends on fraction of a SB64 in frame (xmis * ymis / bw * bh). |
| 384 // It is converted to bits * 256 units |
| 385 target_rate = (cpi->rc.sb64_target_rate * xmis * ymis * 256) / (bw * bh); |
| 386 |
| 387 if (projected_rate < (target_rate / 4)) { |
| 388 segment = 2; |
| 389 } else if (projected_rate < (target_rate / 2)) { |
| 390 segment = 1; |
| 391 } else { |
| 392 segment = 0; |
| 393 } |
| 394 |
| 395 complexity_metric = |
| 396 clamp((int)((projected_rate * 64) / target_rate), 16, 255); |
| 397 } |
| 398 |
| 399 // Fill in the entires in the segment map corresponding to this SB64 |
| 400 for (y = 0; y < ymis; y++) { |
| 401 for (x = 0; x < xmis; x++) { |
| 402 cpi->segmentation_map[mi_offset + y * cm->mi_cols + x] = segment; |
| 403 cpi->complexity_map[mi_offset + y * cm->mi_cols + x] = |
| 404 (unsigned char)complexity_metric; |
| 405 } |
| 406 } |
| 407 } |
| 408 |
364 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, | 409 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
365 BLOCK_SIZE bsize, int output_enabled) { | 410 BLOCK_SIZE bsize, int output_enabled) { |
366 int i, x_idx, y; | 411 int i, x_idx, y; |
367 VP9_COMMON *const cm = &cpi->common; | 412 VP9_COMMON *const cm = &cpi->common; |
368 MACROBLOCK *const x = &cpi->mb; | 413 MACROBLOCK *const x = &cpi->mb; |
369 MACROBLOCKD *const xd = &x->e_mbd; | 414 MACROBLOCKD *const xd = &x->e_mbd; |
| 415 struct macroblock_plane *const p = x->plane; |
| 416 struct macroblockd_plane *const pd = xd->plane; |
370 MODE_INFO *mi = &ctx->mic; | 417 MODE_INFO *mi = &ctx->mic; |
371 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 418 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
372 MODE_INFO *mi_addr = xd->mi_8x8[0]; | 419 MODE_INFO *mi_addr = xd->mi_8x8[0]; |
373 | 420 |
374 int mb_mode_index = ctx->best_mode_index; | 421 int mb_mode_index = ctx->best_mode_index; |
375 const int mis = cm->mode_info_stride; | 422 const int mis = cm->mode_info_stride; |
376 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 423 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
377 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 424 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 425 int max_plane; |
378 | 426 |
379 assert(mi->mbmi.mode < MB_MODE_COUNT); | 427 assert(mi->mbmi.mode < MB_MODE_COUNT); |
380 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); | 428 assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); |
381 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); | 429 assert(mi->mbmi.ref_frame[1] < MAX_REF_FRAMES); |
382 assert(mi->mbmi.sb_type == bsize); | 430 assert(mi->mbmi.sb_type == bsize); |
383 | 431 |
| 432 // For in frame adaptive Q copy over the chosen segment id into the |
| 433 // mode innfo context for the chosen mode / partition. |
| 434 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && output_enabled) |
| 435 mi->mbmi.segment_id = xd->mi_8x8[0]->mbmi.segment_id; |
| 436 |
384 *mi_addr = *mi; | 437 *mi_addr = *mi; |
385 | 438 |
| 439 max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; |
| 440 for (i = 0; i < max_plane; ++i) { |
| 441 p[i].coeff = ctx->coeff_pbuf[i][1]; |
| 442 p[i].qcoeff = ctx->qcoeff_pbuf[i][1]; |
| 443 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; |
| 444 p[i].eobs = ctx->eobs_pbuf[i][1]; |
| 445 } |
| 446 |
| 447 for (i = max_plane; i < MAX_MB_PLANE; ++i) { |
| 448 p[i].coeff = ctx->coeff_pbuf[i][2]; |
| 449 p[i].qcoeff = ctx->qcoeff_pbuf[i][2]; |
| 450 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2]; |
| 451 p[i].eobs = ctx->eobs_pbuf[i][2]; |
| 452 } |
| 453 |
386 // Restore the coding context of the MB to that that was in place | 454 // Restore the coding context of the MB to that that was in place |
387 // when the mode was picked for it | 455 // when the mode was picked for it |
388 for (y = 0; y < mi_height; y++) | 456 for (y = 0; y < mi_height; y++) |
389 for (x_idx = 0; x_idx < mi_width; x_idx++) | 457 for (x_idx = 0; x_idx < mi_width; x_idx++) |
390 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx | 458 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx |
391 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) | 459 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) { |
392 xd->mi_8x8[x_idx + y * mis] = mi_addr; | 460 xd->mi_8x8[x_idx + y * mis] = mi_addr; |
| 461 } |
393 | 462 |
394 if (cpi->sf.variance_adaptive_quantization) { | 463 if ((cpi->oxcf.aq_mode == VARIANCE_AQ) || |
| 464 (cpi->oxcf.aq_mode == COMPLEXITY_AQ)) { |
395 vp9_mb_init_quantizer(cpi, x); | 465 vp9_mb_init_quantizer(cpi, x); |
396 } | 466 } |
397 | 467 |
398 // FIXME(rbultje) I'm pretty sure this should go to the end of this block | 468 // FIXME(rbultje) I'm pretty sure this should go to the end of this block |
399 // (i.e. after the output_enabled) | 469 // (i.e. after the output_enabled) |
400 if (bsize < BLOCK_32X32) { | 470 if (bsize < BLOCK_32X32) { |
401 if (bsize < BLOCK_16X16) | 471 if (bsize < BLOCK_16X16) |
402 ctx->tx_rd_diff[ALLOW_16X16] = ctx->tx_rd_diff[ALLOW_8X8]; | 472 ctx->tx_rd_diff[ALLOW_16X16] = ctx->tx_rd_diff[ALLOW_8X8]; |
403 ctx->tx_rd_diff[ALLOW_32X32] = ctx->tx_rd_diff[ALLOW_16X16]; | 473 ctx->tx_rd_diff[ALLOW_32X32] = ctx->tx_rd_diff[ALLOW_16X16]; |
404 } | 474 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 mbmi->best_mv[0].as_int = best_mv[0].as_int; | 524 mbmi->best_mv[0].as_int = best_mv[0].as_int; |
455 mbmi->best_mv[1].as_int = best_mv[1].as_int; | 525 mbmi->best_mv[1].as_int = best_mv[1].as_int; |
456 vp9_update_mv_count(cpi, x, best_mv); | 526 vp9_update_mv_count(cpi, x, best_mv); |
457 } | 527 } |
458 | 528 |
459 if (cm->mcomp_filter_type == SWITCHABLE && is_inter_mode(mbmi->mode)) { | 529 if (cm->mcomp_filter_type == SWITCHABLE && is_inter_mode(mbmi->mode)) { |
460 const int ctx = vp9_get_pred_context_switchable_interp(xd); | 530 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
461 ++cm->counts.switchable_interp[ctx][mbmi->interp_filter]; | 531 ++cm->counts.switchable_interp[ctx][mbmi->interp_filter]; |
462 } | 532 } |
463 | 533 |
464 cpi->rd_comp_pred_diff[SINGLE_PREDICTION_ONLY] += ctx->single_pred_diff; | 534 cpi->rd_comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff; |
465 cpi->rd_comp_pred_diff[COMP_PREDICTION_ONLY] += ctx->comp_pred_diff; | 535 cpi->rd_comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff; |
466 cpi->rd_comp_pred_diff[HYBRID_PREDICTION] += ctx->hybrid_pred_diff; | 536 cpi->rd_comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff; |
467 | 537 |
468 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 538 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
469 cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; | 539 cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; |
470 } | 540 } |
471 } | 541 } |
472 | 542 |
473 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, | 543 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, |
474 int mi_row, int mi_col) { | 544 int mi_row, int mi_col) { |
475 uint8_t *const buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, | 545 uint8_t *const buffers[4] = {src->y_buffer, src->u_buffer, src->v_buffer, |
476 src->alpha_buffer}; | 546 src->alpha_buffer}; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 | 603 |
534 /* set up source buffers */ | 604 /* set up source buffers */ |
535 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); | 605 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); |
536 | 606 |
537 /* R/D setup */ | 607 /* R/D setup */ |
538 x->rddiv = cpi->RDDIV; | 608 x->rddiv = cpi->RDDIV; |
539 x->rdmult = cpi->RDMULT; | 609 x->rdmult = cpi->RDMULT; |
540 | 610 |
541 /* segment ID */ | 611 /* segment ID */ |
542 if (seg->enabled) { | 612 if (seg->enabled) { |
543 if (!cpi->sf.variance_adaptive_quantization) { | 613 if (cpi->oxcf.aq_mode != VARIANCE_AQ) { |
544 uint8_t *map = seg->update_map ? cpi->segmentation_map | 614 uint8_t *map = seg->update_map ? cpi->segmentation_map |
545 : cm->last_frame_seg_map; | 615 : cm->last_frame_seg_map; |
546 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 616 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
547 } | 617 } |
548 vp9_mb_init_quantizer(cpi, x); | 618 vp9_mb_init_quantizer(cpi, x); |
549 | 619 |
550 if (seg->enabled && cpi->seg0_cnt > 0 | 620 if (seg->enabled && cpi->seg0_cnt > 0 |
551 && !vp9_segfeature_active(seg, 0, SEG_LVL_REF_FRAME) | 621 && !vp9_segfeature_active(seg, 0, SEG_LVL_REF_FRAME) |
552 && vp9_segfeature_active(seg, 1, SEG_LVL_REF_FRAME)) { | 622 && vp9_segfeature_active(seg, 1, SEG_LVL_REF_FRAME)) { |
553 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; | 623 cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; |
(...skipping 17 matching lines...) Expand all Loading... |
571 } | 641 } |
572 | 642 |
573 static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, | 643 static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, |
574 int mi_row, int mi_col, | 644 int mi_row, int mi_col, |
575 int *totalrate, int64_t *totaldist, | 645 int *totalrate, int64_t *totaldist, |
576 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, | 646 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, |
577 int64_t best_rd) { | 647 int64_t best_rd) { |
578 VP9_COMMON *const cm = &cpi->common; | 648 VP9_COMMON *const cm = &cpi->common; |
579 MACROBLOCK *const x = &cpi->mb; | 649 MACROBLOCK *const x = &cpi->mb; |
580 MACROBLOCKD *const xd = &x->e_mbd; | 650 MACROBLOCKD *const xd = &x->e_mbd; |
| 651 struct macroblock_plane *const p = x->plane; |
| 652 struct macroblockd_plane *const pd = xd->plane; |
| 653 int i; |
581 int orig_rdmult = x->rdmult; | 654 int orig_rdmult = x->rdmult; |
582 double rdmult_ratio; | 655 double rdmult_ratio; |
583 | 656 |
584 vp9_clear_system_state(); // __asm emms; | 657 vp9_clear_system_state(); // __asm emms; |
585 rdmult_ratio = 1.0; // avoid uninitialized warnings | 658 rdmult_ratio = 1.0; // avoid uninitialized warnings |
586 | 659 |
587 // Use the lower precision, but faster, 32x32 fdct for mode selection. | 660 // Use the lower precision, but faster, 32x32 fdct for mode selection. |
588 x->use_lp32x32fdct = 1; | 661 x->use_lp32x32fdct = 1; |
589 | 662 |
590 if (bsize < BLOCK_8X8) { | 663 if (bsize < BLOCK_8X8) { |
591 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 | 664 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
592 // there is nothing to be done. | 665 // there is nothing to be done. |
593 if (xd->ab_index != 0) { | 666 if (x->ab_index != 0) { |
594 *totalrate = 0; | 667 *totalrate = 0; |
595 *totaldist = 0; | 668 *totaldist = 0; |
596 return; | 669 return; |
597 } | 670 } |
598 } | 671 } |
599 | 672 |
600 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 673 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
601 xd->mi_8x8[0]->mbmi.sb_type = bsize; | 674 xd->mi_8x8[0]->mbmi.sb_type = bsize; |
602 | 675 |
| 676 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 677 p[i].coeff = ctx->coeff_pbuf[i][0]; |
| 678 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; |
| 679 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; |
| 680 p[i].eobs = ctx->eobs_pbuf[i][0]; |
| 681 } |
| 682 ctx->is_coded = 0; |
| 683 x->skip_recode = 0; |
| 684 |
603 // Set to zero to make sure we do not use the previous encoded frame stats | 685 // Set to zero to make sure we do not use the previous encoded frame stats |
604 xd->mi_8x8[0]->mbmi.skip_coeff = 0; | 686 xd->mi_8x8[0]->mbmi.skip_coeff = 0; |
605 | 687 |
606 x->source_variance = get_sby_perpixel_variance(cpi, x, bsize); | 688 x->source_variance = get_sby_perpixel_variance(cpi, x, bsize); |
607 | 689 |
608 if (cpi->sf.variance_adaptive_quantization) { | 690 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
609 int energy; | 691 int energy; |
610 if (bsize <= BLOCK_16X16) { | 692 if (bsize <= BLOCK_16X16) { |
611 energy = x->mb_energy; | 693 energy = x->mb_energy; |
612 } else { | 694 } else { |
613 energy = vp9_block_energy(cpi, x, bsize); | 695 energy = vp9_block_energy(cpi, x, bsize); |
614 } | 696 } |
615 | 697 |
616 xd->mi_8x8[0]->mbmi.segment_id = vp9_vaq_segment_id(energy); | 698 xd->mi_8x8[0]->mbmi.segment_id = vp9_vaq_segment_id(energy); |
617 rdmult_ratio = vp9_vaq_rdmult_ratio(energy); | 699 rdmult_ratio = vp9_vaq_rdmult_ratio(energy); |
618 vp9_mb_init_quantizer(cpi, x); | 700 vp9_mb_init_quantizer(cpi, x); |
619 } | 701 } |
620 | 702 |
621 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) | 703 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) |
622 vp9_activity_masking(cpi, x); | 704 vp9_activity_masking(cpi, x); |
623 | 705 |
624 if (cpi->sf.variance_adaptive_quantization) { | 706 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
625 vp9_clear_system_state(); // __asm emms; | 707 vp9_clear_system_state(); // __asm emms; |
626 x->rdmult = round(x->rdmult * rdmult_ratio); | 708 x->rdmult = round(x->rdmult * rdmult_ratio); |
| 709 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 710 const int mi_offset = mi_row * cm->mi_cols + mi_col; |
| 711 unsigned char complexity = cpi->complexity_map[mi_offset]; |
| 712 const int is_edge = (mi_row == 0) || (mi_row == (cm->mi_rows - 1)) || |
| 713 (mi_col == 0) || (mi_col == (cm->mi_cols - 1)); |
| 714 |
| 715 if (!is_edge && (complexity > 128)) |
| 716 x->rdmult = x->rdmult + ((x->rdmult * (complexity - 128)) / 256); |
627 } | 717 } |
628 | 718 |
629 // Find best coding mode & reconstruct the MB so it is available | 719 // Find best coding mode & reconstruct the MB so it is available |
630 // as a predictor for MBs that follow in the SB | 720 // as a predictor for MBs that follow in the SB |
631 if (frame_is_intra_only(cm)) { | 721 if (frame_is_intra_only(cm)) { |
632 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, | 722 vp9_rd_pick_intra_mode_sb(cpi, x, totalrate, totaldist, bsize, ctx, |
633 best_rd); | 723 best_rd); |
634 } else { | 724 } else { |
635 if (bsize >= BLOCK_8X8) | 725 if (bsize >= BLOCK_8X8) |
636 vp9_rd_pick_inter_mode_sb(cpi, x, tile, mi_row, mi_col, | 726 vp9_rd_pick_inter_mode_sb(cpi, x, tile, mi_row, mi_col, |
637 totalrate, totaldist, bsize, ctx, best_rd); | 727 totalrate, totaldist, bsize, ctx, best_rd); |
638 else | 728 else |
639 vp9_rd_pick_inter_mode_sub8x8(cpi, x, tile, mi_row, mi_col, totalrate, | 729 vp9_rd_pick_inter_mode_sub8x8(cpi, x, tile, mi_row, mi_col, totalrate, |
640 totaldist, bsize, ctx, best_rd); | 730 totaldist, bsize, ctx, best_rd); |
641 } | 731 } |
642 | 732 |
643 if (cpi->sf.variance_adaptive_quantization) { | 733 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
644 x->rdmult = orig_rdmult; | 734 x->rdmult = orig_rdmult; |
645 if (*totalrate != INT_MAX) { | 735 if (*totalrate != INT_MAX) { |
646 vp9_clear_system_state(); // __asm emms; | 736 vp9_clear_system_state(); // __asm emms; |
647 *totalrate = round(*totalrate * rdmult_ratio); | 737 *totalrate = round(*totalrate * rdmult_ratio); |
648 } | 738 } |
649 } | 739 } |
650 } | 740 } |
651 | 741 |
652 static void update_stats(VP9_COMP *cpi) { | 742 static void update_stats(VP9_COMP *cpi) { |
653 VP9_COMMON *const cm = &cpi->common; | 743 VP9_COMMON *const cm = &cpi->common; |
654 MACROBLOCK *const x = &cpi->mb; | 744 MACROBLOCK *const x = &cpi->mb; |
655 MACROBLOCKD *const xd = &x->e_mbd; | 745 MACROBLOCKD *const xd = &x->e_mbd; |
656 MODE_INFO *mi = xd->mi_8x8[0]; | 746 MODE_INFO *mi = xd->mi_8x8[0]; |
657 MB_MODE_INFO *const mbmi = &mi->mbmi; | 747 MB_MODE_INFO *const mbmi = &mi->mbmi; |
658 | 748 |
659 if (!frame_is_intra_only(cm)) { | 749 if (!frame_is_intra_only(cm)) { |
660 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 750 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
661 SEG_LVL_REF_FRAME); | 751 SEG_LVL_REF_FRAME); |
662 | 752 |
663 if (!seg_ref_active) | 753 if (!seg_ref_active) |
664 cpi->intra_inter_count[vp9_get_pred_context_intra_inter(xd)] | 754 cpi->intra_inter_count[vp9_get_intra_inter_context(xd)] |
665 [is_inter_block(mbmi)]++; | 755 [is_inter_block(mbmi)]++; |
666 | 756 |
667 // If the segment reference feature is enabled we have only a single | 757 // If the segment reference feature is enabled we have only a single |
668 // reference frame allowed for the segment so exclude it from | 758 // reference frame allowed for the segment so exclude it from |
669 // the reference frame counts used to work out probabilities. | 759 // the reference frame counts used to work out probabilities. |
670 if (is_inter_block(mbmi) && !seg_ref_active) { | 760 if (is_inter_block(mbmi) && !seg_ref_active) { |
671 if (cm->comp_pred_mode == HYBRID_PREDICTION) | 761 if (cm->reference_mode == REFERENCE_MODE_SELECT) |
672 cpi->comp_inter_count[vp9_get_pred_context_comp_inter_inter(cm, xd)] | 762 cpi->comp_inter_count[vp9_get_reference_mode_context(cm, xd)] |
673 [has_second_ref(mbmi)]++; | 763 [has_second_ref(mbmi)]++; |
674 | 764 |
675 if (has_second_ref(mbmi)) { | 765 if (has_second_ref(mbmi)) { |
676 cpi->comp_ref_count[vp9_get_pred_context_comp_ref_p(cm, xd)] | 766 cpi->comp_ref_count[vp9_get_pred_context_comp_ref_p(cm, xd)] |
677 [mbmi->ref_frame[0] == GOLDEN_FRAME]++; | 767 [mbmi->ref_frame[0] == GOLDEN_FRAME]++; |
678 } else { | 768 } else { |
679 cpi->single_ref_count[vp9_get_pred_context_single_ref_p1(xd)][0] | 769 cpi->single_ref_count[vp9_get_pred_context_single_ref_p1(xd)][0] |
680 [mbmi->ref_frame[0] != LAST_FRAME]++; | 770 [mbmi->ref_frame[0] != LAST_FRAME]++; |
681 if (mbmi->ref_frame[0] != LAST_FRAME) | 771 if (mbmi->ref_frame[0] != LAST_FRAME) |
682 cpi->single_ref_count[vp9_get_pred_context_single_ref_p2(xd)][1] | 772 cpi->single_ref_count[vp9_get_pred_context_single_ref_p2(xd)][1] |
683 [mbmi->ref_frame[0] != GOLDEN_FRAME]++; | 773 [mbmi->ref_frame[0] != GOLDEN_FRAME]++; |
684 } | 774 } |
685 } | 775 } |
686 | |
687 // Count of last ref frame 0,0 usage | |
688 if (mbmi->mode == ZEROMV && mbmi->ref_frame[0] == LAST_FRAME) | |
689 cpi->inter_zz_count++; | |
690 } | 776 } |
691 } | 777 } |
692 | 778 |
693 static BLOCK_SIZE *get_sb_partitioning(MACROBLOCK *x, BLOCK_SIZE bsize) { | 779 static BLOCK_SIZE *get_sb_partitioning(MACROBLOCK *x, BLOCK_SIZE bsize) { |
694 MACROBLOCKD *const xd = &x->e_mbd; | |
695 switch (bsize) { | 780 switch (bsize) { |
696 case BLOCK_64X64: | 781 case BLOCK_64X64: |
697 return &x->sb64_partitioning; | 782 return &x->sb64_partitioning; |
698 case BLOCK_32X32: | 783 case BLOCK_32X32: |
699 return &x->sb_partitioning[xd->sb_index]; | 784 return &x->sb_partitioning[x->sb_index]; |
700 case BLOCK_16X16: | 785 case BLOCK_16X16: |
701 return &x->mb_partitioning[xd->sb_index][xd->mb_index]; | 786 return &x->mb_partitioning[x->sb_index][x->mb_index]; |
702 case BLOCK_8X8: | 787 case BLOCK_8X8: |
703 return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; | 788 return &x->b_partitioning[x->sb_index][x->mb_index][x->b_index]; |
704 default: | 789 default: |
705 assert(0); | 790 assert(0); |
706 return NULL; | 791 return NULL; |
707 } | 792 } |
708 } | 793 } |
709 | 794 |
710 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, | 795 static void restore_context(VP9_COMP *cpi, int mi_row, int mi_col, |
711 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 796 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
712 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 797 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
713 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], | 798 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 } | 851 } |
767 vpx_memcpy(sa, cpi->above_seg_context + mi_col, | 852 vpx_memcpy(sa, cpi->above_seg_context + mi_col, |
768 sizeof(*cpi->above_seg_context) * mi_width); | 853 sizeof(*cpi->above_seg_context) * mi_width); |
769 vpx_memcpy(sl, cpi->left_seg_context + (mi_row & MI_MASK), | 854 vpx_memcpy(sl, cpi->left_seg_context + (mi_row & MI_MASK), |
770 sizeof(cpi->left_seg_context[0]) * mi_height); | 855 sizeof(cpi->left_seg_context[0]) * mi_height); |
771 } | 856 } |
772 | 857 |
773 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, | 858 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, |
774 TOKENEXTRA **tp, int mi_row, int mi_col, | 859 TOKENEXTRA **tp, int mi_row, int mi_col, |
775 int output_enabled, BLOCK_SIZE bsize, int sub_index) { | 860 int output_enabled, BLOCK_SIZE bsize, int sub_index) { |
776 VP9_COMMON * const cm = &cpi->common; | 861 VP9_COMMON *const cm = &cpi->common; |
777 MACROBLOCK * const x = &cpi->mb; | 862 MACROBLOCK *const x = &cpi->mb; |
778 MACROBLOCKD * const xd = &x->e_mbd; | |
779 | 863 |
780 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 864 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
781 return; | 865 return; |
782 | 866 |
783 if (sub_index != -1) | 867 if (sub_index != -1) |
784 *get_sb_index(xd, bsize) = sub_index; | 868 *get_sb_index(x, bsize) = sub_index; |
785 | 869 |
786 if (bsize < BLOCK_8X8) { | 870 if (bsize < BLOCK_8X8) { |
787 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 | 871 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
788 // there is nothing to be done. | 872 // there is nothing to be done. |
789 if (xd->ab_index > 0) | 873 if (x->ab_index > 0) |
790 return; | 874 return; |
791 } | 875 } |
792 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 876 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
793 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); | 877 update_state(cpi, get_block_context(x, bsize), bsize, output_enabled); |
794 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); | 878 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize); |
795 | 879 |
796 if (output_enabled) { | 880 if (output_enabled) { |
797 update_stats(cpi); | 881 update_stats(cpi); |
798 | 882 |
799 (*tp)->token = EOSB_TOKEN; | 883 (*tp)->token = EOSB_TOKEN; |
800 (*tp)++; | 884 (*tp)++; |
801 } | 885 } |
802 } | 886 } |
803 | 887 |
804 static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, | 888 static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, |
805 TOKENEXTRA **tp, int mi_row, int mi_col, | 889 TOKENEXTRA **tp, int mi_row, int mi_col, |
806 int output_enabled, BLOCK_SIZE bsize) { | 890 int output_enabled, BLOCK_SIZE bsize) { |
807 VP9_COMMON * const cm = &cpi->common; | 891 VP9_COMMON *const cm = &cpi->common; |
808 MACROBLOCK * const x = &cpi->mb; | 892 MACROBLOCK *const x = &cpi->mb; |
809 MACROBLOCKD * const xd = &x->e_mbd; | |
810 BLOCK_SIZE c1 = BLOCK_8X8; | 893 BLOCK_SIZE c1 = BLOCK_8X8; |
811 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; | 894 const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; |
812 int pl = 0; | 895 int pl = 0; |
813 PARTITION_TYPE partition; | 896 PARTITION_TYPE partition; |
814 BLOCK_SIZE subsize; | 897 BLOCK_SIZE subsize; |
815 int i; | 898 int i; |
816 | 899 |
817 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 900 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
818 return; | 901 return; |
819 | 902 |
820 c1 = BLOCK_4X4; | 903 c1 = BLOCK_4X4; |
821 if (bsize >= BLOCK_8X8) { | 904 if (bsize >= BLOCK_8X8) { |
822 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, | 905 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, |
823 mi_row, mi_col, bsize); | 906 mi_row, mi_col, bsize); |
824 c1 = *(get_sb_partitioning(x, bsize)); | 907 c1 = *(get_sb_partitioning(x, bsize)); |
825 } | 908 } |
826 partition = partition_lookup[bsl][c1]; | 909 partition = partition_lookup[bsl][c1]; |
827 | 910 |
828 switch (partition) { | 911 switch (partition) { |
829 case PARTITION_NONE: | 912 case PARTITION_NONE: |
830 if (output_enabled && bsize >= BLOCK_8X8) | 913 if (output_enabled && bsize >= BLOCK_8X8) |
831 cpi->partition_count[pl][PARTITION_NONE]++; | 914 cm->counts.partition[pl][PARTITION_NONE]++; |
832 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, -1); | 915 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, -1); |
833 break; | 916 break; |
834 case PARTITION_VERT: | 917 case PARTITION_VERT: |
835 if (output_enabled) | 918 if (output_enabled) |
836 cpi->partition_count[pl][PARTITION_VERT]++; | 919 cm->counts.partition[pl][PARTITION_VERT]++; |
837 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); | 920 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); |
838 encode_b(cpi, tile, tp, mi_row, mi_col + bs, output_enabled, c1, 1); | 921 encode_b(cpi, tile, tp, mi_row, mi_col + bs, output_enabled, c1, 1); |
839 break; | 922 break; |
840 case PARTITION_HORZ: | 923 case PARTITION_HORZ: |
841 if (output_enabled) | 924 if (output_enabled) |
842 cpi->partition_count[pl][PARTITION_HORZ]++; | 925 cm->counts.partition[pl][PARTITION_HORZ]++; |
843 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); | 926 encode_b(cpi, tile, tp, mi_row, mi_col, output_enabled, c1, 0); |
844 encode_b(cpi, tile, tp, mi_row + bs, mi_col, output_enabled, c1, 1); | 927 encode_b(cpi, tile, tp, mi_row + bs, mi_col, output_enabled, c1, 1); |
845 break; | 928 break; |
846 case PARTITION_SPLIT: | 929 case PARTITION_SPLIT: |
847 subsize = get_subsize(bsize, PARTITION_SPLIT); | 930 subsize = get_subsize(bsize, PARTITION_SPLIT); |
848 | 931 |
849 if (output_enabled) | 932 if (output_enabled) |
850 cpi->partition_count[pl][PARTITION_SPLIT]++; | 933 cm->counts.partition[pl][PARTITION_SPLIT]++; |
851 | 934 |
852 for (i = 0; i < 4; i++) { | 935 for (i = 0; i < 4; i++) { |
853 const int x_idx = i & 1, y_idx = i >> 1; | 936 const int x_idx = i & 1, y_idx = i >> 1; |
854 | 937 |
855 *get_sb_index(xd, subsize) = i; | 938 *get_sb_index(x, subsize) = i; |
856 encode_sb(cpi, tile, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, | 939 encode_sb(cpi, tile, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, |
857 output_enabled, subsize); | 940 output_enabled, subsize); |
858 } | 941 } |
859 break; | 942 break; |
860 default: | 943 default: |
861 assert(0); | 944 assert(0); |
862 break; | 945 break; |
863 } | 946 } |
864 | 947 |
865 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 948 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 } | 1055 } |
973 return 0; | 1056 return 0; |
974 } | 1057 } |
975 | 1058 |
976 static void rd_use_partition(VP9_COMP *cpi, | 1059 static void rd_use_partition(VP9_COMP *cpi, |
977 const TileInfo *const tile, | 1060 const TileInfo *const tile, |
978 MODE_INFO **mi_8x8, | 1061 MODE_INFO **mi_8x8, |
979 TOKENEXTRA **tp, int mi_row, int mi_col, | 1062 TOKENEXTRA **tp, int mi_row, int mi_col, |
980 BLOCK_SIZE bsize, int *rate, int64_t *dist, | 1063 BLOCK_SIZE bsize, int *rate, int64_t *dist, |
981 int do_recon) { | 1064 int do_recon) { |
982 VP9_COMMON * const cm = &cpi->common; | 1065 VP9_COMMON *const cm = &cpi->common; |
983 MACROBLOCK * const x = &cpi->mb; | 1066 MACROBLOCK *const x = &cpi->mb; |
984 MACROBLOCKD *xd = &cpi->mb.e_mbd; | |
985 const int mis = cm->mode_info_stride; | 1067 const int mis = cm->mode_info_stride; |
986 int bsl = b_width_log2(bsize); | 1068 int bsl = b_width_log2(bsize); |
987 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1069 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
988 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1070 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
989 int ms = num_4x4_blocks_wide / 2; | 1071 int ms = num_4x4_blocks_wide / 2; |
990 int mh = num_4x4_blocks_high / 2; | 1072 int mh = num_4x4_blocks_high / 2; |
991 int bss = (1 << bsl) / 4; | 1073 int bss = (1 << bsl) / 4; |
992 int i, pl; | 1074 int i, pl; |
993 PARTITION_TYPE partition = PARTITION_NONE; | 1075 PARTITION_TYPE partition = PARTITION_NONE; |
994 BLOCK_SIZE subsize; | 1076 BLOCK_SIZE subsize; |
(...skipping 14 matching lines...) Expand all Loading... |
1009 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 1091 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
1010 return; | 1092 return; |
1011 | 1093 |
1012 partition = partition_lookup[bsl][bs_type]; | 1094 partition = partition_lookup[bsl][bs_type]; |
1013 | 1095 |
1014 subsize = get_subsize(bsize, partition); | 1096 subsize = get_subsize(bsize, partition); |
1015 | 1097 |
1016 if (bsize < BLOCK_8X8) { | 1098 if (bsize < BLOCK_8X8) { |
1017 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 | 1099 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
1018 // there is nothing to be done. | 1100 // there is nothing to be done. |
1019 if (xd->ab_index != 0) { | 1101 if (x->ab_index != 0) { |
1020 *rate = 0; | 1102 *rate = 0; |
1021 *dist = 0; | 1103 *dist = 0; |
1022 return; | 1104 return; |
1023 } | 1105 } |
1024 } else { | 1106 } else { |
1025 *(get_sb_partitioning(x, bsize)) = subsize; | 1107 *(get_sb_partitioning(x, bsize)) = subsize; |
1026 } | 1108 } |
1027 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1109 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1028 | 1110 |
1029 if (bsize == BLOCK_16X16) { | 1111 if (bsize == BLOCK_16X16) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 *(get_sb_partitioning(x, bsize)) = subsize; | 1149 *(get_sb_partitioning(x, bsize)) = subsize; |
1068 } | 1150 } |
1069 } | 1151 } |
1070 | 1152 |
1071 switch (partition) { | 1153 switch (partition) { |
1072 case PARTITION_NONE: | 1154 case PARTITION_NONE: |
1073 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1155 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1074 bsize, get_block_context(x, bsize), INT64_MAX); | 1156 bsize, get_block_context(x, bsize), INT64_MAX); |
1075 break; | 1157 break; |
1076 case PARTITION_HORZ: | 1158 case PARTITION_HORZ: |
1077 *get_sb_index(xd, subsize) = 0; | 1159 *get_sb_index(x, subsize) = 0; |
1078 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1160 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1079 subsize, get_block_context(x, subsize), INT64_MAX); | 1161 subsize, get_block_context(x, subsize), INT64_MAX); |
1080 if (last_part_rate != INT_MAX && | 1162 if (last_part_rate != INT_MAX && |
1081 bsize >= BLOCK_8X8 && mi_row + (mh >> 1) < cm->mi_rows) { | 1163 bsize >= BLOCK_8X8 && mi_row + (mh >> 1) < cm->mi_rows) { |
1082 int rt = 0; | 1164 int rt = 0; |
1083 int64_t dt = 0; | 1165 int64_t dt = 0; |
1084 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1166 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1085 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1167 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1086 *get_sb_index(xd, subsize) = 1; | 1168 *get_sb_index(x, subsize) = 1; |
1087 pick_sb_modes(cpi, tile, mi_row + (ms >> 1), mi_col, &rt, &dt, subsize, | 1169 pick_sb_modes(cpi, tile, mi_row + (ms >> 1), mi_col, &rt, &dt, subsize, |
1088 get_block_context(x, subsize), INT64_MAX); | 1170 get_block_context(x, subsize), INT64_MAX); |
1089 if (rt == INT_MAX || dt == INT_MAX) { | 1171 if (rt == INT_MAX || dt == INT_MAX) { |
1090 last_part_rate = INT_MAX; | 1172 last_part_rate = INT_MAX; |
1091 last_part_dist = INT_MAX; | 1173 last_part_dist = INT_MAX; |
1092 break; | 1174 break; |
1093 } | 1175 } |
1094 | 1176 |
1095 last_part_rate += rt; | 1177 last_part_rate += rt; |
1096 last_part_dist += dt; | 1178 last_part_dist += dt; |
1097 } | 1179 } |
1098 break; | 1180 break; |
1099 case PARTITION_VERT: | 1181 case PARTITION_VERT: |
1100 *get_sb_index(xd, subsize) = 0; | 1182 *get_sb_index(x, subsize) = 0; |
1101 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, | 1183 pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, |
1102 subsize, get_block_context(x, subsize), INT64_MAX); | 1184 subsize, get_block_context(x, subsize), INT64_MAX); |
1103 if (last_part_rate != INT_MAX && | 1185 if (last_part_rate != INT_MAX && |
1104 bsize >= BLOCK_8X8 && mi_col + (ms >> 1) < cm->mi_cols) { | 1186 bsize >= BLOCK_8X8 && mi_col + (ms >> 1) < cm->mi_cols) { |
1105 int rt = 0; | 1187 int rt = 0; |
1106 int64_t dt = 0; | 1188 int64_t dt = 0; |
1107 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1189 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1108 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1190 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1109 *get_sb_index(xd, subsize) = 1; | 1191 *get_sb_index(x, subsize) = 1; |
1110 pick_sb_modes(cpi, tile, mi_row, mi_col + (ms >> 1), &rt, &dt, subsize, | 1192 pick_sb_modes(cpi, tile, mi_row, mi_col + (ms >> 1), &rt, &dt, subsize, |
1111 get_block_context(x, subsize), INT64_MAX); | 1193 get_block_context(x, subsize), INT64_MAX); |
1112 if (rt == INT_MAX || dt == INT_MAX) { | 1194 if (rt == INT_MAX || dt == INT_MAX) { |
1113 last_part_rate = INT_MAX; | 1195 last_part_rate = INT_MAX; |
1114 last_part_dist = INT_MAX; | 1196 last_part_dist = INT_MAX; |
1115 break; | 1197 break; |
1116 } | 1198 } |
1117 last_part_rate += rt; | 1199 last_part_rate += rt; |
1118 last_part_dist += dt; | 1200 last_part_dist += dt; |
1119 } | 1201 } |
1120 break; | 1202 break; |
1121 case PARTITION_SPLIT: | 1203 case PARTITION_SPLIT: |
1122 // Split partition. | 1204 // Split partition. |
1123 last_part_rate = 0; | 1205 last_part_rate = 0; |
1124 last_part_dist = 0; | 1206 last_part_dist = 0; |
1125 for (i = 0; i < 4; i++) { | 1207 for (i = 0; i < 4; i++) { |
1126 int x_idx = (i & 1) * (ms >> 1); | 1208 int x_idx = (i & 1) * (ms >> 1); |
1127 int y_idx = (i >> 1) * (ms >> 1); | 1209 int y_idx = (i >> 1) * (ms >> 1); |
1128 int jj = i >> 1, ii = i & 0x01; | 1210 int jj = i >> 1, ii = i & 0x01; |
1129 int rt; | 1211 int rt; |
1130 int64_t dt; | 1212 int64_t dt; |
1131 | 1213 |
1132 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | 1214 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
1133 continue; | 1215 continue; |
1134 | 1216 |
1135 *get_sb_index(xd, subsize) = i; | 1217 *get_sb_index(x, subsize) = i; |
1136 | 1218 |
1137 rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, | 1219 rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, |
1138 mi_row + y_idx, mi_col + x_idx, subsize, &rt, &dt, | 1220 mi_row + y_idx, mi_col + x_idx, subsize, &rt, &dt, |
1139 i != 3); | 1221 i != 3); |
1140 if (rt == INT_MAX || dt == INT_MAX) { | 1222 if (rt == INT_MAX || dt == INT_MAX) { |
1141 last_part_rate = INT_MAX; | 1223 last_part_rate = INT_MAX; |
1142 last_part_dist = INT_MAX; | 1224 last_part_dist = INT_MAX; |
1143 break; | 1225 break; |
1144 } | 1226 } |
1145 last_part_rate += rt; | 1227 last_part_rate += rt; |
(...skipping 20 matching lines...) Expand all Loading... |
1166 | 1248 |
1167 // Split partition. | 1249 // Split partition. |
1168 for (i = 0; i < 4; i++) { | 1250 for (i = 0; i < 4; i++) { |
1169 int x_idx = (i & 1) * (num_4x4_blocks_wide >> 2); | 1251 int x_idx = (i & 1) * (num_4x4_blocks_wide >> 2); |
1170 int y_idx = (i >> 1) * (num_4x4_blocks_wide >> 2); | 1252 int y_idx = (i >> 1) * (num_4x4_blocks_wide >> 2); |
1171 int rt = 0; | 1253 int rt = 0; |
1172 int64_t dt = 0; | 1254 int64_t dt = 0; |
1173 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1255 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1174 PARTITION_CONTEXT sl[8], sa[8]; | 1256 PARTITION_CONTEXT sl[8], sa[8]; |
1175 | 1257 |
1176 if ((mi_row + y_idx >= cm->mi_rows) | 1258 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
1177 || (mi_col + x_idx >= cm->mi_cols)) | |
1178 continue; | 1259 continue; |
1179 | 1260 |
1180 *get_sb_index(xd, split_subsize) = i; | 1261 *get_sb_index(x, split_subsize) = i; |
1181 *get_sb_partitioning(x, bsize) = split_subsize; | 1262 *get_sb_partitioning(x, bsize) = split_subsize; |
1182 *get_sb_partitioning(x, split_subsize) = split_subsize; | 1263 *get_sb_partitioning(x, split_subsize) = split_subsize; |
1183 | 1264 |
1184 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1265 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1185 | 1266 |
1186 pick_sb_modes(cpi, tile, mi_row + y_idx, mi_col + x_idx, &rt, &dt, | 1267 pick_sb_modes(cpi, tile, mi_row + y_idx, mi_col + x_idx, &rt, &dt, |
1187 split_subsize, get_block_context(x, split_subsize), | 1268 split_subsize, get_block_context(x, split_subsize), |
1188 INT64_MAX); | 1269 INT64_MAX); |
1189 | 1270 |
1190 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1271 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1191 | 1272 |
1192 if (rt == INT_MAX || dt == INT_MAX) { | 1273 if (rt == INT_MAX || dt == INT_MAX) { |
1193 split_rate = INT_MAX; | 1274 split_rate = INT_MAX; |
1194 split_dist = INT_MAX; | 1275 split_dist = INT_MAX; |
1195 break; | 1276 break; |
1196 } | 1277 } |
1197 | 1278 |
1198 if (i != 3) | 1279 if (i != 3) |
1199 encode_sb(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, 0, | 1280 encode_sb(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, 0, |
1200 split_subsize); | 1281 split_subsize); |
1201 | 1282 |
1202 split_rate += rt; | 1283 split_rate += rt; |
1203 split_dist += dt; | 1284 split_dist += dt; |
1204 pl = partition_plane_context(cpi->above_seg_context, | 1285 pl = partition_plane_context(cpi->above_seg_context, |
1205 cpi->left_seg_context, | 1286 cpi->left_seg_context, |
1206 mi_row + y_idx, mi_col + x_idx, bsize); | 1287 mi_row + y_idx, mi_col + x_idx, |
| 1288 split_subsize); |
1207 split_rate += x->partition_cost[pl][PARTITION_NONE]; | 1289 split_rate += x->partition_cost[pl][PARTITION_NONE]; |
1208 } | 1290 } |
1209 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, | 1291 pl = partition_plane_context(cpi->above_seg_context, cpi->left_seg_context, |
1210 mi_row, mi_col, bsize); | 1292 mi_row, mi_col, bsize); |
1211 if (split_rate < INT_MAX) { | 1293 if (split_rate < INT_MAX) { |
1212 split_rate += x->partition_cost[pl][PARTITION_SPLIT]; | 1294 split_rate += x->partition_cost[pl][PARTITION_SPLIT]; |
1213 | 1295 |
1214 chosen_rate = split_rate; | 1296 chosen_rate = split_rate; |
1215 chosen_dist = split_dist; | 1297 chosen_dist = split_dist; |
1216 } | 1298 } |
(...skipping 17 matching lines...) Expand all Loading... |
1234 chosen_dist = none_dist; | 1316 chosen_dist = none_dist; |
1235 } | 1317 } |
1236 | 1318 |
1237 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1319 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1238 | 1320 |
1239 // We must have chosen a partitioning and encoding or we'll fail later on. | 1321 // We must have chosen a partitioning and encoding or we'll fail later on. |
1240 // No other opportunities for success. | 1322 // No other opportunities for success. |
1241 if ( bsize == BLOCK_64X64) | 1323 if ( bsize == BLOCK_64X64) |
1242 assert(chosen_rate < INT_MAX && chosen_dist < INT_MAX); | 1324 assert(chosen_rate < INT_MAX && chosen_dist < INT_MAX); |
1243 | 1325 |
1244 if (do_recon) | 1326 if (do_recon) { |
1245 encode_sb(cpi, tile, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); | 1327 int output_enabled = (bsize == BLOCK_64X64); |
| 1328 |
| 1329 // Check the projected output rate for this SB against it's target |
| 1330 // and and if necessary apply a Q delta using segmentation to get |
| 1331 // closer to the target. |
| 1332 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { |
| 1333 select_in_frame_q_segment(cpi, mi_row, mi_col, |
| 1334 output_enabled, chosen_rate); |
| 1335 } |
| 1336 |
| 1337 encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize); |
| 1338 } |
1246 | 1339 |
1247 *rate = chosen_rate; | 1340 *rate = chosen_rate; |
1248 *dist = chosen_dist; | 1341 *dist = chosen_dist; |
1249 } | 1342 } |
1250 | 1343 |
1251 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { | 1344 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { |
1252 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, | 1345 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, |
1253 BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, BLOCK_8X8, | 1346 BLOCK_4X4, BLOCK_4X4, BLOCK_8X8, BLOCK_8X8, |
1254 BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16 | 1347 BLOCK_8X8, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, BLOCK_16X16 |
1255 }; | 1348 }; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 // Check border cases where max and min from neighbours may not be legal. | 1443 // Check border cases where max and min from neighbours may not be legal. |
1351 *max_block_size = find_partition_size(*max_block_size, | 1444 *max_block_size = find_partition_size(*max_block_size, |
1352 row8x8_remaining, col8x8_remaining, | 1445 row8x8_remaining, col8x8_remaining, |
1353 &bh, &bw); | 1446 &bh, &bw); |
1354 *min_block_size = MIN(*min_block_size, *max_block_size); | 1447 *min_block_size = MIN(*min_block_size, *max_block_size); |
1355 } | 1448 } |
1356 | 1449 |
1357 static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) { | 1450 static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) { |
1358 VP9_COMMON *const cm = &cpi->common; | 1451 VP9_COMMON *const cm = &cpi->common; |
1359 MACROBLOCK *const x = &cpi->mb; | 1452 MACROBLOCK *const x = &cpi->mb; |
1360 MACROBLOCKD *const xd = &x->e_mbd; | |
1361 | 1453 |
1362 // Only use 8x8 result for non HD videos. | 1454 // Only use 8x8 result for non HD videos. |
1363 // int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0; | 1455 // int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0; |
1364 int use_8x8 = 1; | 1456 int use_8x8 = 1; |
1365 | 1457 |
1366 if (cm->frame_type && !cpi->is_src_frame_alt_ref && | 1458 if (cm->frame_type && !cpi->is_src_frame_alt_ref && |
1367 ((use_8x8 && bsize == BLOCK_16X16) || | 1459 ((use_8x8 && bsize == BLOCK_16X16) || |
1368 bsize == BLOCK_32X32 || bsize == BLOCK_64X64)) { | 1460 bsize == BLOCK_32X32 || bsize == BLOCK_64X64)) { |
1369 int ref0 = 0, ref1 = 0, ref2 = 0, ref3 = 0; | 1461 int ref0 = 0, ref1 = 0, ref2 = 0, ref3 = 0; |
1370 PICK_MODE_CONTEXT *block_context = NULL; | 1462 PICK_MODE_CONTEXT *block_context = NULL; |
1371 | 1463 |
1372 if (bsize == BLOCK_16X16) { | 1464 if (bsize == BLOCK_16X16) { |
1373 block_context = x->sb8x8_context[xd->sb_index][xd->mb_index]; | 1465 block_context = x->sb8x8_context[x->sb_index][x->mb_index]; |
1374 } else if (bsize == BLOCK_32X32) { | 1466 } else if (bsize == BLOCK_32X32) { |
1375 block_context = x->mb_context[xd->sb_index]; | 1467 block_context = x->mb_context[x->sb_index]; |
1376 } else if (bsize == BLOCK_64X64) { | 1468 } else if (bsize == BLOCK_64X64) { |
1377 block_context = x->sb32_context; | 1469 block_context = x->sb32_context; |
1378 } | 1470 } |
1379 | 1471 |
1380 if (block_context) { | 1472 if (block_context) { |
1381 ref0 = block_context[0].mic.mbmi.ref_frame[0]; | 1473 ref0 = block_context[0].mic.mbmi.ref_frame[0]; |
1382 ref1 = block_context[1].mic.mbmi.ref_frame[0]; | 1474 ref1 = block_context[1].mic.mbmi.ref_frame[0]; |
1383 ref2 = block_context[2].mic.mbmi.ref_frame[0]; | 1475 ref2 = block_context[2].mic.mbmi.ref_frame[0]; |
1384 ref3 = block_context[3].mic.mbmi.ref_frame[0]; | 1476 ref3 = block_context[3].mic.mbmi.ref_frame[0]; |
1385 } | 1477 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); | 1545 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); |
1454 } | 1546 } |
1455 | 1547 |
1456 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 1548 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
1457 // unlikely to be selected depending on previous rate-distortion optimization | 1549 // unlikely to be selected depending on previous rate-distortion optimization |
1458 // results, for encoding speed-up. | 1550 // results, for encoding speed-up. |
1459 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, | 1551 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, |
1460 TOKENEXTRA **tp, int mi_row, | 1552 TOKENEXTRA **tp, int mi_row, |
1461 int mi_col, BLOCK_SIZE bsize, int *rate, | 1553 int mi_col, BLOCK_SIZE bsize, int *rate, |
1462 int64_t *dist, int do_recon, int64_t best_rd) { | 1554 int64_t *dist, int do_recon, int64_t best_rd) { |
1463 VP9_COMMON * const cm = &cpi->common; | 1555 VP9_COMMON *const cm = &cpi->common; |
1464 MACROBLOCK * const x = &cpi->mb; | 1556 MACROBLOCK *const x = &cpi->mb; |
1465 MACROBLOCKD * const xd = &x->e_mbd; | |
1466 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; | 1557 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; |
1467 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1558 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1468 PARTITION_CONTEXT sl[8], sa[8]; | 1559 PARTITION_CONTEXT sl[8], sa[8]; |
1469 TOKENEXTRA *tp_orig = *tp; | 1560 TOKENEXTRA *tp_orig = *tp; |
1470 int i, pl; | 1561 int i, pl; |
1471 BLOCK_SIZE subsize; | 1562 BLOCK_SIZE subsize; |
1472 int this_rate, sum_rate = 0, best_rate = INT_MAX; | 1563 int this_rate, sum_rate = 0, best_rate = INT_MAX; |
1473 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; | 1564 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; |
1474 int64_t sum_rd = 0; | 1565 int64_t sum_rd = 0; |
1475 int do_split = bsize >= BLOCK_8X8; | 1566 int do_split = bsize >= BLOCK_8X8; |
1476 int do_rect = 1; | 1567 int do_rect = 1; |
1477 // Override skipping rectangular partition operations for edge blocks | 1568 // Override skipping rectangular partition operations for edge blocks |
1478 const int force_horz_split = (mi_row + ms >= cm->mi_rows); | 1569 const int force_horz_split = (mi_row + ms >= cm->mi_rows); |
1479 const int force_vert_split = (mi_col + ms >= cm->mi_cols); | 1570 const int force_vert_split = (mi_col + ms >= cm->mi_cols); |
| 1571 const int xss = x->e_mbd.plane[1].subsampling_x; |
| 1572 const int yss = x->e_mbd.plane[1].subsampling_y; |
1480 | 1573 |
1481 int partition_none_allowed = !force_horz_split && !force_vert_split; | 1574 int partition_none_allowed = !force_horz_split && !force_vert_split; |
1482 int partition_horz_allowed = !force_vert_split && bsize >= BLOCK_8X8; | 1575 int partition_horz_allowed = !force_vert_split && yss <= xss && |
1483 int partition_vert_allowed = !force_horz_split && bsize >= BLOCK_8X8; | 1576 bsize >= BLOCK_8X8; |
| 1577 int partition_vert_allowed = !force_horz_split && xss <= yss && |
| 1578 bsize >= BLOCK_8X8; |
1484 | 1579 |
1485 int partition_split_done = 0; | 1580 int partition_split_done = 0; |
1486 (void) *tp_orig; | 1581 (void) *tp_orig; |
1487 | 1582 |
1488 if (bsize < BLOCK_8X8) { | 1583 if (bsize < BLOCK_8X8) { |
1489 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 | 1584 // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 |
1490 // there is nothing to be done. | 1585 // there is nothing to be done. |
1491 if (xd->ab_index != 0) { | 1586 if (x->ab_index != 0) { |
1492 *rate = 0; | 1587 *rate = 0; |
1493 *dist = 0; | 1588 *dist = 0; |
1494 return; | 1589 return; |
1495 } | 1590 } |
1496 } | 1591 } |
1497 assert(mi_height_log2(bsize) == mi_width_log2(bsize)); | 1592 assert(num_8x8_blocks_wide_lookup[bsize] == |
| 1593 num_8x8_blocks_high_lookup[bsize]); |
1498 | 1594 |
1499 if (bsize == BLOCK_16X16) { | 1595 if (bsize == BLOCK_16X16) { |
1500 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 1596 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
1501 x->mb_energy = vp9_block_energy(cpi, x, bsize); | 1597 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
1502 } | 1598 } |
1503 | 1599 |
1504 // Determine partition types in search according to the speed features. | 1600 // Determine partition types in search according to the speed features. |
1505 // The threshold set here has to be of square block size. | 1601 // The threshold set here has to be of square block size. |
1506 if (cpi->sf.auto_min_max_partition_size) { | 1602 if (cpi->sf.auto_min_max_partition_size) { |
1507 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && | 1603 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && |
(...skipping 30 matching lines...) Expand all Loading... |
1538 get_block_context(x, bsize), best_rd); | 1634 get_block_context(x, bsize), best_rd); |
1539 if (this_rate != INT_MAX) { | 1635 if (this_rate != INT_MAX) { |
1540 if (bsize >= BLOCK_8X8) { | 1636 if (bsize >= BLOCK_8X8) { |
1541 pl = partition_plane_context(cpi->above_seg_context, | 1637 pl = partition_plane_context(cpi->above_seg_context, |
1542 cpi->left_seg_context, | 1638 cpi->left_seg_context, |
1543 mi_row, mi_col, bsize); | 1639 mi_row, mi_col, bsize); |
1544 this_rate += x->partition_cost[pl][PARTITION_NONE]; | 1640 this_rate += x->partition_cost[pl][PARTITION_NONE]; |
1545 } | 1641 } |
1546 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 1642 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
1547 if (sum_rd < best_rd) { | 1643 if (sum_rd < best_rd) { |
1548 int64_t stop_thresh = 2048; | 1644 int64_t stop_thresh = 4096; |
| 1645 int64_t stop_thresh_rd; |
1549 | 1646 |
1550 best_rate = this_rate; | 1647 best_rate = this_rate; |
1551 best_dist = this_dist; | 1648 best_dist = this_dist; |
1552 best_rd = sum_rd; | 1649 best_rd = sum_rd; |
1553 if (bsize >= BLOCK_8X8) | 1650 if (bsize >= BLOCK_8X8) |
1554 *(get_sb_partitioning(x, bsize)) = bsize; | 1651 *(get_sb_partitioning(x, bsize)) = bsize; |
1555 | 1652 |
1556 // Adjust threshold according to partition size. | 1653 // Adjust threshold according to partition size. |
1557 stop_thresh >>= 8 - (b_width_log2_lookup[bsize] + | 1654 stop_thresh >>= 8 - (b_width_log2_lookup[bsize] + |
1558 b_height_log2_lookup[bsize]); | 1655 b_height_log2_lookup[bsize]); |
1559 | 1656 |
| 1657 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); |
1560 // If obtained distortion is very small, choose current partition | 1658 // If obtained distortion is very small, choose current partition |
1561 // and stop splitting. | 1659 // and stop splitting. |
1562 if (this_dist < stop_thresh) { | 1660 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { |
1563 do_split = 0; | 1661 do_split = 0; |
1564 do_rect = 0; | 1662 do_rect = 0; |
1565 } | 1663 } |
1566 } | 1664 } |
1567 } | 1665 } |
1568 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1666 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1569 } | 1667 } |
1570 | 1668 |
1571 // store estimated motion vector | 1669 // store estimated motion vector |
1572 if (cpi->sf.adaptive_motion_search) | 1670 if (cpi->sf.adaptive_motion_search) |
1573 store_pred_mv(x, get_block_context(x, bsize)); | 1671 store_pred_mv(x, get_block_context(x, bsize)); |
1574 | 1672 |
1575 // PARTITION_SPLIT | 1673 // PARTITION_SPLIT |
1576 sum_rd = 0; | 1674 sum_rd = 0; |
1577 // TODO(jingning): use the motion vectors given by the above search as | 1675 // TODO(jingning): use the motion vectors given by the above search as |
1578 // the starting point of motion search in the following partition type check. | 1676 // the starting point of motion search in the following partition type check. |
1579 if (do_split) { | 1677 if (do_split) { |
1580 subsize = get_subsize(bsize, PARTITION_SPLIT); | 1678 subsize = get_subsize(bsize, PARTITION_SPLIT); |
1581 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | 1679 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { |
1582 const int x_idx = (i & 1) * ms; | 1680 const int x_idx = (i & 1) * ms; |
1583 const int y_idx = (i >> 1) * ms; | 1681 const int y_idx = (i >> 1) * ms; |
1584 | 1682 |
1585 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 1683 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
1586 continue; | 1684 continue; |
1587 | 1685 |
1588 *get_sb_index(xd, subsize) = i; | 1686 *get_sb_index(x, subsize) = i; |
1589 if (cpi->sf.adaptive_motion_search) | 1687 if (cpi->sf.adaptive_motion_search) |
1590 load_pred_mv(x, get_block_context(x, bsize)); | 1688 load_pred_mv(x, get_block_context(x, bsize)); |
| 1689 if (cpi->sf.adaptive_pred_filter_type && bsize == BLOCK_8X8 && |
| 1690 partition_none_allowed) |
| 1691 get_block_context(x, subsize)->pred_filter_type = |
| 1692 get_block_context(x, bsize)->mic.mbmi.interp_filter; |
1591 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, subsize, | 1693 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, subsize, |
1592 &this_rate, &this_dist, i != 3, best_rd - sum_rd); | 1694 &this_rate, &this_dist, i != 3, best_rd - sum_rd); |
1593 | 1695 |
1594 if (this_rate == INT_MAX) { | 1696 if (this_rate == INT_MAX) { |
1595 sum_rd = INT64_MAX; | 1697 sum_rd = INT64_MAX; |
1596 } else { | 1698 } else { |
1597 sum_rate += this_rate; | 1699 sum_rate += this_rate; |
1598 sum_dist += this_dist; | 1700 sum_dist += this_dist; |
1599 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1701 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1600 } | 1702 } |
(...skipping 24 matching lines...) Expand all Loading... |
1625 x->subblock_ref = 0; | 1727 x->subblock_ref = 0; |
1626 | 1728 |
1627 if (partition_split_done && | 1729 if (partition_split_done && |
1628 cpi->sf.using_small_partition_info) { | 1730 cpi->sf.using_small_partition_info) { |
1629 compute_fast_motion_search_level(cpi, bsize); | 1731 compute_fast_motion_search_level(cpi, bsize); |
1630 } | 1732 } |
1631 | 1733 |
1632 // PARTITION_HORZ | 1734 // PARTITION_HORZ |
1633 if (partition_horz_allowed && do_rect) { | 1735 if (partition_horz_allowed && do_rect) { |
1634 subsize = get_subsize(bsize, PARTITION_HORZ); | 1736 subsize = get_subsize(bsize, PARTITION_HORZ); |
1635 *get_sb_index(xd, subsize) = 0; | 1737 *get_sb_index(x, subsize) = 0; |
1636 if (cpi->sf.adaptive_motion_search) | 1738 if (cpi->sf.adaptive_motion_search) |
1637 load_pred_mv(x, get_block_context(x, bsize)); | 1739 load_pred_mv(x, get_block_context(x, bsize)); |
| 1740 if (cpi->sf.adaptive_pred_filter_type && bsize == BLOCK_8X8 && |
| 1741 partition_none_allowed) |
| 1742 get_block_context(x, subsize)->pred_filter_type = |
| 1743 get_block_context(x, bsize)->mic.mbmi.interp_filter; |
1638 pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, | 1744 pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
1639 get_block_context(x, subsize), best_rd); | 1745 get_block_context(x, subsize), best_rd); |
1640 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1746 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1641 | 1747 |
1642 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { | 1748 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { |
1643 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1749 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1644 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1750 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1645 | 1751 |
1646 *get_sb_index(xd, subsize) = 1; | 1752 *get_sb_index(x, subsize) = 1; |
1647 if (cpi->sf.adaptive_motion_search) | 1753 if (cpi->sf.adaptive_motion_search) |
1648 load_pred_mv(x, get_block_context(x, bsize)); | 1754 load_pred_mv(x, get_block_context(x, bsize)); |
| 1755 if (cpi->sf.adaptive_pred_filter_type && bsize == BLOCK_8X8 && |
| 1756 partition_none_allowed) |
| 1757 get_block_context(x, subsize)->pred_filter_type = |
| 1758 get_block_context(x, bsize)->mic.mbmi.interp_filter; |
1649 pick_sb_modes(cpi, tile, mi_row + ms, mi_col, &this_rate, | 1759 pick_sb_modes(cpi, tile, mi_row + ms, mi_col, &this_rate, |
1650 &this_dist, subsize, get_block_context(x, subsize), | 1760 &this_dist, subsize, get_block_context(x, subsize), |
1651 best_rd - sum_rd); | 1761 best_rd - sum_rd); |
1652 if (this_rate == INT_MAX) { | 1762 if (this_rate == INT_MAX) { |
1653 sum_rd = INT64_MAX; | 1763 sum_rd = INT64_MAX; |
1654 } else { | 1764 } else { |
1655 sum_rate += this_rate; | 1765 sum_rate += this_rate; |
1656 sum_dist += this_dist; | 1766 sum_dist += this_dist; |
1657 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1767 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1658 } | 1768 } |
(...skipping 11 matching lines...) Expand all Loading... |
1670 *(get_sb_partitioning(x, bsize)) = subsize; | 1780 *(get_sb_partitioning(x, bsize)) = subsize; |
1671 } | 1781 } |
1672 } | 1782 } |
1673 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1783 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1674 } | 1784 } |
1675 | 1785 |
1676 // PARTITION_VERT | 1786 // PARTITION_VERT |
1677 if (partition_vert_allowed && do_rect) { | 1787 if (partition_vert_allowed && do_rect) { |
1678 subsize = get_subsize(bsize, PARTITION_VERT); | 1788 subsize = get_subsize(bsize, PARTITION_VERT); |
1679 | 1789 |
1680 *get_sb_index(xd, subsize) = 0; | 1790 *get_sb_index(x, subsize) = 0; |
1681 if (cpi->sf.adaptive_motion_search) | 1791 if (cpi->sf.adaptive_motion_search) |
1682 load_pred_mv(x, get_block_context(x, bsize)); | 1792 load_pred_mv(x, get_block_context(x, bsize)); |
| 1793 if (cpi->sf.adaptive_pred_filter_type && bsize == BLOCK_8X8 && |
| 1794 partition_none_allowed) |
| 1795 get_block_context(x, subsize)->pred_filter_type = |
| 1796 get_block_context(x, bsize)->mic.mbmi.interp_filter; |
1683 pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, | 1797 pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
1684 get_block_context(x, subsize), best_rd); | 1798 get_block_context(x, subsize), best_rd); |
1685 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1799 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1686 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { | 1800 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { |
1687 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1801 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
1688 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1802 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
1689 | 1803 |
1690 *get_sb_index(xd, subsize) = 1; | 1804 *get_sb_index(x, subsize) = 1; |
1691 if (cpi->sf.adaptive_motion_search) | 1805 if (cpi->sf.adaptive_motion_search) |
1692 load_pred_mv(x, get_block_context(x, bsize)); | 1806 load_pred_mv(x, get_block_context(x, bsize)); |
| 1807 if (cpi->sf.adaptive_pred_filter_type && bsize == BLOCK_8X8 && |
| 1808 partition_none_allowed) |
| 1809 get_block_context(x, subsize)->pred_filter_type = |
| 1810 get_block_context(x, bsize)->mic.mbmi.interp_filter; |
1693 pick_sb_modes(cpi, tile, mi_row, mi_col + ms, &this_rate, | 1811 pick_sb_modes(cpi, tile, mi_row, mi_col + ms, &this_rate, |
1694 &this_dist, subsize, get_block_context(x, subsize), | 1812 &this_dist, subsize, get_block_context(x, subsize), |
1695 best_rd - sum_rd); | 1813 best_rd - sum_rd); |
1696 if (this_rate == INT_MAX) { | 1814 if (this_rate == INT_MAX) { |
1697 sum_rd = INT64_MAX; | 1815 sum_rd = INT64_MAX; |
1698 } else { | 1816 } else { |
1699 sum_rate += this_rate; | 1817 sum_rate += this_rate; |
1700 sum_dist += this_dist; | 1818 sum_dist += this_dist; |
1701 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1819 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
1702 } | 1820 } |
(...skipping 11 matching lines...) Expand all Loading... |
1714 *(get_sb_partitioning(x, bsize)) = subsize; | 1832 *(get_sb_partitioning(x, bsize)) = subsize; |
1715 } | 1833 } |
1716 } | 1834 } |
1717 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1835 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
1718 } | 1836 } |
1719 | 1837 |
1720 | 1838 |
1721 *rate = best_rate; | 1839 *rate = best_rate; |
1722 *dist = best_dist; | 1840 *dist = best_dist; |
1723 | 1841 |
1724 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) | 1842 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) { |
1725 encode_sb(cpi, tile, tp, mi_row, mi_col, bsize == BLOCK_64X64, bsize); | 1843 int output_enabled = (bsize == BLOCK_64X64); |
| 1844 |
| 1845 // Check the projected output rate for this SB against it's target |
| 1846 // and and if necessary apply a Q delta using segmentation to get |
| 1847 // closer to the target. |
| 1848 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { |
| 1849 select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, best_rate); |
| 1850 } |
| 1851 encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize); |
| 1852 } |
1726 if (bsize == BLOCK_64X64) { | 1853 if (bsize == BLOCK_64X64) { |
1727 assert(tp_orig < *tp); | 1854 assert(tp_orig < *tp); |
1728 assert(best_rate < INT_MAX); | 1855 assert(best_rate < INT_MAX); |
1729 assert(best_dist < INT_MAX); | 1856 assert(best_dist < INT_MAX); |
1730 } else { | 1857 } else { |
1731 assert(tp_orig == *tp); | 1858 assert(tp_orig == *tp); |
1732 } | 1859 } |
1733 } | 1860 } |
1734 | 1861 |
1735 // Examines 64x64 block and chooses a best reference frame | 1862 // Examines 64x64 block and chooses a best reference frame |
(...skipping 25 matching lines...) Expand all Loading... |
1761 r += x->partition_cost[pl][PARTITION_NONE]; | 1888 r += x->partition_cost[pl][PARTITION_NONE]; |
1762 | 1889 |
1763 *(get_sb_partitioning(x, BLOCK_64X64)) = BLOCK_64X64; | 1890 *(get_sb_partitioning(x, BLOCK_64X64)) = BLOCK_64X64; |
1764 cpi->set_ref_frame_mask = 0; | 1891 cpi->set_ref_frame_mask = 0; |
1765 } | 1892 } |
1766 | 1893 |
1767 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); | 1894 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, BLOCK_64X64); |
1768 } | 1895 } |
1769 | 1896 |
1770 static void encode_sb_row(VP9_COMP *cpi, const TileInfo *const tile, | 1897 static void encode_sb_row(VP9_COMP *cpi, const TileInfo *const tile, |
1771 int mi_row, TOKENEXTRA **tp, int *totalrate) { | 1898 int mi_row, TOKENEXTRA **tp) { |
1772 VP9_COMMON * const cm = &cpi->common; | 1899 VP9_COMMON * const cm = &cpi->common; |
1773 int mi_col; | 1900 int mi_col; |
1774 | 1901 |
1775 // Initialize the left context for the new SB row | 1902 // Initialize the left context for the new SB row |
1776 vpx_memset(&cpi->left_context, 0, sizeof(cpi->left_context)); | 1903 vpx_memset(&cpi->left_context, 0, sizeof(cpi->left_context)); |
1777 vpx_memset(cpi->left_seg_context, 0, sizeof(cpi->left_seg_context)); | 1904 vpx_memset(cpi->left_seg_context, 0, sizeof(cpi->left_seg_context)); |
1778 | 1905 |
1779 // Code each SB in the row | 1906 // Code each SB in the row |
1780 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; | 1907 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; |
1781 mi_col += MI_BLOCK_SIZE) { | 1908 mi_col += MI_BLOCK_SIZE) { |
1782 int dummy_rate; | 1909 int dummy_rate; |
1783 int64_t dummy_dist; | 1910 int64_t dummy_dist; |
1784 | 1911 |
| 1912 BLOCK_SIZE i; |
| 1913 MACROBLOCK *x = &cpi->mb; |
| 1914 for (i = BLOCK_4X4; i < BLOCK_8X8; ++i) { |
| 1915 const int num_4x4_w = num_4x4_blocks_wide_lookup[i]; |
| 1916 const int num_4x4_h = num_4x4_blocks_high_lookup[i]; |
| 1917 const int num_4x4_blk = MAX(4, num_4x4_w * num_4x4_h); |
| 1918 for (x->sb_index = 0; x->sb_index < 4; ++x->sb_index) |
| 1919 for (x->mb_index = 0; x->mb_index < 4; ++x->mb_index) |
| 1920 for (x->b_index = 0; x->b_index < 16 / num_4x4_blk; ++x->b_index) |
| 1921 get_block_context(x, i)->pred_filter_type = SWITCHABLE; |
| 1922 } |
| 1923 |
1785 vp9_zero(cpi->mb.pred_mv); | 1924 vp9_zero(cpi->mb.pred_mv); |
1786 | 1925 |
1787 if (cpi->sf.reference_masking) | 1926 if (cpi->sf.reference_masking) |
1788 rd_pick_reference_frame(cpi, tile, mi_row, mi_col); | 1927 rd_pick_reference_frame(cpi, tile, mi_row, mi_col); |
1789 | 1928 |
1790 if (cpi->sf.use_lastframe_partitioning || | 1929 if (cpi->sf.use_lastframe_partitioning || |
1791 cpi->sf.use_one_partition_size_always ) { | 1930 cpi->sf.use_one_partition_size_always ) { |
1792 const int idx_str = cm->mode_info_stride * mi_row + mi_col; | 1931 const int idx_str = cm->mode_info_stride * mi_row + mi_col; |
1793 MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; | 1932 MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; |
1794 MODE_INFO **prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; | 1933 MODE_INFO **prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1842 MACROBLOCK *const x = &cpi->mb; | 1981 MACROBLOCK *const x = &cpi->mb; |
1843 VP9_COMMON *const cm = &cpi->common; | 1982 VP9_COMMON *const cm = &cpi->common; |
1844 MACROBLOCKD *const xd = &x->e_mbd; | 1983 MACROBLOCKD *const xd = &x->e_mbd; |
1845 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); | 1984 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); |
1846 | 1985 |
1847 x->act_zbin_adj = 0; | 1986 x->act_zbin_adj = 0; |
1848 cpi->seg0_idx = 0; | 1987 cpi->seg0_idx = 0; |
1849 | 1988 |
1850 xd->mode_info_stride = cm->mode_info_stride; | 1989 xd->mode_info_stride = cm->mode_info_stride; |
1851 | 1990 |
1852 // reset intra mode contexts | |
1853 if (frame_is_intra_only(cm)) | |
1854 vp9_init_mbmode_probs(cm); | |
1855 | |
1856 // Copy data over into macro block data structures. | 1991 // Copy data over into macro block data structures. |
1857 vp9_setup_src_planes(x, cpi->Source, 0, 0); | 1992 vp9_setup_src_planes(x, cpi->Source, 0, 0); |
1858 | 1993 |
1859 // TODO(jkoleszar): are these initializations required? | 1994 // TODO(jkoleszar): are these initializations required? |
1860 setup_pre_planes(xd, 0, &cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]], | 1995 setup_pre_planes(xd, 0, &cm->yv12_fb[cm->ref_frame_map[cpi->lst_fb_idx]], |
1861 0, 0, NULL); | 1996 0, 0, NULL); |
1862 setup_dst_planes(xd, get_frame_new_buffer(cm), 0, 0); | 1997 setup_dst_planes(xd, get_frame_new_buffer(cm), 0, 0); |
1863 | 1998 |
1864 setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); | 1999 setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); |
1865 | 2000 |
1866 xd->mi_8x8[0]->mbmi.mode = DC_PRED; | 2001 xd->mi_8x8[0]->mbmi.mode = DC_PRED; |
1867 xd->mi_8x8[0]->mbmi.uv_mode = DC_PRED; | 2002 xd->mi_8x8[0]->mbmi.uv_mode = DC_PRED; |
1868 | 2003 |
1869 vp9_zero(cpi->y_mode_count); | 2004 vp9_zero(cpi->y_mode_count); |
1870 vp9_zero(cpi->y_uv_mode_count); | 2005 vp9_zero(cpi->y_uv_mode_count); |
1871 vp9_zero(cm->counts.inter_mode); | 2006 vp9_zero(cm->counts.inter_mode); |
1872 vp9_zero(cpi->partition_count); | 2007 vp9_zero(cm->counts.partition); |
1873 vp9_zero(cpi->intra_inter_count); | 2008 vp9_zero(cpi->intra_inter_count); |
1874 vp9_zero(cpi->comp_inter_count); | 2009 vp9_zero(cpi->comp_inter_count); |
1875 vp9_zero(cpi->single_ref_count); | 2010 vp9_zero(cpi->single_ref_count); |
1876 vp9_zero(cpi->comp_ref_count); | 2011 vp9_zero(cpi->comp_ref_count); |
1877 vp9_zero(cm->counts.tx); | 2012 vp9_zero(cm->counts.tx); |
1878 vp9_zero(cm->counts.mbskip); | 2013 vp9_zero(cm->counts.mbskip); |
1879 | 2014 |
1880 // Note: this memset assumes above_context[0], [1] and [2] | 2015 // Note: this memset assumes above_context[0], [1] and [2] |
1881 // are allocated as part of the same buffer. | 2016 // are allocated as part of the same buffer. |
1882 vpx_memset(cpi->above_context[0], 0, | 2017 vpx_memset(cpi->above_context[0], 0, |
(...skipping 23 matching lines...) Expand all Loading... |
1906 if (cpi->sf.tx_size_search_method == USE_LARGESTALL && | 2041 if (cpi->sf.tx_size_search_method == USE_LARGESTALL && |
1907 cpi->common.tx_mode >= ALLOW_32X32) | 2042 cpi->common.tx_mode >= ALLOW_32X32) |
1908 cpi->common.tx_mode = ALLOW_32X32; | 2043 cpi->common.tx_mode = ALLOW_32X32; |
1909 } | 2044 } |
1910 | 2045 |
1911 static void encode_frame_internal(VP9_COMP *cpi) { | 2046 static void encode_frame_internal(VP9_COMP *cpi) { |
1912 int mi_row; | 2047 int mi_row; |
1913 MACROBLOCK * const x = &cpi->mb; | 2048 MACROBLOCK * const x = &cpi->mb; |
1914 VP9_COMMON * const cm = &cpi->common; | 2049 VP9_COMMON * const cm = &cpi->common; |
1915 MACROBLOCKD * const xd = &x->e_mbd; | 2050 MACROBLOCKD * const xd = &x->e_mbd; |
1916 int totalrate; | |
1917 | 2051 |
1918 // fprintf(stderr, "encode_frame_internal frame %d (%d) type %d\n", | 2052 // fprintf(stderr, "encode_frame_internal frame %d (%d) type %d\n", |
1919 // cpi->common.current_video_frame, cpi->common.show_frame, | 2053 // cpi->common.current_video_frame, cpi->common.show_frame, |
1920 // cm->frame_type); | 2054 // cm->frame_type); |
1921 | 2055 |
1922 // debug output | 2056 // debug output |
1923 #if DBG_PRNT_SEGMAP | 2057 #if DBG_PRNT_SEGMAP |
1924 { | 2058 { |
1925 FILE *statsfile; | 2059 FILE *statsfile; |
1926 statsfile = fopen("segmap2.stt", "a"); | 2060 statsfile = fopen("segmap2.stt", "a"); |
1927 fprintf(statsfile, "\n"); | 2061 fprintf(statsfile, "\n"); |
1928 fclose(statsfile); | 2062 fclose(statsfile); |
1929 } | 2063 } |
1930 #endif | 2064 #endif |
1931 | 2065 |
1932 totalrate = 0; | |
1933 | |
1934 // Reset frame count of inter 0,0 motion vector usage. | |
1935 cpi->inter_zz_count = 0; | |
1936 | |
1937 vp9_zero(cm->counts.switchable_interp); | 2066 vp9_zero(cm->counts.switchable_interp); |
1938 vp9_zero(cpi->tx_stepdown_count); | 2067 vp9_zero(cpi->tx_stepdown_count); |
1939 | 2068 |
1940 xd->mi_8x8 = cm->mi_grid_visible; | 2069 xd->mi_8x8 = cm->mi_grid_visible; |
1941 // required for vp9_frame_init_quantizer | 2070 // required for vp9_frame_init_quantizer |
1942 xd->mi_8x8[0] = cm->mi; | 2071 xd->mi_8x8[0] = cm->mi; |
1943 | 2072 |
1944 xd->last_mi = cm->prev_mi; | 2073 xd->last_mi = cm->prev_mi; |
1945 | 2074 |
1946 vp9_zero(cpi->NMVcount); | 2075 vp9_zero(cpi->NMVcount); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 | 2117 |
1989 for (tile_row = 0; tile_row < tile_rows; tile_row++) { | 2118 for (tile_row = 0; tile_row < tile_rows; tile_row++) { |
1990 for (tile_col = 0; tile_col < tile_cols; tile_col++) { | 2119 for (tile_col = 0; tile_col < tile_cols; tile_col++) { |
1991 TileInfo tile; | 2120 TileInfo tile; |
1992 TOKENEXTRA *tp_old = tp; | 2121 TOKENEXTRA *tp_old = tp; |
1993 | 2122 |
1994 // For each row of SBs in the frame | 2123 // For each row of SBs in the frame |
1995 vp9_tile_init(&tile, cm, tile_row, tile_col); | 2124 vp9_tile_init(&tile, cm, tile_row, tile_col); |
1996 for (mi_row = tile.mi_row_start; | 2125 for (mi_row = tile.mi_row_start; |
1997 mi_row < tile.mi_row_end; mi_row += 8) | 2126 mi_row < tile.mi_row_end; mi_row += 8) |
1998 encode_sb_row(cpi, &tile, mi_row, &tp, &totalrate); | 2127 encode_sb_row(cpi, &tile, mi_row, &tp); |
1999 | 2128 |
2000 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); | 2129 cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); |
2001 assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); | 2130 assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); |
2002 } | 2131 } |
2003 } | 2132 } |
2004 } | 2133 } |
2005 | 2134 |
2006 vpx_usec_timer_mark(&emr_timer); | 2135 vpx_usec_timer_mark(&emr_timer); |
2007 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); | 2136 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); |
2008 } | 2137 } |
2009 | 2138 |
2010 if (cpi->sf.skip_encode_sb) { | 2139 if (cpi->sf.skip_encode_sb) { |
2011 int j; | 2140 int j; |
2012 unsigned int intra_count = 0, inter_count = 0; | 2141 unsigned int intra_count = 0, inter_count = 0; |
2013 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { | 2142 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { |
2014 intra_count += cpi->intra_inter_count[j][0]; | 2143 intra_count += cpi->intra_inter_count[j][0]; |
2015 inter_count += cpi->intra_inter_count[j][1]; | 2144 inter_count += cpi->intra_inter_count[j][1]; |
2016 } | 2145 } |
2017 cpi->sf.skip_encode_frame = ((intra_count << 2) < inter_count); | 2146 cpi->sf.skip_encode_frame = ((intra_count << 2) < inter_count); |
2018 cpi->sf.skip_encode_frame &= (cm->frame_type != KEY_FRAME); | 2147 cpi->sf.skip_encode_frame &= (cm->frame_type != KEY_FRAME); |
2019 cpi->sf.skip_encode_frame &= cm->show_frame; | 2148 cpi->sf.skip_encode_frame &= cm->show_frame; |
2020 } else { | 2149 } else { |
2021 cpi->sf.skip_encode_frame = 0; | 2150 cpi->sf.skip_encode_frame = 0; |
2022 } | 2151 } |
2023 | 2152 |
2024 // 256 rate units to the bit, | |
2025 // projected_frame_size in units of BYTES | |
2026 cpi->projected_frame_size = totalrate >> 8; | |
2027 | |
2028 #if 0 | 2153 #if 0 |
2029 // Keep record of the total distortion this time around for future use | 2154 // Keep record of the total distortion this time around for future use |
2030 cpi->last_frame_distortion = cpi->frame_distortion; | 2155 cpi->last_frame_distortion = cpi->frame_distortion; |
2031 #endif | 2156 #endif |
2032 } | 2157 } |
2033 | 2158 |
2034 static int check_dual_ref_flags(VP9_COMP *cpi) { | 2159 static int check_dual_ref_flags(VP9_COMP *cpi) { |
2035 const int ref_flags = cpi->ref_frame_flags; | 2160 const int ref_flags = cpi->ref_frame_flags; |
2036 | 2161 |
2037 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { | 2162 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2218 * worked best for that type of frame in the past. | 2343 * worked best for that type of frame in the past. |
2219 * It also predicts whether another coding mode would have worked | 2344 * It also predicts whether another coding mode would have worked |
2220 * better that this coding mode. If that is the case, it remembers | 2345 * better that this coding mode. If that is the case, it remembers |
2221 * that for subsequent frames. | 2346 * that for subsequent frames. |
2222 * It does the same analysis for transform size selection also. | 2347 * It does the same analysis for transform size selection also. |
2223 */ | 2348 */ |
2224 int frame_type = get_frame_type(cpi); | 2349 int frame_type = get_frame_type(cpi); |
2225 | 2350 |
2226 /* prediction (compound, single or hybrid) mode selection */ | 2351 /* prediction (compound, single or hybrid) mode selection */ |
2227 if (frame_type == 3 || !cm->allow_comp_inter_inter) | 2352 if (frame_type == 3 || !cm->allow_comp_inter_inter) |
2228 pred_type = SINGLE_PREDICTION_ONLY; | 2353 pred_type = SINGLE_REFERENCE; |
2229 else if (cpi->rd_prediction_type_threshes[frame_type][1] | 2354 else if (cpi->rd_prediction_type_threshes[frame_type][1] |
2230 > cpi->rd_prediction_type_threshes[frame_type][0] | 2355 > cpi->rd_prediction_type_threshes[frame_type][0] |
2231 && cpi->rd_prediction_type_threshes[frame_type][1] | 2356 && cpi->rd_prediction_type_threshes[frame_type][1] |
2232 > cpi->rd_prediction_type_threshes[frame_type][2] | 2357 > cpi->rd_prediction_type_threshes[frame_type][2] |
2233 && check_dual_ref_flags(cpi) && cpi->static_mb_pct == 100) | 2358 && check_dual_ref_flags(cpi) && cpi->static_mb_pct == 100) |
2234 pred_type = COMP_PREDICTION_ONLY; | 2359 pred_type = COMPOUND_REFERENCE; |
2235 else if (cpi->rd_prediction_type_threshes[frame_type][0] | 2360 else if (cpi->rd_prediction_type_threshes[frame_type][0] |
2236 > cpi->rd_prediction_type_threshes[frame_type][2]) | 2361 > cpi->rd_prediction_type_threshes[frame_type][2]) |
2237 pred_type = SINGLE_PREDICTION_ONLY; | 2362 pred_type = SINGLE_REFERENCE; |
2238 else | 2363 else |
2239 pred_type = HYBRID_PREDICTION; | 2364 pred_type = REFERENCE_MODE_SELECT; |
2240 | 2365 |
2241 /* filter type selection */ | 2366 /* filter type selection */ |
2242 // FIXME(rbultje) for some odd reason, we often select smooth_filter | 2367 // FIXME(rbultje) for some odd reason, we often select smooth_filter |
2243 // as default filter for ARF overlay frames. This is a REALLY BAD | 2368 // as default filter for ARF overlay frames. This is a REALLY BAD |
2244 // IDEA so we explicitly disable it here. | 2369 // IDEA so we explicitly disable it here. |
2245 if (frame_type != 3 && | 2370 if (frame_type != 3 && |
2246 cpi->rd_filter_threshes[frame_type][1] > | 2371 cpi->rd_filter_threshes[frame_type][1] > |
2247 cpi->rd_filter_threshes[frame_type][0] && | 2372 cpi->rd_filter_threshes[frame_type][0] && |
2248 cpi->rd_filter_threshes[frame_type][1] > | 2373 cpi->rd_filter_threshes[frame_type][1] > |
2249 cpi->rd_filter_threshes[frame_type][2] && | 2374 cpi->rd_filter_threshes[frame_type][2] && |
(...skipping 12 matching lines...) Expand all Loading... |
2262 filter_type = SWITCHABLE; | 2387 filter_type = SWITCHABLE; |
2263 } | 2388 } |
2264 | 2389 |
2265 cpi->mb.e_mbd.lossless = 0; | 2390 cpi->mb.e_mbd.lossless = 0; |
2266 if (cpi->oxcf.lossless) { | 2391 if (cpi->oxcf.lossless) { |
2267 cpi->mb.e_mbd.lossless = 1; | 2392 cpi->mb.e_mbd.lossless = 1; |
2268 } | 2393 } |
2269 | 2394 |
2270 /* transform size selection (4x4, 8x8, 16x16 or select-per-mb) */ | 2395 /* transform size selection (4x4, 8x8, 16x16 or select-per-mb) */ |
2271 select_tx_mode(cpi); | 2396 select_tx_mode(cpi); |
2272 cpi->common.comp_pred_mode = pred_type; | 2397 cpi->common.reference_mode = pred_type; |
2273 cpi->common.mcomp_filter_type = filter_type; | 2398 cpi->common.mcomp_filter_type = filter_type; |
2274 encode_frame_internal(cpi); | 2399 encode_frame_internal(cpi); |
2275 | 2400 |
2276 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { | 2401 for (i = 0; i < REFERENCE_MODES; ++i) { |
2277 const int diff = (int) (cpi->rd_comp_pred_diff[i] / cpi->common.MBs); | 2402 const int diff = (int) (cpi->rd_comp_pred_diff[i] / cpi->common.MBs); |
2278 cpi->rd_prediction_type_threshes[frame_type][i] += diff; | 2403 cpi->rd_prediction_type_threshes[frame_type][i] += diff; |
2279 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; | 2404 cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; |
2280 } | 2405 } |
2281 | 2406 |
2282 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { | 2407 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
2283 const int64_t diff = cpi->rd_filter_diff[i] / cpi->common.MBs; | 2408 const int64_t diff = cpi->rd_filter_diff[i] / cpi->common.MBs; |
2284 cpi->rd_filter_threshes[frame_type][i] = | 2409 cpi->rd_filter_threshes[frame_type][i] = |
2285 (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; | 2410 (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; |
2286 } | 2411 } |
2287 | 2412 |
2288 for (i = 0; i < TX_MODES; ++i) { | 2413 for (i = 0; i < TX_MODES; ++i) { |
2289 int64_t pd = cpi->rd_tx_select_diff[i]; | 2414 int64_t pd = cpi->rd_tx_select_diff[i]; |
2290 int diff; | 2415 int diff; |
2291 if (i == TX_MODE_SELECT) | 2416 if (i == TX_MODE_SELECT) |
2292 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, | 2417 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, |
2293 2048 * (TX_SIZES - 1), 0); | 2418 2048 * (TX_SIZES - 1), 0); |
2294 diff = (int) (pd / cpi->common.MBs); | 2419 diff = (int) (pd / cpi->common.MBs); |
2295 cpi->rd_tx_select_threshes[frame_type][i] += diff; | 2420 cpi->rd_tx_select_threshes[frame_type][i] += diff; |
2296 cpi->rd_tx_select_threshes[frame_type][i] /= 2; | 2421 cpi->rd_tx_select_threshes[frame_type][i] /= 2; |
2297 } | 2422 } |
2298 | 2423 |
2299 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { | 2424 if (cpi->common.reference_mode == REFERENCE_MODE_SELECT) { |
2300 int single_count_zero = 0; | 2425 int single_count_zero = 0; |
2301 int comp_count_zero = 0; | 2426 int comp_count_zero = 0; |
2302 | 2427 |
2303 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { | 2428 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { |
2304 single_count_zero += cpi->comp_inter_count[i][0]; | 2429 single_count_zero += cpi->comp_inter_count[i][0]; |
2305 comp_count_zero += cpi->comp_inter_count[i][1]; | 2430 comp_count_zero += cpi->comp_inter_count[i][1]; |
2306 } | 2431 } |
2307 | 2432 |
2308 if (comp_count_zero == 0) { | 2433 if (comp_count_zero == 0) { |
2309 cpi->common.comp_pred_mode = SINGLE_PREDICTION_ONLY; | 2434 cpi->common.reference_mode = SINGLE_REFERENCE; |
2310 vp9_zero(cpi->comp_inter_count); | 2435 vp9_zero(cpi->comp_inter_count); |
2311 } else if (single_count_zero == 0) { | 2436 } else if (single_count_zero == 0) { |
2312 cpi->common.comp_pred_mode = COMP_PREDICTION_ONLY; | 2437 cpi->common.reference_mode = COMPOUND_REFERENCE; |
2313 vp9_zero(cpi->comp_inter_count); | 2438 vp9_zero(cpi->comp_inter_count); |
2314 } | 2439 } |
2315 } | 2440 } |
2316 | 2441 |
2317 if (cpi->common.tx_mode == TX_MODE_SELECT) { | 2442 if (cpi->common.tx_mode == TX_MODE_SELECT) { |
2318 int count4x4 = 0; | 2443 int count4x4 = 0; |
2319 int count8x8_lp = 0, count8x8_8x8p = 0; | 2444 int count8x8_lp = 0, count8x8_8x8p = 0; |
2320 int count16x16_16x16p = 0, count16x16_lp = 0; | 2445 int count16x16_16x16p = 0, count16x16_lp = 0; |
2321 int count32x32 = 0; | 2446 int count32x32 = 0; |
2322 | 2447 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 #endif | 2519 #endif |
2395 } | 2520 } |
2396 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, | 2521 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
2397 int mi_row, int mi_col, BLOCK_SIZE bsize) { | 2522 int mi_row, int mi_col, BLOCK_SIZE bsize) { |
2398 VP9_COMMON * const cm = &cpi->common; | 2523 VP9_COMMON * const cm = &cpi->common; |
2399 MACROBLOCK * const x = &cpi->mb; | 2524 MACROBLOCK * const x = &cpi->mb; |
2400 MACROBLOCKD * const xd = &x->e_mbd; | 2525 MACROBLOCKD * const xd = &x->e_mbd; |
2401 MODE_INFO **mi_8x8 = xd->mi_8x8; | 2526 MODE_INFO **mi_8x8 = xd->mi_8x8; |
2402 MODE_INFO *mi = mi_8x8[0]; | 2527 MODE_INFO *mi = mi_8x8[0]; |
2403 MB_MODE_INFO *mbmi = &mi->mbmi; | 2528 MB_MODE_INFO *mbmi = &mi->mbmi; |
| 2529 PICK_MODE_CONTEXT *ctx = get_block_context(x, bsize); |
2404 unsigned int segment_id = mbmi->segment_id; | 2530 unsigned int segment_id = mbmi->segment_id; |
2405 const int mis = cm->mode_info_stride; | 2531 const int mis = cm->mode_info_stride; |
2406 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 2532 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
2407 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 2533 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 2534 x->skip_recode = !x->select_txfm_size && mbmi->sb_type >= BLOCK_8X8 && |
| 2535 (cpi->oxcf.aq_mode != COMPLEXITY_AQ); |
| 2536 x->skip_optimize = ctx->is_coded; |
| 2537 ctx->is_coded = 1; |
2408 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; | 2538 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; |
2409 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && | 2539 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && |
2410 xd->q_index < QIDX_SKIP_THRESH); | 2540 x->q_index < QIDX_SKIP_THRESH); |
2411 if (x->skip_encode) | 2541 if (x->skip_encode) |
2412 return; | 2542 return; |
2413 | 2543 |
2414 if (cm->frame_type == KEY_FRAME) { | 2544 if (cm->frame_type == KEY_FRAME) { |
2415 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { | 2545 if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { |
2416 adjust_act_zbin(cpi, x); | 2546 adjust_act_zbin(cpi, x); |
2417 vp9_update_zbin_extra(cpi, x); | 2547 vp9_update_zbin_extra(cpi, x); |
2418 } | 2548 } |
2419 } else { | 2549 } else { |
2420 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 2550 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2485 cm->counts.mbskip[mb_skip_context][1]++; | 2615 cm->counts.mbskip[mb_skip_context][1]++; |
2486 reset_skip_context(xd, MAX(bsize, BLOCK_8X8)); | 2616 reset_skip_context(xd, MAX(bsize, BLOCK_8X8)); |
2487 } | 2617 } |
2488 | 2618 |
2489 if (output_enabled) { | 2619 if (output_enabled) { |
2490 if (cm->tx_mode == TX_MODE_SELECT && | 2620 if (cm->tx_mode == TX_MODE_SELECT && |
2491 mbmi->sb_type >= BLOCK_8X8 && | 2621 mbmi->sb_type >= BLOCK_8X8 && |
2492 !(is_inter_block(mbmi) && | 2622 !(is_inter_block(mbmi) && |
2493 (mbmi->skip_coeff || | 2623 (mbmi->skip_coeff || |
2494 vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)))) { | 2624 vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)))) { |
2495 const uint8_t context = vp9_get_pred_context_tx_size(xd); | 2625 ++get_tx_counts(max_txsize_lookup[bsize], vp9_get_tx_size_context(xd), |
2496 ++get_tx_counts(bsize, context, &cm->counts.tx)[mbmi->tx_size]; | 2626 &cm->counts.tx)[mbmi->tx_size]; |
2497 } else { | 2627 } else { |
2498 int x, y; | 2628 int x, y; |
2499 TX_SIZE sz = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 2629 TX_SIZE tx_size; |
2500 assert(sizeof(tx_mode_to_biggest_tx_size) / | |
2501 sizeof(tx_mode_to_biggest_tx_size[0]) == TX_MODES); | |
2502 // The new intra coding scheme requires no change of transform size | 2630 // The new intra coding scheme requires no change of transform size |
2503 if (is_inter_block(&mi->mbmi)) { | 2631 if (is_inter_block(&mi->mbmi)) { |
2504 if (sz == TX_32X32 && bsize < BLOCK_32X32) | 2632 tx_size = MIN(tx_mode_to_biggest_tx_size[cm->tx_mode], |
2505 sz = TX_16X16; | 2633 max_txsize_lookup[bsize]); |
2506 if (sz == TX_16X16 && bsize < BLOCK_16X16) | |
2507 sz = TX_8X8; | |
2508 if (sz == TX_8X8 && bsize < BLOCK_8X8) | |
2509 sz = TX_4X4; | |
2510 } else if (bsize >= BLOCK_8X8) { | |
2511 sz = mbmi->tx_size; | |
2512 } else { | 2634 } else { |
2513 sz = TX_4X4; | 2635 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; |
2514 } | 2636 } |
2515 | 2637 |
2516 for (y = 0; y < mi_height; y++) | 2638 for (y = 0; y < mi_height; y++) |
2517 for (x = 0; x < mi_width; x++) | 2639 for (x = 0; x < mi_width; x++) |
2518 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 2640 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
2519 mi_8x8[mis * y + x]->mbmi.tx_size = sz; | 2641 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; |
2520 } | 2642 } |
2521 } | 2643 } |
2522 } | 2644 } |
OLD | NEW |