OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 xd->mi[0].src_mi->mbmi.tx_size > TX_16X16) | 242 xd->mi[0].src_mi->mbmi.tx_size > TX_16X16) |
243 xd->mi[0].src_mi->mbmi.tx_size = TX_16X16; | 243 xd->mi[0].src_mi->mbmi.tx_size = TX_16X16; |
244 } else { | 244 } else { |
245 xd->mi[0].src_mi->mbmi.tx_size = | 245 xd->mi[0].src_mi->mbmi.tx_size = |
246 MIN(max_txsize_lookup[bsize], | 246 MIN(max_txsize_lookup[bsize], |
247 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 247 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
248 } | 248 } |
249 | 249 |
250 #if CONFIG_VP9_HIGHBITDEPTH | 250 #if CONFIG_VP9_HIGHBITDEPTH |
251 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 251 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
252 vp9_model_rd_from_var_lapndz(sse - var, 1 << num_pels_log2_lookup[bsize], | 252 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], |
253 dc_quant >> (xd->bd - 5), &rate, &dist); | 253 dc_quant >> (xd->bd - 5), &rate, &dist); |
254 } else { | 254 } else { |
255 vp9_model_rd_from_var_lapndz(sse - var, 1 << num_pels_log2_lookup[bsize], | 255 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], |
256 dc_quant >> 3, &rate, &dist); | 256 dc_quant >> 3, &rate, &dist); |
257 } | 257 } |
258 #else | 258 #else |
259 vp9_model_rd_from_var_lapndz(sse - var, 1 << num_pels_log2_lookup[bsize], | 259 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], |
260 dc_quant >> 3, &rate, &dist); | 260 dc_quant >> 3, &rate, &dist); |
261 #endif // CONFIG_VP9_HIGHBITDEPTH | 261 #endif // CONFIG_VP9_HIGHBITDEPTH |
262 | 262 |
263 *out_rate_sum = rate >> 1; | 263 *out_rate_sum = rate >> 1; |
264 *out_dist_sum = dist << 3; | 264 *out_dist_sum = dist << 3; |
265 | 265 |
266 #if CONFIG_VP9_HIGHBITDEPTH | 266 #if CONFIG_VP9_HIGHBITDEPTH |
267 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 267 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
268 vp9_model_rd_from_var_lapndz(var, 1 << num_pels_log2_lookup[bsize], | 268 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], |
269 ac_quant >> (xd->bd - 5), &rate, &dist); | 269 ac_quant >> (xd->bd - 5), &rate, &dist); |
270 } else { | 270 } else { |
271 vp9_model_rd_from_var_lapndz(var, 1 << num_pels_log2_lookup[bsize], | 271 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], |
272 ac_quant >> 3, &rate, &dist); | 272 ac_quant >> 3, &rate, &dist); |
273 } | 273 } |
274 #else | 274 #else |
275 vp9_model_rd_from_var_lapndz(var, 1 << num_pels_log2_lookup[bsize], | 275 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], |
276 ac_quant >> 3, &rate, &dist); | 276 ac_quant >> 3, &rate, &dist); |
277 #endif // CONFIG_VP9_HIGHBITDEPTH | 277 #endif // CONFIG_VP9_HIGHBITDEPTH |
278 | 278 |
279 *out_rate_sum += rate; | 279 *out_rate_sum += rate; |
280 *out_dist_sum += dist << 4; | 280 *out_dist_sum += dist << 4; |
281 | 281 |
282 if (*out_rate_sum == 0) | 282 if (*out_rate_sum == 0) |
283 x->skip_txfm[0] = 1; | 283 x->skip_txfm[0] = 1; |
284 } | 284 } |
285 | 285 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 pd->dst.buf, dst_stride, | 440 pd->dst.buf, dst_stride, |
441 i, j, 0); | 441 i, j, 0); |
442 // This procedure assumes zero offset from p->src.buf and pd->dst.buf. | 442 // This procedure assumes zero offset from p->src.buf and pd->dst.buf. |
443 model_rd_for_sb_y(cpi, bsize_tx, x, xd, &rate, &dist, &var_y, &sse_y); | 443 model_rd_for_sb_y(cpi, bsize_tx, x, xd, &rate, &dist, &var_y, &sse_y); |
444 p->src.buf = src_buf_base; | 444 p->src.buf = src_buf_base; |
445 pd->dst.buf = dst_buf_base; | 445 pd->dst.buf = dst_buf_base; |
446 args->rate += rate; | 446 args->rate += rate; |
447 args->dist += dist; | 447 args->dist += dist; |
448 } | 448 } |
449 | 449 |
450 static const THR_MODES mode_idx[MAX_REF_FRAMES][4] = { | 450 static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][4] = { |
451 {THR_DC, THR_H_PRED, THR_V_PRED, THR_TM}, | 451 {THR_DC, THR_H_PRED, THR_V_PRED, THR_TM}, |
452 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV}, | 452 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV}, |
453 {THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG}, | 453 {THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG}, |
454 {THR_NEARESTA, THR_NEARA, THR_ZEROA, THR_NEWA}, | |
455 }; | 454 }; |
456 | 455 |
457 static const PREDICTION_MODE intra_mode_list[] = { | 456 static const PREDICTION_MODE intra_mode_list[] = { |
458 DC_PRED, V_PRED, H_PRED, TM_PRED | 457 DC_PRED, V_PRED, H_PRED, TM_PRED |
459 }; | 458 }; |
460 | 459 |
461 void vp9_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost, | 460 void vp9_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x, RD_COST *rd_cost, |
462 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { | 461 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { |
463 MACROBLOCKD *const xd = &x->e_mbd; | 462 MACROBLOCKD *const xd = &x->e_mbd; |
464 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 463 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 TileDataEnc *tile_data, | 514 TileDataEnc *tile_data, |
516 int mi_row, int mi_col, RD_COST *rd_cost, | 515 int mi_row, int mi_col, RD_COST *rd_cost, |
517 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { | 516 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { |
518 VP9_COMMON *const cm = &cpi->common; | 517 VP9_COMMON *const cm = &cpi->common; |
519 TileInfo *const tile_info = &tile_data->tile_info; | 518 TileInfo *const tile_info = &tile_data->tile_info; |
520 MACROBLOCKD *const xd = &x->e_mbd; | 519 MACROBLOCKD *const xd = &x->e_mbd; |
521 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 520 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
522 struct macroblockd_plane *const pd = &xd->plane[0]; | 521 struct macroblockd_plane *const pd = &xd->plane[0]; |
523 PREDICTION_MODE best_mode = ZEROMV; | 522 PREDICTION_MODE best_mode = ZEROMV; |
524 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; | 523 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; |
525 TX_SIZE best_tx_size = MIN(max_txsize_lookup[bsize], | 524 TX_SIZE best_tx_size = TX_SIZES; |
526 tx_mode_to_biggest_tx_size[cm->tx_mode]); | |
527 INTERP_FILTER best_pred_filter = EIGHTTAP; | 525 INTERP_FILTER best_pred_filter = EIGHTTAP; |
528 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 526 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
529 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 527 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
530 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 528 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
531 VP9_ALT_FLAG }; | 529 VP9_ALT_FLAG }; |
532 RD_COST this_rdc, best_rdc; | 530 RD_COST this_rdc, best_rdc; |
533 uint8_t skip_txfm = 0, best_mode_skip_txfm = 0; | 531 uint8_t skip_txfm = 0, best_mode_skip_txfm = 0; |
534 // var_y and sse_y are saved to be used in skipping checking | 532 // var_y and sse_y are saved to be used in skipping checking |
535 unsigned int var_y = UINT_MAX; | 533 unsigned int var_y = UINT_MAX; |
536 unsigned int sse_y = UINT_MAX; | 534 unsigned int sse_y = UINT_MAX; |
537 // Reduce the intra cost penalty for small blocks (<=16x16). | 535 // Reduce the intra cost penalty for small blocks (<=16x16). |
538 const int reduction_fac = | 536 const int reduction_fac = |
539 (cpi->sf.partition_search_type == VAR_BASED_PARTITION && | 537 (cpi->sf.partition_search_type == VAR_BASED_PARTITION && |
540 bsize <= BLOCK_16X16) ? 4 : 1; | 538 bsize <= BLOCK_16X16) ? 2 : 0; |
541 const int intra_cost_penalty = vp9_get_intra_cost_penalty( | 539 const int intra_cost_penalty = vp9_get_intra_cost_penalty( |
542 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth) / reduction_fac; | 540 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth) >> reduction_fac; |
543 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, | 541 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, |
544 intra_cost_penalty, 0); | 542 intra_cost_penalty, 0); |
545 const int8_t segment_id = mbmi->segment_id; | 543 const int *const rd_threshes = cpi->rd.threshes[mbmi->segment_id][bsize]; |
546 const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize]; | |
547 const int *const rd_thresh_freq_fact = tile_data->thresh_freq_fact[bsize]; | 544 const int *const rd_thresh_freq_fact = tile_data->thresh_freq_fact[bsize]; |
548 INTERP_FILTER filter_ref; | 545 INTERP_FILTER filter_ref; |
549 const int bsl = mi_width_log2_lookup[bsize]; | 546 const int bsl = mi_width_log2_lookup[bsize]; |
550 const int pred_filter_search = cm->interp_filter == SWITCHABLE ? | 547 const int pred_filter_search = cm->interp_filter == SWITCHABLE ? |
551 (((mi_row + mi_col) >> bsl) + | 548 (((mi_row + mi_col) >> bsl) + |
552 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; | 549 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; |
553 int const_motion[MAX_REF_FRAMES] = { 0 }; | 550 int const_motion[MAX_REF_FRAMES] = { 0 }; |
554 const int bh = num_4x4_blocks_high_lookup[bsize] << 2; | 551 const int bh = num_4x4_blocks_high_lookup[bsize] << 2; |
555 const int bw = num_4x4_blocks_wide_lookup[bsize] << 2; | 552 const int bw = num_4x4_blocks_wide_lookup[bsize] << 2; |
556 // For speed 6, the result of interp filter is reused later in actual encoding | 553 // For speed 6, the result of interp filter is reused later in actual encoding |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 | 589 |
593 if (xd->up_available) | 590 if (xd->up_available) |
594 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; | 591 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; |
595 else if (xd->left_available) | 592 else if (xd->left_available) |
596 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter; | 593 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter; |
597 else | 594 else |
598 filter_ref = cm->interp_filter; | 595 filter_ref = cm->interp_filter; |
599 | 596 |
600 // initialize mode decisions | 597 // initialize mode decisions |
601 vp9_rd_cost_reset(&best_rdc); | 598 vp9_rd_cost_reset(&best_rdc); |
602 vp9_rd_cost_reset(&this_rdc); | |
603 vp9_rd_cost_reset(rd_cost); | 599 vp9_rd_cost_reset(rd_cost); |
604 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); | |
605 mbmi->sb_type = bsize; | 600 mbmi->sb_type = bsize; |
606 mbmi->ref_frame[0] = NONE; | 601 mbmi->ref_frame[0] = NONE; |
607 mbmi->ref_frame[1] = NONE; | 602 mbmi->ref_frame[1] = NONE; |
608 mbmi->tx_size = MIN(max_txsize_lookup[bsize], | 603 mbmi->tx_size = MIN(max_txsize_lookup[bsize], |
609 tx_mode_to_biggest_tx_size[cm->tx_mode]); | 604 tx_mode_to_biggest_tx_size[cm->tx_mode]); |
610 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? | 605 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? |
611 EIGHTTAP : cm->interp_filter; | 606 EIGHTTAP : cm->interp_filter; |
612 mbmi->segment_id = segment_id; | 607 |
| 608 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 609 vp9_denoiser_reset_frame_stats(ctx); |
| 610 #endif |
613 | 611 |
614 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { | 612 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { |
615 x->pred_mv_sad[ref_frame] = INT_MAX; | 613 x->pred_mv_sad[ref_frame] = INT_MAX; |
616 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 614 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
617 frame_mv[ZEROMV][ref_frame].as_int = 0; | 615 frame_mv[ZEROMV][ref_frame].as_int = 0; |
618 | 616 |
619 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 617 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
620 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); | 618 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); |
621 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; | 619 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; |
622 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; | 620 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; |
623 | 621 |
624 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, | 622 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, |
625 sf, sf); | 623 sf, sf); |
626 | 624 |
627 if (!cm->error_resilient_mode) | 625 if (cm->use_prev_frame_mvs) |
628 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame, | 626 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame, |
629 candidates, mi_row, mi_col); | 627 candidates, mi_row, mi_col); |
630 else | 628 else |
631 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile_info, | 629 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile_info, |
632 xd->mi[0].src_mi, | 630 xd->mi[0].src_mi, |
633 ref_frame, candidates, | 631 ref_frame, candidates, |
634 mi_row, mi_col); | 632 mi_row, mi_col); |
635 | 633 |
636 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, | 634 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, |
637 &frame_mv[NEARESTMV][ref_frame], | 635 &frame_mv[NEARESTMV][ref_frame], |
(...skipping 21 matching lines...) Expand all Loading... |
659 if (ref_frame_skip_mask & (1 << ref_frame)) | 657 if (ref_frame_skip_mask & (1 << ref_frame)) |
660 continue; | 658 continue; |
661 | 659 |
662 // Select prediction reference frames. | 660 // Select prediction reference frames. |
663 xd->plane[0].pre[0] = yv12_mb[ref_frame][0]; | 661 xd->plane[0].pre[0] = yv12_mb[ref_frame][0]; |
664 | 662 |
665 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); | 663 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); |
666 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); | 664 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); |
667 | 665 |
668 mbmi->ref_frame[0] = ref_frame; | 666 mbmi->ref_frame[0] = ref_frame; |
| 667 set_ref_ptrs(cm, xd, ref_frame, NONE); |
669 | 668 |
670 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 669 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
671 int rate_mv = 0; | 670 int rate_mv = 0; |
672 int mode_rd_thresh; | 671 int mode_rd_thresh; |
673 int mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; | 672 int mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; |
674 | 673 |
675 if (const_motion[ref_frame] && this_mode == NEARMV) | 674 if (const_motion[ref_frame] && this_mode == NEARMV) |
676 continue; | 675 continue; |
677 | 676 |
678 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) | 677 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) |
679 continue; | 678 continue; |
680 | 679 |
681 mode_rd_thresh = best_mode_skip_txfm ? rd_threshes[mode_index] << 1 : | 680 mode_rd_thresh = best_mode_skip_txfm ? rd_threshes[mode_index] << 1 : |
682 rd_threshes[mode_index]; | 681 rd_threshes[mode_index]; |
683 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh, | 682 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh, |
684 rd_thresh_freq_fact[mode_index])) | 683 rd_thresh_freq_fact[mode_index])) |
685 continue; | 684 continue; |
686 | 685 |
687 if (this_mode == NEWMV) { | 686 if (this_mode == NEWMV) { |
688 if (ref_frame > LAST_FRAME) | 687 if (ref_frame > LAST_FRAME) |
689 continue; | 688 continue; |
690 if (cpi->sf.partition_search_type != VAR_BASED_PARTITION && | 689 if (cpi->sf.partition_search_type != VAR_BASED_PARTITION && |
691 this_rdc.rdcost < (int64_t)(1 << num_pels_log2_lookup[bsize])) | 690 best_rdc.rdcost < (int64_t)(1 << num_pels_log2_lookup[bsize])) |
692 continue; | 691 continue; |
693 if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, | 692 if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, |
694 &frame_mv[NEWMV][ref_frame], | 693 &frame_mv[NEWMV][ref_frame], |
695 &rate_mv, best_rdc.rdcost)) | 694 &rate_mv, best_rdc.rdcost)) |
696 continue; | 695 continue; |
697 } | 696 } |
698 | 697 |
699 if (this_mode != NEARESTMV && | 698 if (this_mode != NEARESTMV && |
700 frame_mv[this_mode][ref_frame].as_int == | 699 frame_mv[this_mode][ref_frame].as_int == |
701 frame_mv[NEARESTMV][ref_frame].as_int) | 700 frame_mv[NEARESTMV][ref_frame].as_int) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 mbmi->mode = best_mode; | 833 mbmi->mode = best_mode; |
835 mbmi->interp_filter = best_pred_filter; | 834 mbmi->interp_filter = best_pred_filter; |
836 mbmi->tx_size = best_tx_size; | 835 mbmi->tx_size = best_tx_size; |
837 mbmi->ref_frame[0] = best_ref_frame; | 836 mbmi->ref_frame[0] = best_ref_frame; |
838 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; | 837 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; |
839 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; | 838 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; |
840 x->skip_txfm[0] = best_mode_skip_txfm; | 839 x->skip_txfm[0] = best_mode_skip_txfm; |
841 | 840 |
842 // Perform intra prediction search, if the best SAD is above a certain | 841 // Perform intra prediction search, if the best SAD is above a certain |
843 // threshold. | 842 // threshold. |
844 if (!x->skip && best_rdc.rdcost > inter_mode_thresh && | 843 if (best_rdc.rdcost == INT64_MAX || |
845 bsize <= cpi->sf.max_intra_bsize) { | 844 (!x->skip && best_rdc.rdcost > inter_mode_thresh && |
| 845 bsize <= cpi->sf.max_intra_bsize)) { |
846 struct estimate_block_intra_args args = { cpi, x, DC_PRED, 0, 0 }; | 846 struct estimate_block_intra_args args = { cpi, x, DC_PRED, 0, 0 }; |
847 const TX_SIZE intra_tx_size = | 847 const TX_SIZE intra_tx_size = |
848 MIN(max_txsize_lookup[bsize], | 848 MIN(max_txsize_lookup[bsize], |
849 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 849 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
850 int i; | 850 int i; |
| 851 TX_SIZE best_intra_tx_size = TX_SIZES; |
851 | 852 |
852 if (reuse_inter_pred && best_pred != NULL) { | 853 if (reuse_inter_pred && best_pred != NULL) { |
853 if (best_pred->data == orig_dst.buf) { | 854 if (best_pred->data == orig_dst.buf) { |
854 this_mode_pred = &tmp[get_pred_buffer(tmp, 3)]; | 855 this_mode_pred = &tmp[get_pred_buffer(tmp, 3)]; |
| 856 #if CONFIG_VP9_HIGHBITDEPTH |
| 857 if (cm->use_highbitdepth) |
| 858 vp9_highbd_convolve_copy(best_pred->data, best_pred->stride, |
| 859 this_mode_pred->data, this_mode_pred->stride, |
| 860 NULL, 0, NULL, 0, bw, bh, xd->bd); |
| 861 else |
| 862 vp9_convolve_copy(best_pred->data, best_pred->stride, |
| 863 this_mode_pred->data, this_mode_pred->stride, |
| 864 NULL, 0, NULL, 0, bw, bh); |
| 865 #else |
855 vp9_convolve_copy(best_pred->data, best_pred->stride, | 866 vp9_convolve_copy(best_pred->data, best_pred->stride, |
856 this_mode_pred->data, this_mode_pred->stride, | 867 this_mode_pred->data, this_mode_pred->stride, |
857 NULL, 0, NULL, 0, bw, bh); | 868 NULL, 0, NULL, 0, bw, bh); |
| 869 #endif // CONFIG_VP9_HIGHBITDEPTH |
858 best_pred = this_mode_pred; | 870 best_pred = this_mode_pred; |
859 } | 871 } |
860 } | 872 } |
861 pd->dst = orig_dst; | 873 pd->dst = orig_dst; |
862 | 874 |
863 for (i = 0; i < 4; ++i) { | 875 for (i = 0; i < 4; ++i) { |
864 const TX_SIZE saved_tx_size = mbmi->tx_size; | |
865 const PREDICTION_MODE this_mode = intra_mode_list[i]; | 876 const PREDICTION_MODE this_mode = intra_mode_list[i]; |
866 if (!((1 << this_mode) & cpi->sf.intra_y_mode_mask[intra_tx_size])) | 877 if (!((1 << this_mode) & cpi->sf.intra_y_mode_mask[intra_tx_size])) |
867 continue; | 878 continue; |
868 skip_txfm = x->skip_txfm[0]; | |
869 args.mode = this_mode; | 879 args.mode = this_mode; |
870 args.rate = 0; | 880 args.rate = 0; |
871 args.dist = 0; | 881 args.dist = 0; |
872 mbmi->tx_size = intra_tx_size; | 882 mbmi->tx_size = intra_tx_size; |
873 vp9_foreach_transformed_block_in_plane(xd, bsize, 0, | 883 vp9_foreach_transformed_block_in_plane(xd, bsize, 0, |
874 estimate_block_intra, &args); | 884 estimate_block_intra, &args); |
875 this_rdc.rate = args.rate; | 885 this_rdc.rate = args.rate; |
876 this_rdc.dist = args.dist; | 886 this_rdc.dist = args.dist; |
877 this_rdc.rate += cpi->mbmode_cost[this_mode]; | 887 this_rdc.rate += cpi->mbmode_cost[this_mode]; |
878 this_rdc.rate += intra_cost_penalty; | 888 this_rdc.rate += intra_cost_penalty; |
879 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, | 889 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, |
880 this_rdc.rate, this_rdc.dist); | 890 this_rdc.rate, this_rdc.dist); |
881 | 891 |
882 if (this_rdc.rdcost < best_rdc.rdcost) { | 892 if (this_rdc.rdcost < best_rdc.rdcost) { |
883 best_rdc = this_rdc; | 893 best_rdc = this_rdc; |
884 mbmi->mode = this_mode; | 894 mbmi->mode = this_mode; |
885 mbmi->tx_size = intra_tx_size; | 895 best_intra_tx_size = mbmi->tx_size; |
886 mbmi->ref_frame[0] = INTRA_FRAME; | 896 mbmi->ref_frame[0] = INTRA_FRAME; |
887 mbmi->uv_mode = this_mode; | 897 mbmi->uv_mode = this_mode; |
888 mbmi->mv[0].as_int = INVALID_MV; | 898 mbmi->mv[0].as_int = INVALID_MV; |
889 } else { | |
890 x->skip_txfm[0] = best_mode_skip_txfm; | |
891 mbmi->tx_size = saved_tx_size; | |
892 } | 899 } |
893 } | 900 } |
| 901 |
| 902 // Reset mb_mode_info to the best inter mode. |
| 903 if (mbmi->ref_frame[0] != INTRA_FRAME) { |
| 904 x->skip_txfm[0] = best_mode_skip_txfm; |
| 905 mbmi->tx_size = best_tx_size; |
| 906 } else { |
| 907 mbmi->tx_size = best_intra_tx_size; |
| 908 } |
894 } | 909 } |
895 | 910 |
896 pd->dst = orig_dst; | 911 pd->dst = orig_dst; |
897 | 912 |
898 if (reuse_inter_pred && best_pred != NULL) { | 913 if (reuse_inter_pred && best_pred != NULL) { |
899 if (best_pred->data != orig_dst.buf && is_inter_mode(mbmi->mode)) { | 914 if (best_pred->data != orig_dst.buf && is_inter_mode(mbmi->mode)) { |
900 #if CONFIG_VP9_HIGHBITDEPTH | 915 #if CONFIG_VP9_HIGHBITDEPTH |
901 if (cm->use_highbitdepth) | 916 if (cm->use_highbitdepth) |
902 vp9_highbd_convolve_copy(best_pred->data, best_pred->stride, | 917 vp9_highbd_convolve_copy(best_pred->data, best_pred->stride, |
903 pd->dst.buf, pd->dst.stride, NULL, 0, | 918 pd->dst.buf, pd->dst.stride, NULL, 0, |
904 NULL, 0, bw, bh, xd->bd); | 919 NULL, 0, bw, bh, xd->bd); |
905 else | 920 else |
906 vp9_convolve_copy(best_pred->data, best_pred->stride, | 921 vp9_convolve_copy(best_pred->data, best_pred->stride, |
907 pd->dst.buf, pd->dst.stride, NULL, 0, | 922 pd->dst.buf, pd->dst.stride, NULL, 0, |
908 NULL, 0, bw, bh); | 923 NULL, 0, bw, bh); |
909 #else | 924 #else |
910 vp9_convolve_copy(best_pred->data, best_pred->stride, | 925 vp9_convolve_copy(best_pred->data, best_pred->stride, |
911 pd->dst.buf, pd->dst.stride, NULL, 0, | 926 pd->dst.buf, pd->dst.stride, NULL, 0, |
912 NULL, 0, bw, bh); | 927 NULL, 0, bw, bh); |
913 #endif | 928 #endif // CONFIG_VP9_HIGHBITDEPTH |
914 } | 929 } |
915 } | 930 } |
916 | 931 |
917 if (is_inter_block(mbmi)) | 932 if (cpi->sf.adaptive_rd_thresh) { |
918 vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact, | 933 THR_MODES best_mode_idx = is_inter_block(mbmi) ? |
919 cpi->sf.adaptive_rd_thresh, bsize, | 934 mode_idx[best_ref_frame][INTER_OFFSET(mbmi->mode)] : |
920 mode_idx[best_ref_frame][INTER_OFFSET(mbmi->mode)]); | 935 mode_idx[INTRA_FRAME][mbmi->mode]; |
921 else | 936 PREDICTION_MODE this_mode; |
922 vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact, | 937 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { |
923 cpi->sf.adaptive_rd_thresh, bsize, | 938 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
924 mode_idx[INTRA_FRAME][mbmi->mode]); | 939 THR_MODES thr_mode_idx = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; |
| 940 int *freq_fact = &tile_data->thresh_freq_fact[bsize][thr_mode_idx]; |
| 941 if (thr_mode_idx == best_mode_idx) |
| 942 *freq_fact -= (*freq_fact >> 4); |
| 943 else |
| 944 *freq_fact = MIN(*freq_fact + RD_THRESH_INC, |
| 945 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT); |
| 946 } |
| 947 } |
| 948 } |
925 | 949 |
926 *rd_cost = best_rdc; | 950 *rd_cost = best_rdc; |
927 } | 951 } |
| 952 |
| 953 void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, |
| 954 TileDataEnc *tile_data, |
| 955 int mi_row, int mi_col, RD_COST *rd_cost, |
| 956 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { |
| 957 VP9_COMMON *const cm = &cpi->common; |
| 958 TileInfo *const tile_info = &tile_data->tile_info; |
| 959 SPEED_FEATURES *const sf = &cpi->sf; |
| 960 MACROBLOCKD *const xd = &x->e_mbd; |
| 961 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 962 const struct segmentation *const seg = &cm->seg; |
| 963 MV_REFERENCE_FRAME ref_frame, second_ref_frame = NONE; |
| 964 MV_REFERENCE_FRAME best_ref_frame = NONE; |
| 965 unsigned char segment_id = mbmi->segment_id; |
| 966 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
| 967 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
| 968 VP9_ALT_FLAG }; |
| 969 int64_t best_rd = INT64_MAX; |
| 970 b_mode_info bsi[MAX_REF_FRAMES][4]; |
| 971 int ref_frame_skip_mask = 0; |
| 972 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 973 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 974 int idx, idy; |
| 975 |
| 976 x->skip_encode = sf->skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
| 977 ctx->pred_pixel_ready = 0; |
| 978 |
| 979 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { |
| 980 int_mv dummy_mv[2]; |
| 981 x->pred_mv_sad[ref_frame] = INT_MAX; |
| 982 |
| 983 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
| 984 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); |
| 985 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; |
| 986 const struct scale_factors *const sf = |
| 987 &cm->frame_refs[ref_frame - 1].sf; |
| 988 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, |
| 989 sf, sf); |
| 990 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame, |
| 991 candidates, mi_row, mi_col); |
| 992 |
| 993 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, |
| 994 &dummy_mv[0], &dummy_mv[1]); |
| 995 } else { |
| 996 ref_frame_skip_mask |= (1 << ref_frame); |
| 997 } |
| 998 } |
| 999 |
| 1000 mbmi->sb_type = bsize; |
| 1001 mbmi->tx_size = TX_4X4; |
| 1002 mbmi->uv_mode = DC_PRED; |
| 1003 mbmi->ref_frame[0] = LAST_FRAME; |
| 1004 mbmi->ref_frame[1] = NONE; |
| 1005 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP |
| 1006 : cm->interp_filter; |
| 1007 |
| 1008 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { |
| 1009 int64_t this_rd = 0; |
| 1010 int plane; |
| 1011 |
| 1012 if (ref_frame_skip_mask & (1 << ref_frame)) |
| 1013 continue; |
| 1014 |
| 1015 // TODO(jingning, agrange): Scaling reference frame not supported for |
| 1016 // sub8x8 blocks. Is this supported now? |
| 1017 if (ref_frame > INTRA_FRAME && |
| 1018 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) |
| 1019 continue; |
| 1020 |
| 1021 // If the segment reference frame feature is enabled.... |
| 1022 // then do nothing if the current ref frame is not allowed.. |
| 1023 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
| 1024 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) |
| 1025 continue; |
| 1026 |
| 1027 mbmi->ref_frame[0] = ref_frame; |
| 1028 x->skip = 0; |
| 1029 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); |
| 1030 |
| 1031 // Select prediction reference frames. |
| 1032 for (plane = 0; plane < MAX_MB_PLANE; plane++) |
| 1033 xd->plane[plane].pre[0] = yv12_mb[ref_frame][plane]; |
| 1034 |
| 1035 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
| 1036 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
| 1037 int_mv b_mv[MB_MODE_COUNT]; |
| 1038 int64_t b_best_rd = INT64_MAX; |
| 1039 const int i = idy * 2 + idx; |
| 1040 PREDICTION_MODE this_mode; |
| 1041 int b_rate = 0; |
| 1042 int64_t b_dist = 0; |
| 1043 RD_COST this_rdc; |
| 1044 unsigned int var_y, sse_y; |
| 1045 |
| 1046 struct macroblock_plane *p = &x->plane[0]; |
| 1047 struct macroblockd_plane *pd = &xd->plane[0]; |
| 1048 |
| 1049 const struct buf_2d orig_src = p->src; |
| 1050 const struct buf_2d orig_dst = pd->dst; |
| 1051 struct buf_2d orig_pre[2]; |
| 1052 vpx_memcpy(orig_pre, xd->plane[0].pre, sizeof(orig_pre)); |
| 1053 |
| 1054 // set buffer pointers for sub8x8 motion search. |
| 1055 p->src.buf = |
| 1056 &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)]; |
| 1057 pd->dst.buf = |
| 1058 &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i, pd->dst.stride)]; |
| 1059 pd->pre[0].buf = |
| 1060 &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8, |
| 1061 i, pd->pre[0].stride)]; |
| 1062 |
| 1063 b_mv[ZEROMV].as_int = 0; |
| 1064 b_mv[NEWMV].as_int = INVALID_MV; |
| 1065 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile_info, i, 0, mi_row, mi_col, |
| 1066 &b_mv[NEARESTMV], |
| 1067 &b_mv[NEARMV]); |
| 1068 |
| 1069 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
| 1070 xd->mi[0].bmi[i].as_mv[0].as_int = b_mv[this_mode].as_int; |
| 1071 |
| 1072 if (this_mode == NEWMV) { |
| 1073 const int step_param = cpi->sf.mv.fullpel_search_step_param; |
| 1074 MV mvp_full; |
| 1075 MV tmp_mv; |
| 1076 int cost_list[5]; |
| 1077 const int tmp_col_min = x->mv_col_min; |
| 1078 const int tmp_col_max = x->mv_col_max; |
| 1079 const int tmp_row_min = x->mv_row_min; |
| 1080 const int tmp_row_max = x->mv_row_max; |
| 1081 int dummy_dist; |
| 1082 |
| 1083 if (i == 0) { |
| 1084 mvp_full.row = b_mv[NEARESTMV].as_mv.row >> 3; |
| 1085 mvp_full.col = b_mv[NEARESTMV].as_mv.col >> 3; |
| 1086 } else { |
| 1087 mvp_full.row = xd->mi[0].bmi[0].as_mv[0].as_mv.row >> 3; |
| 1088 mvp_full.col = xd->mi[0].bmi[0].as_mv[0].as_mv.col >> 3; |
| 1089 } |
| 1090 |
| 1091 vp9_set_mv_search_range(x, &mbmi->ref_mvs[0]->as_mv); |
| 1092 |
| 1093 vp9_full_pixel_search( |
| 1094 cpi, x, bsize, &mvp_full, step_param, x->sadperbit4, |
| 1095 cond_cost_list(cpi, cost_list), |
| 1096 &mbmi->ref_mvs[ref_frame][0].as_mv, &tmp_mv, |
| 1097 INT_MAX, 0); |
| 1098 |
| 1099 x->mv_col_min = tmp_col_min; |
| 1100 x->mv_col_max = tmp_col_max; |
| 1101 x->mv_row_min = tmp_row_min; |
| 1102 x->mv_row_max = tmp_row_max; |
| 1103 |
| 1104 // calculate the bit cost on motion vector |
| 1105 mvp_full.row = tmp_mv.row * 8; |
| 1106 mvp_full.col = tmp_mv.col * 8; |
| 1107 |
| 1108 b_rate += vp9_mv_bit_cost(&mvp_full, |
| 1109 &mbmi->ref_mvs[ref_frame][0].as_mv, |
| 1110 x->nmvjointcost, x->mvcost, |
| 1111 MV_COST_WEIGHT); |
| 1112 |
| 1113 b_rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] |
| 1114 [INTER_OFFSET(NEWMV)]; |
| 1115 if (RDCOST(x->rdmult, x->rddiv, b_rate, 0) > b_best_rd) |
| 1116 continue; |
| 1117 |
| 1118 cpi->find_fractional_mv_step(x, &tmp_mv, |
| 1119 &mbmi->ref_mvs[ref_frame][0].as_mv, |
| 1120 cpi->common.allow_high_precision_mv, |
| 1121 x->errorperbit, |
| 1122 &cpi->fn_ptr[bsize], |
| 1123 cpi->sf.mv.subpel_force_stop, |
| 1124 cpi->sf.mv.subpel_iters_per_step, |
| 1125 cond_cost_list(cpi, cost_list), |
| 1126 x->nmvjointcost, x->mvcost, |
| 1127 &dummy_dist, |
| 1128 &x->pred_sse[ref_frame], NULL, 0, 0); |
| 1129 |
| 1130 xd->mi[0].bmi[i].as_mv[0].as_mv = tmp_mv; |
| 1131 } |
| 1132 |
| 1133 vp9_build_inter_predictor(pd->pre[0].buf, pd->pre[0].stride, |
| 1134 pd->dst.buf, pd->dst.stride, |
| 1135 &xd->mi[0].bmi[i].as_mv[0].as_mv, |
| 1136 &xd->block_refs[0]->sf, |
| 1137 4 * num_4x4_blocks_wide, |
| 1138 4 * num_4x4_blocks_high, 0, |
| 1139 vp9_get_interp_kernel(mbmi->interp_filter), |
| 1140 MV_PRECISION_Q3, |
| 1141 mi_col * MI_SIZE + 4 * (i & 0x01), |
| 1142 mi_row * MI_SIZE + 4 * (i >> 1)); |
| 1143 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist, |
| 1144 &var_y, &sse_y); |
| 1145 |
| 1146 this_rdc.rate += b_rate; |
| 1147 this_rdc.dist += b_dist; |
| 1148 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, |
| 1149 this_rdc.rate, this_rdc.dist); |
| 1150 if (this_rdc.rdcost < b_best_rd) { |
| 1151 b_best_rd = this_rdc.rdcost; |
| 1152 bsi[ref_frame][i].as_mode = this_mode; |
| 1153 bsi[ref_frame][i].as_mv[0].as_mv = xd->mi[0].bmi[i].as_mv[0].as_mv; |
| 1154 } |
| 1155 } // mode search |
| 1156 |
| 1157 // restore source and prediction buffer pointers. |
| 1158 p->src = orig_src; |
| 1159 pd->pre[0] = orig_pre[0]; |
| 1160 pd->dst = orig_dst; |
| 1161 this_rd += b_best_rd; |
| 1162 |
| 1163 xd->mi[0].bmi[i] = bsi[ref_frame][i]; |
| 1164 if (num_4x4_blocks_wide > 1) |
| 1165 xd->mi[0].bmi[i + 1] = xd->mi[0].bmi[i]; |
| 1166 if (num_4x4_blocks_high > 1) |
| 1167 xd->mi[0].bmi[i + 2] = xd->mi[0].bmi[i]; |
| 1168 } |
| 1169 } // loop through sub8x8 blocks |
| 1170 |
| 1171 if (this_rd < best_rd) { |
| 1172 best_rd = this_rd; |
| 1173 best_ref_frame = ref_frame; |
| 1174 } |
| 1175 } // reference frames |
| 1176 |
| 1177 mbmi->tx_size = TX_4X4; |
| 1178 mbmi->ref_frame[0] = best_ref_frame; |
| 1179 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
| 1180 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
| 1181 const int block = idy * 2 + idx; |
| 1182 xd->mi[0].bmi[block] = bsi[best_ref_frame][block]; |
| 1183 if (num_4x4_blocks_wide > 1) |
| 1184 xd->mi[0].bmi[block + 1] = bsi[best_ref_frame][block]; |
| 1185 if (num_4x4_blocks_high > 1) |
| 1186 xd->mi[0].bmi[block + 2] = bsi[best_ref_frame][block]; |
| 1187 } |
| 1188 } |
| 1189 mbmi->mode = xd->mi[0].bmi[3].as_mode; |
| 1190 ctx->mic = *(xd->mi[0].src_mi); |
| 1191 ctx->skip_txfm[0] = 0; |
| 1192 ctx->skip = 0; |
| 1193 // Dummy assignment for speed -5. No effect in speed -6. |
| 1194 rd_cost->rdcost = best_rd; |
| 1195 } |
OLD | NEW |