Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_pickmode.c

Issue 756673003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_pickmode.h ('k') | source/libvpx/vp9/encoder/vp9_quantize.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const POSITION *const mv_ref = &mv_ref_search[i]; 58 const POSITION *const mv_ref = &mv_ref_search[i];
59 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { 59 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
60 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * 60 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row *
61 xd->mi_stride].src_mi; 61 xd->mi_stride].src_mi;
62 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; 62 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
63 // Keep counts for entropy encoding. 63 // Keep counts for entropy encoding.
64 context_counter += mode_2_counter[candidate->mode]; 64 context_counter += mode_2_counter[candidate->mode];
65 different_ref_found = 1; 65 different_ref_found = 1;
66 66
67 if (candidate->ref_frame[0] == ref_frame) 67 if (candidate->ref_frame[0] == ref_frame)
68 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, -1)); 68 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, -1),
69 refmv_count, mv_ref_list, Done);
69 } 70 }
70 } 71 }
71 72
72 const_motion = 1; 73 const_motion = 1;
73 74
74 // Check the rest of the neighbors in much the same way 75 // Check the rest of the neighbors in much the same way
75 // as before except we don't need to keep track of sub blocks or 76 // as before except we don't need to keep track of sub blocks or
76 // mode counts. 77 // mode counts.
77 for (; i < MVREF_NEIGHBOURS && !refmv_count; ++i) { 78 for (; i < MVREF_NEIGHBOURS && !refmv_count; ++i) {
78 const POSITION *const mv_ref = &mv_ref_search[i]; 79 const POSITION *const mv_ref = &mv_ref_search[i];
79 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { 80 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
80 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * 81 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row *
81 xd->mi_stride].src_mi->mbmi; 82 xd->mi_stride].src_mi->mbmi;
82 different_ref_found = 1; 83 different_ref_found = 1;
83 84
84 if (candidate->ref_frame[0] == ref_frame) 85 if (candidate->ref_frame[0] == ref_frame)
85 ADD_MV_REF_LIST(candidate->mv[0]); 86 ADD_MV_REF_LIST(candidate->mv[0], refmv_count, mv_ref_list, Done);
86 } 87 }
87 } 88 }
88 89
89 // Since we couldn't find 2 mvs from the same reference frame 90 // Since we couldn't find 2 mvs from the same reference frame
90 // go back through the neighbors and find motion vectors from 91 // go back through the neighbors and find motion vectors from
91 // different reference frames. 92 // different reference frames.
92 if (different_ref_found && !refmv_count) { 93 if (different_ref_found && !refmv_count) {
93 for (i = 0; i < MVREF_NEIGHBOURS; ++i) { 94 for (i = 0; i < MVREF_NEIGHBOURS; ++i) {
94 const POSITION *mv_ref = &mv_ref_search[i]; 95 const POSITION *mv_ref = &mv_ref_search[i];
95 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { 96 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) {
96 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row 97 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row
97 * xd->mi_stride].src_mi->mbmi; 98 * xd->mi_stride].src_mi->mbmi;
98 99
99 // If the candidate is INTRA we don't want to consider its mv. 100 // If the candidate is INTRA we don't want to consider its mv.
100 IF_DIFF_REF_FRAME_ADD_MV(candidate); 101 IF_DIFF_REF_FRAME_ADD_MV(candidate, ref_frame, ref_sign_bias,
102 refmv_count, mv_ref_list, Done);
101 } 103 }
102 } 104 }
103 } 105 }
104 106
105 Done: 107 Done:
106 108
107 mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; 109 mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter];
108 110
109 // Clamp vectors 111 // Clamp vectors
110 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) 112 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i)
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); 434 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
433 assert(plane == 0); 435 assert(plane == 0);
434 (void) plane; 436 (void) plane;
435 437
436 p->src.buf = &src_buf_base[4 * (j * src_stride + i)]; 438 p->src.buf = &src_buf_base[4 * (j * src_stride + i)];
437 pd->dst.buf = &dst_buf_base[4 * (j * dst_stride + i)]; 439 pd->dst.buf = &dst_buf_base[4 * (j * dst_stride + i)];
438 // Use source buffer as an approximation for the fully reconstructed buffer. 440 // Use source buffer as an approximation for the fully reconstructed buffer.
439 vp9_predict_intra_block(xd, block >> (2 * tx_size), 441 vp9_predict_intra_block(xd, block >> (2 * tx_size),
440 b_width_log2_lookup[plane_bsize], 442 b_width_log2_lookup[plane_bsize],
441 tx_size, args->mode, 443 tx_size, args->mode,
442 p->src.buf, src_stride, 444 x->skip_encode ? p->src.buf : pd->dst.buf,
445 x->skip_encode ? src_stride : dst_stride,
443 pd->dst.buf, dst_stride, 446 pd->dst.buf, dst_stride,
444 i, j, 0); 447 i, j, 0);
445 // This procedure assumes zero offset from p->src.buf and pd->dst.buf. 448 // This procedure assumes zero offset from p->src.buf and pd->dst.buf.
446 model_rd_for_sb_y(cpi, bsize_tx, x, xd, &rate, &dist, &var_y, &sse_y); 449 model_rd_for_sb_y(cpi, bsize_tx, x, xd, &rate, &dist, &var_y, &sse_y);
447 p->src.buf = src_buf_base; 450 p->src.buf = src_buf_base;
448 pd->dst.buf = dst_buf_base; 451 pd->dst.buf = dst_buf_base;
449 args->rate += rate; 452 args->rate += rate;
450 args->dist += dist; 453 args->dist += dist;
451 } 454 }
452 455
453 static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][INTER_MODES] = { 456 static const THR_MODES mode_idx[MAX_REF_FRAMES][4] = {
457 {THR_DC, THR_H_PRED, THR_V_PRED, THR_TM},
454 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV}, 458 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV},
455 {THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG}, 459 {THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG},
456 {THR_NEARESTA, THR_NEARA, THR_ZEROA, THR_NEWA}, 460 {THR_NEARESTA, THR_NEARA, THR_ZEROA, THR_NEWA},
457 }; 461 };
458 462
463 static const PREDICTION_MODE intra_mode_list[] = {
464 DC_PRED, V_PRED, H_PRED, TM_PRED
465 };
466
459 // TODO(jingning) placeholder for inter-frame non-RD mode decision. 467 // TODO(jingning) placeholder for inter-frame non-RD mode decision.
460 // this needs various further optimizations. to be continued.. 468 // this needs various further optimizations. to be continued..
461 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 469 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
462 const TileInfo *const tile, 470 TileDataEnc *tile_data,
463 int mi_row, int mi_col, 471 int mi_row, int mi_col, RD_COST *rd_cost,
464 int *returnrate, 472 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
465 int64_t *returndistortion,
466 BLOCK_SIZE bsize,
467 PICK_MODE_CONTEXT *ctx) {
468 VP9_COMMON *const cm = &cpi->common; 473 VP9_COMMON *const cm = &cpi->common;
474 TileInfo *const tile_info = &tile_data->tile_info;
469 MACROBLOCKD *const xd = &x->e_mbd; 475 MACROBLOCKD *const xd = &x->e_mbd;
470 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 476 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
471 struct macroblockd_plane *const pd = &xd->plane[0]; 477 struct macroblockd_plane *const pd = &xd->plane[0];
472 PREDICTION_MODE best_mode = ZEROMV; 478 PREDICTION_MODE best_mode = ZEROMV;
473 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; 479 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME;
474 TX_SIZE best_tx_size = MIN(max_txsize_lookup[bsize], 480 TX_SIZE best_tx_size = MIN(max_txsize_lookup[bsize],
475 tx_mode_to_biggest_tx_size[cm->tx_mode]); 481 tx_mode_to_biggest_tx_size[cm->tx_mode]);
476 INTERP_FILTER best_pred_filter = EIGHTTAP; 482 INTERP_FILTER best_pred_filter = EIGHTTAP;
477 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 483 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
478 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; 484 struct buf_2d yv12_mb[4][MAX_MB_PLANE];
479 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 485 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
480 VP9_ALT_FLAG }; 486 VP9_ALT_FLAG };
481 int64_t best_rd = INT64_MAX; 487 RD_COST this_rdc, best_rdc;
482 int64_t this_rd = INT64_MAX;
483 uint8_t skip_txfm = 0; 488 uint8_t skip_txfm = 0;
484 int rate = INT_MAX;
485 int64_t dist = INT64_MAX;
486 // var_y and sse_y are saved to be used in skipping checking 489 // var_y and sse_y are saved to be used in skipping checking
487 unsigned int var_y = UINT_MAX; 490 unsigned int var_y = UINT_MAX;
488 unsigned int sse_y = UINT_MAX; 491 unsigned int sse_y = UINT_MAX;
489 // Reduce the intra cost penalty for small blocks (<=16x16). 492 // Reduce the intra cost penalty for small blocks (<=16x16).
490 const int reduction_fac = 493 const int reduction_fac =
491 (cpi->sf.partition_search_type == VAR_BASED_PARTITION && 494 (cpi->sf.partition_search_type == VAR_BASED_PARTITION &&
492 bsize <= BLOCK_16X16) ? 4 : 1; 495 bsize <= BLOCK_16X16) ? 4 : 1;
493 const int intra_cost_penalty = vp9_get_intra_cost_penalty( 496 const int intra_cost_penalty = vp9_get_intra_cost_penalty(
494 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth) / reduction_fac; 497 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth) / reduction_fac;
495 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, 498 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv,
496 intra_cost_penalty, 0); 499 intra_cost_penalty, 0);
497 const int intra_mode_cost = 50; 500 const int intra_mode_cost = 50;
498 501
499 const int8_t segment_id = mbmi->segment_id; 502 const int8_t segment_id = mbmi->segment_id;
500 const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize]; 503 const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize];
501 const int *const rd_thresh_freq_fact = cpi->rd.thresh_freq_fact[bsize]; 504 const int *const rd_thresh_freq_fact = tile_data->thresh_freq_fact[bsize];
502 INTERP_FILTER filter_ref = cm->interp_filter; 505 INTERP_FILTER filter_ref;
503 const int bsl = mi_width_log2_lookup[bsize]; 506 const int bsl = mi_width_log2_lookup[bsize];
504 const int pred_filter_search = cm->interp_filter == SWITCHABLE ? 507 const int pred_filter_search = cm->interp_filter == SWITCHABLE ?
505 (((mi_row + mi_col) >> bsl) + 508 (((mi_row + mi_col) >> bsl) +
506 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; 509 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0;
507 int const_motion[MAX_REF_FRAMES] = { 0 }; 510 int const_motion[MAX_REF_FRAMES] = { 0 };
508 const int bh = num_4x4_blocks_high_lookup[bsize] << 2; 511 const int bh = num_4x4_blocks_high_lookup[bsize] << 2;
509 const int bw = num_4x4_blocks_wide_lookup[bsize] << 2; 512 const int bw = num_4x4_blocks_wide_lookup[bsize] << 2;
510 // For speed 6, the result of interp filter is reused later in actual encoding 513 // For speed 6, the result of interp filter is reused later in actual encoding
511 // process. 514 // process.
512 // tmp[3] points to dst buffer, and the other 3 point to allocated buffers. 515 // tmp[3] points to dst buffer, and the other 3 point to allocated buffers.
513 PRED_BUFFER tmp[4]; 516 PRED_BUFFER tmp[4];
514 DECLARE_ALIGNED_ARRAY(16, uint8_t, pred_buf, 3 * 64 * 64); 517 DECLARE_ALIGNED_ARRAY(16, uint8_t, pred_buf, 3 * 64 * 64);
515 #if CONFIG_VP9_HIGHBITDEPTH 518 #if CONFIG_VP9_HIGHBITDEPTH
516 DECLARE_ALIGNED_ARRAY(16, uint16_t, pred_buf_16, 3 * 64 * 64); 519 DECLARE_ALIGNED_ARRAY(16, uint16_t, pred_buf_16, 3 * 64 * 64);
517 #endif 520 #endif
518 struct buf_2d orig_dst = pd->dst; 521 struct buf_2d orig_dst = pd->dst;
519 PRED_BUFFER *best_pred = NULL; 522 PRED_BUFFER *best_pred = NULL;
520 PRED_BUFFER *this_mode_pred = NULL; 523 PRED_BUFFER *this_mode_pred = NULL;
521 const int pixels_in_block = bh * bw; 524 const int pixels_in_block = bh * bw;
525 int reuse_inter_pred = cpi->sf.reuse_inter_pred_sby && ctx->pred_pixel_ready;
526 int ref_frame_skip_mask = 0;
522 527
523 if (cpi->sf.reuse_inter_pred_sby) { 528 if (reuse_inter_pred) {
524 int i; 529 int i;
525 for (i = 0; i < 3; i++) { 530 for (i = 0; i < 3; i++) {
526 #if CONFIG_VP9_HIGHBITDEPTH 531 #if CONFIG_VP9_HIGHBITDEPTH
527 if (cm->use_highbitdepth) 532 if (cm->use_highbitdepth)
528 tmp[i].data = CONVERT_TO_BYTEPTR(&pred_buf_16[pixels_in_block * i]); 533 tmp[i].data = CONVERT_TO_BYTEPTR(&pred_buf_16[pixels_in_block * i]);
529 else 534 else
530 tmp[i].data = &pred_buf[pixels_in_block * i]; 535 tmp[i].data = &pred_buf[pixels_in_block * i];
531 #else 536 #else
532 tmp[i].data = &pred_buf[pixels_in_block * i]; 537 tmp[i].data = &pred_buf[pixels_in_block * i];
533 #endif // CONFIG_VP9_HIGHBITDEPTH 538 #endif // CONFIG_VP9_HIGHBITDEPTH
534 tmp[i].stride = bw; 539 tmp[i].stride = bw;
535 tmp[i].in_use = 0; 540 tmp[i].in_use = 0;
536 } 541 }
537 tmp[3].data = pd->dst.buf; 542 tmp[3].data = pd->dst.buf;
538 tmp[3].stride = pd->dst.stride; 543 tmp[3].stride = pd->dst.stride;
539 tmp[3].in_use = 0; 544 tmp[3].in_use = 0;
540 } 545 }
541 546
542 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; 547 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
543 x->skip = 0; 548 x->skip = 0;
544 549
550 if (xd->up_available)
551 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter;
552 else if (xd->left_available)
553 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter;
554 else
555 filter_ref = cm->interp_filter;
556
545 // initialize mode decisions 557 // initialize mode decisions
546 *returnrate = INT_MAX; 558 vp9_rd_cost_reset(&best_rdc);
547 *returndistortion = INT64_MAX; 559 vp9_rd_cost_reset(&this_rdc);
560 vp9_rd_cost_reset(rd_cost);
548 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); 561 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO));
549 mbmi->sb_type = bsize; 562 mbmi->sb_type = bsize;
550 mbmi->ref_frame[0] = NONE; 563 mbmi->ref_frame[0] = NONE;
551 mbmi->ref_frame[1] = NONE; 564 mbmi->ref_frame[1] = NONE;
552 mbmi->tx_size = MIN(max_txsize_lookup[bsize], 565 mbmi->tx_size = MIN(max_txsize_lookup[bsize],
553 tx_mode_to_biggest_tx_size[cm->tx_mode]); 566 tx_mode_to_biggest_tx_size[cm->tx_mode]);
554 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? 567 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ?
555 EIGHTTAP : cm->interp_filter; 568 EIGHTTAP : cm->interp_filter;
556 mbmi->segment_id = segment_id; 569 mbmi->segment_id = segment_id;
557 570
558 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 571 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) {
559 PREDICTION_MODE this_mode;
560 x->pred_mv_sad[ref_frame] = INT_MAX; 572 x->pred_mv_sad[ref_frame] = INT_MAX;
561 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; 573 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
562 frame_mv[ZEROMV][ref_frame].as_int = 0; 574 frame_mv[ZEROMV][ref_frame].as_int = 0;
563 575
564 if (xd->up_available)
565 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter;
566 else if (xd->left_available)
567 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter;
568
569 if (cpi->ref_frame_flags & flag_list[ref_frame]) { 576 if (cpi->ref_frame_flags & flag_list[ref_frame]) {
570 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); 577 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
571 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; 578 int_mv *const candidates = mbmi->ref_mvs[ref_frame];
572 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; 579 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
580
573 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, 581 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col,
574 sf, sf); 582 sf, sf);
575 583
576 if (!cm->error_resilient_mode) 584 if (!cm->error_resilient_mode)
577 vp9_find_mv_refs(cm, xd, tile, xd->mi[0].src_mi, ref_frame, 585 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame,
578 candidates, mi_row, mi_col); 586 candidates, mi_row, mi_col);
579 else 587 else
580 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile, xd->mi[0].src_mi, 588 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile_info,
589 xd->mi[0].src_mi,
581 ref_frame, candidates, 590 ref_frame, candidates,
582 mi_row, mi_col); 591 mi_row, mi_col);
583 592
584 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, 593 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
585 &frame_mv[NEARESTMV][ref_frame], 594 &frame_mv[NEARESTMV][ref_frame],
586 &frame_mv[NEARMV][ref_frame]); 595 &frame_mv[NEARMV][ref_frame]);
587 596
588 if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8) 597 if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8)
589 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, 598 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride,
590 ref_frame, bsize); 599 ref_frame, bsize);
591 } else { 600 } else {
601 ref_frame_skip_mask |= (1 << ref_frame);
602 }
603 }
604
605 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) {
606 PREDICTION_MODE this_mode;
607 int i = (ref_frame == LAST_FRAME) ? GOLDEN_FRAME : LAST_FRAME;
608
609 if (!(cpi->ref_frame_flags & flag_list[ref_frame]))
592 continue; 610 continue;
593 } 611
612 if (cpi->ref_frame_flags & flag_list[i])
613 if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1))
614 ref_frame_skip_mask |= (1 << ref_frame);
615
616 if (ref_frame_skip_mask & (1 << ref_frame))
617 continue;
594 618
595 // Select prediction reference frames. 619 // Select prediction reference frames.
596 xd->plane[0].pre[0] = yv12_mb[ref_frame][0]; 620 xd->plane[0].pre[0] = yv12_mb[ref_frame][0];
597 621
598 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); 622 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd);
599 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); 623 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd);
600 624
601 mbmi->ref_frame[0] = ref_frame; 625 mbmi->ref_frame[0] = ref_frame;
602 626
603 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { 627 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
604 int rate_mv = 0; 628 int rate_mv = 0;
605 int mode_rd_thresh; 629 int mode_rd_thresh;
630 int mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)];
606 631
607 if (const_motion[ref_frame] && 632 if (const_motion[ref_frame] && this_mode == NEARMV)
608 (this_mode == NEARMV || this_mode == ZEROMV))
609 continue; 633 continue;
610 634
611 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) 635 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode)))
612 continue; 636 continue;
613 637
614 mode_rd_thresh = 638 mode_rd_thresh = rd_threshes[mode_index];
615 rd_threshes[mode_idx[ref_frame - 639 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh,
616 LAST_FRAME][INTER_OFFSET(this_mode)]]; 640 rd_thresh_freq_fact[mode_index]))
617 if (rd_less_than_thresh(best_rd, mode_rd_thresh,
618 rd_thresh_freq_fact[this_mode]))
619 continue; 641 continue;
620 642
621 if (this_mode == NEWMV) { 643 if (this_mode == NEWMV) {
644 if (ref_frame > LAST_FRAME)
645 continue;
622 if (cpi->sf.partition_search_type != VAR_BASED_PARTITION && 646 if (cpi->sf.partition_search_type != VAR_BASED_PARTITION &&
623 this_rd < (int64_t)(1 << num_pels_log2_lookup[bsize])) 647 this_rdc.rdcost < (int64_t)(1 << num_pels_log2_lookup[bsize]))
624 continue; 648 continue;
625 if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, 649 if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col,
626 &frame_mv[NEWMV][ref_frame], 650 &frame_mv[NEWMV][ref_frame],
627 &rate_mv, best_rd)) 651 &rate_mv, best_rdc.rdcost))
628 continue; 652 continue;
629 } 653 }
630 654
631 if (this_mode != NEARESTMV && 655 if (this_mode != NEARESTMV &&
632 frame_mv[this_mode][ref_frame].as_int == 656 frame_mv[this_mode][ref_frame].as_int ==
633 frame_mv[NEARESTMV][ref_frame].as_int) 657 frame_mv[NEARESTMV][ref_frame].as_int)
634 continue; 658 continue;
635 659
636 mbmi->mode = this_mode; 660 mbmi->mode = this_mode;
637 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; 661 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int;
638 662
639 // Search for the best prediction filter type, when the resulting 663 // Search for the best prediction filter type, when the resulting
640 // motion vector is at sub-pixel accuracy level for luma component, i.e., 664 // motion vector is at sub-pixel accuracy level for luma component, i.e.,
641 // the last three bits are all zeros. 665 // the last three bits are all zeros.
642 if (cpi->sf.reuse_inter_pred_sby) { 666 if (reuse_inter_pred) {
643 if (this_mode == NEARESTMV) { 667 if (!this_mode_pred) {
644 this_mode_pred = &tmp[3]; 668 this_mode_pred = &tmp[3];
645 } else { 669 } else {
646 this_mode_pred = &tmp[get_pred_buffer(tmp, 3)]; 670 this_mode_pred = &tmp[get_pred_buffer(tmp, 3)];
647 pd->dst.buf = this_mode_pred->data; 671 pd->dst.buf = this_mode_pred->data;
648 pd->dst.stride = bw; 672 pd->dst.stride = bw;
649 } 673 }
650 } 674 }
651 675
652 if ((this_mode == NEWMV || filter_ref == SWITCHABLE) && 676 if ((this_mode == NEWMV || filter_ref == SWITCHABLE) &&
653 pred_filter_search && 677 pred_filter_search &&
(...skipping 16 matching lines...) Expand all
670 &pf_dist[filter], &pf_var[filter], &pf_sse[filter]); 694 &pf_dist[filter], &pf_var[filter], &pf_sse[filter]);
671 cost = RDCOST(x->rdmult, x->rddiv, 695 cost = RDCOST(x->rdmult, x->rddiv,
672 vp9_get_switchable_rate(cpi) + pf_rate[filter], 696 vp9_get_switchable_rate(cpi) + pf_rate[filter],
673 pf_dist[filter]); 697 pf_dist[filter]);
674 pf_tx_size[filter] = mbmi->tx_size; 698 pf_tx_size[filter] = mbmi->tx_size;
675 if (cost < best_cost) { 699 if (cost < best_cost) {
676 best_filter = filter; 700 best_filter = filter;
677 best_cost = cost; 701 best_cost = cost;
678 skip_txfm = x->skip_txfm[0]; 702 skip_txfm = x->skip_txfm[0];
679 703
680 if (cpi->sf.reuse_inter_pred_sby) { 704 if (reuse_inter_pred) {
681 if (this_mode_pred != current_pred) { 705 if (this_mode_pred != current_pred) {
682 free_pred_buffer(this_mode_pred); 706 free_pred_buffer(this_mode_pred);
683 this_mode_pred = current_pred; 707 this_mode_pred = current_pred;
684 } 708 }
685 709
686 if (filter < EIGHTTAP_SHARP) { 710 if (filter < EIGHTTAP_SHARP) {
687 current_pred = &tmp[get_pred_buffer(tmp, 3)]; 711 current_pred = &tmp[get_pred_buffer(tmp, 3)];
688 pd->dst.buf = current_pred->data; 712 pd->dst.buf = current_pred->data;
689 pd->dst.stride = bw; 713 pd->dst.stride = bw;
690 } 714 }
691 } 715 }
692 } 716 }
693 } 717 }
694 718
695 if (cpi->sf.reuse_inter_pred_sby && this_mode_pred != current_pred) 719 if (reuse_inter_pred && this_mode_pred != current_pred)
696 free_pred_buffer(current_pred); 720 free_pred_buffer(current_pred);
697 721
698 mbmi->interp_filter = best_filter; 722 mbmi->interp_filter = best_filter;
699 mbmi->tx_size = pf_tx_size[mbmi->interp_filter]; 723 mbmi->tx_size = pf_tx_size[mbmi->interp_filter];
700 rate = pf_rate[mbmi->interp_filter]; 724 this_rdc.rate = pf_rate[mbmi->interp_filter];
701 dist = pf_dist[mbmi->interp_filter]; 725 this_rdc.dist = pf_dist[mbmi->interp_filter];
702 var_y = pf_var[mbmi->interp_filter]; 726 var_y = pf_var[mbmi->interp_filter];
703 sse_y = pf_sse[mbmi->interp_filter]; 727 sse_y = pf_sse[mbmi->interp_filter];
704 x->skip_txfm[0] = skip_txfm; 728 x->skip_txfm[0] = skip_txfm;
705 } else { 729 } else {
706 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref; 730 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref;
707 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); 731 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
708 model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist, &var_y, &sse_y); 732 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist,
733 &var_y, &sse_y);
709 } 734 }
710 735
711 rate += rate_mv; 736 this_rdc.rate += rate_mv;
712 rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] 737 this_rdc.rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]]
713 [INTER_OFFSET(this_mode)]; 738 [INTER_OFFSET(this_mode)];
714 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); 739 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
740 this_rdc.rate, this_rdc.dist);
715 741
716 // Skipping checking: test to see if this block can be reconstructed by 742 // Skipping checking: test to see if this block can be reconstructed by
717 // prediction only. 743 // prediction only.
718 if (cpi->allow_encode_breakout) { 744 if (cpi->allow_encode_breakout) {
719 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame, 745 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame,
720 this_mode, var_y, sse_y, yv12_mb, &rate, &dist); 746 this_mode, var_y, sse_y, yv12_mb,
747 &this_rdc.rate, &this_rdc.dist);
721 if (x->skip) { 748 if (x->skip) {
722 rate += rate_mv; 749 this_rdc.rate += rate_mv;
723 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); 750 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
751 this_rdc.rate, this_rdc.dist);
724 } 752 }
725 } 753 }
726 754
727 #if CONFIG_VP9_TEMPORAL_DENOISING 755 #if CONFIG_VP9_TEMPORAL_DENOISING
728 if (cpi->oxcf.noise_sensitivity > 0) { 756 if (cpi->oxcf.noise_sensitivity > 0) {
729 vp9_denoiser_update_frame_stats(mbmi, sse_y, this_mode, ctx); 757 vp9_denoiser_update_frame_stats(mbmi, sse_y, this_mode, ctx);
730 } 758 }
731 #else 759 #else
732 (void)ctx; 760 (void)ctx;
733 #endif 761 #endif
734 762
735 if (this_rd < best_rd || x->skip) { 763 if (this_rdc.rdcost < best_rdc.rdcost || x->skip) {
736 best_rd = this_rd; 764 best_rdc = this_rdc;
737 *returnrate = rate;
738 *returndistortion = dist;
739 best_mode = this_mode; 765 best_mode = this_mode;
740 best_pred_filter = mbmi->interp_filter; 766 best_pred_filter = mbmi->interp_filter;
741 best_tx_size = mbmi->tx_size; 767 best_tx_size = mbmi->tx_size;
742 best_ref_frame = ref_frame; 768 best_ref_frame = ref_frame;
743 skip_txfm = x->skip_txfm[0]; 769 skip_txfm = x->skip_txfm[0];
744 770
745 if (cpi->sf.reuse_inter_pred_sby) { 771 if (reuse_inter_pred) {
746 free_pred_buffer(best_pred); 772 free_pred_buffer(best_pred);
747
748 best_pred = this_mode_pred; 773 best_pred = this_mode_pred;
749 } 774 }
750 } else { 775 } else {
751 if (cpi->sf.reuse_inter_pred_sby) 776 if (reuse_inter_pred)
752 free_pred_buffer(this_mode_pred); 777 free_pred_buffer(this_mode_pred);
753 } 778 }
754 779
755 if (x->skip) 780 if (x->skip)
756 break; 781 break;
757 } 782 }
758 // If the current reference frame is valid and we found a usable mode, 783
759 // we are done. 784 // Check that a prediction mode has been selected.
760 if (best_rd < INT64_MAX) 785 assert(best_rdc.rdcost < INT64_MAX);
786
787 if (x->skip)
761 break; 788 break;
762 } 789 }
763 790
764 // If best prediction is not in dst buf, then copy the prediction block from
765 // temp buf to dst buf.
766 if (best_pred != NULL && cpi->sf.reuse_inter_pred_sby &&
767 best_pred->data != orig_dst.buf) {
768 pd->dst = orig_dst;
769 #if CONFIG_VP9_HIGHBITDEPTH
770 if (cm->use_highbitdepth) {
771 vp9_highbd_convolve_copy(best_pred->data, bw, pd->dst.buf, pd->dst.stride,
772 NULL, 0, NULL, 0, bw, bh, xd->bd);
773 } else {
774 vp9_convolve_copy(best_pred->data, bw, pd->dst.buf, pd->dst.stride,
775 NULL, 0, NULL, 0, bw, bh);
776 }
777 #else
778 vp9_convolve_copy(best_pred->data, bw, pd->dst.buf, pd->dst.stride, NULL, 0,
779 NULL, 0, bw, bh);
780 #endif // CONFIG_VP9_HIGHBITDEPTH
781 }
782
783 mbmi->mode = best_mode; 791 mbmi->mode = best_mode;
784 mbmi->interp_filter = best_pred_filter; 792 mbmi->interp_filter = best_pred_filter;
785 mbmi->tx_size = best_tx_size; 793 mbmi->tx_size = best_tx_size;
786 mbmi->ref_frame[0] = best_ref_frame; 794 mbmi->ref_frame[0] = best_ref_frame;
787 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; 795 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int;
788 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; 796 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int;
789 x->skip_txfm[0] = skip_txfm; 797 x->skip_txfm[0] = skip_txfm;
790 798
791 // Perform intra prediction search, if the best SAD is above a certain 799 // Perform intra prediction search, if the best SAD is above a certain
792 // threshold. 800 // threshold.
793 if (!x->skip && best_rd > inter_mode_thresh && 801 if (!x->skip && best_rdc.rdcost > inter_mode_thresh &&
794 bsize <= cpi->sf.max_intra_bsize) { 802 bsize <= cpi->sf.max_intra_bsize) {
795 PREDICTION_MODE this_mode;
796 struct estimate_block_intra_args args = { cpi, x, DC_PRED, 0, 0 }; 803 struct estimate_block_intra_args args = { cpi, x, DC_PRED, 0, 0 };
797 const TX_SIZE intra_tx_size = 804 const TX_SIZE intra_tx_size =
798 MIN(max_txsize_lookup[bsize], 805 MIN(max_txsize_lookup[bsize],
799 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); 806 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
807 int i;
800 808
801 if (cpi->sf.reuse_inter_pred_sby) { 809 if (reuse_inter_pred && best_pred != NULL) {
802 pd->dst.buf = tmp[0].data; 810 if (best_pred->data == orig_dst.buf) {
803 pd->dst.stride = bw; 811 this_mode_pred = &tmp[get_pred_buffer(tmp, 3)];
812 vp9_convolve_copy(best_pred->data, best_pred->stride,
813 this_mode_pred->data, this_mode_pred->stride,
814 NULL, 0, NULL, 0, bw, bh);
815 best_pred = this_mode_pred;
816 }
804 } 817 }
818 pd->dst = orig_dst;
805 819
806 for (this_mode = DC_PRED; this_mode <= DC_PRED; ++this_mode) { 820 for (i = 0; i < 4; ++i) {
807 const TX_SIZE saved_tx_size = mbmi->tx_size; 821 const TX_SIZE saved_tx_size = mbmi->tx_size;
822 const PREDICTION_MODE this_mode = intra_mode_list[i];
823 if (!((1 << this_mode) & cpi->sf.intra_y_mode_mask[intra_tx_size]))
824 continue;
825 skip_txfm = x->skip_txfm[0];
808 args.mode = this_mode; 826 args.mode = this_mode;
809 args.rate = 0; 827 args.rate = 0;
810 args.dist = 0; 828 args.dist = 0;
811 mbmi->tx_size = intra_tx_size; 829 mbmi->tx_size = intra_tx_size;
812 vp9_foreach_transformed_block_in_plane(xd, bsize, 0, 830 vp9_foreach_transformed_block_in_plane(xd, bsize, 0,
813 estimate_block_intra, &args); 831 estimate_block_intra, &args);
814 mbmi->tx_size = saved_tx_size; 832 this_rdc.rate = args.rate;
815 rate = args.rate; 833 this_rdc.dist = args.dist;
816 dist = args.dist; 834 this_rdc.rate += cpi->mbmode_cost[this_mode];
817 rate += cpi->mbmode_cost[this_mode]; 835 this_rdc.rate += intra_cost_penalty;
818 rate += intra_cost_penalty; 836 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
819 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); 837 this_rdc.rate, this_rdc.dist);
820 838
821 if (this_rd + intra_mode_cost < best_rd) { 839 if (this_rdc.rdcost + intra_mode_cost < best_rdc.rdcost) {
822 best_rd = this_rd; 840 best_rdc = this_rdc;
823 *returnrate = rate;
824 *returndistortion = dist;
825 mbmi->mode = this_mode; 841 mbmi->mode = this_mode;
826 mbmi->tx_size = intra_tx_size; 842 mbmi->tx_size = intra_tx_size;
827 mbmi->ref_frame[0] = INTRA_FRAME; 843 mbmi->ref_frame[0] = INTRA_FRAME;
828 mbmi->uv_mode = this_mode; 844 mbmi->uv_mode = this_mode;
829 mbmi->mv[0].as_int = INVALID_MV; 845 mbmi->mv[0].as_int = INVALID_MV;
830 } else { 846 } else {
831 x->skip_txfm[0] = skip_txfm; 847 x->skip_txfm[0] = skip_txfm;
848 mbmi->tx_size = saved_tx_size;
832 } 849 }
833 } 850 }
834 if (cpi->sf.reuse_inter_pred_sby)
835 pd->dst = orig_dst;
836 } 851 }
852
853 pd->dst = orig_dst;
854
855 if (reuse_inter_pred && best_pred != NULL) {
856 if (best_pred->data != orig_dst.buf && is_inter_mode(mbmi->mode)) {
857 #if CONFIG_VP9_HIGHBITDEPTH
858 if (cm->use_highbitdepth)
859 vp9_highbd_convolve_copy(best_pred->data, best_pred->stride,
860 pd->dst.buf, pd->dst.stride, NULL, 0,
861 NULL, 0, bw, bh, xd->bd);
862 else
863 vp9_convolve_copy(best_pred->data, best_pred->stride,
864 pd->dst.buf, pd->dst.stride, NULL, 0,
865 NULL, 0, bw, bh);
866 #else
867 vp9_convolve_copy(best_pred->data, best_pred->stride,
868 pd->dst.buf, pd->dst.stride, NULL, 0,
869 NULL, 0, bw, bh);
870 #endif
871 }
872 }
873
874 if (is_inter_block(mbmi))
875 vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact,
876 cpi->sf.adaptive_rd_thresh, bsize,
877 mode_idx[best_ref_frame][INTER_OFFSET(mbmi->mode)]);
878 else
879 vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact,
880 cpi->sf.adaptive_rd_thresh, bsize,
881 mode_idx[INTRA_FRAME][mbmi->mode]);
882
883 *rd_cost = best_rdc;
837 } 884 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_pickmode.h ('k') | source/libvpx/vp9/encoder/vp9_quantize.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698