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

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

Issue 1124333011: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: only update to last nights LKGR Created 5 years, 7 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_rdopt.h ('k') | source/libvpx/vp9/encoder/vp9_sad.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) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, 157 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize,
158 MACROBLOCK *x, MACROBLOCKD *xd, 158 MACROBLOCK *x, MACROBLOCKD *xd,
159 int *out_rate_sum, int64_t *out_dist_sum, 159 int *out_rate_sum, int64_t *out_dist_sum,
160 int *skip_txfm_sb, int64_t *skip_sse_sb) { 160 int *skip_txfm_sb, int64_t *skip_sse_sb) {
161 // Note our transform coeffs are 8 times an orthogonal transform. 161 // Note our transform coeffs are 8 times an orthogonal transform.
162 // Hence quantizer step is also 8 times. To get effective quantizer 162 // Hence quantizer step is also 8 times. To get effective quantizer
163 // we need to divide by 8 before sending to modeling function. 163 // we need to divide by 8 before sending to modeling function.
164 int i; 164 int i;
165 int64_t rate_sum = 0; 165 int64_t rate_sum = 0;
166 int64_t dist_sum = 0; 166 int64_t dist_sum = 0;
167 const int ref = xd->mi[0].src_mi->mbmi.ref_frame[0]; 167 const int ref = xd->mi[0]->mbmi.ref_frame[0];
168 unsigned int sse; 168 unsigned int sse;
169 unsigned int var = 0; 169 unsigned int var = 0;
170 unsigned int sum_sse = 0; 170 unsigned int sum_sse = 0;
171 int64_t total_sse = 0; 171 int64_t total_sse = 0;
172 int skip_flag = 1; 172 int skip_flag = 1;
173 const int shift = 6; 173 const int shift = 6;
174 int rate; 174 int rate;
175 int64_t dist; 175 int64_t dist;
176 176
177 x->pred_sse[ref] = 0; 177 x->pred_sse[ref] = 0;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 for (i = 0; i < block_size; i++) { 285 for (i = 0; i < block_size; i++) {
286 const int diff = coeff[i] - dqcoeff[i]; 286 const int diff = coeff[i] - dqcoeff[i];
287 error += diff * diff; 287 error += diff * diff;
288 sqcoeff += coeff[i] * coeff[i]; 288 sqcoeff += coeff[i] * coeff[i];
289 } 289 }
290 290
291 *ssz = sqcoeff; 291 *ssz = sqcoeff;
292 return error; 292 return error;
293 } 293 }
294 294
295 int64_t vp9_block_error_fp_c(const int16_t *coeff, const int16_t *dqcoeff,
296 int block_size) {
297 int i;
298 int64_t error = 0;
299
300 for (i = 0; i < block_size; i++) {
301 const int diff = coeff[i] - dqcoeff[i];
302 error += diff * diff;
303 }
304
305 return error;
306 }
295 307
296 #if CONFIG_VP9_HIGHBITDEPTH 308 #if CONFIG_VP9_HIGHBITDEPTH
297 int64_t vp9_highbd_block_error_c(const tran_low_t *coeff, 309 int64_t vp9_highbd_block_error_c(const tran_low_t *coeff,
298 const tran_low_t *dqcoeff, 310 const tran_low_t *dqcoeff,
299 intptr_t block_size, 311 intptr_t block_size,
300 int64_t *ssz, int bd) { 312 int64_t *ssz, int bd) {
301 int i; 313 int i;
302 int64_t error = 0, sqcoeff = 0; 314 int64_t error = 0, sqcoeff = 0;
303 int shift = 2 * (bd - 8); 315 int shift = 2 * (bd - 8);
304 int rounding = shift > 0 ? 1 << (shift - 1) : 0; 316 int rounding = shift > 0 ? 1 << (shift - 1) : 0;
(...skipping 23 matching lines...) Expand all
328 { 1, 2, 3, 4, 11, 256 - 21, 0 }, 340 { 1, 2, 3, 4, 11, 256 - 21, 0 },
329 { 1, 2, 3, 4, 11, 1024 - 21, 0 }, 341 { 1, 2, 3, 4, 11, 1024 - 21, 0 },
330 }; 342 };
331 static int cost_coeffs(MACROBLOCK *x, 343 static int cost_coeffs(MACROBLOCK *x,
332 int plane, int block, 344 int plane, int block,
333 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, 345 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L,
334 TX_SIZE tx_size, 346 TX_SIZE tx_size,
335 const int16_t *scan, const int16_t *nb, 347 const int16_t *scan, const int16_t *nb,
336 int use_fast_coef_costing) { 348 int use_fast_coef_costing) {
337 MACROBLOCKD *const xd = &x->e_mbd; 349 MACROBLOCKD *const xd = &x->e_mbd;
338 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; 350 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
339 const struct macroblock_plane *p = &x->plane[plane]; 351 const struct macroblock_plane *p = &x->plane[plane];
340 const struct macroblockd_plane *pd = &xd->plane[plane]; 352 const struct macroblockd_plane *pd = &xd->plane[plane];
341 const PLANE_TYPE type = pd->plane_type; 353 const PLANE_TYPE type = pd->plane_type;
342 const int16_t *band_count = &band_counts[tx_size][1]; 354 const int16_t *band_count = &band_counts[tx_size][1];
343 const int eob = p->eobs[block]; 355 const int eob = p->eobs[block];
344 const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); 356 const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
345 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = 357 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] =
346 x->token_costs[tx_size][type][is_inter_block(mbmi)]; 358 x->token_costs[tx_size][type][is_inter_block(mbmi)];
347 uint8_t token_cache[32 * 32]; 359 uint8_t token_cache[32 * 32];
348 int pt = combine_entropy_contexts(*A, *L); 360 int pt = combine_entropy_contexts(*A, *L);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); 445 tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
434 #if CONFIG_VP9_HIGHBITDEPTH 446 #if CONFIG_VP9_HIGHBITDEPTH
435 args->dist = vp9_highbd_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, 447 args->dist = vp9_highbd_block_error(coeff, dqcoeff, 16 << ss_txfrm_size,
436 &this_sse, bd) >> shift; 448 &this_sse, bd) >> shift;
437 #else 449 #else
438 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, 450 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size,
439 &this_sse) >> shift; 451 &this_sse) >> shift;
440 #endif // CONFIG_VP9_HIGHBITDEPTH 452 #endif // CONFIG_VP9_HIGHBITDEPTH
441 args->sse = this_sse >> shift; 453 args->sse = this_sse >> shift;
442 454
443 if (x->skip_encode && !is_inter_block(&xd->mi[0].src_mi->mbmi)) { 455 if (x->skip_encode && !is_inter_block(&xd->mi[0]->mbmi)) {
444 // TODO(jingning): tune the model to better capture the distortion. 456 // TODO(jingning): tune the model to better capture the distortion.
445 int64_t p = (pd->dequant[1] * pd->dequant[1] * 457 int64_t p = (pd->dequant[1] * pd->dequant[1] *
446 (1 << ss_txfrm_size)) >> (shift + 2); 458 (1 << ss_txfrm_size)) >> (shift + 2);
447 #if CONFIG_VP9_HIGHBITDEPTH 459 #if CONFIG_VP9_HIGHBITDEPTH
448 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 460 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
449 p >>= ((xd->bd - 8) * 2); 461 p >>= ((xd->bd - 8) * 2);
450 } 462 }
451 #endif // CONFIG_VP9_HIGHBITDEPTH 463 #endif // CONFIG_VP9_HIGHBITDEPTH
452 args->dist += (p >> 4); 464 args->dist += (p >> 4);
453 args->sse += p; 465 args->sse += p;
454 } 466 }
455 } 467 }
456 468
457 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, 469 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize,
458 TX_SIZE tx_size, struct rdcost_block_args* args) { 470 TX_SIZE tx_size, struct rdcost_block_args* args) {
459 int x_idx, y_idx; 471 int x_idx, y_idx;
460 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx); 472 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx);
461 473
462 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, 474 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx,
463 args->t_left + y_idx, tx_size, 475 args->t_left + y_idx, tx_size,
464 args->so->scan, args->so->neighbors, 476 args->so->scan, args->so->neighbors,
465 args->use_fast_coef_costing); 477 args->use_fast_coef_costing);
466 } 478 }
467 479
468 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, 480 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize,
469 TX_SIZE tx_size, void *arg) { 481 TX_SIZE tx_size, void *arg) {
470 struct rdcost_block_args *args = arg; 482 struct rdcost_block_args *args = arg;
471 MACROBLOCK *const x = args->x; 483 MACROBLOCK *const x = args->x;
472 MACROBLOCKD *const xd = &x->e_mbd; 484 MACROBLOCKD *const xd = &x->e_mbd;
473 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 485 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
474 int64_t rd1, rd2, rd; 486 int64_t rd1, rd2, rd;
475 487
476 if (args->skip) 488 if (args->skip)
477 return; 489 return;
478 490
479 if (!is_inter_block(mbmi)) { 491 if (!is_inter_block(mbmi)) {
480 struct encode_b_args arg = {x, NULL, &mbmi->skip}; 492 struct encode_b_args arg = {x, NULL, &mbmi->skip};
481 vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &arg); 493 vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &arg);
482 #if CONFIG_VP9_HIGHBITDEPTH 494 #if CONFIG_VP9_HIGHBITDEPTH
483 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 495 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 int use_fast_coef_casting) { 581 int use_fast_coef_casting) {
570 MACROBLOCKD *const xd = &x->e_mbd; 582 MACROBLOCKD *const xd = &x->e_mbd;
571 const struct macroblockd_plane *const pd = &xd->plane[plane]; 583 const struct macroblockd_plane *const pd = &xd->plane[plane];
572 struct rdcost_block_args args; 584 struct rdcost_block_args args;
573 vp9_zero(args); 585 vp9_zero(args);
574 args.x = x; 586 args.x = x;
575 args.best_rd = ref_best_rd; 587 args.best_rd = ref_best_rd;
576 args.use_fast_coef_costing = use_fast_coef_casting; 588 args.use_fast_coef_costing = use_fast_coef_casting;
577 589
578 if (plane == 0) 590 if (plane == 0)
579 xd->mi[0].src_mi->mbmi.tx_size = tx_size; 591 xd->mi[0]->mbmi.tx_size = tx_size;
580 592
581 vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left); 593 vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left);
582 594
583 args.so = get_scan(xd, tx_size, pd->plane_type, 0); 595 args.so = get_scan(xd, tx_size, pd->plane_type, 0);
584 596
585 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, 597 vp9_foreach_transformed_block_in_plane(xd, bsize, plane,
586 block_rd_txfm, &args); 598 block_rd_txfm, &args);
587 if (args.skip) { 599 if (args.skip) {
588 *rate = INT_MAX; 600 *rate = INT_MAX;
589 *distortion = INT64_MAX; 601 *distortion = INT64_MAX;
590 *sse = INT64_MAX; 602 *sse = INT64_MAX;
591 *skippable = 0; 603 *skippable = 0;
592 } else { 604 } else {
593 *distortion = args.this_dist; 605 *distortion = args.this_dist;
594 *rate = args.this_rate; 606 *rate = args.this_rate;
595 *sse = args.this_sse; 607 *sse = args.this_sse;
596 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); 608 *skippable = vp9_is_skippable_in_plane(x, bsize, plane);
597 } 609 }
598 } 610 }
599 611
600 static void choose_largest_tx_size(VP9_COMP *cpi, MACROBLOCK *x, 612 static void choose_largest_tx_size(VP9_COMP *cpi, MACROBLOCK *x,
601 int *rate, int64_t *distortion, 613 int *rate, int64_t *distortion,
602 int *skip, int64_t *sse, 614 int *skip, int64_t *sse,
603 int64_t ref_best_rd, 615 int64_t ref_best_rd,
604 BLOCK_SIZE bs) { 616 BLOCK_SIZE bs) {
605 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 617 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
606 VP9_COMMON *const cm = &cpi->common; 618 VP9_COMMON *const cm = &cpi->common;
607 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; 619 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
608 MACROBLOCKD *const xd = &x->e_mbd; 620 MACROBLOCKD *const xd = &x->e_mbd;
609 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 621 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
610 622
611 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); 623 mbmi->tx_size = MIN(max_tx_size, largest_tx_size);
612 624
613 txfm_rd_in_plane(x, rate, distortion, skip, 625 txfm_rd_in_plane(x, rate, distortion, skip,
614 sse, ref_best_rd, 0, bs, 626 sse, ref_best_rd, 0, bs,
615 mbmi->tx_size, cpi->sf.use_fast_coef_costing); 627 mbmi->tx_size, cpi->sf.use_fast_coef_costing);
616 } 628 }
617 629
618 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, 630 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x,
619 int *rate, 631 int *rate,
620 int64_t *distortion, 632 int64_t *distortion,
621 int *skip, 633 int *skip,
622 int64_t *psse, 634 int64_t *psse,
623 int64_t tx_cache[TX_MODES], 635 int64_t tx_cache[TX_MODES],
624 int64_t ref_best_rd, 636 int64_t ref_best_rd,
625 BLOCK_SIZE bs) { 637 BLOCK_SIZE bs) {
626 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 638 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
627 VP9_COMMON *const cm = &cpi->common; 639 VP9_COMMON *const cm = &cpi->common;
628 MACROBLOCKD *const xd = &x->e_mbd; 640 MACROBLOCKD *const xd = &x->e_mbd;
629 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 641 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
630 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); 642 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
631 int r[TX_SIZES][2], s[TX_SIZES]; 643 int r[TX_SIZES][2], s[TX_SIZES];
632 int64_t d[TX_SIZES], sse[TX_SIZES]; 644 int64_t d[TX_SIZES], sse[TX_SIZES];
633 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, 645 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX},
634 {INT64_MAX, INT64_MAX}, 646 {INT64_MAX, INT64_MAX},
635 {INT64_MAX, INT64_MAX}, 647 {INT64_MAX, INT64_MAX},
636 {INT64_MAX, INT64_MAX}}; 648 {INT64_MAX, INT64_MAX}};
637 int n, m; 649 int n, m;
638 int s0, s1; 650 int s0, s1;
639 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; 651 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 718
707 static void super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 719 static void super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
708 int64_t *distortion, int *skip, 720 int64_t *distortion, int *skip,
709 int64_t *psse, BLOCK_SIZE bs, 721 int64_t *psse, BLOCK_SIZE bs,
710 int64_t txfm_cache[TX_MODES], 722 int64_t txfm_cache[TX_MODES],
711 int64_t ref_best_rd) { 723 int64_t ref_best_rd) {
712 MACROBLOCKD *xd = &x->e_mbd; 724 MACROBLOCKD *xd = &x->e_mbd;
713 int64_t sse; 725 int64_t sse;
714 int64_t *ret_sse = psse ? psse : &sse; 726 int64_t *ret_sse = psse ? psse : &sse;
715 727
716 assert(bs == xd->mi[0].src_mi->mbmi.sb_type); 728 assert(bs == xd->mi[0]->mbmi.sb_type);
717 729
718 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) { 730 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) {
719 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); 731 memset(txfm_cache, 0, TX_MODES * sizeof(int64_t));
720 choose_largest_tx_size(cpi, x, rate, distortion, skip, ret_sse, ref_best_rd, 732 choose_largest_tx_size(cpi, x, rate, distortion, skip, ret_sse, ref_best_rd,
721 bs); 733 bs);
722 } else { 734 } else {
723 choose_tx_size_from_rd(cpi, x, rate, distortion, skip, ret_sse, 735 choose_tx_size_from_rd(cpi, x, rate, distortion, skip, ret_sse,
724 txfm_cache, ref_best_rd, bs); 736 txfm_cache, ref_best_rd, bs);
725 } 737 }
726 } 738 }
727 739
728 static int conditional_skipintra(PREDICTION_MODE mode, 740 static int conditional_skipintra(PREDICTION_MODE mode,
729 PREDICTION_MODE best_intra_mode) { 741 PREDICTION_MODE best_intra_mode) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 783 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
772 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 784 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
773 int idx, idy; 785 int idx, idy;
774 uint8_t best_dst[8 * 8]; 786 uint8_t best_dst[8 * 8];
775 #if CONFIG_VP9_HIGHBITDEPTH 787 #if CONFIG_VP9_HIGHBITDEPTH
776 uint16_t best_dst16[8 * 8]; 788 uint16_t best_dst16[8 * 8];
777 #endif 789 #endif
778 790
779 assert(ib < 4); 791 assert(ib < 4);
780 792
781 vpx_memcpy(ta, a, sizeof(ta)); 793 memcpy(ta, a, sizeof(ta));
782 vpx_memcpy(tl, l, sizeof(tl)); 794 memcpy(tl, l, sizeof(tl));
783 xd->mi[0].src_mi->mbmi.tx_size = TX_4X4; 795 xd->mi[0]->mbmi.tx_size = TX_4X4;
784 796
785 #if CONFIG_VP9_HIGHBITDEPTH 797 #if CONFIG_VP9_HIGHBITDEPTH
786 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 798 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
787 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { 799 for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
788 int64_t this_rd; 800 int64_t this_rd;
789 int ratey = 0; 801 int ratey = 0;
790 int64_t distortion = 0; 802 int64_t distortion = 0;
791 int rate = bmode_costs[mode]; 803 int rate = bmode_costs[mode];
792 804
793 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) 805 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode)))
794 continue; 806 continue;
795 807
796 // Only do the oblique modes if the best so far is 808 // Only do the oblique modes if the best so far is
797 // one of the neighboring directional modes 809 // one of the neighboring directional modes
798 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { 810 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
799 if (conditional_skipintra(mode, *best_mode)) 811 if (conditional_skipintra(mode, *best_mode))
800 continue; 812 continue;
801 } 813 }
802 814
803 vpx_memcpy(tempa, ta, sizeof(ta)); 815 memcpy(tempa, ta, sizeof(ta));
804 vpx_memcpy(templ, tl, sizeof(tl)); 816 memcpy(templ, tl, sizeof(tl));
805 817
806 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { 818 for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
807 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { 819 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
808 const int block = ib + idy * 2 + idx; 820 const int block = ib + idy * 2 + idx;
809 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; 821 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride];
810 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; 822 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
811 int16_t *const src_diff = vp9_raster_block_offset_int16(BLOCK_8X8, 823 int16_t *const src_diff = vp9_raster_block_offset_int16(BLOCK_8X8,
812 block, 824 block,
813 p->src_diff); 825 p->src_diff);
814 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); 826 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
815 xd->mi[0].src_mi->bmi[block].as_mode = mode; 827 xd->mi[0]->bmi[block].as_mode = mode;
816 vp9_predict_intra_block(xd, block, 1, 828 vp9_predict_intra_block(xd, block, 1,
817 TX_4X4, mode, 829 TX_4X4, mode,
818 x->skip_encode ? src : dst, 830 x->skip_encode ? src : dst,
819 x->skip_encode ? src_stride : dst_stride, 831 x->skip_encode ? src_stride : dst_stride,
820 dst, dst_stride, idx, idy, 0); 832 dst, dst_stride, idx, idy, 0);
821 vp9_highbd_subtract_block(4, 4, src_diff, 8, src, src_stride, 833 vp9_highbd_subtract_block(4, 4, src_diff, 8, src, src_stride,
822 dst, dst_stride, xd->bd); 834 dst, dst_stride, xd->bd);
823 if (xd->lossless) { 835 if (xd->lossless) {
824 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; 836 const scan_order *so = &vp9_default_scan_orders[TX_4X4];
825 vp9_highbd_fwht4x4(src_diff, coeff, 8); 837 vp9_highbd_fwht4x4(src_diff, coeff, 8);
(...skipping 28 matching lines...) Expand all
854 866
855 rate += ratey; 867 rate += ratey;
856 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); 868 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
857 869
858 if (this_rd < best_rd) { 870 if (this_rd < best_rd) {
859 *bestrate = rate; 871 *bestrate = rate;
860 *bestratey = ratey; 872 *bestratey = ratey;
861 *bestdistortion = distortion; 873 *bestdistortion = distortion;
862 best_rd = this_rd; 874 best_rd = this_rd;
863 *best_mode = mode; 875 *best_mode = mode;
864 vpx_memcpy(a, tempa, sizeof(tempa)); 876 memcpy(a, tempa, sizeof(tempa));
865 vpx_memcpy(l, templ, sizeof(templ)); 877 memcpy(l, templ, sizeof(templ));
866 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) { 878 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) {
867 vpx_memcpy(best_dst16 + idy * 8, 879 memcpy(best_dst16 + idy * 8,
868 CONVERT_TO_SHORTPTR(dst_init + idy * dst_stride), 880 CONVERT_TO_SHORTPTR(dst_init + idy * dst_stride),
869 num_4x4_blocks_wide * 4 * sizeof(uint16_t)); 881 num_4x4_blocks_wide * 4 * sizeof(uint16_t));
870 } 882 }
871 } 883 }
872 next_highbd: 884 next_highbd:
873 {} 885 {}
874 } 886 }
875 if (best_rd >= rd_thresh || x->skip_encode) 887 if (best_rd >= rd_thresh || x->skip_encode)
876 return best_rd; 888 return best_rd;
877 889
878 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) { 890 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) {
879 vpx_memcpy(CONVERT_TO_SHORTPTR(dst_init + idy * dst_stride), 891 memcpy(CONVERT_TO_SHORTPTR(dst_init + idy * dst_stride),
880 best_dst16 + idy * 8, 892 best_dst16 + idy * 8,
881 num_4x4_blocks_wide * 4 * sizeof(uint16_t)); 893 num_4x4_blocks_wide * 4 * sizeof(uint16_t));
882 } 894 }
883 895
884 return best_rd; 896 return best_rd;
885 } 897 }
886 #endif // CONFIG_VP9_HIGHBITDEPTH 898 #endif // CONFIG_VP9_HIGHBITDEPTH
887 899
888 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { 900 for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
889 int64_t this_rd; 901 int64_t this_rd;
890 int ratey = 0; 902 int ratey = 0;
891 int64_t distortion = 0; 903 int64_t distortion = 0;
892 int rate = bmode_costs[mode]; 904 int rate = bmode_costs[mode];
893 905
894 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) 906 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode)))
895 continue; 907 continue;
896 908
897 // Only do the oblique modes if the best so far is 909 // Only do the oblique modes if the best so far is
898 // one of the neighboring directional modes 910 // one of the neighboring directional modes
899 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { 911 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
900 if (conditional_skipintra(mode, *best_mode)) 912 if (conditional_skipintra(mode, *best_mode))
901 continue; 913 continue;
902 } 914 }
903 915
904 vpx_memcpy(tempa, ta, sizeof(ta)); 916 memcpy(tempa, ta, sizeof(ta));
905 vpx_memcpy(templ, tl, sizeof(tl)); 917 memcpy(templ, tl, sizeof(tl));
906 918
907 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { 919 for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
908 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { 920 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
909 const int block = ib + idy * 2 + idx; 921 const int block = ib + idy * 2 + idx;
910 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; 922 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride];
911 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; 923 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
912 int16_t *const src_diff = 924 int16_t *const src_diff =
913 vp9_raster_block_offset_int16(BLOCK_8X8, block, p->src_diff); 925 vp9_raster_block_offset_int16(BLOCK_8X8, block, p->src_diff);
914 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); 926 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
915 xd->mi[0].src_mi->bmi[block].as_mode = mode; 927 xd->mi[0]->bmi[block].as_mode = mode;
916 vp9_predict_intra_block(xd, block, 1, 928 vp9_predict_intra_block(xd, block, 1,
917 TX_4X4, mode, 929 TX_4X4, mode,
918 x->skip_encode ? src : dst, 930 x->skip_encode ? src : dst,
919 x->skip_encode ? src_stride : dst_stride, 931 x->skip_encode ? src_stride : dst_stride,
920 dst, dst_stride, idx, idy, 0); 932 dst, dst_stride, idx, idy, 0);
921 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride); 933 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride);
922 934
923 if (xd->lossless) { 935 if (xd->lossless) {
924 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; 936 const scan_order *so = &vp9_default_scan_orders[TX_4X4];
925 vp9_fwht4x4(src_diff, coeff, 8); 937 vp9_fwht4x4(src_diff, coeff, 8);
(...skipping 26 matching lines...) Expand all
952 964
953 rate += ratey; 965 rate += ratey;
954 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); 966 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
955 967
956 if (this_rd < best_rd) { 968 if (this_rd < best_rd) {
957 *bestrate = rate; 969 *bestrate = rate;
958 *bestratey = ratey; 970 *bestratey = ratey;
959 *bestdistortion = distortion; 971 *bestdistortion = distortion;
960 best_rd = this_rd; 972 best_rd = this_rd;
961 *best_mode = mode; 973 *best_mode = mode;
962 vpx_memcpy(a, tempa, sizeof(tempa)); 974 memcpy(a, tempa, sizeof(tempa));
963 vpx_memcpy(l, templ, sizeof(templ)); 975 memcpy(l, templ, sizeof(templ));
964 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) 976 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy)
965 vpx_memcpy(best_dst + idy * 8, dst_init + idy * dst_stride, 977 memcpy(best_dst + idy * 8, dst_init + idy * dst_stride,
966 num_4x4_blocks_wide * 4); 978 num_4x4_blocks_wide * 4);
967 } 979 }
968 next: 980 next:
969 {} 981 {}
970 } 982 }
971 983
972 if (best_rd >= rd_thresh || x->skip_encode) 984 if (best_rd >= rd_thresh || x->skip_encode)
973 return best_rd; 985 return best_rd;
974 986
975 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) 987 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy)
976 vpx_memcpy(dst_init + idy * dst_stride, best_dst + idy * 8, 988 memcpy(dst_init + idy * dst_stride, best_dst + idy * 8,
977 num_4x4_blocks_wide * 4); 989 num_4x4_blocks_wide * 4);
978 990
979 return best_rd; 991 return best_rd;
980 } 992 }
981 993
982 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb, 994 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb,
983 int *rate, int *rate_y, 995 int *rate, int *rate_y,
984 int64_t *distortion, 996 int64_t *distortion,
985 int64_t best_rd) { 997 int64_t best_rd) {
986 int i, j; 998 int i, j;
987 const MACROBLOCKD *const xd = &mb->e_mbd; 999 const MACROBLOCKD *const xd = &mb->e_mbd;
988 MODE_INFO *const mic = xd->mi[0].src_mi; 1000 MODE_INFO *const mic = xd->mi[0];
989 const MODE_INFO *above_mi = xd->above_mi; 1001 const MODE_INFO *above_mi = xd->above_mi;
990 const MODE_INFO *left_mi = xd->left_mi; 1002 const MODE_INFO *left_mi = xd->left_mi;
991 const BLOCK_SIZE bsize = xd->mi[0].src_mi->mbmi.sb_type; 1003 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
992 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 1004 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
993 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1005 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
994 int idx, idy; 1006 int idx, idy;
995 int cost = 0; 1007 int cost = 0;
996 int64_t total_distortion = 0; 1008 int64_t total_distortion = 0;
997 int tot_rate_y = 0; 1009 int tot_rate_y = 0;
998 int64_t total_rd = 0; 1010 int64_t total_rd = 0;
999 ENTROPY_CONTEXT t_above[4], t_left[4]; 1011 ENTROPY_CONTEXT t_above[4], t_left[4];
1000 const int *bmode_costs = cpi->mbmode_cost; 1012 const int *bmode_costs = cpi->mbmode_cost;
1001 1013
1002 vpx_memcpy(t_above, xd->plane[0].above_context, sizeof(t_above)); 1014 memcpy(t_above, xd->plane[0].above_context, sizeof(t_above));
1003 vpx_memcpy(t_left, xd->plane[0].left_context, sizeof(t_left)); 1015 memcpy(t_left, xd->plane[0].left_context, sizeof(t_left));
1004 1016
1005 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block. 1017 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block.
1006 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { 1018 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
1007 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { 1019 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
1008 PREDICTION_MODE best_mode = DC_PRED; 1020 PREDICTION_MODE best_mode = DC_PRED;
1009 int r = INT_MAX, ry = INT_MAX; 1021 int r = INT_MAX, ry = INT_MAX;
1010 int64_t d = INT64_MAX, this_rd = INT64_MAX; 1022 int64_t d = INT64_MAX, this_rd = INT64_MAX;
1011 i = idy * 2 + idx; 1023 i = idy * 2 + idx;
1012 if (cpi->common.frame_type == KEY_FRAME) { 1024 if (cpi->common.frame_type == KEY_FRAME) {
1013 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, i); 1025 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, i);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 // This function is used only for intra_only frames 1061 // This function is used only for intra_only frames
1050 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, 1062 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
1051 int *rate, int *rate_tokenonly, 1063 int *rate, int *rate_tokenonly,
1052 int64_t *distortion, int *skippable, 1064 int64_t *distortion, int *skippable,
1053 BLOCK_SIZE bsize, 1065 BLOCK_SIZE bsize,
1054 int64_t tx_cache[TX_MODES], 1066 int64_t tx_cache[TX_MODES],
1055 int64_t best_rd) { 1067 int64_t best_rd) {
1056 PREDICTION_MODE mode; 1068 PREDICTION_MODE mode;
1057 PREDICTION_MODE mode_selected = DC_PRED; 1069 PREDICTION_MODE mode_selected = DC_PRED;
1058 MACROBLOCKD *const xd = &x->e_mbd; 1070 MACROBLOCKD *const xd = &x->e_mbd;
1059 MODE_INFO *const mic = xd->mi[0].src_mi; 1071 MODE_INFO *const mic = xd->mi[0];
1060 int this_rate, this_rate_tokenonly, s; 1072 int this_rate, this_rate_tokenonly, s;
1061 int64_t this_distortion, this_rd; 1073 int64_t this_distortion, this_rd;
1062 TX_SIZE best_tx = TX_4X4; 1074 TX_SIZE best_tx = TX_4X4;
1063 int i; 1075 int i;
1064 int *bmode_costs; 1076 int *bmode_costs;
1065 const MODE_INFO *above_mi = xd->above_mi; 1077 const MODE_INFO *above_mi = xd->above_mi;
1066 const MODE_INFO *left_mi = xd->left_mi; 1078 const MODE_INFO *left_mi = xd->left_mi;
1067 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); 1079 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
1068 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); 1080 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0);
1069 bmode_costs = cpi->y_mode_costs[A][L]; 1081 bmode_costs = cpi->y_mode_costs[A][L];
1070 1082
1071 if (cpi->sf.tx_size_search_method == USE_FULL_RD) 1083 if (cpi->sf.tx_size_search_method == USE_FULL_RD)
1072 for (i = 0; i < TX_MODES; i++) 1084 for (i = 0; i < TX_MODES; i++)
1073 tx_cache[i] = INT64_MAX; 1085 tx_cache[i] = INT64_MAX;
1074 1086
1075 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); 1087 memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
1076 /* Y Search for intra prediction mode */ 1088 /* Y Search for intra prediction mode */
1077 for (mode = DC_PRED; mode <= TM_PRED; mode++) { 1089 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1078 int64_t local_tx_cache[TX_MODES]; 1090 int64_t local_tx_cache[TX_MODES];
1079 1091
1080 if (cpi->sf.use_nonrd_pick_mode) { 1092 if (cpi->sf.use_nonrd_pick_mode) {
1081 // These speed features are turned on in hybrid non-RD and RD mode 1093 // These speed features are turned on in hybrid non-RD and RD mode
1082 // for key frame coding in the context of real-time setting. 1094 // for key frame coding in the context of real-time setting.
1083 if (conditional_skipintra(mode, mode_selected)) 1095 if (conditional_skipintra(mode, mode_selected))
1084 continue; 1096 continue;
1085 if (*skippable) 1097 if (*skippable)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 return best_rd; 1136 return best_rd;
1125 } 1137 }
1126 1138
1127 // Return value 0: early termination triggered, no valid rd cost available; 1139 // Return value 0: early termination triggered, no valid rd cost available;
1128 // 1: rd cost values are valid. 1140 // 1: rd cost values are valid.
1129 static int super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x, 1141 static int super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x,
1130 int *rate, int64_t *distortion, int *skippable, 1142 int *rate, int64_t *distortion, int *skippable,
1131 int64_t *sse, BLOCK_SIZE bsize, 1143 int64_t *sse, BLOCK_SIZE bsize,
1132 int64_t ref_best_rd) { 1144 int64_t ref_best_rd) {
1133 MACROBLOCKD *const xd = &x->e_mbd; 1145 MACROBLOCKD *const xd = &x->e_mbd;
1134 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 1146 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
1135 const TX_SIZE uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]); 1147 const TX_SIZE uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]);
1136 int plane; 1148 int plane;
1137 int pnrate = 0, pnskip = 1; 1149 int pnrate = 0, pnskip = 1;
1138 int64_t pndist = 0, pnsse = 0; 1150 int64_t pndist = 0, pnsse = 0;
1139 int is_cost_valid = 1; 1151 int is_cost_valid = 1;
1140 1152
1141 if (ref_best_rd < 0) 1153 if (ref_best_rd < 0)
1142 is_cost_valid = 0; 1154 is_cost_valid = 0;
1143 1155
1144 if (is_inter_block(mbmi) && is_cost_valid) { 1156 if (is_inter_block(mbmi) && is_cost_valid) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 int *rate, int *rate_tokenonly, 1194 int *rate, int *rate_tokenonly,
1183 int64_t *distortion, int *skippable, 1195 int64_t *distortion, int *skippable,
1184 BLOCK_SIZE bsize, TX_SIZE max_tx_size) { 1196 BLOCK_SIZE bsize, TX_SIZE max_tx_size) {
1185 MACROBLOCKD *xd = &x->e_mbd; 1197 MACROBLOCKD *xd = &x->e_mbd;
1186 PREDICTION_MODE mode; 1198 PREDICTION_MODE mode;
1187 PREDICTION_MODE mode_selected = DC_PRED; 1199 PREDICTION_MODE mode_selected = DC_PRED;
1188 int64_t best_rd = INT64_MAX, this_rd; 1200 int64_t best_rd = INT64_MAX, this_rd;
1189 int this_rate_tokenonly, this_rate, s; 1201 int this_rate_tokenonly, this_rate, s;
1190 int64_t this_distortion, this_sse; 1202 int64_t this_distortion, this_sse;
1191 1203
1192 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); 1204 memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
1193 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { 1205 for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
1194 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) 1206 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode)))
1195 continue; 1207 continue;
1196 1208
1197 xd->mi[0].src_mi->mbmi.uv_mode = mode; 1209 xd->mi[0]->mbmi.uv_mode = mode;
1198 1210
1199 if (!super_block_uvrd(cpi, x, &this_rate_tokenonly, 1211 if (!super_block_uvrd(cpi, x, &this_rate_tokenonly,
1200 &this_distortion, &s, &this_sse, bsize, best_rd)) 1212 &this_distortion, &s, &this_sse, bsize, best_rd))
1201 continue; 1213 continue;
1202 this_rate = this_rate_tokenonly + 1214 this_rate = this_rate_tokenonly +
1203 cpi->intra_uv_mode_cost[cpi->common.frame_type][mode]; 1215 cpi->intra_uv_mode_cost[cpi->common.frame_type][mode];
1204 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); 1216 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
1205 1217
1206 if (this_rd < best_rd) { 1218 if (this_rd < best_rd) {
1207 mode_selected = mode; 1219 mode_selected = mode;
1208 best_rd = this_rd; 1220 best_rd = this_rd;
1209 *rate = this_rate; 1221 *rate = this_rate;
1210 *rate_tokenonly = this_rate_tokenonly; 1222 *rate_tokenonly = this_rate_tokenonly;
1211 *distortion = this_distortion; 1223 *distortion = this_distortion;
1212 *skippable = s; 1224 *skippable = s;
1213 if (!x->select_tx_size) 1225 if (!x->select_tx_size)
1214 swap_block_ptr(x, ctx, 2, 0, 1, MAX_MB_PLANE); 1226 swap_block_ptr(x, ctx, 2, 0, 1, MAX_MB_PLANE);
1215 } 1227 }
1216 } 1228 }
1217 1229
1218 xd->mi[0].src_mi->mbmi.uv_mode = mode_selected; 1230 xd->mi[0]->mbmi.uv_mode = mode_selected;
1219 return best_rd; 1231 return best_rd;
1220 } 1232 }
1221 1233
1222 static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x, 1234 static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x,
1223 int *rate, int *rate_tokenonly, 1235 int *rate, int *rate_tokenonly,
1224 int64_t *distortion, int *skippable, 1236 int64_t *distortion, int *skippable,
1225 BLOCK_SIZE bsize) { 1237 BLOCK_SIZE bsize) {
1226 const VP9_COMMON *cm = &cpi->common; 1238 const VP9_COMMON *cm = &cpi->common;
1227 int64_t unused; 1239 int64_t unused;
1228 1240
1229 x->e_mbd.mi[0].src_mi->mbmi.uv_mode = DC_PRED; 1241 x->e_mbd.mi[0]->mbmi.uv_mode = DC_PRED;
1230 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); 1242 memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
1231 super_block_uvrd(cpi, x, rate_tokenonly, distortion, 1243 super_block_uvrd(cpi, x, rate_tokenonly, distortion,
1232 skippable, &unused, bsize, INT64_MAX); 1244 skippable, &unused, bsize, INT64_MAX);
1233 *rate = *rate_tokenonly + cpi->intra_uv_mode_cost[cm->frame_type][DC_PRED]; 1245 *rate = *rate_tokenonly + cpi->intra_uv_mode_cost[cm->frame_type][DC_PRED];
1234 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); 1246 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
1235 } 1247 }
1236 1248
1237 static void choose_intra_uv_mode(VP9_COMP *cpi, MACROBLOCK *const x, 1249 static void choose_intra_uv_mode(VP9_COMP *cpi, MACROBLOCK *const x,
1238 PICK_MODE_CONTEXT *ctx, 1250 PICK_MODE_CONTEXT *ctx,
1239 BLOCK_SIZE bsize, TX_SIZE max_tx_size, 1251 BLOCK_SIZE bsize, TX_SIZE max_tx_size,
1240 int *rate_uv, int *rate_uv_tokenonly, 1252 int *rate_uv, int *rate_uv_tokenonly,
1241 int64_t *dist_uv, int *skip_uv, 1253 int64_t *dist_uv, int *skip_uv,
1242 PREDICTION_MODE *mode_uv) { 1254 PREDICTION_MODE *mode_uv) {
1243 // Use an estimated rd for uv_intra based on DC_PRED if the 1255 // Use an estimated rd for uv_intra based on DC_PRED if the
1244 // appropriate speed flag is set. 1256 // appropriate speed flag is set.
1245 if (cpi->sf.use_uv_intra_rd_estimate) { 1257 if (cpi->sf.use_uv_intra_rd_estimate) {
1246 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv, 1258 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv,
1247 skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); 1259 skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize);
1248 // Else do a proper rd search for each possible transform size that may 1260 // Else do a proper rd search for each possible transform size that may
1249 // be considered in the main rd loop. 1261 // be considered in the main rd loop.
1250 } else { 1262 } else {
1251 rd_pick_intra_sbuv_mode(cpi, x, ctx, 1263 rd_pick_intra_sbuv_mode(cpi, x, ctx,
1252 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, 1264 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv,
1253 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size); 1265 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size);
1254 } 1266 }
1255 *mode_uv = x->e_mbd.mi[0].src_mi->mbmi.uv_mode; 1267 *mode_uv = x->e_mbd.mi[0]->mbmi.uv_mode;
1256 } 1268 }
1257 1269
1258 static int cost_mv_ref(const VP9_COMP *cpi, PREDICTION_MODE mode, 1270 static int cost_mv_ref(const VP9_COMP *cpi, PREDICTION_MODE mode,
1259 int mode_context) { 1271 int mode_context) {
1260 assert(is_inter_mode(mode)); 1272 assert(is_inter_mode(mode));
1261 return cpi->inter_mode_cost[mode_context][INTER_OFFSET(mode)]; 1273 return cpi->inter_mode_cost[mode_context][INTER_OFFSET(mode)];
1262 } 1274 }
1263 1275
1264 static int set_and_cost_bmi_mvs(VP9_COMP *cpi, MACROBLOCKD *xd, int i, 1276 static int set_and_cost_bmi_mvs(VP9_COMP *cpi, MACROBLOCKD *xd, int i,
1265 PREDICTION_MODE mode, int_mv this_mv[2], 1277 PREDICTION_MODE mode, int_mv this_mv[2],
1266 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], 1278 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES],
1267 int_mv seg_mvs[MAX_REF_FRAMES], 1279 int_mv seg_mvs[MAX_REF_FRAMES],
1268 int_mv *best_ref_mv[2], const int *mvjcost, 1280 int_mv *best_ref_mv[2], const int *mvjcost,
1269 int *mvcost[2]) { 1281 int *mvcost[2]) {
1270 MODE_INFO *const mic = xd->mi[0].src_mi; 1282 MODE_INFO *const mic = xd->mi[0];
1271 const MB_MODE_INFO *const mbmi = &mic->mbmi; 1283 const MB_MODE_INFO *const mbmi = &mic->mbmi;
1272 int thismvcost = 0; 1284 int thismvcost = 0;
1273 int idx, idy; 1285 int idx, idy;
1274 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; 1286 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type];
1275 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; 1287 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type];
1276 const int is_compound = has_second_ref(mbmi); 1288 const int is_compound = has_second_ref(mbmi);
1277 1289
1278 switch (mode) { 1290 switch (mode) {
1279 case NEWMV: 1291 case NEWMV:
1280 this_mv[0].as_int = seg_mvs[mbmi->ref_frame[0]].as_int; 1292 this_mv[0].as_int = seg_mvs[mbmi->ref_frame[0]].as_int;
(...skipping 21 matching lines...) Expand all
1302 } 1314 }
1303 1315
1304 mic->bmi[i].as_mv[0].as_int = this_mv[0].as_int; 1316 mic->bmi[i].as_mv[0].as_int = this_mv[0].as_int;
1305 if (is_compound) 1317 if (is_compound)
1306 mic->bmi[i].as_mv[1].as_int = this_mv[1].as_int; 1318 mic->bmi[i].as_mv[1].as_int = this_mv[1].as_int;
1307 1319
1308 mic->bmi[i].as_mode = mode; 1320 mic->bmi[i].as_mode = mode;
1309 1321
1310 for (idy = 0; idy < num_4x4_blocks_high; ++idy) 1322 for (idy = 0; idy < num_4x4_blocks_high; ++idy)
1311 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) 1323 for (idx = 0; idx < num_4x4_blocks_wide; ++idx)
1312 vpx_memmove(&mic->bmi[i + idy * 2 + idx], 1324 memmove(&mic->bmi[i + idy * 2 + idx], &mic->bmi[i], sizeof(mic->bmi[i]));
1313 &mic->bmi[i], sizeof(mic->bmi[i]));
1314 1325
1315 return cost_mv_ref(cpi, mode, mbmi->mode_context[mbmi->ref_frame[0]]) + 1326 return cost_mv_ref(cpi, mode, mbmi->mode_context[mbmi->ref_frame[0]]) +
1316 thismvcost; 1327 thismvcost;
1317 } 1328 }
1318 1329
1319 static int64_t encode_inter_mb_segment(VP9_COMP *cpi, 1330 static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
1320 MACROBLOCK *x, 1331 MACROBLOCK *x,
1321 int64_t best_yrd, 1332 int64_t best_yrd,
1322 int i, 1333 int i,
1323 int *labelyrate, 1334 int *labelyrate,
1324 int64_t *distortion, int64_t *sse, 1335 int64_t *distortion, int64_t *sse,
1325 ENTROPY_CONTEXT *ta, 1336 ENTROPY_CONTEXT *ta,
1326 ENTROPY_CONTEXT *tl, 1337 ENTROPY_CONTEXT *tl,
1327 int mi_row, int mi_col) { 1338 int mi_row, int mi_col) {
1328 int k; 1339 int k;
1329 MACROBLOCKD *xd = &x->e_mbd; 1340 MACROBLOCKD *xd = &x->e_mbd;
1330 struct macroblockd_plane *const pd = &xd->plane[0]; 1341 struct macroblockd_plane *const pd = &xd->plane[0];
1331 struct macroblock_plane *const p = &x->plane[0]; 1342 struct macroblock_plane *const p = &x->plane[0];
1332 MODE_INFO *const mi = xd->mi[0].src_mi; 1343 MODE_INFO *const mi = xd->mi[0];
1333 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd); 1344 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd);
1334 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; 1345 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
1335 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize]; 1346 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize];
1336 int idx, idy; 1347 int idx, idy;
1337 1348
1338 const uint8_t *const src = 1349 const uint8_t *const src =
1339 &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)]; 1350 &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)];
1340 uint8_t *const dst = &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i, 1351 uint8_t *const dst = &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i,
1341 pd->dst.stride)]; 1352 pd->dst.stride)];
1342 int64_t thisdistortion = 0, thissse = 0; 1353 int64_t thisdistortion = 0, thissse = 0;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 } BEST_SEG_INFO; 1474 } BEST_SEG_INFO;
1464 1475
1465 static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) { 1476 static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) {
1466 return (mv->row >> 3) < x->mv_row_min || 1477 return (mv->row >> 3) < x->mv_row_min ||
1467 (mv->row >> 3) > x->mv_row_max || 1478 (mv->row >> 3) > x->mv_row_max ||
1468 (mv->col >> 3) < x->mv_col_min || 1479 (mv->col >> 3) < x->mv_col_min ||
1469 (mv->col >> 3) > x->mv_col_max; 1480 (mv->col >> 3) > x->mv_col_max;
1470 } 1481 }
1471 1482
1472 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { 1483 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) {
1473 MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0].src_mi->mbmi; 1484 MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0]->mbmi;
1474 struct macroblock_plane *const p = &x->plane[0]; 1485 struct macroblock_plane *const p = &x->plane[0];
1475 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; 1486 struct macroblockd_plane *const pd = &x->e_mbd.plane[0];
1476 1487
1477 p->src.buf = &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, 1488 p->src.buf = &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i,
1478 p->src.stride)]; 1489 p->src.stride)];
1479 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); 1490 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0);
1480 pd->pre[0].buf = &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8, i, 1491 pd->pre[0].buf = &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8, i,
1481 pd->pre[0].stride)]; 1492 pd->pre[0].stride)];
1482 if (has_second_ref(mbmi)) 1493 if (has_second_ref(mbmi))
1483 pd->pre[1].buf = &pd->pre[1].buf[vp9_raster_block_offset(BLOCK_8X8, i, 1494 pd->pre[1].buf = &pd->pre[1].buf[vp9_raster_block_offset(BLOCK_8X8, i,
1484 pd->pre[1].stride)]; 1495 pd->pre[1].stride)];
1485 } 1496 }
1486 1497
1487 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, 1498 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src,
1488 struct buf_2d orig_pre[2]) { 1499 struct buf_2d orig_pre[2]) {
1489 MB_MODE_INFO *mbmi = &x->e_mbd.mi[0].src_mi->mbmi; 1500 MB_MODE_INFO *mbmi = &x->e_mbd.mi[0]->mbmi;
1490 x->plane[0].src = orig_src; 1501 x->plane[0].src = orig_src;
1491 x->e_mbd.plane[0].pre[0] = orig_pre[0]; 1502 x->e_mbd.plane[0].pre[0] = orig_pre[0];
1492 if (has_second_ref(mbmi)) 1503 if (has_second_ref(mbmi))
1493 x->e_mbd.plane[0].pre[1] = orig_pre[1]; 1504 x->e_mbd.plane[0].pre[1] = orig_pre[1];
1494 } 1505 }
1495 1506
1496 static INLINE int mv_has_subpel(const MV *mv) { 1507 static INLINE int mv_has_subpel(const MV *mv) {
1497 return (mv->row & 0x0F) || (mv->col & 0x0F); 1508 return (mv->row & 0x0F) || (mv->col & 0x0F);
1498 } 1509 }
1499 1510
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, 1548 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
1538 BLOCK_SIZE bsize, 1549 BLOCK_SIZE bsize,
1539 int_mv *frame_mv, 1550 int_mv *frame_mv,
1540 int mi_row, int mi_col, 1551 int mi_row, int mi_col,
1541 int_mv single_newmv[MAX_REF_FRAMES], 1552 int_mv single_newmv[MAX_REF_FRAMES],
1542 int *rate_mv) { 1553 int *rate_mv) {
1543 const VP9_COMMON *const cm = &cpi->common; 1554 const VP9_COMMON *const cm = &cpi->common;
1544 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize]; 1555 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
1545 const int ph = 4 * num_4x4_blocks_high_lookup[bsize]; 1556 const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
1546 MACROBLOCKD *xd = &x->e_mbd; 1557 MACROBLOCKD *xd = &x->e_mbd;
1547 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; 1558 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
1548 const int refs[2] = {mbmi->ref_frame[0], 1559 const int refs[2] = {mbmi->ref_frame[0],
1549 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]}; 1560 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]};
1550 int_mv ref_mv[2]; 1561 int_mv ref_mv[2];
1551 int ite, ref; 1562 int ite, ref;
1552 // Prediction buffer from second frame.
1553 #if CONFIG_VP9_HIGHBITDEPTH
1554 uint8_t *second_pred;
1555 uint8_t *second_pred_alloc;
1556 #else
1557 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t));
1558 #endif // CONFIG_VP9_HIGHBITDEPTH
1559 const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter); 1563 const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter);
1560 struct scale_factors sf; 1564 struct scale_factors sf;
1561 1565
1562 // Do joint motion search in compound mode to get more accurate mv. 1566 // Do joint motion search in compound mode to get more accurate mv.
1563 struct buf_2d backup_yv12[2][MAX_MB_PLANE]; 1567 struct buf_2d backup_yv12[2][MAX_MB_PLANE];
1564 int last_besterr[2] = {INT_MAX, INT_MAX}; 1568 int last_besterr[2] = {INT_MAX, INT_MAX};
1565 const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = { 1569 const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = {
1566 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]), 1570 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]),
1567 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[1]) 1571 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[1])
1568 }; 1572 };
1573
1574 // Prediction buffer from second frame.
1569 #if CONFIG_VP9_HIGHBITDEPTH 1575 #if CONFIG_VP9_HIGHBITDEPTH
1570 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 1576 DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[64 * 64]);
1571 second_pred_alloc = vpx_memalign(16, pw * ph * sizeof(uint16_t)); 1577 uint8_t *second_pred;
1572 second_pred = CONVERT_TO_BYTEPTR(second_pred_alloc); 1578 #else
1573 } else { 1579 DECLARE_ALIGNED(16, uint8_t, second_pred[64 * 64]);
1574 second_pred_alloc = vpx_memalign(16, pw * ph * sizeof(uint8_t));
1575 second_pred = second_pred_alloc;
1576 }
1577 #endif // CONFIG_VP9_HIGHBITDEPTH 1580 #endif // CONFIG_VP9_HIGHBITDEPTH
1578 1581
1579 for (ref = 0; ref < 2; ++ref) { 1582 for (ref = 0; ref < 2; ++ref) {
1580 ref_mv[ref] = mbmi->ref_mvs[refs[ref]][0]; 1583 ref_mv[ref] = mbmi->ref_mvs[refs[ref]][0];
1581 1584
1582 if (scaled_ref_frame[ref]) { 1585 if (scaled_ref_frame[ref]) {
1583 int i; 1586 int i;
1584 // Swap out the reference frame for a version that's been scaled to 1587 // Swap out the reference frame for a version that's been scaled to
1585 // match the resolution of the current frame, allowing the existing 1588 // match the resolution of the current frame, allowing the existing
1586 // motion search code to be used without additional modifications. 1589 // motion search code to be used without additional modifications.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 // odd iterations search in the second. The predictor 1624 // odd iterations search in the second. The predictor
1622 // found for the 'other' reference frame is factored in. 1625 // found for the 'other' reference frame is factored in.
1623 1626
1624 // Initialized here because of compiler problem in Visual Studio. 1627 // Initialized here because of compiler problem in Visual Studio.
1625 ref_yv12[0] = xd->plane[0].pre[0]; 1628 ref_yv12[0] = xd->plane[0].pre[0];
1626 ref_yv12[1] = xd->plane[0].pre[1]; 1629 ref_yv12[1] = xd->plane[0].pre[1];
1627 1630
1628 // Get the prediction block from the 'other' reference frame. 1631 // Get the prediction block from the 'other' reference frame.
1629 #if CONFIG_VP9_HIGHBITDEPTH 1632 #if CONFIG_VP9_HIGHBITDEPTH
1630 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 1633 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1634 second_pred = CONVERT_TO_BYTEPTR(second_pred_alloc_16);
1631 vp9_highbd_build_inter_predictor(ref_yv12[!id].buf, 1635 vp9_highbd_build_inter_predictor(ref_yv12[!id].buf,
1632 ref_yv12[!id].stride, 1636 ref_yv12[!id].stride,
1633 second_pred, pw, 1637 second_pred, pw,
1634 &frame_mv[refs[!id]].as_mv, 1638 &frame_mv[refs[!id]].as_mv,
1635 &sf, pw, ph, 0, 1639 &sf, pw, ph, 0,
1636 kernel, MV_PRECISION_Q3, 1640 kernel, MV_PRECISION_Q3,
1637 mi_col * MI_SIZE, mi_row * MI_SIZE, 1641 mi_col * MI_SIZE, mi_row * MI_SIZE,
1638 xd->bd); 1642 xd->bd);
1639 } else { 1643 } else {
1644 second_pred = (uint8_t *)second_pred_alloc_16;
1640 vp9_build_inter_predictor(ref_yv12[!id].buf, 1645 vp9_build_inter_predictor(ref_yv12[!id].buf,
1641 ref_yv12[!id].stride, 1646 ref_yv12[!id].stride,
1642 second_pred, pw, 1647 second_pred, pw,
1643 &frame_mv[refs[!id]].as_mv, 1648 &frame_mv[refs[!id]].as_mv,
1644 &sf, pw, ph, 0, 1649 &sf, pw, ph, 0,
1645 kernel, MV_PRECISION_Q3, 1650 kernel, MV_PRECISION_Q3,
1646 mi_col * MI_SIZE, mi_row * MI_SIZE); 1651 mi_col * MI_SIZE, mi_row * MI_SIZE);
1647 } 1652 }
1648 #else 1653 #else
1649 vp9_build_inter_predictor(ref_yv12[!id].buf, 1654 vp9_build_inter_predictor(ref_yv12[!id].buf,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 // Restore the prediction frame pointers to their unscaled versions. 1720 // Restore the prediction frame pointers to their unscaled versions.
1716 int i; 1721 int i;
1717 for (i = 0; i < MAX_MB_PLANE; i++) 1722 for (i = 0; i < MAX_MB_PLANE; i++)
1718 xd->plane[i].pre[ref] = backup_yv12[ref][i]; 1723 xd->plane[i].pre[ref] = backup_yv12[ref][i];
1719 } 1724 }
1720 1725
1721 *rate_mv += vp9_mv_bit_cost(&frame_mv[refs[ref]].as_mv, 1726 *rate_mv += vp9_mv_bit_cost(&frame_mv[refs[ref]].as_mv,
1722 &mbmi->ref_mvs[refs[ref]][0].as_mv, 1727 &mbmi->ref_mvs[refs[ref]][0].as_mv,
1723 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); 1728 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
1724 } 1729 }
1725
1726 #if CONFIG_VP9_HIGHBITDEPTH
1727 vpx_free(second_pred_alloc);
1728 #else
1729 vpx_free(second_pred);
1730 #endif // CONFIG_VP9_HIGHBITDEPTH
1731 } 1730 }
1732 1731
1733 static int64_t rd_pick_best_sub8x8_mode(VP9_COMP *cpi, MACROBLOCK *x, 1732 static int64_t rd_pick_best_sub8x8_mode(VP9_COMP *cpi, MACROBLOCK *x,
1734 const TileInfo * const tile, 1733 const TileInfo * const tile,
1735 int_mv *best_ref_mv, 1734 int_mv *best_ref_mv,
1736 int_mv *second_best_ref_mv, 1735 int_mv *second_best_ref_mv,
1737 int64_t best_rd, int *returntotrate, 1736 int64_t best_rd, int *returntotrate,
1738 int *returnyrate, 1737 int *returnyrate,
1739 int64_t *returndistortion, 1738 int64_t *returndistortion,
1740 int *skippable, int64_t *psse, 1739 int *skippable, int64_t *psse,
1741 int mvthresh, 1740 int mvthresh,
1742 int_mv seg_mvs[4][MAX_REF_FRAMES], 1741 int_mv seg_mvs[4][MAX_REF_FRAMES],
1743 BEST_SEG_INFO *bsi_buf, int filter_idx, 1742 BEST_SEG_INFO *bsi_buf, int filter_idx,
1744 int mi_row, int mi_col) { 1743 int mi_row, int mi_col) {
1745 int i; 1744 int i;
1746 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; 1745 BEST_SEG_INFO *bsi = bsi_buf + filter_idx;
1747 MACROBLOCKD *xd = &x->e_mbd; 1746 MACROBLOCKD *xd = &x->e_mbd;
1748 MODE_INFO *mi = xd->mi[0].src_mi; 1747 MODE_INFO *mi = xd->mi[0];
1749 MB_MODE_INFO *mbmi = &mi->mbmi; 1748 MB_MODE_INFO *mbmi = &mi->mbmi;
1750 int mode_idx; 1749 int mode_idx;
1751 int k, br = 0, idx, idy; 1750 int k, br = 0, idx, idy;
1752 int64_t bd = 0, block_sse = 0; 1751 int64_t bd = 0, block_sse = 0;
1753 PREDICTION_MODE this_mode; 1752 PREDICTION_MODE this_mode;
1754 VP9_COMMON *cm = &cpi->common; 1753 VP9_COMMON *cm = &cpi->common;
1755 struct macroblock_plane *const p = &x->plane[0]; 1754 struct macroblock_plane *const p = &x->plane[0];
1756 struct macroblockd_plane *const pd = &xd->plane[0]; 1755 struct macroblockd_plane *const pd = &xd->plane[0];
1757 const int label_count = 4; 1756 const int label_count = 4;
1758 int64_t this_segment_rd = 0; 1757 int64_t this_segment_rd = 0;
(...skipping 11 matching lines...) Expand all
1770 1769
1771 bsi->segment_rd = best_rd; 1770 bsi->segment_rd = best_rd;
1772 bsi->ref_mv[0] = best_ref_mv; 1771 bsi->ref_mv[0] = best_ref_mv;
1773 bsi->ref_mv[1] = second_best_ref_mv; 1772 bsi->ref_mv[1] = second_best_ref_mv;
1774 bsi->mvp.as_int = best_ref_mv->as_int; 1773 bsi->mvp.as_int = best_ref_mv->as_int;
1775 bsi->mvthresh = mvthresh; 1774 bsi->mvthresh = mvthresh;
1776 1775
1777 for (i = 0; i < 4; i++) 1776 for (i = 0; i < 4; i++)
1778 bsi->modes[i] = ZEROMV; 1777 bsi->modes[i] = ZEROMV;
1779 1778
1780 vpx_memcpy(t_above, pd->above_context, sizeof(t_above)); 1779 memcpy(t_above, pd->above_context, sizeof(t_above));
1781 vpx_memcpy(t_left, pd->left_context, sizeof(t_left)); 1780 memcpy(t_left, pd->left_context, sizeof(t_left));
1782 1781
1783 // 64 makes this threshold really big effectively 1782 // 64 makes this threshold really big effectively
1784 // making it so that we very rarely check mvs on 1783 // making it so that we very rarely check mvs on
1785 // segments. setting this to 1 would make mv thresh 1784 // segments. setting this to 1 would make mv thresh
1786 // roughly equal to what it is for macroblocks 1785 // roughly equal to what it is for macroblocks
1787 label_mv_thresh = 1 * bsi->mvthresh / label_count; 1786 label_mv_thresh = 1 * bsi->mvthresh / label_count;
1788 1787
1789 // Segmentation method overheads 1788 // Segmentation method overheads
1790 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { 1789 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
1791 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { 1790 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
(...skipping 21 matching lines...) Expand all
1813 1812
1814 mode_idx = INTER_OFFSET(this_mode); 1813 mode_idx = INTER_OFFSET(this_mode);
1815 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; 1814 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX;
1816 if (!(inter_mode_mask & (1 << this_mode))) 1815 if (!(inter_mode_mask & (1 << this_mode)))
1817 continue; 1816 continue;
1818 1817
1819 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, 1818 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv,
1820 this_mode, mbmi->ref_frame)) 1819 this_mode, mbmi->ref_frame))
1821 continue; 1820 continue;
1822 1821
1823 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre)); 1822 memcpy(orig_pre, pd->pre, sizeof(orig_pre));
1824 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, 1823 memcpy(bsi->rdstat[i][mode_idx].ta, t_above,
1825 sizeof(bsi->rdstat[i][mode_idx].ta)); 1824 sizeof(bsi->rdstat[i][mode_idx].ta));
1826 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, 1825 memcpy(bsi->rdstat[i][mode_idx].tl, t_left,
1827 sizeof(bsi->rdstat[i][mode_idx].tl)); 1826 sizeof(bsi->rdstat[i][mode_idx].tl));
1828 1827
1829 // motion search for newmv (single predictor case only) 1828 // motion search for newmv (single predictor case only)
1830 if (!has_second_rf && this_mode == NEWMV && 1829 if (!has_second_rf && this_mode == NEWMV &&
1831 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) { 1830 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) {
1832 MV *const new_mv = &mode_mv[NEWMV][0].as_mv; 1831 MV *const new_mv = &mode_mv[NEWMV][0].as_mv;
1833 int step_param = 0; 1832 int step_param = 0;
1834 int thissme, bestsme = INT_MAX; 1833 int thissme, bestsme = INT_MAX;
1835 int sadpb = x->sadperbit4; 1834 int sadpb = x->sadperbit4;
1836 MV mvp_full; 1835 MV mvp_full;
1837 int max_mv; 1836 int max_mv;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 if (filter_idx > 1 && !subpelmv && !have_ref) { 1992 if (filter_idx > 1 && !subpelmv && !have_ref) {
1994 ref_bsi = bsi_buf + 1; 1993 ref_bsi = bsi_buf + 1;
1995 have_ref = 1; 1994 have_ref = 1;
1996 for (ref = 0; ref < 1 + has_second_rf; ++ref) 1995 for (ref = 0; ref < 1 + has_second_rf; ++ref)
1997 have_ref &= mode_mv[this_mode][ref].as_int == 1996 have_ref &= mode_mv[this_mode][ref].as_int ==
1998 ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int; 1997 ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int;
1999 } 1998 }
2000 1999
2001 if (!subpelmv && have_ref && 2000 if (!subpelmv && have_ref &&
2002 ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { 2001 ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) {
2003 vpx_memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx], 2002 memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx],
2004 sizeof(SEG_RDSTAT)); 2003 sizeof(SEG_RDSTAT));
2005 if (num_4x4_blocks_wide > 1) 2004 if (num_4x4_blocks_wide > 1)
2006 bsi->rdstat[i + 1][mode_idx].eobs = 2005 bsi->rdstat[i + 1][mode_idx].eobs =
2007 ref_bsi->rdstat[i + 1][mode_idx].eobs; 2006 ref_bsi->rdstat[i + 1][mode_idx].eobs;
2008 if (num_4x4_blocks_high > 1) 2007 if (num_4x4_blocks_high > 1)
2009 bsi->rdstat[i + 2][mode_idx].eobs = 2008 bsi->rdstat[i + 2][mode_idx].eobs =
2010 ref_bsi->rdstat[i + 2][mode_idx].eobs; 2009 ref_bsi->rdstat[i + 2][mode_idx].eobs;
2011 2010
2012 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { 2011 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) {
2013 mode_selected = this_mode; 2012 mode_selected = this_mode;
2014 best_rd = bsi->rdstat[i][mode_idx].brdcost; 2013 best_rd = bsi->rdstat[i][mode_idx].brdcost;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 if (best_rd == INT64_MAX) { 2045 if (best_rd == INT64_MAX) {
2047 int iy, midx; 2046 int iy, midx;
2048 for (iy = i + 1; iy < 4; ++iy) 2047 for (iy = i + 1; iy < 4; ++iy)
2049 for (midx = 0; midx < INTER_MODES; ++midx) 2048 for (midx = 0; midx < INTER_MODES; ++midx)
2050 bsi->rdstat[iy][midx].brdcost = INT64_MAX; 2049 bsi->rdstat[iy][midx].brdcost = INT64_MAX;
2051 bsi->segment_rd = INT64_MAX; 2050 bsi->segment_rd = INT64_MAX;
2052 return INT64_MAX; 2051 return INT64_MAX;
2053 } 2052 }
2054 2053
2055 mode_idx = INTER_OFFSET(mode_selected); 2054 mode_idx = INTER_OFFSET(mode_selected);
2056 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above)); 2055 memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above));
2057 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left)); 2056 memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left));
2058 2057
2059 set_and_cost_bmi_mvs(cpi, xd, i, mode_selected, mode_mv[mode_selected], 2058 set_and_cost_bmi_mvs(cpi, xd, i, mode_selected, mode_mv[mode_selected],
2060 frame_mv, seg_mvs[i], bsi->ref_mv, x->nmvjointcost, 2059 frame_mv, seg_mvs[i], bsi->ref_mv, x->nmvjointcost,
2061 x->mvcost); 2060 x->mvcost);
2062 2061
2063 br += bsi->rdstat[i][mode_idx].brate; 2062 br += bsi->rdstat[i][mode_idx].brate;
2064 bd += bsi->rdstat[i][mode_idx].bdist; 2063 bd += bsi->rdstat[i][mode_idx].bdist;
2065 block_sse += bsi->rdstat[i][mode_idx].bsse; 2064 block_sse += bsi->rdstat[i][mode_idx].bsse;
2066 segmentyrate += bsi->rdstat[i][mode_idx].byrate; 2065 segmentyrate += bsi->rdstat[i][mode_idx].byrate;
2067 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; 2066 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 2113
2115 static void estimate_ref_frame_costs(const VP9_COMMON *cm, 2114 static void estimate_ref_frame_costs(const VP9_COMMON *cm,
2116 const MACROBLOCKD *xd, 2115 const MACROBLOCKD *xd,
2117 int segment_id, 2116 int segment_id,
2118 unsigned int *ref_costs_single, 2117 unsigned int *ref_costs_single,
2119 unsigned int *ref_costs_comp, 2118 unsigned int *ref_costs_comp,
2120 vp9_prob *comp_mode_p) { 2119 vp9_prob *comp_mode_p) {
2121 int seg_ref_active = vp9_segfeature_active(&cm->seg, segment_id, 2120 int seg_ref_active = vp9_segfeature_active(&cm->seg, segment_id,
2122 SEG_LVL_REF_FRAME); 2121 SEG_LVL_REF_FRAME);
2123 if (seg_ref_active) { 2122 if (seg_ref_active) {
2124 vpx_memset(ref_costs_single, 0, MAX_REF_FRAMES * sizeof(*ref_costs_single)); 2123 memset(ref_costs_single, 0, MAX_REF_FRAMES * sizeof(*ref_costs_single));
2125 vpx_memset(ref_costs_comp, 0, MAX_REF_FRAMES * sizeof(*ref_costs_comp)); 2124 memset(ref_costs_comp, 0, MAX_REF_FRAMES * sizeof(*ref_costs_comp));
2126 *comp_mode_p = 128; 2125 *comp_mode_p = 128;
2127 } else { 2126 } else {
2128 vp9_prob intra_inter_p = vp9_get_intra_inter_prob(cm, xd); 2127 vp9_prob intra_inter_p = vp9_get_intra_inter_prob(cm, xd);
2129 vp9_prob comp_inter_p = 128; 2128 vp9_prob comp_inter_p = 128;
2130 2129
2131 if (cm->reference_mode == REFERENCE_MODE_SELECT) { 2130 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
2132 comp_inter_p = vp9_get_reference_mode_prob(cm, xd); 2131 comp_inter_p = vp9_get_reference_mode_prob(cm, xd);
2133 *comp_mode_p = comp_inter_p; 2132 *comp_mode_p = comp_inter_p;
2134 } else { 2133 } else {
2135 *comp_mode_p = 128; 2134 *comp_mode_p = 128;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 const int64_t tx_size_diff[TX_MODES], 2178 const int64_t tx_size_diff[TX_MODES],
2180 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS], 2179 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS],
2181 int skippable) { 2180 int skippable) {
2182 MACROBLOCKD *const xd = &x->e_mbd; 2181 MACROBLOCKD *const xd = &x->e_mbd;
2183 2182
2184 // Take a snapshot of the coding context so it can be 2183 // Take a snapshot of the coding context so it can be
2185 // restored if we decide to encode this way 2184 // restored if we decide to encode this way
2186 ctx->skip = x->skip; 2185 ctx->skip = x->skip;
2187 ctx->skippable = skippable; 2186 ctx->skippable = skippable;
2188 ctx->best_mode_index = mode_index; 2187 ctx->best_mode_index = mode_index;
2189 ctx->mic = *xd->mi[0].src_mi; 2188 ctx->mic = *xd->mi[0];
2190 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE]; 2189 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE];
2191 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE]; 2190 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE];
2192 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT]; 2191 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT];
2193 2192
2194 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); 2193 memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff));
2195 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, 2194 memcpy(ctx->best_filter_diff, best_filter_diff,
2196 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); 2195 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS);
2197 } 2196 }
2198 2197
2199 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, 2198 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
2200 const TileInfo *const tile, 2199 const TileInfo *const tile,
2201 MV_REFERENCE_FRAME ref_frame, 2200 MV_REFERENCE_FRAME ref_frame,
2202 BLOCK_SIZE block_size, 2201 BLOCK_SIZE block_size,
2203 int mi_row, int mi_col, 2202 int mi_row, int mi_col,
2204 int_mv frame_nearest_mv[MAX_REF_FRAMES], 2203 int_mv frame_nearest_mv[MAX_REF_FRAMES],
2205 int_mv frame_near_mv[MAX_REF_FRAMES], 2204 int_mv frame_near_mv[MAX_REF_FRAMES],
2206 struct buf_2d yv12_mb[4][MAX_MB_PLANE]) { 2205 struct buf_2d yv12_mb[4][MAX_MB_PLANE]) {
2207 const VP9_COMMON *cm = &cpi->common; 2206 const VP9_COMMON *cm = &cpi->common;
2208 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); 2207 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
2209 MACROBLOCKD *const xd = &x->e_mbd; 2208 MACROBLOCKD *const xd = &x->e_mbd;
2210 MODE_INFO *const mi = xd->mi[0].src_mi; 2209 MODE_INFO *const mi = xd->mi[0];
2211 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame]; 2210 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame];
2212 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; 2211 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
2213 2212
2214 assert(yv12 != NULL); 2213 assert(yv12 != NULL);
2215 2214
2216 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this 2215 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this
2217 // use the UV scaling factors. 2216 // use the UV scaling factors.
2218 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); 2217 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf);
2219 2218
2220 // Gets an initial list of candidate vectors from neighbours and orders them 2219 // Gets an initial list of candidate vectors from neighbours and orders them
(...skipping 12 matching lines...) Expand all
2233 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, 2232 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride,
2234 ref_frame, block_size); 2233 ref_frame, block_size);
2235 } 2234 }
2236 2235
2237 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, 2236 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
2238 BLOCK_SIZE bsize, 2237 BLOCK_SIZE bsize,
2239 int mi_row, int mi_col, 2238 int mi_row, int mi_col,
2240 int_mv *tmp_mv, int *rate_mv) { 2239 int_mv *tmp_mv, int *rate_mv) {
2241 MACROBLOCKD *xd = &x->e_mbd; 2240 MACROBLOCKD *xd = &x->e_mbd;
2242 const VP9_COMMON *cm = &cpi->common; 2241 const VP9_COMMON *cm = &cpi->common;
2243 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; 2242 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
2244 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}}; 2243 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
2245 int bestsme = INT_MAX; 2244 int bestsme = INT_MAX;
2246 int step_param; 2245 int step_param;
2247 int sadpb = x->sadperbit16; 2246 int sadpb = x->sadperbit16;
2248 MV mvp_full; 2247 MV mvp_full;
2249 int ref = mbmi->ref_frame[0]; 2248 int ref = mbmi->ref_frame[0];
2250 MV ref_mv = mbmi->ref_mvs[ref][0].as_mv; 2249 MV ref_mv = mbmi->ref_mvs[ref][0].as_mv;
2251 2250
2252 int tmp_col_min = x->mv_col_min; 2251 int tmp_col_min = x->mv_col_min;
2253 int tmp_col_max = x->mv_col_max; 2252 int tmp_col_max = x->mv_col_max;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 int mi_row, int mi_col, 2404 int mi_row, int mi_col,
2406 int_mv single_newmv[MAX_REF_FRAMES], 2405 int_mv single_newmv[MAX_REF_FRAMES],
2407 INTERP_FILTER (*single_filter)[MAX_REF_FRAMES], 2406 INTERP_FILTER (*single_filter)[MAX_REF_FRAMES],
2408 int (*single_skippable)[MAX_REF_FRAMES], 2407 int (*single_skippable)[MAX_REF_FRAMES],
2409 int64_t *psse, 2408 int64_t *psse,
2410 const int64_t ref_best_rd, 2409 const int64_t ref_best_rd,
2411 int64_t *mask_filter, 2410 int64_t *mask_filter,
2412 int64_t filter_cache[]) { 2411 int64_t filter_cache[]) {
2413 VP9_COMMON *cm = &cpi->common; 2412 VP9_COMMON *cm = &cpi->common;
2414 MACROBLOCKD *xd = &x->e_mbd; 2413 MACROBLOCKD *xd = &x->e_mbd;
2415 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; 2414 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
2416 const int is_comp_pred = has_second_ref(mbmi); 2415 const int is_comp_pred = has_second_ref(mbmi);
2417 const int this_mode = mbmi->mode; 2416 const int this_mode = mbmi->mode;
2418 int_mv *frame_mv = mode_mv[this_mode]; 2417 int_mv *frame_mv = mode_mv[this_mode];
2419 int i; 2418 int i;
2420 int refs[2] = { mbmi->ref_frame[0], 2419 int refs[2] = { mbmi->ref_frame[0],
2421 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; 2420 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) };
2422 int_mv cur_mv[2]; 2421 int_mv cur_mv[2];
2423 #if CONFIG_VP9_HIGHBITDEPTH 2422 #if CONFIG_VP9_HIGHBITDEPTH
2424 DECLARE_ALIGNED_ARRAY(16, uint16_t, tmp_buf16, MAX_MB_PLANE * 64 * 64); 2423 DECLARE_ALIGNED(16, uint16_t, tmp_buf16[MAX_MB_PLANE * 64 * 64]);
2425 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf8, MAX_MB_PLANE * 64 * 64);
2426 uint8_t *tmp_buf; 2424 uint8_t *tmp_buf;
2427 #else 2425 #else
2428 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); 2426 DECLARE_ALIGNED(16, uint8_t, tmp_buf[MAX_MB_PLANE * 64 * 64]);
2429 #endif // CONFIG_VP9_HIGHBITDEPTH 2427 #endif // CONFIG_VP9_HIGHBITDEPTH
2430 int pred_exists = 0; 2428 int pred_exists = 0;
2431 int intpel_mv; 2429 int intpel_mv;
2432 int64_t rd, tmp_rd, best_rd = INT64_MAX; 2430 int64_t rd, tmp_rd, best_rd = INT64_MAX;
2433 int best_needs_copy = 0; 2431 int best_needs_copy = 0;
2434 uint8_t *orig_dst[MAX_MB_PLANE]; 2432 uint8_t *orig_dst[MAX_MB_PLANE];
2435 int orig_dst_stride[MAX_MB_PLANE]; 2433 int orig_dst_stride[MAX_MB_PLANE];
2436 int rs = 0; 2434 int rs = 0;
2437 INTERP_FILTER best_filter = SWITCHABLE; 2435 INTERP_FILTER best_filter = SWITCHABLE;
2438 uint8_t skip_txfm[MAX_MB_PLANE << 2] = {0}; 2436 uint8_t skip_txfm[MAX_MB_PLANE << 2] = {0};
2439 int64_t bsse[MAX_MB_PLANE << 2] = {0}; 2437 int64_t bsse[MAX_MB_PLANE << 2] = {0};
2440 2438
2441 int bsl = mi_width_log2_lookup[bsize]; 2439 int bsl = mi_width_log2_lookup[bsize];
2442 int pred_filter_search = cpi->sf.cb_pred_filter_search ? 2440 int pred_filter_search = cpi->sf.cb_pred_filter_search ?
2443 (((mi_row + mi_col) >> bsl) + 2441 (((mi_row + mi_col) >> bsl) +
2444 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; 2442 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0;
2445 2443
2446 int skip_txfm_sb = 0; 2444 int skip_txfm_sb = 0;
2447 int64_t skip_sse_sb = INT64_MAX; 2445 int64_t skip_sse_sb = INT64_MAX;
2448 int64_t distortion_y = 0, distortion_uv = 0; 2446 int64_t distortion_y = 0, distortion_uv = 0;
2449 2447
2450 #if CONFIG_VP9_HIGHBITDEPTH 2448 #if CONFIG_VP9_HIGHBITDEPTH
2451 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 2449 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2452 tmp_buf = CONVERT_TO_BYTEPTR(tmp_buf16); 2450 tmp_buf = CONVERT_TO_BYTEPTR(tmp_buf16);
2453 } else { 2451 } else {
2454 tmp_buf = tmp_buf8; 2452 tmp_buf = (uint8_t *)tmp_buf16;
2455 } 2453 }
2456 #endif // CONFIG_VP9_HIGHBITDEPTH 2454 #endif // CONFIG_VP9_HIGHBITDEPTH
2457 2455
2458 if (pred_filter_search) { 2456 if (pred_filter_search) {
2459 INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE; 2457 INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE;
2460 if (xd->up_available) 2458 if (xd->up_available)
2461 af = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; 2459 af = xd->mi[-xd->mi_stride]->mbmi.interp_filter;
2462 if (xd->left_available) 2460 if (xd->left_available)
2463 lf = xd->mi[-1].src_mi->mbmi.interp_filter; 2461 lf = xd->mi[-1]->mbmi.interp_filter;
2464 2462
2465 if ((this_mode != NEWMV) || (af == lf)) 2463 if ((this_mode != NEWMV) || (af == lf))
2466 best_filter = af; 2464 best_filter = af;
2467 } 2465 }
2468 2466
2469 if (is_comp_pred) { 2467 if (is_comp_pred) {
2470 if (frame_mv[refs[0]].as_int == INVALID_MV || 2468 if (frame_mv[refs[0]].as_int == INVALID_MV ||
2471 frame_mv[refs[1]].as_int == INVALID_MV) 2469 frame_mv[refs[1]].as_int == INVALID_MV)
2472 return INT64_MAX; 2470 return INT64_MAX;
2473 2471
(...skipping 24 matching lines...) Expand all
2498 } 2496 }
2499 *rate2 += rate_mv; 2497 *rate2 += rate_mv;
2500 } else { 2498 } else {
2501 int_mv tmp_mv; 2499 int_mv tmp_mv;
2502 single_motion_search(cpi, x, bsize, mi_row, mi_col, 2500 single_motion_search(cpi, x, bsize, mi_row, mi_col,
2503 &tmp_mv, &rate_mv); 2501 &tmp_mv, &rate_mv);
2504 if (tmp_mv.as_int == INVALID_MV) 2502 if (tmp_mv.as_int == INVALID_MV)
2505 return INT64_MAX; 2503 return INT64_MAX;
2506 2504
2507 frame_mv[refs[0]].as_int = 2505 frame_mv[refs[0]].as_int =
2508 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = tmp_mv.as_int; 2506 xd->mi[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int;
2509 single_newmv[refs[0]].as_int = tmp_mv.as_int; 2507 single_newmv[refs[0]].as_int = tmp_mv.as_int;
2510 2508
2511 // Estimate the rate implications of a new mv but discount this 2509 // Estimate the rate implications of a new mv but discount this
2512 // under certain circumstances where we want to help initiate a weak 2510 // under certain circumstances where we want to help initiate a weak
2513 // motion field, where the distortion gain for a single block may not 2511 // motion field, where the distortion gain for a single block may not
2514 // be enough to overcome the cost of a new mv. 2512 // be enough to overcome the cost of a new mv.
2515 if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0])) { 2513 if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0])) {
2516 *rate2 += MAX((rate_mv / NEW_MV_DISCOUNT_FACTOR), 1); 2514 *rate2 += MAX((rate_mv / NEW_MV_DISCOUNT_FACTOR), 1);
2517 } else { 2515 } else {
2518 *rate2 += rate_mv; 2516 *rate2 += rate_mv;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2653 } 2651 }
2654 2652
2655 if ((cm->interp_filter == SWITCHABLE && newbest) || 2653 if ((cm->interp_filter == SWITCHABLE && newbest) ||
2656 (cm->interp_filter != SWITCHABLE && 2654 (cm->interp_filter != SWITCHABLE &&
2657 cm->interp_filter == mbmi->interp_filter)) { 2655 cm->interp_filter == mbmi->interp_filter)) {
2658 pred_exists = 1; 2656 pred_exists = 1;
2659 tmp_rd = best_rd; 2657 tmp_rd = best_rd;
2660 2658
2661 skip_txfm_sb = tmp_skip_sb; 2659 skip_txfm_sb = tmp_skip_sb;
2662 skip_sse_sb = tmp_skip_sse; 2660 skip_sse_sb = tmp_skip_sse;
2663 vpx_memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm)); 2661 memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm));
2664 vpx_memcpy(bsse, x->bsse, sizeof(bsse)); 2662 memcpy(bsse, x->bsse, sizeof(bsse));
2665 } 2663 }
2666 } 2664 }
2667 restore_dst_buf(xd, orig_dst, orig_dst_stride); 2665 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2668 } 2666 }
2669 } 2667 }
2670 // Set the appropriate filter 2668 // Set the appropriate filter
2671 mbmi->interp_filter = cm->interp_filter != SWITCHABLE ? 2669 mbmi->interp_filter = cm->interp_filter != SWITCHABLE ?
2672 cm->interp_filter : best_filter; 2670 cm->interp_filter : best_filter;
2673 rs = cm->interp_filter == SWITCHABLE ? vp9_get_switchable_rate(cpi, xd) : 0; 2671 rs = cm->interp_filter == SWITCHABLE ? vp9_get_switchable_rate(cpi, xd) : 0;
2674 2672
2675 if (pred_exists) { 2673 if (pred_exists) {
2676 if (best_needs_copy) { 2674 if (best_needs_copy) {
2677 // again temporarily set the buffers to local memory to prevent a memcpy 2675 // again temporarily set the buffers to local memory to prevent a memcpy
2678 for (i = 0; i < MAX_MB_PLANE; i++) { 2676 for (i = 0; i < MAX_MB_PLANE; i++) {
2679 xd->plane[i].dst.buf = tmp_buf + i * 64 * 64; 2677 xd->plane[i].dst.buf = tmp_buf + i * 64 * 64;
2680 xd->plane[i].dst.stride = 64; 2678 xd->plane[i].dst.stride = 64;
2681 } 2679 }
2682 } 2680 }
2683 rd = tmp_rd + RDCOST(x->rdmult, x->rddiv, rs, 0); 2681 rd = tmp_rd + RDCOST(x->rdmult, x->rddiv, rs, 0);
2684 } else { 2682 } else {
2685 int tmp_rate; 2683 int tmp_rate;
2686 int64_t tmp_dist; 2684 int64_t tmp_dist;
2687 // Handles the special case when a filter that is not in the 2685 // Handles the special case when a filter that is not in the
2688 // switchable list (ex. bilinear) is indicated at the frame level, or 2686 // switchable list (ex. bilinear) is indicated at the frame level, or
2689 // skip condition holds. 2687 // skip condition holds.
2690 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); 2688 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
2691 model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist, 2689 model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist,
2692 &skip_txfm_sb, &skip_sse_sb); 2690 &skip_txfm_sb, &skip_sse_sb);
2693 rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist); 2691 rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist);
2694 vpx_memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm)); 2692 memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm));
2695 vpx_memcpy(bsse, x->bsse, sizeof(bsse)); 2693 memcpy(bsse, x->bsse, sizeof(bsse));
2696 } 2694 }
2697 2695
2698 if (!is_comp_pred) 2696 if (!is_comp_pred)
2699 single_filter[this_mode][refs[0]] = mbmi->interp_filter; 2697 single_filter[this_mode][refs[0]] = mbmi->interp_filter;
2700 2698
2701 if (cpi->sf.adaptive_mode_search) 2699 if (cpi->sf.adaptive_mode_search)
2702 if (is_comp_pred) 2700 if (is_comp_pred)
2703 if (single_skippable[this_mode][refs[0]] && 2701 if (single_skippable[this_mode][refs[0]] &&
2704 single_skippable[this_mode][refs[1]]) 2702 single_skippable[this_mode][refs[1]])
2705 vpx_memset(skip_txfm, 1, sizeof(skip_txfm)); 2703 memset(skip_txfm, 1, sizeof(skip_txfm));
2706 2704
2707 if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) { 2705 if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) {
2708 // if current pred_error modeled rd is substantially more than the best 2706 // if current pred_error modeled rd is substantially more than the best
2709 // so far, do not bother doing full rd 2707 // so far, do not bother doing full rd
2710 if (rd / 2 > ref_best_rd) { 2708 if (rd / 2 > ref_best_rd) {
2711 restore_dst_buf(xd, orig_dst, orig_dst_stride); 2709 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2712 return INT64_MAX; 2710 return INT64_MAX;
2713 } 2711 }
2714 } 2712 }
2715 2713
2716 if (cm->interp_filter == SWITCHABLE) 2714 if (cm->interp_filter == SWITCHABLE)
2717 *rate2 += rs; 2715 *rate2 += rs;
2718 2716
2719 vpx_memcpy(x->skip_txfm, skip_txfm, sizeof(skip_txfm)); 2717 memcpy(x->skip_txfm, skip_txfm, sizeof(skip_txfm));
2720 vpx_memcpy(x->bsse, bsse, sizeof(bsse)); 2718 memcpy(x->bsse, bsse, sizeof(bsse));
2721 2719
2722 if (!skip_txfm_sb) { 2720 if (!skip_txfm_sb) {
2723 int skippable_y, skippable_uv; 2721 int skippable_y, skippable_uv;
2724 int64_t sseuv = INT64_MAX; 2722 int64_t sseuv = INT64_MAX;
2725 int64_t rdcosty = INT64_MAX; 2723 int64_t rdcosty = INT64_MAX;
2726 2724
2727 // Y cost and distortion 2725 // Y cost and distortion
2728 vp9_subtract_plane(x, bsize, 0); 2726 vp9_subtract_plane(x, bsize, 0);
2729 super_block_yrd(cpi, x, rate_y, &distortion_y, &skippable_y, psse, 2727 super_block_yrd(cpi, x, rate_y, &distortion_y, &skippable_y, psse,
2730 bsize, txfm_cache, ref_best_rd); 2728 bsize, txfm_cache, ref_best_rd);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { 2774 PICK_MODE_CONTEXT *ctx, int64_t best_rd) {
2777 VP9_COMMON *const cm = &cpi->common; 2775 VP9_COMMON *const cm = &cpi->common;
2778 MACROBLOCKD *const xd = &x->e_mbd; 2776 MACROBLOCKD *const xd = &x->e_mbd;
2779 struct macroblockd_plane *const pd = xd->plane; 2777 struct macroblockd_plane *const pd = xd->plane;
2780 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; 2778 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0;
2781 int y_skip = 0, uv_skip = 0; 2779 int y_skip = 0, uv_skip = 0;
2782 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; 2780 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 };
2783 TX_SIZE max_uv_tx_size; 2781 TX_SIZE max_uv_tx_size;
2784 x->skip_encode = 0; 2782 x->skip_encode = 0;
2785 ctx->skip = 0; 2783 ctx->skip = 0;
2786 xd->mi[0].src_mi->mbmi.ref_frame[0] = INTRA_FRAME; 2784 xd->mi[0]->mbmi.ref_frame[0] = INTRA_FRAME;
2787 xd->mi[0].src_mi->mbmi.ref_frame[1] = NONE; 2785 xd->mi[0]->mbmi.ref_frame[1] = NONE;
2788 2786
2789 if (bsize >= BLOCK_8X8) { 2787 if (bsize >= BLOCK_8X8) {
2790 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, 2788 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
2791 &dist_y, &y_skip, bsize, tx_cache, 2789 &dist_y, &y_skip, bsize, tx_cache,
2792 best_rd) >= best_rd) { 2790 best_rd) >= best_rd) {
2793 rd_cost->rate = INT_MAX; 2791 rd_cost->rate = INT_MAX;
2794 return; 2792 return;
2795 } 2793 }
2796 } else { 2794 } else {
2797 y_skip = 0; 2795 y_skip = 0;
2798 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly, 2796 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly,
2799 &dist_y, best_rd) >= best_rd) { 2797 &dist_y, best_rd) >= best_rd) {
2800 rd_cost->rate = INT_MAX; 2798 rd_cost->rate = INT_MAX;
2801 return; 2799 return;
2802 } 2800 }
2803 } 2801 }
2804 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0].src_mi->mbmi.tx_size, bsize, 2802 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize,
2805 pd[1].subsampling_x, 2803 pd[1].subsampling_x,
2806 pd[1].subsampling_y); 2804 pd[1].subsampling_y);
2807 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, 2805 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
2808 &dist_uv, &uv_skip, MAX(BLOCK_8X8, bsize), 2806 &dist_uv, &uv_skip, MAX(BLOCK_8X8, bsize),
2809 max_uv_tx_size); 2807 max_uv_tx_size);
2810 2808
2811 if (y_skip && uv_skip) { 2809 if (y_skip && uv_skip) {
2812 rd_cost->rate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + 2810 rd_cost->rate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly +
2813 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); 2811 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
2814 rd_cost->dist = dist_y + dist_uv; 2812 rd_cost->dist = dist_y + dist_uv;
2815 vp9_zero(ctx->tx_rd_diff); 2813 vp9_zero(ctx->tx_rd_diff);
2816 } else { 2814 } else {
2817 int i; 2815 int i;
2818 rd_cost->rate = rate_y + rate_uv + 2816 rd_cost->rate = rate_y + rate_uv +
2819 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); 2817 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
2820 rd_cost->dist = dist_y + dist_uv; 2818 rd_cost->dist = dist_y + dist_uv;
2821 if (cpi->sf.tx_size_search_method == USE_FULL_RD) 2819 if (cpi->sf.tx_size_search_method == USE_FULL_RD)
2822 for (i = 0; i < TX_MODES; i++) { 2820 for (i = 0; i < TX_MODES; i++) {
2823 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) 2821 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX)
2824 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; 2822 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode];
2825 else 2823 else
2826 ctx->tx_rd_diff[i] = 0; 2824 ctx->tx_rd_diff[i] = 0;
2827 } 2825 }
2828 } 2826 }
2829 2827
2830 ctx->mic = *xd->mi[0].src_mi; 2828 ctx->mic = *xd->mi[0];
2831 rd_cost->rdcost = RDCOST(x->rdmult, x->rddiv, rd_cost->rate, rd_cost->dist); 2829 rd_cost->rdcost = RDCOST(x->rdmult, x->rddiv, rd_cost->rate, rd_cost->dist);
2832 } 2830 }
2833 2831
2832 // This function is designed to apply a bias or adjustment to an rd value based
2833 // on the relative variance of the source and reconstruction.
2834 #define LOW_VAR_THRESH 16
2835 #define VLOW_ADJ_MAX 25
2836 #define VHIGH_ADJ_MAX 8
2837 static void rd_variance_adjustment(VP9_COMP *cpi,
2838 MACROBLOCK *x,
2839 BLOCK_SIZE bsize,
2840 int64_t *this_rd,
2841 MV_REFERENCE_FRAME ref_frame,
2842 unsigned int source_variance) {
2843 MACROBLOCKD *const xd = &x->e_mbd;
2844 unsigned int recon_variance;
2845 unsigned int absvar_diff = 0;
2846 int64_t var_error = 0;
2847 int64_t var_factor = 0;
2848
2849 if (*this_rd == INT64_MAX)
2850 return;
2851
2852 #if CONFIG_VP9_HIGHBITDEPTH
2853 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2854 recon_variance =
2855 vp9_high_get_sby_perpixel_variance(cpi, &xd->plane[0].dst, bsize, xd->bd);
2856 } else {
2857 recon_variance =
2858 vp9_get_sby_perpixel_variance(cpi, &xd->plane[0].dst, bsize);
2859 }
2860 #else
2861 recon_variance =
2862 vp9_get_sby_perpixel_variance(cpi, &xd->plane[0].dst, bsize);
2863 #endif // CONFIG_VP9_HIGHBITDEPTH
2864
2865 if ((source_variance + recon_variance) > LOW_VAR_THRESH) {
2866 absvar_diff = (source_variance > recon_variance)
2867 ? (source_variance - recon_variance)
2868 : (recon_variance - source_variance);
2869
2870 var_error = (200 * source_variance * recon_variance) /
2871 ((source_variance * source_variance) +
2872 (recon_variance * recon_variance));
2873 var_error = 100 - var_error;
2874 }
2875
2876 // Source variance above a threshold and ref frame is intra.
2877 // This case is targeted mainly at discouraging intra modes that give rise
2878 // to a predictor with a low spatial complexity compared to the source.
2879 if ((source_variance > LOW_VAR_THRESH) && (ref_frame == INTRA_FRAME) &&
2880 (source_variance > recon_variance)) {
2881 var_factor = MIN(absvar_diff, MIN(VLOW_ADJ_MAX, var_error));
2882 // A second possible case of interest is where the source variance
2883 // is very low and we wish to discourage false texture or motion trails.
2884 } else if ((source_variance < (LOW_VAR_THRESH >> 1)) &&
2885 (recon_variance > source_variance)) {
2886 var_factor = MIN(absvar_diff, MIN(VHIGH_ADJ_MAX, var_error));
2887 }
2888 *this_rd += (*this_rd * var_factor) / 100;
2889 }
2890
2834 void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, 2891 void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi,
2835 TileDataEnc *tile_data, 2892 TileDataEnc *tile_data,
2836 MACROBLOCK *x, 2893 MACROBLOCK *x,
2837 int mi_row, int mi_col, 2894 int mi_row, int mi_col,
2838 RD_COST *rd_cost, BLOCK_SIZE bsize, 2895 RD_COST *rd_cost, BLOCK_SIZE bsize,
2839 PICK_MODE_CONTEXT *ctx, 2896 PICK_MODE_CONTEXT *ctx,
2840 int64_t best_rd_so_far) { 2897 int64_t best_rd_so_far) {
2841 VP9_COMMON *const cm = &cpi->common; 2898 VP9_COMMON *const cm = &cpi->common;
2842 TileInfo *const tile_info = &tile_data->tile_info; 2899 TileInfo *const tile_info = &tile_data->tile_info;
2843 RD_OPT *const rd_opt = &cpi->rd; 2900 RD_OPT *const rd_opt = &cpi->rd;
2844 SPEED_FEATURES *const sf = &cpi->sf; 2901 SPEED_FEATURES *const sf = &cpi->sf;
2845 MACROBLOCKD *const xd = &x->e_mbd; 2902 MACROBLOCKD *const xd = &x->e_mbd;
2846 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 2903 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
2847 const struct segmentation *const seg = &cm->seg; 2904 const struct segmentation *const seg = &cm->seg;
2848 PREDICTION_MODE this_mode; 2905 PREDICTION_MODE this_mode;
2849 MV_REFERENCE_FRAME ref_frame, second_ref_frame; 2906 MV_REFERENCE_FRAME ref_frame, second_ref_frame;
2850 unsigned char segment_id = mbmi->segment_id; 2907 unsigned char segment_id = mbmi->segment_id;
2851 int comp_pred, i, k; 2908 int comp_pred, i, k;
2852 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 2909 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
2853 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; 2910 struct buf_2d yv12_mb[4][MAX_MB_PLANE];
2854 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; 2911 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } };
2855 INTERP_FILTER single_inter_filter[MB_MODE_COUNT][MAX_REF_FRAMES]; 2912 INTERP_FILTER single_inter_filter[MB_MODE_COUNT][MAX_REF_FRAMES];
2856 int single_skippable[MB_MODE_COUNT][MAX_REF_FRAMES]; 2913 int single_skippable[MB_MODE_COUNT][MAX_REF_FRAMES];
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl) 3142 int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl)
3086 + get_chessboard_index(cm->current_video_frame)) & 0x1; 3143 + get_chessboard_index(cm->current_video_frame)) & 0x1;
3087 MB_MODE_INFO *ref_mbmi; 3144 MB_MODE_INFO *ref_mbmi;
3088 int const_motion = 1; 3145 int const_motion = 1;
3089 int skip_ref_frame = !cb_partition_search_ctrl; 3146 int skip_ref_frame = !cb_partition_search_ctrl;
3090 MV_REFERENCE_FRAME rf = NONE; 3147 MV_REFERENCE_FRAME rf = NONE;
3091 int_mv ref_mv; 3148 int_mv ref_mv;
3092 ref_mv.as_int = INVALID_MV; 3149 ref_mv.as_int = INVALID_MV;
3093 3150
3094 if ((mi_row - 1) >= tile_info->mi_row_start) { 3151 if ((mi_row - 1) >= tile_info->mi_row_start) {
3095 ref_mv = xd->mi[-xd->mi_stride].src_mi->mbmi.mv[0]; 3152 ref_mv = xd->mi[-xd->mi_stride]->mbmi.mv[0];
3096 rf = xd->mi[-xd->mi_stride].src_mi->mbmi.ref_frame[0]; 3153 rf = xd->mi[-xd->mi_stride]->mbmi.ref_frame[0];
3097 for (i = 0; i < mi_width; ++i) { 3154 for (i = 0; i < mi_width; ++i) {
3098 ref_mbmi = &xd->mi[-xd->mi_stride + i].src_mi->mbmi; 3155 ref_mbmi = &xd->mi[-xd->mi_stride + i]->mbmi;
3099 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && 3156 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) &&
3100 (ref_frame == ref_mbmi->ref_frame[0]); 3157 (ref_frame == ref_mbmi->ref_frame[0]);
3101 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); 3158 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]);
3102 } 3159 }
3103 } 3160 }
3104 3161
3105 if ((mi_col - 1) >= tile_info->mi_col_start) { 3162 if ((mi_col - 1) >= tile_info->mi_col_start) {
3106 if (ref_mv.as_int == INVALID_MV) 3163 if (ref_mv.as_int == INVALID_MV)
3107 ref_mv = xd->mi[-1].src_mi->mbmi.mv[0]; 3164 ref_mv = xd->mi[-1]->mbmi.mv[0];
3108 if (rf == NONE) 3165 if (rf == NONE)
3109 rf = xd->mi[-1].src_mi->mbmi.ref_frame[0]; 3166 rf = xd->mi[-1]->mbmi.ref_frame[0];
3110 for (i = 0; i < mi_height; ++i) { 3167 for (i = 0; i < mi_height; ++i) {
3111 ref_mbmi = &xd->mi[i * xd->mi_stride - 1].src_mi->mbmi; 3168 ref_mbmi = &xd->mi[i * xd->mi_stride - 1]->mbmi;
3112 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && 3169 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) &&
3113 (ref_frame == ref_mbmi->ref_frame[0]); 3170 (ref_frame == ref_mbmi->ref_frame[0]);
3114 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); 3171 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]);
3115 } 3172 }
3116 } 3173 }
3117 3174
3118 if (skip_ref_frame && this_mode != NEARESTMV && this_mode != NEWMV) 3175 if (skip_ref_frame && this_mode != NEARESTMV && this_mode != NEWMV)
3119 if (rf > INTRA_FRAME) 3176 if (rf > INTRA_FRAME)
3120 if (ref_frame != rf) 3177 if (ref_frame != rf)
3121 continue; 3178 continue;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3201 if (comp_pred) 3258 if (comp_pred)
3202 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; 3259 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
3203 } 3260 }
3204 3261
3205 for (i = 0; i < TX_MODES; ++i) 3262 for (i = 0; i < TX_MODES; ++i)
3206 tx_cache[i] = INT64_MAX; 3263 tx_cache[i] = INT64_MAX;
3207 3264
3208 if (ref_frame == INTRA_FRAME) { 3265 if (ref_frame == INTRA_FRAME) {
3209 TX_SIZE uv_tx; 3266 TX_SIZE uv_tx;
3210 struct macroblockd_plane *const pd = &xd->plane[1]; 3267 struct macroblockd_plane *const pd = &xd->plane[1];
3211 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); 3268 memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
3212 super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, 3269 super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable,
3213 NULL, bsize, tx_cache, best_rd); 3270 NULL, bsize, tx_cache, best_rd);
3214 if (rate_y == INT_MAX) 3271 if (rate_y == INT_MAX)
3215 continue; 3272 continue;
3216 3273
3217 uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize, pd->subsampling_x, 3274 uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize, pd->subsampling_x,
3218 pd->subsampling_y); 3275 pd->subsampling_y);
3219 if (rate_uv_intra[uv_tx] == INT_MAX) { 3276 if (rate_uv_intra[uv_tx] == INT_MAX) {
3220 choose_intra_uv_mode(cpi, x, ctx, bsize, uv_tx, 3277 choose_intra_uv_mode(cpi, x, ctx, bsize, uv_tx,
3221 &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx], 3278 &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx],
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3280 } 3337 }
3281 } else { 3338 } else {
3282 // Add in the cost of the no skip flag. 3339 // Add in the cost of the no skip flag.
3283 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); 3340 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
3284 } 3341 }
3285 3342
3286 // Calculate the final RD estimate for this mode. 3343 // Calculate the final RD estimate for this mode.
3287 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 3344 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
3288 } 3345 }
3289 3346
3347 // Apply an adjustment to the rd value based on the similarity of the
3348 // source variance and reconstructed variance.
3349 rd_variance_adjustment(cpi, x, bsize, &this_rd,
3350 ref_frame, x->source_variance);
3351
3290 if (ref_frame == INTRA_FRAME) { 3352 if (ref_frame == INTRA_FRAME) {
3291 // Keep record of best intra rd 3353 // Keep record of best intra rd
3292 if (this_rd < best_intra_rd) { 3354 if (this_rd < best_intra_rd) {
3293 best_intra_rd = this_rd; 3355 best_intra_rd = this_rd;
3294 best_intra_mode = mbmi->mode; 3356 best_intra_mode = mbmi->mode;
3295 } 3357 }
3296 } 3358 }
3297 3359
3298 if (!disable_skip && ref_frame == INTRA_FRAME) { 3360 if (!disable_skip && ref_frame == INTRA_FRAME) {
3299 for (i = 0; i < REFERENCE_MODES; ++i) 3361 for (i = 0; i < REFERENCE_MODES; ++i)
(...skipping 20 matching lines...) Expand all
3320 rd_cost->rate = rate2; 3382 rd_cost->rate = rate2;
3321 rd_cost->dist = distortion2; 3383 rd_cost->dist = distortion2;
3322 rd_cost->rdcost = this_rd; 3384 rd_cost->rdcost = this_rd;
3323 best_rd = this_rd; 3385 best_rd = this_rd;
3324 best_mbmode = *mbmi; 3386 best_mbmode = *mbmi;
3325 best_skip2 = this_skip2; 3387 best_skip2 = this_skip2;
3326 best_mode_skippable = skippable; 3388 best_mode_skippable = skippable;
3327 3389
3328 if (!x->select_tx_size) 3390 if (!x->select_tx_size)
3329 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); 3391 swap_block_ptr(x, ctx, 1, 0, 0, max_plane);
3330 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], 3392 memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size],
3331 sizeof(uint8_t) * ctx->num_4x4_blk); 3393 sizeof(uint8_t) * ctx->num_4x4_blk);
3332 3394
3333 // TODO(debargha): enhance this test with a better distortion prediction 3395 // TODO(debargha): enhance this test with a better distortion prediction
3334 // based on qp, activity mask and history 3396 // based on qp, activity mask and history
3335 if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) && 3397 if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) &&
3336 (mode_index > MIN_EARLY_TERM_INDEX)) { 3398 (mode_index > MIN_EARLY_TERM_INDEX)) {
3337 int qstep = xd->plane[0].dequant[1]; 3399 int qstep = xd->plane[0].dequant[1];
3338 // TODO(debargha): Enhance this by specializing for each mode_index 3400 // TODO(debargha): Enhance this by specializing for each mode_index
3339 int scale = 4; 3401 int scale = 4;
3340 #if CONFIG_VP9_HIGHBITDEPTH 3402 #if CONFIG_VP9_HIGHBITDEPTH
3341 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 3403 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
3510 vp9_zero(best_tx_diff); 3572 vp9_zero(best_tx_diff);
3511 } 3573 }
3512 3574
3513 // TODO(yunqingwang): Moving this line in front of the above best_filter_diff 3575 // TODO(yunqingwang): Moving this line in front of the above best_filter_diff
3514 // updating code causes PSNR loss. Need to figure out the confliction. 3576 // updating code causes PSNR loss. Need to figure out the confliction.
3515 x->skip |= best_mode_skippable; 3577 x->skip |= best_mode_skippable;
3516 3578
3517 if (!x->skip && !x->select_tx_size) { 3579 if (!x->skip && !x->select_tx_size) {
3518 int has_high_freq_coeff = 0; 3580 int has_high_freq_coeff = 0;
3519 int plane; 3581 int plane;
3520 int max_plane = is_inter_block(&xd->mi[0].src_mi->mbmi) 3582 int max_plane = is_inter_block(&xd->mi[0]->mbmi)
3521 ? MAX_MB_PLANE : 1; 3583 ? MAX_MB_PLANE : 1;
3522 for (plane = 0; plane < max_plane; ++plane) { 3584 for (plane = 0; plane < max_plane; ++plane) {
3523 x->plane[plane].eobs = ctx->eobs_pbuf[plane][1]; 3585 x->plane[plane].eobs = ctx->eobs_pbuf[plane][1];
3524 has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane); 3586 has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane);
3525 } 3587 }
3526 3588
3527 for (plane = max_plane; plane < MAX_MB_PLANE; ++plane) { 3589 for (plane = max_plane; plane < MAX_MB_PLANE; ++plane) {
3528 x->plane[plane].eobs = ctx->eobs_pbuf[plane][2]; 3590 x->plane[plane].eobs = ctx->eobs_pbuf[plane][2];
3529 has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane); 3591 has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane);
3530 } 3592 }
3531 3593
3532 best_mode_skippable |= !has_high_freq_coeff; 3594 best_mode_skippable |= !has_high_freq_coeff;
3533 } 3595 }
3534 3596
3535 assert(best_mode_index >= 0); 3597 assert(best_mode_index >= 0);
3536 3598
3537 store_coding_context(x, ctx, best_mode_index, best_pred_diff, 3599 store_coding_context(x, ctx, best_mode_index, best_pred_diff,
3538 best_tx_diff, best_filter_diff, best_mode_skippable); 3600 best_tx_diff, best_filter_diff, best_mode_skippable);
3539 } 3601 }
3540 3602
3541 void vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi, 3603 void vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi,
3542 TileDataEnc *tile_data, 3604 TileDataEnc *tile_data,
3543 MACROBLOCK *x, 3605 MACROBLOCK *x,
3544 RD_COST *rd_cost, 3606 RD_COST *rd_cost,
3545 BLOCK_SIZE bsize, 3607 BLOCK_SIZE bsize,
3546 PICK_MODE_CONTEXT *ctx, 3608 PICK_MODE_CONTEXT *ctx,
3547 int64_t best_rd_so_far) { 3609 int64_t best_rd_so_far) {
3548 VP9_COMMON *const cm = &cpi->common; 3610 VP9_COMMON *const cm = &cpi->common;
3549 MACROBLOCKD *const xd = &x->e_mbd; 3611 MACROBLOCKD *const xd = &x->e_mbd;
3550 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 3612 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
3551 unsigned char segment_id = mbmi->segment_id; 3613 unsigned char segment_id = mbmi->segment_id;
3552 const int comp_pred = 0; 3614 const int comp_pred = 0;
3553 int i; 3615 int i;
3554 int64_t best_tx_diff[TX_MODES]; 3616 int64_t best_tx_diff[TX_MODES];
3555 int64_t best_pred_diff[REFERENCE_MODES]; 3617 int64_t best_pred_diff[REFERENCE_MODES];
3556 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; 3618 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
3557 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; 3619 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
3558 vp9_prob comp_mode_p; 3620 vp9_prob comp_mode_p;
3559 INTERP_FILTER best_filter = SWITCHABLE; 3621 INTERP_FILTER best_filter = SWITCHABLE;
3560 int64_t this_rd = INT64_MAX; 3622 int64_t this_rd = INT64_MAX;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
3646 int mi_row, int mi_col, 3708 int mi_row, int mi_col,
3647 RD_COST *rd_cost, 3709 RD_COST *rd_cost,
3648 BLOCK_SIZE bsize, 3710 BLOCK_SIZE bsize,
3649 PICK_MODE_CONTEXT *ctx, 3711 PICK_MODE_CONTEXT *ctx,
3650 int64_t best_rd_so_far) { 3712 int64_t best_rd_so_far) {
3651 VP9_COMMON *const cm = &cpi->common; 3713 VP9_COMMON *const cm = &cpi->common;
3652 TileInfo *const tile_info = &tile_data->tile_info; 3714 TileInfo *const tile_info = &tile_data->tile_info;
3653 RD_OPT *const rd_opt = &cpi->rd; 3715 RD_OPT *const rd_opt = &cpi->rd;
3654 SPEED_FEATURES *const sf = &cpi->sf; 3716 SPEED_FEATURES *const sf = &cpi->sf;
3655 MACROBLOCKD *const xd = &x->e_mbd; 3717 MACROBLOCKD *const xd = &x->e_mbd;
3656 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 3718 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
3657 const struct segmentation *const seg = &cm->seg; 3719 const struct segmentation *const seg = &cm->seg;
3658 MV_REFERENCE_FRAME ref_frame, second_ref_frame; 3720 MV_REFERENCE_FRAME ref_frame, second_ref_frame;
3659 unsigned char segment_id = mbmi->segment_id; 3721 unsigned char segment_id = mbmi->segment_id;
3660 int comp_pred, i; 3722 int comp_pred, i;
3661 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 3723 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
3662 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; 3724 struct buf_2d yv12_mb[4][MAX_MB_PLANE];
3663 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 3725 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
3664 VP9_ALT_FLAG }; 3726 VP9_ALT_FLAG };
3665 int64_t best_rd = best_rd_so_far; 3727 int64_t best_rd = best_rd_so_far;
3666 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise 3728 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise
(...skipping 14 matching lines...) Expand all
3681 const int intra_cost_penalty = vp9_get_intra_cost_penalty( 3743 const int intra_cost_penalty = vp9_get_intra_cost_penalty(
3682 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth); 3744 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth);
3683 int_mv seg_mvs[4][MAX_REF_FRAMES]; 3745 int_mv seg_mvs[4][MAX_REF_FRAMES];
3684 b_mode_info best_bmodes[4]; 3746 b_mode_info best_bmodes[4];
3685 int best_skip2 = 0; 3747 int best_skip2 = 0;
3686 int ref_frame_skip_mask[2] = { 0 }; 3748 int ref_frame_skip_mask[2] = { 0 };
3687 int64_t mask_filter = 0; 3749 int64_t mask_filter = 0;
3688 int64_t filter_cache[SWITCHABLE_FILTER_CONTEXTS]; 3750 int64_t filter_cache[SWITCHABLE_FILTER_CONTEXTS];
3689 3751
3690 x->skip_encode = sf->skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; 3752 x->skip_encode = sf->skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
3691 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); 3753 memset(x->zcoeff_blk[TX_4X4], 0, 4);
3692 vp9_zero(best_mbmode); 3754 vp9_zero(best_mbmode);
3693 3755
3694 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) 3756 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
3695 filter_cache[i] = INT64_MAX; 3757 filter_cache[i] = INT64_MAX;
3696 3758
3697 for (i = 0; i < 4; i++) { 3759 for (i = 0; i < 4; i++) {
3698 int j; 3760 int j;
3699 for (j = 0; j < MAX_REF_FRAMES; j++) 3761 for (j = 0; j < MAX_REF_FRAMES; j++)
3700 seg_mvs[i][j].as_int = INVALID_MV; 3762 seg_mvs[i][j].as_int = INVALID_MV;
3701 } 3763 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3937 (mbmi->interp_filter == cm->interp_filter && 3999 (mbmi->interp_filter == cm->interp_filter &&
3938 cm->interp_filter != SWITCHABLE)) { 4000 cm->interp_filter != SWITCHABLE)) {
3939 tmp_best_rdu = tmp_rd; 4001 tmp_best_rdu = tmp_rd;
3940 tmp_best_rate = rate; 4002 tmp_best_rate = rate;
3941 tmp_best_ratey = rate_y; 4003 tmp_best_ratey = rate_y;
3942 tmp_best_distortion = distortion; 4004 tmp_best_distortion = distortion;
3943 tmp_best_sse = total_sse; 4005 tmp_best_sse = total_sse;
3944 tmp_best_skippable = skippable; 4006 tmp_best_skippable = skippable;
3945 tmp_best_mbmode = *mbmi; 4007 tmp_best_mbmode = *mbmi;
3946 for (i = 0; i < 4; i++) { 4008 for (i = 0; i < 4; i++) {
3947 tmp_best_bmodes[i] = xd->mi[0].src_mi->bmi[i]; 4009 tmp_best_bmodes[i] = xd->mi[0]->bmi[i];
3948 x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i]; 4010 x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i];
3949 } 4011 }
3950 pred_exists = 1; 4012 pred_exists = 1;
3951 if (switchable_filter_index == 0 && 4013 if (switchable_filter_index == 0 &&
3952 sf->use_rd_breakout && 4014 sf->use_rd_breakout &&
3953 best_rd < INT64_MAX) { 4015 best_rd < INT64_MAX) {
3954 if (tmp_best_rdu / 2 > best_rd) { 4016 if (tmp_best_rdu / 2 > best_rd) {
3955 // skip searching the other filters if the first is 4017 // skip searching the other filters if the first is
3956 // already substantially larger than the best so far 4018 // already substantially larger than the best so far
3957 tmp_best_filter = mbmi->interp_filter; 4019 tmp_best_filter = mbmi->interp_filter;
(...skipping 23 matching lines...) Expand all
3981 if (tmp_rd == INT64_MAX) 4043 if (tmp_rd == INT64_MAX)
3982 continue; 4044 continue;
3983 } else { 4045 } else {
3984 total_sse = tmp_best_sse; 4046 total_sse = tmp_best_sse;
3985 rate = tmp_best_rate; 4047 rate = tmp_best_rate;
3986 rate_y = tmp_best_ratey; 4048 rate_y = tmp_best_ratey;
3987 distortion = tmp_best_distortion; 4049 distortion = tmp_best_distortion;
3988 skippable = tmp_best_skippable; 4050 skippable = tmp_best_skippable;
3989 *mbmi = tmp_best_mbmode; 4051 *mbmi = tmp_best_mbmode;
3990 for (i = 0; i < 4; i++) 4052 for (i = 0; i < 4; i++)
3991 xd->mi[0].src_mi->bmi[i] = tmp_best_bmodes[i]; 4053 xd->mi[0]->bmi[i] = tmp_best_bmodes[i];
3992 } 4054 }
3993 4055
3994 rate2 += rate; 4056 rate2 += rate;
3995 distortion2 += distortion; 4057 distortion2 += distortion;
3996 4058
3997 if (cm->interp_filter == SWITCHABLE) 4059 if (cm->interp_filter == SWITCHABLE)
3998 rate2 += vp9_get_switchable_rate(cpi, xd); 4060 rate2 += vp9_get_switchable_rate(cpi, xd);
3999 4061
4000 if (!mode_excluded) 4062 if (!mode_excluded)
4001 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE 4063 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE
4002 : cm->reference_mode == COMPOUND_REFERENCE; 4064 : cm->reference_mode == COMPOUND_REFERENCE;
4003 4065
4004 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); 4066 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred);
4005 4067
4006 tmp_best_rdu = best_rd - 4068 tmp_best_rdu = best_rd -
4007 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), 4069 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2),
4008 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); 4070 RDCOST(x->rdmult, x->rddiv, 0, total_sse));
4009 4071
4010 if (tmp_best_rdu > 0) { 4072 if (tmp_best_rdu > 0) {
4011 // If even the 'Y' rd value of split is higher than best so far 4073 // If even the 'Y' rd value of split is higher than best so far
4012 // then dont bother looking at UV 4074 // then dont bother looking at UV
4013 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, 4075 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col,
4014 BLOCK_8X8); 4076 BLOCK_8X8);
4015 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); 4077 memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
4016 if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, 4078 if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
4017 &uv_sse, BLOCK_8X8, tmp_best_rdu)) 4079 &uv_sse, BLOCK_8X8, tmp_best_rdu))
4018 continue; 4080 continue;
4019 4081
4020 rate2 += rate_uv; 4082 rate2 += rate_uv;
4021 distortion2 += distortion_uv; 4083 distortion2 += distortion_uv;
4022 skippable = skippable && uv_skippable; 4084 skippable = skippable && uv_skippable;
4023 total_sse += uv_sse; 4085 total_sse += uv_sse;
4024 } 4086 }
4025 } 4087 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
4086 rd_cost->rate = rate2; 4148 rd_cost->rate = rate2;
4087 rd_cost->dist = distortion2; 4149 rd_cost->dist = distortion2;
4088 rd_cost->rdcost = this_rd; 4150 rd_cost->rdcost = this_rd;
4089 best_rd = this_rd; 4151 best_rd = this_rd;
4090 best_yrd = best_rd - 4152 best_yrd = best_rd -
4091 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); 4153 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv);
4092 best_mbmode = *mbmi; 4154 best_mbmode = *mbmi;
4093 best_skip2 = this_skip2; 4155 best_skip2 = this_skip2;
4094 if (!x->select_tx_size) 4156 if (!x->select_tx_size)
4095 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); 4157 swap_block_ptr(x, ctx, 1, 0, 0, max_plane);
4096 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4], 4158 memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4],
4097 sizeof(uint8_t) * ctx->num_4x4_blk); 4159 sizeof(uint8_t) * ctx->num_4x4_blk);
4098 4160
4099 for (i = 0; i < 4; i++) 4161 for (i = 0; i < 4; i++)
4100 best_bmodes[i] = xd->mi[0].src_mi->bmi[i]; 4162 best_bmodes[i] = xd->mi[0]->bmi[i];
4101 4163
4102 // TODO(debargha): enhance this test with a better distortion prediction 4164 // TODO(debargha): enhance this test with a better distortion prediction
4103 // based on qp, activity mask and history 4165 // based on qp, activity mask and history
4104 if ((sf->mode_search_skip_flags & FLAG_EARLY_TERMINATE) && 4166 if ((sf->mode_search_skip_flags & FLAG_EARLY_TERMINATE) &&
4105 (ref_index > MIN_EARLY_TERM_INDEX)) { 4167 (ref_index > MIN_EARLY_TERM_INDEX)) {
4106 int qstep = xd->plane[0].dequant[1]; 4168 int qstep = xd->plane[0].dequant[1];
4107 // TODO(debargha): Enhance this by specializing for each mode_index 4169 // TODO(debargha): Enhance this by specializing for each mode_index
4108 int scale = 4; 4170 int scale = 4;
4109 #if CONFIG_VP9_HIGHBITDEPTH 4171 #if CONFIG_VP9_HIGHBITDEPTH
4110 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 4172 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
4208 !is_inter_block(&best_mbmode)); 4270 !is_inter_block(&best_mbmode));
4209 4271
4210 vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact, 4272 vp9_update_rd_thresh_fact(tile_data->thresh_freq_fact,
4211 sf->adaptive_rd_thresh, bsize, best_ref_index); 4273 sf->adaptive_rd_thresh, bsize, best_ref_index);
4212 4274
4213 // macroblock modes 4275 // macroblock modes
4214 *mbmi = best_mbmode; 4276 *mbmi = best_mbmode;
4215 x->skip |= best_skip2; 4277 x->skip |= best_skip2;
4216 if (!is_inter_block(&best_mbmode)) { 4278 if (!is_inter_block(&best_mbmode)) {
4217 for (i = 0; i < 4; i++) 4279 for (i = 0; i < 4; i++)
4218 xd->mi[0].src_mi->bmi[i].as_mode = best_bmodes[i].as_mode; 4280 xd->mi[0]->bmi[i].as_mode = best_bmodes[i].as_mode;
4219 } else { 4281 } else {
4220 for (i = 0; i < 4; ++i) 4282 for (i = 0; i < 4; ++i)
4221 vpx_memcpy(&xd->mi[0].src_mi->bmi[i], &best_bmodes[i], 4283 memcpy(&xd->mi[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info));
4222 sizeof(b_mode_info));
4223 4284
4224 mbmi->mv[0].as_int = xd->mi[0].src_mi->bmi[3].as_mv[0].as_int; 4285 mbmi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int;
4225 mbmi->mv[1].as_int = xd->mi[0].src_mi->bmi[3].as_mv[1].as_int; 4286 mbmi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int;
4226 } 4287 }
4227 4288
4228 for (i = 0; i < REFERENCE_MODES; ++i) { 4289 for (i = 0; i < REFERENCE_MODES; ++i) {
4229 if (best_pred_rd[i] == INT64_MAX) 4290 if (best_pred_rd[i] == INT64_MAX)
4230 best_pred_diff[i] = INT_MIN; 4291 best_pred_diff[i] = INT_MIN;
4231 else 4292 else
4232 best_pred_diff[i] = best_rd - best_pred_rd[i]; 4293 best_pred_diff[i] = best_rd - best_pred_rd[i];
4233 } 4294 }
4234 4295
4235 if (!x->skip) { 4296 if (!x->skip) {
4236 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { 4297 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
4237 if (best_filter_rd[i] == INT64_MAX) 4298 if (best_filter_rd[i] == INT64_MAX)
4238 best_filter_diff[i] = 0; 4299 best_filter_diff[i] = 0;
4239 else 4300 else
4240 best_filter_diff[i] = best_rd - best_filter_rd[i]; 4301 best_filter_diff[i] = best_rd - best_filter_rd[i];
4241 } 4302 }
4242 if (cm->interp_filter == SWITCHABLE) 4303 if (cm->interp_filter == SWITCHABLE)
4243 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); 4304 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0);
4244 } else { 4305 } else {
4245 vp9_zero(best_filter_diff); 4306 vp9_zero(best_filter_diff);
4246 } 4307 }
4247 4308
4248 store_coding_context(x, ctx, best_ref_index, 4309 store_coding_context(x, ctx, best_ref_index,
4249 best_pred_diff, best_tx_diff, best_filter_diff, 0); 4310 best_pred_diff, best_tx_diff, best_filter_diff, 0);
4250 } 4311 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rdopt.h ('k') | source/libvpx/vp9/encoder/vp9_sad.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698