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

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

Issue 958693004: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 10 months 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.c ('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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 int *out_rate_sum, int64_t *out_dist_sum, 209 int *out_rate_sum, int64_t *out_dist_sum,
210 unsigned int *var_y, unsigned int *sse_y) { 210 unsigned int *var_y, unsigned int *sse_y) {
211 // Note our transform coeffs are 8 times an orthogonal transform. 211 // Note our transform coeffs are 8 times an orthogonal transform.
212 // Hence quantizer step is also 8 times. To get effective quantizer 212 // Hence quantizer step is also 8 times. To get effective quantizer
213 // we need to divide by 8 before sending to modeling function. 213 // we need to divide by 8 before sending to modeling function.
214 unsigned int sse; 214 unsigned int sse;
215 int rate; 215 int rate;
216 int64_t dist; 216 int64_t dist;
217 struct macroblock_plane *const p = &x->plane[0]; 217 struct macroblock_plane *const p = &x->plane[0];
218 struct macroblockd_plane *const pd = &xd->plane[0]; 218 struct macroblockd_plane *const pd = &xd->plane[0];
219 const int64_t dc_thr = p->quant_thred[0] >> 6;
220 const int64_t ac_thr = p->quant_thred[1] >> 6;
219 const uint32_t dc_quant = pd->dequant[0]; 221 const uint32_t dc_quant = pd->dequant[0];
220 const uint32_t ac_quant = pd->dequant[1]; 222 const uint32_t ac_quant = pd->dequant[1];
221 unsigned int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride, 223 unsigned int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride,
222 pd->dst.buf, pd->dst.stride, &sse); 224 pd->dst.buf, pd->dst.stride, &sse);
223 *var_y = var; 225 *var_y = var;
224 *sse_y = sse; 226 *sse_y = sse;
225 227
226 if (sse < dc_quant * dc_quant >> 6) 228 x->skip_txfm[0] = 0;
227 x->skip_txfm[0] = 1; 229 // Check if all ac coefficients can be quantized to zero.
228 else if (var < ac_quant * ac_quant >> 6) 230 if (var < ac_thr || var == 0) {
229 x->skip_txfm[0] = 2; 231 x->skip_txfm[0] = 2;
230 else 232 // Check if dc coefficient can be quantized to zero.
231 x->skip_txfm[0] = 0; 233 if (sse - var < dc_thr || sse == var)
234 x->skip_txfm[0] = 1;
235 }
232 236
233 if (cpi->common.tx_mode == TX_MODE_SELECT) { 237 if (cpi->common.tx_mode == TX_MODE_SELECT) {
234 if (sse > (var << 2)) 238 if (sse > (var << 2))
235 xd->mi[0].src_mi->mbmi.tx_size = 239 xd->mi[0].src_mi->mbmi.tx_size =
236 MIN(max_txsize_lookup[bsize], 240 MIN(max_txsize_lookup[bsize],
237 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); 241 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
238 else 242 else
239 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8; 243 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8;
240 244
241 if (cpi->sf.partition_search_type == VAR_BASED_PARTITION && 245 if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) {
242 xd->mi[0].src_mi->mbmi.tx_size > TX_16X16) 246 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
243 xd->mi[0].src_mi->mbmi.tx_size = TX_16X16; 247 xd->mi[0].src_mi->mbmi.segment_id != CR_SEGMENT_ID_BASE)
248 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8;
249 else if (xd->mi[0].src_mi->mbmi.tx_size > TX_16X16)
250 xd->mi[0].src_mi->mbmi.tx_size = TX_16X16;
251 }
244 } else { 252 } else {
245 xd->mi[0].src_mi->mbmi.tx_size = 253 xd->mi[0].src_mi->mbmi.tx_size =
246 MIN(max_txsize_lookup[bsize], 254 MIN(max_txsize_lookup[bsize],
247 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); 255 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
248 } 256 }
249 257
250 #if CONFIG_VP9_HIGHBITDEPTH 258 #if CONFIG_VP9_HIGHBITDEPTH
251 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 259 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
252 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize], 260 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
253 dc_quant >> (xd->bd - 5), &rate, &dist); 261 dc_quant >> (xd->bd - 5), &rate, &dist);
(...skipping 22 matching lines...) Expand all
276 ac_quant >> 3, &rate, &dist); 284 ac_quant >> 3, &rate, &dist);
277 #endif // CONFIG_VP9_HIGHBITDEPTH 285 #endif // CONFIG_VP9_HIGHBITDEPTH
278 286
279 *out_rate_sum += rate; 287 *out_rate_sum += rate;
280 *out_dist_sum += dist << 4; 288 *out_dist_sum += dist << 4;
281 289
282 if (*out_rate_sum == 0) 290 if (*out_rate_sum == 0)
283 x->skip_txfm[0] = 1; 291 x->skip_txfm[0] = 1;
284 } 292 }
285 293
294 static void model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE bsize,
295 MACROBLOCK *x, MACROBLOCKD *xd,
296 int *out_rate_sum, int64_t *out_dist_sum,
297 unsigned int *var_y, unsigned int *sse_y) {
298 // Note our transform coeffs are 8 times an orthogonal transform.
299 // Hence quantizer step is also 8 times. To get effective quantizer
300 // we need to divide by 8 before sending to modeling function.
301 unsigned int sse;
302 int rate;
303 int64_t dist;
304 int i;
305
306 *out_rate_sum = 0;
307 *out_dist_sum = 0;
308
309 for (i = 1; i <= 2; ++i) {
310 struct macroblock_plane *const p = &x->plane[i];
311 struct macroblockd_plane *const pd = &xd->plane[i];
312 const uint32_t dc_quant = pd->dequant[0];
313 const uint32_t ac_quant = pd->dequant[1];
314 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd);
315 unsigned int var;
316
317 if (!x->color_sensitivity[i - 1])
318 continue;
319
320 var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride,
321 pd->dst.buf, pd->dst.stride, &sse);
322 *var_y += var;
323 *sse_y += sse;
324
325 #if CONFIG_VP9_HIGHBITDEPTH
326 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
327 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bs],
328 dc_quant >> (xd->bd - 5), &rate, &dist);
329 } else {
330 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bs],
331 dc_quant >> 3, &rate, &dist);
332 }
333 #else
334 vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bs],
335 dc_quant >> 3, &rate, &dist);
336 #endif // CONFIG_VP9_HIGHBITDEPTH
337
338 *out_rate_sum += rate >> 1;
339 *out_dist_sum += dist << 3;
340
341 #if CONFIG_VP9_HIGHBITDEPTH
342 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
343 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bs],
344 ac_quant >> (xd->bd - 5), &rate, &dist);
345 } else {
346 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bs],
347 ac_quant >> 3, &rate, &dist);
348 }
349 #else
350 vp9_model_rd_from_var_lapndz(var, num_pels_log2_lookup[bs],
351 ac_quant >> 3, &rate, &dist);
352 #endif // CONFIG_VP9_HIGHBITDEPTH
353
354 *out_rate_sum += rate;
355 *out_dist_sum += dist << 4;
356 }
357 }
358
286 static int get_pred_buffer(PRED_BUFFER *p, int len) { 359 static int get_pred_buffer(PRED_BUFFER *p, int len) {
287 int i; 360 int i;
288 361
289 for (i = 0; i < len; i++) { 362 for (i = 0; i < len; i++) {
290 if (!p[i].in_use) { 363 if (!p[i].in_use) {
291 p[i].in_use = 1; 364 p[i].in_use = 1;
292 return i; 365 return i;
293 } 366 }
294 } 367 }
295 return -1; 368 return -1;
(...skipping 22 matching lines...) Expand all
318 unsigned int thresh_dc; 391 unsigned int thresh_dc;
319 if (x->encode_breakout > 0) { 392 if (x->encode_breakout > 0) {
320 // Set a maximum for threshold to avoid big PSNR loss in low bit rate 393 // Set a maximum for threshold to avoid big PSNR loss in low bit rate
321 // case. Use extreme low threshold for static frames to limit 394 // case. Use extreme low threshold for static frames to limit
322 // skipping. 395 // skipping.
323 const unsigned int max_thresh = 36000; 396 const unsigned int max_thresh = 36000;
324 // The encode_breakout input 397 // The encode_breakout input
325 const unsigned int min_thresh = 398 const unsigned int min_thresh =
326 MIN(((unsigned int)x->encode_breakout << 4), max_thresh); 399 MIN(((unsigned int)x->encode_breakout << 4), max_thresh);
327 #if CONFIG_VP9_HIGHBITDEPTH 400 #if CONFIG_VP9_HIGHBITDEPTH
328 const int shift = 2 * xd->bd - 16; 401 const int shift = (xd->bd << 1) - 16;
329 #endif 402 #endif
330 403
331 // Calculate threshold according to dequant value. 404 // Calculate threshold according to dequant value.
332 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; 405 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) >> 3;
333 #if CONFIG_VP9_HIGHBITDEPTH 406 #if CONFIG_VP9_HIGHBITDEPTH
334 if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) && shift > 0) { 407 if ((xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) && shift > 0) {
335 thresh_ac = ROUND_POWER_OF_TWO(thresh_ac, shift); 408 thresh_ac = ROUND_POWER_OF_TWO(thresh_ac, shift);
336 } 409 }
337 #endif // CONFIG_VP9_HIGHBITDEPTH 410 #endif // CONFIG_VP9_HIGHBITDEPTH
338 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh); 411 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh);
339 412
340 // Adjust ac threshold according to partition size. 413 // Adjust ac threshold according to partition size.
341 thresh_ac >>= 414 thresh_ac >>=
342 8 - (b_width_log2_lookup[bsize] + b_height_log2_lookup[bsize]); 415 8 - (b_width_log2_lookup[bsize] + b_height_log2_lookup[bsize]);
(...skipping 21 matching lines...) Expand all
364 xd->plane[2].pre[0] = yv12_mb[ref_frame][2]; 437 xd->plane[2].pre[0] = yv12_mb[ref_frame][2];
365 vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, bsize); 438 vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, bsize);
366 } 439 }
367 440
368 var_u = cpi->fn_ptr[uv_size].vf(x->plane[1].src.buf, 441 var_u = cpi->fn_ptr[uv_size].vf(x->plane[1].src.buf,
369 x->plane[1].src.stride, 442 x->plane[1].src.stride,
370 xd->plane[1].dst.buf, 443 xd->plane[1].dst.buf,
371 xd->plane[1].dst.stride, &sse_u); 444 xd->plane[1].dst.stride, &sse_u);
372 445
373 // U skipping condition checking 446 // U skipping condition checking
374 if ((var_u * 4 <= thresh_ac) && (sse_u - var_u <= thresh_dc)) { 447 if (((var_u << 2) <= thresh_ac) && (sse_u - var_u <= thresh_dc)) {
375 var_v = cpi->fn_ptr[uv_size].vf(x->plane[2].src.buf, 448 var_v = cpi->fn_ptr[uv_size].vf(x->plane[2].src.buf,
376 x->plane[2].src.stride, 449 x->plane[2].src.stride,
377 xd->plane[2].dst.buf, 450 xd->plane[2].dst.buf,
378 xd->plane[2].dst.stride, &sse_v); 451 xd->plane[2].dst.stride, &sse_v);
379 452
380 // V skipping condition checking 453 // V skipping condition checking
381 if ((var_v * 4 <= thresh_ac) && (sse_v - var_v <= thresh_dc)) { 454 if (((var_v << 2) <= thresh_ac) && (sse_v - var_v <= thresh_dc)) {
382 x->skip = 1; 455 x->skip = 1;
383 456
384 // The cost of skip bit needs to be added. 457 // The cost of skip bit needs to be added.
385 *rate = cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] 458 *rate = cpi->inter_mode_cost[mbmi->mode_context[ref_frame]]
386 [INTER_OFFSET(this_mode)]; 459 [INTER_OFFSET(this_mode)];
387 460
388 // More on this part of rate 461 // More on this part of rate
389 // rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); 462 // rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
390 463
391 // Scaling factor for SSE from spatial domain to frequency 464 // Scaling factor for SSE from spatial domain to frequency
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 574
502 if (this_rdc.rdcost < best_rdc.rdcost) { 575 if (this_rdc.rdcost < best_rdc.rdcost) {
503 best_rdc = this_rdc; 576 best_rdc = this_rdc;
504 mbmi->mode = this_mode; 577 mbmi->mode = this_mode;
505 } 578 }
506 } 579 }
507 580
508 *rd_cost = best_rdc; 581 *rd_cost = best_rdc;
509 } 582 }
510 583
584 static const PREDICTION_MODE inter_mode_set[INTER_MODES] = {
585 ZEROMV, NEARESTMV, NEARMV, NEWMV,
586 };
587
588 static const int ref_frame_cost[MAX_REF_FRAMES] = {
589 1235, 229, 530, 615,
590 };
511 // TODO(jingning) placeholder for inter-frame non-RD mode decision. 591 // TODO(jingning) placeholder for inter-frame non-RD mode decision.
512 // this needs various further optimizations. to be continued.. 592 // this needs various further optimizations. to be continued..
513 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 593 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
514 TileDataEnc *tile_data, 594 TileDataEnc *tile_data,
515 int mi_row, int mi_col, RD_COST *rd_cost, 595 int mi_row, int mi_col, RD_COST *rd_cost,
516 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { 596 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
517 VP9_COMMON *const cm = &cpi->common; 597 VP9_COMMON *const cm = &cpi->common;
518 TileInfo *const tile_info = &tile_data->tile_info; 598 TileInfo *const tile_info = &tile_data->tile_info;
519 MACROBLOCKD *const xd = &x->e_mbd; 599 MACROBLOCKD *const xd = &x->e_mbd;
520 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 600 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (cpi->ref_frame_flags & flag_list[ref_frame]) { 697 if (cpi->ref_frame_flags & flag_list[ref_frame]) {
618 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); 698 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
619 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; 699 int_mv *const candidates = mbmi->ref_mvs[ref_frame];
620 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; 700 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
621 701
622 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, 702 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col,
623 sf, sf); 703 sf, sf);
624 704
625 if (cm->use_prev_frame_mvs) 705 if (cm->use_prev_frame_mvs)
626 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame, 706 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame,
627 candidates, mi_row, mi_col); 707 candidates, mi_row, mi_col, NULL, NULL);
628 else 708 else
629 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile_info, 709 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile_info,
630 xd->mi[0].src_mi, 710 xd->mi[0].src_mi,
631 ref_frame, candidates, 711 ref_frame, candidates,
632 mi_row, mi_col); 712 mi_row, mi_col);
633 713
634 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, 714 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
635 &frame_mv[NEARESTMV][ref_frame], 715 &frame_mv[NEARESTMV][ref_frame],
636 &frame_mv[NEARMV][ref_frame]); 716 &frame_mv[NEARMV][ref_frame]);
637 717
(...skipping 13 matching lines...) Expand all
651 continue; 731 continue;
652 732
653 if (cpi->ref_frame_flags & flag_list[i]) 733 if (cpi->ref_frame_flags & flag_list[i])
654 if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1)) 734 if (x->pred_mv_sad[ref_frame] > (x->pred_mv_sad[i] << 1))
655 ref_frame_skip_mask |= (1 << ref_frame); 735 ref_frame_skip_mask |= (1 << ref_frame);
656 736
657 if (ref_frame_skip_mask & (1 << ref_frame)) 737 if (ref_frame_skip_mask & (1 << ref_frame))
658 continue; 738 continue;
659 739
660 // Select prediction reference frames. 740 // Select prediction reference frames.
661 xd->plane[0].pre[0] = yv12_mb[ref_frame][0]; 741 for (i = 0; i < MAX_MB_PLANE; i++)
742 xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
662 743
663 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd); 744 clamp_mv2(&frame_mv[NEARESTMV][ref_frame].as_mv, xd);
664 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd); 745 clamp_mv2(&frame_mv[NEARMV][ref_frame].as_mv, xd);
665 746
666 mbmi->ref_frame[0] = ref_frame; 747 mbmi->ref_frame[0] = ref_frame;
667 set_ref_ptrs(cm, xd, ref_frame, NONE); 748 set_ref_ptrs(cm, xd, ref_frame, NONE);
668 749
669 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { 750 for (i = 0; i < INTER_MODES; ++i) {
670 int rate_mv = 0; 751 int rate_mv = 0;
671 int mode_rd_thresh; 752 int mode_rd_thresh;
672 int mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)]; 753 int mode_index;
754 this_mode = inter_mode_set[i];
755 mode_index = mode_idx[ref_frame][INTER_OFFSET(this_mode)];
673 756
674 if (const_motion[ref_frame] && this_mode == NEARMV) 757 if (const_motion[ref_frame] && this_mode == NEARMV)
675 continue; 758 continue;
676 759
677 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) 760 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode)))
678 continue; 761 continue;
679 762
680 mode_rd_thresh = best_mode_skip_txfm ? rd_threshes[mode_index] << 1 : 763 mode_rd_thresh = best_mode_skip_txfm ? rd_threshes[mode_index] << 1 :
681 rd_threshes[mode_index]; 764 rd_threshes[mode_index];
682 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh, 765 if (rd_less_than_thresh(best_rdc.rdcost, mode_rd_thresh,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 int64_t best_cost = INT64_MAX; 811 int64_t best_cost = INT64_MAX;
729 INTERP_FILTER best_filter = SWITCHABLE, filter; 812 INTERP_FILTER best_filter = SWITCHABLE, filter;
730 PRED_BUFFER *current_pred = this_mode_pred; 813 PRED_BUFFER *current_pred = this_mode_pred;
731 814
732 for (filter = EIGHTTAP; filter <= EIGHTTAP_SHARP; ++filter) { 815 for (filter = EIGHTTAP; filter <= EIGHTTAP_SHARP; ++filter) {
733 int64_t cost; 816 int64_t cost;
734 mbmi->interp_filter = filter; 817 mbmi->interp_filter = filter;
735 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); 818 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
736 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[filter], 819 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[filter],
737 &pf_dist[filter], &pf_var[filter], &pf_sse[filter]); 820 &pf_dist[filter], &pf_var[filter], &pf_sse[filter]);
738 cost = RDCOST(x->rdmult, x->rddiv, 821 pf_rate[filter] += vp9_get_switchable_rate(cpi, xd);
739 vp9_get_switchable_rate(cpi, xd) + pf_rate[filter], 822 cost = RDCOST(x->rdmult, x->rddiv, pf_rate[filter], pf_dist[filter]);
740 pf_dist[filter]);
741 pf_tx_size[filter] = mbmi->tx_size; 823 pf_tx_size[filter] = mbmi->tx_size;
742 if (cost < best_cost) { 824 if (cost < best_cost) {
743 best_filter = filter; 825 best_filter = filter;
744 best_cost = cost; 826 best_cost = cost;
745 skip_txfm = x->skip_txfm[0]; 827 skip_txfm = x->skip_txfm[0];
746 828
747 if (reuse_inter_pred) { 829 if (reuse_inter_pred) {
748 if (this_mode_pred != current_pred) { 830 if (this_mode_pred != current_pred) {
749 free_pred_buffer(this_mode_pred); 831 free_pred_buffer(this_mode_pred);
750 this_mode_pred = current_pred; 832 this_mode_pred = current_pred;
(...skipping 16 matching lines...) Expand all
767 this_rdc.rate = pf_rate[mbmi->interp_filter]; 849 this_rdc.rate = pf_rate[mbmi->interp_filter];
768 this_rdc.dist = pf_dist[mbmi->interp_filter]; 850 this_rdc.dist = pf_dist[mbmi->interp_filter];
769 var_y = pf_var[mbmi->interp_filter]; 851 var_y = pf_var[mbmi->interp_filter];
770 sse_y = pf_sse[mbmi->interp_filter]; 852 sse_y = pf_sse[mbmi->interp_filter];
771 x->skip_txfm[0] = skip_txfm; 853 x->skip_txfm[0] = skip_txfm;
772 } else { 854 } else {
773 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref; 855 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref;
774 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); 856 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize);
775 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist, 857 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist,
776 &var_y, &sse_y); 858 &var_y, &sse_y);
859 this_rdc.rate += cm->interp_filter == SWITCHABLE ?
860 vp9_get_switchable_rate(cpi, xd) : 0;
861 }
862
863 // chroma component rate-distortion cost modeling
864 if (x->color_sensitivity[0] || x->color_sensitivity[1]) {
865 int uv_rate = 0;
866 int64_t uv_dist = 0;
867 if (x->color_sensitivity[0])
868 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 1);
869 if (x->color_sensitivity[1])
870 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 2);
871 model_rd_for_sb_uv(cpi, bsize, x, xd, &uv_rate, &uv_dist,
872 &var_y, &sse_y);
873 this_rdc.rate += uv_rate;
874 this_rdc.dist += uv_dist;
777 } 875 }
778 876
779 this_rdc.rate += rate_mv; 877 this_rdc.rate += rate_mv;
780 this_rdc.rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] 878 this_rdc.rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]]
781 [INTER_OFFSET(this_mode)]; 879 [INTER_OFFSET(this_mode)];
880 this_rdc.rate += ref_frame_cost[ref_frame];
782 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, 881 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
783 this_rdc.rate, this_rdc.dist); 882 this_rdc.rate, this_rdc.dist);
784 883
785 // Skipping checking: test to see if this block can be reconstructed by 884 // Skipping checking: test to see if this block can be reconstructed by
786 // prediction only. 885 // prediction only.
787 if (cpi->allow_encode_breakout) { 886 if (cpi->allow_encode_breakout) {
788 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame, 887 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame,
789 this_mode, var_y, sse_y, yv12_mb, 888 this_mode, var_y, sse_y, yv12_mb,
790 &this_rdc.rate, &this_rdc.dist); 889 &this_rdc.rate, &this_rdc.dist);
791 if (x->skip) { 890 if (x->skip) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 continue; 977 continue;
879 args.mode = this_mode; 978 args.mode = this_mode;
880 args.rate = 0; 979 args.rate = 0;
881 args.dist = 0; 980 args.dist = 0;
882 mbmi->tx_size = intra_tx_size; 981 mbmi->tx_size = intra_tx_size;
883 vp9_foreach_transformed_block_in_plane(xd, bsize, 0, 982 vp9_foreach_transformed_block_in_plane(xd, bsize, 0,
884 estimate_block_intra, &args); 983 estimate_block_intra, &args);
885 this_rdc.rate = args.rate; 984 this_rdc.rate = args.rate;
886 this_rdc.dist = args.dist; 985 this_rdc.dist = args.dist;
887 this_rdc.rate += cpi->mbmode_cost[this_mode]; 986 this_rdc.rate += cpi->mbmode_cost[this_mode];
987 this_rdc.rate += ref_frame_cost[INTRA_FRAME];
888 this_rdc.rate += intra_cost_penalty; 988 this_rdc.rate += intra_cost_penalty;
889 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, 989 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
890 this_rdc.rate, this_rdc.dist); 990 this_rdc.rate, this_rdc.dist);
891 991
892 if (this_rdc.rdcost < best_rdc.rdcost) { 992 if (this_rdc.rdcost < best_rdc.rdcost) {
893 best_rdc = this_rdc; 993 best_rdc = this_rdc;
894 mbmi->mode = this_mode; 994 mbmi->mode = this_mode;
895 best_intra_tx_size = mbmi->tx_size; 995 best_intra_tx_size = mbmi->tx_size;
896 mbmi->ref_frame[0] = INTRA_FRAME; 996 mbmi->ref_frame[0] = INTRA_FRAME;
897 mbmi->uv_mode = this_mode; 997 mbmi->uv_mode = this_mode;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 x->pred_mv_sad[ref_frame] = INT_MAX; 1081 x->pred_mv_sad[ref_frame] = INT_MAX;
982 1082
983 if (cpi->ref_frame_flags & flag_list[ref_frame]) { 1083 if (cpi->ref_frame_flags & flag_list[ref_frame]) {
984 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); 1084 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
985 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; 1085 int_mv *const candidates = mbmi->ref_mvs[ref_frame];
986 const struct scale_factors *const sf = 1086 const struct scale_factors *const sf =
987 &cm->frame_refs[ref_frame - 1].sf; 1087 &cm->frame_refs[ref_frame - 1].sf;
988 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, 1088 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col,
989 sf, sf); 1089 sf, sf);
990 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame, 1090 vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0].src_mi, ref_frame,
991 candidates, mi_row, mi_col); 1091 candidates, mi_row, mi_col, NULL, NULL);
992 1092
993 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, 1093 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
994 &dummy_mv[0], &dummy_mv[1]); 1094 &dummy_mv[0], &dummy_mv[1]);
995 } else { 1095 } else {
996 ref_frame_skip_mask |= (1 << ref_frame); 1096 ref_frame_skip_mask |= (1 << ref_frame);
997 } 1097 }
998 } 1098 }
999 1099
1000 mbmi->sb_type = bsize; 1100 mbmi->sb_type = bsize;
1001 mbmi->tx_size = TX_4X4; 1101 mbmi->tx_size = TX_4X4;
(...skipping 29 matching lines...) Expand all
1031 // Select prediction reference frames. 1131 // Select prediction reference frames.
1032 for (plane = 0; plane < MAX_MB_PLANE; plane++) 1132 for (plane = 0; plane < MAX_MB_PLANE; plane++)
1033 xd->plane[plane].pre[0] = yv12_mb[ref_frame][plane]; 1133 xd->plane[plane].pre[0] = yv12_mb[ref_frame][plane];
1034 1134
1035 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { 1135 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
1036 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { 1136 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
1037 int_mv b_mv[MB_MODE_COUNT]; 1137 int_mv b_mv[MB_MODE_COUNT];
1038 int64_t b_best_rd = INT64_MAX; 1138 int64_t b_best_rd = INT64_MAX;
1039 const int i = idy * 2 + idx; 1139 const int i = idy * 2 + idx;
1040 PREDICTION_MODE this_mode; 1140 PREDICTION_MODE this_mode;
1041 int b_rate = 0;
1042 int64_t b_dist = 0;
1043 RD_COST this_rdc; 1141 RD_COST this_rdc;
1044 unsigned int var_y, sse_y; 1142 unsigned int var_y, sse_y;
1045 1143
1046 struct macroblock_plane *p = &x->plane[0]; 1144 struct macroblock_plane *p = &x->plane[0];
1047 struct macroblockd_plane *pd = &xd->plane[0]; 1145 struct macroblockd_plane *pd = &xd->plane[0];
1048 1146
1049 const struct buf_2d orig_src = p->src; 1147 const struct buf_2d orig_src = p->src;
1050 const struct buf_2d orig_dst = pd->dst; 1148 const struct buf_2d orig_dst = pd->dst;
1051 struct buf_2d orig_pre[2]; 1149 struct buf_2d orig_pre[2];
1052 vpx_memcpy(orig_pre, xd->plane[0].pre, sizeof(orig_pre)); 1150 vpx_memcpy(orig_pre, xd->plane[0].pre, sizeof(orig_pre));
1053 1151
1054 // set buffer pointers for sub8x8 motion search. 1152 // set buffer pointers for sub8x8 motion search.
1055 p->src.buf = 1153 p->src.buf =
1056 &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)]; 1154 &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)];
1057 pd->dst.buf = 1155 pd->dst.buf =
1058 &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i, pd->dst.stride)]; 1156 &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i, pd->dst.stride)];
1059 pd->pre[0].buf = 1157 pd->pre[0].buf =
1060 &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8, 1158 &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8,
1061 i, pd->pre[0].stride)]; 1159 i, pd->pre[0].stride)];
1062 1160
1063 b_mv[ZEROMV].as_int = 0; 1161 b_mv[ZEROMV].as_int = 0;
1064 b_mv[NEWMV].as_int = INVALID_MV; 1162 b_mv[NEWMV].as_int = INVALID_MV;
1065 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile_info, i, 0, mi_row, mi_col, 1163 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile_info, i, 0, mi_row, mi_col,
1066 &b_mv[NEARESTMV], 1164 &b_mv[NEARESTMV],
1067 &b_mv[NEARMV]); 1165 &b_mv[NEARMV]);
1068 1166
1069 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { 1167 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
1168 int b_rate = 0;
1070 xd->mi[0].bmi[i].as_mv[0].as_int = b_mv[this_mode].as_int; 1169 xd->mi[0].bmi[i].as_mv[0].as_int = b_mv[this_mode].as_int;
1071 1170
1072 if (this_mode == NEWMV) { 1171 if (this_mode == NEWMV) {
1073 const int step_param = cpi->sf.mv.fullpel_search_step_param; 1172 const int step_param = cpi->sf.mv.fullpel_search_step_param;
1074 MV mvp_full; 1173 MV mvp_full;
1075 MV tmp_mv; 1174 MV tmp_mv;
1076 int cost_list[5]; 1175 int cost_list[5];
1077 const int tmp_col_min = x->mv_col_min; 1176 const int tmp_col_min = x->mv_col_min;
1078 const int tmp_col_max = x->mv_col_max; 1177 const int tmp_col_max = x->mv_col_max;
1079 const int tmp_row_min = x->mv_row_min; 1178 const int tmp_row_min = x->mv_row_min;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 x->errorperbit, 1220 x->errorperbit,
1122 &cpi->fn_ptr[bsize], 1221 &cpi->fn_ptr[bsize],
1123 cpi->sf.mv.subpel_force_stop, 1222 cpi->sf.mv.subpel_force_stop,
1124 cpi->sf.mv.subpel_iters_per_step, 1223 cpi->sf.mv.subpel_iters_per_step,
1125 cond_cost_list(cpi, cost_list), 1224 cond_cost_list(cpi, cost_list),
1126 x->nmvjointcost, x->mvcost, 1225 x->nmvjointcost, x->mvcost,
1127 &dummy_dist, 1226 &dummy_dist,
1128 &x->pred_sse[ref_frame], NULL, 0, 0); 1227 &x->pred_sse[ref_frame], NULL, 0, 0);
1129 1228
1130 xd->mi[0].bmi[i].as_mv[0].as_mv = tmp_mv; 1229 xd->mi[0].bmi[i].as_mv[0].as_mv = tmp_mv;
1230 } else {
1231 b_rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]]
1232 [INTER_OFFSET(this_mode)];
1131 } 1233 }
1132 1234
1133 vp9_build_inter_predictor(pd->pre[0].buf, pd->pre[0].stride, 1235 #if CONFIG_VP9_HIGHBITDEPTH
1236 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1237 vp9_highbd_build_inter_predictor(pd->pre[0].buf, pd->pre[0].stride,
1134 pd->dst.buf, pd->dst.stride, 1238 pd->dst.buf, pd->dst.stride,
1135 &xd->mi[0].bmi[i].as_mv[0].as_mv, 1239 &xd->mi[0].bmi[i].as_mv[0].as_mv,
1136 &xd->block_refs[0]->sf, 1240 &xd->block_refs[0]->sf,
1137 4 * num_4x4_blocks_wide, 1241 4 * num_4x4_blocks_wide,
1138 4 * num_4x4_blocks_high, 0, 1242 4 * num_4x4_blocks_high, 0,
1139 vp9_get_interp_kernel(mbmi->interp_filter), 1243 vp9_get_interp_kernel(mbmi->interp_filter),
1140 MV_PRECISION_Q3, 1244 MV_PRECISION_Q3,
1141 mi_col * MI_SIZE + 4 * (i & 0x01), 1245 mi_col * MI_SIZE + 4 * (i & 0x01),
1142 mi_row * MI_SIZE + 4 * (i >> 1)); 1246 mi_row * MI_SIZE + 4 * (i >> 1), xd->bd);
1247 } else {
1248 #endif
1249 vp9_build_inter_predictor(pd->pre[0].buf, pd->pre[0].stride,
1250 pd->dst.buf, pd->dst.stride,
1251 &xd->mi[0].bmi[i].as_mv[0].as_mv,
1252 &xd->block_refs[0]->sf,
1253 4 * num_4x4_blocks_wide,
1254 4 * num_4x4_blocks_high, 0,
1255 vp9_get_interp_kernel(mbmi->interp_filter),
1256 MV_PRECISION_Q3,
1257 mi_col * MI_SIZE + 4 * (i & 0x01),
1258 mi_row * MI_SIZE + 4 * (i >> 1));
1259
1260 #if CONFIG_VP9_HIGHBITDEPTH
1261 }
1262 #endif
1263
1143 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist, 1264 model_rd_for_sb_y(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist,
1144 &var_y, &sse_y); 1265 &var_y, &sse_y);
1145 1266
1146 this_rdc.rate += b_rate; 1267 this_rdc.rate += b_rate;
1147 this_rdc.dist += b_dist;
1148 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, 1268 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
1149 this_rdc.rate, this_rdc.dist); 1269 this_rdc.rate, this_rdc.dist);
1150 if (this_rdc.rdcost < b_best_rd) { 1270 if (this_rdc.rdcost < b_best_rd) {
1151 b_best_rd = this_rdc.rdcost; 1271 b_best_rd = this_rdc.rdcost;
1152 bsi[ref_frame][i].as_mode = this_mode; 1272 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; 1273 bsi[ref_frame][i].as_mv[0].as_mv = xd->mi[0].bmi[i].as_mv[0].as_mv;
1154 } 1274 }
1155 } // mode search 1275 } // mode search
1156 1276
1157 // restore source and prediction buffer pointers. 1277 // restore source and prediction buffer pointers.
(...skipping 28 matching lines...) Expand all
1186 xd->mi[0].bmi[block + 2] = bsi[best_ref_frame][block]; 1306 xd->mi[0].bmi[block + 2] = bsi[best_ref_frame][block];
1187 } 1307 }
1188 } 1308 }
1189 mbmi->mode = xd->mi[0].bmi[3].as_mode; 1309 mbmi->mode = xd->mi[0].bmi[3].as_mode;
1190 ctx->mic = *(xd->mi[0].src_mi); 1310 ctx->mic = *(xd->mi[0].src_mi);
1191 ctx->skip_txfm[0] = 0; 1311 ctx->skip_txfm[0] = 0;
1192 ctx->skip = 0; 1312 ctx->skip = 0;
1193 // Dummy assignment for speed -5. No effect in speed -6. 1313 // Dummy assignment for speed -5. No effect in speed -6.
1194 rd_cost->rdcost = best_rd; 1314 rd_cost->rdcost = best_rd;
1195 } 1315 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.c ('k') | source/libvpx/vp9/encoder/vp9_quantize.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698