| OLD | NEW |
| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 typedef struct { | 49 typedef struct { |
| 50 MB_PREDICTION_MODE mode; | 50 MB_PREDICTION_MODE mode; |
| 51 MV_REFERENCE_FRAME ref_frame[2]; | 51 MV_REFERENCE_FRAME ref_frame[2]; |
| 52 } MODE_DEFINITION; | 52 } MODE_DEFINITION; |
| 53 | 53 |
| 54 typedef struct { | 54 typedef struct { |
| 55 MV_REFERENCE_FRAME ref_frame[2]; | 55 MV_REFERENCE_FRAME ref_frame[2]; |
| 56 } REF_DEFINITION; | 56 } REF_DEFINITION; |
| 57 | 57 |
| 58 struct rdcost_block_args { |
| 59 MACROBLOCK *x; |
| 60 ENTROPY_CONTEXT t_above[16]; |
| 61 ENTROPY_CONTEXT t_left[16]; |
| 62 int rate; |
| 63 int64_t dist; |
| 64 int64_t sse; |
| 65 int this_rate; |
| 66 int64_t this_dist; |
| 67 int64_t this_sse; |
| 68 int64_t this_rd; |
| 69 int64_t best_rd; |
| 70 int skip; |
| 71 const scan_order *so; |
| 72 }; |
| 73 |
| 58 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { | 74 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { |
| 59 {NEARESTMV, {LAST_FRAME, NONE}}, | 75 {NEARESTMV, {LAST_FRAME, NONE}}, |
| 60 {NEARESTMV, {ALTREF_FRAME, NONE}}, | 76 {NEARESTMV, {ALTREF_FRAME, NONE}}, |
| 61 {NEARESTMV, {GOLDEN_FRAME, NONE}}, | 77 {NEARESTMV, {GOLDEN_FRAME, NONE}}, |
| 62 | 78 |
| 63 {DC_PRED, {INTRA_FRAME, NONE}}, | 79 {DC_PRED, {INTRA_FRAME, NONE}}, |
| 64 | 80 |
| 65 {NEWMV, {LAST_FRAME, NONE}}, | 81 {NEWMV, {LAST_FRAME, NONE}}, |
| 66 {NEWMV, {ALTREF_FRAME, NONE}}, | 82 {NEWMV, {ALTREF_FRAME, NONE}}, |
| 67 {NEWMV, {GOLDEN_FRAME, NONE}}, | 83 {NEWMV, {GOLDEN_FRAME, NONE}}, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 278 |
| 263 // Further tests required to see if optimum is different | 279 // Further tests required to see if optimum is different |
| 264 // for key frames, golden frames and arf frames. | 280 // for key frames, golden frames and arf frames. |
| 265 // if (cpi->common.refresh_golden_frame || | 281 // if (cpi->common.refresh_golden_frame || |
| 266 // cpi->common.refresh_alt_ref_frame) | 282 // cpi->common.refresh_alt_ref_frame) |
| 267 qindex = clamp(cm->base_qindex + cm->y_dc_delta_q, 0, MAXQ); | 283 qindex = clamp(cm->base_qindex + cm->y_dc_delta_q, 0, MAXQ); |
| 268 | 284 |
| 269 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) | 285 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) |
| 270 cpi->RDMULT = vp9_compute_rd_mult(cpi, qindex); | 286 cpi->RDMULT = vp9_compute_rd_mult(cpi, qindex); |
| 271 | 287 |
| 272 x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO + (x->errorperbit == 0); | 288 x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO; |
| 289 x->errorperbit += (x->errorperbit == 0); |
| 273 | 290 |
| 274 vp9_set_speed_features(cpi); | 291 vp9_set_speed_features(cpi); |
| 275 | 292 |
| 276 x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && | 293 x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && |
| 277 cm->frame_type != KEY_FRAME) ? 0 : 1; | 294 cm->frame_type != KEY_FRAME) ? 0 : 1; |
| 278 | 295 |
| 279 set_block_thresholds(cpi); | 296 set_block_thresholds(cpi); |
| 280 | 297 |
| 281 fill_token_costs(x->token_costs, cm->fc.coef_probs); | 298 fill_token_costs(x->token_costs, cm->fc.coef_probs); |
| 282 | 299 |
| 283 for (i = 0; i < PARTITION_CONTEXTS; i++) | 300 if (!cpi->sf.use_pick_mode) { |
| 284 vp9_cost_tokens(x->partition_cost[i], get_partition_probs(cm, i), | 301 for (i = 0; i < PARTITION_CONTEXTS; i++) |
| 285 vp9_partition_tree); | 302 vp9_cost_tokens(x->partition_cost[i], get_partition_probs(cm, i), |
| 303 vp9_partition_tree); |
| 286 | 304 |
| 287 fill_mode_costs(cpi); | 305 fill_mode_costs(cpi); |
| 288 | 306 |
| 289 if (!frame_is_intra_only(cm)) { | 307 if (!frame_is_intra_only(cm)) { |
| 290 vp9_build_nmv_cost_table(x->nmvjointcost, | 308 vp9_build_nmv_cost_table(x->nmvjointcost, |
| 291 cm->allow_high_precision_mv ? x->nmvcost_hp | 309 cm->allow_high_precision_mv ? x->nmvcost_hp |
| 292 : x->nmvcost, | 310 : x->nmvcost, |
| 293 &cm->fc.nmvc, | 311 &cm->fc.nmvc, |
| 294 cm->allow_high_precision_mv, 1, 1); | 312 cm->allow_high_precision_mv, 1, 1); |
| 295 | 313 |
| 296 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) | 314 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) |
| 297 vp9_cost_tokens((int *)x->inter_mode_cost[i], | 315 vp9_cost_tokens((int *)x->inter_mode_cost[i], |
| 298 cm->fc.inter_mode_probs[i], vp9_inter_mode_tree); | 316 cm->fc.inter_mode_probs[i], vp9_inter_mode_tree); |
| 317 } |
| 299 } | 318 } |
| 300 } | 319 } |
| 301 | 320 |
| 302 static const int MAX_XSQ_Q10 = 245727; | 321 static const int MAX_XSQ_Q10 = 245727; |
| 303 | 322 |
| 304 static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { | 323 static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { |
| 305 // NOTE: The tables below must be of the same size | 324 // NOTE: The tables below must be of the same size |
| 306 | 325 |
| 307 // The functions described below are sampled at the four most significant | 326 // The functions described below are sampled at the four most significant |
| 308 // bits of x^2 + 8 / 256 | 327 // bits of x^2 + 8 / 256 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // Hence quantizer step is also 8 times. To get effective quantizer | 431 // Hence quantizer step is also 8 times. To get effective quantizer |
| 413 // we need to divide by 8 before sending to modeling function. | 432 // we need to divide by 8 before sending to modeling function. |
| 414 int i, rate_sum = 0, dist_sum = 0; | 433 int i, rate_sum = 0, dist_sum = 0; |
| 415 int ref = xd->mi_8x8[0]->mbmi.ref_frame[0]; | 434 int ref = xd->mi_8x8[0]->mbmi.ref_frame[0]; |
| 416 unsigned int sse; | 435 unsigned int sse; |
| 417 | 436 |
| 418 for (i = 0; i < MAX_MB_PLANE; ++i) { | 437 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 419 struct macroblock_plane *const p = &x->plane[i]; | 438 struct macroblock_plane *const p = &x->plane[i]; |
| 420 struct macroblockd_plane *const pd = &xd->plane[i]; | 439 struct macroblockd_plane *const pd = &xd->plane[i]; |
| 421 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); | 440 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); |
| 441 |
| 422 (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, | 442 (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, |
| 423 pd->dst.buf, pd->dst.stride, &sse); | 443 pd->dst.buf, pd->dst.stride, &sse); |
| 444 |
| 424 if (i == 0) | 445 if (i == 0) |
| 425 x->pred_sse[ref] = sse; | 446 x->pred_sse[ref] = sse; |
| 426 | 447 if (cpi->sf.use_pick_mode) { |
| 427 dist_sum += (int)sse; | 448 dist_sum += (int)sse; |
| 449 } else { |
| 450 int rate; |
| 451 int64_t dist; |
| 452 model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs], |
| 453 pd->dequant[1] >> 3, &rate, &dist); |
| 454 rate_sum += rate; |
| 455 dist_sum += (int)dist; |
| 456 } |
| 428 } | 457 } |
| 429 | 458 |
| 430 *out_rate_sum = rate_sum; | 459 *out_rate_sum = rate_sum; |
| 431 *out_dist_sum = (int64_t)dist_sum << 4; | 460 *out_dist_sum = (int64_t)dist_sum << 4; |
| 432 } | 461 } |
| 433 | 462 |
| 434 static void model_rd_for_sb_y_tx(VP9_COMP *cpi, BLOCK_SIZE bsize, | 463 static void model_rd_for_sb_y_tx(VP9_COMP *cpi, BLOCK_SIZE bsize, |
| 435 TX_SIZE tx_size, | 464 TX_SIZE tx_size, |
| 436 MACROBLOCK *x, MACROBLOCKD *xd, | 465 MACROBLOCK *x, MACROBLOCKD *xd, |
| 437 int *out_rate_sum, int64_t *out_dist_sum, | 466 int *out_rate_sum, int64_t *out_dist_sum, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 cost += (*token_costs)[0][pt][EOB_TOKEN]; | 597 cost += (*token_costs)[0][pt][EOB_TOKEN]; |
| 569 } | 598 } |
| 570 } | 599 } |
| 571 | 600 |
| 572 // is eob first coefficient; | 601 // is eob first coefficient; |
| 573 *A = *L = (c > 0); | 602 *A = *L = (c > 0); |
| 574 | 603 |
| 575 return cost; | 604 return cost; |
| 576 } | 605 } |
| 577 | 606 |
| 578 static void dist_block(int plane, int block, TX_SIZE tx_size, void *arg) { | 607 static void dist_block(int plane, int block, TX_SIZE tx_size, |
| 608 struct rdcost_block_args* args) { |
| 579 const int ss_txfrm_size = tx_size << 1; | 609 const int ss_txfrm_size = tx_size << 1; |
| 580 struct rdcost_block_args* args = arg; | |
| 581 MACROBLOCK* const x = args->x; | 610 MACROBLOCK* const x = args->x; |
| 582 MACROBLOCKD* const xd = &x->e_mbd; | 611 MACROBLOCKD* const xd = &x->e_mbd; |
| 583 struct macroblock_plane *const p = &x->plane[plane]; | 612 struct macroblock_plane *const p = &x->plane[plane]; |
| 584 struct macroblockd_plane *const pd = &xd->plane[plane]; | 613 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 585 int64_t this_sse; | 614 int64_t this_sse; |
| 586 int shift = args->tx_size == TX_32X32 ? 0 : 2; | 615 int shift = tx_size == TX_32X32 ? 0 : 2; |
| 587 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); | 616 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
| 588 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); | 617 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 589 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, | 618 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, |
| 590 &this_sse) >> shift; | 619 &this_sse) >> shift; |
| 591 args->sse = this_sse >> shift; | 620 args->sse = this_sse >> shift; |
| 592 | 621 |
| 593 if (x->skip_encode && !is_inter_block(&xd->mi_8x8[0]->mbmi)) { | 622 if (x->skip_encode && !is_inter_block(&xd->mi_8x8[0]->mbmi)) { |
| 594 // TODO(jingning): tune the model to better capture the distortion. | 623 // TODO(jingning): tune the model to better capture the distortion. |
| 595 int64_t p = (pd->dequant[1] * pd->dequant[1] * | 624 int64_t p = (pd->dequant[1] * pd->dequant[1] * |
| 596 (1 << ss_txfrm_size)) >> (shift + 2); | 625 (1 << ss_txfrm_size)) >> (shift + 2); |
| 597 args->dist += (p >> 4); | 626 args->dist += (p >> 4); |
| 598 args->sse += p; | 627 args->sse += p; |
| 599 } | 628 } |
| 600 } | 629 } |
| 601 | 630 |
| 602 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, | 631 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, |
| 603 TX_SIZE tx_size, void *arg) { | 632 TX_SIZE tx_size, struct rdcost_block_args* args) { |
| 604 struct rdcost_block_args* args = arg; | |
| 605 | |
| 606 int x_idx, y_idx; | 633 int x_idx, y_idx; |
| 607 txfrm_block_to_raster_xy(plane_bsize, args->tx_size, block, &x_idx, &y_idx); | 634 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx); |
| 608 | 635 |
| 609 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, | 636 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, |
| 610 args->t_left + y_idx, args->tx_size, | 637 args->t_left + y_idx, tx_size, |
| 611 args->scan, args->nb); | 638 args->so->scan, args->so->neighbors); |
| 612 } | 639 } |
| 613 | 640 |
| 614 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, | 641 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, |
| 615 TX_SIZE tx_size, void *arg) { | 642 TX_SIZE tx_size, void *arg) { |
| 616 struct rdcost_block_args *args = arg; | 643 struct rdcost_block_args *args = arg; |
| 617 MACROBLOCK *const x = args->x; | 644 MACROBLOCK *const x = args->x; |
| 618 MACROBLOCKD *const xd = &x->e_mbd; | 645 MACROBLOCKD *const xd = &x->e_mbd; |
| 619 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; | 646 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
| 620 struct encode_b_args encode_args = {x, NULL, &mbmi->skip_coeff}; | |
| 621 | |
| 622 int64_t rd1, rd2, rd; | 647 int64_t rd1, rd2, rd; |
| 623 | 648 |
| 624 if (args->skip) | 649 if (args->skip) |
| 625 return; | 650 return; |
| 626 | 651 |
| 627 if (!is_inter_block(&xd->mi_8x8[0]->mbmi)) | 652 if (!is_inter_block(mbmi)) |
| 628 vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &encode_args); | 653 vp9_encode_block_intra(x, plane, block, plane_bsize, tx_size, &mbmi->skip); |
| 629 else | 654 else |
| 630 vp9_xform_quant(plane, block, plane_bsize, tx_size, &encode_args); | 655 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); |
| 631 | 656 |
| 632 dist_block(plane, block, tx_size, args); | 657 dist_block(plane, block, tx_size, args); |
| 633 rate_block(plane, block, plane_bsize, tx_size, args); | 658 rate_block(plane, block, plane_bsize, tx_size, args); |
| 634 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist); | 659 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist); |
| 635 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse); | 660 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse); |
| 636 | 661 |
| 637 // TODO(jingning): temporarily enabled only for luma component | 662 // TODO(jingning): temporarily enabled only for luma component |
| 638 rd = MIN(rd1, rd2); | 663 rd = MIN(rd1, rd2); |
| 639 if (plane == 0) | 664 if (plane == 0) |
| 640 x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] || | 665 x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] || |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 for (i = 0; i < num_4x4_w; i += 8) | 702 for (i = 0; i < num_4x4_w; i += 8) |
| 678 t_above[i] = !!*(const uint64_t *)&above[i]; | 703 t_above[i] = !!*(const uint64_t *)&above[i]; |
| 679 for (i = 0; i < num_4x4_h; i += 8) | 704 for (i = 0; i < num_4x4_h; i += 8) |
| 680 t_left[i] = !!*(const uint64_t *)&left[i]; | 705 t_left[i] = !!*(const uint64_t *)&left[i]; |
| 681 break; | 706 break; |
| 682 default: | 707 default: |
| 683 assert(0 && "Invalid transform size."); | 708 assert(0 && "Invalid transform size."); |
| 684 } | 709 } |
| 685 } | 710 } |
| 686 | 711 |
| 687 static void init_rdcost_stack(MACROBLOCK *x, TX_SIZE tx_size, | |
| 688 const int num_4x4_w, const int num_4x4_h, | |
| 689 const int64_t ref_rdcost, | |
| 690 struct rdcost_block_args *arg) { | |
| 691 vpx_memset(arg, 0, sizeof(struct rdcost_block_args)); | |
| 692 arg->x = x; | |
| 693 arg->tx_size = tx_size; | |
| 694 arg->bw = num_4x4_w; | |
| 695 arg->bh = num_4x4_h; | |
| 696 arg->best_rd = ref_rdcost; | |
| 697 } | |
| 698 | |
| 699 static void txfm_rd_in_plane(MACROBLOCK *x, | 712 static void txfm_rd_in_plane(MACROBLOCK *x, |
| 700 struct rdcost_block_args *rd_stack, | |
| 701 int *rate, int64_t *distortion, | 713 int *rate, int64_t *distortion, |
| 702 int *skippable, int64_t *sse, | 714 int *skippable, int64_t *sse, |
| 703 int64_t ref_best_rd, int plane, | 715 int64_t ref_best_rd, int plane, |
| 704 BLOCK_SIZE bsize, TX_SIZE tx_size) { | 716 BLOCK_SIZE bsize, TX_SIZE tx_size) { |
| 705 MACROBLOCKD *const xd = &x->e_mbd; | 717 MACROBLOCKD *const xd = &x->e_mbd; |
| 706 struct macroblockd_plane *const pd = &xd->plane[plane]; | 718 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 707 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); | 719 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); |
| 708 const int num_4x4_w = num_4x4_blocks_wide_lookup[bs]; | 720 const int num_4x4_w = num_4x4_blocks_wide_lookup[bs]; |
| 709 const int num_4x4_h = num_4x4_blocks_high_lookup[bs]; | 721 const int num_4x4_h = num_4x4_blocks_high_lookup[bs]; |
| 710 const scan_order *so; | 722 struct rdcost_block_args args = { 0 }; |
| 723 args.x = x; |
| 724 args.best_rd = ref_best_rd; |
| 711 | 725 |
| 712 init_rdcost_stack(x, tx_size, num_4x4_w, num_4x4_h, | |
| 713 ref_best_rd, rd_stack); | |
| 714 if (plane == 0) | 726 if (plane == 0) |
| 715 xd->mi_8x8[0]->mbmi.tx_size = tx_size; | 727 xd->mi_8x8[0]->mbmi.tx_size = tx_size; |
| 716 | 728 |
| 717 vp9_get_entropy_contexts(tx_size, rd_stack->t_above, rd_stack->t_left, | 729 vp9_get_entropy_contexts(tx_size, args.t_above, args.t_left, |
| 718 pd->above_context, pd->left_context, | 730 pd->above_context, pd->left_context, |
| 719 num_4x4_w, num_4x4_h); | 731 num_4x4_w, num_4x4_h); |
| 720 | 732 |
| 721 so = get_scan(xd, tx_size, pd->plane_type, 0); | 733 args.so = get_scan(xd, tx_size, pd->plane_type, 0); |
| 722 rd_stack->scan = so->scan; | |
| 723 rd_stack->nb = so->neighbors; | |
| 724 | 734 |
| 725 foreach_transformed_block_in_plane(xd, bsize, plane, | 735 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, |
| 726 block_rd_txfm, rd_stack); | 736 block_rd_txfm, &args); |
| 727 if (rd_stack->skip) { | 737 if (args.skip) { |
| 728 *rate = INT_MAX; | 738 *rate = INT_MAX; |
| 729 *distortion = INT64_MAX; | 739 *distortion = INT64_MAX; |
| 730 *sse = INT64_MAX; | 740 *sse = INT64_MAX; |
| 731 *skippable = 0; | 741 *skippable = 0; |
| 732 } else { | 742 } else { |
| 733 *distortion = rd_stack->this_dist; | 743 *distortion = args.this_dist; |
| 734 *rate = rd_stack->this_rate; | 744 *rate = args.this_rate; |
| 735 *sse = rd_stack->this_sse; | 745 *sse = args.this_sse; |
| 736 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); | 746 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); |
| 737 } | 747 } |
| 738 } | 748 } |
| 739 | 749 |
| 740 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x, | 750 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x, |
| 741 int *rate, int64_t *distortion, | 751 int *rate, int64_t *distortion, |
| 742 int *skip, int64_t *sse, | 752 int *skip, int64_t *sse, |
| 743 int64_t ref_best_rd, | 753 int64_t ref_best_rd, |
| 744 BLOCK_SIZE bs) { | 754 BLOCK_SIZE bs) { |
| 745 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 755 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 746 VP9_COMMON *const cm = &cpi->common; | 756 VP9_COMMON *const cm = &cpi->common; |
| 747 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 757 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
| 748 MACROBLOCKD *const xd = &x->e_mbd; | 758 MACROBLOCKD *const xd = &x->e_mbd; |
| 749 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 759 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 750 | 760 |
| 751 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); | 761 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); |
| 752 | 762 |
| 753 txfm_rd_in_plane(x, &cpi->rdcost_stack, rate, distortion, skip, | 763 txfm_rd_in_plane(x, rate, distortion, skip, |
| 754 &sse[mbmi->tx_size], ref_best_rd, 0, bs, | 764 &sse[mbmi->tx_size], ref_best_rd, 0, bs, |
| 755 mbmi->tx_size); | 765 mbmi->tx_size); |
| 756 cpi->tx_stepdown_count[0]++; | 766 cpi->tx_stepdown_count[0]++; |
| 757 } | 767 } |
| 758 | 768 |
| 759 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, | 769 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, |
| 760 int (*r)[2], int *rate, | 770 int (*r)[2], int *rate, |
| 761 int64_t *d, int64_t *distortion, | 771 int64_t *d, int64_t *distortion, |
| 762 int *s, int *skip, | 772 int *s, int *skip, |
| 763 int64_t tx_cache[TX_MODES], | 773 int64_t tx_cache[TX_MODES], |
| 764 BLOCK_SIZE bs) { | 774 BLOCK_SIZE bs) { |
| 765 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 775 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 766 VP9_COMMON *const cm = &cpi->common; | 776 VP9_COMMON *const cm = &cpi->common; |
| 767 MACROBLOCKD *const xd = &x->e_mbd; | 777 MACROBLOCKD *const xd = &x->e_mbd; |
| 768 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 778 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 769 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); | 779 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); |
| 770 int64_t rd[TX_SIZES][2]; | 780 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, |
| 781 {INT64_MAX, INT64_MAX}, |
| 782 {INT64_MAX, INT64_MAX}, |
| 783 {INT64_MAX, INT64_MAX}}; |
| 771 int n, m; | 784 int n, m; |
| 772 int s0, s1; | 785 int s0, s1; |
| 773 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 786 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
| 774 int64_t best_rd = INT64_MAX; | 787 int64_t best_rd = INT64_MAX; |
| 775 TX_SIZE best_tx = TX_4X4; | 788 TX_SIZE best_tx = TX_4X4; |
| 776 | 789 |
| 777 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs); | 790 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs); |
| 778 assert(skip_prob > 0); | 791 assert(skip_prob > 0); |
| 779 s0 = vp9_cost_bit(skip_prob, 0); | 792 s0 = vp9_cost_bit(skip_prob, 0); |
| 780 s1 = vp9_cost_bit(skip_prob, 1); | 793 s1 = vp9_cost_bit(skip_prob, 1); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 int (*r)[2], int *rate, | 848 int (*r)[2], int *rate, |
| 836 int64_t *d, int64_t *distortion, | 849 int64_t *d, int64_t *distortion, |
| 837 int *s, int *skip, int64_t *sse, | 850 int *s, int *skip, int64_t *sse, |
| 838 int64_t ref_best_rd, | 851 int64_t ref_best_rd, |
| 839 BLOCK_SIZE bs) { | 852 BLOCK_SIZE bs) { |
| 840 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 853 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 841 VP9_COMMON *const cm = &cpi->common; | 854 VP9_COMMON *const cm = &cpi->common; |
| 842 MACROBLOCKD *const xd = &x->e_mbd; | 855 MACROBLOCKD *const xd = &x->e_mbd; |
| 843 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 856 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 844 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); | 857 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); |
| 845 int64_t rd[TX_SIZES][2]; | 858 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, |
| 859 {INT64_MAX, INT64_MAX}, |
| 860 {INT64_MAX, INT64_MAX}, |
| 861 {INT64_MAX, INT64_MAX}}; |
| 846 int n, m; | 862 int n, m; |
| 847 int s0, s1; | 863 int s0, s1; |
| 848 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00}; | 864 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00}; |
| 849 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 865 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
| 850 int64_t best_rd = INT64_MAX; | 866 int64_t best_rd = INT64_MAX; |
| 851 TX_SIZE best_tx = TX_4X4; | 867 TX_SIZE best_tx = TX_4X4; |
| 852 | 868 |
| 853 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs); | 869 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs); |
| 854 assert(skip_prob > 0); | 870 assert(skip_prob > 0); |
| 855 s0 = vp9_cost_bit(skip_prob, 0); | 871 s0 = vp9_cost_bit(skip_prob, 0); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 874 best_rd = rd[n][1]; | 890 best_rd = rd[n][1]; |
| 875 best_tx = n; | 891 best_tx = n; |
| 876 } | 892 } |
| 877 } | 893 } |
| 878 | 894 |
| 879 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ? | 895 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ? |
| 880 best_tx : MIN(max_tx_size, max_mode_tx_size); | 896 best_tx : MIN(max_tx_size, max_mode_tx_size); |
| 881 | 897 |
| 882 // Actually encode using the chosen mode if a model was used, but do not | 898 // Actually encode using the chosen mode if a model was used, but do not |
| 883 // update the r, d costs | 899 // update the r, d costs |
| 884 txfm_rd_in_plane(x, &cpi->rdcost_stack, rate, distortion, skip, | 900 txfm_rd_in_plane(x, rate, distortion, skip, |
| 885 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size); | 901 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size); |
| 886 | 902 |
| 887 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) { | 903 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) { |
| 888 cpi->tx_stepdown_count[0]++; | 904 cpi->tx_stepdown_count[0]++; |
| 889 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) { | 905 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) { |
| 890 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; | 906 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; |
| 891 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { | 907 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { |
| 892 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; | 908 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; |
| 893 } else { | 909 } else { |
| 894 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; | 910 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; |
| 895 } | 911 } |
| 896 } | 912 } |
| 897 | 913 |
| 898 static void super_block_yrd(VP9_COMP *cpi, | 914 static void super_block_yrd(VP9_COMP *cpi, |
| 899 MACROBLOCK *x, int *rate, int64_t *distortion, | 915 MACROBLOCK *x, int *rate, int64_t *distortion, |
| 900 int *skip, int64_t *psse, BLOCK_SIZE bs, | 916 int *skip, int64_t *psse, BLOCK_SIZE bs, |
| 901 int64_t txfm_cache[TX_MODES], | 917 int64_t txfm_cache[TX_MODES], |
| 902 int64_t ref_best_rd) { | 918 int64_t ref_best_rd) { |
| 903 int r[TX_SIZES][2], s[TX_SIZES]; | 919 int r[TX_SIZES][2], s[TX_SIZES]; |
| 904 int64_t d[TX_SIZES], sse[TX_SIZES]; | 920 int64_t d[TX_SIZES], sse[TX_SIZES]; |
| 905 MACROBLOCKD *xd = &x->e_mbd; | 921 MACROBLOCKD *xd = &x->e_mbd; |
| 906 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 922 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 907 struct rdcost_block_args *rdcost_stack = &cpi->rdcost_stack; | |
| 908 const int b_inter_mode = is_inter_block(mbmi); | 923 const int b_inter_mode = is_inter_block(mbmi); |
| 909 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 924 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 910 TX_SIZE tx_size; | 925 TX_SIZE tx_size; |
| 911 | 926 |
| 912 | 927 |
| 913 assert(bs == mbmi->sb_type); | 928 assert(bs == mbmi->sb_type); |
| 914 if (b_inter_mode) | 929 if (b_inter_mode) |
| 915 vp9_subtract_sby(x, bs); | 930 vp9_subtract_sby(x, bs); |
| 916 | 931 |
| 917 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || | 932 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || |
| 918 (cpi->sf.tx_size_search_method != USE_FULL_RD && | 933 (cpi->sf.tx_size_search_method != USE_FULL_RD && |
| 919 !b_inter_mode)) { | 934 !b_inter_mode)) { |
| 920 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 935 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
| 921 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, | 936 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, |
| 922 ref_best_rd, bs); | 937 ref_best_rd, bs); |
| 923 if (psse) | 938 if (psse) |
| 924 *psse = sse[mbmi->tx_size]; | 939 *psse = sse[mbmi->tx_size]; |
| 925 return; | 940 return; |
| 926 } | 941 } |
| 927 | 942 |
| 928 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER && | 943 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER && |
| 929 b_inter_mode) { | 944 b_inter_mode) { |
| 930 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | 945 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) |
| 931 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd, | 946 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd, |
| 932 &r[tx_size][0], &d[tx_size], &s[tx_size]); | 947 &r[tx_size][0], &d[tx_size], &s[tx_size]); |
| 933 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, | 948 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, |
| 934 skip, sse, ref_best_rd, bs); | 949 skip, sse, ref_best_rd, bs); |
| 935 } else { | 950 } else { |
| 936 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | 951 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) |
| 937 txfm_rd_in_plane(x, rdcost_stack, &r[tx_size][0], &d[tx_size], | 952 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], |
| 938 &s[tx_size], &sse[tx_size], | 953 &s[tx_size], &sse[tx_size], |
| 939 ref_best_rd, 0, bs, tx_size); | 954 ref_best_rd, 0, bs, tx_size); |
| 940 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, | 955 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, |
| 941 skip, txfm_cache, bs); | 956 skip, txfm_cache, bs); |
| 942 } | 957 } |
| 943 if (psse) | 958 if (psse) |
| 944 *psse = sse[mbmi->tx_size]; | 959 *psse = sse[mbmi->tx_size]; |
| 945 } | 960 } |
| 946 | 961 |
| 947 static int conditional_skipintra(MB_PREDICTION_MODE mode, | 962 static int conditional_skipintra(MB_PREDICTION_MODE mode, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 x->skip_encode ? src_stride : dst_stride, | 1053 x->skip_encode ? src_stride : dst_stride, |
| 1039 dst, dst_stride, idx, idy, 0); | 1054 dst, dst_stride, idx, idy, 0); |
| 1040 vp9_subtract_block(4, 4, src_diff, 8, | 1055 vp9_subtract_block(4, 4, src_diff, 8, |
| 1041 src, src_stride, | 1056 src, src_stride, |
| 1042 dst, dst_stride); | 1057 dst, dst_stride); |
| 1043 | 1058 |
| 1044 tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block); | 1059 tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block); |
| 1045 so = &vp9_scan_orders[TX_4X4][tx_type]; | 1060 so = &vp9_scan_orders[TX_4X4][tx_type]; |
| 1046 | 1061 |
| 1047 if (tx_type != DCT_DCT) | 1062 if (tx_type != DCT_DCT) |
| 1048 vp9_short_fht4x4(src_diff, coeff, 8, tx_type); | 1063 vp9_fht4x4(src_diff, coeff, 8, tx_type); |
| 1049 else | 1064 else |
| 1050 x->fwd_txm4x4(src_diff, coeff, 8); | 1065 x->fwd_txm4x4(src_diff, coeff, 8); |
| 1051 | 1066 |
| 1052 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); | 1067 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); |
| 1053 | 1068 |
| 1054 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4, | 1069 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4, |
| 1055 so->scan, so->neighbors); | 1070 so->scan, so->neighbors); |
| 1056 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), | 1071 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), |
| 1057 16, &ssz) >> 2; | 1072 16, &ssz) >> 2; |
| 1058 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) | 1073 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 bmode_costs = mb->mbmode_cost; | 1139 bmode_costs = mb->mbmode_cost; |
| 1125 | 1140 |
| 1126 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block. | 1141 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block. |
| 1127 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 1142 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
| 1128 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | 1143 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
| 1129 MB_PREDICTION_MODE best_mode = DC_PRED; | 1144 MB_PREDICTION_MODE best_mode = DC_PRED; |
| 1130 int r = INT_MAX, ry = INT_MAX; | 1145 int r = INT_MAX, ry = INT_MAX; |
| 1131 int64_t d = INT64_MAX, this_rd = INT64_MAX; | 1146 int64_t d = INT64_MAX, this_rd = INT64_MAX; |
| 1132 i = idy * 2 + idx; | 1147 i = idy * 2 + idx; |
| 1133 if (cpi->common.frame_type == KEY_FRAME) { | 1148 if (cpi->common.frame_type == KEY_FRAME) { |
| 1134 const MB_PREDICTION_MODE A = above_block_mode(mic, above_mi, i); | 1149 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, i); |
| 1135 const MB_PREDICTION_MODE L = left_block_mode(mic, left_mi, i); | 1150 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, i); |
| 1136 | 1151 |
| 1137 bmode_costs = mb->y_mode_costs[A][L]; | 1152 bmode_costs = mb->y_mode_costs[A][L]; |
| 1138 } | 1153 } |
| 1139 | 1154 |
| 1140 this_rd = rd_pick_intra4x4block(cpi, mb, i, &best_mode, bmode_costs, | 1155 this_rd = rd_pick_intra4x4block(cpi, mb, i, &best_mode, bmode_costs, |
| 1141 t_above + idx, t_left + idy, &r, &ry, &d, | 1156 t_above + idx, t_left + idy, &r, &ry, &d, |
| 1142 bsize, best_rd - total_rd); | 1157 bsize, best_rd - total_rd); |
| 1143 if (this_rd >= best_rd - total_rd) | 1158 if (this_rd >= best_rd - total_rd) |
| 1144 return INT64_MAX; | 1159 return INT64_MAX; |
| 1145 | 1160 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 /* Y Search for intra prediction mode */ | 1205 /* Y Search for intra prediction mode */ |
| 1191 for (mode = DC_PRED; mode <= TM_PRED; mode++) { | 1206 for (mode = DC_PRED; mode <= TM_PRED; mode++) { |
| 1192 int64_t local_tx_cache[TX_MODES]; | 1207 int64_t local_tx_cache[TX_MODES]; |
| 1193 MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; | 1208 MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; |
| 1194 MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; | 1209 MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; |
| 1195 | 1210 |
| 1196 if (!(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]] & (1 << mode))) | 1211 if (!(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]] & (1 << mode))) |
| 1197 continue; | 1212 continue; |
| 1198 | 1213 |
| 1199 if (cpi->common.frame_type == KEY_FRAME) { | 1214 if (cpi->common.frame_type == KEY_FRAME) { |
| 1200 const MB_PREDICTION_MODE A = above_block_mode(mic, above_mi, 0); | 1215 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); |
| 1201 const MB_PREDICTION_MODE L = left_block_mode(mic, left_mi, 0); | 1216 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); |
| 1202 | 1217 |
| 1203 bmode_costs = x->y_mode_costs[A][L]; | 1218 bmode_costs = x->y_mode_costs[A][L]; |
| 1204 } | 1219 } |
| 1205 mic->mbmi.mode = mode; | 1220 mic->mbmi.mode = mode; |
| 1206 | 1221 |
| 1207 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, &s, NULL, | 1222 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, &s, NULL, |
| 1208 bsize, local_tx_cache, best_rd); | 1223 bsize, local_tx_cache, best_rd); |
| 1209 | 1224 |
| 1210 if (this_rate_tokenonly == INT_MAX) | 1225 if (this_rate_tokenonly == INT_MAX) |
| 1211 continue; | 1226 continue; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 | 1271 |
| 1257 if (is_inter_block(mbmi)) | 1272 if (is_inter_block(mbmi)) |
| 1258 vp9_subtract_sbuv(x, bsize); | 1273 vp9_subtract_sbuv(x, bsize); |
| 1259 | 1274 |
| 1260 *rate = 0; | 1275 *rate = 0; |
| 1261 *distortion = 0; | 1276 *distortion = 0; |
| 1262 *sse = 0; | 1277 *sse = 0; |
| 1263 *skippable = 1; | 1278 *skippable = 1; |
| 1264 | 1279 |
| 1265 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { | 1280 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
| 1266 txfm_rd_in_plane(x, &cpi->rdcost_stack, &pnrate, &pndist, &pnskip, &pnsse, | 1281 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse, |
| 1267 ref_best_rd, plane, bsize, uv_txfm_size); | 1282 ref_best_rd, plane, bsize, uv_txfm_size); |
| 1268 if (pnrate == INT_MAX) | 1283 if (pnrate == INT_MAX) |
| 1269 goto term; | 1284 goto term; |
| 1270 *rate += pnrate; | 1285 *rate += pnrate; |
| 1271 *distortion += pndist; | 1286 *distortion += pndist; |
| 1272 *sse += pnsse; | 1287 *sse += pnsse; |
| 1273 *skippable &= pnskip; | 1288 *skippable &= pnskip; |
| 1274 } | 1289 } |
| 1275 return; | 1290 return; |
| 1276 | 1291 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 int64_t segment_rd; | 1593 int64_t segment_rd; |
| 1579 int r; | 1594 int r; |
| 1580 int64_t d; | 1595 int64_t d; |
| 1581 int64_t sse; | 1596 int64_t sse; |
| 1582 int segment_yrate; | 1597 int segment_yrate; |
| 1583 MB_PREDICTION_MODE modes[4]; | 1598 MB_PREDICTION_MODE modes[4]; |
| 1584 SEG_RDSTAT rdstat[4][INTER_MODES]; | 1599 SEG_RDSTAT rdstat[4][INTER_MODES]; |
| 1585 int mvthresh; | 1600 int mvthresh; |
| 1586 } BEST_SEG_INFO; | 1601 } BEST_SEG_INFO; |
| 1587 | 1602 |
| 1588 static INLINE int mv_check_bounds(MACROBLOCK *x, int_mv *mv) { | 1603 static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) { |
| 1589 int r = 0; | 1604 return (mv->row >> 3) < x->mv_row_min || |
| 1590 r |= (mv->as_mv.row >> 3) < x->mv_row_min; | 1605 (mv->row >> 3) > x->mv_row_max || |
| 1591 r |= (mv->as_mv.row >> 3) > x->mv_row_max; | 1606 (mv->col >> 3) < x->mv_col_min || |
| 1592 r |= (mv->as_mv.col >> 3) < x->mv_col_min; | 1607 (mv->col >> 3) > x->mv_col_max; |
| 1593 r |= (mv->as_mv.col >> 3) > x->mv_col_max; | |
| 1594 return r; | |
| 1595 } | 1608 } |
| 1596 | 1609 |
| 1597 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { | 1610 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { |
| 1598 MB_MODE_INFO *const mbmi = &x->e_mbd.mi_8x8[0]->mbmi; | 1611 MB_MODE_INFO *const mbmi = &x->e_mbd.mi_8x8[0]->mbmi; |
| 1599 struct macroblock_plane *const p = &x->plane[0]; | 1612 struct macroblock_plane *const p = &x->plane[0]; |
| 1600 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; | 1613 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; |
| 1601 | 1614 |
| 1602 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)]; | 1615 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)]; |
| 1603 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); | 1616 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); |
| 1604 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i, | 1617 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1619 | 1632 |
| 1620 static INLINE int mv_has_subpel(const MV *mv) { | 1633 static INLINE int mv_has_subpel(const MV *mv) { |
| 1621 return (mv->row & 0x0F) || (mv->col & 0x0F); | 1634 return (mv->row & 0x0F) || (mv->col & 0x0F); |
| 1622 } | 1635 } |
| 1623 | 1636 |
| 1624 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, | 1637 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, |
| 1625 const TileInfo *const tile, | 1638 const TileInfo *const tile, |
| 1626 BEST_SEG_INFO *bsi_buf, int filter_idx, | 1639 BEST_SEG_INFO *bsi_buf, int filter_idx, |
| 1627 int_mv seg_mvs[4][MAX_REF_FRAMES], | 1640 int_mv seg_mvs[4][MAX_REF_FRAMES], |
| 1628 int mi_row, int mi_col) { | 1641 int mi_row, int mi_col) { |
| 1629 int i, br = 0, idx, idy; | 1642 int k, br = 0, idx, idy; |
| 1630 int64_t bd = 0, block_sse = 0; | 1643 int64_t bd = 0, block_sse = 0; |
| 1631 MB_PREDICTION_MODE this_mode; | 1644 MB_PREDICTION_MODE this_mode; |
| 1645 MACROBLOCKD *xd = &x->e_mbd; |
| 1632 VP9_COMMON *cm = &cpi->common; | 1646 VP9_COMMON *cm = &cpi->common; |
| 1633 MODE_INFO *mi = x->e_mbd.mi_8x8[0]; | 1647 MODE_INFO *mi = xd->mi_8x8[0]; |
| 1634 MB_MODE_INFO *const mbmi = &mi->mbmi; | 1648 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1635 struct macroblock_plane *const p = &x->plane[0]; | 1649 struct macroblock_plane *const p = &x->plane[0]; |
| 1636 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; | 1650 struct macroblockd_plane *const pd = &xd->plane[0]; |
| 1637 const int label_count = 4; | 1651 const int label_count = 4; |
| 1638 int64_t this_segment_rd = 0; | 1652 int64_t this_segment_rd = 0; |
| 1639 int label_mv_thresh; | 1653 int label_mv_thresh; |
| 1640 int segmentyrate = 0; | 1654 int segmentyrate = 0; |
| 1641 const BLOCK_SIZE bsize = mbmi->sb_type; | 1655 const BLOCK_SIZE bsize = mbmi->sb_type; |
| 1642 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1656 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 1643 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1657 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 1644 vp9_variance_fn_ptr_t *v_fn_ptr; | 1658 vp9_variance_fn_ptr_t *v_fn_ptr = &cpi->fn_ptr[bsize]; |
| 1645 ENTROPY_CONTEXT t_above[2], t_left[2]; | 1659 ENTROPY_CONTEXT t_above[2], t_left[2]; |
| 1646 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; | 1660 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; |
| 1647 int mode_idx; | 1661 int mode_idx; |
| 1648 int subpelmv = 1, have_ref = 0; | 1662 int subpelmv = 1, have_ref = 0; |
| 1649 const int has_second_rf = has_second_ref(mbmi); | 1663 const int has_second_rf = has_second_ref(mbmi); |
| 1650 | 1664 |
| 1651 vpx_memcpy(t_above, pd->above_context, sizeof(t_above)); | 1665 vpx_memcpy(t_above, pd->above_context, sizeof(t_above)); |
| 1652 vpx_memcpy(t_left, pd->left_context, sizeof(t_left)); | 1666 vpx_memcpy(t_left, pd->left_context, sizeof(t_left)); |
| 1653 | 1667 |
| 1654 v_fn_ptr = &cpi->fn_ptr[bsize]; | |
| 1655 | |
| 1656 // 64 makes this threshold really big effectively | 1668 // 64 makes this threshold really big effectively |
| 1657 // making it so that we very rarely check mvs on | 1669 // making it so that we very rarely check mvs on |
| 1658 // segments. setting this to 1 would make mv thresh | 1670 // segments. setting this to 1 would make mv thresh |
| 1659 // roughly equal to what it is for macroblocks | 1671 // roughly equal to what it is for macroblocks |
| 1660 label_mv_thresh = 1 * bsi->mvthresh / label_count; | 1672 label_mv_thresh = 1 * bsi->mvthresh / label_count; |
| 1661 | 1673 |
| 1662 // Segmentation method overheads | 1674 // Segmentation method overheads |
| 1663 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 1675 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
| 1664 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | 1676 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
| 1665 // TODO(jingning,rbultje): rewrite the rate-distortion optimization | 1677 // TODO(jingning,rbultje): rewrite the rate-distortion optimization |
| 1666 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop | 1678 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop |
| 1667 int_mv mode_mv[MB_MODE_COUNT], second_mode_mv[MB_MODE_COUNT]; | 1679 int_mv mode_mv[MB_MODE_COUNT], second_mode_mv[MB_MODE_COUNT]; |
| 1668 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 1680 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 1669 MB_PREDICTION_MODE mode_selected = ZEROMV; | 1681 MB_PREDICTION_MODE mode_selected = ZEROMV; |
| 1670 int64_t best_rd = INT64_MAX; | 1682 int64_t best_rd = INT64_MAX; |
| 1671 i = idy * 2 + idx; | 1683 const int i = idy * 2 + idx; |
| 1684 int ref; |
| 1672 | 1685 |
| 1673 frame_mv[ZEROMV][mbmi->ref_frame[0]].as_int = 0; | 1686 for (ref = 0; ref < 1 + has_second_rf; ++ref) { |
| 1674 vp9_append_sub8x8_mvs_for_idx(cm, &x->e_mbd, tile, | 1687 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
| 1675 i, 0, mi_row, mi_col, | 1688 frame_mv[ZEROMV][frame].as_int = 0; |
| 1676 &frame_mv[NEARESTMV][mbmi->ref_frame[0]], | 1689 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, i, ref, mi_row, mi_col, |
| 1677 &frame_mv[NEARMV][mbmi->ref_frame[0]]); | 1690 &frame_mv[NEARESTMV][frame], |
| 1678 if (has_second_rf) { | 1691 &frame_mv[NEARMV][frame]); |
| 1679 frame_mv[ZEROMV][mbmi->ref_frame[1]].as_int = 0; | |
| 1680 vp9_append_sub8x8_mvs_for_idx(cm, &x->e_mbd, tile, | |
| 1681 i, 1, mi_row, mi_col, | |
| 1682 &frame_mv[NEARESTMV][mbmi->ref_frame[1]], | |
| 1683 &frame_mv[NEARMV][mbmi->ref_frame[1]]); | |
| 1684 } | 1692 } |
| 1693 |
| 1685 // search for the best motion vector on this segment | 1694 // search for the best motion vector on this segment |
| 1686 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 1695 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
| 1687 const struct buf_2d orig_src = x->plane[0].src; | 1696 const struct buf_2d orig_src = x->plane[0].src; |
| 1688 struct buf_2d orig_pre[2]; | 1697 struct buf_2d orig_pre[2]; |
| 1689 | 1698 |
| 1690 mode_idx = INTER_OFFSET(this_mode); | 1699 mode_idx = INTER_OFFSET(this_mode); |
| 1691 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; | 1700 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; |
| 1692 | 1701 |
| 1693 // if we're near/nearest and mv == 0,0, compare to zeromv | 1702 // if we're near/nearest and mv == 0,0, compare to zeromv |
| 1694 if ((this_mode == NEARMV || this_mode == NEARESTMV || | 1703 if ((this_mode == NEARMV || this_mode == NEARESTMV || |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 int thissme, bestsme = INT_MAX; | 1751 int thissme, bestsme = INT_MAX; |
| 1743 int sadpb = x->sadperbit4; | 1752 int sadpb = x->sadperbit4; |
| 1744 MV mvp_full; | 1753 MV mvp_full; |
| 1745 int max_mv; | 1754 int max_mv; |
| 1746 | 1755 |
| 1747 /* Is the best so far sufficiently good that we cant justify doing | 1756 /* Is the best so far sufficiently good that we cant justify doing |
| 1748 * and new motion search. */ | 1757 * and new motion search. */ |
| 1749 if (best_rd < label_mv_thresh) | 1758 if (best_rd < label_mv_thresh) |
| 1750 break; | 1759 break; |
| 1751 | 1760 |
| 1752 if (cpi->compressor_speed) { | 1761 if (cpi->oxcf.mode != MODE_SECONDPASS_BEST && |
| 1762 cpi->oxcf.mode != MODE_BESTQUALITY) { |
| 1753 // use previous block's result as next block's MV predictor. | 1763 // use previous block's result as next block's MV predictor. |
| 1754 if (i > 0) { | 1764 if (i > 0) { |
| 1755 bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int; | 1765 bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int; |
| 1756 if (i == 2) | 1766 if (i == 2) |
| 1757 bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int; | 1767 bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int; |
| 1758 } | 1768 } |
| 1759 } | 1769 } |
| 1760 if (i == 0) | 1770 if (i == 0) |
| 1761 max_mv = x->max_mv_context[mbmi->ref_frame[0]]; | 1771 max_mv = x->max_mv_context[mbmi->ref_frame[0]]; |
| 1762 else | 1772 else |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1802 } else if (cpi->sf.search_method == BIGDIA) { | 1812 } else if (cpi->sf.search_method == BIGDIA) { |
| 1803 bestsme = vp9_bigdia_search(x, &mvp_full, | 1813 bestsme = vp9_bigdia_search(x, &mvp_full, |
| 1804 step_param, | 1814 step_param, |
| 1805 sadpb, 1, v_fn_ptr, 1, | 1815 sadpb, 1, v_fn_ptr, 1, |
| 1806 &bsi->ref_mv->as_mv, | 1816 &bsi->ref_mv->as_mv, |
| 1807 &new_mv->as_mv); | 1817 &new_mv->as_mv); |
| 1808 } else { | 1818 } else { |
| 1809 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, | 1819 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, |
| 1810 sadpb, further_steps, 0, v_fn_ptr, | 1820 sadpb, further_steps, 0, v_fn_ptr, |
| 1811 &bsi->ref_mv->as_mv, | 1821 &bsi->ref_mv->as_mv, |
| 1812 new_mv); | 1822 &new_mv->as_mv); |
| 1813 } | 1823 } |
| 1814 | 1824 |
| 1815 // Should we do a full search (best quality only) | 1825 // Should we do a full search (best quality only) |
| 1816 if (cpi->compressor_speed == 0) { | 1826 if (cpi->oxcf.mode == MODE_BESTQUALITY || |
| 1827 cpi->oxcf.mode == MODE_SECONDPASS_BEST) { |
| 1817 /* Check if mvp_full is within the range. */ | 1828 /* Check if mvp_full is within the range. */ |
| 1818 clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, | 1829 clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, |
| 1819 x->mv_row_min, x->mv_row_max); | 1830 x->mv_row_min, x->mv_row_max); |
| 1820 | 1831 |
| 1821 thissme = cpi->full_search_sad(x, &mvp_full, | 1832 thissme = cpi->full_search_sad(x, &mvp_full, |
| 1822 sadpb, 16, v_fn_ptr, | 1833 sadpb, 16, v_fn_ptr, |
| 1823 x->nmvjointcost, x->mvcost, | 1834 x->nmvjointcost, x->mvcost, |
| 1824 &bsi->ref_mv->as_mv, i); | 1835 &bsi->ref_mv->as_mv, i); |
| 1825 | 1836 |
| 1826 if (thissme < bestsme) { | 1837 if (thissme < bestsme) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 second_mode_mv[this_mode].as_int; | 1911 second_mode_mv[this_mode].as_int; |
| 1901 if (num_4x4_blocks_wide > 1) | 1912 if (num_4x4_blocks_wide > 1) |
| 1902 bsi->rdstat[i + 1][mode_idx].mvs[1].as_int = | 1913 bsi->rdstat[i + 1][mode_idx].mvs[1].as_int = |
| 1903 second_mode_mv[this_mode].as_int; | 1914 second_mode_mv[this_mode].as_int; |
| 1904 if (num_4x4_blocks_high > 1) | 1915 if (num_4x4_blocks_high > 1) |
| 1905 bsi->rdstat[i + 2][mode_idx].mvs[1].as_int = | 1916 bsi->rdstat[i + 2][mode_idx].mvs[1].as_int = |
| 1906 second_mode_mv[this_mode].as_int; | 1917 second_mode_mv[this_mode].as_int; |
| 1907 } | 1918 } |
| 1908 | 1919 |
| 1909 // Trap vectors that reach beyond the UMV borders | 1920 // Trap vectors that reach beyond the UMV borders |
| 1910 if (mv_check_bounds(x, &mode_mv[this_mode])) | 1921 if (mv_check_bounds(x, &mode_mv[this_mode].as_mv) || |
| 1911 continue; | 1922 (has_second_rf && |
| 1912 if (has_second_rf && | 1923 mv_check_bounds(x, &second_mode_mv[this_mode].as_mv))) |
| 1913 mv_check_bounds(x, &second_mode_mv[this_mode])) | |
| 1914 continue; | 1924 continue; |
| 1915 | 1925 |
| 1916 if (filter_idx > 0) { | 1926 if (filter_idx > 0) { |
| 1917 BEST_SEG_INFO *ref_bsi = bsi_buf; | 1927 BEST_SEG_INFO *ref_bsi = bsi_buf; |
| 1918 subpelmv = mv_has_subpel(&mode_mv[this_mode].as_mv); | 1928 subpelmv = mv_has_subpel(&mode_mv[this_mode].as_mv); |
| 1919 have_ref = mode_mv[this_mode].as_int == | 1929 have_ref = mode_mv[this_mode].as_int == |
| 1920 ref_bsi->rdstat[i][mode_idx].mvs[0].as_int; | 1930 ref_bsi->rdstat[i][mode_idx].mvs[0].as_int; |
| 1921 if (has_second_rf) { | 1931 if (has_second_rf) { |
| 1922 subpelmv |= mv_has_subpel(&second_mode_mv[this_mode].as_mv); | 1932 subpelmv |= mv_has_subpel(&second_mode_mv[this_mode].as_mv); |
| 1923 have_ref &= second_mode_mv[this_mode].as_int == | 1933 have_ref &= second_mode_mv[this_mode].as_int == |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2014 } | 2024 } |
| 2015 } /* for each label */ | 2025 } /* for each label */ |
| 2016 | 2026 |
| 2017 bsi->r = br; | 2027 bsi->r = br; |
| 2018 bsi->d = bd; | 2028 bsi->d = bd; |
| 2019 bsi->segment_yrate = segmentyrate; | 2029 bsi->segment_yrate = segmentyrate; |
| 2020 bsi->segment_rd = this_segment_rd; | 2030 bsi->segment_rd = this_segment_rd; |
| 2021 bsi->sse = block_sse; | 2031 bsi->sse = block_sse; |
| 2022 | 2032 |
| 2023 // update the coding decisions | 2033 // update the coding decisions |
| 2024 for (i = 0; i < 4; ++i) | 2034 for (k = 0; k < 4; ++k) |
| 2025 bsi->modes[i] = mi->bmi[i].as_mode; | 2035 bsi->modes[k] = mi->bmi[k].as_mode; |
| 2026 } | 2036 } |
| 2027 | 2037 |
| 2028 static int64_t rd_pick_best_mbsegmentation(VP9_COMP *cpi, MACROBLOCK *x, | 2038 static int64_t rd_pick_best_mbsegmentation(VP9_COMP *cpi, MACROBLOCK *x, |
| 2029 const TileInfo *const tile, | 2039 const TileInfo *const tile, |
| 2030 int_mv *best_ref_mv, | 2040 int_mv *best_ref_mv, |
| 2031 int_mv *second_best_ref_mv, | 2041 int_mv *second_best_ref_mv, |
| 2032 int64_t best_rd, | 2042 int64_t best_rd, |
| 2033 int *returntotrate, | 2043 int *returntotrate, |
| 2034 int *returnyrate, | 2044 int *returnyrate, |
| 2035 int64_t *returndistortion, | 2045 int64_t *returndistortion, |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2303 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8) | 2313 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8) |
| 2304 mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, | 2314 mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, |
| 2305 ref_frame, block_size); | 2315 ref_frame, block_size); |
| 2306 } | 2316 } |
| 2307 | 2317 |
| 2308 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi, | 2318 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi, |
| 2309 int ref_frame) { | 2319 int ref_frame) { |
| 2310 const VP9_COMMON *const cm = &cpi->common; | 2320 const VP9_COMMON *const cm = &cpi->common; |
| 2311 const int ref_idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 2321 const int ref_idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
| 2312 const int scaled_idx = cpi->scaled_ref_idx[ref_frame - 1]; | 2322 const int scaled_idx = cpi->scaled_ref_idx[ref_frame - 1]; |
| 2313 return (scaled_idx != ref_idx) ? &cm->yv12_fb[scaled_idx] : NULL; | 2323 return (scaled_idx != ref_idx) ? &cm->frame_bufs[scaled_idx].buf : NULL; |
| 2314 } | 2324 } |
| 2315 | 2325 |
| 2316 static INLINE int get_switchable_rate(const MACROBLOCK *x) { | 2326 static INLINE int get_switchable_rate(const MACROBLOCK *x) { |
| 2317 const MACROBLOCKD *const xd = &x->e_mbd; | 2327 const MACROBLOCKD *const xd = &x->e_mbd; |
| 2318 const MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 2328 const MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 2319 const int ctx = vp9_get_pred_context_switchable_interp(xd); | 2329 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
| 2320 return SWITCHABLE_INTERP_RATE_FACTOR * | 2330 return SWITCHABLE_INTERP_RATE_FACTOR * |
| 2321 x->switchable_interp_costs[ctx][mbmi->interp_filter]; | 2331 x->switchable_interp_costs[ctx][mbmi->interp_filter]; |
| 2322 } | 2332 } |
| 2323 | 2333 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2356 // match the resolution of the current frame, allowing the existing | 2366 // match the resolution of the current frame, allowing the existing |
| 2357 // motion search code to be used without additional modifications. | 2367 // motion search code to be used without additional modifications. |
| 2358 for (i = 0; i < MAX_MB_PLANE; i++) | 2368 for (i = 0; i < MAX_MB_PLANE; i++) |
| 2359 backup_yv12[i] = xd->plane[i].pre[0]; | 2369 backup_yv12[i] = xd->plane[i].pre[0]; |
| 2360 | 2370 |
| 2361 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); | 2371 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
| 2362 } | 2372 } |
| 2363 | 2373 |
| 2364 vp9_set_mv_search_range(x, &ref_mv.as_mv); | 2374 vp9_set_mv_search_range(x, &ref_mv.as_mv); |
| 2365 | 2375 |
| 2366 // Adjust search parameters based on small partitions' result. | 2376 // Work out the size of the first step in the mv step search. |
| 2367 if (x->fast_ms) { | 2377 // 0 here is maximum length first step. 1 is MAX >> 1 etc. |
| 2368 // adjust search range | 2378 if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) { |
| 2369 step_param = 6; | 2379 // Take wtd average of the step_params based on the last frame's |
| 2370 if (x->fast_ms > 1) | 2380 // max mv magnitude and that based on the best ref mvs of the current |
| 2371 step_param = 8; | 2381 // block for the given reference. |
| 2382 step_param = (vp9_init_search_range(cpi, x->max_mv_context[ref]) + |
| 2383 cpi->mv_step_param) >> 1; |
| 2372 } else { | 2384 } else { |
| 2373 // Work out the size of the first step in the mv step search. | 2385 step_param = cpi->mv_step_param; |
| 2374 // 0 here is maximum length first step. 1 is MAX >> 1 etc. | |
| 2375 if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) { | |
| 2376 // Take wtd average of the step_params based on the last frame's | |
| 2377 // max mv magnitude and that based on the best ref mvs of the current | |
| 2378 // block for the given reference. | |
| 2379 step_param = (vp9_init_search_range(cpi, x->max_mv_context[ref]) + | |
| 2380 cpi->mv_step_param) >> 1; | |
| 2381 } else { | |
| 2382 step_param = cpi->mv_step_param; | |
| 2383 } | |
| 2384 } | 2386 } |
| 2385 | 2387 |
| 2386 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64 && | 2388 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64 && |
| 2387 cpi->common.show_frame) { | 2389 cpi->common.show_frame) { |
| 2388 int boffset = 2 * (b_width_log2(BLOCK_64X64) - MIN(b_height_log2(bsize), | 2390 int boffset = 2 * (b_width_log2(BLOCK_64X64) - MIN(b_height_log2(bsize), |
| 2389 b_width_log2(bsize))); | 2391 b_width_log2(bsize))); |
| 2390 step_param = MAX(step_param, boffset); | 2392 step_param = MAX(step_param, boffset); |
| 2391 } | 2393 } |
| 2392 | 2394 |
| 2393 if (cpi->sf.adaptive_motion_search) { | 2395 if (cpi->sf.adaptive_motion_search) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2431 &cpi->fn_ptr[bsize], 1, | 2433 &cpi->fn_ptr[bsize], 1, |
| 2432 &ref_mv.as_mv, &tmp_mv->as_mv); | 2434 &ref_mv.as_mv, &tmp_mv->as_mv); |
| 2433 } else if (cpi->sf.search_method == BIGDIA) { | 2435 } else if (cpi->sf.search_method == BIGDIA) { |
| 2434 bestsme = vp9_bigdia_search(x, &mvp_full, step_param, sadpb, 1, | 2436 bestsme = vp9_bigdia_search(x, &mvp_full, step_param, sadpb, 1, |
| 2435 &cpi->fn_ptr[bsize], 1, | 2437 &cpi->fn_ptr[bsize], 1, |
| 2436 &ref_mv.as_mv, &tmp_mv->as_mv); | 2438 &ref_mv.as_mv, &tmp_mv->as_mv); |
| 2437 } else { | 2439 } else { |
| 2438 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, | 2440 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, |
| 2439 sadpb, further_steps, 1, | 2441 sadpb, further_steps, 1, |
| 2440 &cpi->fn_ptr[bsize], | 2442 &cpi->fn_ptr[bsize], |
| 2441 &ref_mv.as_mv, tmp_mv); | 2443 &ref_mv.as_mv, &tmp_mv->as_mv); |
| 2442 } | 2444 } |
| 2443 | 2445 |
| 2444 x->mv_col_min = tmp_col_min; | 2446 x->mv_col_min = tmp_col_min; |
| 2445 x->mv_col_max = tmp_col_max; | 2447 x->mv_col_max = tmp_col_max; |
| 2446 x->mv_row_min = tmp_row_min; | 2448 x->mv_row_min = tmp_row_min; |
| 2447 x->mv_row_max = tmp_row_max; | 2449 x->mv_row_max = tmp_row_max; |
| 2448 | 2450 |
| 2449 if (bestsme < INT_MAX) { | 2451 if (bestsme < INT_MAX) { |
| 2450 int dis; /* TODO: use dis in distortion calculation later. */ | 2452 int dis; /* TODO: use dis in distortion calculation later. */ |
| 2451 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv.as_mv, | 2453 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv.as_mv, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2726 } | 2728 } |
| 2727 } | 2729 } |
| 2728 } | 2730 } |
| 2729 | 2731 |
| 2730 for (i = 0; i < num_refs; ++i) { | 2732 for (i = 0; i < num_refs; ++i) { |
| 2731 cur_mv[i] = frame_mv[refs[i]]; | 2733 cur_mv[i] = frame_mv[refs[i]]; |
| 2732 // Clip "next_nearest" so that it does not extend to far out of image | 2734 // Clip "next_nearest" so that it does not extend to far out of image |
| 2733 if (this_mode != NEWMV) | 2735 if (this_mode != NEWMV) |
| 2734 clamp_mv2(&cur_mv[i].as_mv, xd); | 2736 clamp_mv2(&cur_mv[i].as_mv, xd); |
| 2735 | 2737 |
| 2736 if (mv_check_bounds(x, &cur_mv[i])) | 2738 if (mv_check_bounds(x, &cur_mv[i].as_mv)) |
| 2737 return INT64_MAX; | 2739 return INT64_MAX; |
| 2738 mbmi->mv[i].as_int = cur_mv[i].as_int; | 2740 mbmi->mv[i].as_int = cur_mv[i].as_int; |
| 2739 } | 2741 } |
| 2740 | 2742 |
| 2741 // do first prediction into the destination buffer. Do the next | 2743 // do first prediction into the destination buffer. Do the next |
| 2742 // prediction into a temporary buffer. Then keep track of which one | 2744 // prediction into a temporary buffer. Then keep track of which one |
| 2743 // of these currently holds the best predictor, and use the other | 2745 // of these currently holds the best predictor, and use the other |
| 2744 // one for future predictions. In the end, copy from tmp_buf to | 2746 // one for future predictions. In the end, copy from tmp_buf to |
| 2745 // dst if necessary. | 2747 // dst if necessary. |
| 2746 for (i = 0; i < MAX_MB_PLANE; i++) { | 2748 for (i = 0; i < MAX_MB_PLANE; i++) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2778 *best_filter = EIGHTTAP; | 2780 *best_filter = EIGHTTAP; |
| 2779 } else { | 2781 } else { |
| 2780 int newbest; | 2782 int newbest; |
| 2781 int tmp_rate_sum = 0; | 2783 int tmp_rate_sum = 0; |
| 2782 int64_t tmp_dist_sum = 0; | 2784 int64_t tmp_dist_sum = 0; |
| 2783 | 2785 |
| 2784 for (i = 0; i < SWITCHABLE_FILTERS; ++i) { | 2786 for (i = 0; i < SWITCHABLE_FILTERS; ++i) { |
| 2785 int j; | 2787 int j; |
| 2786 int64_t rs_rd; | 2788 int64_t rs_rd; |
| 2787 mbmi->interp_filter = i; | 2789 mbmi->interp_filter = i; |
| 2788 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 2790 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 2789 rs = get_switchable_rate(x); | 2791 rs = get_switchable_rate(x); |
| 2790 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); | 2792 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); |
| 2791 | 2793 |
| 2792 if (i > 0 && intpel_mv) { | 2794 if (i > 0 && intpel_mv) { |
| 2793 rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum); | 2795 rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum); |
| 2794 cpi->rd_filter_cache[i] = rd; | 2796 cpi->rd_filter_cache[i] = rd; |
| 2795 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = | 2797 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = |
| 2796 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); | 2798 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); |
| 2797 if (cm->interp_filter == SWITCHABLE) | 2799 if (cm->interp_filter == SWITCHABLE) |
| 2798 rd += rs_rd; | 2800 rd += rs_rd; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2849 cm->interp_filter == mbmi->interp_filter)) { | 2851 cm->interp_filter == mbmi->interp_filter)) { |
| 2850 pred_exists = 1; | 2852 pred_exists = 1; |
| 2851 } | 2853 } |
| 2852 } | 2854 } |
| 2853 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2855 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
| 2854 } | 2856 } |
| 2855 } | 2857 } |
| 2856 // Set the appropriate filter | 2858 // Set the appropriate filter |
| 2857 mbmi->interp_filter = cm->interp_filter != SWITCHABLE ? | 2859 mbmi->interp_filter = cm->interp_filter != SWITCHABLE ? |
| 2858 cm->interp_filter : *best_filter; | 2860 cm->interp_filter : *best_filter; |
| 2859 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 2861 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 2860 rs = cm->interp_filter == SWITCHABLE ? get_switchable_rate(x) : 0; | 2862 rs = cm->interp_filter == SWITCHABLE ? get_switchable_rate(x) : 0; |
| 2861 | 2863 |
| 2862 if (pred_exists) { | 2864 if (pred_exists) { |
| 2863 if (best_needs_copy) { | 2865 if (best_needs_copy) { |
| 2864 // again temporarily set the buffers to local memory to prevent a memcpy | 2866 // again temporarily set the buffers to local memory to prevent a memcpy |
| 2865 for (i = 0; i < MAX_MB_PLANE; i++) { | 2867 for (i = 0; i < MAX_MB_PLANE; i++) { |
| 2866 xd->plane[i].dst.buf = tmp_buf + i * 64 * 64; | 2868 xd->plane[i].dst.buf = tmp_buf + i * 64 * 64; |
| 2867 xd->plane[i].dst.stride = 64; | 2869 xd->plane[i].dst.stride = 64; |
| 2868 } | 2870 } |
| 2869 } | 2871 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2882 // so far, do not bother doing full rd | 2884 // so far, do not bother doing full rd |
| 2883 if (rd / 2 > ref_best_rd) { | 2885 if (rd / 2 > ref_best_rd) { |
| 2884 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2886 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
| 2885 return INT64_MAX; | 2887 return INT64_MAX; |
| 2886 } | 2888 } |
| 2887 } | 2889 } |
| 2888 | 2890 |
| 2889 if (cm->interp_filter == SWITCHABLE) | 2891 if (cm->interp_filter == SWITCHABLE) |
| 2890 *rate2 += get_switchable_rate(x); | 2892 *rate2 += get_switchable_rate(x); |
| 2891 | 2893 |
| 2892 if (!is_comp_pred && cpi->enable_encode_breakout) { | 2894 if (!is_comp_pred) { |
| 2893 if (cpi->active_map_enabled && x->active_ptr[0] == 0) | 2895 if (cpi->active_map_enabled && x->active_ptr[0] == 0) |
| 2894 x->skip = 1; | 2896 x->skip = 1; |
| 2895 else if (x->encode_breakout) { | 2897 else if (cpi->allow_encode_breakout && x->encode_breakout) { |
| 2896 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); | 2898 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); |
| 2897 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); | 2899 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); |
| 2898 unsigned int var, sse; | 2900 unsigned int var, sse; |
| 2899 // Skipping threshold for ac. | 2901 // Skipping threshold for ac. |
| 2900 unsigned int thresh_ac; | 2902 unsigned int thresh_ac; |
| 2903 // Set a maximum for threshold to avoid big PSNR loss in low bitrate case. |
| 2904 // Use extreme low threshold for static frames to limit skipping. |
| 2905 const unsigned int max_thresh = (cpi->allow_encode_breakout == |
| 2906 ENCODE_BREAKOUT_LIMITED) ? 128 : 36000; |
| 2901 // The encode_breakout input | 2907 // The encode_breakout input |
| 2902 unsigned int encode_breakout = x->encode_breakout << 4; | 2908 const unsigned int min_thresh = ((x->encode_breakout << 4) > max_thresh) ? |
| 2903 unsigned int max_thresh = 36000; | 2909 max_thresh : (x->encode_breakout << 4); |
| 2904 | |
| 2905 // Use extreme low threshold for static frames to limit skipping. | |
| 2906 if (cpi->enable_encode_breakout == 2) | |
| 2907 max_thresh = 128; | |
| 2908 | 2910 |
| 2909 // Calculate threshold according to dequant value. | 2911 // Calculate threshold according to dequant value. |
| 2910 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; | 2912 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; |
| 2911 | 2913 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh); |
| 2912 // Use encode_breakout input if it is bigger than internal threshold. | |
| 2913 if (thresh_ac < encode_breakout) | |
| 2914 thresh_ac = encode_breakout; | |
| 2915 | |
| 2916 // Set a maximum for threshold to avoid big PSNR loss in low bitrate case. | |
| 2917 if (thresh_ac > max_thresh) | |
| 2918 thresh_ac = max_thresh; | |
| 2919 | 2914 |
| 2920 var = cpi->fn_ptr[y_size].vf(x->plane[0].src.buf, x->plane[0].src.stride, | 2915 var = cpi->fn_ptr[y_size].vf(x->plane[0].src.buf, x->plane[0].src.stride, |
| 2921 xd->plane[0].dst.buf, | 2916 xd->plane[0].dst.buf, |
| 2922 xd->plane[0].dst.stride, &sse); | 2917 xd->plane[0].dst.stride, &sse); |
| 2923 | 2918 |
| 2924 // Adjust threshold according to partition size. | 2919 // Adjust threshold according to partition size. |
| 2925 thresh_ac >>= 8 - (b_width_log2_lookup[bsize] + | 2920 thresh_ac >>= 8 - (b_width_log2_lookup[bsize] + |
| 2926 b_height_log2_lookup[bsize]); | 2921 b_height_log2_lookup[bsize]); |
| 2927 | 2922 |
| 2928 // Y skipping condition checking | 2923 // Y skipping condition checking |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3243 cpi->rd_thresh_freq_fact[bsize][mode_index] >> 5)) || | 3238 cpi->rd_thresh_freq_fact[bsize][mode_index] >> 5)) || |
| 3244 cpi->rd_threshes[segment_id][bsize][mode_index] == INT_MAX) | 3239 cpi->rd_threshes[segment_id][bsize][mode_index] == INT_MAX) |
| 3245 continue; | 3240 continue; |
| 3246 | 3241 |
| 3247 // Do not allow compound prediction if the segment level reference | 3242 // Do not allow compound prediction if the segment level reference |
| 3248 // frame feature is in use as in this case there can only be one reference. | 3243 // frame feature is in use as in this case there can only be one reference. |
| 3249 if ((second_ref_frame > INTRA_FRAME) && | 3244 if ((second_ref_frame > INTRA_FRAME) && |
| 3250 vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) | 3245 vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
| 3251 continue; | 3246 continue; |
| 3252 | 3247 |
| 3253 // Skip some checking based on small partitions' result. | |
| 3254 if (x->fast_ms > 1 && !ref_frame) | |
| 3255 continue; | |
| 3256 if (x->fast_ms > 2 && ref_frame != x->subblock_ref) | |
| 3257 continue; | |
| 3258 | |
| 3259 mbmi->ref_frame[0] = ref_frame; | 3248 mbmi->ref_frame[0] = ref_frame; |
| 3260 mbmi->ref_frame[1] = second_ref_frame; | 3249 mbmi->ref_frame[1] = second_ref_frame; |
| 3261 | 3250 |
| 3262 if (!(ref_frame == INTRA_FRAME | 3251 if (!(ref_frame == INTRA_FRAME |
| 3263 || (cpi->ref_frame_flags & flag_list[ref_frame]))) { | 3252 || (cpi->ref_frame_flags & flag_list[ref_frame]))) { |
| 3264 continue; | 3253 continue; |
| 3265 } | 3254 } |
| 3266 if (!(second_ref_frame == NONE | 3255 if (!(second_ref_frame == NONE |
| 3267 || (cpi->ref_frame_flags & flag_list[second_ref_frame]))) { | 3256 || (cpi->ref_frame_flags & flag_list[second_ref_frame]))) { |
| 3268 continue; | 3257 continue; |
| 3269 } | 3258 } |
| 3270 | 3259 |
| 3271 comp_pred = second_ref_frame > INTRA_FRAME; | 3260 comp_pred = second_ref_frame > INTRA_FRAME; |
| 3272 if (comp_pred) { | 3261 if (comp_pred) { |
| 3273 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) | 3262 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) |
| 3274 if (vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) | 3263 if (vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) |
| 3275 continue; | 3264 continue; |
| 3276 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) | 3265 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) |
| 3277 if (ref_frame != best_inter_ref_frame && | 3266 if (ref_frame != best_inter_ref_frame && |
| 3278 second_ref_frame != best_inter_ref_frame) | 3267 second_ref_frame != best_inter_ref_frame) |
| 3279 continue; | 3268 continue; |
| 3280 } | 3269 } |
| 3281 | 3270 |
| 3282 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); | 3271 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); |
| 3283 mbmi->uv_mode = DC_PRED; | 3272 mbmi->uv_mode = DC_PRED; |
| 3284 | 3273 |
| 3285 // Evaluate all sub-pel filters irrespective of whether we can use | 3274 // Evaluate all sub-pel filters irrespective of whether we can use |
| 3286 // them for this frame. | 3275 // them for this frame. |
| 3287 mbmi->interp_filter = cm->interp_filter; | 3276 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP |
| 3288 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 3277 : cm->interp_filter; |
| 3278 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 3289 | 3279 |
| 3290 if (comp_pred) { | 3280 if (comp_pred) { |
| 3291 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) | 3281 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) |
| 3292 continue; | 3282 continue; |
| 3293 | 3283 |
| 3294 mode_excluded = mode_excluded ? mode_excluded | 3284 mode_excluded = mode_excluded ? mode_excluded |
| 3295 : cm->reference_mode == SINGLE_REFERENCE; | 3285 : cm->reference_mode == SINGLE_REFERENCE; |
| 3296 } else { | 3286 } else { |
| 3297 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) | 3287 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) |
| 3298 mode_excluded = mode_excluded ? | 3288 mode_excluded = mode_excluded ? |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3902 | 3892 |
| 3903 if (second_ref_frame > 0 && | 3893 if (second_ref_frame > 0 && |
| 3904 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) | 3894 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) |
| 3905 continue; | 3895 continue; |
| 3906 | 3896 |
| 3907 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); | 3897 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); |
| 3908 mbmi->uv_mode = DC_PRED; | 3898 mbmi->uv_mode = DC_PRED; |
| 3909 | 3899 |
| 3910 // Evaluate all sub-pel filters irrespective of whether we can use | 3900 // Evaluate all sub-pel filters irrespective of whether we can use |
| 3911 // them for this frame. | 3901 // them for this frame. |
| 3912 mbmi->interp_filter = cm->interp_filter; | 3902 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP |
| 3913 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 3903 : cm->interp_filter; |
| 3904 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 3914 | 3905 |
| 3915 if (comp_pred) { | 3906 if (comp_pred) { |
| 3916 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) | 3907 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) |
| 3917 continue; | 3908 continue; |
| 3918 | 3909 |
| 3919 mode_excluded = mode_excluded ? mode_excluded | 3910 mode_excluded = mode_excluded ? mode_excluded |
| 3920 : cm->reference_mode == SINGLE_REFERENCE; | 3911 : cm->reference_mode == SINGLE_REFERENCE; |
| 3921 } else { | 3912 } else { |
| 3922 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) { | 3913 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) { |
| 3923 mode_excluded = mode_excluded ? | 3914 mode_excluded = mode_excluded ? |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4026 } else if (cpi->sf.adaptive_pred_interp_filter == 2) { | 4017 } else if (cpi->sf.adaptive_pred_interp_filter == 2) { |
| 4027 tmp_best_filter = ctx->pred_interp_filter < SWITCHABLE ? | 4018 tmp_best_filter = ctx->pred_interp_filter < SWITCHABLE ? |
| 4028 ctx->pred_interp_filter : 0; | 4019 ctx->pred_interp_filter : 0; |
| 4029 } else { | 4020 } else { |
| 4030 for (switchable_filter_index = 0; | 4021 for (switchable_filter_index = 0; |
| 4031 switchable_filter_index < SWITCHABLE_FILTERS; | 4022 switchable_filter_index < SWITCHABLE_FILTERS; |
| 4032 ++switchable_filter_index) { | 4023 ++switchable_filter_index) { |
| 4033 int newbest, rs; | 4024 int newbest, rs; |
| 4034 int64_t rs_rd; | 4025 int64_t rs_rd; |
| 4035 mbmi->interp_filter = switchable_filter_index; | 4026 mbmi->interp_filter = switchable_filter_index; |
| 4036 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 4027 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 4037 | |
| 4038 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, | 4028 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, |
| 4039 &mbmi->ref_mvs[ref_frame][0], | 4029 &mbmi->ref_mvs[ref_frame][0], |
| 4040 second_ref, | 4030 second_ref, |
| 4041 best_yrd, | 4031 best_yrd, |
| 4042 &rate, &rate_y, &distortion, | 4032 &rate, &rate_y, &distortion, |
| 4043 &skippable, &total_sse, | 4033 &skippable, &total_sse, |
| 4044 (int)this_rd_thresh, seg_mvs, | 4034 (int)this_rd_thresh, seg_mvs, |
| 4045 bsi, switchable_filter_index, | 4035 bsi, switchable_filter_index, |
| 4046 mi_row, mi_col); | 4036 mi_row, mi_col); |
| 4047 | 4037 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4092 } | 4082 } |
| 4093 } // switchable_filter_index loop | 4083 } // switchable_filter_index loop |
| 4094 } | 4084 } |
| 4095 } | 4085 } |
| 4096 | 4086 |
| 4097 if (tmp_best_rdu == INT64_MAX && pred_exists) | 4087 if (tmp_best_rdu == INT64_MAX && pred_exists) |
| 4098 continue; | 4088 continue; |
| 4099 | 4089 |
| 4100 mbmi->interp_filter = (cm->interp_filter == SWITCHABLE ? | 4090 mbmi->interp_filter = (cm->interp_filter == SWITCHABLE ? |
| 4101 tmp_best_filter : cm->interp_filter); | 4091 tmp_best_filter : cm->interp_filter); |
| 4102 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); | 4092 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 4103 if (!pred_exists) { | 4093 if (!pred_exists) { |
| 4104 // Handles the special case when a filter that is not in the | 4094 // Handles the special case when a filter that is not in the |
| 4105 // switchable list (bilinear, 6-tap) is indicated at the frame level | 4095 // switchable list (bilinear, 6-tap) is indicated at the frame level |
| 4106 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, | 4096 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, |
| 4107 &mbmi->ref_mvs[ref_frame][0], | 4097 &mbmi->ref_mvs[ref_frame][0], |
| 4108 second_ref, | 4098 second_ref, |
| 4109 best_yrd, | 4099 best_yrd, |
| 4110 &rate, &rate_y, &distortion, | 4100 &rate, &rate_y, &distortion, |
| 4111 &skippable, &total_sse, | 4101 &skippable, &total_sse, |
| 4112 (int)this_rd_thresh, seg_mvs, | 4102 (int)this_rd_thresh, seg_mvs, |
| 4113 bsi, 0, | 4103 bsi, 0, |
| 4114 mi_row, mi_col); | 4104 mi_row, mi_col); |
| 4115 if (tmp_rd == INT64_MAX) | 4105 if (tmp_rd == INT64_MAX) |
| 4116 continue; | 4106 continue; |
| 4117 } else { | 4107 } else { |
| 4118 if (cm->interp_filter == SWITCHABLE) { | |
| 4119 int rs = get_switchable_rate(x); | |
| 4120 tmp_best_rdu -= RDCOST(x->rdmult, x->rddiv, rs, 0); | |
| 4121 } | |
| 4122 tmp_rd = tmp_best_rdu; | |
| 4123 total_sse = tmp_best_sse; | 4108 total_sse = tmp_best_sse; |
| 4124 rate = tmp_best_rate; | 4109 rate = tmp_best_rate; |
| 4125 rate_y = tmp_best_ratey; | 4110 rate_y = tmp_best_ratey; |
| 4126 distortion = tmp_best_distortion; | 4111 distortion = tmp_best_distortion; |
| 4127 skippable = tmp_best_skippable; | 4112 skippable = tmp_best_skippable; |
| 4128 *mbmi = tmp_best_mbmode; | 4113 *mbmi = tmp_best_mbmode; |
| 4129 for (i = 0; i < 4; i++) | 4114 for (i = 0; i < 4; i++) |
| 4130 xd->mi_8x8[0]->bmi[i] = tmp_best_bmodes[i]; | 4115 xd->mi_8x8[0]->bmi[i] = tmp_best_bmodes[i]; |
| 4131 } | 4116 } |
| 4132 | 4117 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4446 | 4431 |
| 4447 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 4432 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
| 4448 store_coding_context(x, ctx, best_mode_index, | 4433 store_coding_context(x, ctx, best_mode_index, |
| 4449 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], | 4434 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], |
| 4450 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : | 4435 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : |
| 4451 mbmi->ref_frame[1]][0], | 4436 mbmi->ref_frame[1]][0], |
| 4452 best_pred_diff, best_tx_diff, best_filter_diff); | 4437 best_pred_diff, best_tx_diff, best_filter_diff); |
| 4453 | 4438 |
| 4454 return best_rd; | 4439 return best_rd; |
| 4455 } | 4440 } |
| OLD | NEW |