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

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

Issue 394353005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 5 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/vp9/encoder/vp9_firstpass.h ('k') | source/libvpx/vp9/encoder/vp9_pickmode.h » ('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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // Read frame stats at an offset from the current position. 91 // Read frame stats at an offset from the current position.
92 static const FIRSTPASS_STATS *read_frame_stats(const TWO_PASS *p, int offset) { 92 static const FIRSTPASS_STATS *read_frame_stats(const TWO_PASS *p, int offset) {
93 if ((offset >= 0 && p->stats_in + offset >= p->stats_in_end) || 93 if ((offset >= 0 && p->stats_in + offset >= p->stats_in_end) ||
94 (offset < 0 && p->stats_in + offset < p->stats_in_start)) { 94 (offset < 0 && p->stats_in + offset < p->stats_in_start)) {
95 return NULL; 95 return NULL;
96 } 96 }
97 97
98 return &p->stats_in[offset]; 98 return &p->stats_in[offset];
99 } 99 }
100 100
101 #if CONFIG_FP_MB_STATS
102 static int input_mb_stats(FIRSTPASS_FRAME_MB_STATS *fp_frame_stats,
103 const VP9_COMMON *const cm) {
104 FILE *fpfile;
105 int ret;
106
107 fpfile = fopen("firstpass_mb.stt", "r");
108 fseek(fpfile, cm->current_video_frame * cm->MBs * sizeof(FIRSTPASS_MB_STATS),
109 SEEK_SET);
110 ret = fread(fp_frame_stats->mb_stats, sizeof(FIRSTPASS_MB_STATS), cm->MBs,
111 fpfile);
112 fclose(fpfile);
113 if (ret < cm->MBs) {
114 return EOF;
115 }
116 return 1;
117 }
118
119 static void output_mb_stats(FIRSTPASS_FRAME_MB_STATS *fp_frame_stats,
120 const VP9_COMMON *const cm) {
121 FILE *fpfile;
122
123 fpfile = fopen("firstpass_mb.stt", "a");
124 fwrite(fp_frame_stats->mb_stats, sizeof(FIRSTPASS_MB_STATS), cm->MBs, fpfile);
125 fclose(fpfile);
126 }
127 #endif
128
129 static int input_stats(TWO_PASS *p, FIRSTPASS_STATS *fps) { 101 static int input_stats(TWO_PASS *p, FIRSTPASS_STATS *fps) {
130 if (p->stats_in >= p->stats_in_end) 102 if (p->stats_in >= p->stats_in_end)
131 return EOF; 103 return EOF;
132 104
133 *fps = *p->stats_in; 105 *fps = *p->stats_in;
134 ++p->stats_in; 106 ++p->stats_in;
135 return 1; 107 return 1;
136 } 108 }
137 109
138 static void output_stats(FIRSTPASS_STATS *stats, 110 static void output_stats(FIRSTPASS_STATS *stats,
(...skipping 29 matching lines...) Expand all
168 stats->MVcv, 140 stats->MVcv,
169 stats->mv_in_out_count, 141 stats->mv_in_out_count,
170 stats->new_mv_count, 142 stats->new_mv_count,
171 stats->count, 143 stats->count,
172 stats->duration); 144 stats->duration);
173 fclose(fpfile); 145 fclose(fpfile);
174 } 146 }
175 #endif 147 #endif
176 } 148 }
177 149
150 #if CONFIG_FP_MB_STATS
151 static void output_fpmb_stats(uint8_t *this_frame_mb_stats, VP9_COMMON *cm,
152 struct vpx_codec_pkt_list *pktlist) {
153 struct vpx_codec_cx_pkt pkt;
154 pkt.kind = VPX_CODEC_FPMB_STATS_PKT;
155 pkt.data.firstpass_mb_stats.buf = this_frame_mb_stats;
156 pkt.data.firstpass_mb_stats.sz = cm->MBs * sizeof(uint8_t);
157 vpx_codec_pkt_list_add(pktlist, &pkt);
158 }
159 #endif
160
178 static void zero_stats(FIRSTPASS_STATS *section) { 161 static void zero_stats(FIRSTPASS_STATS *section) {
179 section->frame = 0.0; 162 section->frame = 0.0;
180 section->intra_error = 0.0; 163 section->intra_error = 0.0;
181 section->coded_error = 0.0; 164 section->coded_error = 0.0;
182 section->sr_coded_error = 0.0; 165 section->sr_coded_error = 0.0;
183 section->pcnt_inter = 0.0; 166 section->pcnt_inter = 0.0;
184 section->pcnt_motion = 0.0; 167 section->pcnt_motion = 0.0;
185 section->pcnt_second_ref = 0.0; 168 section->pcnt_second_ref = 0.0;
186 section->pcnt_neutral = 0.0; 169 section->pcnt_neutral = 0.0;
187 section->MVr = 0.0; 170 section->MVr = 0.0;
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 int intrapenalty = 256; 449 int intrapenalty = 256;
467 int neutral_count = 0; 450 int neutral_count = 0;
468 int new_mv_count = 0; 451 int new_mv_count = 0;
469 int sum_in_vectors = 0; 452 int sum_in_vectors = 0;
470 uint32_t lastmv_as_int = 0; 453 uint32_t lastmv_as_int = 0;
471 TWO_PASS *twopass = &cpi->twopass; 454 TWO_PASS *twopass = &cpi->twopass;
472 const MV zero_mv = {0, 0}; 455 const MV zero_mv = {0, 0};
473 const YV12_BUFFER_CONFIG *first_ref_buf = lst_yv12; 456 const YV12_BUFFER_CONFIG *first_ref_buf = lst_yv12;
474 457
475 #if CONFIG_FP_MB_STATS 458 #if CONFIG_FP_MB_STATS
476 FIRSTPASS_FRAME_MB_STATS *this_frame_mb_stats = &twopass->this_frame_mb_stats; 459 if (cpi->use_fp_mb_stats) {
460 vp9_zero_array(cpi->twopass.frame_mb_stats_buf, cm->MBs);
461 }
477 #endif 462 #endif
478 463
479 vp9_clear_system_state(); 464 vp9_clear_system_state();
480 465
481 set_first_pass_params(cpi); 466 set_first_pass_params(cpi);
482 vp9_set_quantizer(cm, find_fp_qindex()); 467 vp9_set_quantizer(cm, find_fp_qindex());
483 468
484 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) { 469 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
485 MV_REFERENCE_FRAME ref_frame = LAST_FRAME; 470 MV_REFERENCE_FRAME ref_frame = LAST_FRAME;
486 const YV12_BUFFER_CONFIG *scaled_ref_buf = NULL; 471 const YV12_BUFFER_CONFIG *scaled_ref_buf = NULL;
487 twopass = &cpi->svc.layer_context[cpi->svc.spatial_layer_id].twopass; 472 twopass = &cpi->svc.layer_context[cpi->svc.spatial_layer_id].twopass;
488 473
474 if (cpi->common.current_video_frame == 0) {
475 cpi->ref_frame_flags = 0;
476 } else {
477 LAYER_CONTEXT *lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
478 if (lc->current_video_frame_in_layer == 0)
479 cpi->ref_frame_flags = VP9_GOLD_FLAG;
480 else
481 cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
482 }
483
489 vp9_scale_references(cpi); 484 vp9_scale_references(cpi);
490 485
491 // Use either last frame or alt frame for motion search. 486 // Use either last frame or alt frame for motion search.
492 if (cpi->ref_frame_flags & VP9_LAST_FLAG) { 487 if (cpi->ref_frame_flags & VP9_LAST_FLAG) {
493 scaled_ref_buf = vp9_get_scaled_ref_frame(cpi, LAST_FRAME); 488 scaled_ref_buf = vp9_get_scaled_ref_frame(cpi, LAST_FRAME);
494 ref_frame = LAST_FRAME; 489 ref_frame = LAST_FRAME;
495 } else if (cpi->ref_frame_flags & VP9_ALT_FLAG) { 490 } else if (cpi->ref_frame_flags & VP9_GOLD_FLAG) {
496 scaled_ref_buf = vp9_get_scaled_ref_frame(cpi, ALTREF_FRAME); 491 scaled_ref_buf = vp9_get_scaled_ref_frame(cpi, GOLDEN_FRAME);
497 ref_frame = ALTREF_FRAME; 492 ref_frame = GOLDEN_FRAME;
498 } 493 }
499 494
500 if (scaled_ref_buf != NULL) { 495 if (scaled_ref_buf != NULL)
501 // Update the stride since we are using scaled reference buffer
502 first_ref_buf = scaled_ref_buf; 496 first_ref_buf = scaled_ref_buf;
503 recon_y_stride = first_ref_buf->y_stride; 497
504 recon_uv_stride = first_ref_buf->uv_stride; 498 recon_y_stride = new_yv12->y_stride;
505 uv_mb_height = 16 >> (first_ref_buf->y_height > first_ref_buf->uv_height); 499 recon_uv_stride = new_yv12->uv_stride;
506 } 500 uv_mb_height = 16 >> (new_yv12->y_height > new_yv12->uv_height);
507 501
508 // Disable golden frame for svc first pass for now. 502 // Disable golden frame for svc first pass for now.
509 gld_yv12 = NULL; 503 gld_yv12 = NULL;
510 set_ref_ptrs(cm, xd, ref_frame, NONE); 504 set_ref_ptrs(cm, xd, ref_frame, NONE);
511 505
512 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, 506 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source,
513 &cpi->scaled_source); 507 &cpi->scaled_source);
514 } 508 }
515 509
516 vp9_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); 510 vp9_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 // When the error score is very low this causes us to pick all or lots of 592 // When the error score is very low this causes us to pick all or lots of
599 // INTRA modes and throw lots of key frames. 593 // INTRA modes and throw lots of key frames.
600 // This penalty adds a cost matching that of a 0,0 mv to the intra case. 594 // This penalty adds a cost matching that of a 0,0 mv to the intra case.
601 this_error += intrapenalty; 595 this_error += intrapenalty;
602 596
603 // Accumulate the intra error. 597 // Accumulate the intra error.
604 intra_error += (int64_t)this_error; 598 intra_error += (int64_t)this_error;
605 599
606 #if CONFIG_FP_MB_STATS 600 #if CONFIG_FP_MB_STATS
607 if (cpi->use_fp_mb_stats) { 601 if (cpi->use_fp_mb_stats) {
608 this_frame_mb_stats->mb_stats[mb_row * cm->mb_cols + mb_col].mode = 602 // TODO(pengchong): store some related block statistics here
609 DC_PRED;
610 this_frame_mb_stats->mb_stats[mb_row * cm->mb_cols + mb_col].err =
611 this_error;
612 this_frame_mb_stats->mb_stats[mb_row * cm->mb_cols + mb_col].mv.as_int
613 = 0;
614 } 603 }
615 #endif 604 #endif
616 605
617 // Set up limit values for motion vectors to prevent them extending 606 // Set up limit values for motion vectors to prevent them extending
618 // outside the UMV borders. 607 // outside the UMV borders.
619 x->mv_col_min = -((mb_col * 16) + BORDER_MV_PIXELS_B16); 608 x->mv_col_min = -((mb_col * 16) + BORDER_MV_PIXELS_B16);
620 x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + BORDER_MV_PIXELS_B16; 609 x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + BORDER_MV_PIXELS_B16;
621 610
622 // Other than for the first frame do a motion search. 611 // Other than for the first frame do a motion search.
623 if (cm->current_video_frame > 0) { 612 if (cm->current_video_frame > 0) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 sum_mvc += mv.as_mv.col; 723 sum_mvc += mv.as_mv.col;
735 sum_mvc_abs += abs(mv.as_mv.col); 724 sum_mvc_abs += abs(mv.as_mv.col);
736 sum_mvrs += mv.as_mv.row * mv.as_mv.row; 725 sum_mvrs += mv.as_mv.row * mv.as_mv.row;
737 sum_mvcs += mv.as_mv.col * mv.as_mv.col; 726 sum_mvcs += mv.as_mv.col * mv.as_mv.col;
738 ++intercount; 727 ++intercount;
739 728
740 best_ref_mv.as_int = mv.as_int; 729 best_ref_mv.as_int = mv.as_int;
741 730
742 #if CONFIG_FP_MB_STATS 731 #if CONFIG_FP_MB_STATS
743 if (cpi->use_fp_mb_stats) { 732 if (cpi->use_fp_mb_stats) {
744 this_frame_mb_stats->mb_stats[mb_row * cm->mb_cols + mb_col].mode = 733 // TODO(pengchong): save some related block statistics here
745 NEWMV;
746 this_frame_mb_stats->mb_stats[mb_row * cm->mb_cols + mb_col].err =
747 motion_error;
748 this_frame_mb_stats->mb_stats[mb_row * cm->mb_cols + mb_col].mv.
749 as_int = mv.as_int;
750 } 734 }
751 #endif 735 #endif
752 736
753 if (mv.as_int) { 737 if (mv.as_int) {
754 ++mvcount; 738 ++mvcount;
755 739
756 // Non-zero vector, was it different from the last non zero vector? 740 // Non-zero vector, was it different from the last non zero vector?
757 if (mv.as_int != lastmv_as_int) 741 if (mv.as_int != lastmv_as_int)
758 ++new_mv_count; 742 ++new_mv_count;
759 lastmv_as_int = mv.as_int; 743 lastmv_as_int = mv.as_int;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // cpi->source_time_stamp. 834 // cpi->source_time_stamp.
851 fps.duration = (double)(cpi->source->ts_end - cpi->source->ts_start); 835 fps.duration = (double)(cpi->source->ts_end - cpi->source->ts_start);
852 836
853 // Don't want to do output stats with a stack variable! 837 // Don't want to do output stats with a stack variable!
854 twopass->this_frame_stats = fps; 838 twopass->this_frame_stats = fps;
855 output_stats(&twopass->this_frame_stats, cpi->output_pkt_list); 839 output_stats(&twopass->this_frame_stats, cpi->output_pkt_list);
856 accumulate_stats(&twopass->total_stats, &fps); 840 accumulate_stats(&twopass->total_stats, &fps);
857 841
858 #if CONFIG_FP_MB_STATS 842 #if CONFIG_FP_MB_STATS
859 if (cpi->use_fp_mb_stats) { 843 if (cpi->use_fp_mb_stats) {
860 output_mb_stats(this_frame_mb_stats, cm); 844 output_fpmb_stats(twopass->frame_mb_stats_buf, cm, cpi->output_pkt_list);
861 } 845 }
862 #endif 846 #endif
863 } 847 }
864 848
865 // Copy the previous Last Frame back into gf and and arf buffers if 849 // Copy the previous Last Frame back into gf and and arf buffers if
866 // the prediction is good enough... but also don't allow it to lag too far. 850 // the prediction is good enough... but also don't allow it to lag too far.
867 if ((twopass->sr_update_lag > 3) || 851 if ((twopass->sr_update_lag > 3) ||
868 ((cm->current_video_frame > 0) && 852 ((cm->current_video_frame > 0) &&
869 (twopass->this_frame_stats.pcnt_inter > 0.20) && 853 (twopass->this_frame_stats.pcnt_inter > 0.20) &&
870 ((twopass->this_frame_stats.intra_error / 854 ((twopass->this_frame_stats.intra_error /
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 if (cm->current_video_frame == 0) 886 if (cm->current_video_frame == 0)
903 recon_file = fopen(filename, "wb"); 887 recon_file = fopen(filename, "wb");
904 else 888 else
905 recon_file = fopen(filename, "ab"); 889 recon_file = fopen(filename, "ab");
906 890
907 (void)fwrite(lst_yv12->buffer_alloc, lst_yv12->frame_size, 1, recon_file); 891 (void)fwrite(lst_yv12->buffer_alloc, lst_yv12->frame_size, 1, recon_file);
908 fclose(recon_file); 892 fclose(recon_file);
909 } 893 }
910 894
911 ++cm->current_video_frame; 895 ++cm->current_video_frame;
896 if (cpi->use_svc)
897 vp9_inc_frame_in_layer(&cpi->svc);
912 } 898 }
913 899
914 static double calc_correction_factor(double err_per_mb, 900 static double calc_correction_factor(double err_per_mb,
915 double err_divisor, 901 double err_divisor,
916 double pt_low, 902 double pt_low,
917 double pt_high, 903 double pt_high,
918 int q) { 904 int q) {
919 const double error_term = err_per_mb / err_divisor; 905 const double error_term = err_per_mb / err_divisor;
920 906
921 // Adjustment based on actual quantizer to power term. 907 // Adjustment based on actual quantizer to power term.
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 double decay_accumulator = 1.0; 1485 double decay_accumulator = 1.0;
1500 double zero_motion_accumulator = 1.0; 1486 double zero_motion_accumulator = 1.0;
1501 1487
1502 double loop_decay_rate = 1.00; 1488 double loop_decay_rate = 1.00;
1503 double last_loop_decay_rate = 1.00; 1489 double last_loop_decay_rate = 1.00;
1504 1490
1505 double this_frame_mv_in_out = 0.0; 1491 double this_frame_mv_in_out = 0.0;
1506 double mv_in_out_accumulator = 0.0; 1492 double mv_in_out_accumulator = 0.0;
1507 double abs_mv_in_out_accumulator = 0.0; 1493 double abs_mv_in_out_accumulator = 0.0;
1508 double mv_ratio_accumulator_thresh; 1494 double mv_ratio_accumulator_thresh;
1509 unsigned int allow_alt_ref = is_altref_enabled(oxcf); 1495 unsigned int allow_alt_ref = is_altref_enabled(cpi);
1510 1496
1511 int f_boost = 0; 1497 int f_boost = 0;
1512 int b_boost = 0; 1498 int b_boost = 0;
1513 int flash_detected; 1499 int flash_detected;
1514 int active_max_gf_interval; 1500 int active_max_gf_interval;
1515 int64_t gf_group_bits; 1501 int64_t gf_group_bits;
1516 double gf_group_error_left; 1502 double gf_group_error_left;
1517 int gf_arf_bits; 1503 int gf_arf_bits;
1518 1504
1519 // Reset the GF group data structures unless this is a key 1505 // Reset the GF group data structures unless this is a key
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 cpi->rc.is_src_frame_alt_ref = 1; 2059 cpi->rc.is_src_frame_alt_ref = 1;
2074 break; 2060 break;
2075 case ARF_UPDATE: 2061 case ARF_UPDATE:
2076 cpi->refresh_last_frame = 0; 2062 cpi->refresh_last_frame = 0;
2077 cpi->refresh_golden_frame = 0; 2063 cpi->refresh_golden_frame = 0;
2078 cpi->refresh_alt_ref_frame = 1; 2064 cpi->refresh_alt_ref_frame = 1;
2079 break; 2065 break;
2080 default: 2066 default:
2081 assert(0); 2067 assert(0);
2082 } 2068 }
2069 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) {
2070 cpi->refresh_golden_frame = 0;
2071 if (cpi->alt_ref_source == NULL)
2072 cpi->refresh_alt_ref_frame = 0;
2073 }
2083 } 2074 }
2084 2075
2085 2076
2086 void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { 2077 void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
2087 VP9_COMMON *const cm = &cpi->common; 2078 VP9_COMMON *const cm = &cpi->common;
2088 RATE_CONTROL *const rc = &cpi->rc; 2079 RATE_CONTROL *const rc = &cpi->rc;
2089 TWO_PASS *const twopass = &cpi->twopass; 2080 TWO_PASS *const twopass = &cpi->twopass;
2090 int frames_left; 2081 int frames_left;
2091 FIRSTPASS_STATS this_frame; 2082 FIRSTPASS_STATS this_frame;
2092 FIRSTPASS_STATS this_frame_copy; 2083 FIRSTPASS_STATS this_frame_copy;
(...skipping 22 matching lines...) Expand all
2115 target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index]; 2106 target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index];
2116 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate); 2107 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate);
2117 rc->base_frame_target = target_rate; 2108 rc->base_frame_target = target_rate;
2118 #ifdef LONG_TERM_VBR_CORRECTION 2109 #ifdef LONG_TERM_VBR_CORRECTION
2119 // Correction to rate target based on prior over or under shoot. 2110 // Correction to rate target based on prior over or under shoot.
2120 if (cpi->oxcf.rc_mode == VPX_VBR) 2111 if (cpi->oxcf.rc_mode == VPX_VBR)
2121 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target); 2112 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target);
2122 #endif 2113 #endif
2123 vp9_rc_set_frame_target(cpi, target_rate); 2114 vp9_rc_set_frame_target(cpi, target_rate);
2124 cm->frame_type = INTER_FRAME; 2115 cm->frame_type = INTER_FRAME;
2116
2117 if (is_spatial_svc) {
2118 if (cpi->svc.spatial_layer_id == 0) {
2119 lc->is_key_frame = 0;
2120 } else {
2121 lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame;
2122
2123 if (lc->is_key_frame)
2124 cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
2125 }
2126 }
2127
2125 return; 2128 return;
2126 } 2129 }
2127 2130
2128 vp9_clear_system_state(); 2131 vp9_clear_system_state();
2129 2132
2130 if (is_spatial_svc && twopass->kf_intra_err_min == 0) { 2133 if (is_spatial_svc && twopass->kf_intra_err_min == 0) {
2131 twopass->kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs; 2134 twopass->kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs;
2132 twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs; 2135 twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs;
2133 } 2136 }
2134 2137
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 // As long as max_thresh for encode breakout is small enough, it is ok 2185 // As long as max_thresh for encode breakout is small enough, it is ok
2183 // to enable it for show frame, i.e. set allow_encode_breakout to 2186 // to enable it for show frame, i.e. set allow_encode_breakout to
2184 // ENCODE_BREAKOUT_LIMITED. 2187 // ENCODE_BREAKOUT_LIMITED.
2185 if (!cm->show_frame) 2188 if (!cm->show_frame)
2186 cpi->allow_encode_breakout = ENCODE_BREAKOUT_DISABLED; 2189 cpi->allow_encode_breakout = ENCODE_BREAKOUT_DISABLED;
2187 else 2190 else
2188 cpi->allow_encode_breakout = ENCODE_BREAKOUT_LIMITED; 2191 cpi->allow_encode_breakout = ENCODE_BREAKOUT_LIMITED;
2189 } 2192 }
2190 2193
2191 rc->frames_till_gf_update_due = rc->baseline_gf_interval; 2194 rc->frames_till_gf_update_due = rc->baseline_gf_interval;
2192 cpi->refresh_golden_frame = 1; 2195 if (!is_spatial_svc)
2193 } 2196 cpi->refresh_golden_frame = 1;
2194
2195 {
2196 FIRSTPASS_STATS next_frame;
2197 if (lookup_next_frame_stats(twopass, &next_frame) != EOF) {
2198 twopass->next_iiratio = (int)(next_frame.intra_error /
2199 DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
2200 }
2201 } 2197 }
2202 2198
2203 configure_buffer_updates(cpi); 2199 configure_buffer_updates(cpi);
2204 2200
2205 target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index]; 2201 target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index];
2206 if (cpi->common.frame_type == KEY_FRAME) 2202 if (cpi->common.frame_type == KEY_FRAME)
2207 target_rate = vp9_rc_clamp_iframe_target_size(cpi, target_rate); 2203 target_rate = vp9_rc_clamp_iframe_target_size(cpi, target_rate);
2208 else 2204 else
2209 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate); 2205 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate);
2210 2206
2211 rc->base_frame_target = target_rate; 2207 rc->base_frame_target = target_rate;
2212 #ifdef LONG_TERM_VBR_CORRECTION 2208 #ifdef LONG_TERM_VBR_CORRECTION
2213 // Correction to rate target based on prior over or under shoot. 2209 // Correction to rate target based on prior over or under shoot.
2214 if (cpi->oxcf.rc_mode == VPX_VBR) 2210 if (cpi->oxcf.rc_mode == VPX_VBR)
2215 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target); 2211 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target);
2216 #endif 2212 #endif
2217 vp9_rc_set_frame_target(cpi, target_rate); 2213 vp9_rc_set_frame_target(cpi, target_rate);
2218 2214
2219 // Update the total stats remaining structure. 2215 // Update the total stats remaining structure.
2220 subtract_stats(&twopass->total_left_stats, &this_frame); 2216 subtract_stats(&twopass->total_left_stats, &this_frame);
2221
2222 #if CONFIG_FP_MB_STATS
2223 if (cpi->use_fp_mb_stats) {
2224 input_mb_stats(&twopass->this_frame_mb_stats, cm);
2225 }
2226 #endif
2227 } 2217 }
2228 2218
2229 void vp9_twopass_postencode_update(VP9_COMP *cpi) { 2219 void vp9_twopass_postencode_update(VP9_COMP *cpi) {
2230 TWO_PASS *const twopass = &cpi->twopass; 2220 TWO_PASS *const twopass = &cpi->twopass;
2231 RATE_CONTROL *const rc = &cpi->rc; 2221 RATE_CONTROL *const rc = &cpi->rc;
2232 #ifdef LONG_TERM_VBR_CORRECTION 2222 #ifdef LONG_TERM_VBR_CORRECTION
2233 // In this experimental mode, the VBR correction is done exclusively through 2223 // In this experimental mode, the VBR correction is done exclusively through
2234 // rc->vbr_bits_off_target. Based on the sign of this value, a limited % 2224 // rc->vbr_bits_off_target. Based on the sign of this value, a limited %
2235 // adjustment is made to the target rate of subsequent frames, to try and 2225 // adjustment is made to the target rate of subsequent frames, to try and
2236 // push it back towards 0. This mode is less likely to suffer from 2226 // push it back towards 0. This mode is less likely to suffer from
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 twopass->kf_group_bits += rc->this_frame_target - bits_used; 2258 twopass->kf_group_bits += rc->this_frame_target - bits_used;
2269 } else { 2259 } else {
2270 #endif 2260 #endif
2271 twopass->kf_group_bits -= bits_used; 2261 twopass->kf_group_bits -= bits_used;
2272 } 2262 }
2273 twopass->kf_group_bits = MAX(twopass->kf_group_bits, 0); 2263 twopass->kf_group_bits = MAX(twopass->kf_group_bits, 0);
2274 2264
2275 // Increment the gf group index ready for the next frame. 2265 // Increment the gf group index ready for the next frame.
2276 ++twopass->gf_group.index; 2266 ++twopass->gf_group.index;
2277 } 2267 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_firstpass.h ('k') | source/libvpx/vp9/encoder/vp9_pickmode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698