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

Side by Side Diff: source/libvpx/vp8/encoder/rdopt.c

Issue 11974002: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp8/encoder/rdopt.h ('k') | source/libvpx/vp8/encoder/temporal_filter.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 16, 16, 16, 16, 17, 17, 17, 18, 216 16, 16, 16, 16, 17, 17, 17, 18,
217 18, 18, 19, 19, 19, 20, 20, 20, 217 18, 18, 19, 19, 19, 20, 20, 20,
218 }; 218 };
219 219
220 void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex) 220 void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex)
221 { 221 {
222 cpi->mb.sadperbit16 = sad_per_bit16lut[QIndex]; 222 cpi->mb.sadperbit16 = sad_per_bit16lut[QIndex];
223 cpi->mb.sadperbit4 = sad_per_bit4lut[QIndex]; 223 cpi->mb.sadperbit4 = sad_per_bit4lut[QIndex];
224 } 224 }
225 225
226 void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue) 226 void vp8_initialize_rd_consts(VP8_COMP *cpi, MACROBLOCK *x, int Qvalue)
227 { 227 {
228 int q; 228 int q;
229 int i; 229 int i;
230 double capped_q = (Qvalue < 160) ? (double)Qvalue : 160.0; 230 double capped_q = (Qvalue < 160) ? (double)Qvalue : 160.0;
231 double rdconst = 2.80; 231 double rdconst = 2.80;
232 232
233 vp8_clear_system_state(); 233 vp8_clear_system_state();
234 234
235 /* Further tests required to see if optimum is different 235 /* Further tests required to see if optimum is different
236 * for key frames, golden frames and arf frames. 236 * for key frames, golden frames and arf frames.
237 */ 237 */
238 cpi->RDMULT = (int)(rdconst * (capped_q * capped_q)); 238 cpi->RDMULT = (int)(rdconst * (capped_q * capped_q));
239 239
240 /* Extend rate multiplier along side quantizer zbin increases */ 240 /* Extend rate multiplier along side quantizer zbin increases */
241 if (cpi->zbin_over_quant > 0) 241 if (cpi->mb.zbin_over_quant > 0)
242 { 242 {
243 double oq_factor; 243 double oq_factor;
244 double modq; 244 double modq;
245 245
246 /* Experimental code using the same basic equation as used for Q above 246 /* Experimental code using the same basic equation as used for Q above
247 * The units of cpi->zbin_over_quant are 1/128 of Q bin size 247 * The units of cpi->mb.zbin_over_quant are 1/128 of Q bin size
248 */ 248 */
249 oq_factor = 1.0 + ((double)0.0015625 * cpi->zbin_over_quant); 249 oq_factor = 1.0 + ((double)0.0015625 * cpi->mb.zbin_over_quant);
250 modq = (int)((double)capped_q * oq_factor); 250 modq = (int)((double)capped_q * oq_factor);
251 cpi->RDMULT = (int)(rdconst * (modq * modq)); 251 cpi->RDMULT = (int)(rdconst * (modq * modq));
252 } 252 }
253 253
254 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) 254 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME))
255 { 255 {
256 if (cpi->twopass.next_iiratio > 31) 256 if (cpi->twopass.next_iiratio > 31)
257 cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4; 257 cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4;
258 else 258 else
259 cpi->RDMULT += 259 cpi->RDMULT +=
260 (cpi->RDMULT * rd_iifactor[cpi->twopass.next_iiratio]) >> 4; 260 (cpi->RDMULT * rd_iifactor[cpi->twopass.next_iiratio]) >> 4;
261 } 261 }
262 262
263 cpi->mb.errorperbit = (cpi->RDMULT / 110); 263 cpi->mb.errorperbit = (cpi->RDMULT / 110);
264 cpi->mb.errorperbit += (cpi->mb.errorperbit==0); 264 cpi->mb.errorperbit += (cpi->mb.errorperbit==0);
265 265
266 vp8_set_speed_features(cpi); 266 vp8_set_speed_features(cpi);
267 267
268 for (i = 0; i < MAX_MODES; i++)
269 {
270 x->mode_test_hit_counts[i] = 0;
271 }
272
268 q = (int)pow(Qvalue, 1.25); 273 q = (int)pow(Qvalue, 1.25);
269 274
270 if (q < 8) 275 if (q < 8)
271 q = 8; 276 q = 8;
272 277
273 if (cpi->RDMULT > 1000) 278 if (cpi->RDMULT > 1000)
274 { 279 {
275 cpi->RDDIV = 1; 280 cpi->RDDIV = 1;
276 cpi->RDMULT /= 100; 281 cpi->RDMULT /= 100;
277 282
278 for (i = 0; i < MAX_MODES; i++) 283 for (i = 0; i < MAX_MODES; i++)
279 { 284 {
280 if (cpi->sf.thresh_mult[i] < INT_MAX) 285 if (cpi->sf.thresh_mult[i] < INT_MAX)
281 { 286 {
282 cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q / 100; 287 x->rd_threshes[i] = cpi->sf.thresh_mult[i] * q / 100;
283 } 288 }
284 else 289 else
285 { 290 {
286 cpi->rd_threshes[i] = INT_MAX; 291 x->rd_threshes[i] = INT_MAX;
287 } 292 }
288 293
289 cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i]; 294 cpi->rd_baseline_thresh[i] = x->rd_threshes[i];
290 } 295 }
291 } 296 }
292 else 297 else
293 { 298 {
294 cpi->RDDIV = 100; 299 cpi->RDDIV = 100;
295 300
296 for (i = 0; i < MAX_MODES; i++) 301 for (i = 0; i < MAX_MODES; i++)
297 { 302 {
298 if (cpi->sf.thresh_mult[i] < (INT_MAX / q)) 303 if (cpi->sf.thresh_mult[i] < (INT_MAX / q))
299 { 304 {
300 cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q; 305 x->rd_threshes[i] = cpi->sf.thresh_mult[i] * q;
301 } 306 }
302 else 307 else
303 { 308 {
304 cpi->rd_threshes[i] = INT_MAX; 309 x->rd_threshes[i] = INT_MAX;
305 } 310 }
306 311
307 cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i]; 312 cpi->rd_baseline_thresh[i] = x->rd_threshes[i];
308 } 313 }
309 } 314 }
310 315
311 { 316 {
312 /* build token cost array for the type of frame we have now */ 317 /* build token cost array for the type of frame we have now */
313 FRAME_CONTEXT *l = &cpi->lfc_n; 318 FRAME_CONTEXT *l = &cpi->lfc_n;
314 319
315 if(cpi->common.refresh_alt_ref_frame) 320 if(cpi->common.refresh_alt_ref_frame)
316 l = &cpi->lfc_a; 321 l = &cpi->lfc_a;
317 else if(cpi->common.refresh_golden_frame) 322 else if(cpi->common.refresh_golden_frame)
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 static void copy_predictor(unsigned char *dst, const unsigned char *predictor) 623 static void copy_predictor(unsigned char *dst, const unsigned char *predictor)
619 { 624 {
620 const unsigned int *p = (const unsigned int *)predictor; 625 const unsigned int *p = (const unsigned int *)predictor;
621 unsigned int *d = (unsigned int *)dst; 626 unsigned int *d = (unsigned int *)dst;
622 d[0] = p[0]; 627 d[0] = p[0];
623 d[4] = p[4]; 628 d[4] = p[4];
624 d[8] = p[8]; 629 d[8] = p[8];
625 d[12] = p[12]; 630 d[12] = p[12];
626 } 631 }
627 static int rd_pick_intra4x4block( 632 static int rd_pick_intra4x4block(
628 VP8_COMP *cpi,
629 MACROBLOCK *x, 633 MACROBLOCK *x,
630 BLOCK *be, 634 BLOCK *be,
631 BLOCKD *b, 635 BLOCKD *b,
632 B_PREDICTION_MODE *best_mode, 636 B_PREDICTION_MODE *best_mode,
633 const int *bmode_costs, 637 const int *bmode_costs,
634 ENTROPY_CONTEXT *a, 638 ENTROPY_CONTEXT *a,
635 ENTROPY_CONTEXT *l, 639 ENTROPY_CONTEXT *l,
636 640
637 int *bestrate, 641 int *bestrate,
638 int *bestratey, 642 int *bestratey,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32); 698 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32);
695 } 699 }
696 } 700 }
697 b->bmi.as_mode = *best_mode; 701 b->bmi.as_mode = *best_mode;
698 702
699 vp8_short_idct4x4llm(best_dqcoeff, best_predictor, 16, dst, dst_stride); 703 vp8_short_idct4x4llm(best_dqcoeff, best_predictor, 16, dst, dst_stride);
700 704
701 return best_rd; 705 return best_rd;
702 } 706 }
703 707
704 static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate, 708 static int rd_pick_intra4x4mby_modes(MACROBLOCK *mb, int *Rate,
705 int *rate_y, int *Distortion, int best_rd) 709 int *rate_y, int *Distortion, int best_rd)
706 { 710 {
707 MACROBLOCKD *const xd = &mb->e_mbd; 711 MACROBLOCKD *const xd = &mb->e_mbd;
708 int i; 712 int i;
709 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED]; 713 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
710 int distortion = 0; 714 int distortion = 0;
711 int tot_rate_y = 0; 715 int tot_rate_y = 0;
712 int64_t total_rd = 0; 716 int64_t total_rd = 0;
713 ENTROPY_CONTEXT_PLANES t_above, t_left; 717 ENTROPY_CONTEXT_PLANES t_above, t_left;
714 ENTROPY_CONTEXT *ta; 718 ENTROPY_CONTEXT *ta;
(...skipping 19 matching lines...) Expand all
734 738
735 if (mb->e_mbd.frame_type == KEY_FRAME) 739 if (mb->e_mbd.frame_type == KEY_FRAME)
736 { 740 {
737 const B_PREDICTION_MODE A = above_block_mode(mic, i, mis); 741 const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
738 const B_PREDICTION_MODE L = left_block_mode(mic, i); 742 const B_PREDICTION_MODE L = left_block_mode(mic, i);
739 743
740 bmode_costs = mb->bmode_costs[A][L]; 744 bmode_costs = mb->bmode_costs[A][L];
741 } 745 }
742 746
743 total_rd += rd_pick_intra4x4block( 747 total_rd += rd_pick_intra4x4block(
744 cpi, mb, mb->block + i, xd->block + i, &best_mode, bmode_costs, 748 mb, mb->block + i, xd->block + i, &best_mode, bmode_costs,
745 ta + vp8_block2above[i], 749 ta + vp8_block2above[i],
746 tl + vp8_block2left[i], &r, &ry, &d); 750 tl + vp8_block2left[i], &r, &ry, &d);
747 751
748 cost += r; 752 cost += r;
749 distortion += d; 753 distortion += d;
750 tot_rate_y += ry; 754 tot_rate_y += ry;
751 755
752 mic->bmi[i].as_mode = best_mode; 756 mic->bmi[i].as_mode = best_mode;
753 757
754 if(total_rd >= (int64_t)best_rd) 758 if(total_rd >= (int64_t)best_rd)
755 break; 759 break;
756 } 760 }
757 761
758 if(total_rd >= (int64_t)best_rd) 762 if(total_rd >= (int64_t)best_rd)
759 return INT_MAX; 763 return INT_MAX;
760 764
761 *Rate = cost; 765 *Rate = cost;
762 *rate_y = tot_rate_y; 766 *rate_y = tot_rate_y;
763 *Distortion = distortion; 767 *Distortion = distortion;
764 768
765 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion); 769 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
766 } 770 }
767 771
768 772
769 static int rd_pick_intra16x16mby_mode(VP8_COMP *cpi, 773 static int rd_pick_intra16x16mby_mode(MACROBLOCK *x,
770 MACROBLOCK *x,
771 int *Rate, 774 int *Rate,
772 int *rate_y, 775 int *rate_y,
773 int *Distortion) 776 int *Distortion)
774 { 777 {
775 MB_PREDICTION_MODE mode; 778 MB_PREDICTION_MODE mode;
776 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 779 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
777 int rate, ratey; 780 int rate, ratey;
778 int distortion; 781 int distortion;
779 int best_rd = INT_MAX; 782 int best_rd = INT_MAX;
780 int this_rd; 783 int this_rd;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 865
863 vp8_transform_mbuv(x); 866 vp8_transform_mbuv(x);
864 vp8_quantize_mbuv(x); 867 vp8_quantize_mbuv(x);
865 868
866 *rate = rd_cost_mbuv(x); 869 *rate = rd_cost_mbuv(x);
867 *distortion = vp8_mbuverror(x) / 4; 870 *distortion = vp8_mbuverror(x) / 4;
868 871
869 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); 872 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
870 } 873 }
871 874
872 static void rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *rate_tokenonly, int *distortion) 875 static void rd_pick_intra_mbuv_mode(MACROBLOCK *x, int *rate,
876 int *rate_tokenonly, int *distortion)
873 { 877 {
874 MB_PREDICTION_MODE mode; 878 MB_PREDICTION_MODE mode;
875 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 879 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
876 int best_rd = INT_MAX; 880 int best_rd = INT_MAX;
877 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r); 881 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r);
878 int rate_to; 882 int rate_to;
879 MACROBLOCKD *xd = &x->e_mbd; 883 MACROBLOCKD *xd = &x->e_mbd;
880 884
881 for (mode = DC_PRED; mode <= TM_PRED; mode++) 885 for (mode = DC_PRED; mode <= TM_PRED; mode++)
882 { 886 {
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 1726
1723 if(cpi->common.last_frame_type != KEY_FRAME) 1727 if(cpi->common.last_frame_type != KEY_FRAME)
1724 { 1728 {
1725 insertsortsad(near_sad, near_sadidx, 8); 1729 insertsortsad(near_sad, near_sadidx, 8);
1726 }else 1730 }else
1727 { 1731 {
1728 insertsortsad(near_sad, near_sadidx, 3); 1732 insertsortsad(near_sad, near_sadidx, 3);
1729 } 1733 }
1730 } 1734 }
1731 1735
1732 static void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv) 1736 static void rd_update_mvcount(MACROBLOCK *x, int_mv *best_ref_mv)
1733 { 1737 {
1734 if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV) 1738 if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV)
1735 { 1739 {
1736 int i; 1740 int i;
1737 1741
1738 for (i = 0; i < x->partition_info->count; i++) 1742 for (i = 0; i < x->partition_info->count; i++)
1739 { 1743 {
1740 if (x->partition_info->bmi[i].mode == NEW4X4) 1744 if (x->partition_info->bmi[i].mode == NEW4X4)
1741 { 1745 {
1742 cpi->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row 1746 x->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row
1743 - best_ref_mv->as_mv.row) >> 1)]++; 1747 - best_ref_mv->as_mv.row) >> 1)]++;
1744 cpi->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col 1748 x->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col
1745 - best_ref_mv->as_mv.col) >> 1)]++; 1749 - best_ref_mv->as_mv.col) >> 1)]++;
1746 } 1750 }
1747 } 1751 }
1748 } 1752 }
1749 else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV) 1753 else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV)
1750 { 1754 {
1751 cpi->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row 1755 x->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row
1752 - best_ref_mv->as_mv.row) >> 1)]++; 1756 - best_ref_mv->as_mv.row) >> 1)]++;
1753 cpi->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col 1757 x->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col
1754 - best_ref_mv->as_mv.col) >> 1)]++; 1758 - best_ref_mv->as_mv.col) >> 1)]++;
1755 } 1759 }
1756 } 1760 }
1757 1761
1758 static int evaluate_inter_mode_rd(int mdcounts[4], 1762 static int evaluate_inter_mode_rd(int mdcounts[4],
1759 RATE_DISTORTION* rd, 1763 RATE_DISTORTION* rd,
1760 int* disable_skip, 1764 int* disable_skip,
1761 VP8_COMP *cpi, MACROBLOCK *x) 1765 VP8_COMP *cpi, MACROBLOCK *x)
1762 { 1766 {
1763 MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode; 1767 MB_PREDICTION_MODE this_mode = x->e_mbd.mode_info_context->mbmi.mode;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 cpi->common.ref_frame_sign_bias); 2008 cpi->common.ref_frame_sign_bias);
2005 2009
2006 mode_mv = mode_mv_sb[sign_bias]; 2010 mode_mv = mode_mv_sb[sign_bias];
2007 best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int; 2011 best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int;
2008 } 2012 }
2009 2013
2010 get_predictor_pointers(cpi, plane, recon_yoffset, recon_uvoffset); 2014 get_predictor_pointers(cpi, plane, recon_yoffset, recon_uvoffset);
2011 2015
2012 *returnintra = INT_MAX; 2016 *returnintra = INT_MAX;
2013 /* Count of the number of MBs tested so far this frame */ 2017 /* Count of the number of MBs tested so far this frame */
2014 cpi->mbs_tested_so_far++; 2018 x->mbs_tested_so_far++;
2015 2019
2016 x->skip = 0; 2020 x->skip = 0;
2017 2021
2018 for (mode_index = 0; mode_index < MAX_MODES; mode_index++) 2022 for (mode_index = 0; mode_index < MAX_MODES; mode_index++)
2019 { 2023 {
2020 int this_rd = INT_MAX; 2024 int this_rd = INT_MAX;
2021 int disable_skip = 0; 2025 int disable_skip = 0;
2022 int other_cost = 0; 2026 int other_cost = 0;
2023 int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]]; 2027 int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]];
2024 2028
2025 /* Test best rd so far against threshold for trying this mode. */ 2029 /* Test best rd so far against threshold for trying this mode. */
2026 if (best_mode.rd <= cpi->rd_threshes[mode_index]) 2030 if (best_mode.rd <= x->rd_threshes[mode_index])
2027 continue; 2031 continue;
2028 2032
2029 if (this_ref_frame < 0) 2033 if (this_ref_frame < 0)
2030 continue; 2034 continue;
2031 2035
2032 /* These variables hold are rolling total cost and distortion for 2036 /* These variables hold are rolling total cost and distortion for
2033 * this mode 2037 * this mode
2034 */ 2038 */
2035 rd.rate2 = 0; 2039 rd.rate2 = 0;
2036 rd.distortion2 = 0; 2040 rd.distortion2 = 0;
(...skipping 25 matching lines...) Expand all
2062 sign_bias = cpi->common.ref_frame_sign_bias[this_ref_frame]; 2066 sign_bias = cpi->common.ref_frame_sign_bias[this_ref_frame];
2063 mode_mv = mode_mv_sb[sign_bias]; 2067 mode_mv = mode_mv_sb[sign_bias];
2064 best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int; 2068 best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int;
2065 } 2069 }
2066 } 2070 }
2067 2071
2068 /* Check to see if the testing frequency for this mode is at its 2072 /* Check to see if the testing frequency for this mode is at its
2069 * max If so then prevent it from being tested and increase the 2073 * max If so then prevent it from being tested and increase the
2070 * threshold for its testing 2074 * threshold for its testing
2071 */ 2075 */
2072 if (cpi->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_ index] > 1)) 2076 if (x->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_in dex] > 1))
2073 { 2077 {
2074 if (cpi->mbs_tested_so_far <= cpi->mode_check_freq[mode_index] * cp i->mode_test_hit_counts[mode_index]) 2078 if (x->mbs_tested_so_far <= cpi->mode_check_freq[mode_index] * x->m ode_test_hit_counts[mode_index])
2075 { 2079 {
2076 /* Increase the threshold for coding this mode to make it 2080 /* Increase the threshold for coding this mode to make it
2077 * less likely to be chosen 2081 * less likely to be chosen
2078 */ 2082 */
2079 cpi->rd_thresh_mult[mode_index] += 4; 2083 x->rd_thresh_mult[mode_index] += 4;
2080 2084
2081 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT) 2085 if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
2082 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT; 2086 x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
2083 2087
2084 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_ind ex] >> 7) * cpi->rd_thresh_mult[mode_index]; 2088 x->rd_threshes[mode_index] =
2089 (cpi->rd_baseline_thresh[mode_index] >> 7) *
2090 x->rd_thresh_mult[mode_index];
2085 2091
2086 continue; 2092 continue;
2087 } 2093 }
2088 } 2094 }
2089 2095
2090 /* We have now reached the point where we are going to test the 2096 /* We have now reached the point where we are going to test the
2091 * current mode so increment the counter for the number of times 2097 * current mode so increment the counter for the number of times
2092 * it has been tested 2098 * it has been tested
2093 */ 2099 */
2094 cpi->mode_test_hit_counts[mode_index] ++; 2100 x->mode_test_hit_counts[mode_index] ++;
2095 2101
2096 /* Experimental code. Special case for gf and arf zeromv modes. 2102 /* Experimental code. Special case for gf and arf zeromv modes.
2097 * Increase zbin size to supress noise 2103 * Increase zbin size to supress noise
2098 */ 2104 */
2099 if (cpi->zbin_mode_boost_enabled) 2105 if (x->zbin_mode_boost_enabled)
2100 { 2106 {
2101 if ( this_ref_frame == INTRA_FRAME ) 2107 if ( this_ref_frame == INTRA_FRAME )
2102 cpi->zbin_mode_boost = 0; 2108 x->zbin_mode_boost = 0;
2103 else 2109 else
2104 { 2110 {
2105 if (vp8_mode_order[mode_index] == ZEROMV) 2111 if (vp8_mode_order[mode_index] == ZEROMV)
2106 { 2112 {
2107 if (this_ref_frame != LAST_FRAME) 2113 if (this_ref_frame != LAST_FRAME)
2108 cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST; 2114 x->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST;
2109 else 2115 else
2110 cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST; 2116 x->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST;
2111 } 2117 }
2112 else if (vp8_mode_order[mode_index] == SPLITMV) 2118 else if (vp8_mode_order[mode_index] == SPLITMV)
2113 cpi->zbin_mode_boost = 0; 2119 x->zbin_mode_boost = 0;
2114 else 2120 else
2115 cpi->zbin_mode_boost = MV_ZBIN_BOOST; 2121 x->zbin_mode_boost = MV_ZBIN_BOOST;
2116 } 2122 }
2117 2123
2118 vp8_update_zbin_extra(cpi, x); 2124 vp8_update_zbin_extra(cpi, x);
2119 } 2125 }
2120 2126
2121 if(!uv_intra_done && this_ref_frame == INTRA_FRAME) 2127 if(!uv_intra_done && this_ref_frame == INTRA_FRAME)
2122 { 2128 {
2123 rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, 2129 rd_pick_intra_mbuv_mode(x, &uv_intra_rate,
2124 &uv_intra_rate_tokenonly, 2130 &uv_intra_rate_tokenonly,
2125 &uv_intra_distortion); 2131 &uv_intra_distortion);
2126 uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode; 2132 uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode;
2127 2133
2128 /* 2134 /*
2129 * Total of the eobs is used later to further adjust rate2. Since uv 2135 * Total of the eobs is used later to further adjust rate2. Since uv
2130 * block's intra eobs will be overwritten when we check inter modes, 2136 * block's intra eobs will be overwritten when we check inter modes,
2131 * we need to save uv_intra_tteob here. 2137 * we need to save uv_intra_tteob here.
2132 */ 2138 */
2133 for (i = 16; i < 24; i++) 2139 for (i = 16; i < 24; i++)
2134 uv_intra_tteob += x->e_mbd.eobs[i]; 2140 uv_intra_tteob += x->e_mbd.eobs[i];
2135 2141
2136 uv_intra_done = 1; 2142 uv_intra_done = 1;
2137 } 2143 }
2138 2144
2139 switch (this_mode) 2145 switch (this_mode)
2140 { 2146 {
2141 case B_PRED: 2147 case B_PRED:
2142 { 2148 {
2143 int tmp_rd; 2149 int tmp_rd;
2144 2150
2145 /* Note the rate value returned here includes the cost of 2151 /* Note the rate value returned here includes the cost of
2146 * coding the BPRED mode: x->mbmode_cost[x->e_mbd.frame_type][BPRED] 2152 * coding the BPRED mode: x->mbmode_cost[x->e_mbd.frame_type][BPRED]
2147 */ 2153 */
2148 int distortion; 2154 int distortion;
2149 tmp_rd = rd_pick_intra4x4mby_modes(cpi, x, &rate, &rd.rate_y, &disto rtion, best_mode.yrd); 2155 tmp_rd = rd_pick_intra4x4mby_modes(x, &rate, &rd.rate_y, &distortion , best_mode.yrd);
2150 rd.rate2 += rate; 2156 rd.rate2 += rate;
2151 rd.distortion2 += distortion; 2157 rd.distortion2 += distortion;
2152 2158
2153 if(tmp_rd < best_mode.yrd) 2159 if(tmp_rd < best_mode.yrd)
2154 { 2160 {
2155 rd.rate2 += uv_intra_rate; 2161 rd.rate2 += uv_intra_rate;
2156 rd.rate_uv = uv_intra_rate_tokenonly; 2162 rd.rate_uv = uv_intra_rate_tokenonly;
2157 rd.distortion2 += uv_intra_distortion; 2163 rd.distortion2 += uv_intra_distortion;
2158 rd.distortion_uv = uv_intra_distortion; 2164 rd.distortion_uv = uv_intra_distortion;
2159 } 2165 }
2160 else 2166 else
2161 { 2167 {
2162 this_rd = INT_MAX; 2168 this_rd = INT_MAX;
2163 disable_skip = 1; 2169 disable_skip = 1;
2164 } 2170 }
2165 } 2171 }
2166 break; 2172 break;
2167 2173
2168 case SPLITMV: 2174 case SPLITMV:
2169 { 2175 {
2170 int tmp_rd; 2176 int tmp_rd;
2171 int this_rd_thresh; 2177 int this_rd_thresh;
2172 int distortion; 2178 int distortion;
2173 2179
2174 this_rd_thresh = (vp8_ref_frame_order[mode_index] == 1) ? cpi->rd_th reshes[THR_NEW1] : cpi->rd_threshes[THR_NEW3]; 2180 this_rd_thresh = (vp8_ref_frame_order[mode_index] == 1) ?
2175 this_rd_thresh = (vp8_ref_frame_order[mode_index] == 2) ? cpi->rd_th reshes[THR_NEW2] : this_rd_thresh; 2181 x->rd_threshes[THR_NEW1] : x->rd_threshes[THR_NEW3];
2182 this_rd_thresh = (vp8_ref_frame_order[mode_index] == 2) ?
2183 x->rd_threshes[THR_NEW2] : this_rd_thresh;
2176 2184
2177 tmp_rd = vp8_rd_pick_best_mbsegmentation(cpi, x, &best_ref_mv, 2185 tmp_rd = vp8_rd_pick_best_mbsegmentation(cpi, x, &best_ref_mv,
2178 best_mode.yrd, mdcounts, 2186 best_mode.yrd, mdcounts,
2179 &rate, &rd.rate_y, &distort ion, this_rd_thresh) ; 2187 &rate, &rd.rate_y, &distort ion, this_rd_thresh) ;
2180 2188
2181 rd.rate2 += rate; 2189 rd.rate2 += rate;
2182 rd.distortion2 += distortion; 2190 rd.distortion2 += distortion;
2183 2191
2184 /* If even the 'Y' rd value of split is higher than best so far 2192 /* If even the 'Y' rd value of split is higher than best so far
2185 * then dont bother looking at UV 2193 * then dont bother looking at UV
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode; 2466 x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode;
2459 /* required for left and above block mv */ 2467 /* required for left and above block mv */
2460 x->e_mbd.mode_info_context->mbmi.mv.as_int = 0; 2468 x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
2461 } 2469 }
2462 update_best_mode(&best_mode, this_rd, &rd, other_cost, x); 2470 update_best_mode(&best_mode, this_rd, &rd, other_cost, x);
2463 2471
2464 2472
2465 /* Testing this mode gave rise to an improvement in best error 2473 /* Testing this mode gave rise to an improvement in best error
2466 * score. Lower threshold a bit for next time 2474 * score. Lower threshold a bit for next time
2467 */ 2475 */
2468 cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] > = (MIN_THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT; 2476 x->rd_thresh_mult[mode_index] =
2469 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index]; 2477 (x->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
2478 x->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
2470 } 2479 }
2471 2480
2472 /* If the mode did not help improve the best error case then raise 2481 /* If the mode did not help improve the best error case then raise
2473 * the threshold for testing that mode next time around. 2482 * the threshold for testing that mode next time around.
2474 */ 2483 */
2475 else 2484 else
2476 { 2485 {
2477 cpi->rd_thresh_mult[mode_index] += 4; 2486 x->rd_thresh_mult[mode_index] += 4;
2478 2487
2479 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT) 2488 if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
2480 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT; 2489 x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
2481
2482 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
2483 } 2490 }
2491 x->rd_threshes[mode_index] =
2492 (cpi->rd_baseline_thresh[mode_index] >> 7) *
2493 x->rd_thresh_mult[mode_index];
2484 2494
2485 if (x->skip) 2495 if (x->skip)
2486 break; 2496 break;
2487 2497
2488 } 2498 }
2489 2499
2490 /* Reduce the activation RD thresholds for the best choice mode */ 2500 /* Reduce the activation RD thresholds for the best choice mode */
2491 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thre sh[best_mode_index] < (INT_MAX >> 2))) 2501 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thre sh[best_mode_index] < (INT_MAX >> 2)))
2492 { 2502 {
2493 int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 2); 2503 int best_adjustment = (x->rd_thresh_mult[best_mode_index] >> 2);
2494 2504
2495 cpi->rd_thresh_mult[best_mode_index] = (cpi->rd_thresh_mult[best_mode_in dex] >= (MIN_THRESHMULT + best_adjustment)) ? cpi->rd_thresh_mult[best_mode_inde x] - best_adjustment : MIN_THRESHMULT; 2505 x->rd_thresh_mult[best_mode_index] =
2496 cpi->rd_threshes[best_mode_index] = (cpi->rd_baseline_thresh[best_mode_i ndex] >> 7) * cpi->rd_thresh_mult[best_mode_index]; 2506 (x->rd_thresh_mult[best_mode_index] >=
2507 (MIN_THRESHMULT + best_adjustment)) ?
2508 x->rd_thresh_mult[best_mode_index] - best_adjustment :
2509 MIN_THRESHMULT;
2510 x->rd_threshes[best_mode_index] =
2511 (cpi->rd_baseline_thresh[best_mode_index] >> 7) *
2512 x->rd_thresh_mult[best_mode_index];
2497 } 2513 }
2498 2514
2499 /* Note how often each mode chosen as best */ 2515 /* Note how often each mode chosen as best */
2500 cpi->mode_chosen_counts[best_mode_index] ++; 2516 cpi->mode_chosen_counts[best_mode_index] ++;
2501 2517
2502 #if CONFIG_TEMPORAL_DENOISING 2518 #if CONFIG_TEMPORAL_DENOISING
2503 if (cpi->oxcf.noise_sensitivity) 2519 if (cpi->oxcf.noise_sensitivity)
2504 { 2520 {
2505 if (x->best_sse_inter_mode == DC_PRED) 2521 if (x->best_sse_inter_mode == DC_PRED)
2506 { 2522 {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 vpx_memcpy(x->partition_info, &best_mode.partition, sizeof(PARTITION_INF O)); 2601 vpx_memcpy(x->partition_info, &best_mode.partition, sizeof(PARTITION_INF O));
2586 2602
2587 x->e_mbd.mode_info_context->mbmi.mv.as_int = 2603 x->e_mbd.mode_info_context->mbmi.mv.as_int =
2588 x->partition_info->bmi[15].mv.as_int; 2604 x->partition_info->bmi[15].mv.as_int;
2589 } 2605 }
2590 2606
2591 if (sign_bias 2607 if (sign_bias
2592 != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame ]) 2608 != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame ])
2593 best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int; 2609 best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int;
2594 2610
2595 rd_update_mvcount(cpi, x, &best_ref_mv); 2611 rd_update_mvcount(x, &best_ref_mv);
2596 } 2612 }
2597 2613
2598 void vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate_) 2614 void vp8_rd_pick_intra_mode(MACROBLOCK *x, int *rate_)
2599 { 2615 {
2600 int error4x4, error16x16; 2616 int error4x4, error16x16;
2601 int rate4x4, rate16x16 = 0, rateuv; 2617 int rate4x4, rate16x16 = 0, rateuv;
2602 int dist4x4, dist16x16, distuv; 2618 int dist4x4, dist16x16, distuv;
2603 int rate; 2619 int rate;
2604 int rate4x4_tokenonly = 0; 2620 int rate4x4_tokenonly = 0;
2605 int rate16x16_tokenonly = 0; 2621 int rate16x16_tokenonly = 0;
2606 int rateuv_tokenonly = 0; 2622 int rateuv_tokenonly = 0;
2607 2623
2608 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; 2624 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
2609 2625
2610 rd_pick_intra_mbuv_mode(cpi, x, &rateuv, &rateuv_tokenonly, &distuv); 2626 rd_pick_intra_mbuv_mode(x, &rateuv, &rateuv_tokenonly, &distuv);
2611 rate = rateuv; 2627 rate = rateuv;
2612 2628
2613 error16x16 = rd_pick_intra16x16mby_mode(cpi, x, 2629 error16x16 = rd_pick_intra16x16mby_mode(x, &rate16x16, &rate16x16_tokenonly,
2614 &rate16x16, &rate16x16_tokenonly,
2615 &dist16x16); 2630 &dist16x16);
2616 2631
2617 error4x4 = rd_pick_intra4x4mby_modes(cpi, x, 2632 error4x4 = rd_pick_intra4x4mby_modes(x, &rate4x4, &rate4x4_tokenonly,
2618 &rate4x4, &rate4x4_tokenonly,
2619 &dist4x4, error16x16); 2633 &dist4x4, error16x16);
2620 2634
2621 if (error4x4 < error16x16) 2635 if (error4x4 < error16x16)
2622 { 2636 {
2623 x->e_mbd.mode_info_context->mbmi.mode = B_PRED; 2637 x->e_mbd.mode_info_context->mbmi.mode = B_PRED;
2624 rate += rate4x4; 2638 rate += rate4x4;
2625 } 2639 }
2626 else 2640 else
2627 { 2641 {
2628 rate += rate16x16; 2642 rate += rate16x16;
2629 } 2643 }
2630 2644
2631 *rate_ = rate; 2645 *rate_ = rate;
2632 } 2646 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/rdopt.h ('k') | source/libvpx/vp8/encoder/temporal_filter.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698