| 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 |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 MACROBLOCK *x = &cpi->mb; | 460 MACROBLOCK *x = &cpi->mb; |
| 461 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 461 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
| 462 | 462 |
| 463 int i, j, k; | 463 int i, j, k; |
| 464 v64x64 vt; | 464 v64x64 vt; |
| 465 uint8_t *s; | 465 uint8_t *s; |
| 466 const uint8_t *d; | 466 const uint8_t *d; |
| 467 int sp; | 467 int sp; |
| 468 int dp; | 468 int dp; |
| 469 int pixels_wide = 64, pixels_high = 64; | 469 int pixels_wide = 64, pixels_high = 64; |
| 470 int_mv nearest_mv, near_mv; | |
| 471 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); | 470 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); |
| 472 const struct scale_factors *const sf = &cm->frame_refs[LAST_FRAME - 1].sf; | 471 const struct scale_factors *const sf = &cm->frame_refs[LAST_FRAME - 1].sf; |
| 473 | 472 |
| 474 vp9_clear_system_state(); | 473 vp9_clear_system_state(); |
| 475 vp9_zero(vt); | 474 vp9_zero(vt); |
| 476 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 475 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
| 477 | 476 |
| 478 if (xd->mb_to_right_edge < 0) | 477 if (xd->mb_to_right_edge < 0) |
| 479 pixels_wide += (xd->mb_to_right_edge >> 3); | 478 pixels_wide += (xd->mb_to_right_edge >> 3); |
| 480 if (xd->mb_to_bottom_edge < 0) | 479 if (xd->mb_to_bottom_edge < 0) |
| 481 pixels_high += (xd->mb_to_bottom_edge >> 3); | 480 pixels_high += (xd->mb_to_bottom_edge >> 3); |
| 482 | 481 |
| 483 s = x->plane[0].src.buf; | 482 s = x->plane[0].src.buf; |
| 484 sp = x->plane[0].src.stride; | 483 sp = x->plane[0].src.stride; |
| 485 | 484 |
| 486 if (cm->frame_type != KEY_FRAME) { | 485 if (cm->frame_type != KEY_FRAME) { |
| 487 vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col, sf); | 486 vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col, sf); |
| 488 | 487 |
| 489 xd->mi[0].src_mi->mbmi.ref_frame[0] = LAST_FRAME; | 488 xd->mi[0].src_mi->mbmi.ref_frame[0] = LAST_FRAME; |
| 490 xd->mi[0].src_mi->mbmi.sb_type = BLOCK_64X64; | 489 xd->mi[0].src_mi->mbmi.sb_type = BLOCK_64X64; |
| 491 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, | 490 xd->mi[0].src_mi->mbmi.mv[0].as_int = 0; |
| 492 xd->mi[0].src_mi->mbmi.ref_mvs[LAST_FRAME], | |
| 493 &nearest_mv, &near_mv); | |
| 494 | |
| 495 xd->mi[0].src_mi->mbmi.mv[0] = nearest_mv; | |
| 496 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_64X64); | 491 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_64X64); |
| 497 | 492 |
| 498 d = xd->plane[0].dst.buf; | 493 d = xd->plane[0].dst.buf; |
| 499 dp = xd->plane[0].dst.stride; | 494 dp = xd->plane[0].dst.stride; |
| 500 } else { | 495 } else { |
| 501 d = VP9_VAR_OFFS; | 496 d = VP9_VAR_OFFS; |
| 502 dp = 0; | 497 dp = 0; |
| 503 #if CONFIG_VP9_HIGHBITDEPTH | 498 #if CONFIG_VP9_HIGHBITDEPTH |
| 504 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 499 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 505 switch (xd->bd) { | 500 switch (xd->bd) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 } | 595 } |
| 601 } | 596 } |
| 602 } | 597 } |
| 603 } | 598 } |
| 604 | 599 |
| 605 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, | 600 static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
| 606 int mi_row, int mi_col, BLOCK_SIZE bsize, | 601 int mi_row, int mi_col, BLOCK_SIZE bsize, |
| 607 int output_enabled) { | 602 int output_enabled) { |
| 608 int i, x_idx, y; | 603 int i, x_idx, y; |
| 609 VP9_COMMON *const cm = &cpi->common; | 604 VP9_COMMON *const cm = &cpi->common; |
| 610 RD_OPT *const rd_opt = &cpi->rd; | 605 COUNTS *const counts = cpi->frame_counts; |
| 611 MACROBLOCK *const x = &cpi->mb; | 606 MACROBLOCK *const x = &cpi->mb; |
| 612 MACROBLOCKD *const xd = &x->e_mbd; | 607 MACROBLOCKD *const xd = &x->e_mbd; |
| 613 struct macroblock_plane *const p = x->plane; | 608 struct macroblock_plane *const p = x->plane; |
| 614 struct macroblockd_plane *const pd = xd->plane; | 609 struct macroblockd_plane *const pd = xd->plane; |
| 615 MODE_INFO *mi = &ctx->mic; | 610 MODE_INFO *mi = &ctx->mic; |
| 616 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 611 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 617 MODE_INFO *mi_addr = &xd->mi[0]; | 612 MODE_INFO *mi_addr = &xd->mi[0]; |
| 618 const struct segmentation *const seg = &cm->seg; | 613 const struct segmentation *const seg = &cm->seg; |
| 614 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; |
| 615 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; |
| 616 const int x_mis = MIN(bw, cm->mi_cols - mi_col); |
| 617 const int y_mis = MIN(bh, cm->mi_rows - mi_row); |
| 618 MV_REF *const frame_mvs = |
| 619 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; |
| 620 int w, h; |
| 619 | 621 |
| 620 const int mis = cm->mi_stride; | 622 const int mis = cm->mi_stride; |
| 621 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 623 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
| 622 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 624 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 623 int max_plane; | 625 int max_plane; |
| 624 | 626 |
| 625 assert(mi->mbmi.sb_type == bsize); | 627 assert(mi->mbmi.sb_type == bsize); |
| 626 | 628 |
| 627 *mi_addr = *mi; | 629 *mi_addr = *mi; |
| 628 mi_addr->src_mi = mi_addr; | 630 mi_addr->src_mi = mi_addr; |
| 629 | 631 |
| 630 // If segmentation in use | 632 // If segmentation in use |
| 631 if (seg->enabled && output_enabled) { | 633 if (seg->enabled && output_enabled) { |
| 632 // For in frame complexity AQ copy the segment id from the segment map. | 634 // For in frame complexity AQ copy the segment id from the segment map. |
| 633 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 635 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 634 const uint8_t *const map = seg->update_map ? cpi->segmentation_map | 636 const uint8_t *const map = seg->update_map ? cpi->segmentation_map |
| 635 : cm->last_frame_seg_map; | 637 : cm->last_frame_seg_map; |
| 636 mi_addr->mbmi.segment_id = | 638 mi_addr->mbmi.segment_id = |
| 637 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 639 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
| 638 } | 640 } |
| 639 // Else for cyclic refresh mode update the segment map, set the segment id | 641 // Else for cyclic refresh mode update the segment map, set the segment id |
| 640 // and then update the quantizer. | 642 // and then update the quantizer. |
| 641 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { | 643 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
| 642 vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0].src_mi->mbmi, | 644 vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0].src_mi->mbmi, |
| 643 mi_row, mi_col, bsize, 1); | 645 mi_row, mi_col, bsize, 1, ctx->rate); |
| 644 } | 646 } |
| 645 } | 647 } |
| 646 | 648 |
| 647 max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; | 649 max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; |
| 648 for (i = 0; i < max_plane; ++i) { | 650 for (i = 0; i < max_plane; ++i) { |
| 649 p[i].coeff = ctx->coeff_pbuf[i][1]; | 651 p[i].coeff = ctx->coeff_pbuf[i][1]; |
| 650 p[i].qcoeff = ctx->qcoeff_pbuf[i][1]; | 652 p[i].qcoeff = ctx->qcoeff_pbuf[i][1]; |
| 651 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; | 653 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; |
| 652 p[i].eobs = ctx->eobs_pbuf[i][1]; | 654 p[i].eobs = ctx->eobs_pbuf[i][1]; |
| 653 } | 655 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 | 688 |
| 687 x->skip = ctx->skip; | 689 x->skip = ctx->skip; |
| 688 vpx_memcpy(x->zcoeff_blk[mbmi->tx_size], ctx->zcoeff_blk, | 690 vpx_memcpy(x->zcoeff_blk[mbmi->tx_size], ctx->zcoeff_blk, |
| 689 sizeof(uint8_t) * ctx->num_4x4_blk); | 691 sizeof(uint8_t) * ctx->num_4x4_blk); |
| 690 | 692 |
| 691 if (!output_enabled) | 693 if (!output_enabled) |
| 692 return; | 694 return; |
| 693 | 695 |
| 694 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { | 696 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 695 for (i = 0; i < TX_MODES; i++) | 697 for (i = 0; i < TX_MODES; i++) |
| 696 rd_opt->tx_select_diff[i] += ctx->tx_rd_diff[i]; | 698 counts->tx_select_diff[i] += ctx->tx_rd_diff[i]; |
| 697 } | 699 } |
| 698 | 700 |
| 699 #if CONFIG_INTERNAL_STATS | 701 #if CONFIG_INTERNAL_STATS |
| 700 if (frame_is_intra_only(cm)) { | 702 if (frame_is_intra_only(cm)) { |
| 701 static const int kf_mode_index[] = { | 703 static const int kf_mode_index[] = { |
| 702 THR_DC /*DC_PRED*/, | 704 THR_DC /*DC_PRED*/, |
| 703 THR_V_PRED /*V_PRED*/, | 705 THR_V_PRED /*V_PRED*/, |
| 704 THR_H_PRED /*H_PRED*/, | 706 THR_H_PRED /*H_PRED*/, |
| 705 THR_D45_PRED /*D45_PRED*/, | 707 THR_D45_PRED /*D45_PRED*/, |
| 706 THR_D135_PRED /*D135_PRED*/, | 708 THR_D135_PRED /*D135_PRED*/, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 719 if (!frame_is_intra_only(cm)) { | 721 if (!frame_is_intra_only(cm)) { |
| 720 if (is_inter_block(mbmi)) { | 722 if (is_inter_block(mbmi)) { |
| 721 vp9_update_mv_count(cm, xd); | 723 vp9_update_mv_count(cm, xd); |
| 722 | 724 |
| 723 if (cm->interp_filter == SWITCHABLE) { | 725 if (cm->interp_filter == SWITCHABLE) { |
| 724 const int ctx = vp9_get_pred_context_switchable_interp(xd); | 726 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
| 725 ++cm->counts.switchable_interp[ctx][mbmi->interp_filter]; | 727 ++cm->counts.switchable_interp[ctx][mbmi->interp_filter]; |
| 726 } | 728 } |
| 727 } | 729 } |
| 728 | 730 |
| 729 rd_opt->comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff; | 731 counts->comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff; |
| 730 rd_opt->comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff; | 732 counts->comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff; |
| 731 rd_opt->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff; | 733 counts->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff; |
| 732 | 734 |
| 733 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) | 735 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) |
| 734 rd_opt->filter_diff[i] += ctx->best_filter_diff[i]; | 736 counts->filter_diff[i] += ctx->best_filter_diff[i]; |
| 737 } |
| 738 |
| 739 for (h = 0; h < y_mis; ++h) { |
| 740 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; |
| 741 for (w = 0; w < x_mis; ++w) { |
| 742 MV_REF *const mv = frame_mv + w; |
| 743 mv->ref_frame[0] = mi->src_mi->mbmi.ref_frame[0]; |
| 744 mv->ref_frame[1] = mi->src_mi->mbmi.ref_frame[1]; |
| 745 mv->mv[0].as_int = mi->src_mi->mbmi.mv[0].as_int; |
| 746 mv->mv[1].as_int = mi->src_mi->mbmi.mv[1].as_int; |
| 747 } |
| 735 } | 748 } |
| 736 } | 749 } |
| 737 | 750 |
| 738 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, | 751 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, |
| 739 int mi_row, int mi_col) { | 752 int mi_row, int mi_col) { |
| 740 uint8_t *const buffers[3] = {src->y_buffer, src->u_buffer, src->v_buffer }; | 753 uint8_t *const buffers[3] = {src->y_buffer, src->u_buffer, src->v_buffer }; |
| 741 const int strides[3] = {src->y_stride, src->uv_stride, src->uv_stride }; | 754 const int strides[3] = {src->y_stride, src->uv_stride, src->uv_stride }; |
| 742 int i; | 755 int i; |
| 743 | 756 |
| 744 // Set current frame pointer. | 757 // Set current frame pointer. |
| 745 x->e_mbd.cur_buf = src; | 758 x->e_mbd.cur_buf = src; |
| 746 | 759 |
| 747 for (i = 0; i < MAX_MB_PLANE; i++) | 760 for (i = 0; i < MAX_MB_PLANE; i++) |
| 748 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mi_row, mi_col, | 761 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mi_row, mi_col, |
| 749 NULL, x->e_mbd.plane[i].subsampling_x, | 762 NULL, x->e_mbd.plane[i].subsampling_x, |
| 750 x->e_mbd.plane[i].subsampling_y); | 763 x->e_mbd.plane[i].subsampling_y); |
| 751 } | 764 } |
| 752 | 765 |
| 753 static void set_mode_info_seg_skip(MACROBLOCK *x, TX_MODE tx_mode, int *rate, | 766 static void set_mode_info_seg_skip(MACROBLOCK *x, TX_MODE tx_mode, |
| 754 int64_t *dist, BLOCK_SIZE bsize) { | 767 RD_COST *rd_cost, BLOCK_SIZE bsize) { |
| 755 MACROBLOCKD *const xd = &x->e_mbd; | 768 MACROBLOCKD *const xd = &x->e_mbd; |
| 756 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 769 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 757 INTERP_FILTER filter_ref; | 770 INTERP_FILTER filter_ref; |
| 758 | 771 |
| 759 if (xd->up_available) | 772 if (xd->up_available) |
| 760 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; | 773 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; |
| 761 else if (xd->left_available) | 774 else if (xd->left_available) |
| 762 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter; | 775 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter; |
| 763 else | 776 else |
| 764 filter_ref = EIGHTTAP; | 777 filter_ref = EIGHTTAP; |
| 765 | 778 |
| 766 mbmi->sb_type = bsize; | 779 mbmi->sb_type = bsize; |
| 767 mbmi->mode = ZEROMV; | 780 mbmi->mode = ZEROMV; |
| 768 mbmi->tx_size = MIN(max_txsize_lookup[bsize], | 781 mbmi->tx_size = MIN(max_txsize_lookup[bsize], |
| 769 tx_mode_to_biggest_tx_size[tx_mode]); | 782 tx_mode_to_biggest_tx_size[tx_mode]); |
| 770 mbmi->skip = 1; | 783 mbmi->skip = 1; |
| 771 mbmi->uv_mode = DC_PRED; | 784 mbmi->uv_mode = DC_PRED; |
| 772 mbmi->ref_frame[0] = LAST_FRAME; | 785 mbmi->ref_frame[0] = LAST_FRAME; |
| 773 mbmi->ref_frame[1] = NONE; | 786 mbmi->ref_frame[1] = NONE; |
| 774 mbmi->mv[0].as_int = 0; | 787 mbmi->mv[0].as_int = 0; |
| 775 mbmi->interp_filter = filter_ref; | 788 mbmi->interp_filter = filter_ref; |
| 776 | 789 |
| 777 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = 0; | 790 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = 0; |
| 778 x->skip = 1; | 791 x->skip = 1; |
| 779 | 792 |
| 780 *rate = 0; | 793 vp9_rd_cost_init(rd_cost); |
| 781 *dist = 0; | |
| 782 } | 794 } |
| 783 | 795 |
| 784 static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, | 796 static void rd_pick_sb_modes(VP9_COMP *cpi, |
| 797 TileDataEnc *tile_data, |
| 785 int mi_row, int mi_col, RD_COST *rd_cost, | 798 int mi_row, int mi_col, RD_COST *rd_cost, |
| 786 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, | 799 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, |
| 787 int64_t best_rd) { | 800 int64_t best_rd) { |
| 788 VP9_COMMON *const cm = &cpi->common; | 801 VP9_COMMON *const cm = &cpi->common; |
| 802 TileInfo *const tile_info = &tile_data->tile_info; |
| 789 MACROBLOCK *const x = &cpi->mb; | 803 MACROBLOCK *const x = &cpi->mb; |
| 790 MACROBLOCKD *const xd = &x->e_mbd; | 804 MACROBLOCKD *const xd = &x->e_mbd; |
| 791 MB_MODE_INFO *mbmi; | 805 MB_MODE_INFO *mbmi; |
| 792 struct macroblock_plane *const p = x->plane; | 806 struct macroblock_plane *const p = x->plane; |
| 793 struct macroblockd_plane *const pd = xd->plane; | 807 struct macroblockd_plane *const pd = xd->plane; |
| 794 const AQ_MODE aq_mode = cpi->oxcf.aq_mode; | 808 const AQ_MODE aq_mode = cpi->oxcf.aq_mode; |
| 795 int i, orig_rdmult; | 809 int i, orig_rdmult; |
| 796 double rdmult_ratio; | |
| 797 | 810 |
| 798 vp9_clear_system_state(); | 811 vp9_clear_system_state(); |
| 799 rdmult_ratio = 1.0; // avoid uninitialized warnings | |
| 800 | 812 |
| 801 // Use the lower precision, but faster, 32x32 fdct for mode selection. | 813 // Use the lower precision, but faster, 32x32 fdct for mode selection. |
| 802 x->use_lp32x32fdct = 1; | 814 x->use_lp32x32fdct = 1; |
| 803 | 815 |
| 804 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 816 set_offsets(cpi, tile_info, mi_row, mi_col, bsize); |
| 805 mbmi = &xd->mi[0].src_mi->mbmi; | 817 mbmi = &xd->mi[0].src_mi->mbmi; |
| 806 mbmi->sb_type = bsize; | 818 mbmi->sb_type = bsize; |
| 807 | 819 |
| 808 for (i = 0; i < MAX_MB_PLANE; ++i) { | 820 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 809 p[i].coeff = ctx->coeff_pbuf[i][0]; | 821 p[i].coeff = ctx->coeff_pbuf[i][0]; |
| 810 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; | 822 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; |
| 811 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; | 823 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; |
| 812 p[i].eobs = ctx->eobs_pbuf[i][0]; | 824 p[i].eobs = ctx->eobs_pbuf[i][0]; |
| 813 } | 825 } |
| 814 ctx->is_coded = 0; | 826 ctx->is_coded = 0; |
| 815 ctx->skippable = 0; | 827 ctx->skippable = 0; |
| 828 ctx->pred_pixel_ready = 0; |
| 816 x->skip_recode = 0; | 829 x->skip_recode = 0; |
| 817 | 830 |
| 818 // Set to zero to make sure we do not use the previous encoded frame stats | 831 // Set to zero to make sure we do not use the previous encoded frame stats |
| 819 mbmi->skip = 0; | 832 mbmi->skip = 0; |
| 820 | 833 |
| 821 #if CONFIG_VP9_HIGHBITDEPTH | 834 #if CONFIG_VP9_HIGHBITDEPTH |
| 822 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 835 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 823 x->source_variance = | 836 x->source_variance = |
| 824 high_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize, xd->bd); | 837 high_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize, xd->bd); |
| 825 } else { | 838 } else { |
| 826 x->source_variance = | 839 x->source_variance = |
| 827 get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); | 840 get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); |
| 828 } | 841 } |
| 829 #else | 842 #else |
| 830 x->source_variance = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); | 843 x->source_variance = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); |
| 831 #endif // CONFIG_VP9_HIGHBITDEPTH | 844 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 832 | 845 |
| 833 // Save rdmult before it might be changed, so it can be restored later. | 846 // Save rdmult before it might be changed, so it can be restored later. |
| 834 orig_rdmult = x->rdmult; | 847 orig_rdmult = x->rdmult; |
| 835 | 848 |
| 836 if (aq_mode == VARIANCE_AQ) { | 849 if (aq_mode == VARIANCE_AQ) { |
| 837 const int energy = bsize <= BLOCK_16X16 ? x->mb_energy | 850 const int energy = bsize <= BLOCK_16X16 ? x->mb_energy |
| 838 : vp9_block_energy(cpi, x, bsize); | 851 : vp9_block_energy(cpi, x, bsize); |
| 852 int segment_qindex; |
| 839 if (cm->frame_type == KEY_FRAME || | 853 if (cm->frame_type == KEY_FRAME || |
| 840 cpi->refresh_alt_ref_frame || | 854 cpi->refresh_alt_ref_frame || |
| 841 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { | 855 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { |
| 842 mbmi->segment_id = vp9_vaq_segment_id(energy); | 856 mbmi->segment_id = vp9_vaq_segment_id(energy); |
| 843 } else { | 857 } else { |
| 844 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map | 858 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map |
| 845 : cm->last_frame_seg_map; | 859 : cm->last_frame_seg_map; |
| 846 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 860 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
| 847 } | 861 } |
| 848 | |
| 849 rdmult_ratio = vp9_vaq_rdmult_ratio(energy); | |
| 850 vp9_init_plane_quantizers(cpi, x); | 862 vp9_init_plane_quantizers(cpi, x); |
| 851 vp9_clear_system_state(); | 863 vp9_clear_system_state(); |
| 852 x->rdmult = (int)round(x->rdmult * rdmult_ratio); | 864 segment_qindex = vp9_get_qindex(&cm->seg, mbmi->segment_id, |
| 865 cm->base_qindex); |
| 866 x->rdmult = vp9_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q); |
| 853 } else if (aq_mode == COMPLEXITY_AQ) { | 867 } else if (aq_mode == COMPLEXITY_AQ) { |
| 854 const int mi_offset = mi_row * cm->mi_cols + mi_col; | 868 const int mi_offset = mi_row * cm->mi_cols + mi_col; |
| 855 unsigned char complexity = cpi->complexity_map[mi_offset]; | 869 unsigned char complexity = cpi->complexity_map[mi_offset]; |
| 856 const int is_edge = (mi_row <= 1) || (mi_row >= (cm->mi_rows - 2)) || | 870 const int is_edge = (mi_row <= 1) || (mi_row >= (cm->mi_rows - 2)) || |
| 857 (mi_col <= 1) || (mi_col >= (cm->mi_cols - 2)); | 871 (mi_col <= 1) || (mi_col >= (cm->mi_cols - 2)); |
| 858 if (!is_edge && (complexity > 128)) | 872 if (!is_edge && (complexity > 128)) |
| 859 x->rdmult += ((x->rdmult * (complexity - 128)) / 256); | 873 x->rdmult += ((x->rdmult * (complexity - 128)) / 256); |
| 860 } else if (aq_mode == CYCLIC_REFRESH_AQ) { | 874 } else if (aq_mode == CYCLIC_REFRESH_AQ) { |
| 861 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map | 875 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map |
| 862 : cm->last_frame_seg_map; | 876 : cm->last_frame_seg_map; |
| 863 // If segment 1, use rdmult for that segment. | 877 // If segment 1, use rdmult for that segment. |
| 864 if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) | 878 if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) |
| 865 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 879 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
| 866 } | 880 } |
| 867 | 881 |
| 868 // Find best coding mode & reconstruct the MB so it is available | 882 // Find best coding mode & reconstruct the MB so it is available |
| 869 // as a predictor for MBs that follow in the SB | 883 // as a predictor for MBs that follow in the SB |
| 870 if (frame_is_intra_only(cm)) { | 884 if (frame_is_intra_only(cm)) { |
| 871 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); | 885 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); |
| 872 } else { | 886 } else { |
| 873 if (bsize >= BLOCK_8X8) { | 887 if (bsize >= BLOCK_8X8) { |
| 874 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 888 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
| 875 vp9_rd_pick_inter_mode_sb_seg_skip(cpi, x, rd_cost, bsize, | 889 vp9_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize, |
| 876 ctx, best_rd); | 890 ctx, best_rd); |
| 877 else | 891 else |
| 878 vp9_rd_pick_inter_mode_sb(cpi, x, tile, mi_row, mi_col, | 892 vp9_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col, |
| 879 rd_cost, bsize, ctx, best_rd); | 893 rd_cost, bsize, ctx, best_rd); |
| 880 } else { | 894 } else { |
| 881 vp9_rd_pick_inter_mode_sub8x8(cpi, x, tile, mi_row, mi_col, rd_cost, | 895 vp9_rd_pick_inter_mode_sub8x8(cpi, tile_data, x, mi_row, mi_col, |
| 882 bsize, ctx, best_rd); | 896 rd_cost, bsize, ctx, best_rd); |
| 883 } | 897 } |
| 884 } | 898 } |
| 885 | 899 |
| 886 if (aq_mode == VARIANCE_AQ && rd_cost->rate != INT_MAX) { | |
| 887 vp9_clear_system_state(); | |
| 888 rd_cost->rate = (int)round(rd_cost->rate * rdmult_ratio); | |
| 889 rd_cost->rdcost = RDCOST(x->rdmult, x->rddiv, rd_cost->rate, rd_cost->dist); | |
| 890 } | |
| 891 | |
| 892 x->rdmult = orig_rdmult; | 900 x->rdmult = orig_rdmult; |
| 893 | 901 |
| 894 // TODO(jingning) The rate-distortion optimization flow needs to be | 902 // TODO(jingning) The rate-distortion optimization flow needs to be |
| 895 // refactored to provide proper exit/return handle. | 903 // refactored to provide proper exit/return handle. |
| 896 if (rd_cost->rate == INT_MAX) | 904 if (rd_cost->rate == INT_MAX) |
| 897 rd_cost->rdcost = INT64_MAX; | 905 rd_cost->rdcost = INT64_MAX; |
| 906 |
| 907 ctx->rate = rd_cost->rate; |
| 908 ctx->dist = rd_cost->dist; |
| 898 } | 909 } |
| 899 | 910 |
| 900 static void update_stats(VP9_COMMON *cm, const MACROBLOCK *x) { | 911 static void update_stats(VP9_COMMON *cm, const MACROBLOCK *x) { |
| 901 const MACROBLOCKD *const xd = &x->e_mbd; | 912 const MACROBLOCKD *const xd = &x->e_mbd; |
| 902 const MODE_INFO *const mi = xd->mi[0].src_mi; | 913 const MODE_INFO *const mi = xd->mi[0].src_mi; |
| 903 const MB_MODE_INFO *const mbmi = &mi->mbmi; | 914 const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 904 | 915 |
| 905 if (!frame_is_intra_only(cm)) { | 916 if (!frame_is_intra_only(cm)) { |
| 906 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 917 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
| 907 SEG_LVL_REF_FRAME); | 918 SEG_LVL_REF_FRAME); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 mi_8x8[index].src_mi->mbmi.sb_type = bsize; | 1165 mi_8x8[index].src_mi->mbmi.sb_type = bsize; |
| 1155 } | 1166 } |
| 1156 } | 1167 } |
| 1157 } else { | 1168 } else { |
| 1158 // Else this is a partial SB64. | 1169 // Else this is a partial SB64. |
| 1159 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining, | 1170 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining, |
| 1160 col8x8_remaining, bsize, mi_8x8); | 1171 col8x8_remaining, bsize, mi_8x8); |
| 1161 } | 1172 } |
| 1162 } | 1173 } |
| 1163 | 1174 |
| 1164 static void copy_partitioning(VP9_COMMON *cm, MODE_INFO *mi_8x8, | |
| 1165 MODE_INFO *prev_mi_8x8) { | |
| 1166 const int mis = cm->mi_stride; | |
| 1167 int block_row, block_col; | |
| 1168 | |
| 1169 for (block_row = 0; block_row < 8; ++block_row) { | |
| 1170 for (block_col = 0; block_col < 8; ++block_col) { | |
| 1171 MODE_INFO *const prev_mi = | |
| 1172 prev_mi_8x8[block_row * mis + block_col].src_mi; | |
| 1173 const BLOCK_SIZE sb_type = prev_mi ? prev_mi->mbmi.sb_type : 0; | |
| 1174 | |
| 1175 if (prev_mi) { | |
| 1176 const ptrdiff_t offset = prev_mi - cm->prev_mi; | |
| 1177 mi_8x8[block_row * mis + block_col].src_mi = cm->mi + offset; | |
| 1178 mi_8x8[block_row * mis + block_col].src_mi->mbmi.sb_type = sb_type; | |
| 1179 } | |
| 1180 } | |
| 1181 } | |
| 1182 } | |
| 1183 | |
| 1184 static void constrain_copy_partitioning(VP9_COMP *const cpi, | |
| 1185 const TileInfo *const tile, | |
| 1186 MODE_INFO *mi_8x8, | |
| 1187 MODE_INFO *prev_mi_8x8, | |
| 1188 int mi_row, int mi_col, | |
| 1189 BLOCK_SIZE bsize) { | |
| 1190 VP9_COMMON *const cm = &cpi->common; | |
| 1191 const int mis = cm->mi_stride; | |
| 1192 const int row8x8_remaining = tile->mi_row_end - mi_row; | |
| 1193 const int col8x8_remaining = tile->mi_col_end - mi_col; | |
| 1194 MODE_INFO *const mi_upper_left = cm->mi + mi_row * mis + mi_col; | |
| 1195 const int bh = num_8x8_blocks_high_lookup[bsize]; | |
| 1196 const int bw = num_8x8_blocks_wide_lookup[bsize]; | |
| 1197 int block_row, block_col; | |
| 1198 | |
| 1199 assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); | |
| 1200 | |
| 1201 // If the SB64 if it is all "in image". | |
| 1202 if ((col8x8_remaining >= MI_BLOCK_SIZE) && | |
| 1203 (row8x8_remaining >= MI_BLOCK_SIZE)) { | |
| 1204 for (block_row = 0; block_row < MI_BLOCK_SIZE; block_row += bh) { | |
| 1205 for (block_col = 0; block_col < MI_BLOCK_SIZE; block_col += bw) { | |
| 1206 const int index = block_row * mis + block_col; | |
| 1207 MODE_INFO *prev_mi = prev_mi_8x8[index].src_mi; | |
| 1208 const BLOCK_SIZE sb_type = prev_mi ? prev_mi->mbmi.sb_type : 0; | |
| 1209 // Use previous partition if block size is not larger than bsize. | |
| 1210 if (prev_mi && sb_type <= bsize) { | |
| 1211 int block_row2, block_col2; | |
| 1212 for (block_row2 = 0; block_row2 < bh; ++block_row2) { | |
| 1213 for (block_col2 = 0; block_col2 < bw; ++block_col2) { | |
| 1214 const int index2 = (block_row + block_row2) * mis + | |
| 1215 block_col + block_col2; | |
| 1216 prev_mi = prev_mi_8x8[index2].src_mi; | |
| 1217 if (prev_mi) { | |
| 1218 const ptrdiff_t offset = prev_mi - cm->prev_mi; | |
| 1219 mi_8x8[index2].src_mi = cm->mi + offset; | |
| 1220 mi_8x8[index2].src_mi->mbmi.sb_type = prev_mi->mbmi.sb_type; | |
| 1221 } | |
| 1222 } | |
| 1223 } | |
| 1224 } else { | |
| 1225 // Otherwise, use fixed partition of size bsize. | |
| 1226 mi_8x8[index].src_mi = mi_upper_left + index; | |
| 1227 mi_8x8[index].src_mi->mbmi.sb_type = bsize; | |
| 1228 } | |
| 1229 } | |
| 1230 } | |
| 1231 } else { | |
| 1232 // Else this is a partial SB64, copy previous partition. | |
| 1233 copy_partitioning(cm, mi_8x8, prev_mi_8x8); | |
| 1234 } | |
| 1235 } | |
| 1236 | |
| 1237 const struct { | 1175 const struct { |
| 1238 int row; | 1176 int row; |
| 1239 int col; | 1177 int col; |
| 1240 } coord_lookup[16] = { | 1178 } coord_lookup[16] = { |
| 1241 // 32x32 index = 0 | 1179 // 32x32 index = 0 |
| 1242 {0, 0}, {0, 2}, {2, 0}, {2, 2}, | 1180 {0, 0}, {0, 2}, {2, 0}, {2, 2}, |
| 1243 // 32x32 index = 1 | 1181 // 32x32 index = 1 |
| 1244 {0, 4}, {0, 6}, {2, 4}, {2, 6}, | 1182 {0, 4}, {0, 6}, {2, 4}, {2, 6}, |
| 1245 // 32x32 index = 2 | 1183 // 32x32 index = 2 |
| 1246 {4, 0}, {4, 2}, {6, 0}, {6, 2}, | 1184 {4, 0}, {4, 2}, {6, 0}, {6, 2}, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 } | 1265 } |
| 1328 } | 1266 } |
| 1329 } else { // partial in-image SB64 | 1267 } else { // partial in-image SB64 |
| 1330 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; | 1268 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; |
| 1331 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; | 1269 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; |
| 1332 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, | 1270 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, |
| 1333 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8); | 1271 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8); |
| 1334 } | 1272 } |
| 1335 } | 1273 } |
| 1336 | 1274 |
| 1337 static int is_background(const VP9_COMP *cpi, const TileInfo *const tile, | |
| 1338 int mi_row, int mi_col) { | |
| 1339 // This assumes the input source frames are of the same dimension. | |
| 1340 const int row8x8_remaining = tile->mi_row_end - mi_row; | |
| 1341 const int col8x8_remaining = tile->mi_col_end - mi_col; | |
| 1342 const int x = mi_col * MI_SIZE; | |
| 1343 const int y = mi_row * MI_SIZE; | |
| 1344 const int src_stride = cpi->Source->y_stride; | |
| 1345 const uint8_t *const src = &cpi->Source->y_buffer[y * src_stride + x]; | |
| 1346 const int pre_stride = cpi->Last_Source->y_stride; | |
| 1347 const uint8_t *const pre = &cpi->Last_Source->y_buffer[y * pre_stride + x]; | |
| 1348 int this_sad = 0; | |
| 1349 int threshold = 0; | |
| 1350 | |
| 1351 if (row8x8_remaining >= MI_BLOCK_SIZE && | |
| 1352 col8x8_remaining >= MI_BLOCK_SIZE) { | |
| 1353 this_sad = cpi->fn_ptr[BLOCK_64X64].sdf(src, src_stride, pre, pre_stride); | |
| 1354 threshold = (1 << 12); | |
| 1355 } else { | |
| 1356 int r, c; | |
| 1357 for (r = 0; r < row8x8_remaining; r += 2) | |
| 1358 for (c = 0; c < col8x8_remaining; c += 2) | |
| 1359 this_sad += cpi->fn_ptr[BLOCK_16X16].sdf(src, src_stride, | |
| 1360 pre, pre_stride); | |
| 1361 threshold = (row8x8_remaining * col8x8_remaining) << 6; | |
| 1362 } | |
| 1363 | |
| 1364 return this_sad < 2 * threshold; | |
| 1365 } | |
| 1366 | |
| 1367 static int sb_has_motion(const VP9_COMMON *cm, MODE_INFO *prev_mi_8x8, | |
| 1368 const int motion_thresh) { | |
| 1369 const int mis = cm->mi_stride; | |
| 1370 int block_row, block_col; | |
| 1371 | |
| 1372 if (cm->prev_mi) { | |
| 1373 for (block_row = 0; block_row < 8; ++block_row) { | |
| 1374 for (block_col = 0; block_col < 8; ++block_col) { | |
| 1375 const MODE_INFO *prev_mi = | |
| 1376 prev_mi_8x8[block_row * mis + block_col].src_mi; | |
| 1377 if (prev_mi) { | |
| 1378 if (abs(prev_mi->mbmi.mv[0].as_mv.row) > motion_thresh || | |
| 1379 abs(prev_mi->mbmi.mv[0].as_mv.col) > motion_thresh) | |
| 1380 return 1; | |
| 1381 } | |
| 1382 } | |
| 1383 } | |
| 1384 } | |
| 1385 return 0; | |
| 1386 } | |
| 1387 | |
| 1388 static void update_state_rt(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, | 1275 static void update_state_rt(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
| 1389 int mi_row, int mi_col, int bsize) { | 1276 int mi_row, int mi_col, int bsize) { |
| 1390 VP9_COMMON *const cm = &cpi->common; | 1277 VP9_COMMON *const cm = &cpi->common; |
| 1391 MACROBLOCK *const x = &cpi->mb; | 1278 MACROBLOCK *const x = &cpi->mb; |
| 1392 MACROBLOCKD *const xd = &x->e_mbd; | 1279 MACROBLOCKD *const xd = &x->e_mbd; |
| 1280 MODE_INFO *const mi = xd->mi[0].src_mi; |
| 1393 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 1281 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 1394 const struct segmentation *const seg = &cm->seg; | 1282 const struct segmentation *const seg = &cm->seg; |
| 1283 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; |
| 1284 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; |
| 1285 const int x_mis = MIN(bw, cm->mi_cols - mi_col); |
| 1286 const int y_mis = MIN(bh, cm->mi_rows - mi_row); |
| 1287 MV_REF *const frame_mvs = |
| 1288 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; |
| 1289 int w, h; |
| 1395 | 1290 |
| 1396 *(xd->mi[0].src_mi) = ctx->mic; | 1291 *(xd->mi[0].src_mi) = ctx->mic; |
| 1397 xd->mi[0].src_mi = &xd->mi[0]; | 1292 xd->mi[0].src_mi = &xd->mi[0]; |
| 1398 | 1293 |
| 1399 if (seg->enabled && cpi->oxcf.aq_mode) { | 1294 if (seg->enabled && cpi->oxcf.aq_mode) { |
| 1400 // For in frame complexity AQ or variance AQ, copy segment_id from | 1295 // For in frame complexity AQ or variance AQ, copy segment_id from |
| 1401 // segmentation_map. | 1296 // segmentation_map. |
| 1402 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ || | 1297 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ || |
| 1403 cpi->oxcf.aq_mode == VARIANCE_AQ ) { | 1298 cpi->oxcf.aq_mode == VARIANCE_AQ ) { |
| 1404 const uint8_t *const map = seg->update_map ? cpi->segmentation_map | 1299 const uint8_t *const map = seg->update_map ? cpi->segmentation_map |
| 1405 : cm->last_frame_seg_map; | 1300 : cm->last_frame_seg_map; |
| 1406 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 1301 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
| 1407 } else { | 1302 } else { |
| 1408 // Setting segmentation map for cyclic_refresh | 1303 // Setting segmentation map for cyclic_refresh |
| 1409 vp9_cyclic_refresh_update_segment(cpi, mbmi, mi_row, mi_col, bsize, 1); | 1304 vp9_cyclic_refresh_update_segment(cpi, mbmi, mi_row, mi_col, bsize, 1, |
| 1305 ctx->rate); |
| 1410 } | 1306 } |
| 1411 vp9_init_plane_quantizers(cpi, x); | 1307 vp9_init_plane_quantizers(cpi, x); |
| 1412 } | 1308 } |
| 1413 | 1309 |
| 1414 if (is_inter_block(mbmi)) { | 1310 if (is_inter_block(mbmi)) { |
| 1415 vp9_update_mv_count(cm, xd); | 1311 vp9_update_mv_count(cm, xd); |
| 1416 | 1312 |
| 1417 if (cm->interp_filter == SWITCHABLE) { | 1313 if (cm->interp_filter == SWITCHABLE) { |
| 1418 const int pred_ctx = vp9_get_pred_context_switchable_interp(xd); | 1314 const int pred_ctx = vp9_get_pred_context_switchable_interp(xd); |
| 1419 ++cm->counts.switchable_interp[pred_ctx][mbmi->interp_filter]; | 1315 ++cm->counts.switchable_interp[pred_ctx][mbmi->interp_filter]; |
| 1420 } | 1316 } |
| 1421 } | 1317 } |
| 1422 | 1318 |
| 1319 for (h = 0; h < y_mis; ++h) { |
| 1320 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; |
| 1321 for (w = 0; w < x_mis; ++w) { |
| 1322 MV_REF *const mv = frame_mv + w; |
| 1323 mv->ref_frame[0] = mi->src_mi->mbmi.ref_frame[0]; |
| 1324 mv->ref_frame[1] = mi->src_mi->mbmi.ref_frame[1]; |
| 1325 mv->mv[0].as_int = mi->src_mi->mbmi.mv[0].as_int; |
| 1326 mv->mv[1].as_int = mi->src_mi->mbmi.mv[1].as_int; |
| 1327 } |
| 1328 } |
| 1329 |
| 1423 x->skip = ctx->skip; | 1330 x->skip = ctx->skip; |
| 1424 x->skip_txfm[0] = mbmi->segment_id ? 0 : ctx->skip_txfm[0]; | 1331 x->skip_txfm[0] = mbmi->segment_id ? 0 : ctx->skip_txfm[0]; |
| 1425 } | 1332 } |
| 1426 | 1333 |
| 1427 static void encode_b_rt(VP9_COMP *cpi, const TileInfo *const tile, | 1334 static void encode_b_rt(VP9_COMP *cpi, const TileInfo *const tile, |
| 1428 TOKENEXTRA **tp, int mi_row, int mi_col, | 1335 TOKENEXTRA **tp, int mi_row, int mi_col, |
| 1429 int output_enabled, BLOCK_SIZE bsize, | 1336 int output_enabled, BLOCK_SIZE bsize, |
| 1430 PICK_MODE_CONTEXT *ctx) { | 1337 PICK_MODE_CONTEXT *ctx) { |
| 1431 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 1338 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1432 update_state_rt(cpi, ctx, mi_row, mi_col, bsize); | 1339 update_state_rt(cpi, ctx, mi_row, mi_col, bsize); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1509 break; | 1416 break; |
| 1510 default: | 1417 default: |
| 1511 assert("Invalid partition type."); | 1418 assert("Invalid partition type."); |
| 1512 break; | 1419 break; |
| 1513 } | 1420 } |
| 1514 | 1421 |
| 1515 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 1422 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
| 1516 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 1423 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
| 1517 } | 1424 } |
| 1518 | 1425 |
| 1519 static void rd_use_partition(VP9_COMP *cpi, const TileInfo *const tile, | 1426 static void rd_use_partition(VP9_COMP *cpi, |
| 1427 TileDataEnc *tile_data, |
| 1520 MODE_INFO *mi_8x8, TOKENEXTRA **tp, | 1428 MODE_INFO *mi_8x8, TOKENEXTRA **tp, |
| 1521 int mi_row, int mi_col, | 1429 int mi_row, int mi_col, |
| 1522 BLOCK_SIZE bsize, int *rate, int64_t *dist, | 1430 BLOCK_SIZE bsize, |
| 1431 int *rate, int64_t *dist, |
| 1523 int do_recon, PC_TREE *pc_tree) { | 1432 int do_recon, PC_TREE *pc_tree) { |
| 1524 VP9_COMMON *const cm = &cpi->common; | 1433 VP9_COMMON *const cm = &cpi->common; |
| 1434 TileInfo *const tile_info = &tile_data->tile_info; |
| 1525 MACROBLOCK *const x = &cpi->mb; | 1435 MACROBLOCK *const x = &cpi->mb; |
| 1526 MACROBLOCKD *const xd = &x->e_mbd; | 1436 MACROBLOCKD *const xd = &x->e_mbd; |
| 1527 const int mis = cm->mi_stride; | 1437 const int mis = cm->mi_stride; |
| 1528 const int bsl = b_width_log2_lookup[bsize]; | 1438 const int bsl = b_width_log2_lookup[bsize]; |
| 1529 const int mi_step = num_4x4_blocks_wide_lookup[bsize] / 2; | 1439 const int mi_step = num_4x4_blocks_wide_lookup[bsize] / 2; |
| 1530 const int bss = (1 << bsl) / 4; | 1440 const int bss = (1 << bsl) / 4; |
| 1531 int i, pl; | 1441 int i, pl; |
| 1532 PARTITION_TYPE partition = PARTITION_NONE; | 1442 PARTITION_TYPE partition = PARTITION_NONE; |
| 1533 BLOCK_SIZE subsize; | 1443 BLOCK_SIZE subsize; |
| 1534 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1444 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1550 vp9_rd_cost_reset(&none_rdc); | 1460 vp9_rd_cost_reset(&none_rdc); |
| 1551 vp9_rd_cost_reset(&chosen_rdc); | 1461 vp9_rd_cost_reset(&chosen_rdc); |
| 1552 | 1462 |
| 1553 partition = partition_lookup[bsl][bs_type]; | 1463 partition = partition_lookup[bsl][bs_type]; |
| 1554 subsize = get_subsize(bsize, partition); | 1464 subsize = get_subsize(bsize, partition); |
| 1555 | 1465 |
| 1556 pc_tree->partitioning = partition; | 1466 pc_tree->partitioning = partition; |
| 1557 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1467 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1558 | 1468 |
| 1559 if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) { | 1469 if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) { |
| 1560 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 1470 set_offsets(cpi, tile_info, mi_row, mi_col, bsize); |
| 1561 x->mb_energy = vp9_block_energy(cpi, x, bsize); | 1471 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 1562 } | 1472 } |
| 1563 | 1473 |
| 1564 if (do_partition_search && | 1474 if (do_partition_search && |
| 1565 cpi->sf.partition_search_type == SEARCH_PARTITION && | 1475 cpi->sf.partition_search_type == SEARCH_PARTITION && |
| 1566 cpi->sf.adjust_partitioning_from_last_frame) { | 1476 cpi->sf.adjust_partitioning_from_last_frame) { |
| 1567 // Check if any of the sub blocks are further split. | 1477 // Check if any of the sub blocks are further split. |
| 1568 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { | 1478 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { |
| 1569 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); | 1479 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); |
| 1570 splits_below = 1; | 1480 splits_below = 1; |
| 1571 for (i = 0; i < 4; i++) { | 1481 for (i = 0; i < 4; i++) { |
| 1572 int jj = i >> 1, ii = i & 0x01; | 1482 int jj = i >> 1, ii = i & 0x01; |
| 1573 MODE_INFO *this_mi = mi_8x8[jj * bss * mis + ii * bss].src_mi; | 1483 MODE_INFO *this_mi = mi_8x8[jj * bss * mis + ii * bss].src_mi; |
| 1574 if (this_mi && this_mi->mbmi.sb_type >= sub_subsize) { | 1484 if (this_mi && this_mi->mbmi.sb_type >= sub_subsize) { |
| 1575 splits_below = 0; | 1485 splits_below = 0; |
| 1576 } | 1486 } |
| 1577 } | 1487 } |
| 1578 } | 1488 } |
| 1579 | 1489 |
| 1580 // If partition is not none try none unless each of the 4 splits are split | 1490 // If partition is not none try none unless each of the 4 splits are split |
| 1581 // even further.. | 1491 // even further.. |
| 1582 if (partition != PARTITION_NONE && !splits_below && | 1492 if (partition != PARTITION_NONE && !splits_below && |
| 1583 mi_row + (mi_step >> 1) < cm->mi_rows && | 1493 mi_row + (mi_step >> 1) < cm->mi_rows && |
| 1584 mi_col + (mi_step >> 1) < cm->mi_cols) { | 1494 mi_col + (mi_step >> 1) < cm->mi_cols) { |
| 1585 pc_tree->partitioning = PARTITION_NONE; | 1495 pc_tree->partitioning = PARTITION_NONE; |
| 1586 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &none_rdc, bsize, | 1496 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &none_rdc, bsize, |
| 1587 ctx, INT64_MAX); | 1497 ctx, INT64_MAX); |
| 1588 | 1498 |
| 1589 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 1499 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 1590 | 1500 |
| 1591 if (none_rdc.rate < INT_MAX) { | 1501 if (none_rdc.rate < INT_MAX) { |
| 1592 none_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; | 1502 none_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 1593 none_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, none_rdc.rate, | 1503 none_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, none_rdc.rate, |
| 1594 none_rdc.dist); | 1504 none_rdc.dist); |
| 1595 } | 1505 } |
| 1596 | 1506 |
| 1597 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1507 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1598 mi_8x8[0].src_mi->mbmi.sb_type = bs_type; | 1508 mi_8x8[0].src_mi->mbmi.sb_type = bs_type; |
| 1599 pc_tree->partitioning = partition; | 1509 pc_tree->partitioning = partition; |
| 1600 } | 1510 } |
| 1601 } | 1511 } |
| 1602 | 1512 |
| 1603 switch (partition) { | 1513 switch (partition) { |
| 1604 case PARTITION_NONE: | 1514 case PARTITION_NONE: |
| 1605 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rdc, | 1515 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &last_part_rdc, |
| 1606 bsize, ctx, INT64_MAX); | 1516 bsize, ctx, INT64_MAX); |
| 1607 break; | 1517 break; |
| 1608 case PARTITION_HORZ: | 1518 case PARTITION_HORZ: |
| 1609 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rdc, | 1519 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &last_part_rdc, |
| 1610 subsize, &pc_tree->horizontal[0], | 1520 subsize, &pc_tree->horizontal[0], |
| 1611 INT64_MAX); | 1521 INT64_MAX); |
| 1612 if (last_part_rdc.rate != INT_MAX && | 1522 if (last_part_rdc.rate != INT_MAX && |
| 1613 bsize >= BLOCK_8X8 && mi_row + (mi_step >> 1) < cm->mi_rows) { | 1523 bsize >= BLOCK_8X8 && mi_row + (mi_step >> 1) < cm->mi_rows) { |
| 1614 RD_COST tmp_rdc; | 1524 RD_COST tmp_rdc; |
| 1615 PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0]; | 1525 PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0]; |
| 1616 vp9_rd_cost_init(&tmp_rdc); | 1526 vp9_rd_cost_init(&tmp_rdc); |
| 1617 update_state(cpi, ctx, mi_row, mi_col, subsize, 0); | 1527 update_state(cpi, ctx, mi_row, mi_col, subsize, 0); |
| 1618 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); | 1528 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); |
| 1619 rd_pick_sb_modes(cpi, tile, mi_row + (mi_step >> 1), mi_col, &tmp_rdc, | 1529 rd_pick_sb_modes(cpi, tile_data, |
| 1530 mi_row + (mi_step >> 1), mi_col, &tmp_rdc, |
| 1620 subsize, &pc_tree->horizontal[1], INT64_MAX); | 1531 subsize, &pc_tree->horizontal[1], INT64_MAX); |
| 1621 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { | 1532 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
| 1622 vp9_rd_cost_reset(&last_part_rdc); | 1533 vp9_rd_cost_reset(&last_part_rdc); |
| 1623 break; | 1534 break; |
| 1624 } | 1535 } |
| 1625 last_part_rdc.rate += tmp_rdc.rate; | 1536 last_part_rdc.rate += tmp_rdc.rate; |
| 1626 last_part_rdc.dist += tmp_rdc.dist; | 1537 last_part_rdc.dist += tmp_rdc.dist; |
| 1627 last_part_rdc.rdcost += tmp_rdc.rdcost; | 1538 last_part_rdc.rdcost += tmp_rdc.rdcost; |
| 1628 } | 1539 } |
| 1629 break; | 1540 break; |
| 1630 case PARTITION_VERT: | 1541 case PARTITION_VERT: |
| 1631 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rdc, | 1542 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &last_part_rdc, |
| 1632 subsize, &pc_tree->vertical[0], INT64_MAX); | 1543 subsize, &pc_tree->vertical[0], INT64_MAX); |
| 1633 if (last_part_rdc.rate != INT_MAX && | 1544 if (last_part_rdc.rate != INT_MAX && |
| 1634 bsize >= BLOCK_8X8 && mi_col + (mi_step >> 1) < cm->mi_cols) { | 1545 bsize >= BLOCK_8X8 && mi_col + (mi_step >> 1) < cm->mi_cols) { |
| 1635 RD_COST tmp_rdc; | 1546 RD_COST tmp_rdc; |
| 1636 PICK_MODE_CONTEXT *ctx = &pc_tree->vertical[0]; | 1547 PICK_MODE_CONTEXT *ctx = &pc_tree->vertical[0]; |
| 1637 vp9_rd_cost_init(&tmp_rdc); | 1548 vp9_rd_cost_init(&tmp_rdc); |
| 1638 update_state(cpi, ctx, mi_row, mi_col, subsize, 0); | 1549 update_state(cpi, ctx, mi_row, mi_col, subsize, 0); |
| 1639 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); | 1550 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); |
| 1640 rd_pick_sb_modes(cpi, tile, mi_row, mi_col + (mi_step >> 1), &tmp_rdc, | 1551 rd_pick_sb_modes(cpi, tile_data, |
| 1552 mi_row, mi_col + (mi_step >> 1), &tmp_rdc, |
| 1641 subsize, &pc_tree->vertical[bsize > BLOCK_8X8], | 1553 subsize, &pc_tree->vertical[bsize > BLOCK_8X8], |
| 1642 INT64_MAX); | 1554 INT64_MAX); |
| 1643 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { | 1555 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
| 1644 vp9_rd_cost_reset(&last_part_rdc); | 1556 vp9_rd_cost_reset(&last_part_rdc); |
| 1645 break; | 1557 break; |
| 1646 } | 1558 } |
| 1647 last_part_rdc.rate += tmp_rdc.rate; | 1559 last_part_rdc.rate += tmp_rdc.rate; |
| 1648 last_part_rdc.dist += tmp_rdc.dist; | 1560 last_part_rdc.dist += tmp_rdc.dist; |
| 1649 last_part_rdc.rdcost += tmp_rdc.rdcost; | 1561 last_part_rdc.rdcost += tmp_rdc.rdcost; |
| 1650 } | 1562 } |
| 1651 break; | 1563 break; |
| 1652 case PARTITION_SPLIT: | 1564 case PARTITION_SPLIT: |
| 1653 if (bsize == BLOCK_8X8) { | 1565 if (bsize == BLOCK_8X8) { |
| 1654 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rdc, | 1566 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &last_part_rdc, |
| 1655 subsize, pc_tree->leaf_split[0], INT64_MAX); | 1567 subsize, pc_tree->leaf_split[0], INT64_MAX); |
| 1656 break; | 1568 break; |
| 1657 } | 1569 } |
| 1658 last_part_rdc.rate = 0; | 1570 last_part_rdc.rate = 0; |
| 1659 last_part_rdc.dist = 0; | 1571 last_part_rdc.dist = 0; |
| 1660 last_part_rdc.rdcost = 0; | 1572 last_part_rdc.rdcost = 0; |
| 1661 for (i = 0; i < 4; i++) { | 1573 for (i = 0; i < 4; i++) { |
| 1662 int x_idx = (i & 1) * (mi_step >> 1); | 1574 int x_idx = (i & 1) * (mi_step >> 1); |
| 1663 int y_idx = (i >> 1) * (mi_step >> 1); | 1575 int y_idx = (i >> 1) * (mi_step >> 1); |
| 1664 int jj = i >> 1, ii = i & 0x01; | 1576 int jj = i >> 1, ii = i & 0x01; |
| 1665 RD_COST tmp_rdc; | 1577 RD_COST tmp_rdc; |
| 1666 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | 1578 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
| 1667 continue; | 1579 continue; |
| 1668 | 1580 |
| 1669 vp9_rd_cost_init(&tmp_rdc); | 1581 vp9_rd_cost_init(&tmp_rdc); |
| 1670 rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, | 1582 rd_use_partition(cpi, tile_data, |
| 1583 mi_8x8 + jj * bss * mis + ii * bss, tp, |
| 1671 mi_row + y_idx, mi_col + x_idx, subsize, | 1584 mi_row + y_idx, mi_col + x_idx, subsize, |
| 1672 &tmp_rdc.rate, &tmp_rdc.dist, | 1585 &tmp_rdc.rate, &tmp_rdc.dist, |
| 1673 i != 3, pc_tree->split[i]); | 1586 i != 3, pc_tree->split[i]); |
| 1674 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { | 1587 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
| 1675 vp9_rd_cost_reset(&last_part_rdc); | 1588 vp9_rd_cost_reset(&last_part_rdc); |
| 1676 break; | 1589 break; |
| 1677 } | 1590 } |
| 1678 last_part_rdc.rate += tmp_rdc.rate; | 1591 last_part_rdc.rate += tmp_rdc.rate; |
| 1679 last_part_rdc.dist += tmp_rdc.dist; | 1592 last_part_rdc.dist += tmp_rdc.dist; |
| 1680 } | 1593 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1711 int y_idx = (i >> 1) * (mi_step >> 1); | 1624 int y_idx = (i >> 1) * (mi_step >> 1); |
| 1712 RD_COST tmp_rdc; | 1625 RD_COST tmp_rdc; |
| 1713 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1626 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
| 1714 PARTITION_CONTEXT sl[8], sa[8]; | 1627 PARTITION_CONTEXT sl[8], sa[8]; |
| 1715 | 1628 |
| 1716 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | 1629 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
| 1717 continue; | 1630 continue; |
| 1718 | 1631 |
| 1719 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1632 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1720 pc_tree->split[i]->partitioning = PARTITION_NONE; | 1633 pc_tree->split[i]->partitioning = PARTITION_NONE; |
| 1721 rd_pick_sb_modes(cpi, tile, mi_row + y_idx, mi_col + x_idx, &tmp_rdc, | 1634 rd_pick_sb_modes(cpi, tile_data, |
| 1635 mi_row + y_idx, mi_col + x_idx, &tmp_rdc, |
| 1722 split_subsize, &pc_tree->split[i]->none, INT64_MAX); | 1636 split_subsize, &pc_tree->split[i]->none, INT64_MAX); |
| 1723 | 1637 |
| 1724 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1638 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1725 | 1639 |
| 1726 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { | 1640 if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { |
| 1727 vp9_rd_cost_reset(&chosen_rdc); | 1641 vp9_rd_cost_reset(&chosen_rdc); |
| 1728 break; | 1642 break; |
| 1729 } | 1643 } |
| 1730 | 1644 |
| 1731 chosen_rdc.rate += tmp_rdc.rate; | 1645 chosen_rdc.rate += tmp_rdc.rate; |
| 1732 chosen_rdc.dist += tmp_rdc.dist; | 1646 chosen_rdc.dist += tmp_rdc.dist; |
| 1733 | 1647 |
| 1734 if (i != 3) | 1648 if (i != 3) |
| 1735 encode_sb(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, 0, | 1649 encode_sb(cpi, tile_info, tp, mi_row + y_idx, mi_col + x_idx, 0, |
| 1736 split_subsize, pc_tree->split[i]); | 1650 split_subsize, pc_tree->split[i]); |
| 1737 | 1651 |
| 1738 pl = partition_plane_context(xd, mi_row + y_idx, mi_col + x_idx, | 1652 pl = partition_plane_context(xd, mi_row + y_idx, mi_col + x_idx, |
| 1739 split_subsize); | 1653 split_subsize); |
| 1740 chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; | 1654 chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 1741 } | 1655 } |
| 1742 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 1656 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 1743 if (chosen_rdc.rate < INT_MAX) { | 1657 if (chosen_rdc.rate < INT_MAX) { |
| 1744 chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT]; | 1658 chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT]; |
| 1745 chosen_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, | 1659 chosen_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1768 if (bsize == BLOCK_64X64) | 1682 if (bsize == BLOCK_64X64) |
| 1769 assert(chosen_rdc.rate < INT_MAX && chosen_rdc.dist < INT64_MAX); | 1683 assert(chosen_rdc.rate < INT_MAX && chosen_rdc.dist < INT64_MAX); |
| 1770 | 1684 |
| 1771 if (do_recon) { | 1685 if (do_recon) { |
| 1772 int output_enabled = (bsize == BLOCK_64X64); | 1686 int output_enabled = (bsize == BLOCK_64X64); |
| 1773 | 1687 |
| 1774 // Check the projected output rate for this SB against it's target | 1688 // Check the projected output rate for this SB against it's target |
| 1775 // and and if necessary apply a Q delta using segmentation to get | 1689 // and and if necessary apply a Q delta using segmentation to get |
| 1776 // closer to the target. | 1690 // closer to the target. |
| 1777 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { | 1691 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { |
| 1778 vp9_select_in_frame_q_segment(cpi, mi_row, mi_col, | 1692 vp9_select_in_frame_q_segment(cpi, bsize, mi_row, mi_col, |
| 1779 output_enabled, chosen_rdc.rate); | 1693 output_enabled, chosen_rdc.rate); |
| 1780 } | 1694 } |
| 1781 | 1695 encode_sb(cpi, tile_info, tp, mi_row, mi_col, output_enabled, bsize, |
| 1782 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) | |
| 1783 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, | |
| 1784 chosen_rdc.rate, chosen_rdc.dist); | |
| 1785 encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize, | |
| 1786 pc_tree); | 1696 pc_tree); |
| 1787 } | 1697 } |
| 1788 | 1698 |
| 1789 *rate = chosen_rdc.rate; | 1699 *rate = chosen_rdc.rate; |
| 1790 *dist = chosen_rdc.dist; | 1700 *dist = chosen_rdc.dist; |
| 1791 } | 1701 } |
| 1792 | 1702 |
| 1793 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { | 1703 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { |
| 1794 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, | 1704 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, |
| 1795 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, | 1705 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2108 return 0; | 2018 return 0; |
| 2109 } else { | 2019 } else { |
| 2110 return abs(this_mv - that_mv) == 2 ? 2 : 1; | 2020 return abs(this_mv - that_mv) == 2 ? 2 : 1; |
| 2111 } | 2021 } |
| 2112 } | 2022 } |
| 2113 #endif | 2023 #endif |
| 2114 | 2024 |
| 2115 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 2025 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
| 2116 // unlikely to be selected depending on previous rate-distortion optimization | 2026 // unlikely to be selected depending on previous rate-distortion optimization |
| 2117 // results, for encoding speed-up. | 2027 // results, for encoding speed-up. |
| 2118 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, | 2028 static void rd_pick_partition(VP9_COMP *cpi, |
| 2029 TileDataEnc *tile_data, |
| 2119 TOKENEXTRA **tp, int mi_row, int mi_col, | 2030 TOKENEXTRA **tp, int mi_row, int mi_col, |
| 2120 BLOCK_SIZE bsize, RD_COST *rd_cost, | 2031 BLOCK_SIZE bsize, RD_COST *rd_cost, |
| 2121 int64_t best_rd, PC_TREE *pc_tree) { | 2032 int64_t best_rd, PC_TREE *pc_tree) { |
| 2122 VP9_COMMON *const cm = &cpi->common; | 2033 VP9_COMMON *const cm = &cpi->common; |
| 2034 TileInfo *const tile_info = &tile_data->tile_info; |
| 2123 MACROBLOCK *const x = &cpi->mb; | 2035 MACROBLOCK *const x = &cpi->mb; |
| 2124 MACROBLOCKD *const xd = &x->e_mbd; | 2036 MACROBLOCKD *const xd = &x->e_mbd; |
| 2125 const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2; | 2037 const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2; |
| 2126 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 2038 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
| 2127 PARTITION_CONTEXT sl[8], sa[8]; | 2039 PARTITION_CONTEXT sl[8], sa[8]; |
| 2128 TOKENEXTRA *tp_orig = *tp; | 2040 TOKENEXTRA *tp_orig = *tp; |
| 2129 PICK_MODE_CONTEXT *ctx = &pc_tree->none; | 2041 PICK_MODE_CONTEXT *ctx = &pc_tree->none; |
| 2130 int i, pl; | 2042 int i, pl; |
| 2131 BLOCK_SIZE subsize; | 2043 BLOCK_SIZE subsize; |
| 2132 RD_COST this_rdc, sum_rdc, best_rdc; | 2044 RD_COST this_rdc, sum_rdc, best_rdc; |
| 2133 int do_split = bsize >= BLOCK_8X8; | 2045 int do_split = bsize >= BLOCK_8X8; |
| 2134 int do_rect = 1; | 2046 int do_rect = 1; |
| 2135 | 2047 |
| 2136 // Override skipping rectangular partition operations for edge blocks | 2048 // Override skipping rectangular partition operations for edge blocks |
| 2137 const int force_horz_split = (mi_row + mi_step >= cm->mi_rows); | 2049 const int force_horz_split = (mi_row + mi_step >= cm->mi_rows); |
| 2138 const int force_vert_split = (mi_col + mi_step >= cm->mi_cols); | 2050 const int force_vert_split = (mi_col + mi_step >= cm->mi_cols); |
| 2139 const int xss = x->e_mbd.plane[1].subsampling_x; | 2051 const int xss = x->e_mbd.plane[1].subsampling_x; |
| 2140 const int yss = x->e_mbd.plane[1].subsampling_y; | 2052 const int yss = x->e_mbd.plane[1].subsampling_y; |
| 2141 | 2053 |
| 2142 BLOCK_SIZE min_size = cpi->sf.min_partition_size; | 2054 BLOCK_SIZE min_size = x->min_partition_size; |
| 2143 BLOCK_SIZE max_size = cpi->sf.max_partition_size; | 2055 BLOCK_SIZE max_size = x->max_partition_size; |
| 2144 | 2056 |
| 2145 #if CONFIG_FP_MB_STATS | 2057 #if CONFIG_FP_MB_STATS |
| 2146 unsigned int src_diff_var = UINT_MAX; | 2058 unsigned int src_diff_var = UINT_MAX; |
| 2147 int none_complexity = 0; | 2059 int none_complexity = 0; |
| 2148 #endif | 2060 #endif |
| 2149 | 2061 |
| 2150 int partition_none_allowed = !force_horz_split && !force_vert_split; | 2062 int partition_none_allowed = !force_horz_split && !force_vert_split; |
| 2151 int partition_horz_allowed = !force_vert_split && yss <= xss && | 2063 int partition_horz_allowed = !force_vert_split && yss <= xss && |
| 2152 bsize >= BLOCK_8X8; | 2064 bsize >= BLOCK_8X8; |
| 2153 int partition_vert_allowed = !force_horz_split && xss <= yss && | 2065 int partition_vert_allowed = !force_horz_split && xss <= yss && |
| 2154 bsize >= BLOCK_8X8; | 2066 bsize >= BLOCK_8X8; |
| 2155 (void) *tp_orig; | 2067 (void) *tp_orig; |
| 2156 | 2068 |
| 2157 assert(num_8x8_blocks_wide_lookup[bsize] == | 2069 assert(num_8x8_blocks_wide_lookup[bsize] == |
| 2158 num_8x8_blocks_high_lookup[bsize]); | 2070 num_8x8_blocks_high_lookup[bsize]); |
| 2159 | 2071 |
| 2160 vp9_rd_cost_init(&this_rdc); | 2072 vp9_rd_cost_init(&this_rdc); |
| 2161 vp9_rd_cost_init(&sum_rdc); | 2073 vp9_rd_cost_init(&sum_rdc); |
| 2162 vp9_rd_cost_reset(&best_rdc); | 2074 vp9_rd_cost_reset(&best_rdc); |
| 2163 best_rdc.rdcost = best_rd; | 2075 best_rdc.rdcost = best_rd; |
| 2164 | 2076 |
| 2165 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 2077 set_offsets(cpi, tile_info, mi_row, mi_col, bsize); |
| 2166 | 2078 |
| 2167 if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) | 2079 if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) |
| 2168 x->mb_energy = vp9_block_energy(cpi, x, bsize); | 2080 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 2169 | 2081 |
| 2170 if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) { | 2082 if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) { |
| 2171 int cb_partition_search_ctrl = ((pc_tree->index == 0 || pc_tree->index == 3) | 2083 int cb_partition_search_ctrl = ((pc_tree->index == 0 || pc_tree->index == 3) |
| 2172 + get_chessboard_index(cm->current_video_frame)) & 0x1; | 2084 + get_chessboard_index(cm->current_video_frame)) & 0x1; |
| 2173 | 2085 |
| 2174 if (cb_partition_search_ctrl && bsize > min_size && bsize < max_size) | 2086 if (cb_partition_search_ctrl && bsize > min_size && bsize < max_size) |
| 2175 set_partition_range(cm, xd, mi_row, mi_col, bsize, &min_size, &max_size); | 2087 set_partition_range(cm, xd, mi_row, mi_col, bsize, &min_size, &max_size); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2187 } | 2099 } |
| 2188 if (cpi->sf.use_square_partition_only) { | 2100 if (cpi->sf.use_square_partition_only) { |
| 2189 partition_horz_allowed &= force_horz_split; | 2101 partition_horz_allowed &= force_horz_split; |
| 2190 partition_vert_allowed &= force_vert_split; | 2102 partition_vert_allowed &= force_vert_split; |
| 2191 } | 2103 } |
| 2192 | 2104 |
| 2193 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 2105 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 2194 | 2106 |
| 2195 #if CONFIG_FP_MB_STATS | 2107 #if CONFIG_FP_MB_STATS |
| 2196 if (cpi->use_fp_mb_stats) { | 2108 if (cpi->use_fp_mb_stats) { |
| 2197 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 2109 set_offsets(cpi, tile_info, mi_row, mi_col, bsize); |
| 2198 src_diff_var = get_sby_perpixel_diff_variance(cpi, &cpi->mb.plane[0].src, | 2110 src_diff_var = get_sby_perpixel_diff_variance(cpi, &cpi->mb.plane[0].src, |
| 2199 mi_row, mi_col, bsize); | 2111 mi_row, mi_col, bsize); |
| 2200 } | 2112 } |
| 2201 #endif | 2113 #endif |
| 2202 | 2114 |
| 2203 #if CONFIG_FP_MB_STATS | 2115 #if CONFIG_FP_MB_STATS |
| 2204 // Decide whether we shall split directly and skip searching NONE by using | 2116 // Decide whether we shall split directly and skip searching NONE by using |
| 2205 // the first pass block statistics | 2117 // the first pass block statistics |
| 2206 if (cpi->use_fp_mb_stats && bsize >= BLOCK_32X32 && do_split && | 2118 if (cpi->use_fp_mb_stats && bsize >= BLOCK_32X32 && do_split && |
| 2207 partition_none_allowed && src_diff_var > 4 && | 2119 partition_none_allowed && src_diff_var > 4 && |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2246 } | 2158 } |
| 2247 | 2159 |
| 2248 if (none_complexity > complexity_16x16_blocks_threshold[bsize]) { | 2160 if (none_complexity > complexity_16x16_blocks_threshold[bsize]) { |
| 2249 partition_none_allowed = 0; | 2161 partition_none_allowed = 0; |
| 2250 } | 2162 } |
| 2251 } | 2163 } |
| 2252 #endif | 2164 #endif |
| 2253 | 2165 |
| 2254 // PARTITION_NONE | 2166 // PARTITION_NONE |
| 2255 if (partition_none_allowed) { | 2167 if (partition_none_allowed) { |
| 2256 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rdc, bsize, ctx, | 2168 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, |
| 2257 best_rdc.rdcost); | 2169 &this_rdc, bsize, ctx, best_rdc.rdcost); |
| 2258 if (this_rdc.rate != INT_MAX) { | 2170 if (this_rdc.rate != INT_MAX) { |
| 2259 if (bsize >= BLOCK_8X8) { | 2171 if (bsize >= BLOCK_8X8) { |
| 2260 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2172 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2261 this_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; | 2173 this_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 2262 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, | 2174 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, |
| 2263 this_rdc.rate, this_rdc.dist); | 2175 this_rdc.rate, this_rdc.dist); |
| 2264 } | 2176 } |
| 2265 | 2177 |
| 2266 if (this_rdc.rdcost < best_rdc.rdcost) { | 2178 if (this_rdc.rdcost < best_rdc.rdcost) { |
| 2267 int64_t dist_breakout_thr = cpi->sf.partition_search_breakout_dist_thr; | 2179 int64_t dist_breakout_thr = cpi->sf.partition_search_breakout_dist_thr; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 skip = 0; | 2228 skip = 0; |
| 2317 break; | 2229 break; |
| 2318 } | 2230 } |
| 2319 } | 2231 } |
| 2320 if (skip == 0) { | 2232 if (skip == 0) { |
| 2321 break; | 2233 break; |
| 2322 } | 2234 } |
| 2323 } | 2235 } |
| 2324 if (skip) { | 2236 if (skip) { |
| 2325 if (src_diff_var == UINT_MAX) { | 2237 if (src_diff_var == UINT_MAX) { |
| 2326 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 2238 set_offsets(cpi, tile_info, mi_row, mi_col, bsize); |
| 2327 src_diff_var = get_sby_perpixel_diff_variance( | 2239 src_diff_var = get_sby_perpixel_diff_variance( |
| 2328 cpi, &cpi->mb.plane[0].src, mi_row, mi_col, bsize); | 2240 cpi, &cpi->mb.plane[0].src, mi_row, mi_col, bsize); |
| 2329 } | 2241 } |
| 2330 if (src_diff_var < 8) { | 2242 if (src_diff_var < 8) { |
| 2331 do_split = 0; | 2243 do_split = 0; |
| 2332 do_rect = 0; | 2244 do_rect = 0; |
| 2333 } | 2245 } |
| 2334 } | 2246 } |
| 2335 } | 2247 } |
| 2336 #endif | 2248 #endif |
| 2337 } | 2249 } |
| 2338 } | 2250 } |
| 2339 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 2251 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 2340 } | 2252 } |
| 2341 | 2253 |
| 2342 // store estimated motion vector | 2254 // store estimated motion vector |
| 2343 if (cpi->sf.adaptive_motion_search) | 2255 if (cpi->sf.adaptive_motion_search) |
| 2344 store_pred_mv(x, ctx); | 2256 store_pred_mv(x, ctx); |
| 2345 | 2257 |
| 2346 // PARTITION_SPLIT | 2258 // PARTITION_SPLIT |
| 2347 // TODO(jingning): use the motion vectors given by the above search as | 2259 // TODO(jingning): use the motion vectors given by the above search as |
| 2348 // the starting point of motion search in the following partition type check. | 2260 // the starting point of motion search in the following partition type check. |
| 2349 if (do_split) { | 2261 if (do_split) { |
| 2350 subsize = get_subsize(bsize, PARTITION_SPLIT); | 2262 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 2351 if (bsize == BLOCK_8X8) { | 2263 if (bsize == BLOCK_8X8) { |
| 2352 i = 4; | 2264 i = 4; |
| 2353 if (cpi->sf.adaptive_pred_interp_filter && partition_none_allowed) | 2265 if (cpi->sf.adaptive_pred_interp_filter && partition_none_allowed) |
| 2354 pc_tree->leaf_split[0]->pred_interp_filter = | 2266 pc_tree->leaf_split[0]->pred_interp_filter = |
| 2355 ctx->mic.mbmi.interp_filter; | 2267 ctx->mic.mbmi.interp_filter; |
| 2356 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rdc, subsize, | 2268 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &sum_rdc, subsize, |
| 2357 pc_tree->leaf_split[0], best_rdc.rdcost); | 2269 pc_tree->leaf_split[0], best_rdc.rdcost); |
| 2358 if (sum_rdc.rate == INT_MAX) | 2270 if (sum_rdc.rate == INT_MAX) |
| 2359 sum_rdc.rdcost = INT64_MAX; | 2271 sum_rdc.rdcost = INT64_MAX; |
| 2360 } else { | 2272 } else { |
| 2361 for (i = 0; i < 4 && sum_rdc.rdcost < best_rdc.rdcost; ++i) { | 2273 for (i = 0; i < 4 && sum_rdc.rdcost < best_rdc.rdcost; ++i) { |
| 2362 const int x_idx = (i & 1) * mi_step; | 2274 const int x_idx = (i & 1) * mi_step; |
| 2363 const int y_idx = (i >> 1) * mi_step; | 2275 const int y_idx = (i >> 1) * mi_step; |
| 2364 | 2276 |
| 2365 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 2277 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
| 2366 continue; | 2278 continue; |
| 2367 | 2279 |
| 2368 if (cpi->sf.adaptive_motion_search) | 2280 if (cpi->sf.adaptive_motion_search) |
| 2369 load_pred_mv(x, ctx); | 2281 load_pred_mv(x, ctx); |
| 2370 | 2282 |
| 2371 pc_tree->split[i]->index = i; | 2283 pc_tree->split[i]->index = i; |
| 2372 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, | 2284 rd_pick_partition(cpi, tile_data, tp, |
| 2285 mi_row + y_idx, mi_col + x_idx, |
| 2373 subsize, &this_rdc, | 2286 subsize, &this_rdc, |
| 2374 best_rdc.rdcost - sum_rdc.rdcost, pc_tree->split[i]); | 2287 best_rdc.rdcost - sum_rdc.rdcost, pc_tree->split[i]); |
| 2375 | 2288 |
| 2376 if (this_rdc.rate == INT_MAX) { | 2289 if (this_rdc.rate == INT_MAX) { |
| 2377 sum_rdc.rdcost = INT64_MAX; | 2290 sum_rdc.rdcost = INT64_MAX; |
| 2378 break; | 2291 break; |
| 2379 } else { | 2292 } else { |
| 2380 sum_rdc.rate += this_rdc.rate; | 2293 sum_rdc.rate += this_rdc.rate; |
| 2381 sum_rdc.dist += this_rdc.dist; | 2294 sum_rdc.dist += this_rdc.dist; |
| 2382 sum_rdc.rdcost += this_rdc.rdcost; | 2295 sum_rdc.rdcost += this_rdc.rdcost; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2405 | 2318 |
| 2406 // PARTITION_HORZ | 2319 // PARTITION_HORZ |
| 2407 if (partition_horz_allowed && do_rect) { | 2320 if (partition_horz_allowed && do_rect) { |
| 2408 subsize = get_subsize(bsize, PARTITION_HORZ); | 2321 subsize = get_subsize(bsize, PARTITION_HORZ); |
| 2409 if (cpi->sf.adaptive_motion_search) | 2322 if (cpi->sf.adaptive_motion_search) |
| 2410 load_pred_mv(x, ctx); | 2323 load_pred_mv(x, ctx); |
| 2411 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && | 2324 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2412 partition_none_allowed) | 2325 partition_none_allowed) |
| 2413 pc_tree->horizontal[0].pred_interp_filter = | 2326 pc_tree->horizontal[0].pred_interp_filter = |
| 2414 ctx->mic.mbmi.interp_filter; | 2327 ctx->mic.mbmi.interp_filter; |
| 2415 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rdc, subsize, | 2328 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &sum_rdc, subsize, |
| 2416 &pc_tree->horizontal[0], best_rdc.rdcost); | 2329 &pc_tree->horizontal[0], best_rdc.rdcost); |
| 2417 | 2330 |
| 2418 if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + mi_step < cm->mi_rows && | 2331 if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + mi_step < cm->mi_rows && |
| 2419 bsize > BLOCK_8X8) { | 2332 bsize > BLOCK_8X8) { |
| 2420 PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0]; | 2333 PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0]; |
| 2421 update_state(cpi, ctx, mi_row, mi_col, subsize, 0); | 2334 update_state(cpi, ctx, mi_row, mi_col, subsize, 0); |
| 2422 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); | 2335 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); |
| 2423 | 2336 |
| 2424 if (cpi->sf.adaptive_motion_search) | 2337 if (cpi->sf.adaptive_motion_search) |
| 2425 load_pred_mv(x, ctx); | 2338 load_pred_mv(x, ctx); |
| 2426 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && | 2339 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2427 partition_none_allowed) | 2340 partition_none_allowed) |
| 2428 pc_tree->horizontal[1].pred_interp_filter = | 2341 pc_tree->horizontal[1].pred_interp_filter = |
| 2429 ctx->mic.mbmi.interp_filter; | 2342 ctx->mic.mbmi.interp_filter; |
| 2430 rd_pick_sb_modes(cpi, tile, mi_row + mi_step, mi_col, &this_rdc, | 2343 rd_pick_sb_modes(cpi, tile_data, mi_row + mi_step, mi_col, |
| 2431 subsize, &pc_tree->horizontal[1], | 2344 &this_rdc, subsize, &pc_tree->horizontal[1], |
| 2432 best_rdc.rdcost - sum_rdc.rdcost); | 2345 best_rdc.rdcost - sum_rdc.rdcost); |
| 2433 if (this_rdc.rate == INT_MAX) { | 2346 if (this_rdc.rate == INT_MAX) { |
| 2434 sum_rdc.rdcost = INT64_MAX; | 2347 sum_rdc.rdcost = INT64_MAX; |
| 2435 } else { | 2348 } else { |
| 2436 sum_rdc.rate += this_rdc.rate; | 2349 sum_rdc.rate += this_rdc.rate; |
| 2437 sum_rdc.dist += this_rdc.dist; | 2350 sum_rdc.dist += this_rdc.dist; |
| 2438 sum_rdc.rdcost += this_rdc.rdcost; | 2351 sum_rdc.rdcost += this_rdc.rdcost; |
| 2439 } | 2352 } |
| 2440 } | 2353 } |
| 2441 | 2354 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2453 // PARTITION_VERT | 2366 // PARTITION_VERT |
| 2454 if (partition_vert_allowed && do_rect) { | 2367 if (partition_vert_allowed && do_rect) { |
| 2455 subsize = get_subsize(bsize, PARTITION_VERT); | 2368 subsize = get_subsize(bsize, PARTITION_VERT); |
| 2456 | 2369 |
| 2457 if (cpi->sf.adaptive_motion_search) | 2370 if (cpi->sf.adaptive_motion_search) |
| 2458 load_pred_mv(x, ctx); | 2371 load_pred_mv(x, ctx); |
| 2459 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && | 2372 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2460 partition_none_allowed) | 2373 partition_none_allowed) |
| 2461 pc_tree->vertical[0].pred_interp_filter = | 2374 pc_tree->vertical[0].pred_interp_filter = |
| 2462 ctx->mic.mbmi.interp_filter; | 2375 ctx->mic.mbmi.interp_filter; |
| 2463 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rdc, subsize, | 2376 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &sum_rdc, subsize, |
| 2464 &pc_tree->vertical[0], best_rdc.rdcost); | 2377 &pc_tree->vertical[0], best_rdc.rdcost); |
| 2465 if (sum_rdc.rdcost < best_rdc.rdcost && mi_col + mi_step < cm->mi_cols && | 2378 if (sum_rdc.rdcost < best_rdc.rdcost && mi_col + mi_step < cm->mi_cols && |
| 2466 bsize > BLOCK_8X8) { | 2379 bsize > BLOCK_8X8) { |
| 2467 update_state(cpi, &pc_tree->vertical[0], mi_row, mi_col, subsize, 0); | 2380 update_state(cpi, &pc_tree->vertical[0], mi_row, mi_col, subsize, 0); |
| 2468 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, | 2381 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, |
| 2469 &pc_tree->vertical[0]); | 2382 &pc_tree->vertical[0]); |
| 2470 | 2383 |
| 2471 if (cpi->sf.adaptive_motion_search) | 2384 if (cpi->sf.adaptive_motion_search) |
| 2472 load_pred_mv(x, ctx); | 2385 load_pred_mv(x, ctx); |
| 2473 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && | 2386 if (cpi->sf.adaptive_pred_interp_filter && bsize == BLOCK_8X8 && |
| 2474 partition_none_allowed) | 2387 partition_none_allowed) |
| 2475 pc_tree->vertical[1].pred_interp_filter = | 2388 pc_tree->vertical[1].pred_interp_filter = |
| 2476 ctx->mic.mbmi.interp_filter; | 2389 ctx->mic.mbmi.interp_filter; |
| 2477 rd_pick_sb_modes(cpi, tile, mi_row, mi_col + mi_step, &this_rdc, subsize, | 2390 rd_pick_sb_modes(cpi, tile_data, mi_row, mi_col + mi_step, |
| 2391 &this_rdc, subsize, |
| 2478 &pc_tree->vertical[1], best_rdc.rdcost - sum_rdc.rdcost); | 2392 &pc_tree->vertical[1], best_rdc.rdcost - sum_rdc.rdcost); |
| 2479 if (this_rdc.rate == INT_MAX) { | 2393 if (this_rdc.rate == INT_MAX) { |
| 2480 sum_rdc.rdcost = INT64_MAX; | 2394 sum_rdc.rdcost = INT64_MAX; |
| 2481 } else { | 2395 } else { |
| 2482 sum_rdc.rate += this_rdc.rate; | 2396 sum_rdc.rate += this_rdc.rate; |
| 2483 sum_rdc.dist += this_rdc.dist; | 2397 sum_rdc.dist += this_rdc.dist; |
| 2484 sum_rdc.rdcost += this_rdc.rdcost; | 2398 sum_rdc.rdcost += this_rdc.rdcost; |
| 2485 } | 2399 } |
| 2486 } | 2400 } |
| 2487 | 2401 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2507 | 2421 |
| 2508 | 2422 |
| 2509 if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && | 2423 if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && |
| 2510 pc_tree->index != 3) { | 2424 pc_tree->index != 3) { |
| 2511 int output_enabled = (bsize == BLOCK_64X64); | 2425 int output_enabled = (bsize == BLOCK_64X64); |
| 2512 | 2426 |
| 2513 // Check the projected output rate for this SB against it's target | 2427 // Check the projected output rate for this SB against it's target |
| 2514 // and and if necessary apply a Q delta using segmentation to get | 2428 // and and if necessary apply a Q delta using segmentation to get |
| 2515 // closer to the target. | 2429 // closer to the target. |
| 2516 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) | 2430 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) |
| 2517 vp9_select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, | 2431 vp9_select_in_frame_q_segment(cpi, bsize, mi_row, mi_col, output_enabled, |
| 2518 best_rdc.rate); | 2432 best_rdc.rate); |
| 2519 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) | 2433 encode_sb(cpi, tile_info, tp, mi_row, mi_col, output_enabled, |
| 2520 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, | 2434 bsize, pc_tree); |
| 2521 best_rdc.rate, best_rdc.dist); | |
| 2522 | |
| 2523 encode_sb(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize, pc_tree); | |
| 2524 } | 2435 } |
| 2525 | 2436 |
| 2526 if (bsize == BLOCK_64X64) { | 2437 if (bsize == BLOCK_64X64) { |
| 2527 assert(tp_orig < *tp); | 2438 assert(tp_orig < *tp); |
| 2528 assert(best_rdc.rate < INT_MAX); | 2439 assert(best_rdc.rate < INT_MAX); |
| 2529 assert(best_rdc.dist < INT64_MAX); | 2440 assert(best_rdc.dist < INT64_MAX); |
| 2530 } else { | 2441 } else { |
| 2531 assert(tp_orig == *tp); | 2442 assert(tp_orig == *tp); |
| 2532 } | 2443 } |
| 2533 } | 2444 } |
| 2534 | 2445 |
| 2535 static void encode_rd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, | 2446 static void encode_rd_sb_row(VP9_COMP *cpi, |
| 2536 int mi_row, TOKENEXTRA **tp) { | 2447 TileDataEnc *tile_data, |
| 2448 int mi_row, |
| 2449 TOKENEXTRA **tp) { |
| 2537 VP9_COMMON *const cm = &cpi->common; | 2450 VP9_COMMON *const cm = &cpi->common; |
| 2538 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 2451 TileInfo *const tile_info = &tile_data->tile_info; |
| 2452 MACROBLOCK *const x = &cpi->mb; |
| 2453 MACROBLOCKD *const xd = &x->e_mbd; |
| 2539 SPEED_FEATURES *const sf = &cpi->sf; | 2454 SPEED_FEATURES *const sf = &cpi->sf; |
| 2540 int mi_col; | 2455 int mi_col; |
| 2541 | 2456 |
| 2542 // Initialize the left context for the new SB row | 2457 // Initialize the left context for the new SB row |
| 2543 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); | 2458 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); |
| 2544 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); | 2459 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); |
| 2545 | 2460 |
| 2546 // Code each SB in the row | 2461 // Code each SB in the row |
| 2547 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; | 2462 for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; |
| 2548 mi_col += MI_BLOCK_SIZE) { | 2463 mi_col += MI_BLOCK_SIZE) { |
| 2549 int dummy_rate; | 2464 int dummy_rate; |
| 2550 int64_t dummy_dist; | 2465 int64_t dummy_dist; |
| 2551 RD_COST dummy_rdc; | 2466 RD_COST dummy_rdc; |
| 2552 int i; | 2467 int i; |
| 2553 | 2468 |
| 2554 const int idx_str = cm->mi_stride * mi_row + mi_col; | 2469 const int idx_str = cm->mi_stride * mi_row + mi_col; |
| 2555 MODE_INFO *mi = cm->mi + idx_str; | 2470 MODE_INFO *mi = cm->mi + idx_str; |
| 2556 MODE_INFO *prev_mi = NULL; | |
| 2557 | |
| 2558 if (cm->frame_type != KEY_FRAME) | |
| 2559 prev_mi = (cm->prev_mip + cm->mi_stride + 1 + idx_str)->src_mi; | |
| 2560 | 2471 |
| 2561 if (sf->adaptive_pred_interp_filter) { | 2472 if (sf->adaptive_pred_interp_filter) { |
| 2562 for (i = 0; i < 64; ++i) | 2473 for (i = 0; i < 64; ++i) |
| 2563 cpi->leaf_tree[i].pred_interp_filter = SWITCHABLE; | 2474 cpi->leaf_tree[i].pred_interp_filter = SWITCHABLE; |
| 2564 | 2475 |
| 2565 for (i = 0; i < 64; ++i) { | 2476 for (i = 0; i < 64; ++i) { |
| 2566 cpi->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE; | 2477 cpi->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE; |
| 2567 cpi->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE; | 2478 cpi->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE; |
| 2568 cpi->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE; | 2479 cpi->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE; |
| 2569 cpi->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE; | 2480 cpi->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE; |
| 2570 } | 2481 } |
| 2571 } | 2482 } |
| 2572 | 2483 |
| 2573 vp9_zero(cpi->mb.pred_mv); | 2484 vp9_zero(cpi->mb.pred_mv); |
| 2574 cpi->pc_root->index = 0; | 2485 cpi->pc_root->index = 0; |
| 2575 | 2486 |
| 2576 // TODO(yunqingwang): use_lastframe_partitioning is no longer used in good- | |
| 2577 // quality encoding. Need to evaluate it in real-time encoding later to | |
| 2578 // decide if it can be removed too. And then, do the code cleanup. | |
| 2579 cpi->mb.source_variance = UINT_MAX; | 2487 cpi->mb.source_variance = UINT_MAX; |
| 2580 if (sf->partition_search_type == FIXED_PARTITION) { | 2488 if (sf->partition_search_type == FIXED_PARTITION) { |
| 2581 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2489 set_offsets(cpi, tile_info, mi_row, mi_col, BLOCK_64X64); |
| 2582 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, | 2490 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, |
| 2583 sf->always_this_block_size); | 2491 sf->always_this_block_size); |
| 2584 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2492 rd_use_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 2585 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2493 BLOCK_64X64, &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2586 } else if (cpi->partition_search_skippable_frame) { | 2494 } else if (cpi->partition_search_skippable_frame) { |
| 2587 BLOCK_SIZE bsize; | 2495 BLOCK_SIZE bsize; |
| 2588 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2496 set_offsets(cpi, tile_info, mi_row, mi_col, BLOCK_64X64); |
| 2589 bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col); | 2497 bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col); |
| 2590 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); | 2498 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); |
| 2591 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2499 rd_use_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 2592 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2500 BLOCK_64X64, &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2593 } else if (sf->partition_search_type == VAR_BASED_PARTITION && | 2501 } else if (sf->partition_search_type == VAR_BASED_PARTITION && |
| 2594 cm->frame_type != KEY_FRAME ) { | 2502 cm->frame_type != KEY_FRAME ) { |
| 2595 choose_partitioning(cpi, tile, mi_row, mi_col); | 2503 choose_partitioning(cpi, tile_info, mi_row, mi_col); |
| 2596 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2504 rd_use_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 2597 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2505 BLOCK_64X64, &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2598 } else if (sf->partition_search_type == SEARCH_PARTITION && | |
| 2599 sf->use_lastframe_partitioning && | |
| 2600 (cpi->rc.frames_since_key % | |
| 2601 sf->last_partitioning_redo_frequency) && | |
| 2602 cm->prev_mi && | |
| 2603 cm->show_frame && | |
| 2604 cm->frame_type != KEY_FRAME && | |
| 2605 !cpi->rc.is_src_frame_alt_ref && | |
| 2606 ((sf->use_lastframe_partitioning != | |
| 2607 LAST_FRAME_PARTITION_LOW_MOTION) || | |
| 2608 !sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))) { | |
| 2609 if (sf->constrain_copy_partition && | |
| 2610 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold)) | |
| 2611 constrain_copy_partitioning(cpi, tile, mi, prev_mi, | |
| 2612 mi_row, mi_col, BLOCK_16X16); | |
| 2613 else | |
| 2614 copy_partitioning(cm, mi, prev_mi); | |
| 2615 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | |
| 2616 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | |
| 2617 } else { | 2506 } else { |
| 2618 // If required set upper and lower partition size limits | 2507 // If required set upper and lower partition size limits |
| 2619 if (sf->auto_min_max_partition_size) { | 2508 if (sf->auto_min_max_partition_size) { |
| 2620 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2509 set_offsets(cpi, tile_info, mi_row, mi_col, BLOCK_64X64); |
| 2621 rd_auto_partition_range(cpi, tile, mi_row, mi_col, | 2510 rd_auto_partition_range(cpi, tile_info, mi_row, mi_col, |
| 2622 &sf->min_partition_size, | 2511 &x->min_partition_size, |
| 2623 &sf->max_partition_size); | 2512 &x->max_partition_size); |
| 2624 } | 2513 } |
| 2625 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 2514 rd_pick_partition(cpi, tile_data, tp, mi_row, mi_col, BLOCK_64X64, |
| 2626 &dummy_rdc, INT64_MAX, cpi->pc_root); | 2515 &dummy_rdc, INT64_MAX, cpi->pc_root); |
| 2627 } | 2516 } |
| 2628 } | 2517 } |
| 2629 } | 2518 } |
| 2630 | 2519 |
| 2631 static void init_encode_frame_mb_context(VP9_COMP *cpi) { | 2520 static void init_encode_frame_mb_context(VP9_COMP *cpi) { |
| 2632 MACROBLOCK *const x = &cpi->mb; | 2521 MACROBLOCK *const x = &cpi->mb; |
| 2633 VP9_COMMON *const cm = &cpi->common; | 2522 VP9_COMMON *const cm = &cpi->common; |
| 2634 MACROBLOCKD *const xd = &x->e_mbd; | 2523 MACROBLOCKD *const xd = &x->e_mbd; |
| 2635 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); | 2524 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 return ONLY_4X4; | 2577 return ONLY_4X4; |
| 2689 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) | 2578 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) |
| 2690 return ALLOW_32X32; | 2579 return ALLOW_32X32; |
| 2691 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| | 2580 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| |
| 2692 cpi->sf.tx_size_search_method == USE_TX_8X8) | 2581 cpi->sf.tx_size_search_method == USE_TX_8X8) |
| 2693 return TX_MODE_SELECT; | 2582 return TX_MODE_SELECT; |
| 2694 else | 2583 else |
| 2695 return cpi->common.tx_mode; | 2584 return cpi->common.tx_mode; |
| 2696 } | 2585 } |
| 2697 | 2586 |
| 2698 static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, | 2587 static void nonrd_pick_sb_modes(VP9_COMP *cpi, |
| 2699 int mi_row, int mi_col, | 2588 TileDataEnc *tile_data, |
| 2700 int *rate, int64_t *dist, | 2589 int mi_row, int mi_col, RD_COST *rd_cost, |
| 2701 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { | 2590 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { |
| 2702 VP9_COMMON *const cm = &cpi->common; | 2591 VP9_COMMON *const cm = &cpi->common; |
| 2592 TileInfo *const tile_info = &tile_data->tile_info; |
| 2703 MACROBLOCK *const x = &cpi->mb; | 2593 MACROBLOCK *const x = &cpi->mb; |
| 2704 MACROBLOCKD *const xd = &x->e_mbd; | 2594 MACROBLOCKD *const xd = &x->e_mbd; |
| 2705 MB_MODE_INFO *mbmi; | 2595 MB_MODE_INFO *mbmi; |
| 2706 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 2596 set_offsets(cpi, tile_info, mi_row, mi_col, bsize); |
| 2707 mbmi = &xd->mi[0].src_mi->mbmi; | 2597 mbmi = &xd->mi[0].src_mi->mbmi; |
| 2708 mbmi->sb_type = bsize; | 2598 mbmi->sb_type = bsize; |
| 2709 | 2599 |
| 2710 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) | 2600 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) |
| 2711 if (mbmi->segment_id && x->in_static_area) | 2601 if (mbmi->segment_id) |
| 2712 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 2602 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
| 2713 | 2603 |
| 2714 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 2604 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
| 2715 set_mode_info_seg_skip(x, cm->tx_mode, rate, dist, bsize); | 2605 set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize); |
| 2716 else | 2606 else |
| 2717 vp9_pick_inter_mode(cpi, x, tile, mi_row, mi_col, rate, dist, bsize, ctx); | 2607 vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col, |
| 2608 rd_cost, bsize, ctx); |
| 2718 | 2609 |
| 2719 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); | 2610 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); |
| 2611 |
| 2612 if (rd_cost->rate == INT_MAX) |
| 2613 vp9_rd_cost_reset(rd_cost); |
| 2614 |
| 2615 ctx->rate = rd_cost->rate; |
| 2616 ctx->dist = rd_cost->dist; |
| 2720 } | 2617 } |
| 2721 | 2618 |
| 2722 static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x, | 2619 static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x, |
| 2723 int mi_row, int mi_col, | 2620 int mi_row, int mi_col, |
| 2724 BLOCK_SIZE bsize, BLOCK_SIZE subsize, | 2621 BLOCK_SIZE bsize, BLOCK_SIZE subsize, |
| 2725 PC_TREE *pc_tree) { | 2622 PC_TREE *pc_tree) { |
| 2726 MACROBLOCKD *xd = &x->e_mbd; | 2623 MACROBLOCKD *xd = &x->e_mbd; |
| 2727 int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; | 2624 int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; |
| 2728 PARTITION_TYPE partition = pc_tree->partitioning; | 2625 PARTITION_TYPE partition = pc_tree->partitioning; |
| 2729 | 2626 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2769 subsubsize, pc_tree->split[2]); | 2666 subsubsize, pc_tree->split[2]); |
| 2770 fill_mode_info_sb(cm, x, mi_row + hbs, mi_col + hbs, subsize, | 2667 fill_mode_info_sb(cm, x, mi_row + hbs, mi_col + hbs, subsize, |
| 2771 subsubsize, pc_tree->split[3]); | 2668 subsubsize, pc_tree->split[3]); |
| 2772 break; | 2669 break; |
| 2773 } | 2670 } |
| 2774 default: | 2671 default: |
| 2775 break; | 2672 break; |
| 2776 } | 2673 } |
| 2777 } | 2674 } |
| 2778 | 2675 |
| 2779 static void nonrd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, | 2676 // Reset the prediction pixel ready flag recursively. |
| 2677 static void pred_pixel_ready_reset(PC_TREE *pc_tree, BLOCK_SIZE bsize) { |
| 2678 pc_tree->none.pred_pixel_ready = 0; |
| 2679 pc_tree->horizontal[0].pred_pixel_ready = 0; |
| 2680 pc_tree->horizontal[1].pred_pixel_ready = 0; |
| 2681 pc_tree->vertical[0].pred_pixel_ready = 0; |
| 2682 pc_tree->vertical[1].pred_pixel_ready = 0; |
| 2683 |
| 2684 if (bsize > BLOCK_8X8) { |
| 2685 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 2686 int i; |
| 2687 for (i = 0; i < 4; ++i) |
| 2688 pred_pixel_ready_reset(pc_tree->split[i], subsize); |
| 2689 } |
| 2690 } |
| 2691 |
| 2692 static void nonrd_pick_partition(VP9_COMP *cpi, |
| 2693 TileDataEnc *tile_data, |
| 2780 TOKENEXTRA **tp, int mi_row, | 2694 TOKENEXTRA **tp, int mi_row, |
| 2781 int mi_col, BLOCK_SIZE bsize, int *rate, | 2695 int mi_col, BLOCK_SIZE bsize, RD_COST *rd_cost, |
| 2782 int64_t *dist, int do_recon, int64_t best_rd, | 2696 int do_recon, int64_t best_rd, |
| 2783 PC_TREE *pc_tree) { | 2697 PC_TREE *pc_tree) { |
| 2784 const SPEED_FEATURES *const sf = &cpi->sf; | 2698 const SPEED_FEATURES *const sf = &cpi->sf; |
| 2785 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 2699 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2786 VP9_COMMON *const cm = &cpi->common; | 2700 VP9_COMMON *const cm = &cpi->common; |
| 2701 TileInfo *const tile_info = &tile_data->tile_info; |
| 2787 MACROBLOCK *const x = &cpi->mb; | 2702 MACROBLOCK *const x = &cpi->mb; |
| 2788 MACROBLOCKD *const xd = &x->e_mbd; | 2703 MACROBLOCKD *const xd = &x->e_mbd; |
| 2789 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; | 2704 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; |
| 2790 TOKENEXTRA *tp_orig = *tp; | 2705 TOKENEXTRA *tp_orig = *tp; |
| 2791 PICK_MODE_CONTEXT *ctx = &pc_tree->none; | 2706 PICK_MODE_CONTEXT *ctx = &pc_tree->none; |
| 2792 int i; | 2707 int i; |
| 2793 BLOCK_SIZE subsize = bsize; | 2708 BLOCK_SIZE subsize = bsize; |
| 2794 int this_rate, sum_rate = 0, best_rate = INT_MAX; | 2709 RD_COST this_rdc, sum_rdc, best_rdc; |
| 2795 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; | |
| 2796 int64_t sum_rd = 0; | |
| 2797 int do_split = bsize >= BLOCK_8X8; | 2710 int do_split = bsize >= BLOCK_8X8; |
| 2798 int do_rect = 1; | 2711 int do_rect = 1; |
| 2799 // Override skipping rectangular partition operations for edge blocks | 2712 // Override skipping rectangular partition operations for edge blocks |
| 2800 const int force_horz_split = (mi_row + ms >= cm->mi_rows); | 2713 const int force_horz_split = (mi_row + ms >= cm->mi_rows); |
| 2801 const int force_vert_split = (mi_col + ms >= cm->mi_cols); | 2714 const int force_vert_split = (mi_col + ms >= cm->mi_cols); |
| 2802 const int xss = x->e_mbd.plane[1].subsampling_x; | 2715 const int xss = x->e_mbd.plane[1].subsampling_x; |
| 2803 const int yss = x->e_mbd.plane[1].subsampling_y; | 2716 const int yss = x->e_mbd.plane[1].subsampling_y; |
| 2804 | 2717 |
| 2805 int partition_none_allowed = !force_horz_split && !force_vert_split; | 2718 int partition_none_allowed = !force_horz_split && !force_vert_split; |
| 2806 int partition_horz_allowed = !force_vert_split && yss <= xss && | 2719 int partition_horz_allowed = !force_vert_split && yss <= xss && |
| 2807 bsize >= BLOCK_8X8; | 2720 bsize >= BLOCK_8X8; |
| 2808 int partition_vert_allowed = !force_horz_split && xss <= yss && | 2721 int partition_vert_allowed = !force_horz_split && xss <= yss && |
| 2809 bsize >= BLOCK_8X8; | 2722 bsize >= BLOCK_8X8; |
| 2810 (void) *tp_orig; | 2723 (void) *tp_orig; |
| 2811 | 2724 |
| 2812 assert(num_8x8_blocks_wide_lookup[bsize] == | 2725 assert(num_8x8_blocks_wide_lookup[bsize] == |
| 2813 num_8x8_blocks_high_lookup[bsize]); | 2726 num_8x8_blocks_high_lookup[bsize]); |
| 2814 | 2727 |
| 2728 vp9_rd_cost_init(&sum_rdc); |
| 2729 vp9_rd_cost_reset(&best_rdc); |
| 2730 best_rdc.rdcost = best_rd; |
| 2731 |
| 2815 // Determine partition types in search according to the speed features. | 2732 // Determine partition types in search according to the speed features. |
| 2816 // The threshold set here has to be of square block size. | 2733 // The threshold set here has to be of square block size. |
| 2817 if (sf->auto_min_max_partition_size) { | 2734 if (sf->auto_min_max_partition_size) { |
| 2818 partition_none_allowed &= (bsize <= sf->max_partition_size && | 2735 partition_none_allowed &= (bsize <= x->max_partition_size && |
| 2819 bsize >= sf->min_partition_size); | 2736 bsize >= x->min_partition_size); |
| 2820 partition_horz_allowed &= ((bsize <= sf->max_partition_size && | 2737 partition_horz_allowed &= ((bsize <= x->max_partition_size && |
| 2821 bsize > sf->min_partition_size) || | 2738 bsize > x->min_partition_size) || |
| 2822 force_horz_split); | 2739 force_horz_split); |
| 2823 partition_vert_allowed &= ((bsize <= sf->max_partition_size && | 2740 partition_vert_allowed &= ((bsize <= x->max_partition_size && |
| 2824 bsize > sf->min_partition_size) || | 2741 bsize > x->min_partition_size) || |
| 2825 force_vert_split); | 2742 force_vert_split); |
| 2826 do_split &= bsize > sf->min_partition_size; | 2743 do_split &= bsize > x->min_partition_size; |
| 2827 } | 2744 } |
| 2828 if (sf->use_square_partition_only) { | 2745 if (sf->use_square_partition_only) { |
| 2829 partition_horz_allowed &= force_horz_split; | 2746 partition_horz_allowed &= force_horz_split; |
| 2830 partition_vert_allowed &= force_vert_split; | 2747 partition_vert_allowed &= force_vert_split; |
| 2831 } | 2748 } |
| 2832 | 2749 |
| 2750 ctx->pred_pixel_ready = !(partition_vert_allowed || |
| 2751 partition_horz_allowed || |
| 2752 do_split); |
| 2753 |
| 2833 // PARTITION_NONE | 2754 // PARTITION_NONE |
| 2834 if (partition_none_allowed) { | 2755 if (partition_none_allowed) { |
| 2835 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2756 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, |
| 2836 &this_rate, &this_dist, bsize, ctx); | 2757 &this_rdc, bsize, ctx); |
| 2837 ctx->mic.mbmi = xd->mi[0].src_mi->mbmi; | 2758 ctx->mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 2838 ctx->skip_txfm[0] = x->skip_txfm[0]; | 2759 ctx->skip_txfm[0] = x->skip_txfm[0]; |
| 2839 ctx->skip = x->skip; | 2760 ctx->skip = x->skip; |
| 2840 | 2761 |
| 2841 if (this_rate != INT_MAX) { | 2762 if (this_rdc.rate != INT_MAX) { |
| 2842 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2763 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2843 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; | 2764 this_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 2844 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 2765 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, |
| 2845 if (sum_rd < best_rd) { | 2766 this_rdc.rate, this_rdc.dist); |
| 2846 int dist_breakout_thr = sf->partition_search_breakout_dist_thr; | 2767 if (this_rdc.rdcost < best_rdc.rdcost) { |
| 2768 int64_t dist_breakout_thr = sf->partition_search_breakout_dist_thr; |
| 2847 int64_t rate_breakout_thr = sf->partition_search_breakout_rate_thr; | 2769 int64_t rate_breakout_thr = sf->partition_search_breakout_rate_thr; |
| 2848 | 2770 |
| 2849 dist_breakout_thr >>= 8 - (b_width_log2_lookup[bsize] + | 2771 dist_breakout_thr >>= 8 - (b_width_log2_lookup[bsize] + |
| 2850 b_height_log2_lookup[bsize]); | 2772 b_height_log2_lookup[bsize]); |
| 2851 | 2773 |
| 2852 rate_breakout_thr *= num_pels_log2_lookup[bsize]; | 2774 rate_breakout_thr *= num_pels_log2_lookup[bsize]; |
| 2853 | 2775 |
| 2854 best_rate = this_rate; | 2776 best_rdc = this_rdc; |
| 2855 best_dist = this_dist; | |
| 2856 best_rd = sum_rd; | |
| 2857 if (bsize >= BLOCK_8X8) | 2777 if (bsize >= BLOCK_8X8) |
| 2858 pc_tree->partitioning = PARTITION_NONE; | 2778 pc_tree->partitioning = PARTITION_NONE; |
| 2859 | 2779 |
| 2860 if (!x->e_mbd.lossless && | 2780 if (!x->e_mbd.lossless && |
| 2861 this_rate < rate_breakout_thr && | 2781 this_rdc.rate < rate_breakout_thr && |
| 2862 this_dist < dist_breakout_thr) { | 2782 this_rdc.dist < dist_breakout_thr) { |
| 2863 do_split = 0; | 2783 do_split = 0; |
| 2864 do_rect = 0; | 2784 do_rect = 0; |
| 2865 } | 2785 } |
| 2866 } | 2786 } |
| 2867 } | 2787 } |
| 2868 } | 2788 } |
| 2869 | 2789 |
| 2870 // store estimated motion vector | 2790 // store estimated motion vector |
| 2871 store_pred_mv(x, ctx); | 2791 store_pred_mv(x, ctx); |
| 2872 | 2792 |
| 2873 // PARTITION_SPLIT | 2793 // PARTITION_SPLIT |
| 2874 sum_rd = 0; | |
| 2875 if (do_split) { | 2794 if (do_split) { |
| 2876 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2795 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2877 sum_rate += cpi->partition_cost[pl][PARTITION_SPLIT]; | 2796 sum_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT]; |
| 2797 sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, sum_rdc.rate, sum_rdc.dist); |
| 2878 subsize = get_subsize(bsize, PARTITION_SPLIT); | 2798 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 2879 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | 2799 for (i = 0; i < 4 && sum_rdc.rdcost < best_rdc.rdcost; ++i) { |
| 2880 const int x_idx = (i & 1) * ms; | 2800 const int x_idx = (i & 1) * ms; |
| 2881 const int y_idx = (i >> 1) * ms; | 2801 const int y_idx = (i >> 1) * ms; |
| 2882 | 2802 |
| 2883 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 2803 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
| 2884 continue; | 2804 continue; |
| 2885 load_pred_mv(x, ctx); | 2805 load_pred_mv(x, ctx); |
| 2886 nonrd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, | 2806 nonrd_pick_partition(cpi, tile_data, tp, |
| 2887 subsize, &this_rate, &this_dist, 0, | 2807 mi_row + y_idx, mi_col + x_idx, |
| 2888 best_rd - sum_rd, pc_tree->split[i]); | 2808 subsize, &this_rdc, 0, |
| 2809 best_rdc.rdcost - sum_rdc.rdcost, pc_tree->split[i]); |
| 2889 | 2810 |
| 2890 if (this_rate == INT_MAX) { | 2811 if (this_rdc.rate == INT_MAX) { |
| 2891 sum_rd = INT64_MAX; | 2812 vp9_rd_cost_reset(&sum_rdc); |
| 2892 } else { | 2813 } else { |
| 2893 sum_rate += this_rate; | 2814 sum_rdc.rate += this_rdc.rate; |
| 2894 sum_dist += this_dist; | 2815 sum_rdc.dist += this_rdc.dist; |
| 2895 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2816 sum_rdc.rdcost += this_rdc.rdcost; |
| 2896 } | 2817 } |
| 2897 } | 2818 } |
| 2898 | 2819 |
| 2899 if (sum_rd < best_rd) { | 2820 if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2900 best_rate = sum_rate; | 2821 best_rdc = sum_rdc; |
| 2901 best_dist = sum_dist; | |
| 2902 best_rd = sum_rd; | |
| 2903 pc_tree->partitioning = PARTITION_SPLIT; | 2822 pc_tree->partitioning = PARTITION_SPLIT; |
| 2904 } else { | 2823 } else { |
| 2905 // skip rectangular partition test when larger block size | 2824 // skip rectangular partition test when larger block size |
| 2906 // gives better rd cost | 2825 // gives better rd cost |
| 2907 if (sf->less_rectangular_check) | 2826 if (sf->less_rectangular_check) |
| 2908 do_rect &= !partition_none_allowed; | 2827 do_rect &= !partition_none_allowed; |
| 2909 } | 2828 } |
| 2910 } | 2829 } |
| 2911 | 2830 |
| 2912 // PARTITION_HORZ | 2831 // PARTITION_HORZ |
| 2913 if (partition_horz_allowed && do_rect) { | 2832 if (partition_horz_allowed && do_rect) { |
| 2914 subsize = get_subsize(bsize, PARTITION_HORZ); | 2833 subsize = get_subsize(bsize, PARTITION_HORZ); |
| 2915 if (sf->adaptive_motion_search) | 2834 if (sf->adaptive_motion_search) |
| 2916 load_pred_mv(x, ctx); | 2835 load_pred_mv(x, ctx); |
| 2917 | 2836 pc_tree->horizontal[0].pred_pixel_ready = 1; |
| 2918 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2837 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &sum_rdc, subsize, |
| 2919 &this_rate, &this_dist, subsize, | |
| 2920 &pc_tree->horizontal[0]); | 2838 &pc_tree->horizontal[0]); |
| 2921 | 2839 |
| 2922 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; | 2840 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 2923 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; | 2841 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; |
| 2924 pc_tree->horizontal[0].skip = x->skip; | 2842 pc_tree->horizontal[0].skip = x->skip; |
| 2925 | 2843 |
| 2926 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2844 if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + ms < cm->mi_rows) { |
| 2927 | |
| 2928 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { | |
| 2929 load_pred_mv(x, ctx); | 2845 load_pred_mv(x, ctx); |
| 2930 nonrd_pick_sb_modes(cpi, tile, mi_row + ms, mi_col, | 2846 pc_tree->horizontal[1].pred_pixel_ready = 1; |
| 2931 &this_rate, &this_dist, subsize, | 2847 nonrd_pick_sb_modes(cpi, tile_data, mi_row + ms, mi_col, |
| 2848 &this_rdc, subsize, |
| 2932 &pc_tree->horizontal[1]); | 2849 &pc_tree->horizontal[1]); |
| 2933 | 2850 |
| 2934 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; | 2851 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 2935 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; | 2852 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; |
| 2936 pc_tree->horizontal[1].skip = x->skip; | 2853 pc_tree->horizontal[1].skip = x->skip; |
| 2937 | 2854 |
| 2938 if (this_rate == INT_MAX) { | 2855 if (this_rdc.rate == INT_MAX) { |
| 2939 sum_rd = INT64_MAX; | 2856 vp9_rd_cost_reset(&sum_rdc); |
| 2940 } else { | 2857 } else { |
| 2941 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2858 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2942 this_rate += cpi->partition_cost[pl][PARTITION_HORZ]; | 2859 this_rdc.rate += cpi->partition_cost[pl][PARTITION_HORZ]; |
| 2943 sum_rate += this_rate; | 2860 sum_rdc.rate += this_rdc.rate; |
| 2944 sum_dist += this_dist; | 2861 sum_rdc.dist += this_rdc.dist; |
| 2945 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2862 sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, |
| 2863 sum_rdc.rate, sum_rdc.dist); |
| 2946 } | 2864 } |
| 2947 } | 2865 } |
| 2948 if (sum_rd < best_rd) { | 2866 |
| 2949 best_rd = sum_rd; | 2867 if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2950 best_rate = sum_rate; | 2868 best_rdc = sum_rdc; |
| 2951 best_dist = sum_dist; | |
| 2952 pc_tree->partitioning = PARTITION_HORZ; | 2869 pc_tree->partitioning = PARTITION_HORZ; |
| 2870 } else { |
| 2871 pred_pixel_ready_reset(pc_tree, bsize); |
| 2953 } | 2872 } |
| 2954 } | 2873 } |
| 2955 | 2874 |
| 2956 // PARTITION_VERT | 2875 // PARTITION_VERT |
| 2957 if (partition_vert_allowed && do_rect) { | 2876 if (partition_vert_allowed && do_rect) { |
| 2958 subsize = get_subsize(bsize, PARTITION_VERT); | 2877 subsize = get_subsize(bsize, PARTITION_VERT); |
| 2959 | |
| 2960 if (sf->adaptive_motion_search) | 2878 if (sf->adaptive_motion_search) |
| 2961 load_pred_mv(x, ctx); | 2879 load_pred_mv(x, ctx); |
| 2962 | 2880 pc_tree->vertical[0].pred_pixel_ready = 1; |
| 2963 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2881 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, &sum_rdc, subsize, |
| 2964 &this_rate, &this_dist, subsize, | |
| 2965 &pc_tree->vertical[0]); | 2882 &pc_tree->vertical[0]); |
| 2966 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; | 2883 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 2967 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; | 2884 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; |
| 2968 pc_tree->vertical[0].skip = x->skip; | 2885 pc_tree->vertical[0].skip = x->skip; |
| 2969 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2886 |
| 2970 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { | 2887 if (sum_rdc.rdcost < best_rdc.rdcost && mi_col + ms < cm->mi_cols) { |
| 2971 load_pred_mv(x, ctx); | 2888 load_pred_mv(x, ctx); |
| 2972 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + ms, | 2889 pc_tree->vertical[1].pred_pixel_ready = 1; |
| 2973 &this_rate, &this_dist, subsize, | 2890 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col + ms, |
| 2891 &this_rdc, subsize, |
| 2974 &pc_tree->vertical[1]); | 2892 &pc_tree->vertical[1]); |
| 2975 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; | 2893 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 2976 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; | 2894 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; |
| 2977 pc_tree->vertical[1].skip = x->skip; | 2895 pc_tree->vertical[1].skip = x->skip; |
| 2978 if (this_rate == INT_MAX) { | 2896 |
| 2979 sum_rd = INT64_MAX; | 2897 if (this_rdc.rate == INT_MAX) { |
| 2898 vp9_rd_cost_reset(&sum_rdc); |
| 2980 } else { | 2899 } else { |
| 2981 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2900 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2982 this_rate += cpi->partition_cost[pl][PARTITION_VERT]; | 2901 sum_rdc.rate += cpi->partition_cost[pl][PARTITION_VERT]; |
| 2983 sum_rate += this_rate; | 2902 sum_rdc.rate += this_rdc.rate; |
| 2984 sum_dist += this_dist; | 2903 sum_rdc.dist += this_rdc.dist; |
| 2985 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2904 sum_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, |
| 2905 sum_rdc.rate, sum_rdc.dist); |
| 2986 } | 2906 } |
| 2987 } | 2907 } |
| 2988 if (sum_rd < best_rd) { | 2908 |
| 2989 best_rate = sum_rate; | 2909 if (sum_rdc.rdcost < best_rdc.rdcost) { |
| 2990 best_dist = sum_dist; | 2910 best_rdc = sum_rdc; |
| 2991 best_rd = sum_rd; | |
| 2992 pc_tree->partitioning = PARTITION_VERT; | 2911 pc_tree->partitioning = PARTITION_VERT; |
| 2912 } else { |
| 2913 pred_pixel_ready_reset(pc_tree, bsize); |
| 2993 } | 2914 } |
| 2994 } | 2915 } |
| 2995 // TODO(JBB): The following line is here just to avoid a static warning | |
| 2996 // that occurs because at this point we never again reuse best_rd | |
| 2997 // despite setting it here. The code should be refactored to avoid this. | |
| 2998 (void) best_rd; | |
| 2999 | 2916 |
| 3000 *rate = best_rate; | 2917 *rd_cost = best_rdc; |
| 3001 *dist = best_dist; | |
| 3002 | 2918 |
| 3003 if (best_rate == INT_MAX) | 2919 if (best_rdc.rate == INT_MAX) { |
| 2920 vp9_rd_cost_reset(rd_cost); |
| 3004 return; | 2921 return; |
| 2922 } |
| 3005 | 2923 |
| 3006 // update mode info array | 2924 // update mode info array |
| 3007 subsize = get_subsize(bsize, pc_tree->partitioning); | 2925 subsize = get_subsize(bsize, pc_tree->partitioning); |
| 3008 fill_mode_info_sb(cm, x, mi_row, mi_col, bsize, subsize, | 2926 fill_mode_info_sb(cm, x, mi_row, mi_col, bsize, subsize, |
| 3009 pc_tree); | 2927 pc_tree); |
| 3010 | 2928 |
| 3011 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) { | 2929 if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && do_recon) { |
| 3012 int output_enabled = (bsize == BLOCK_64X64); | 2930 int output_enabled = (bsize == BLOCK_64X64); |
| 3013 | 2931 |
| 3014 // Check the projected output rate for this SB against it's target | 2932 // Check the projected output rate for this SB against it's target |
| 3015 // and and if necessary apply a Q delta using segmentation to get | 2933 // and and if necessary apply a Q delta using segmentation to get |
| 3016 // closer to the target. | 2934 // closer to the target. |
| 3017 if ((oxcf->aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { | 2935 if ((oxcf->aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { |
| 3018 vp9_select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, | 2936 vp9_select_in_frame_q_segment(cpi, bsize, mi_row, mi_col, output_enabled, |
| 3019 best_rate); | 2937 best_rdc.rate); |
| 3020 } | 2938 } |
| 3021 | 2939 encode_sb_rt(cpi, tile_info, tp, mi_row, mi_col, output_enabled, |
| 3022 if (oxcf->aq_mode == CYCLIC_REFRESH_AQ) | 2940 bsize, pc_tree); |
| 3023 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, | |
| 3024 best_rate, best_dist); | |
| 3025 | |
| 3026 encode_sb_rt(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize, pc_tree); | |
| 3027 } | 2941 } |
| 3028 | 2942 |
| 3029 if (bsize == BLOCK_64X64) { | 2943 if (bsize == BLOCK_64X64) { |
| 3030 assert(tp_orig < *tp); | 2944 assert(tp_orig < *tp); |
| 3031 assert(best_rate < INT_MAX); | 2945 assert(best_rdc.rate < INT_MAX); |
| 3032 assert(best_dist < INT64_MAX); | 2946 assert(best_rdc.dist < INT64_MAX); |
| 3033 } else { | 2947 } else { |
| 3034 assert(tp_orig == *tp); | 2948 assert(tp_orig == *tp); |
| 3035 } | 2949 } |
| 3036 } | 2950 } |
| 3037 | 2951 |
| 2952 static void nonrd_select_partition(VP9_COMP *cpi, |
| 2953 TileDataEnc *tile_data, |
| 2954 MODE_INFO *mi, |
| 2955 TOKENEXTRA **tp, |
| 2956 int mi_row, int mi_col, |
| 2957 BLOCK_SIZE bsize, int output_enabled, |
| 2958 RD_COST *rd_cost, PC_TREE *pc_tree) { |
| 2959 VP9_COMMON *const cm = &cpi->common; |
| 2960 TileInfo *const tile_info = &tile_data->tile_info; |
| 2961 MACROBLOCK *const x = &cpi->mb; |
| 2962 MACROBLOCKD *const xd = &x->e_mbd; |
| 2963 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; |
| 2964 const int mis = cm->mi_stride; |
| 2965 PARTITION_TYPE partition; |
| 2966 BLOCK_SIZE subsize; |
| 2967 RD_COST this_rdc; |
| 2968 |
| 2969 vp9_rd_cost_reset(&this_rdc); |
| 2970 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
| 2971 return; |
| 2972 |
| 2973 subsize = (bsize >= BLOCK_8X8) ? mi[0].src_mi->mbmi.sb_type : BLOCK_4X4; |
| 2974 partition = partition_lookup[bsl][subsize]; |
| 2975 |
| 2976 if (bsize == BLOCK_32X32 && partition != PARTITION_NONE && |
| 2977 subsize >= BLOCK_16X16) { |
| 2978 x->max_partition_size = BLOCK_32X32; |
| 2979 x->min_partition_size = BLOCK_8X8; |
| 2980 nonrd_pick_partition(cpi, tile_data, tp, mi_row, mi_col, bsize, |
| 2981 rd_cost, 0, INT64_MAX, pc_tree); |
| 2982 } else if (bsize == BLOCK_16X16 && partition != PARTITION_NONE) { |
| 2983 x->max_partition_size = BLOCK_16X16; |
| 2984 x->min_partition_size = BLOCK_8X8; |
| 2985 nonrd_pick_partition(cpi, tile_data, tp, mi_row, mi_col, bsize, |
| 2986 rd_cost, 0, INT64_MAX, pc_tree); |
| 2987 } else { |
| 2988 switch (partition) { |
| 2989 case PARTITION_NONE: |
| 2990 pc_tree->none.pred_pixel_ready = 1; |
| 2991 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, rd_cost, |
| 2992 subsize, &pc_tree->none); |
| 2993 pc_tree->none.mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 2994 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; |
| 2995 pc_tree->none.skip = x->skip; |
| 2996 break; |
| 2997 case PARTITION_VERT: |
| 2998 pc_tree->vertical[0].pred_pixel_ready = 1; |
| 2999 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, rd_cost, |
| 3000 subsize, &pc_tree->vertical[0]); |
| 3001 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3002 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; |
| 3003 pc_tree->vertical[0].skip = x->skip; |
| 3004 if (mi_col + hbs < cm->mi_cols) { |
| 3005 pc_tree->vertical[1].pred_pixel_ready = 1; |
| 3006 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col + hbs, |
| 3007 &this_rdc, subsize, &pc_tree->vertical[1]); |
| 3008 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3009 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; |
| 3010 pc_tree->vertical[1].skip = x->skip; |
| 3011 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3012 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3013 rd_cost->rate += this_rdc.rate; |
| 3014 rd_cost->dist += this_rdc.dist; |
| 3015 } |
| 3016 } |
| 3017 break; |
| 3018 case PARTITION_HORZ: |
| 3019 pc_tree->horizontal[0].pred_pixel_ready = 1; |
| 3020 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, rd_cost, |
| 3021 subsize, &pc_tree->horizontal[0]); |
| 3022 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3023 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; |
| 3024 pc_tree->horizontal[0].skip = x->skip; |
| 3025 if (mi_row + hbs < cm->mi_rows) { |
| 3026 pc_tree->horizontal[1].pred_pixel_ready = 1; |
| 3027 nonrd_pick_sb_modes(cpi, tile_data, mi_row + hbs, mi_col, |
| 3028 &this_rdc, subsize, &pc_tree->horizontal[0]); |
| 3029 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3030 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; |
| 3031 pc_tree->horizontal[1].skip = x->skip; |
| 3032 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3033 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3034 rd_cost->rate += this_rdc.rate; |
| 3035 rd_cost->dist += this_rdc.dist; |
| 3036 } |
| 3037 } |
| 3038 break; |
| 3039 case PARTITION_SPLIT: |
| 3040 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 3041 nonrd_select_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 3042 subsize, output_enabled, rd_cost, |
| 3043 pc_tree->split[0]); |
| 3044 nonrd_select_partition(cpi, tile_data, mi + hbs, tp, |
| 3045 mi_row, mi_col + hbs, subsize, output_enabled, |
| 3046 &this_rdc, pc_tree->split[1]); |
| 3047 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3048 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3049 rd_cost->rate += this_rdc.rate; |
| 3050 rd_cost->dist += this_rdc.dist; |
| 3051 } |
| 3052 nonrd_select_partition(cpi, tile_data, mi + hbs * mis, tp, |
| 3053 mi_row + hbs, mi_col, subsize, output_enabled, |
| 3054 &this_rdc, pc_tree->split[2]); |
| 3055 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3056 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3057 rd_cost->rate += this_rdc.rate; |
| 3058 rd_cost->dist += this_rdc.dist; |
| 3059 } |
| 3060 nonrd_select_partition(cpi, tile_data, mi + hbs * mis + hbs, tp, |
| 3061 mi_row + hbs, mi_col + hbs, subsize, |
| 3062 output_enabled, &this_rdc, pc_tree->split[3]); |
| 3063 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3064 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3065 rd_cost->rate += this_rdc.rate; |
| 3066 rd_cost->dist += this_rdc.dist; |
| 3067 } |
| 3068 break; |
| 3069 default: |
| 3070 assert("Invalid partition type."); |
| 3071 break; |
| 3072 } |
| 3073 } |
| 3074 |
| 3075 if (bsize == BLOCK_64X64 && output_enabled) |
| 3076 encode_sb_rt(cpi, tile_info, tp, mi_row, mi_col, 1, bsize, pc_tree); |
| 3077 } |
| 3078 |
| 3079 |
| 3038 static void nonrd_use_partition(VP9_COMP *cpi, | 3080 static void nonrd_use_partition(VP9_COMP *cpi, |
| 3039 const TileInfo *const tile, | 3081 TileDataEnc *tile_data, |
| 3040 MODE_INFO *mi, | 3082 MODE_INFO *mi, |
| 3041 TOKENEXTRA **tp, | 3083 TOKENEXTRA **tp, |
| 3042 int mi_row, int mi_col, | 3084 int mi_row, int mi_col, |
| 3043 BLOCK_SIZE bsize, int output_enabled, | 3085 BLOCK_SIZE bsize, int output_enabled, |
| 3044 int *totrate, int64_t *totdist, | 3086 RD_COST *rd_cost, PC_TREE *pc_tree) { |
| 3045 PC_TREE *pc_tree) { | |
| 3046 VP9_COMMON *const cm = &cpi->common; | 3087 VP9_COMMON *const cm = &cpi->common; |
| 3088 TileInfo *tile_info = &tile_data->tile_info; |
| 3047 MACROBLOCK *const x = &cpi->mb; | 3089 MACROBLOCK *const x = &cpi->mb; |
| 3048 MACROBLOCKD *const xd = &x->e_mbd; | 3090 MACROBLOCKD *const xd = &x->e_mbd; |
| 3049 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; | 3091 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; |
| 3050 const int mis = cm->mi_stride; | 3092 const int mis = cm->mi_stride; |
| 3051 PARTITION_TYPE partition; | 3093 PARTITION_TYPE partition; |
| 3052 BLOCK_SIZE subsize; | 3094 BLOCK_SIZE subsize; |
| 3053 int rate = INT_MAX; | 3095 RD_COST this_rdc; |
| 3054 int64_t dist = INT64_MAX; | |
| 3055 | 3096 |
| 3097 vp9_rd_cost_reset(&this_rdc); |
| 3056 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 3098 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
| 3057 return; | 3099 return; |
| 3058 | 3100 |
| 3059 subsize = (bsize >= BLOCK_8X8) ? mi[0].src_mi->mbmi.sb_type : BLOCK_4X4; | 3101 subsize = (bsize >= BLOCK_8X8) ? mi[0].src_mi->mbmi.sb_type : BLOCK_4X4; |
| 3060 partition = partition_lookup[bsl][subsize]; | 3102 partition = partition_lookup[bsl][subsize]; |
| 3061 | 3103 |
| 3104 if (output_enabled && bsize != BLOCK_4X4) { |
| 3105 int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 3106 cm->counts.partition[ctx][partition]++; |
| 3107 } |
| 3108 |
| 3062 switch (partition) { | 3109 switch (partition) { |
| 3063 case PARTITION_NONE: | 3110 case PARTITION_NONE: |
| 3064 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, | 3111 pc_tree->none.pred_pixel_ready = 1; |
| 3112 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, rd_cost, |
| 3065 subsize, &pc_tree->none); | 3113 subsize, &pc_tree->none); |
| 3066 pc_tree->none.mic.mbmi = xd->mi[0].src_mi->mbmi; | 3114 pc_tree->none.mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3067 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; | 3115 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; |
| 3068 pc_tree->none.skip = x->skip; | 3116 pc_tree->none.skip = x->skip; |
| 3117 encode_b_rt(cpi, tile_info, tp, mi_row, mi_col, output_enabled, subsize, |
| 3118 &pc_tree->none); |
| 3069 break; | 3119 break; |
| 3070 case PARTITION_VERT: | 3120 case PARTITION_VERT: |
| 3071 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, | 3121 pc_tree->vertical[0].pred_pixel_ready = 1; |
| 3122 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, rd_cost, |
| 3072 subsize, &pc_tree->vertical[0]); | 3123 subsize, &pc_tree->vertical[0]); |
| 3073 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3124 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3074 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; | 3125 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; |
| 3075 pc_tree->vertical[0].skip = x->skip; | 3126 pc_tree->vertical[0].skip = x->skip; |
| 3127 encode_b_rt(cpi, tile_info, tp, mi_row, mi_col, output_enabled, subsize, |
| 3128 &pc_tree->vertical[0]); |
| 3076 if (mi_col + hbs < cm->mi_cols) { | 3129 if (mi_col + hbs < cm->mi_cols) { |
| 3077 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, | 3130 pc_tree->vertical[1].pred_pixel_ready = 1; |
| 3078 &rate, &dist, subsize, &pc_tree->vertical[1]); | 3131 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col + hbs, |
| 3132 &this_rdc, subsize, &pc_tree->vertical[1]); |
| 3079 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3133 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3080 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; | 3134 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; |
| 3081 pc_tree->vertical[1].skip = x->skip; | 3135 pc_tree->vertical[1].skip = x->skip; |
| 3082 if (rate != INT_MAX && dist != INT64_MAX && | 3136 encode_b_rt(cpi, tile_info, tp, mi_row, mi_col + hbs, |
| 3083 *totrate != INT_MAX && *totdist != INT64_MAX) { | 3137 output_enabled, subsize, &pc_tree->vertical[1]); |
| 3084 *totrate += rate; | 3138 |
| 3085 *totdist += dist; | 3139 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3140 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3141 rd_cost->rate += this_rdc.rate; |
| 3142 rd_cost->dist += this_rdc.dist; |
| 3086 } | 3143 } |
| 3087 } | 3144 } |
| 3088 break; | 3145 break; |
| 3089 case PARTITION_HORZ: | 3146 case PARTITION_HORZ: |
| 3090 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, | 3147 pc_tree->horizontal[0].pred_pixel_ready = 1; |
| 3148 nonrd_pick_sb_modes(cpi, tile_data, mi_row, mi_col, rd_cost, |
| 3091 subsize, &pc_tree->horizontal[0]); | 3149 subsize, &pc_tree->horizontal[0]); |
| 3092 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3150 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3093 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; | 3151 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; |
| 3094 pc_tree->horizontal[0].skip = x->skip; | 3152 pc_tree->horizontal[0].skip = x->skip; |
| 3153 encode_b_rt(cpi, tile_info, tp, mi_row, mi_col, output_enabled, subsize, |
| 3154 &pc_tree->horizontal[0]); |
| 3155 |
| 3095 if (mi_row + hbs < cm->mi_rows) { | 3156 if (mi_row + hbs < cm->mi_rows) { |
| 3096 nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, | 3157 pc_tree->horizontal[1].pred_pixel_ready = 1; |
| 3097 &rate, &dist, subsize, &pc_tree->horizontal[0]); | 3158 nonrd_pick_sb_modes(cpi, tile_data, mi_row + hbs, mi_col, |
| 3159 &this_rdc, subsize, &pc_tree->horizontal[0]); |
| 3098 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3160 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
| 3099 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; | 3161 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; |
| 3100 pc_tree->horizontal[1].skip = x->skip; | 3162 pc_tree->horizontal[1].skip = x->skip; |
| 3101 if (rate != INT_MAX && dist != INT64_MAX && | 3163 encode_b_rt(cpi, tile_info, tp, mi_row + hbs, mi_col, |
| 3102 *totrate != INT_MAX && *totdist != INT64_MAX) { | 3164 output_enabled, subsize, &pc_tree->horizontal[1]); |
| 3103 *totrate += rate; | 3165 |
| 3104 *totdist += dist; | 3166 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3167 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3168 rd_cost->rate += this_rdc.rate; |
| 3169 rd_cost->dist += this_rdc.dist; |
| 3105 } | 3170 } |
| 3106 } | 3171 } |
| 3107 break; | 3172 break; |
| 3108 case PARTITION_SPLIT: | 3173 case PARTITION_SPLIT: |
| 3109 subsize = get_subsize(bsize, PARTITION_SPLIT); | 3174 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 3110 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, | 3175 nonrd_use_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 3111 subsize, output_enabled, totrate, totdist, | 3176 subsize, output_enabled, rd_cost, |
| 3112 pc_tree->split[0]); | 3177 pc_tree->split[0]); |
| 3113 nonrd_use_partition(cpi, tile, mi + hbs, tp, | 3178 nonrd_use_partition(cpi, tile_data, mi + hbs, tp, |
| 3114 mi_row, mi_col + hbs, subsize, output_enabled, | 3179 mi_row, mi_col + hbs, subsize, output_enabled, |
| 3115 &rate, &dist, pc_tree->split[1]); | 3180 &this_rdc, pc_tree->split[1]); |
| 3116 if (rate != INT_MAX && dist != INT64_MAX && | 3181 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3117 *totrate != INT_MAX && *totdist != INT64_MAX) { | 3182 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3118 *totrate += rate; | 3183 rd_cost->rate += this_rdc.rate; |
| 3119 *totdist += dist; | 3184 rd_cost->dist += this_rdc.dist; |
| 3120 } | 3185 } |
| 3121 nonrd_use_partition(cpi, tile, mi + hbs * mis, tp, | 3186 nonrd_use_partition(cpi, tile_data, mi + hbs * mis, tp, |
| 3122 mi_row + hbs, mi_col, subsize, output_enabled, | 3187 mi_row + hbs, mi_col, subsize, output_enabled, |
| 3123 &rate, &dist, pc_tree->split[2]); | 3188 &this_rdc, pc_tree->split[2]); |
| 3124 if (rate != INT_MAX && dist != INT64_MAX && | 3189 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3125 *totrate != INT_MAX && *totdist != INT64_MAX) { | 3190 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3126 *totrate += rate; | 3191 rd_cost->rate += this_rdc.rate; |
| 3127 *totdist += dist; | 3192 rd_cost->dist += this_rdc.dist; |
| 3128 } | 3193 } |
| 3129 nonrd_use_partition(cpi, tile, mi + hbs * mis + hbs, tp, | 3194 nonrd_use_partition(cpi, tile_data, mi + hbs * mis + hbs, tp, |
| 3130 mi_row + hbs, mi_col + hbs, subsize, output_enabled, | 3195 mi_row + hbs, mi_col + hbs, subsize, output_enabled, |
| 3131 &rate, &dist, pc_tree->split[3]); | 3196 &this_rdc, pc_tree->split[3]); |
| 3132 if (rate != INT_MAX && dist != INT64_MAX && | 3197 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
| 3133 *totrate != INT_MAX && *totdist != INT64_MAX) { | 3198 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
| 3134 *totrate += rate; | 3199 rd_cost->rate += this_rdc.rate; |
| 3135 *totdist += dist; | 3200 rd_cost->dist += this_rdc.dist; |
| 3136 } | 3201 } |
| 3137 break; | 3202 break; |
| 3138 default: | 3203 default: |
| 3139 assert("Invalid partition type."); | 3204 assert("Invalid partition type."); |
| 3140 break; | 3205 break; |
| 3141 } | 3206 } |
| 3142 | 3207 |
| 3143 if (bsize == BLOCK_64X64 && output_enabled) { | 3208 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
| 3144 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) | 3209 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
| 3145 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, | |
| 3146 *totrate, *totdist); | |
| 3147 encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, bsize, pc_tree); | |
| 3148 } | |
| 3149 } | 3210 } |
| 3150 | 3211 |
| 3151 static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, | 3212 static void encode_nonrd_sb_row(VP9_COMP *cpi, |
| 3152 int mi_row, TOKENEXTRA **tp) { | 3213 TileDataEnc *tile_data, |
| 3214 int mi_row, |
| 3215 TOKENEXTRA **tp) { |
| 3153 SPEED_FEATURES *const sf = &cpi->sf; | 3216 SPEED_FEATURES *const sf = &cpi->sf; |
| 3154 VP9_COMMON *const cm = &cpi->common; | 3217 VP9_COMMON *const cm = &cpi->common; |
| 3218 TileInfo *const tile_info = &tile_data->tile_info; |
| 3155 MACROBLOCK *const x = &cpi->mb; | 3219 MACROBLOCK *const x = &cpi->mb; |
| 3156 MACROBLOCKD *const xd = &x->e_mbd; | 3220 MACROBLOCKD *const xd = &x->e_mbd; |
| 3157 int mi_col; | 3221 int mi_col; |
| 3158 | 3222 |
| 3159 // Initialize the left context for the new SB row | 3223 // Initialize the left context for the new SB row |
| 3160 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); | 3224 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); |
| 3161 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); | 3225 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); |
| 3162 | 3226 |
| 3163 // Code each SB in the row | 3227 // Code each SB in the row |
| 3164 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; | 3228 for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; |
| 3165 mi_col += MI_BLOCK_SIZE) { | 3229 mi_col += MI_BLOCK_SIZE) { |
| 3166 int dummy_rate = 0; | 3230 RD_COST dummy_rdc; |
| 3167 int64_t dummy_dist = 0; | |
| 3168 const int idx_str = cm->mi_stride * mi_row + mi_col; | 3231 const int idx_str = cm->mi_stride * mi_row + mi_col; |
| 3169 MODE_INFO *mi = cm->mi + idx_str; | 3232 MODE_INFO *mi = cm->mi + idx_str; |
| 3170 BLOCK_SIZE bsize; | 3233 BLOCK_SIZE bsize; |
| 3171 x->in_static_area = 0; | |
| 3172 x->source_variance = UINT_MAX; | 3234 x->source_variance = UINT_MAX; |
| 3173 vp9_zero(x->pred_mv); | 3235 vp9_zero(x->pred_mv); |
| 3236 vp9_rd_cost_init(&dummy_rdc); |
| 3174 | 3237 |
| 3175 // Set the partition type of the 64X64 block | 3238 // Set the partition type of the 64X64 block |
| 3176 switch (sf->partition_search_type) { | 3239 switch (sf->partition_search_type) { |
| 3177 case VAR_BASED_PARTITION: | 3240 case VAR_BASED_PARTITION: |
| 3178 choose_partitioning(cpi, tile, mi_row, mi_col); | 3241 choose_partitioning(cpi, tile_info, mi_row, mi_col); |
| 3179 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 3242 nonrd_use_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 3180 1, &dummy_rate, &dummy_dist, cpi->pc_root); | 3243 BLOCK_64X64, 1, &dummy_rdc, cpi->pc_root); |
| 3181 break; | 3244 break; |
| 3182 case SOURCE_VAR_BASED_PARTITION: | 3245 case SOURCE_VAR_BASED_PARTITION: |
| 3183 set_source_var_based_partition(cpi, tile, mi, mi_row, mi_col); | 3246 set_source_var_based_partition(cpi, tile_info, mi, mi_row, mi_col); |
| 3184 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 3247 nonrd_use_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 3185 1, &dummy_rate, &dummy_dist, cpi->pc_root); | 3248 BLOCK_64X64, 1, &dummy_rdc, cpi->pc_root); |
| 3186 break; | 3249 break; |
| 3187 case FIXED_PARTITION: | 3250 case FIXED_PARTITION: |
| 3188 bsize = sf->partition_search_type == FIXED_PARTITION ? | 3251 bsize = sf->partition_search_type == FIXED_PARTITION ? |
| 3189 sf->always_this_block_size : | 3252 sf->always_this_block_size : |
| 3190 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); | 3253 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); |
| 3191 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); | 3254 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); |
| 3192 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 3255 nonrd_use_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 3193 1, &dummy_rate, &dummy_dist, cpi->pc_root); | 3256 BLOCK_64X64, 1, &dummy_rdc, cpi->pc_root); |
| 3194 break; | 3257 break; |
| 3195 case REFERENCE_PARTITION: | 3258 case REFERENCE_PARTITION: |
| 3196 if (sf->partition_check || | 3259 set_offsets(cpi, tile_info, mi_row, mi_col, BLOCK_64X64); |
| 3197 !(x->in_static_area = is_background(cpi, tile, mi_row, mi_col))) { | 3260 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled && |
| 3198 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 3261 xd->mi[0].src_mi->mbmi.segment_id) { |
| 3199 auto_partition_range(cpi, tile, mi_row, mi_col, | 3262 auto_partition_range(cpi, tile_info, mi_row, mi_col, |
| 3200 &sf->min_partition_size, | 3263 &x->min_partition_size, |
| 3201 &sf->max_partition_size); | 3264 &x->max_partition_size); |
| 3202 nonrd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 3265 nonrd_pick_partition(cpi, tile_data, tp, mi_row, mi_col, |
| 3203 &dummy_rate, &dummy_dist, 1, INT64_MAX, | 3266 BLOCK_64X64, &dummy_rdc, 1, |
| 3204 cpi->pc_root); | 3267 INT64_MAX, cpi->pc_root); |
| 3205 } else { | 3268 } else { |
| 3206 choose_partitioning(cpi, tile, mi_row, mi_col); | 3269 choose_partitioning(cpi, tile_info, mi_row, mi_col); |
| 3207 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, | 3270 nonrd_select_partition(cpi, tile_data, mi, tp, mi_row, mi_col, |
| 3208 BLOCK_64X64, 1, &dummy_rate, &dummy_dist, | 3271 BLOCK_64X64, 1, &dummy_rdc, cpi->pc_root); |
| 3209 cpi->pc_root); | |
| 3210 } | 3272 } |
| 3273 |
| 3211 break; | 3274 break; |
| 3212 default: | 3275 default: |
| 3213 assert(0); | 3276 assert(0); |
| 3214 break; | 3277 break; |
| 3215 } | 3278 } |
| 3216 } | 3279 } |
| 3217 } | 3280 } |
| 3218 // end RTC play code | 3281 // end RTC play code |
| 3219 | 3282 |
| 3220 static int set_var_thresh_from_histogram(VP9_COMP *cpi) { | 3283 static int set_var_thresh_from_histogram(VP9_COMP *cpi) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3336 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { | 3399 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { |
| 3337 intra_count += cm->counts.intra_inter[j][0]; | 3400 intra_count += cm->counts.intra_inter[j][0]; |
| 3338 inter_count += cm->counts.intra_inter[j][1]; | 3401 inter_count += cm->counts.intra_inter[j][1]; |
| 3339 } | 3402 } |
| 3340 | 3403 |
| 3341 return (intra_count << 2) < inter_count && | 3404 return (intra_count << 2) < inter_count && |
| 3342 cm->frame_type != KEY_FRAME && | 3405 cm->frame_type != KEY_FRAME && |
| 3343 cm->show_frame; | 3406 cm->show_frame; |
| 3344 } | 3407 } |
| 3345 | 3408 |
| 3409 static void tile_data_init(TileDataEnc *tile_data) { |
| 3410 int i, j; |
| 3411 for (i = 0; i < BLOCK_SIZES; ++i) { |
| 3412 for (j = 0; j < MAX_MODES; ++j) { |
| 3413 tile_data->thresh_freq_fact[i][j] = 32; |
| 3414 tile_data->mode_map[i][j] = j; |
| 3415 } |
| 3416 } |
| 3417 } |
| 3418 |
| 3346 static void encode_tiles(VP9_COMP *cpi) { | 3419 static void encode_tiles(VP9_COMP *cpi) { |
| 3347 const VP9_COMMON *const cm = &cpi->common; | 3420 VP9_COMMON *const cm = &cpi->common; |
| 3348 const int tile_cols = 1 << cm->log2_tile_cols; | 3421 const int tile_cols = 1 << cm->log2_tile_cols; |
| 3349 const int tile_rows = 1 << cm->log2_tile_rows; | 3422 const int tile_rows = 1 << cm->log2_tile_rows; |
| 3350 | 3423 |
| 3351 int tile_col, tile_row; | 3424 int tile_col, tile_row; |
| 3352 TileInfo tile[4][1 << 6]; | |
| 3353 TOKENEXTRA *tok[4][1 << 6]; | 3425 TOKENEXTRA *tok[4][1 << 6]; |
| 3354 TOKENEXTRA *pre_tok = cpi->tok; | 3426 TOKENEXTRA *pre_tok = cpi->tok; |
| 3355 int tile_tok = 0; | 3427 int tile_tok = 0; |
| 3356 | 3428 |
| 3429 if (cpi->tile_data == NULL) { |
| 3430 CHECK_MEM_ERROR(cm, cpi->tile_data, |
| 3431 vpx_malloc(tile_cols * tile_rows * sizeof(*cpi->tile_data))); |
| 3432 for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
| 3433 for (tile_col = 0; tile_col < tile_cols; ++tile_col) |
| 3434 tile_data_init(&cpi->tile_data[tile_row * tile_cols + tile_col]); |
| 3435 } |
| 3436 |
| 3357 for (tile_row = 0; tile_row < tile_rows; ++tile_row) { | 3437 for (tile_row = 0; tile_row < tile_rows; ++tile_row) { |
| 3358 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { | 3438 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 3359 vp9_tile_init(&tile[tile_row][tile_col], cm, tile_row, tile_col); | 3439 TileInfo *tile_info = |
| 3440 &cpi->tile_data[tile_row * tile_cols + tile_col].tile_info; |
| 3441 vp9_tile_init(tile_info, cm, tile_row, tile_col); |
| 3360 | 3442 |
| 3361 tok[tile_row][tile_col] = pre_tok + tile_tok; | 3443 tok[tile_row][tile_col] = pre_tok + tile_tok; |
| 3362 pre_tok = tok[tile_row][tile_col]; | 3444 pre_tok = tok[tile_row][tile_col]; |
| 3363 tile_tok = allocated_tokens(tile[tile_row][tile_col]); | 3445 tile_tok = allocated_tokens(*tile_info); |
| 3364 } | 3446 } |
| 3365 } | 3447 } |
| 3366 | 3448 |
| 3367 for (tile_row = 0; tile_row < tile_rows; ++tile_row) { | 3449 for (tile_row = 0; tile_row < tile_rows; ++tile_row) { |
| 3368 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { | 3450 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 3369 const TileInfo * const ptile = &tile[tile_row][tile_col]; | 3451 const TileInfo * const tile_info = |
| 3452 &cpi->tile_data[tile_row * tile_cols + tile_col].tile_info; |
| 3370 TOKENEXTRA * const old_tok = tok[tile_row][tile_col]; | 3453 TOKENEXTRA * const old_tok = tok[tile_row][tile_col]; |
| 3371 int mi_row; | 3454 int mi_row; |
| 3455 TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 3372 | 3456 |
| 3373 for (mi_row = ptile->mi_row_start; mi_row < ptile->mi_row_end; | 3457 for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end; |
| 3374 mi_row += MI_BLOCK_SIZE) { | 3458 mi_row += MI_BLOCK_SIZE) { |
| 3375 if (cpi->sf.use_nonrd_pick_mode && !frame_is_intra_only(cm)) | 3459 if (cpi->sf.use_nonrd_pick_mode && !frame_is_intra_only(cm)) |
| 3376 encode_nonrd_sb_row(cpi, ptile, mi_row, &tok[tile_row][tile_col]); | 3460 encode_nonrd_sb_row(cpi, this_tile, mi_row, &tok[tile_row][tile_col]); |
| 3377 else | 3461 else |
| 3378 encode_rd_sb_row(cpi, ptile, mi_row, &tok[tile_row][tile_col]); | 3462 encode_rd_sb_row(cpi, this_tile, mi_row, &tok[tile_row][tile_col]); |
| 3379 } | 3463 } |
| 3380 cpi->tok_count[tile_row][tile_col] = | 3464 cpi->tok_count[tile_row][tile_col] = |
| 3381 (unsigned int)(tok[tile_row][tile_col] - old_tok); | 3465 (unsigned int)(tok[tile_row][tile_col] - old_tok); |
| 3382 assert(tok[tile_row][tile_col] - old_tok <= allocated_tokens(*ptile)); | 3466 assert(tok[tile_row][tile_col] - old_tok <= allocated_tokens(*tile_info)); |
| 3383 } | 3467 } |
| 3384 } | 3468 } |
| 3385 } | 3469 } |
| 3386 | 3470 |
| 3387 #if CONFIG_FP_MB_STATS | 3471 #if CONFIG_FP_MB_STATS |
| 3388 static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats, | 3472 static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats, |
| 3389 VP9_COMMON *cm, uint8_t **this_frame_mb_stats) { | 3473 VP9_COMMON *cm, uint8_t **this_frame_mb_stats) { |
| 3390 uint8_t *mb_stats_in = firstpass_mb_stats->mb_stats_start + | 3474 uint8_t *mb_stats_in = firstpass_mb_stats->mb_stats_start + |
| 3391 cm->current_video_frame * cm->MBs * sizeof(uint8_t); | 3475 cm->current_video_frame * cm->MBs * sizeof(uint8_t); |
| 3392 | 3476 |
| 3393 if (mb_stats_in > firstpass_mb_stats->mb_stats_end) | 3477 if (mb_stats_in > firstpass_mb_stats->mb_stats_end) |
| 3394 return EOF; | 3478 return EOF; |
| 3395 | 3479 |
| 3396 *this_frame_mb_stats = mb_stats_in; | 3480 *this_frame_mb_stats = mb_stats_in; |
| 3397 | 3481 |
| 3398 return 1; | 3482 return 1; |
| 3399 } | 3483 } |
| 3400 #endif | 3484 #endif |
| 3401 | 3485 |
| 3402 static void encode_frame_internal(VP9_COMP *cpi) { | 3486 static void encode_frame_internal(VP9_COMP *cpi) { |
| 3403 SPEED_FEATURES *const sf = &cpi->sf; | 3487 SPEED_FEATURES *const sf = &cpi->sf; |
| 3404 RD_OPT *const rd_opt = &cpi->rd; | 3488 RD_OPT *const rd_opt = &cpi->rd; |
| 3405 MACROBLOCK *const x = &cpi->mb; | 3489 MACROBLOCK *const x = &cpi->mb; |
| 3406 VP9_COMMON *const cm = &cpi->common; | 3490 VP9_COMMON *const cm = &cpi->common; |
| 3407 MACROBLOCKD *const xd = &x->e_mbd; | 3491 MACROBLOCKD *const xd = &x->e_mbd; |
| 3492 COUNTS *const counts = cpi->frame_counts; |
| 3408 | 3493 |
| 3409 xd->mi = cm->mi; | 3494 xd->mi = cm->mi; |
| 3410 xd->mi[0].src_mi = &xd->mi[0]; | 3495 xd->mi[0].src_mi = &xd->mi[0]; |
| 3411 | 3496 |
| 3412 vp9_zero(cm->counts); | 3497 vp9_zero(cm->counts); |
| 3413 vp9_zero(cpi->coef_counts); | 3498 vp9_zero(counts->coef_counts); |
| 3414 vp9_zero(rd_opt->comp_pred_diff); | 3499 vp9_zero(counts->comp_pred_diff); |
| 3415 vp9_zero(rd_opt->filter_diff); | 3500 vp9_zero(counts->filter_diff); |
| 3416 vp9_zero(rd_opt->tx_select_diff); | 3501 vp9_zero(counts->tx_select_diff); |
| 3417 vp9_zero(rd_opt->tx_select_threshes); | 3502 vp9_zero(rd_opt->tx_select_threshes); |
| 3418 | 3503 |
| 3419 xd->lossless = cm->base_qindex == 0 && | 3504 xd->lossless = cm->base_qindex == 0 && |
| 3420 cm->y_dc_delta_q == 0 && | 3505 cm->y_dc_delta_q == 0 && |
| 3421 cm->uv_dc_delta_q == 0 && | 3506 cm->uv_dc_delta_q == 0 && |
| 3422 cm->uv_ac_delta_q == 0; | 3507 cm->uv_ac_delta_q == 0; |
| 3423 | 3508 |
| 3424 cm->tx_mode = select_tx_mode(cpi); | 3509 cm->tx_mode = select_tx_mode(cpi); |
| 3425 | 3510 |
| 3426 #if CONFIG_VP9_HIGHBITDEPTH | 3511 #if CONFIG_VP9_HIGHBITDEPTH |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3440 cm->lf.filter_level = 0; | 3525 cm->lf.filter_level = 0; |
| 3441 cpi->zbin_mode_boost_enabled = 0; | 3526 cpi->zbin_mode_boost_enabled = 0; |
| 3442 } | 3527 } |
| 3443 | 3528 |
| 3444 vp9_frame_init_quantizer(cpi); | 3529 vp9_frame_init_quantizer(cpi); |
| 3445 | 3530 |
| 3446 vp9_initialize_rd_consts(cpi); | 3531 vp9_initialize_rd_consts(cpi); |
| 3447 vp9_initialize_me_consts(cpi, cm->base_qindex); | 3532 vp9_initialize_me_consts(cpi, cm->base_qindex); |
| 3448 init_encode_frame_mb_context(cpi); | 3533 init_encode_frame_mb_context(cpi); |
| 3449 set_prev_mi(cm); | 3534 set_prev_mi(cm); |
| 3535 cm->use_prev_frame_mvs = !cm->error_resilient_mode && |
| 3536 cm->width == cm->last_width && |
| 3537 cm->height == cm->last_height && |
| 3538 !cm->intra_only && |
| 3539 cm->last_show_frame; |
| 3450 | 3540 |
| 3451 x->quant_fp = cpi->sf.use_quant_fp; | 3541 x->quant_fp = cpi->sf.use_quant_fp; |
| 3452 vp9_zero(x->skip_txfm); | 3542 vp9_zero(x->skip_txfm); |
| 3453 if (sf->use_nonrd_pick_mode) { | 3543 if (sf->use_nonrd_pick_mode) { |
| 3454 // Initialize internal buffer pointers for rtc coding, where non-RD | 3544 // Initialize internal buffer pointers for rtc coding, where non-RD |
| 3455 // mode decision is used and hence no buffer pointer swap needed. | 3545 // mode decision is used and hence no buffer pointer swap needed. |
| 3456 int i; | 3546 int i; |
| 3457 struct macroblock_plane *const p = x->plane; | 3547 struct macroblock_plane *const p = x->plane; |
| 3458 struct macroblockd_plane *const pd = xd->plane; | 3548 struct macroblockd_plane *const pd = xd->plane; |
| 3459 PICK_MODE_CONTEXT *ctx = &cpi->pc_root->none; | 3549 PICK_MODE_CONTEXT *ctx = &cpi->pc_root->none; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3508 } else if (threshes[EIGHTTAP] > threshes[SWITCHABLE - 1]) { | 3598 } else if (threshes[EIGHTTAP] > threshes[SWITCHABLE - 1]) { |
| 3509 return EIGHTTAP; | 3599 return EIGHTTAP; |
| 3510 } else { | 3600 } else { |
| 3511 return SWITCHABLE; | 3601 return SWITCHABLE; |
| 3512 } | 3602 } |
| 3513 } | 3603 } |
| 3514 | 3604 |
| 3515 void vp9_encode_frame(VP9_COMP *cpi) { | 3605 void vp9_encode_frame(VP9_COMP *cpi) { |
| 3516 VP9_COMMON *const cm = &cpi->common; | 3606 VP9_COMMON *const cm = &cpi->common; |
| 3517 RD_OPT *const rd_opt = &cpi->rd; | 3607 RD_OPT *const rd_opt = &cpi->rd; |
| 3608 COUNTS *const counts = cpi->frame_counts; |
| 3518 | 3609 |
| 3519 // In the longer term the encoder should be generalized to match the | 3610 // In the longer term the encoder should be generalized to match the |
| 3520 // decoder such that we allow compound where one of the 3 buffers has a | 3611 // decoder such that we allow compound where one of the 3 buffers has a |
| 3521 // different sign bias and that buffer is then the fixed ref. However, this | 3612 // different sign bias and that buffer is then the fixed ref. However, this |
| 3522 // requires further work in the rd loop. For now the only supported encoder | 3613 // requires further work in the rd loop. For now the only supported encoder |
| 3523 // side behavior is where the ALT ref buffer has opposite sign bias to | 3614 // side behavior is where the ALT ref buffer has opposite sign bias to |
| 3524 // the other two. | 3615 // the other two. |
| 3525 if (!frame_is_intra_only(cm)) { | 3616 if (!frame_is_intra_only(cm)) { |
| 3526 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] == | 3617 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] == |
| 3527 cm->ref_frame_sign_bias[GOLDEN_FRAME]) || | 3618 cm->ref_frame_sign_bias[GOLDEN_FRAME]) || |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3565 cm->reference_mode = SINGLE_REFERENCE; | 3656 cm->reference_mode = SINGLE_REFERENCE; |
| 3566 else | 3657 else |
| 3567 cm->reference_mode = REFERENCE_MODE_SELECT; | 3658 cm->reference_mode = REFERENCE_MODE_SELECT; |
| 3568 | 3659 |
| 3569 if (cm->interp_filter == SWITCHABLE) | 3660 if (cm->interp_filter == SWITCHABLE) |
| 3570 cm->interp_filter = get_interp_filter(filter_thrs, is_alt_ref); | 3661 cm->interp_filter = get_interp_filter(filter_thrs, is_alt_ref); |
| 3571 | 3662 |
| 3572 encode_frame_internal(cpi); | 3663 encode_frame_internal(cpi); |
| 3573 | 3664 |
| 3574 for (i = 0; i < REFERENCE_MODES; ++i) | 3665 for (i = 0; i < REFERENCE_MODES; ++i) |
| 3575 mode_thrs[i] = (mode_thrs[i] + rd_opt->comp_pred_diff[i] / cm->MBs) / 2; | 3666 mode_thrs[i] = (mode_thrs[i] + counts->comp_pred_diff[i] / cm->MBs) / 2; |
| 3576 | 3667 |
| 3577 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) | 3668 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) |
| 3578 filter_thrs[i] = (filter_thrs[i] + rd_opt->filter_diff[i] / cm->MBs) / 2; | 3669 filter_thrs[i] = (filter_thrs[i] + counts->filter_diff[i] / cm->MBs) / 2; |
| 3579 | 3670 |
| 3580 for (i = 0; i < TX_MODES; ++i) { | 3671 for (i = 0; i < TX_MODES; ++i) { |
| 3581 int64_t pd = rd_opt->tx_select_diff[i]; | 3672 int64_t pd = counts->tx_select_diff[i]; |
| 3582 if (i == TX_MODE_SELECT) | 3673 if (i == TX_MODE_SELECT) |
| 3583 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, 2048 * (TX_SIZES - 1), 0); | 3674 pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, 2048 * (TX_SIZES - 1), 0); |
| 3584 tx_thrs[i] = (tx_thrs[i] + (int)(pd / cm->MBs)) / 2; | 3675 tx_thrs[i] = (tx_thrs[i] + (int)(pd / cm->MBs)) / 2; |
| 3585 } | 3676 } |
| 3586 | 3677 |
| 3587 if (cm->reference_mode == REFERENCE_MODE_SELECT) { | 3678 if (cm->reference_mode == REFERENCE_MODE_SELECT) { |
| 3588 int single_count_zero = 0; | 3679 int single_count_zero = 0; |
| 3589 int comp_count_zero = 0; | 3680 int comp_count_zero = 0; |
| 3590 | 3681 |
| 3591 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { | 3682 for (i = 0; i < COMP_INTER_CONTEXTS; i++) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3730 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 3821 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
| 3731 } else { | 3822 } else { |
| 3732 int ref; | 3823 int ref; |
| 3733 const int is_compound = has_second_ref(mbmi); | 3824 const int is_compound = has_second_ref(mbmi); |
| 3734 for (ref = 0; ref < 1 + is_compound; ++ref) { | 3825 for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 3735 YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, | 3826 YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, |
| 3736 mbmi->ref_frame[ref]); | 3827 mbmi->ref_frame[ref]); |
| 3737 vp9_setup_pre_planes(xd, ref, cfg, mi_row, mi_col, | 3828 vp9_setup_pre_planes(xd, ref, cfg, mi_row, mi_col, |
| 3738 &xd->block_refs[ref]->sf); | 3829 &xd->block_refs[ref]->sf); |
| 3739 } | 3830 } |
| 3740 if (!cpi->sf.reuse_inter_pred_sby || seg_skip) | 3831 if (!(cpi->sf.reuse_inter_pred_sby && ctx->pred_pixel_ready) || seg_skip) |
| 3741 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); | 3832 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
| 3742 | 3833 |
| 3743 vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); | 3834 vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
| 3744 | 3835 |
| 3745 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); | 3836 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); |
| 3746 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 3837 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
| 3747 } | 3838 } |
| 3748 | 3839 |
| 3749 if (output_enabled) { | 3840 if (output_enabled) { |
| 3750 if (cm->tx_mode == TX_MODE_SELECT && | 3841 if (cm->tx_mode == TX_MODE_SELECT && |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3763 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; | 3854 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; |
| 3764 } | 3855 } |
| 3765 | 3856 |
| 3766 for (y = 0; y < mi_height; y++) | 3857 for (y = 0; y < mi_height; y++) |
| 3767 for (x = 0; x < mi_width; x++) | 3858 for (x = 0; x < mi_width; x++) |
| 3768 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 3859 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
| 3769 mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size; | 3860 mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size; |
| 3770 } | 3861 } |
| 3771 } | 3862 } |
| 3772 } | 3863 } |
| OLD | NEW |