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 |
11 #include <assert.h> | 11 #include <assert.h> |
12 #include <math.h> | 12 #include <math.h> |
13 | 13 |
14 #include "./vp9_rtcd.h" | 14 #include "./vp9_rtcd.h" |
15 #include "./vpx_dsp_rtcd.h" | 15 #include "./vpx_dsp_rtcd.h" |
16 | 16 |
17 #include "vpx_mem/vpx_mem.h" | 17 #include "vpx_mem/vpx_mem.h" |
18 #include "vpx_ports/mem.h" | 18 #include "vpx_ports/mem.h" |
| 19 #include "vpx_ports/system_state.h" |
19 | 20 |
20 #include "vp9/common/vp9_common.h" | 21 #include "vp9/common/vp9_common.h" |
21 #include "vp9/common/vp9_entropy.h" | 22 #include "vp9/common/vp9_entropy.h" |
22 #include "vp9/common/vp9_entropymode.h" | 23 #include "vp9/common/vp9_entropymode.h" |
23 #include "vp9/common/vp9_idct.h" | 24 #include "vp9/common/vp9_idct.h" |
24 #include "vp9/common/vp9_mvref_common.h" | 25 #include "vp9/common/vp9_mvref_common.h" |
25 #include "vp9/common/vp9_pred_common.h" | 26 #include "vp9/common/vp9_pred_common.h" |
26 #include "vp9/common/vp9_quant_common.h" | 27 #include "vp9/common/vp9_quant_common.h" |
27 #include "vp9/common/vp9_reconinter.h" | 28 #include "vp9/common/vp9_reconinter.h" |
28 #include "vp9/common/vp9_reconintra.h" | 29 #include "vp9/common/vp9_reconintra.h" |
29 #include "vp9/common/vp9_scan.h" | 30 #include "vp9/common/vp9_scan.h" |
30 #include "vp9/common/vp9_seg_common.h" | 31 #include "vp9/common/vp9_seg_common.h" |
31 #include "vp9/common/vp9_systemdependent.h" | |
32 | 32 |
33 #include "vp9/encoder/vp9_cost.h" | 33 #include "vp9/encoder/vp9_cost.h" |
34 #include "vp9/encoder/vp9_encodemb.h" | 34 #include "vp9/encoder/vp9_encodemb.h" |
35 #include "vp9/encoder/vp9_encodemv.h" | 35 #include "vp9/encoder/vp9_encodemv.h" |
36 #include "vp9/encoder/vp9_encoder.h" | 36 #include "vp9/encoder/vp9_encoder.h" |
37 #include "vp9/encoder/vp9_mcomp.h" | 37 #include "vp9/encoder/vp9_mcomp.h" |
38 #include "vp9/encoder/vp9_quantize.h" | 38 #include "vp9/encoder/vp9_quantize.h" |
39 #include "vp9/encoder/vp9_ratectrl.h" | 39 #include "vp9/encoder/vp9_ratectrl.h" |
40 #include "vp9/encoder/vp9_rd.h" | 40 #include "vp9/encoder/vp9_rd.h" |
41 #include "vp9/encoder/vp9_rdopt.h" | 41 #include "vp9/encoder/vp9_rdopt.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 for (i = 0; i < MAX_MB_PLANE; ++i) { | 185 for (i = 0; i < MAX_MB_PLANE; ++i) { |
186 struct macroblock_plane *const p = &x->plane[i]; | 186 struct macroblock_plane *const p = &x->plane[i]; |
187 struct macroblockd_plane *const pd = &xd->plane[i]; | 187 struct macroblockd_plane *const pd = &xd->plane[i]; |
188 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); | 188 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); |
189 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 189 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
190 const BLOCK_SIZE unit_size = txsize_to_bsize[max_tx_size]; | 190 const BLOCK_SIZE unit_size = txsize_to_bsize[max_tx_size]; |
191 const int64_t dc_thr = p->quant_thred[0] >> shift; | 191 const int64_t dc_thr = p->quant_thred[0] >> shift; |
192 const int64_t ac_thr = p->quant_thred[1] >> shift; | 192 const int64_t ac_thr = p->quant_thred[1] >> shift; |
193 // The low thresholds are used to measure if the prediction errors are | 193 // The low thresholds are used to measure if the prediction errors are |
194 // low enough so that we can skip the mode search. | 194 // low enough so that we can skip the mode search. |
195 const int64_t low_dc_thr = MIN(50, dc_thr >> 2); | 195 const int64_t low_dc_thr = VPXMIN(50, dc_thr >> 2); |
196 const int64_t low_ac_thr = MIN(80, ac_thr >> 2); | 196 const int64_t low_ac_thr = VPXMIN(80, ac_thr >> 2); |
197 int bw = 1 << (b_width_log2_lookup[bs] - b_width_log2_lookup[unit_size]); | 197 int bw = 1 << (b_width_log2_lookup[bs] - b_width_log2_lookup[unit_size]); |
198 int bh = 1 << (b_height_log2_lookup[bs] - b_width_log2_lookup[unit_size]); | 198 int bh = 1 << (b_height_log2_lookup[bs] - b_width_log2_lookup[unit_size]); |
199 int idx, idy; | 199 int idx, idy; |
200 int lw = b_width_log2_lookup[unit_size] + 2; | 200 int lw = b_width_log2_lookup[unit_size] + 2; |
201 int lh = b_height_log2_lookup[unit_size] + 2; | 201 int lh = b_height_log2_lookup[unit_size] + 2; |
202 | 202 |
203 sum_sse = 0; | 203 sum_sse = 0; |
204 | 204 |
205 for (idy = 0; idy < bh; ++idy) { | 205 for (idy = 0; idy < bh; ++idy) { |
206 for (idx = 0; idx < bw; ++idx) { | 206 for (idx = 0; idx < bw; ++idx) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 if (x->plane[plane].eobs[block]) { | 498 if (x->plane[plane].eobs[block]) { |
499 const int64_t orig_sse = (int64_t)coeff[0] * coeff[0]; | 499 const int64_t orig_sse = (int64_t)coeff[0] * coeff[0]; |
500 const int64_t resd_sse = coeff[0] - dqcoeff[0]; | 500 const int64_t resd_sse = coeff[0] - dqcoeff[0]; |
501 int64_t dc_correct = orig_sse - resd_sse * resd_sse; | 501 int64_t dc_correct = orig_sse - resd_sse * resd_sse; |
502 #if CONFIG_VP9_HIGHBITDEPTH | 502 #if CONFIG_VP9_HIGHBITDEPTH |
503 dc_correct >>= ((xd->bd - 8) * 2); | 503 dc_correct >>= ((xd->bd - 8) * 2); |
504 #endif | 504 #endif |
505 if (tx_size != TX_32X32) | 505 if (tx_size != TX_32X32) |
506 dc_correct >>= 2; | 506 dc_correct >>= 2; |
507 | 507 |
508 dist = MAX(0, sse - dc_correct); | 508 dist = VPXMAX(0, sse - dc_correct); |
509 } | 509 } |
510 } else { | 510 } else { |
511 // SKIP_TXFM_AC_DC | 511 // SKIP_TXFM_AC_DC |
512 // skip forward transform | 512 // skip forward transform |
513 x->plane[plane].eobs[block] = 0; | 513 x->plane[plane].eobs[block] = 0; |
514 sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4; | 514 sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4; |
515 dist = sse; | 515 dist = sse; |
516 } | 516 } |
517 } else { | 517 } else { |
518 // full forward transform and quantization | 518 // full forward transform and quantization |
519 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); | 519 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); |
520 dist_block(x, plane, block, tx_size, &dist, &sse); | 520 dist_block(x, plane, block, tx_size, &dist, &sse); |
521 } | 521 } |
522 | 522 |
523 rd = RDCOST(x->rdmult, x->rddiv, 0, dist); | 523 rd = RDCOST(x->rdmult, x->rddiv, 0, dist); |
524 if (args->this_rd + rd > args->best_rd) { | 524 if (args->this_rd + rd > args->best_rd) { |
525 args->exit_early = 1; | 525 args->exit_early = 1; |
526 return; | 526 return; |
527 } | 527 } |
528 | 528 |
529 rate = rate_block(plane, block, plane_bsize, tx_size, args); | 529 rate = rate_block(plane, block, plane_bsize, tx_size, args); |
530 rd1 = RDCOST(x->rdmult, x->rddiv, rate, dist); | 530 rd1 = RDCOST(x->rdmult, x->rddiv, rate, dist); |
531 rd2 = RDCOST(x->rdmult, x->rddiv, 0, sse); | 531 rd2 = RDCOST(x->rdmult, x->rddiv, 0, sse); |
532 | 532 |
533 // TODO(jingning): temporarily enabled only for luma component | 533 // TODO(jingning): temporarily enabled only for luma component |
534 rd = MIN(rd1, rd2); | 534 rd = VPXMIN(rd1, rd2); |
535 if (plane == 0) | 535 if (plane == 0) |
536 x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] || | 536 x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] || |
537 (rd1 > rd2 && !xd->lossless); | 537 (rd1 > rd2 && !xd->lossless); |
538 | 538 |
539 args->this_rate += rate; | 539 args->this_rate += rate; |
540 args->this_dist += dist; | 540 args->this_dist += dist; |
541 args->this_sse += sse; | 541 args->this_sse += sse; |
542 args->this_rd += rd; | 542 args->this_rd += rd; |
543 | 543 |
544 if (args->this_rd > args->best_rd) { | 544 if (args->this_rd > args->best_rd) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 int *rate, int64_t *distortion, | 590 int *rate, int64_t *distortion, |
591 int *skip, int64_t *sse, | 591 int *skip, int64_t *sse, |
592 int64_t ref_best_rd, | 592 int64_t ref_best_rd, |
593 BLOCK_SIZE bs) { | 593 BLOCK_SIZE bs) { |
594 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 594 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
595 VP9_COMMON *const cm = &cpi->common; | 595 VP9_COMMON *const cm = &cpi->common; |
596 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 596 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
597 MACROBLOCKD *const xd = &x->e_mbd; | 597 MACROBLOCKD *const xd = &x->e_mbd; |
598 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 598 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
599 | 599 |
600 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); | 600 mbmi->tx_size = VPXMIN(max_tx_size, largest_tx_size); |
601 | 601 |
602 txfm_rd_in_plane(x, rate, distortion, skip, | 602 txfm_rd_in_plane(x, rate, distortion, skip, |
603 sse, ref_best_rd, 0, bs, | 603 sse, ref_best_rd, 0, bs, |
604 mbmi->tx_size, cpi->sf.use_fast_coef_costing); | 604 mbmi->tx_size, cpi->sf.use_fast_coef_costing); |
605 } | 605 } |
606 | 606 |
607 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, | 607 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, |
608 int *rate, | 608 int *rate, |
609 int64_t *distortion, | 609 int64_t *distortion, |
610 int *skip, | 610 int *skip, |
(...skipping 19 matching lines...) Expand all Loading... |
630 | 630 |
631 const vpx_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc->tx_probs); | 631 const vpx_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc->tx_probs); |
632 assert(skip_prob > 0); | 632 assert(skip_prob > 0); |
633 s0 = vp9_cost_bit(skip_prob, 0); | 633 s0 = vp9_cost_bit(skip_prob, 0); |
634 s1 = vp9_cost_bit(skip_prob, 1); | 634 s1 = vp9_cost_bit(skip_prob, 1); |
635 | 635 |
636 if (cm->tx_mode == TX_MODE_SELECT) { | 636 if (cm->tx_mode == TX_MODE_SELECT) { |
637 start_tx = max_tx_size; | 637 start_tx = max_tx_size; |
638 end_tx = 0; | 638 end_tx = 0; |
639 } else { | 639 } else { |
640 TX_SIZE chosen_tx_size = MIN(max_tx_size, | 640 TX_SIZE chosen_tx_size = VPXMIN(max_tx_size, |
641 tx_mode_to_biggest_tx_size[cm->tx_mode]); | 641 tx_mode_to_biggest_tx_size[cm->tx_mode]); |
642 start_tx = chosen_tx_size; | 642 start_tx = chosen_tx_size; |
643 end_tx = chosen_tx_size; | 643 end_tx = chosen_tx_size; |
644 } | 644 } |
645 | 645 |
646 for (n = start_tx; n >= end_tx; n--) { | 646 for (n = start_tx; n >= end_tx; n--) { |
| 647 int r_tx_size = 0; |
| 648 for (m = 0; m <= n - (n == (int) max_tx_size); m++) { |
| 649 if (m == n) |
| 650 r_tx_size += vp9_cost_zero(tx_probs[m]); |
| 651 else |
| 652 r_tx_size += vp9_cost_one(tx_probs[m]); |
| 653 } |
647 txfm_rd_in_plane(x, &r[n][0], &d[n], &s[n], | 654 txfm_rd_in_plane(x, &r[n][0], &d[n], &s[n], |
648 &sse[n], ref_best_rd, 0, bs, n, | 655 &sse[n], ref_best_rd, 0, bs, n, |
649 cpi->sf.use_fast_coef_costing); | 656 cpi->sf.use_fast_coef_costing); |
650 r[n][1] = r[n][0]; | 657 r[n][1] = r[n][0]; |
651 if (r[n][0] < INT_MAX) { | 658 if (r[n][0] < INT_MAX) { |
652 for (m = 0; m <= n - (n == (int) max_tx_size); m++) { | 659 r[n][1] += r_tx_size; |
653 if (m == n) | |
654 r[n][1] += vp9_cost_zero(tx_probs[m]); | |
655 else | |
656 r[n][1] += vp9_cost_one(tx_probs[m]); | |
657 } | |
658 } | 660 } |
659 if (d[n] == INT64_MAX) { | 661 if (d[n] == INT64_MAX || r[n][0] == INT_MAX) { |
660 rd[n][0] = rd[n][1] = INT64_MAX; | 662 rd[n][0] = rd[n][1] = INT64_MAX; |
661 } else if (s[n]) { | 663 } else if (s[n]) { |
662 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]); | 664 if (is_inter_block(mbmi)) { |
| 665 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, sse[n]); |
| 666 } else { |
| 667 rd[n][0] = RDCOST(x->rdmult, x->rddiv, s1, sse[n]); |
| 668 rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1 + r_tx_size, sse[n]); |
| 669 } |
663 } else { | 670 } else { |
664 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]); | 671 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]); |
665 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]); | 672 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]); |
666 } | 673 } |
667 | 674 |
668 // Early termination in transform size search. | 675 // Early termination in transform size search. |
669 if (cpi->sf.tx_size_search_breakout && | 676 if (cpi->sf.tx_size_search_breakout && |
670 (rd[n][1] == INT64_MAX || | 677 (rd[n][1] == INT64_MAX || |
671 (n < (int) max_tx_size && rd[n][1] > rd[n + 1][1]) || | 678 (n < (int) max_tx_size && rd[n][1] > rd[n + 1][1]) || |
672 s[n] == 1)) | 679 s[n] == 1)) |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 int *bmode_costs; | 1045 int *bmode_costs; |
1039 const MODE_INFO *above_mi = xd->above_mi; | 1046 const MODE_INFO *above_mi = xd->above_mi; |
1040 const MODE_INFO *left_mi = xd->left_mi; | 1047 const MODE_INFO *left_mi = xd->left_mi; |
1041 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); | 1048 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); |
1042 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); | 1049 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); |
1043 bmode_costs = cpi->y_mode_costs[A][L]; | 1050 bmode_costs = cpi->y_mode_costs[A][L]; |
1044 | 1051 |
1045 memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); | 1052 memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); |
1046 /* Y Search for intra prediction mode */ | 1053 /* Y Search for intra prediction mode */ |
1047 for (mode = DC_PRED; mode <= TM_PRED; mode++) { | 1054 for (mode = DC_PRED; mode <= TM_PRED; mode++) { |
1048 | |
1049 if (cpi->sf.use_nonrd_pick_mode) { | 1055 if (cpi->sf.use_nonrd_pick_mode) { |
1050 // These speed features are turned on in hybrid non-RD and RD mode | 1056 // These speed features are turned on in hybrid non-RD and RD mode |
1051 // for key frame coding in the context of real-time setting. | 1057 // for key frame coding in the context of real-time setting. |
1052 if (conditional_skipintra(mode, mode_selected)) | 1058 if (conditional_skipintra(mode, mode_selected)) |
1053 continue; | 1059 continue; |
1054 if (*skippable) | 1060 if (*skippable) |
1055 break; | 1061 break; |
1056 } | 1062 } |
1057 | 1063 |
1058 mic->mbmi.mode = mode; | 1064 mic->mbmi.mode = mode; |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 #else | 1382 #else |
1377 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), | 1383 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), |
1378 16, &ssz); | 1384 16, &ssz); |
1379 #endif // CONFIG_VP9_HIGHBITDEPTH | 1385 #endif // CONFIG_VP9_HIGHBITDEPTH |
1380 thissse += ssz; | 1386 thissse += ssz; |
1381 thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4, | 1387 thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4, |
1382 so->scan, so->neighbors, | 1388 so->scan, so->neighbors, |
1383 cpi->sf.use_fast_coef_costing); | 1389 cpi->sf.use_fast_coef_costing); |
1384 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2); | 1390 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2); |
1385 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2); | 1391 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2); |
1386 rd = MIN(rd1, rd2); | 1392 rd = VPXMIN(rd1, rd2); |
1387 if (rd >= best_yrd) | 1393 if (rd >= best_yrd) |
1388 return INT64_MAX; | 1394 return INT64_MAX; |
1389 } | 1395 } |
1390 } | 1396 } |
1391 | 1397 |
1392 *distortion = thisdistortion >> 2; | 1398 *distortion = thisdistortion >> 2; |
1393 *labelyrate = thisrate; | 1399 *labelyrate = thisrate; |
1394 *sse = thissse >> 2; | 1400 *sse = thissse >> 2; |
1395 | 1401 |
1396 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion); | 1402 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion); |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 // use previous block's result as next block's MV predictor. | 1801 // use previous block's result as next block's MV predictor. |
1796 if (i > 0) { | 1802 if (i > 0) { |
1797 bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int; | 1803 bsi->mvp.as_int = mi->bmi[i - 1].as_mv[0].as_int; |
1798 if (i == 2) | 1804 if (i == 2) |
1799 bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int; | 1805 bsi->mvp.as_int = mi->bmi[i - 2].as_mv[0].as_int; |
1800 } | 1806 } |
1801 } | 1807 } |
1802 if (i == 0) | 1808 if (i == 0) |
1803 max_mv = x->max_mv_context[mbmi->ref_frame[0]]; | 1809 max_mv = x->max_mv_context[mbmi->ref_frame[0]]; |
1804 else | 1810 else |
1805 max_mv = MAX(abs(bsi->mvp.as_mv.row), abs(bsi->mvp.as_mv.col)) >> 3; | 1811 max_mv = |
| 1812 VPXMAX(abs(bsi->mvp.as_mv.row), abs(bsi->mvp.as_mv.col)) >> 3; |
1806 | 1813 |
1807 if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) { | 1814 if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) { |
1808 // Take wtd average of the step_params based on the last frame's | 1815 // Take wtd average of the step_params based on the last frame's |
1809 // max mv magnitude and the best ref mvs of the current block for | 1816 // max mv magnitude and the best ref mvs of the current block for |
1810 // the given reference. | 1817 // the given reference. |
1811 step_param = (vp9_init_search_range(max_mv) + | 1818 step_param = (vp9_init_search_range(max_mv) + |
1812 cpi->mv_step_param) / 2; | 1819 cpi->mv_step_param) / 2; |
1813 } else { | 1820 } else { |
1814 step_param = cpi->mv_step_param; | 1821 step_param = cpi->mv_step_param; |
1815 } | 1822 } |
1816 | 1823 |
1817 mvp_full.row = bsi->mvp.as_mv.row >> 3; | 1824 mvp_full.row = bsi->mvp.as_mv.row >> 3; |
1818 mvp_full.col = bsi->mvp.as_mv.col >> 3; | 1825 mvp_full.col = bsi->mvp.as_mv.col >> 3; |
1819 | 1826 |
1820 if (cpi->sf.adaptive_motion_search) { | 1827 if (cpi->sf.adaptive_motion_search) { |
1821 mvp_full.row = x->pred_mv[mbmi->ref_frame[0]].row >> 3; | 1828 mvp_full.row = x->pred_mv[mbmi->ref_frame[0]].row >> 3; |
1822 mvp_full.col = x->pred_mv[mbmi->ref_frame[0]].col >> 3; | 1829 mvp_full.col = x->pred_mv[mbmi->ref_frame[0]].col >> 3; |
1823 step_param = MAX(step_param, 8); | 1830 step_param = VPXMAX(step_param, 8); |
1824 } | 1831 } |
1825 | 1832 |
1826 // adjust src pointer for this block | 1833 // adjust src pointer for this block |
1827 mi_buf_shift(x, i); | 1834 mi_buf_shift(x, i); |
1828 | 1835 |
1829 vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv); | 1836 vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv); |
1830 | 1837 |
1831 bestsme = vp9_full_pixel_search( | 1838 bestsme = vp9_full_pixel_search( |
1832 cpi, x, bsize, &mvp_full, step_param, sadpb, | 1839 cpi, x, bsize, &mvp_full, step_param, sadpb, |
1833 cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL, | 1840 cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL, |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2218 // motion search code to be used without additional modifications. | 2225 // motion search code to be used without additional modifications. |
2219 for (i = 0; i < MAX_MB_PLANE; i++) | 2226 for (i = 0; i < MAX_MB_PLANE; i++) |
2220 backup_yv12[i] = xd->plane[i].pre[0]; | 2227 backup_yv12[i] = xd->plane[i].pre[0]; |
2221 | 2228 |
2222 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); | 2229 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
2223 } | 2230 } |
2224 | 2231 |
2225 vp9_set_mv_search_range(x, &ref_mv); | 2232 vp9_set_mv_search_range(x, &ref_mv); |
2226 | 2233 |
2227 // Work out the size of the first step in the mv step search. | 2234 // Work out the size of the first step in the mv step search. |
2228 // 0 here is maximum length first step. 1 is MAX >> 1 etc. | 2235 // 0 here is maximum length first step. 1 is VPXMAX >> 1 etc. |
2229 if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) { | 2236 if (cpi->sf.mv.auto_mv_step_size && cm->show_frame) { |
2230 // Take wtd average of the step_params based on the last frame's | 2237 // Take wtd average of the step_params based on the last frame's |
2231 // max mv magnitude and that based on the best ref mvs of the current | 2238 // max mv magnitude and that based on the best ref mvs of the current |
2232 // block for the given reference. | 2239 // block for the given reference. |
2233 step_param = (vp9_init_search_range(x->max_mv_context[ref]) + | 2240 step_param = (vp9_init_search_range(x->max_mv_context[ref]) + |
2234 cpi->mv_step_param) / 2; | 2241 cpi->mv_step_param) / 2; |
2235 } else { | 2242 } else { |
2236 step_param = cpi->mv_step_param; | 2243 step_param = cpi->mv_step_param; |
2237 } | 2244 } |
2238 | 2245 |
2239 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64) { | 2246 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64) { |
2240 int boffset = 2 * (b_width_log2_lookup[BLOCK_64X64] - | 2247 int boffset = |
2241 MIN(b_height_log2_lookup[bsize], b_width_log2_lookup[bsize])); | 2248 2 * (b_width_log2_lookup[BLOCK_64X64] - |
2242 step_param = MAX(step_param, boffset); | 2249 VPXMIN(b_height_log2_lookup[bsize], b_width_log2_lookup[bsize])); |
| 2250 step_param = VPXMAX(step_param, boffset); |
2243 } | 2251 } |
2244 | 2252 |
2245 if (cpi->sf.adaptive_motion_search) { | 2253 if (cpi->sf.adaptive_motion_search) { |
2246 int bwl = b_width_log2_lookup[bsize]; | 2254 int bwl = b_width_log2_lookup[bsize]; |
2247 int bhl = b_height_log2_lookup[bsize]; | 2255 int bhl = b_height_log2_lookup[bsize]; |
2248 int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4); | 2256 int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4); |
2249 | 2257 |
2250 if (tlevel < 5) | 2258 if (tlevel < 5) |
2251 step_param += 2; | 2259 step_param += 2; |
2252 | 2260 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2453 | 2461 |
2454 frame_mv[refs[0]].as_int = | 2462 frame_mv[refs[0]].as_int = |
2455 xd->mi[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; | 2463 xd->mi[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; |
2456 single_newmv[refs[0]].as_int = tmp_mv.as_int; | 2464 single_newmv[refs[0]].as_int = tmp_mv.as_int; |
2457 | 2465 |
2458 // Estimate the rate implications of a new mv but discount this | 2466 // Estimate the rate implications of a new mv but discount this |
2459 // under certain circumstances where we want to help initiate a weak | 2467 // under certain circumstances where we want to help initiate a weak |
2460 // motion field, where the distortion gain for a single block may not | 2468 // motion field, where the distortion gain for a single block may not |
2461 // be enough to overcome the cost of a new mv. | 2469 // be enough to overcome the cost of a new mv. |
2462 if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0])) { | 2470 if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0])) { |
2463 *rate2 += MAX((rate_mv / NEW_MV_DISCOUNT_FACTOR), 1); | 2471 *rate2 += VPXMAX((rate_mv / NEW_MV_DISCOUNT_FACTOR), 1); |
2464 } else { | 2472 } else { |
2465 *rate2 += rate_mv; | 2473 *rate2 += rate_mv; |
2466 } | 2474 } |
2467 } | 2475 } |
2468 } | 2476 } |
2469 | 2477 |
2470 for (i = 0; i < is_comp_pred + 1; ++i) { | 2478 for (i = 0; i < is_comp_pred + 1; ++i) { |
2471 cur_mv[i] = frame_mv[refs[i]]; | 2479 cur_mv[i] = frame_mv[refs[i]]; |
2472 // Clip "next_nearest" so that it does not extend to far out of image | 2480 // Clip "next_nearest" so that it does not extend to far out of image |
2473 if (this_mode != NEWMV) | 2481 if (this_mode != NEWMV) |
2474 clamp_mv2(&cur_mv[i].as_mv, xd); | 2482 clamp_mv2(&cur_mv[i].as_mv, xd); |
2475 | 2483 |
2476 if (mv_check_bounds(x, &cur_mv[i].as_mv)) | 2484 if (mv_check_bounds(x, &cur_mv[i].as_mv)) |
2477 return INT64_MAX; | 2485 return INT64_MAX; |
2478 mbmi->mv[i].as_int = cur_mv[i].as_int; | 2486 mbmi->mv[i].as_int = cur_mv[i].as_int; |
2479 } | 2487 } |
2480 | 2488 |
2481 // do first prediction into the destination buffer. Do the next | 2489 // do first prediction into the destination buffer. Do the next |
2482 // prediction into a temporary buffer. Then keep track of which one | 2490 // prediction into a temporary buffer. Then keep track of which one |
2483 // of these currently holds the best predictor, and use the other | 2491 // of these currently holds the best predictor, and use the other |
2484 // one for future predictions. In the end, copy from tmp_buf to | 2492 // one for future predictions. In the end, copy from tmp_buf to |
2485 // dst if necessary. | 2493 // dst if necessary. |
2486 for (i = 0; i < MAX_MB_PLANE; i++) { | 2494 for (i = 0; i < MAX_MB_PLANE; i++) { |
2487 orig_dst[i] = xd->plane[i].dst.buf; | 2495 orig_dst[i] = xd->plane[i].dst.buf; |
2488 orig_dst_stride[i] = xd->plane[i].dst.stride; | 2496 orig_dst_stride[i] = xd->plane[i].dst.stride; |
2489 } | 2497 } |
2490 | 2498 |
2491 // We don't include the cost of the second reference here, because there | 2499 // We don't include the cost of the second reference here, because there |
2492 // are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other | 2500 // are only two options: Last/ARF or Golden/ARF; The second one is always |
2493 // words if you present them in that order, the second one is always known | 2501 // known, which is ARF. |
2494 // if the first is known. | |
2495 // | 2502 // |
2496 // Under some circumstances we discount the cost of new mv mode to encourage | 2503 // Under some circumstances we discount the cost of new mv mode to encourage |
2497 // initiation of a motion field. | 2504 // initiation of a motion field. |
2498 if (discount_newmv_test(cpi, this_mode, frame_mv[refs[0]], | 2505 if (discount_newmv_test(cpi, this_mode, frame_mv[refs[0]], |
2499 mode_mv, refs[0])) { | 2506 mode_mv, refs[0])) { |
2500 *rate2 += MIN(cost_mv_ref(cpi, this_mode, | 2507 *rate2 += VPXMIN(cost_mv_ref(cpi, this_mode, |
2501 mbmi_ext->mode_context[refs[0]]), | 2508 mbmi_ext->mode_context[refs[0]]), |
2502 cost_mv_ref(cpi, NEARESTMV, | 2509 cost_mv_ref(cpi, NEARESTMV, |
2503 mbmi_ext->mode_context[refs[0]])); | 2510 mbmi_ext->mode_context[refs[0]])); |
2504 } else { | 2511 } else { |
2505 *rate2 += cost_mv_ref(cpi, this_mode, mbmi_ext->mode_context[refs[0]]); | 2512 *rate2 += cost_mv_ref(cpi, this_mode, mbmi_ext->mode_context[refs[0]]); |
2506 } | 2513 } |
2507 | 2514 |
2508 if (RDCOST(x->rdmult, x->rddiv, *rate2, 0) > ref_best_rd && | 2515 if (RDCOST(x->rdmult, x->rddiv, *rate2, 0) > ref_best_rd && |
2509 mbmi->mode != NEARESTMV) | 2516 mbmi->mode != NEARESTMV) |
2510 return INT64_MAX; | 2517 return INT64_MAX; |
2511 | 2518 |
2512 pred_exists = 0; | 2519 pred_exists = 0; |
2513 // Are all MVs integer pel for Y and UV | 2520 // Are all MVs integer pel for Y and UV |
(...skipping 21 matching lines...) Expand all Loading... |
2535 int64_t tmp_skip_sse = INT64_MAX; | 2542 int64_t tmp_skip_sse = INT64_MAX; |
2536 | 2543 |
2537 mbmi->interp_filter = i; | 2544 mbmi->interp_filter = i; |
2538 rs = vp9_get_switchable_rate(cpi, xd); | 2545 rs = vp9_get_switchable_rate(cpi, xd); |
2539 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); | 2546 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); |
2540 | 2547 |
2541 if (i > 0 && intpel_mv) { | 2548 if (i > 0 && intpel_mv) { |
2542 rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum); | 2549 rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum); |
2543 filter_cache[i] = rd; | 2550 filter_cache[i] = rd; |
2544 filter_cache[SWITCHABLE_FILTERS] = | 2551 filter_cache[SWITCHABLE_FILTERS] = |
2545 MIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); | 2552 VPXMIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); |
2546 if (cm->interp_filter == SWITCHABLE) | 2553 if (cm->interp_filter == SWITCHABLE) |
2547 rd += rs_rd; | 2554 rd += rs_rd; |
2548 *mask_filter = MAX(*mask_filter, rd); | 2555 *mask_filter = VPXMAX(*mask_filter, rd); |
2549 } else { | 2556 } else { |
2550 int rate_sum = 0; | 2557 int rate_sum = 0; |
2551 int64_t dist_sum = 0; | 2558 int64_t dist_sum = 0; |
2552 if (i > 0 && cpi->sf.adaptive_interp_filter_search && | 2559 if (i > 0 && cpi->sf.adaptive_interp_filter_search && |
2553 (cpi->sf.interp_filter_search_mask & (1 << i))) { | 2560 (cpi->sf.interp_filter_search_mask & (1 << i))) { |
2554 rate_sum = INT_MAX; | 2561 rate_sum = INT_MAX; |
2555 dist_sum = INT64_MAX; | 2562 dist_sum = INT64_MAX; |
2556 continue; | 2563 continue; |
2557 } | 2564 } |
2558 | 2565 |
2559 if ((cm->interp_filter == SWITCHABLE && | 2566 if ((cm->interp_filter == SWITCHABLE && |
2560 (!i || best_needs_copy)) || | 2567 (!i || best_needs_copy)) || |
2561 (cm->interp_filter != SWITCHABLE && | 2568 (cm->interp_filter != SWITCHABLE && |
2562 (cm->interp_filter == mbmi->interp_filter || | 2569 (cm->interp_filter == mbmi->interp_filter || |
2563 (i == 0 && intpel_mv)))) { | 2570 (i == 0 && intpel_mv)))) { |
2564 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2571 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
2565 } else { | 2572 } else { |
2566 for (j = 0; j < MAX_MB_PLANE; j++) { | 2573 for (j = 0; j < MAX_MB_PLANE; j++) { |
2567 xd->plane[j].dst.buf = tmp_buf + j * 64 * 64; | 2574 xd->plane[j].dst.buf = tmp_buf + j * 64 * 64; |
2568 xd->plane[j].dst.stride = 64; | 2575 xd->plane[j].dst.stride = 64; |
2569 } | 2576 } |
2570 } | 2577 } |
2571 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); | 2578 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); |
2572 model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum, | 2579 model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum, |
2573 &tmp_skip_sb, &tmp_skip_sse); | 2580 &tmp_skip_sb, &tmp_skip_sse); |
2574 | 2581 |
2575 rd = RDCOST(x->rdmult, x->rddiv, rate_sum, dist_sum); | 2582 rd = RDCOST(x->rdmult, x->rddiv, rate_sum, dist_sum); |
2576 filter_cache[i] = rd; | 2583 filter_cache[i] = rd; |
2577 filter_cache[SWITCHABLE_FILTERS] = | 2584 filter_cache[SWITCHABLE_FILTERS] = |
2578 MIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); | 2585 VPXMIN(filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); |
2579 if (cm->interp_filter == SWITCHABLE) | 2586 if (cm->interp_filter == SWITCHABLE) |
2580 rd += rs_rd; | 2587 rd += rs_rd; |
2581 *mask_filter = MAX(*mask_filter, rd); | 2588 *mask_filter = VPXMAX(*mask_filter, rd); |
2582 | 2589 |
2583 if (i == 0 && intpel_mv) { | 2590 if (i == 0 && intpel_mv) { |
2584 tmp_rate_sum = rate_sum; | 2591 tmp_rate_sum = rate_sum; |
2585 tmp_dist_sum = dist_sum; | 2592 tmp_dist_sum = dist_sum; |
2586 } | 2593 } |
2587 } | 2594 } |
2588 | 2595 |
2589 if (i == 0 && cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) { | 2596 if (i == 0 && cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) { |
2590 if (rd / 2 > ref_best_rd) { | 2597 if (rd / 2 > ref_best_rd) { |
2591 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2598 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2682 *rate2 = INT_MAX; | 2689 *rate2 = INT_MAX; |
2683 *distortion = INT64_MAX; | 2690 *distortion = INT64_MAX; |
2684 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2691 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
2685 return INT64_MAX; | 2692 return INT64_MAX; |
2686 } | 2693 } |
2687 | 2694 |
2688 *rate2 += *rate_y; | 2695 *rate2 += *rate_y; |
2689 *distortion += distortion_y; | 2696 *distortion += distortion_y; |
2690 | 2697 |
2691 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); | 2698 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); |
2692 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); | 2699 rdcosty = VPXMIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); |
2693 | 2700 |
2694 if (!super_block_uvrd(cpi, x, rate_uv, &distortion_uv, &skippable_uv, | 2701 if (!super_block_uvrd(cpi, x, rate_uv, &distortion_uv, &skippable_uv, |
2695 &sseuv, bsize, ref_best_rd - rdcosty)) { | 2702 &sseuv, bsize, ref_best_rd - rdcosty)) { |
2696 *rate2 = INT_MAX; | 2703 *rate2 = INT_MAX; |
2697 *distortion = INT64_MAX; | 2704 *distortion = INT64_MAX; |
2698 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2705 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
2699 return INT64_MAX; | 2706 return INT64_MAX; |
2700 } | 2707 } |
2701 | 2708 |
2702 *psse += sseuv; | 2709 *psse += sseuv; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2747 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly, | 2754 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly, |
2748 &dist_y, best_rd) >= best_rd) { | 2755 &dist_y, best_rd) >= best_rd) { |
2749 rd_cost->rate = INT_MAX; | 2756 rd_cost->rate = INT_MAX; |
2750 return; | 2757 return; |
2751 } | 2758 } |
2752 } | 2759 } |
2753 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize, | 2760 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize, |
2754 pd[1].subsampling_x, | 2761 pd[1].subsampling_x, |
2755 pd[1].subsampling_y); | 2762 pd[1].subsampling_y); |
2756 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, | 2763 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, |
2757 &dist_uv, &uv_skip, MAX(BLOCK_8X8, bsize), | 2764 &dist_uv, &uv_skip, VPXMAX(BLOCK_8X8, bsize), |
2758 max_uv_tx_size); | 2765 max_uv_tx_size); |
2759 | 2766 |
2760 if (y_skip && uv_skip) { | 2767 if (y_skip && uv_skip) { |
2761 rd_cost->rate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + | 2768 rd_cost->rate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + |
2762 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); | 2769 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
2763 rd_cost->dist = dist_y + dist_uv; | 2770 rd_cost->dist = dist_y + dist_uv; |
2764 } else { | 2771 } else { |
2765 rd_cost->rate = rate_y + rate_uv + | 2772 rd_cost->rate = rate_y + rate_uv + |
2766 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 2773 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
2767 rd_cost->dist = dist_y + dist_uv; | 2774 rd_cost->dist = dist_y + dist_uv; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2814 ((source_variance * source_variance) + | 2821 ((source_variance * source_variance) + |
2815 (recon_variance * recon_variance)); | 2822 (recon_variance * recon_variance)); |
2816 var_error = 100 - var_error; | 2823 var_error = 100 - var_error; |
2817 } | 2824 } |
2818 | 2825 |
2819 // Source variance above a threshold and ref frame is intra. | 2826 // Source variance above a threshold and ref frame is intra. |
2820 // This case is targeted mainly at discouraging intra modes that give rise | 2827 // This case is targeted mainly at discouraging intra modes that give rise |
2821 // to a predictor with a low spatial complexity compared to the source. | 2828 // to a predictor with a low spatial complexity compared to the source. |
2822 if ((source_variance > LOW_VAR_THRESH) && (ref_frame == INTRA_FRAME) && | 2829 if ((source_variance > LOW_VAR_THRESH) && (ref_frame == INTRA_FRAME) && |
2823 (source_variance > recon_variance)) { | 2830 (source_variance > recon_variance)) { |
2824 var_factor = MIN(absvar_diff, MIN(VLOW_ADJ_MAX, var_error)); | 2831 var_factor = VPXMIN(absvar_diff, VPXMIN(VLOW_ADJ_MAX, var_error)); |
2825 // A second possible case of interest is where the source variance | 2832 // A second possible case of interest is where the source variance |
2826 // is very low and we wish to discourage false texture or motion trails. | 2833 // is very low and we wish to discourage false texture or motion trails. |
2827 } else if ((source_variance < (LOW_VAR_THRESH >> 1)) && | 2834 } else if ((source_variance < (LOW_VAR_THRESH >> 1)) && |
2828 (recon_variance > source_variance)) { | 2835 (recon_variance > source_variance)) { |
2829 var_factor = MIN(absvar_diff, MIN(VHIGH_ADJ_MAX, var_error)); | 2836 var_factor = VPXMIN(absvar_diff, VPXMIN(VHIGH_ADJ_MAX, var_error)); |
2830 } | 2837 } |
2831 *this_rd += (*this_rd * var_factor) / 100; | 2838 *this_rd += (*this_rd * var_factor) / 100; |
2832 } | 2839 } |
2833 | 2840 |
2834 | 2841 |
2835 // Do we have an internal image edge (e.g. formatting bars). | 2842 // Do we have an internal image edge (e.g. formatting bars). |
2836 int vp9_internal_image_edge(VP9_COMP *cpi) { | 2843 int vp9_internal_image_edge(VP9_COMP *cpi) { |
2837 return (cpi->oxcf.pass == 2) && | 2844 return (cpi->oxcf.pass == 2) && |
2838 ((cpi->twopass.this_frame_stats.inactive_zone_rows > 0) || | 2845 ((cpi->twopass.this_frame_stats.inactive_zone_rows > 0) || |
2839 (cpi->twopass.this_frame_stats.inactive_zone_cols > 0)); | 2846 (cpi->twopass.this_frame_stats.inactive_zone_cols > 0)); |
2840 } | 2847 } |
2841 | 2848 |
2842 // Checks to see if a super block is on a horizontal image edge. | 2849 // Checks to see if a super block is on a horizontal image edge. |
2843 // In most cases this is the "real" edge unless there are formatting | 2850 // In most cases this is the "real" edge unless there are formatting |
2844 // bars embedded in the stream. | 2851 // bars embedded in the stream. |
2845 int vp9_active_h_edge(VP9_COMP *cpi, int mi_row, int mi_step) { | 2852 int vp9_active_h_edge(VP9_COMP *cpi, int mi_row, int mi_step) { |
2846 int top_edge = 0; | 2853 int top_edge = 0; |
2847 int bottom_edge = cpi->common.mi_rows; | 2854 int bottom_edge = cpi->common.mi_rows; |
2848 int is_active_h_edge = 0; | 2855 int is_active_h_edge = 0; |
2849 | 2856 |
2850 // For two pass account for any formatting bars detected. | 2857 // For two pass account for any formatting bars detected. |
2851 if (cpi->oxcf.pass == 2) { | 2858 if (cpi->oxcf.pass == 2) { |
2852 TWO_PASS *twopass = &cpi->twopass; | 2859 TWO_PASS *twopass = &cpi->twopass; |
2853 | 2860 |
2854 // The inactive region is specified in MBs not mi units. | 2861 // The inactive region is specified in MBs not mi units. |
2855 // The image edge is in the following MB row. | 2862 // The image edge is in the following MB row. |
2856 top_edge += (int)(twopass->this_frame_stats.inactive_zone_rows * 2); | 2863 top_edge += (int)(twopass->this_frame_stats.inactive_zone_rows * 2); |
2857 | 2864 |
2858 bottom_edge -= (int)(twopass->this_frame_stats.inactive_zone_rows * 2); | 2865 bottom_edge -= (int)(twopass->this_frame_stats.inactive_zone_rows * 2); |
2859 bottom_edge = MAX(top_edge, bottom_edge); | 2866 bottom_edge = VPXMAX(top_edge, bottom_edge); |
2860 } | 2867 } |
2861 | 2868 |
2862 if (((top_edge >= mi_row) && (top_edge < (mi_row + mi_step))) || | 2869 if (((top_edge >= mi_row) && (top_edge < (mi_row + mi_step))) || |
2863 ((bottom_edge >= mi_row) && (bottom_edge < (mi_row + mi_step)))) { | 2870 ((bottom_edge >= mi_row) && (bottom_edge < (mi_row + mi_step)))) { |
2864 is_active_h_edge = 1; | 2871 is_active_h_edge = 1; |
2865 } | 2872 } |
2866 return is_active_h_edge; | 2873 return is_active_h_edge; |
2867 } | 2874 } |
2868 | 2875 |
2869 // Checks to see if a super block is on a vertical image edge. | 2876 // Checks to see if a super block is on a vertical image edge. |
2870 // In most cases this is the "real" edge unless there are formatting | 2877 // In most cases this is the "real" edge unless there are formatting |
2871 // bars embedded in the stream. | 2878 // bars embedded in the stream. |
2872 int vp9_active_v_edge(VP9_COMP *cpi, int mi_col, int mi_step) { | 2879 int vp9_active_v_edge(VP9_COMP *cpi, int mi_col, int mi_step) { |
2873 int left_edge = 0; | 2880 int left_edge = 0; |
2874 int right_edge = cpi->common.mi_cols; | 2881 int right_edge = cpi->common.mi_cols; |
2875 int is_active_v_edge = 0; | 2882 int is_active_v_edge = 0; |
2876 | 2883 |
2877 // For two pass account for any formatting bars detected. | 2884 // For two pass account for any formatting bars detected. |
2878 if (cpi->oxcf.pass == 2) { | 2885 if (cpi->oxcf.pass == 2) { |
2879 TWO_PASS *twopass = &cpi->twopass; | 2886 TWO_PASS *twopass = &cpi->twopass; |
2880 | 2887 |
2881 // The inactive region is specified in MBs not mi units. | 2888 // The inactive region is specified in MBs not mi units. |
2882 // The image edge is in the following MB row. | 2889 // The image edge is in the following MB row. |
2883 left_edge += (int)(twopass->this_frame_stats.inactive_zone_cols * 2); | 2890 left_edge += (int)(twopass->this_frame_stats.inactive_zone_cols * 2); |
2884 | 2891 |
2885 right_edge -= (int)(twopass->this_frame_stats.inactive_zone_cols * 2); | 2892 right_edge -= (int)(twopass->this_frame_stats.inactive_zone_cols * 2); |
2886 right_edge = MAX(left_edge, right_edge); | 2893 right_edge = VPXMAX(left_edge, right_edge); |
2887 } | 2894 } |
2888 | 2895 |
2889 if (((left_edge >= mi_col) && (left_edge < (mi_col + mi_step))) || | 2896 if (((left_edge >= mi_col) && (left_edge < (mi_col + mi_step))) || |
2890 ((right_edge >= mi_col) && (right_edge < (mi_col + mi_step)))) { | 2897 ((right_edge >= mi_col) && (right_edge < (mi_col + mi_step)))) { |
2891 is_active_v_edge = 1; | 2898 is_active_v_edge = 1; |
2892 } | 2899 } |
2893 return is_active_v_edge; | 2900 return is_active_v_edge; |
2894 } | 2901 } |
2895 | 2902 |
2896 // Checks to see if a super block is at the edge of the active image. | 2903 // Checks to see if a super block is at the edge of the active image. |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3123 ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK; | 3130 ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK; |
3124 break; | 3131 break; |
3125 case NONE: | 3132 case NONE: |
3126 case MAX_REF_FRAMES: | 3133 case MAX_REF_FRAMES: |
3127 assert(0 && "Invalid Reference frame"); | 3134 assert(0 && "Invalid Reference frame"); |
3128 break; | 3135 break; |
3129 } | 3136 } |
3130 } | 3137 } |
3131 | 3138 |
3132 if ((ref_frame_skip_mask[0] & (1 << ref_frame)) && | 3139 if ((ref_frame_skip_mask[0] & (1 << ref_frame)) && |
3133 (ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame)))) | 3140 (ref_frame_skip_mask[1] & (1 << VPXMAX(0, second_ref_frame)))) |
3134 continue; | 3141 continue; |
3135 | 3142 |
3136 if (mode_skip_mask[ref_frame] & (1 << this_mode)) | 3143 if (mode_skip_mask[ref_frame] & (1 << this_mode)) |
3137 continue; | 3144 continue; |
3138 | 3145 |
3139 // Test best rd so far against threshold for trying this mode. | 3146 // Test best rd so far against threshold for trying this mode. |
3140 if (best_mode_skippable && sf->schedule_mode_search) | 3147 if (best_mode_skippable && sf->schedule_mode_search) |
3141 mode_threshold[mode_index] <<= 1; | 3148 mode_threshold[mode_index] <<= 1; |
3142 | 3149 |
3143 if (best_rd < mode_threshold[mode_index]) | 3150 if (best_rd < mode_threshold[mode_index]) |
3144 continue; | 3151 continue; |
3145 | 3152 |
3146 if (sf->motion_field_mode_search) { | 3153 if (sf->motion_field_mode_search) { |
3147 const int mi_width = MIN(num_8x8_blocks_wide_lookup[bsize], | 3154 const int mi_width = VPXMIN(num_8x8_blocks_wide_lookup[bsize], |
3148 tile_info->mi_col_end - mi_col); | 3155 tile_info->mi_col_end - mi_col); |
3149 const int mi_height = MIN(num_8x8_blocks_high_lookup[bsize], | 3156 const int mi_height = VPXMIN(num_8x8_blocks_high_lookup[bsize], |
3150 tile_info->mi_row_end - mi_row); | 3157 tile_info->mi_row_end - mi_row); |
3151 const int bsl = mi_width_log2_lookup[bsize]; | 3158 const int bsl = mi_width_log2_lookup[bsize]; |
3152 int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl) | 3159 int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl) |
3153 + get_chessboard_index(cm->current_video_frame)) & 0x1; | 3160 + get_chessboard_index(cm->current_video_frame)) & 0x1; |
3154 MB_MODE_INFO *ref_mbmi; | 3161 MB_MODE_INFO *ref_mbmi; |
3155 int const_motion = 1; | 3162 int const_motion = 1; |
3156 int skip_ref_frame = !cb_partition_search_ctrl; | 3163 int skip_ref_frame = !cb_partition_search_ctrl; |
3157 MV_REFERENCE_FRAME rf = NONE; | 3164 MV_REFERENCE_FRAME rf = NONE; |
3158 int_mv ref_mv; | 3165 int_mv ref_mv; |
3159 ref_mv.as_int = INVALID_MV; | 3166 ref_mv.as_int = INVALID_MV; |
3160 | 3167 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3358 if (ref_frame == INTRA_FRAME) { | 3365 if (ref_frame == INTRA_FRAME) { |
3359 // Keep record of best intra rd | 3366 // Keep record of best intra rd |
3360 if (this_rd < best_intra_rd) { | 3367 if (this_rd < best_intra_rd) { |
3361 best_intra_rd = this_rd; | 3368 best_intra_rd = this_rd; |
3362 best_intra_mode = mbmi->mode; | 3369 best_intra_mode = mbmi->mode; |
3363 } | 3370 } |
3364 } | 3371 } |
3365 | 3372 |
3366 if (!disable_skip && ref_frame == INTRA_FRAME) { | 3373 if (!disable_skip && ref_frame == INTRA_FRAME) { |
3367 for (i = 0; i < REFERENCE_MODES; ++i) | 3374 for (i = 0; i < REFERENCE_MODES; ++i) |
3368 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); | 3375 best_pred_rd[i] = VPXMIN(best_pred_rd[i], this_rd); |
3369 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 3376 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
3370 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); | 3377 best_filter_rd[i] = VPXMIN(best_filter_rd[i], this_rd); |
3371 } | 3378 } |
3372 | 3379 |
3373 // Did this mode help.. i.e. is it the new best mode | 3380 // Did this mode help.. i.e. is it the new best mode |
3374 if (this_rd < best_rd || x->skip) { | 3381 if (this_rd < best_rd || x->skip) { |
3375 int max_plane = MAX_MB_PLANE; | 3382 int max_plane = MAX_MB_PLANE; |
3376 if (!mode_excluded) { | 3383 if (!mode_excluded) { |
3377 // Note index of best mode so far | 3384 // Note index of best mode so far |
3378 best_mode_index = mode_index; | 3385 best_mode_index = mode_index; |
3379 | 3386 |
3380 if (ref_frame == INTRA_FRAME) { | 3387 if (ref_frame == INTRA_FRAME) { |
3381 /* required for left and above block mv */ | 3388 /* required for left and above block mv */ |
3382 mbmi->mv[0].as_int = 0; | 3389 mbmi->mv[0].as_int = 0; |
3383 max_plane = 1; | 3390 max_plane = 1; |
3384 } else { | 3391 } else { |
3385 best_pred_sse = x->pred_sse[ref_frame]; | 3392 best_pred_sse = x->pred_sse[ref_frame]; |
3386 } | 3393 } |
3387 | 3394 |
3388 rd_cost->rate = rate2; | 3395 rd_cost->rate = rate2; |
3389 rd_cost->dist = distortion2; | 3396 rd_cost->dist = distortion2; |
3390 rd_cost->rdcost = this_rd; | 3397 rd_cost->rdcost = this_rd; |
3391 best_rd = this_rd; | 3398 best_rd = this_rd; |
3392 best_mbmode = *mbmi; | 3399 best_mbmode = *mbmi; |
3393 best_skip2 = this_skip2; | 3400 best_skip2 = this_skip2; |
3394 best_mode_skippable = skippable; | 3401 best_mode_skippable = skippable; |
3395 | 3402 |
3396 if (!x->select_tx_size) | 3403 if (!x->select_tx_size) |
3397 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); | 3404 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); |
3398 memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], | 3405 memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], |
3399 sizeof(uint8_t) * ctx->num_4x4_blk); | 3406 sizeof(ctx->zcoeff_blk[0]) * ctx->num_4x4_blk); |
3400 | 3407 |
3401 // TODO(debargha): enhance this test with a better distortion prediction | 3408 // TODO(debargha): enhance this test with a better distortion prediction |
3402 // based on qp, activity mask and history | 3409 // based on qp, activity mask and history |
3403 if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) && | 3410 if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
3404 (mode_index > MIN_EARLY_TERM_INDEX)) { | 3411 (mode_index > MIN_EARLY_TERM_INDEX)) { |
3405 int qstep = xd->plane[0].dequant[1]; | 3412 int qstep = xd->plane[0].dequant[1]; |
3406 // TODO(debargha): Enhance this by specializing for each mode_index | 3413 // TODO(debargha): Enhance this by specializing for each mode_index |
3407 int scale = 4; | 3414 int scale = 4; |
3408 #if CONFIG_VP9_HIGHBITDEPTH | 3415 #if CONFIG_VP9_HIGHBITDEPTH |
3409 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 3416 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3459 else if (filter_cache[i] == INT64_MAX) | 3466 else if (filter_cache[i] == INT64_MAX) |
3460 // when early termination is triggered, the encoder does not have | 3467 // when early termination is triggered, the encoder does not have |
3461 // access to the rate-distortion cost. it only knows that the cost | 3468 // access to the rate-distortion cost. it only knows that the cost |
3462 // should be above the maximum valid value. hence it takes the known | 3469 // should be above the maximum valid value. hence it takes the known |
3463 // maximum plus an arbitrary constant as the rate-distortion cost. | 3470 // maximum plus an arbitrary constant as the rate-distortion cost. |
3464 adj_rd = mask_filter - ref + 10; | 3471 adj_rd = mask_filter - ref + 10; |
3465 else | 3472 else |
3466 adj_rd = filter_cache[i] - ref; | 3473 adj_rd = filter_cache[i] - ref; |
3467 | 3474 |
3468 adj_rd += this_rd; | 3475 adj_rd += this_rd; |
3469 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); | 3476 best_filter_rd[i] = VPXMIN(best_filter_rd[i], adj_rd); |
3470 } | 3477 } |
3471 } | 3478 } |
3472 } | 3479 } |
3473 | 3480 |
3474 if (early_term) | 3481 if (early_term) |
3475 break; | 3482 break; |
3476 | 3483 |
3477 if (x->skip && !comp_pred) | 3484 if (x->skip && !comp_pred) |
3478 break; | 3485 break; |
3479 } | 3486 } |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3802 break; | 3809 break; |
3803 case NONE: | 3810 case NONE: |
3804 case MAX_REF_FRAMES: | 3811 case MAX_REF_FRAMES: |
3805 assert(0 && "Invalid Reference frame"); | 3812 assert(0 && "Invalid Reference frame"); |
3806 break; | 3813 break; |
3807 } | 3814 } |
3808 } | 3815 } |
3809 } | 3816 } |
3810 | 3817 |
3811 if ((ref_frame_skip_mask[0] & (1 << ref_frame)) && | 3818 if ((ref_frame_skip_mask[0] & (1 << ref_frame)) && |
3812 (ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame)))) | 3819 (ref_frame_skip_mask[1] & (1 << VPXMAX(0, second_ref_frame)))) |
3813 continue; | 3820 continue; |
3814 | 3821 |
3815 // Test best rd so far against threshold for trying this mode. | 3822 // Test best rd so far against threshold for trying this mode. |
3816 if (!internal_active_edge && | 3823 if (!internal_active_edge && |
3817 rd_less_than_thresh(best_rd, | 3824 rd_less_than_thresh(best_rd, |
3818 rd_opt->threshes[segment_id][bsize][ref_index], | 3825 rd_opt->threshes[segment_id][bsize][ref_index], |
3819 tile_data->thresh_freq_fact[bsize][ref_index])) | 3826 tile_data->thresh_freq_fact[bsize][ref_index])) |
3820 continue; | 3827 continue; |
3821 | 3828 |
3822 comp_pred = second_ref_frame > INTRA_FRAME; | 3829 comp_pred = second_ref_frame > INTRA_FRAME; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3957 (int) this_rd_thresh, seg_mvs, | 3964 (int) this_rd_thresh, seg_mvs, |
3958 bsi, switchable_filter_index, | 3965 bsi, switchable_filter_index, |
3959 mi_row, mi_col); | 3966 mi_row, mi_col); |
3960 | 3967 |
3961 if (tmp_rd == INT64_MAX) | 3968 if (tmp_rd == INT64_MAX) |
3962 continue; | 3969 continue; |
3963 rs = vp9_get_switchable_rate(cpi, xd); | 3970 rs = vp9_get_switchable_rate(cpi, xd); |
3964 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); | 3971 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); |
3965 filter_cache[switchable_filter_index] = tmp_rd; | 3972 filter_cache[switchable_filter_index] = tmp_rd; |
3966 filter_cache[SWITCHABLE_FILTERS] = | 3973 filter_cache[SWITCHABLE_FILTERS] = |
3967 MIN(filter_cache[SWITCHABLE_FILTERS], | 3974 VPXMIN(filter_cache[SWITCHABLE_FILTERS], tmp_rd + rs_rd); |
3968 tmp_rd + rs_rd); | |
3969 if (cm->interp_filter == SWITCHABLE) | 3975 if (cm->interp_filter == SWITCHABLE) |
3970 tmp_rd += rs_rd; | 3976 tmp_rd += rs_rd; |
3971 | 3977 |
3972 mask_filter = MAX(mask_filter, tmp_rd); | 3978 mask_filter = VPXMAX(mask_filter, tmp_rd); |
3973 | 3979 |
3974 newbest = (tmp_rd < tmp_best_rd); | 3980 newbest = (tmp_rd < tmp_best_rd); |
3975 if (newbest) { | 3981 if (newbest) { |
3976 tmp_best_filter = mbmi->interp_filter; | 3982 tmp_best_filter = mbmi->interp_filter; |
3977 tmp_best_rd = tmp_rd; | 3983 tmp_best_rd = tmp_rd; |
3978 } | 3984 } |
3979 if ((newbest && cm->interp_filter == SWITCHABLE) || | 3985 if ((newbest && cm->interp_filter == SWITCHABLE) || |
3980 (mbmi->interp_filter == cm->interp_filter && | 3986 (mbmi->interp_filter == cm->interp_filter && |
3981 cm->interp_filter != SWITCHABLE)) { | 3987 cm->interp_filter != SWITCHABLE)) { |
3982 tmp_best_rdu = tmp_rd; | 3988 tmp_best_rdu = tmp_rd; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4039 | 4045 |
4040 if (cm->interp_filter == SWITCHABLE) | 4046 if (cm->interp_filter == SWITCHABLE) |
4041 rate2 += vp9_get_switchable_rate(cpi, xd); | 4047 rate2 += vp9_get_switchable_rate(cpi, xd); |
4042 | 4048 |
4043 if (!mode_excluded) | 4049 if (!mode_excluded) |
4044 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE | 4050 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE |
4045 : cm->reference_mode == COMPOUND_REFERENCE; | 4051 : cm->reference_mode == COMPOUND_REFERENCE; |
4046 | 4052 |
4047 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); | 4053 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); |
4048 | 4054 |
4049 tmp_best_rdu = best_rd - | 4055 tmp_best_rdu = |
4050 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), | 4056 best_rd - VPXMIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), |
4051 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); | 4057 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); |
4052 | 4058 |
4053 if (tmp_best_rdu > 0) { | 4059 if (tmp_best_rdu > 0) { |
4054 // If even the 'Y' rd value of split is higher than best so far | 4060 // If even the 'Y' rd value of split is higher than best so far |
4055 // then dont bother looking at UV | 4061 // then dont bother looking at UV |
4056 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, | 4062 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, |
4057 BLOCK_8X8); | 4063 BLOCK_8X8); |
4058 memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); | 4064 memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); |
4059 if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, | 4065 if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, |
4060 &uv_sse, BLOCK_8X8, tmp_best_rdu)) | 4066 &uv_sse, BLOCK_8X8, tmp_best_rdu)) |
4061 continue; | 4067 continue; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4101 // Add in the cost of the no skip flag. | 4107 // Add in the cost of the no skip flag. |
4102 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 4108 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
4103 } | 4109 } |
4104 | 4110 |
4105 // Calculate the final RD estimate for this mode. | 4111 // Calculate the final RD estimate for this mode. |
4106 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 4112 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
4107 } | 4113 } |
4108 | 4114 |
4109 if (!disable_skip && ref_frame == INTRA_FRAME) { | 4115 if (!disable_skip && ref_frame == INTRA_FRAME) { |
4110 for (i = 0; i < REFERENCE_MODES; ++i) | 4116 for (i = 0; i < REFERENCE_MODES; ++i) |
4111 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); | 4117 best_pred_rd[i] = VPXMIN(best_pred_rd[i], this_rd); |
4112 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 4118 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
4113 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); | 4119 best_filter_rd[i] = VPXMIN(best_filter_rd[i], this_rd); |
4114 } | 4120 } |
4115 | 4121 |
4116 // Did this mode help.. i.e. is it the new best mode | 4122 // Did this mode help.. i.e. is it the new best mode |
4117 if (this_rd < best_rd || x->skip) { | 4123 if (this_rd < best_rd || x->skip) { |
4118 if (!mode_excluded) { | 4124 if (!mode_excluded) { |
4119 int max_plane = MAX_MB_PLANE; | 4125 int max_plane = MAX_MB_PLANE; |
4120 // Note index of best mode so far | 4126 // Note index of best mode so far |
4121 best_ref_index = ref_index; | 4127 best_ref_index = ref_index; |
4122 | 4128 |
4123 if (ref_frame == INTRA_FRAME) { | 4129 if (ref_frame == INTRA_FRAME) { |
4124 /* required for left and above block mv */ | 4130 /* required for left and above block mv */ |
4125 mbmi->mv[0].as_int = 0; | 4131 mbmi->mv[0].as_int = 0; |
4126 max_plane = 1; | 4132 max_plane = 1; |
4127 } | 4133 } |
4128 | 4134 |
4129 rd_cost->rate = rate2; | 4135 rd_cost->rate = rate2; |
4130 rd_cost->dist = distortion2; | 4136 rd_cost->dist = distortion2; |
4131 rd_cost->rdcost = this_rd; | 4137 rd_cost->rdcost = this_rd; |
4132 best_rd = this_rd; | 4138 best_rd = this_rd; |
4133 best_yrd = best_rd - | 4139 best_yrd = best_rd - |
4134 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); | 4140 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); |
4135 best_mbmode = *mbmi; | 4141 best_mbmode = *mbmi; |
4136 best_skip2 = this_skip2; | 4142 best_skip2 = this_skip2; |
4137 if (!x->select_tx_size) | 4143 if (!x->select_tx_size) |
4138 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); | 4144 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); |
4139 memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4], | 4145 memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4], |
4140 sizeof(uint8_t) * ctx->num_4x4_blk); | 4146 sizeof(ctx->zcoeff_blk[0]) * ctx->num_4x4_blk); |
4141 | 4147 |
4142 for (i = 0; i < 4; i++) | 4148 for (i = 0; i < 4; i++) |
4143 best_bmodes[i] = xd->mi[0]->bmi[i]; | 4149 best_bmodes[i] = xd->mi[0]->bmi[i]; |
4144 | 4150 |
4145 // TODO(debargha): enhance this test with a better distortion prediction | 4151 // TODO(debargha): enhance this test with a better distortion prediction |
4146 // based on qp, activity mask and history | 4152 // based on qp, activity mask and history |
4147 if ((sf->mode_search_skip_flags & FLAG_EARLY_TERMINATE) && | 4153 if ((sf->mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
4148 (ref_index > MIN_EARLY_TERM_INDEX)) { | 4154 (ref_index > MIN_EARLY_TERM_INDEX)) { |
4149 int qstep = xd->plane[0].dequant[1]; | 4155 int qstep = xd->plane[0].dequant[1]; |
4150 // TODO(debargha): Enhance this by specializing for each mode_index | 4156 // TODO(debargha): Enhance this by specializing for each mode_index |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4202 else if (filter_cache[i] == INT64_MAX) | 4208 else if (filter_cache[i] == INT64_MAX) |
4203 // when early termination is triggered, the encoder does not have | 4209 // when early termination is triggered, the encoder does not have |
4204 // access to the rate-distortion cost. it only knows that the cost | 4210 // access to the rate-distortion cost. it only knows that the cost |
4205 // should be above the maximum valid value. hence it takes the known | 4211 // should be above the maximum valid value. hence it takes the known |
4206 // maximum plus an arbitrary constant as the rate-distortion cost. | 4212 // maximum plus an arbitrary constant as the rate-distortion cost. |
4207 adj_rd = mask_filter - ref + 10; | 4213 adj_rd = mask_filter - ref + 10; |
4208 else | 4214 else |
4209 adj_rd = filter_cache[i] - ref; | 4215 adj_rd = filter_cache[i] - ref; |
4210 | 4216 |
4211 adj_rd += this_rd; | 4217 adj_rd += this_rd; |
4212 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); | 4218 best_filter_rd[i] = VPXMIN(best_filter_rd[i], adj_rd); |
4213 } | 4219 } |
4214 } | 4220 } |
4215 | 4221 |
4216 if (early_term) | 4222 if (early_term) |
4217 break; | 4223 break; |
4218 | 4224 |
4219 if (x->skip && !comp_pred) | 4225 if (x->skip && !comp_pred) |
4220 break; | 4226 break; |
4221 } | 4227 } |
4222 | 4228 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4283 } | 4289 } |
4284 if (cm->interp_filter == SWITCHABLE) | 4290 if (cm->interp_filter == SWITCHABLE) |
4285 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); | 4291 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
4286 } else { | 4292 } else { |
4287 vp9_zero(best_filter_diff); | 4293 vp9_zero(best_filter_diff); |
4288 } | 4294 } |
4289 | 4295 |
4290 store_coding_context(x, ctx, best_ref_index, | 4296 store_coding_context(x, ctx, best_ref_index, |
4291 best_pred_diff, best_filter_diff, 0); | 4297 best_pred_diff, best_filter_diff, 0); |
4292 } | 4298 } |
OLD | NEW |