| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 int dis; | 130 int dis; |
| 131 int rate_mode; | 131 int rate_mode; |
| 132 const int tmp_col_min = x->mv_col_min; | 132 const int tmp_col_min = x->mv_col_min; |
| 133 const int tmp_col_max = x->mv_col_max; | 133 const int tmp_col_max = x->mv_col_max; |
| 134 const int tmp_row_min = x->mv_row_min; | 134 const int tmp_row_min = x->mv_row_min; |
| 135 const int tmp_row_max = x->mv_row_max; | 135 const int tmp_row_max = x->mv_row_max; |
| 136 int rv = 0; | 136 int rv = 0; |
| 137 int cost_list[5]; | 137 int cost_list[5]; |
| 138 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, | 138 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, |
| 139 ref); | 139 ref); |
| 140 if (cpi->common.show_frame && | |
| 141 (x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[LAST_FRAME]) | |
| 142 return rv; | |
| 143 | |
| 144 if (scaled_ref_frame) { | 140 if (scaled_ref_frame) { |
| 145 int i; | 141 int i; |
| 146 // Swap out the reference frame for a version that's been scaled to | 142 // Swap out the reference frame for a version that's been scaled to |
| 147 // match the resolution of the current frame, allowing the existing | 143 // match the resolution of the current frame, allowing the existing |
| 148 // motion search code to be used without additional modifications. | 144 // motion search code to be used without additional modifications. |
| 149 for (i = 0; i < MAX_MB_PLANE; i++) | 145 for (i = 0; i < MAX_MB_PLANE; i++) |
| 150 backup_yv12[i] = xd->plane[i].pre[0]; | 146 backup_yv12[i] = xd->plane[i].pre[0]; |
| 151 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); | 147 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
| 152 } | 148 } |
| 153 vp9_set_mv_search_range(x, &ref_mv); | 149 vp9_set_mv_search_range(x, &ref_mv); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 int rate; | 210 int rate; |
| 215 int64_t dist; | 211 int64_t dist; |
| 216 struct macroblock_plane *const p = &x->plane[0]; | 212 struct macroblock_plane *const p = &x->plane[0]; |
| 217 struct macroblockd_plane *const pd = &xd->plane[0]; | 213 struct macroblockd_plane *const pd = &xd->plane[0]; |
| 218 const int64_t dc_thr = p->quant_thred[0] >> 6; | 214 const int64_t dc_thr = p->quant_thred[0] >> 6; |
| 219 const int64_t ac_thr = p->quant_thred[1] >> 6; | 215 const int64_t ac_thr = p->quant_thred[1] >> 6; |
| 220 const uint32_t dc_quant = pd->dequant[0]; | 216 const uint32_t dc_quant = pd->dequant[0]; |
| 221 const uint32_t ac_quant = pd->dequant[1]; | 217 const uint32_t ac_quant = pd->dequant[1]; |
| 222 unsigned int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride, | 218 unsigned int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride, |
| 223 pd->dst.buf, pd->dst.stride, &sse); | 219 pd->dst.buf, pd->dst.stride, &sse); |
| 220 int skip_dc = 0; |
| 221 |
| 224 *var_y = var; | 222 *var_y = var; |
| 225 *sse_y = sse; | 223 *sse_y = sse; |
| 226 | 224 |
| 227 if (cpi->common.tx_mode == TX_MODE_SELECT) { | 225 if (cpi->common.tx_mode == TX_MODE_SELECT) { |
| 228 if (sse > (var << 2)) | 226 if (sse > (var << 2)) |
| 229 xd->mi[0].src_mi->mbmi.tx_size = | 227 xd->mi[0].src_mi->mbmi.tx_size = |
| 230 MIN(max_txsize_lookup[bsize], | 228 MIN(max_txsize_lookup[bsize], |
| 231 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 229 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 232 else | 230 else |
| 233 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8; | 231 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8; |
| 234 | 232 |
| 235 if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) { | 233 if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) { |
| 236 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && | 234 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && |
| 237 xd->mi[0].src_mi->mbmi.segment_id != CR_SEGMENT_ID_BASE) | 235 cyclic_refresh_segment_id_boosted(xd->mi[0].src_mi->mbmi.segment_id)) |
| 238 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8; | 236 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8; |
| 239 else if (xd->mi[0].src_mi->mbmi.tx_size > TX_16X16) | 237 else if (xd->mi[0].src_mi->mbmi.tx_size > TX_16X16) |
| 240 xd->mi[0].src_mi->mbmi.tx_size = TX_16X16; | 238 xd->mi[0].src_mi->mbmi.tx_size = TX_16X16; |
| 241 } | 239 } |
| 242 } else { | 240 } else { |
| 243 xd->mi[0].src_mi->mbmi.tx_size = | 241 xd->mi[0].src_mi->mbmi.tx_size = |
| 244 MIN(max_txsize_lookup[bsize], | 242 MIN(max_txsize_lookup[bsize], |
| 245 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 243 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 246 } | 244 } |
| 247 | 245 |
| 248 // Evaluate if the partition block is a skippable block in Y plane. | 246 // Evaluate if the partition block is a skippable block in Y plane. |
| 249 { | 247 { |
| 250 const BLOCK_SIZE unit_size = | 248 const BLOCK_SIZE unit_size = |
| 251 txsize_to_bsize[xd->mi[0].src_mi->mbmi.tx_size]; | 249 txsize_to_bsize[xd->mi[0].src_mi->mbmi.tx_size]; |
| 252 const unsigned int num_blk_log2 = | 250 const unsigned int num_blk_log2 = |
| 253 (b_width_log2_lookup[bsize] - b_width_log2_lookup[unit_size]) + | 251 (b_width_log2_lookup[bsize] - b_width_log2_lookup[unit_size]) + |
| 254 (b_height_log2_lookup[bsize] - b_height_log2_lookup[unit_size]); | 252 (b_height_log2_lookup[bsize] - b_height_log2_lookup[unit_size]); |
| 255 const unsigned int sse_tx = sse >> num_blk_log2; | 253 const unsigned int sse_tx = sse >> num_blk_log2; |
| 256 const unsigned int var_tx = var >> num_blk_log2; | 254 const unsigned int var_tx = var >> num_blk_log2; |
| 257 | 255 |
| 258 x->skip_txfm[0] = 0; | 256 x->skip_txfm[0] = 0; |
| 259 // Check if all ac coefficients can be quantized to zero. | 257 // Check if all ac coefficients can be quantized to zero. |
| 260 if (var_tx < ac_thr || var == 0) { | 258 if (var_tx < ac_thr || var == 0) { |
| 261 x->skip_txfm[0] = 2; | 259 x->skip_txfm[0] = 2; |
| 262 // Check if dc coefficient can be quantized to zero. | 260 // Check if dc coefficient can be quantized to zero. |
| 263 if (sse_tx - var_tx < dc_thr || sse == var) | 261 if (sse_tx - var_tx < dc_thr || sse == var) |
| 264 x->skip_txfm[0] = 1; | 262 x->skip_txfm[0] = 1; |
| 263 } else { |
| 264 if (sse_tx - var_tx < dc_thr || sse == var) |
| 265 skip_dc = 1; |
| 265 } | 266 } |
| 266 } | 267 } |
| 267 | 268 |
| 268 if (x->skip_txfm[0] == 1) { | 269 if (x->skip_txfm[0] == 1) { |
| 269 *out_rate_sum = 0; | 270 *out_rate_sum = 0; |
| 270 *out_dist_sum = sse << 4; | 271 *out_dist_sum = sse << 4; |
| 271 return; | 272 return; |
| 272 } | 273 } |
| 273 | 274 |
| 275 if (!skip_dc) { |
| 276 #if CONFIG_VP9_HIGHBITDEPTH |
| 277 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 278 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], |
| 279 dc_quant >> (xd->bd - 5), &rate, &dist); |
| 280 } else { |
| 281 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], |
| 282 dc_quant >> 3, &rate, &dist); |
| 283 } |
| 284 #else |
| 285 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], |
| 286 dc_quant >> 3, &rate, &dist); |
| 287 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 288 } |
| 289 |
| 290 if (!skip_dc) { |
| 291 *out_rate_sum = rate >> 1; |
| 292 *out_dist_sum = dist << 3; |
| 293 } else { |
| 294 *out_rate_sum = 0; |
| 295 *out_dist_sum = (sse - var) << 4; |
| 296 } |
| 297 |
| 274 #if CONFIG_VP9_HIGHBITDEPTH | 298 #if CONFIG_VP9_HIGHBITDEPTH |
| 275 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 299 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 276 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], | |
| 277 dc_quant >> (xd->bd - 5), &rate, &dist); | |
| 278 } else { | |
| 279 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], | |
| 280 dc_quant >> 3, &rate, &dist); | |
| 281 } | |
| 282 #else | |
| 283 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], | |
| 284 dc_quant >> 3, &rate, &dist); | |
| 285 #endif // CONFIG_VP9_HIGHBITDEPTH | |
| 286 | |
| 287 *out_rate_sum = rate >> 1; | |
| 288 *out_dist_sum = dist << 3; | |
| 289 | |
| 290 #if CONFIG_VP9_HIGHBITDEPTH | |
| 291 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | |
| 292 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], | 300 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], |
| 293 ac_quant >> (xd->bd - 5), &rate, &dist); | 301 ac_quant >> (xd->bd - 5), &rate, &dist); |
| 294 } else { | 302 } else { |
| 295 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], | 303 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], |
| 296 ac_quant >> 3, &rate, &dist); | 304 ac_quant >> 3, &rate, &dist); |
| 297 } | 305 } |
| 298 #else | 306 #else |
| 299 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], | 307 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bsize], |
| 300 ac_quant >> 3, &rate, &dist); | 308 ac_quant >> 3, &rate, &dist); |
| 301 #endif // CONFIG_VP9_HIGHBITDEPTH | 309 #endif // CONFIG_VP9_HIGHBITDEPTH |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 595 |
| 588 if (this_rdc.rdcost < best_rdc.rdcost) { | 596 if (this_rdc.rdcost < best_rdc.rdcost) { |
| 589 best_rdc = this_rdc; | 597 best_rdc = this_rdc; |
| 590 mbmi->mode = this_mode; | 598 mbmi->mode = this_mode; |
| 591 } | 599 } |
| 592 } | 600 } |
| 593 | 601 |
| 594 *rd_cost = best_rdc; | 602 *rd_cost = best_rdc; |
| 595 } | 603 } |
| 596 | 604 |
| 597 static const PREDICTION_MODE inter_mode_set[INTER_MODES] = { | |
| 598 ZEROMV, NEARESTMV, NEARMV, NEWMV, | |
| 599 }; | |
| 600 | |
| 601 static const int ref_frame_cost[MAX_REF_FRAMES] = { | 605 static const int ref_frame_cost[MAX_REF_FRAMES] = { |
| 602 1235, 229, 530, 615, | 606 1235, 229, 530, 615, |
| 603 }; | 607 }; |
| 608 |
| 609 typedef struct { |
| 610 MV_REFERENCE_FRAME ref_frame; |
| 611 PREDICTION_MODE pred_mode; |
| 612 } REF_MODE; |
| 613 |
| 614 #define RT_INTER_MODES 8 |
| 615 static const REF_MODE ref_mode_set[RT_INTER_MODES] = { |
| 616 {LAST_FRAME, ZEROMV}, |
| 617 {LAST_FRAME, NEARESTMV}, |
| 618 {LAST_FRAME, NEARMV}, |
| 619 {LAST_FRAME, NEWMV}, |
| 620 {GOLDEN_FRAME, ZEROMV}, |
| 621 {GOLDEN_FRAME, NEARESTMV}, |
| 622 {GOLDEN_FRAME, NEARMV}, |
| 623 {GOLDEN_FRAME, NEWMV} |
| 624 }; |
| 625 |
| 604 // TODO(jingning) placeholder for inter-frame non-RD mode decision. | 626 // TODO(jingning) placeholder for inter-frame non-RD mode decision. |
| 605 // this needs various further optimizations. to be continued.. | 627 // this needs various further optimizations. to be continued.. |
| 606 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, | 628 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, |
| 607 TileDataEnc *tile_data, | 629 TileDataEnc *tile_data, |
| 608 int mi_row, int mi_col, RD_COST *rd_cost, | 630 int mi_row, int mi_col, RD_COST *rd_cost, |
| 609 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { | 631 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { |
| 610 VP9_COMMON *const cm = &cpi->common; | 632 VP9_COMMON *const cm = &cpi->common; |
| 611 TileInfo *const tile_info = &tile_data->tile_info; | 633 TileInfo *const tile_info = &tile_data->tile_info; |
| 612 MACROBLOCKD *const xd = &x->e_mbd; | 634 MACROBLOCKD *const xd = &x->e_mbd; |
| 613 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 635 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 DECLARE_ALIGNED_ARRAY(16, uint8_t, pred_buf, 3 * 64 * 64); | 672 DECLARE_ALIGNED_ARRAY(16, uint8_t, pred_buf, 3 * 64 * 64); |
| 651 #if CONFIG_VP9_HIGHBITDEPTH | 673 #if CONFIG_VP9_HIGHBITDEPTH |
| 652 DECLARE_ALIGNED_ARRAY(16, uint16_t, pred_buf_16, 3 * 64 * 64); | 674 DECLARE_ALIGNED_ARRAY(16, uint16_t, pred_buf_16, 3 * 64 * 64); |
| 653 #endif | 675 #endif |
| 654 struct buf_2d orig_dst = pd->dst; | 676 struct buf_2d orig_dst = pd->dst; |
| 655 PRED_BUFFER *best_pred = NULL; | 677 PRED_BUFFER *best_pred = NULL; |
| 656 PRED_BUFFER *this_mode_pred = NULL; | 678 PRED_BUFFER *this_mode_pred = NULL; |
| 657 const int pixels_in_block = bh * bw; | 679 const int pixels_in_block = bh * bw; |
| 658 int reuse_inter_pred = cpi->sf.reuse_inter_pred_sby && ctx->pred_pixel_ready; | 680 int reuse_inter_pred = cpi->sf.reuse_inter_pred_sby && ctx->pred_pixel_ready; |
| 659 int ref_frame_skip_mask = 0; | 681 int ref_frame_skip_mask = 0; |
| 682 int idx; |
| 660 | 683 |
| 661 if (reuse_inter_pred) { | 684 if (reuse_inter_pred) { |
| 662 int i; | 685 int i; |
| 663 for (i = 0; i < 3; i++) { | 686 for (i = 0; i < 3; i++) { |
| 664 #if CONFIG_VP9_HIGHBITDEPTH | 687 #if CONFIG_VP9_HIGHBITDEPTH |
| 665 if (cm->use_highbitdepth) | 688 if (cm->use_highbitdepth) |
| 666 tmp[i].data = CONVERT_TO_BYTEPTR(&pred_buf_16[pixels_in_block * i]); | 689 tmp[i].data = CONVERT_TO_BYTEPTR(&pred_buf_16[pixels_in_block * i]); |
| 667 else | 690 else |
| 668 tmp[i].data = &pred_buf[pixels_in_block * i]; | 691 tmp[i].data = &pred_buf[pixels_in_block * i]; |
| 669 #else | 692 #else |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, | 756 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, |
| 734 ref_frame, bsize); | 757 ref_frame, bsize); |
| 735 } else { | 758 } else { |
| 736 ref_frame_skip_mask |= (1 << ref_frame); | 759 ref_frame_skip_mask |= (1 << ref_frame); |
| 737 } | 760 } |
| 738 } | 761 } |
| 739 | 762 |
| 740 if (cpi->rc.frames_since_golden == 0) | 763 if (cpi->rc.frames_since_golden == 0) |
| 741 ref_frame_skip_mask |= (1 << GOLDEN_FRAME); | 764 ref_frame_skip_mask |= (1 << GOLDEN_FRAME); |
| 742 | 765 |
| 743 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { | 766 for (idx = 0; idx < RT_INTER_MODES; ++idx) { |
| 744 PREDICTION_MODE this_mode; | 767 int rate_mv = 0; |
| 745 int i = (ref_frame == LAST_FRAME) ? GOLDEN_FRAME : LAST_FRAME; | 768 int mode_rd_thresh; |
| 769 int mode_index; |
| 770 int i; |
| 771 PREDICTION_MODE this_mode = ref_mode_set[idx].pred_mode; |
| 772 |
| 773 ref_frame = ref_mode_set[idx].ref_frame; |
| 774 mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; |
| 775 |
| 776 i = (ref_frame == LAST_FRAME) ? GOLDEN_FRAME : LAST_FRAME; |
| 746 | 777 |
| 747 if (!(cpi->ref_frame_flags & flag_list[ref_frame])) | 778 if (!(cpi->ref_frame_flags & flag_list[ref_frame])) |
| 748 continue; | 779 continue; |
| 749 | 780 |
| 750 if (cpi->ref_frame_flags & flag_list[i]) | 781 if (cpi->ref_frame_flags & flag_list[i]) |
| 751 if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1)) | 782 if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1)) |
| 752 ref_frame_skip_mask |= (1 << ref_frame); | 783 ref_frame_skip_mask |= (1 << ref_frame); |
| 753 | 784 |
| 754 if (ref_frame_skip_mask & (1 << ref_frame)) | 785 if (ref_frame_skip_mask & (1 << ref_frame)) |
| 755 continue; | 786 continue; |
| 756 | 787 |
| 757 // Select prediction reference frames. | 788 // Select prediction reference frames. |
| 758 for (i = 0; i < MAX_MB_PLANE; i++) | 789 for (i = 0; i < MAX_MB_PLANE; i++) |
| 759 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; | 790 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; |
| 760 | 791 |
| 761 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); | 792 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); |
| 762 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); | 793 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); |
| 763 | 794 |
| 764 mbmi->ref_frame[0] = ref_frame; | 795 mbmi->ref_frame[0] = ref_frame; |
| 765 set_ref_ptrs(cm, xd, ref_frame, NONE); | 796 set_ref_ptrs(cm, xd, ref_frame, NONE); |
| 766 | 797 |
| 767 for (i = 0; i < INTER_MODES; ++i) { | 798 if (const_motion[ref_frame] && this_mode == NEARMV) |
| 768 int rate_mv = 0; | 799 continue; |
| 769 int mode_rd_thresh; | |
| 770 int mode_index; | |
| 771 this_mode = inter_mode_set[i]; | |
| 772 mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; | |
| 773 | 800 |
| 774 if (const_motion[ref_frame] && this_mode == NEARMV) | 801 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) |
| 802 continue; |
| 803 |
| 804 mode_rd_thresh = best_mode_skip_txfm ? |
| 805 rd_threshes[mode_index] << 1 : rd_threshes[mode_index]; |
| 806 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh, |
| 807 rd_thresh_freq_fact[mode_index])) |
| 808 continue; |
| 809 |
| 810 if (this_mode == NEWMV) { |
| 811 if (cpi->sf.partition_search_type != VAR_BASED_PARTITION |
| 812 && best_rdc.rdcost < (int64_t) (1 << num_pels_log2_lookup[bsize])) |
| 775 continue; | 813 continue; |
| 814 if (ref_frame > LAST_FRAME) { |
| 815 int tmp_sad; |
| 816 int dis, cost_list[5]; |
| 776 | 817 |
| 777 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) | 818 if (bsize < BLOCK_16X16) |
| 819 continue; |
| 820 |
| 821 tmp_sad = vp9_int_pro_motion_estimation(cpi, x, bsize); |
| 822 if (tmp_sad > x->pred_mv_sad[LAST_FRAME]) |
| 823 continue; |
| 824 |
| 825 frame_mv[NEWMV][ref_frame].as_int = mbmi->mv[0].as_int; |
| 826 rate_mv = vp9_mv_bit_cost(&frame_mv[NEWMV][ref_frame].as_mv, |
| 827 &mbmi->ref_mvs[ref_frame][0].as_mv, |
| 828 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
| 829 frame_mv[NEWMV][ref_frame].as_mv.row >>= 3; |
| 830 frame_mv[NEWMV][ref_frame].as_mv.col >>= 3; |
| 831 |
| 832 cpi->find_fractional_mv_step(x, &frame_mv[NEWMV][ref_frame].as_mv, |
| 833 &mbmi->ref_mvs[ref_frame][0].as_mv, |
| 834 cpi->common.allow_high_precision_mv, |
| 835 x->errorperbit, |
| 836 &cpi->fn_ptr[bsize], |
| 837 cpi->sf.mv.subpel_force_stop, |
| 838 cpi->sf.mv.subpel_iters_per_step, |
| 839 cond_cost_list(cpi, cost_list), |
| 840 x->nmvjointcost, x->mvcost, &dis, |
| 841 &x->pred_sse[ref_frame], NULL, 0, 0); |
| 842 } else if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, |
| 843 &frame_mv[NEWMV][ref_frame], &rate_mv, best_rdc.rdcost)) { |
| 778 continue; | 844 continue; |
| 845 } |
| 846 } |
| 779 | 847 |
| 780 mode_rd_thresh = best_mode_skip_txfm ? rd_threshes[mode_index] << 1 : | 848 if (this_mode != NEARESTMV && frame_mv[this_mode][ref_frame].as_int == |
| 781 rd_threshes[mode_index]; | 849 frame_mv[NEARESTMV][ref_frame].as_int) |
| 782 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh, | 850 continue; |
| 783 rd_thresh_freq_fact[mode_index])) | |
| 784 continue; | |
| 785 | 851 |
| 786 if (this_mode == NEWMV) { | 852 mbmi->mode = this_mode; |
| 787 if (ref_frame > LAST_FRAME) | 853 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; |
| 788 continue; | 854 |
| 789 if (cpi->sf.partition_search_type != VAR_BASED_PARTITION && | 855 // Search for the best prediction filter type, when the resulting |
| 790 best_rdc.rdcost < (int64_t)(1 << num_pels_log2_lookup[bsize])) | 856 // motion vector is at sub-pixel accuracy level for luma component, i.e., |
| 791 continue; | 857 // the last three bits are all zeros. |
| 792 if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, | 858 if (reuse_inter_pred) { |
| 793 &frame_mv[NEWMV][ref_frame], | 859 if (!this_mode_pred) { |
| 794 &rate_mv, best_rdc.rdcost)) | 860 this_mode_pred = &tmp[3]; |
| 795 continue; | 861 } else { |
| 862 this_mode_pred = &tmp[get_pred_buffer(tmp, 3)]; |
| 863 pd->dst.buf = this_mode_pred->data; |
| 864 pd->dst.stride = bw; |
| 796 } | 865 } |
| 866 } |
| 797 | 867 |
| 798 if (this_mode != NEARESTMV && | 868 if ((this_mode == NEWMV || filter_ref == SWITCHABLE) && pred_filter_search |
| 799 frame_mv[this_mode][ref_frame].as_int == | 869 && (ref_frame == LAST_FRAME) |
| 800 frame_mv[NEARESTMV][ref_frame].as_int) | 870 && (((mbmi->mv[0].as_mv.row | mbmi->mv[0].as_mv.col) & 0x07) != 0)) { |
| 801 continue; | 871 int pf_rate[3]; |
| 872 int64_t pf_dist[3]; |
| 873 unsigned int pf_var[3]; |
| 874 unsigned int pf_sse[3]; |
| 875 TX_SIZE pf_tx_size[3]; |
| 876 int64_t best_cost = INT64_MAX; |
| 877 INTERP_FILTER best_filter = SWITCHABLE, filter; |
| 878 PRED_BUFFER *current_pred = this_mode_pred; |
| 802 | 879 |
| 803 mbmi->mode = this_mode; | 880 for (filter = EIGHTTAP; filter <= EIGHTTAP_SHARP; ++filter) { |
| 804 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; | 881 int64_t cost; |
| 882 mbmi->interp_filter = filter; |
| 883 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); |
| 884 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[filter], &pf_dist[filter], |
| 885 &pf_var[filter], &pf_sse[filter]); |
| 886 pf_rate[filter] += vp9_get_switchable_rate(cpi, xd); |
| 887 cost = RDCOST(x->rdmult, x->rddiv, pf_rate[filter], pf_dist[filter]); |
| 888 pf_tx_size[filter] = mbmi->tx_size; |
| 889 if (cost < best_cost) { |
| 890 best_filter = filter; |
| 891 best_cost = cost; |
| 892 skip_txfm = x->skip_txfm[0]; |
| 805 | 893 |
| 806 // Search for the best prediction filter type, when the resulting | 894 if (reuse_inter_pred) { |
| 807 // motion vector is at sub-pixel accuracy level for luma component, i.e., | 895 if (this_mode_pred != current_pred) { |
| 808 // the last three bits are all zeros. | 896 free_pred_buffer(this_mode_pred); |
| 809 if (reuse_inter_pred) { | 897 this_mode_pred = current_pred; |
| 810 if (!this_mode_pred) { | 898 } |
| 811 this_mode_pred = &tmp[3]; | 899 |
| 812 } else { | 900 if (filter < EIGHTTAP_SHARP) { |
| 813 this_mode_pred = &tmp[get_pred_buffer(tmp, 3)]; | 901 current_pred = &tmp[get_pred_buffer(tmp, 3)]; |
| 814 pd->dst.buf = this_mode_pred->data; | 902 pd->dst.buf = current_pred->data; |
| 815 pd->dst.stride = bw; | 903 pd->dst.stride = bw; |
| 904 } |
| 905 } |
| 816 } | 906 } |
| 817 } | 907 } |
| 818 | 908 |
| 819 if ((this_mode == NEWMV || filter_ref == SWITCHABLE) && | 909 if (reuse_inter_pred && this_mode_pred != current_pred) |
| 820 pred_filter_search && | 910 free_pred_buffer(current_pred); |
| 821 ((mbmi->mv[0].as_mv.row & 0x07) != 0 || | |
| 822 (mbmi->mv[0].as_mv.col & 0x07) != 0)) { | |
| 823 int pf_rate[3]; | |
| 824 int64_t pf_dist[3]; | |
| 825 unsigned int pf_var[3]; | |
| 826 unsigned int pf_sse[3]; | |
| 827 TX_SIZE pf_tx_size[3]; | |
| 828 int64_t best_cost = INT64_MAX; | |
| 829 INTERP_FILTER best_filter = SWITCHABLE, filter; | |
| 830 PRED_BUFFER *current_pred = this_mode_pred; | |
| 831 | 911 |
| 832 for (filter = EIGHTTAP; filter <= EIGHTTAP_SHARP; ++filter) { | 912 mbmi->interp_filter = best_filter; |
| 833 int64_t cost; | 913 mbmi->tx_size = pf_tx_size[mbmi->interp_filter]; |
| 834 mbmi->interp_filter = filter; | 914 this_rdc.rate = pf_rate[mbmi->interp_filter]; |
| 835 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); | 915 this_rdc.dist = pf_dist[mbmi->interp_filter]; |
| 836 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[filter], | 916 var_y = pf_var[mbmi->interp_filter]; |
| 837 &pf_dist[filter], &pf_var[filter], &pf_sse[filter]); | 917 sse_y = pf_sse[mbmi->interp_filter]; |
| 838 pf_rate[filter] += vp9_get_switchable_rate(cpi, xd); | 918 x->skip_txfm[0] = skip_txfm; |
| 839 cost = RDCOST(x->rdmult, x->rddiv, pf_rate[filter], pf_dist[filter]); | 919 } else { |
| 840 pf_tx_size[filter] = mbmi->tx_size; | 920 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP : filter_ref; |
| 841 if (cost < best_cost) { | 921 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); |
| 842 best_filter = filter; | 922 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist, |
| 843 best_cost = cost; | 923 &var_y, &sse_y); |
| 844 skip_txfm = x->skip_txfm[0]; | 924 this_rdc.rate += |
| 925 cm->interp_filter == SWITCHABLE ? |
| 926 vp9_get_switchable_rate(cpi, xd) : 0; |
| 927 } |
| 845 | 928 |
| 846 if (reuse_inter_pred) { | 929 // chroma component rate-distortion cost modeling |
| 847 if (this_mode_pred != current_pred) { | 930 if (x->color_sensitivity[0] || x->color_sensitivity[1]) { |
| 848 free_pred_buffer(this_mode_pred); | 931 int uv_rate = 0; |
| 849 this_mode_pred = current_pred; | 932 int64_t uv_dist = 0; |
| 850 } | 933 if (x->color_sensitivity[0]) |
| 934 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 1); |
| 935 if (x->color_sensitivity[1]) |
| 936 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 2); |
| 937 model_rd_for_sb_uv(cpi, bsize, x, xd, &uv_rate, &uv_dist, &var_y, &sse_y); |
| 938 this_rdc.rate += uv_rate; |
| 939 this_rdc.dist += uv_dist; |
| 940 } |
| 851 | 941 |
| 852 if (filter < EIGHTTAP_SHARP) { | 942 this_rdc.rate += rate_mv; |
| 853 current_pred = &tmp[get_pred_buffer(tmp, 3)]; | 943 this_rdc.rate += |
| 854 pd->dst.buf = current_pred->data; | 944 cpi->inter_mode_cost[mbmi->mode_context[ref_frame]][INTER_OFFSET( |
| 855 pd->dst.stride = bw; | 945 this_mode)]; |
| 856 } | 946 this_rdc.rate += ref_frame_cost[ref_frame]; |
| 857 } | 947 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, this_rdc.rate, this_rdc.dist); |
| 858 } | |
| 859 } | |
| 860 | 948 |
| 861 if (reuse_inter_pred && this_mode_pred != current_pred) | 949 // Skipping checking: test to see if this block can be reconstructed by |
| 862 free_pred_buffer(current_pred); | 950 // prediction only. |
| 863 | 951 if (cpi->allow_encode_breakout) { |
| 864 mbmi->interp_filter = best_filter; | 952 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame, this_mode, |
| 865 mbmi->tx_size = pf_tx_size[mbmi->interp_filter]; | 953 var_y, sse_y, yv12_mb, &this_rdc.rate, |
| 866 this_rdc.rate = pf_rate[mbmi->interp_filter]; | 954 &this_rdc.dist); |
| 867 this_rdc.dist = pf_dist[mbmi->interp_filter]; | 955 if (x->skip) { |
| 868 var_y = pf_var[mbmi->interp_filter]; | 956 this_rdc.rate += rate_mv; |
| 869 sse_y = pf_sse[mbmi->interp_filter]; | 957 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, this_rdc.rate, |
| 870 x->skip_txfm[0] = skip_txfm; | 958 this_rdc.dist); |
| 871 } else { | |
| 872 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref; | |
| 873 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); | |
| 874 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist, | |
| 875 &var_y, &sse_y); | |
| 876 this_rdc.rate += cm->interp_filter == SWITCHABLE ? | |
| 877 vp9_get_switchable_rate(cpi, xd) : 0; | |
| 878 } | 959 } |
| 879 | 960 } |
| 880 // chroma component rate-distortion cost modeling | |
| 881 if (x->color_sensitivity[0] || x->color_sensitivity[1]) { | |
| 882 int uv_rate = 0; | |
| 883 int64_t uv_dist = 0; | |
| 884 if (x->color_sensitivity[0]) | |
| 885 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 1); | |
| 886 if (x->color_sensitivity[1]) | |
| 887 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 2); | |
| 888 model_rd_for_sb_uv(cpi, bsize, x, xd, &uv_rate, &uv_dist, | |
| 889 &var_y, &sse_y); | |
| 890 this_rdc.rate += uv_rate; | |
| 891 this_rdc.dist += uv_dist; | |
| 892 } | |
| 893 | |
| 894 this_rdc.rate += rate_mv; | |
| 895 this_rdc.rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] | |
| 896 [INTER_OFFSET(this_mode)]; | |
| 897 this_rdc.rate += ref_frame_cost[ref_frame]; | |
| 898 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, | |
| 899 this_rdc.rate, this_rdc.dist); | |
| 900 | |
| 901 // Skipping checking: test to see if this block can be reconstructed by | |
| 902 // prediction only. | |
| 903 if (cpi->allow_encode_breakout) { | |
| 904 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame, | |
| 905 this_mode, var_y, sse_y, yv12_mb, | |
| 906 &this_rdc.rate, &this_rdc.dist); | |
| 907 if (x->skip) { | |
| 908 this_rdc.rate += rate_mv; | |
| 909 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, | |
| 910 this_rdc.rate, this_rdc.dist); | |
| 911 } | |
| 912 } | |
| 913 | 961 |
| 914 #if CONFIG_VP9_TEMPORAL_DENOISING | 962 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 915 if (cpi->oxcf.noise_sensitivity > 0) | 963 if (cpi->oxcf.noise_sensitivity > 0) |
| 916 vp9_denoiser_update_frame_stats(mbmi, sse_y, this_mode, ctx); | 964 vp9_denoiser_update_frame_stats(mbmi, sse_y, this_mode, ctx); |
| 917 #else | 965 #else |
| 918 (void)ctx; | 966 (void)ctx; |
| 919 #endif | 967 #endif |
| 920 | 968 |
| 921 if (this_rdc.rdcost < best_rdc.rdcost || x->skip) { | 969 if (this_rdc.rdcost < best_rdc.rdcost || x->skip) { |
| 922 best_rdc = this_rdc; | 970 best_rdc = this_rdc; |
| 923 best_mode = this_mode; | 971 best_mode = this_mode; |
| 924 best_pred_filter = mbmi->interp_filter; | 972 best_pred_filter = mbmi->interp_filter; |
| 925 best_tx_size = mbmi->tx_size; | 973 best_tx_size = mbmi->tx_size; |
| 926 best_ref_frame = ref_frame; | 974 best_ref_frame = ref_frame; |
| 927 best_mode_skip_txfm = x->skip_txfm[0]; | 975 best_mode_skip_txfm = x->skip_txfm[0]; |
| 928 | 976 |
| 929 if (reuse_inter_pred) { | 977 if (reuse_inter_pred) { |
| 930 free_pred_buffer(best_pred); | 978 free_pred_buffer(best_pred); |
| 931 best_pred = this_mode_pred; | 979 best_pred = this_mode_pred; |
| 932 } | |
| 933 } else { | |
| 934 if (reuse_inter_pred) | |
| 935 free_pred_buffer(this_mode_pred); | |
| 936 } | 980 } |
| 937 | 981 } else { |
| 938 if (x->skip) | 982 if (reuse_inter_pred) |
| 939 break; | 983 free_pred_buffer(this_mode_pred); |
| 940 } | 984 } |
| 941 | 985 |
| 942 // Check that a prediction mode has been selected. | |
| 943 assert(best_rdc.rdcost < INT64_MAX); | |
| 944 | |
| 945 if (x->skip) | 986 if (x->skip) |
| 946 break; | 987 break; |
| 947 } | 988 } |
| 948 | 989 |
| 949 mbmi->mode = best_mode; | 990 mbmi->mode = best_mode; |
| 950 mbmi->interp_filter = best_pred_filter; | 991 mbmi->interp_filter = best_pred_filter; |
| 951 mbmi->tx_size = best_tx_size; | 992 mbmi->tx_size = best_tx_size; |
| 952 mbmi->ref_frame[0] = best_ref_frame; | 993 mbmi->ref_frame[0] = best_ref_frame; |
| 953 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; | 994 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; |
| 954 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; | 995 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 #endif // CONFIG_VP9_HIGHBITDEPTH | 1086 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1046 } | 1087 } |
| 1047 } | 1088 } |
| 1048 | 1089 |
| 1049 if (cpi->sf.adaptive_rd_thresh) { | 1090 if (cpi->sf.adaptive_rd_thresh) { |
| 1050 THR_MODES best_mode_idx = is_inter_block(mbmi) ? | 1091 THR_MODES best_mode_idx = is_inter_block(mbmi) ? |
| 1051 mode_idx[best_ref_frame][INTER_OFFSET(mbmi->mode)] : | 1092 mode_idx[best_ref_frame][INTER_OFFSET(mbmi->mode)] : |
| 1052 mode_idx[INTRA_FRAME][mbmi->mode]; | 1093 mode_idx[INTRA_FRAME][mbmi->mode]; |
| 1053 PREDICTION_MODE this_mode; | 1094 PREDICTION_MODE this_mode; |
| 1054 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { | 1095 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { |
| 1096 if (best_ref_frame != ref_frame) continue; |
| 1055 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 1097 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
| 1056 THR_MODES thr_mode_idx = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; | 1098 THR_MODES thr_mode_idx = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; |
| 1057 int *freq_fact = &tile_data->thresh_freq_fact[bsize][thr_mode_idx]; | 1099 int *freq_fact = &tile_data->thresh_freq_fact[bsize][thr_mode_idx]; |
| 1058 if (thr_mode_idx == best_mode_idx) | 1100 if (thr_mode_idx == best_mode_idx) |
| 1059 *freq_fact -= (*freq_fact >> 4); | 1101 *freq_fact -= (*freq_fact >> 4); |
| 1060 else | 1102 else |
| 1061 *freq_fact = MIN(*freq_fact + RD_THRESH_INC, | 1103 *freq_fact = MIN(*freq_fact + RD_THRESH_INC, |
| 1062 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT); | 1104 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT); |
| 1063 } | 1105 } |
| 1064 } | 1106 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 xd->mi[0].bmi[block + 2] = bsi[best_ref_frame][block]; | 1365 xd->mi[0].bmi[block + 2] = bsi[best_ref_frame][block]; |
| 1324 } | 1366 } |
| 1325 } | 1367 } |
| 1326 mbmi->mode = xd->mi[0].bmi[3].as_mode; | 1368 mbmi->mode = xd->mi[0].bmi[3].as_mode; |
| 1327 ctx->mic = *(xd->mi[0].src_mi); | 1369 ctx->mic = *(xd->mi[0].src_mi); |
| 1328 ctx->skip_txfm[0] = 0; | 1370 ctx->skip_txfm[0] = 0; |
| 1329 ctx->skip = 0; | 1371 ctx->skip = 0; |
| 1330 // Dummy assignment for speed -5. No effect in speed -6. | 1372 // Dummy assignment for speed -5. No effect in speed -6. |
| 1331 rd_cost->rdcost = best_rd; | 1373 rd_cost->rdcost = best_rd; |
| 1332 } | 1374 } |
| OLD | NEW |