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 | 11 |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 #include <math.h> | 13 #include <math.h> |
14 #include <limits.h> | 14 #include <limits.h> |
15 #include <assert.h> | 15 #include <assert.h> |
16 #include "vpx_config.h" | 16 #include "vpx_config.h" |
17 #include "vpx_rtcd.h" | 17 #include "vp8_rtcd.h" |
18 #include "vp8/common/pragmas.h" | 18 #include "vp8/common/pragmas.h" |
19 #include "tokenize.h" | 19 #include "tokenize.h" |
20 #include "treewriter.h" | 20 #include "treewriter.h" |
21 #include "onyx_int.h" | 21 #include "onyx_int.h" |
22 #include "modecosts.h" | 22 #include "modecosts.h" |
23 #include "encodeintra.h" | 23 #include "encodeintra.h" |
24 #include "pickinter.h" | 24 #include "pickinter.h" |
25 #include "vp8/common/entropymode.h" | 25 #include "vp8/common/entropymode.h" |
26 #include "vp8/common/reconinter.h" | 26 #include "vp8/common/reconinter.h" |
27 #include "vp8/common/reconintra4x4.h" | 27 #include "vp8/common/reconintra4x4.h" |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 static void copy_predictor(unsigned char *dst, const unsigned char *predictor) | 618 static void copy_predictor(unsigned char *dst, const unsigned char *predictor) |
619 { | 619 { |
620 const unsigned int *p = (const unsigned int *)predictor; | 620 const unsigned int *p = (const unsigned int *)predictor; |
621 unsigned int *d = (unsigned int *)dst; | 621 unsigned int *d = (unsigned int *)dst; |
622 d[0] = p[0]; | 622 d[0] = p[0]; |
623 d[4] = p[4]; | 623 d[4] = p[4]; |
624 d[8] = p[8]; | 624 d[8] = p[8]; |
625 d[12] = p[12]; | 625 d[12] = p[12]; |
626 } | 626 } |
627 static int rd_pick_intra4x4block( | 627 static int rd_pick_intra4x4block( |
| 628 VP8_COMP *cpi, |
628 MACROBLOCK *x, | 629 MACROBLOCK *x, |
629 BLOCK *be, | 630 BLOCK *be, |
630 BLOCKD *b, | 631 BLOCKD *b, |
631 B_PREDICTION_MODE *best_mode, | 632 B_PREDICTION_MODE *best_mode, |
632 const int *bmode_costs, | 633 const int *bmode_costs, |
633 ENTROPY_CONTEXT *a, | 634 ENTROPY_CONTEXT *a, |
634 ENTROPY_CONTEXT *l, | 635 ENTROPY_CONTEXT *l, |
635 | 636 |
636 int *bestrate, | 637 int *bestrate, |
637 int *bestratey, | 638 int *bestratey, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32); | 694 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32); |
694 } | 695 } |
695 } | 696 } |
696 b->bmi.as_mode = *best_mode; | 697 b->bmi.as_mode = *best_mode; |
697 | 698 |
698 vp8_short_idct4x4llm(best_dqcoeff, best_predictor, 16, dst, dst_stride); | 699 vp8_short_idct4x4llm(best_dqcoeff, best_predictor, 16, dst, dst_stride); |
699 | 700 |
700 return best_rd; | 701 return best_rd; |
701 } | 702 } |
702 | 703 |
703 static int rd_pick_intra4x4mby_modes(MACROBLOCK *mb, int *Rate, | 704 static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate, |
704 int *rate_y, int *Distortion, int best_rd) | 705 int *rate_y, int *Distortion, int best_rd) |
705 { | 706 { |
706 MACROBLOCKD *const xd = &mb->e_mbd; | 707 MACROBLOCKD *const xd = &mb->e_mbd; |
707 int i; | 708 int i; |
708 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED]; | 709 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED]; |
709 int distortion = 0; | 710 int distortion = 0; |
710 int tot_rate_y = 0; | 711 int tot_rate_y = 0; |
711 int64_t total_rd = 0; | 712 int64_t total_rd = 0; |
712 ENTROPY_CONTEXT_PLANES t_above, t_left; | 713 ENTROPY_CONTEXT_PLANES t_above, t_left; |
713 ENTROPY_CONTEXT *ta; | 714 ENTROPY_CONTEXT *ta; |
(...skipping 19 matching lines...) Expand all Loading... |
733 | 734 |
734 if (mb->e_mbd.frame_type == KEY_FRAME) | 735 if (mb->e_mbd.frame_type == KEY_FRAME) |
735 { | 736 { |
736 const B_PREDICTION_MODE A = above_block_mode(mic, i, mis); | 737 const B_PREDICTION_MODE A = above_block_mode(mic, i, mis); |
737 const B_PREDICTION_MODE L = left_block_mode(mic, i); | 738 const B_PREDICTION_MODE L = left_block_mode(mic, i); |
738 | 739 |
739 bmode_costs = mb->bmode_costs[A][L]; | 740 bmode_costs = mb->bmode_costs[A][L]; |
740 } | 741 } |
741 | 742 |
742 total_rd += rd_pick_intra4x4block( | 743 total_rd += rd_pick_intra4x4block( |
743 mb, mb->block + i, xd->block + i, &best_mode, bmode_costs, | 744 cpi, mb, mb->block + i, xd->block + i, &best_mode, bmode_costs, |
744 ta + vp8_block2above[i], | 745 ta + vp8_block2above[i], |
745 tl + vp8_block2left[i], &r, &ry, &d); | 746 tl + vp8_block2left[i], &r, &ry, &d); |
746 | 747 |
747 cost += r; | 748 cost += r; |
748 distortion += d; | 749 distortion += d; |
749 tot_rate_y += ry; | 750 tot_rate_y += ry; |
750 | 751 |
751 mic->bmi[i].as_mode = best_mode; | 752 mic->bmi[i].as_mode = best_mode; |
752 | 753 |
753 if(total_rd >= (int64_t)best_rd) | 754 if(total_rd >= (int64_t)best_rd) |
754 break; | 755 break; |
755 } | 756 } |
756 | 757 |
757 if(total_rd >= (int64_t)best_rd) | 758 if(total_rd >= (int64_t)best_rd) |
758 return INT_MAX; | 759 return INT_MAX; |
759 | 760 |
760 *Rate = cost; | 761 *Rate = cost; |
761 *rate_y = tot_rate_y; | 762 *rate_y = tot_rate_y; |
762 *Distortion = distortion; | 763 *Distortion = distortion; |
763 | 764 |
764 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion); | 765 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion); |
765 } | 766 } |
766 | 767 |
767 | 768 |
768 static int rd_pick_intra16x16mby_mode(MACROBLOCK *x, | 769 static int rd_pick_intra16x16mby_mode(VP8_COMP *cpi, |
| 770 MACROBLOCK *x, |
769 int *Rate, | 771 int *Rate, |
770 int *rate_y, | 772 int *rate_y, |
771 int *Distortion) | 773 int *Distortion) |
772 { | 774 { |
773 MB_PREDICTION_MODE mode; | 775 MB_PREDICTION_MODE mode; |
774 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); | 776 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); |
775 int rate, ratey; | 777 int rate, ratey; |
776 int distortion; | 778 int distortion; |
777 int best_rd = INT_MAX; | 779 int best_rd = INT_MAX; |
778 int this_rd; | 780 int this_rd; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 862 |
861 vp8_transform_mbuv(x); | 863 vp8_transform_mbuv(x); |
862 vp8_quantize_mbuv(x); | 864 vp8_quantize_mbuv(x); |
863 | 865 |
864 *rate = rd_cost_mbuv(x); | 866 *rate = rd_cost_mbuv(x); |
865 *distortion = vp8_mbuverror(x) / 4; | 867 *distortion = vp8_mbuverror(x) / 4; |
866 | 868 |
867 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); | 869 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); |
868 } | 870 } |
869 | 871 |
870 static void rd_pick_intra_mbuv_mode(MACROBLOCK *x, int *rate, | 872 static void rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int
*rate_tokenonly, int *distortion) |
871 int *rate_tokenonly, int *distortion) | |
872 { | 873 { |
873 MB_PREDICTION_MODE mode; | 874 MB_PREDICTION_MODE mode; |
874 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); | 875 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); |
875 int best_rd = INT_MAX; | 876 int best_rd = INT_MAX; |
876 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r); | 877 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r); |
877 int rate_to; | 878 int rate_to; |
878 MACROBLOCKD *xd = &x->e_mbd; | 879 MACROBLOCKD *xd = &x->e_mbd; |
879 | 880 |
880 for (mode = DC_PRED; mode <= TM_PRED; mode++) | 881 for (mode = DC_PRED; mode <= TM_PRED; mode++) |
881 { | 882 { |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 static void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv) | 1732 static void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv) |
1732 { | 1733 { |
1733 if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV) | 1734 if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV) |
1734 { | 1735 { |
1735 int i; | 1736 int i; |
1736 | 1737 |
1737 for (i = 0; i < x->partition_info->count; i++) | 1738 for (i = 0; i < x->partition_info->count; i++) |
1738 { | 1739 { |
1739 if (x->partition_info->bmi[i].mode == NEW4X4) | 1740 if (x->partition_info->bmi[i].mode == NEW4X4) |
1740 { | 1741 { |
1741 x->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row | 1742 cpi->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row |
1742 - best_ref_mv->as_mv.row) >> 1)]++; | 1743 - best_ref_mv->as_mv.row) >> 1)]++; |
1743 x->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col | 1744 cpi->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col |
1744 - best_ref_mv->as_mv.col) >> 1)]++; | 1745 - best_ref_mv->as_mv.col) >> 1)]++; |
1745 } | 1746 } |
1746 } | 1747 } |
1747 } | 1748 } |
1748 else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV) | 1749 else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV) |
1749 { | 1750 { |
1750 x->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row | 1751 cpi->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row |
1751 - best_ref_mv->as_mv.row) >> 1)]++; | 1752 - best_ref_mv->as_mv.row) >> 1)]++; |
1752 x->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col | 1753 cpi->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col |
1753 - best_ref_mv->as_mv.col) >> 1)]++; | 1754 - best_ref_mv->as_mv.col) >> 1)]++; |
1754 } | 1755 } |
1755 } | 1756 } |
1756 | 1757 |
1757 static int evaluate_inter_mode_rd(int mdcounts[4], | 1758 static int evaluate_inter_mode_rd(int mdcounts[4], |
1758 RATE_DISTORTION* rd, | 1759 RATE_DISTORTION* rd, |
1759 int* disable_skip, | 1760 int* disable_skip, |
1760 VP8_COMP *cpi, MACROBLOCK *x) | 1761 VP8_COMP *cpi, MACROBLOCK *x) |
1761 { | 1762 { |
1762 MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode; | 1763 MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 cpi->zbin_mode_boost = 0; | 2113 cpi->zbin_mode_boost = 0; |
2113 else | 2114 else |
2114 cpi->zbin_mode_boost = MV_ZBIN_BOOST; | 2115 cpi->zbin_mode_boost = MV_ZBIN_BOOST; |
2115 } | 2116 } |
2116 | 2117 |
2117 vp8_update_zbin_extra(cpi, x); | 2118 vp8_update_zbin_extra(cpi, x); |
2118 } | 2119 } |
2119 | 2120 |
2120 if(!uv_intra_done && this_ref_frame == INTRA_FRAME) | 2121 if(!uv_intra_done && this_ref_frame == INTRA_FRAME) |
2121 { | 2122 { |
2122 rd_pick_intra_mbuv_mode(x, &uv_intra_rate, | 2123 rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, |
2123 &uv_intra_rate_tokenonly, | 2124 &uv_intra_rate_tokenonly, |
2124 &uv_intra_distortion); | 2125 &uv_intra_distortion); |
2125 uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode; | 2126 uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode; |
2126 | 2127 |
2127 /* | 2128 /* |
2128 * Total of the eobs is used later to further adjust rate2. Since uv | 2129 * Total of the eobs is used later to further adjust rate2. Since uv |
2129 * block's intra eobs will be overwritten when we check inter modes, | 2130 * block's intra eobs will be overwritten when we check inter modes, |
2130 * we need to save uv_intra_tteob here. | 2131 * we need to save uv_intra_tteob here. |
2131 */ | 2132 */ |
2132 for (i = 16; i < 24; i++) | 2133 for (i = 16; i < 24; i++) |
2133 uv_intra_tteob += x->e_mbd.eobs[i]; | 2134 uv_intra_tteob += x->e_mbd.eobs[i]; |
2134 | 2135 |
2135 uv_intra_done = 1; | 2136 uv_intra_done = 1; |
2136 } | 2137 } |
2137 | 2138 |
2138 switch (this_mode) | 2139 switch (this_mode) |
2139 { | 2140 { |
2140 case B_PRED: | 2141 case B_PRED: |
2141 { | 2142 { |
2142 int tmp_rd; | 2143 int tmp_rd; |
2143 | 2144 |
2144 /* Note the rate value returned here includes the cost of | 2145 /* Note the rate value returned here includes the cost of |
2145 * coding the BPRED mode: x->mbmode_cost[x->e_mbd.frame_type][BPRED] | 2146 * coding the BPRED mode: x->mbmode_cost[x->e_mbd.frame_type][BPRED] |
2146 */ | 2147 */ |
2147 int distortion; | 2148 int distortion; |
2148 tmp_rd = rd_pick_intra4x4mby_modes(x, &rate, &rd.rate_y, &distortion
, best_mode.yrd); | 2149 tmp_rd = rd_pick_intra4x4mby_modes(cpi, x, &rate, &rd.rate_y, &disto
rtion, best_mode.yrd); |
2149 rd.rate2 += rate; | 2150 rd.rate2 += rate; |
2150 rd.distortion2 += distortion; | 2151 rd.distortion2 += distortion; |
2151 | 2152 |
2152 if(tmp_rd < best_mode.yrd) | 2153 if(tmp_rd < best_mode.yrd) |
2153 { | 2154 { |
2154 rd.rate2 += uv_intra_rate; | 2155 rd.rate2 += uv_intra_rate; |
2155 rd.rate_uv = uv_intra_rate_tokenonly; | 2156 rd.rate_uv = uv_intra_rate_tokenonly; |
2156 rd.distortion2 += uv_intra_distortion; | 2157 rd.distortion2 += uv_intra_distortion; |
2157 rd.distortion_uv = uv_intra_distortion; | 2158 rd.distortion_uv = uv_intra_distortion; |
2158 } | 2159 } |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 x->partition_info->bmi[15].mv.as_int; | 2588 x->partition_info->bmi[15].mv.as_int; |
2588 } | 2589 } |
2589 | 2590 |
2590 if (sign_bias | 2591 if (sign_bias |
2591 != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame
]) | 2592 != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame
]) |
2592 best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int; | 2593 best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int; |
2593 | 2594 |
2594 rd_update_mvcount(cpi, x, &best_ref_mv); | 2595 rd_update_mvcount(cpi, x, &best_ref_mv); |
2595 } | 2596 } |
2596 | 2597 |
2597 void vp8_rd_pick_intra_mode(MACROBLOCK *x, int *rate_) | 2598 void vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate_) |
2598 { | 2599 { |
2599 int error4x4, error16x16; | 2600 int error4x4, error16x16; |
2600 int rate4x4, rate16x16 = 0, rateuv; | 2601 int rate4x4, rate16x16 = 0, rateuv; |
2601 int dist4x4, dist16x16, distuv; | 2602 int dist4x4, dist16x16, distuv; |
2602 int rate; | 2603 int rate; |
2603 int rate4x4_tokenonly = 0; | 2604 int rate4x4_tokenonly = 0; |
2604 int rate16x16_tokenonly = 0; | 2605 int rate16x16_tokenonly = 0; |
2605 int rateuv_tokenonly = 0; | 2606 int rateuv_tokenonly = 0; |
2606 | 2607 |
2607 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; | 2608 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; |
2608 | 2609 |
2609 rd_pick_intra_mbuv_mode(x, &rateuv, &rateuv_tokenonly, &distuv); | 2610 rd_pick_intra_mbuv_mode(cpi, x, &rateuv, &rateuv_tokenonly, &distuv); |
2610 rate = rateuv; | 2611 rate = rateuv; |
2611 | 2612 |
2612 error16x16 = rd_pick_intra16x16mby_mode(x, &rate16x16, &rate16x16_tokenonly, | 2613 error16x16 = rd_pick_intra16x16mby_mode(cpi, x, |
| 2614 &rate16x16, &rate16x16_tokenonly, |
2613 &dist16x16); | 2615 &dist16x16); |
2614 | 2616 |
2615 error4x4 = rd_pick_intra4x4mby_modes(x, &rate4x4, &rate4x4_tokenonly, | 2617 error4x4 = rd_pick_intra4x4mby_modes(cpi, x, |
| 2618 &rate4x4, &rate4x4_tokenonly, |
2616 &dist4x4, error16x16); | 2619 &dist4x4, error16x16); |
2617 | 2620 |
2618 if (error4x4 < error16x16) | 2621 if (error4x4 < error16x16) |
2619 { | 2622 { |
2620 x->e_mbd.mode_info_context->mbmi.mode = B_PRED; | 2623 x->e_mbd.mode_info_context->mbmi.mode = B_PRED; |
2621 rate += rate4x4; | 2624 rate += rate4x4; |
2622 } | 2625 } |
2623 else | 2626 else |
2624 { | 2627 { |
2625 rate += rate16x16; | 2628 rate += rate16x16; |
2626 } | 2629 } |
2627 | 2630 |
2628 *rate_ = rate; | 2631 *rate_ = rate; |
2629 } | 2632 } |
OLD | NEW |