Merge "Using struct twopass_rc* instead of VP9_COMP*."

This commit is contained in:
Dmitry Kovalev
2014-01-08 14:14:05 -08:00
committed by Gerrit Code Review

View File

@@ -92,30 +92,31 @@ static int kfboost_qadjust(int qindex) {
// Resets the first pass file to the given position using a relative seek from // Resets the first pass file to the given position using a relative seek from
// the current position. // the current position.
static void reset_fpf_position(VP9_COMP *cpi, FIRSTPASS_STATS *position) { static void reset_fpf_position(struct twopass_rc *p,
cpi->twopass.stats_in = position; FIRSTPASS_STATS *position) {
p->stats_in = position;
} }
static int lookup_next_frame_stats(VP9_COMP *cpi, FIRSTPASS_STATS *next_frame) { static int lookup_next_frame_stats(const struct twopass_rc *p,
if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end) FIRSTPASS_STATS *next_frame) {
if (p->stats_in >= p->stats_in_end)
return EOF; return EOF;
*next_frame = *cpi->twopass.stats_in; *next_frame = *p->stats_in;
return 1; return 1;
} }
// Read frame stats at an offset from the current position // Read frame stats at an offset from the current position
static int read_frame_stats(VP9_COMP *cpi, static int read_frame_stats(const struct twopass_rc *p,
FIRSTPASS_STATS *frame_stats, FIRSTPASS_STATS *frame_stats, int offset) {
int offset) { const FIRSTPASS_STATS *fps_ptr = p->stats_in;
FIRSTPASS_STATS *fps_ptr = cpi->twopass.stats_in;
// Check legality of offset // Check legality of offset
if (offset >= 0) { if (offset >= 0) {
if (&fps_ptr[offset] >= cpi->twopass.stats_in_end) if (&fps_ptr[offset] >= p->stats_in_end)
return EOF; return EOF;
} else if (offset < 0) { } else if (offset < 0) {
if (&fps_ptr[offset] < cpi->twopass.stats_in_start) if (&fps_ptr[offset] < p->stats_in_start)
return EOF; return EOF;
} }
@@ -123,13 +124,12 @@ static int read_frame_stats(VP9_COMP *cpi,
return 1; return 1;
} }
static int input_stats(VP9_COMP *cpi, FIRSTPASS_STATS *fps) { static int input_stats(struct twopass_rc *p, FIRSTPASS_STATS *fps) {
if (cpi->twopass.stats_in >= cpi->twopass.stats_in_end) if (p->stats_in >= p->stats_in_end)
return EOF; return EOF;
*fps = *cpi->twopass.stats_in; *fps = *p->stats_in;
cpi->twopass.stats_in = ++p->stats_in;
(void *)((char *)cpi->twopass.stats_in + sizeof(FIRSTPASS_STATS));
return 1; return 1;
} }
@@ -1097,7 +1097,7 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
start_pos = cpi->twopass.stats_in; // Note the starting "file" position. start_pos = cpi->twopass.stats_in; // Note the starting "file" position.
while (input_stats(cpi, &this_frame) != EOF) { while (input_stats(&cpi->twopass, &this_frame) != EOF) {
IIRatio = this_frame.intra_error IIRatio = this_frame.intra_error
/ DOUBLE_DIVIDE_CHECK(this_frame.coded_error); / DOUBLE_DIVIDE_CHECK(this_frame.coded_error);
IIRatio = (IIRatio < 1.0) ? 1.0 : (IIRatio > 20.0) ? 20.0 : IIRatio; IIRatio = (IIRatio < 1.0) ? 1.0 : (IIRatio > 20.0) ? 20.0 : IIRatio;
@@ -1108,7 +1108,7 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats.count); DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats.count);
// Reset file position // Reset file position
reset_fpf_position(cpi, start_pos); reset_fpf_position(&cpi->twopass, start_pos);
} }
// Scan the first pass file and calculate a modified total error based upon // Scan the first pass file and calculate a modified total error based upon
@@ -1125,13 +1125,13 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
cpi->twopass.modified_error_max = cpi->twopass.modified_error_max =
(av_error * cpi->oxcf.two_pass_vbrmax_section) / 100; (av_error * cpi->oxcf.two_pass_vbrmax_section) / 100;
while (input_stats(cpi, &this_frame) != EOF) { while (input_stats(&cpi->twopass, &this_frame) != EOF) {
cpi->twopass.modified_error_total += cpi->twopass.modified_error_total +=
calculate_modified_err(cpi, &this_frame); calculate_modified_err(cpi, &this_frame);
} }
cpi->twopass.modified_error_left = cpi->twopass.modified_error_total; cpi->twopass.modified_error_left = cpi->twopass.modified_error_total;
reset_fpf_position(cpi, start_pos); // Reset file position reset_fpf_position(&cpi->twopass, start_pos); // Reset file position
} }
} }
@@ -1178,7 +1178,7 @@ static int detect_transition_to_still(
// Look ahead a few frames to see if static condition // Look ahead a few frames to see if static condition
// persists... // persists...
for (j = 0; j < still_interval; j++) { for (j = 0; j < still_interval; j++) {
if (EOF == input_stats(cpi, &tmp_next_frame)) if (EOF == input_stats(&cpi->twopass, &tmp_next_frame))
break; break;
zz_inter = zz_inter =
@@ -1187,7 +1187,7 @@ static int detect_transition_to_still(
break; break;
} }
// Reset file position // Reset file position
reset_fpf_position(cpi, position); reset_fpf_position(&cpi->twopass, position);
// Only if it does do we signal a transition to still // Only if it does do we signal a transition to still
if (j == still_interval) if (j == still_interval)
@@ -1207,7 +1207,7 @@ static int detect_flash(VP9_COMP *cpi, int offset) {
// Read the frame data. // Read the frame data.
// The return is FALSE (no flash detected) if not a valid frame // The return is FALSE (no flash detected) if not a valid frame
if (read_frame_stats(cpi, &next_frame, offset) != EOF) { if (read_frame_stats(&cpi->twopass, &next_frame, offset) != EOF) {
// What we are looking for here is a situation where there is a // What we are looking for here is a situation where there is a
// brief break in prediction (such as a flash) but subsequent frames // brief break in prediction (such as a flash) but subsequent frames
// are reasonably well predicted by an earlier (pre flash) frame. // are reasonably well predicted by an earlier (pre flash) frame.
@@ -1312,7 +1312,7 @@ static int calc_arf_boost(VP9_COMP *cpi, int offset,
// Search forward from the proposed arf/next gf position // Search forward from the proposed arf/next gf position
for (i = 0; i < f_frames; i++) { for (i = 0; i < f_frames; i++) {
if (read_frame_stats(cpi, &this_frame, (i + offset)) == EOF) if (read_frame_stats(&cpi->twopass, &this_frame, (i + offset)) == EOF)
break; break;
// Update the motion related elements to the boost calculation // Update the motion related elements to the boost calculation
@@ -1349,7 +1349,7 @@ static int calc_arf_boost(VP9_COMP *cpi, int offset,
// Search backward towards last gf position // Search backward towards last gf position
for (i = -1; i >= -b_frames; i--) { for (i = -1; i >= -b_frames; i--) {
if (read_frame_stats(cpi, &this_frame, (i + offset)) == EOF) if (read_frame_stats(&cpi->twopass, &this_frame, (i + offset)) == EOF)
break; break;
// Update the motion related elements to the boost calculation // Update the motion related elements to the boost calculation
@@ -1597,7 +1597,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
mod_frame_err = calculate_modified_err(cpi, this_frame); mod_frame_err = calculate_modified_err(cpi, this_frame);
gf_group_err += mod_frame_err; gf_group_err += mod_frame_err;
if (EOF == input_stats(cpi, &next_frame)) if (EOF == input_stats(&cpi->twopass, &next_frame))
break; break;
// Test for the case where there is a brief flash but the prediction // Test for the case where there is a brief flash but the prediction
@@ -1666,7 +1666,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
while (i < (cpi->rc.frames_to_key - 1)) { while (i < (cpi->rc.frames_to_key - 1)) {
i++; i++;
if (EOF == input_stats(cpi, this_frame)) if (EOF == input_stats(&cpi->twopass, this_frame))
break; break;
if (i < cpi->rc.frames_to_key) { if (i < cpi->rc.frames_to_key) {
@@ -1797,7 +1797,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
(int64_t)max_bits * cpi->rc.baseline_gf_interval; (int64_t)max_bits * cpi->rc.baseline_gf_interval;
// Reset the file position // Reset the file position
reset_fpf_position(cpi, start_pos); reset_fpf_position(&cpi->twopass, start_pos);
// Assign bits to the arf or gf. // Assign bits to the arf or gf.
for (i = 0; for (i = 0;
@@ -1922,10 +1922,10 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
FIRSTPASS_STATS sectionstats; FIRSTPASS_STATS sectionstats;
zero_stats(&sectionstats); zero_stats(&sectionstats);
reset_fpf_position(cpi, start_pos); reset_fpf_position(&cpi->twopass, start_pos);
for (i = 0; i < cpi->rc.baseline_gf_interval; i++) { for (i = 0; i < cpi->rc.baseline_gf_interval; i++) {
input_stats(cpi, &next_frame); input_stats(&cpi->twopass, &next_frame);
accumulate_stats(&sectionstats, &next_frame); accumulate_stats(&sectionstats, &next_frame);
} }
@@ -1935,7 +1935,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
(sectionstats.intra_error / (sectionstats.intra_error /
DOUBLE_DIVIDE_CHECK(sectionstats.coded_error)); DOUBLE_DIVIDE_CHECK(sectionstats.coded_error));
reset_fpf_position(cpi, start_pos); reset_fpf_position(&cpi->twopass, start_pos);
} }
} }
@@ -2079,7 +2079,7 @@ void vp9_get_second_pass_params(VP9_COMP *cpi) {
// adjust_maxq_qrange(cpi); // adjust_maxq_qrange(cpi);
} }
vp9_zero(this_frame); vp9_zero(this_frame);
if (EOF == input_stats(cpi, &this_frame)) if (EOF == input_stats(&cpi->twopass, &this_frame))
return; return;
this_frame_intra_error = this_frame.intra_error; this_frame_intra_error = this_frame.intra_error;
@@ -2147,7 +2147,7 @@ void vp9_get_second_pass_params(VP9_COMP *cpi) {
DOUBLE_DIVIDE_CHECK(this_frame_coded_error)); DOUBLE_DIVIDE_CHECK(this_frame_coded_error));
{ {
FIRSTPASS_STATS next_frame; FIRSTPASS_STATS next_frame;
if (lookup_next_frame_stats(cpi, &next_frame) != EOF) { if (lookup_next_frame_stats(&cpi->twopass, &next_frame) != EOF) {
cpi->twopass.next_iiratio = (int)(next_frame.intra_error / cpi->twopass.next_iiratio = (int)(next_frame.intra_error /
DOUBLE_DIVIDE_CHECK(next_frame.coded_error)); DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
} }
@@ -2235,7 +2235,7 @@ static int test_candidate_kf(VP9_COMP *cpi,
old_boost_score = boost_score; old_boost_score = boost_score;
// Get the next frame details // Get the next frame details
if (EOF == input_stats(cpi, &local_next_frame)) if (EOF == input_stats(&cpi->twopass, &local_next_frame))
break; break;
} }
@@ -2245,7 +2245,7 @@ static int test_candidate_kf(VP9_COMP *cpi,
is_viable_kf = 1; is_viable_kf = 1;
} else { } else {
// Reset the file position // Reset the file position
reset_fpf_position(cpi, start_pos); reset_fpf_position(&cpi->twopass, start_pos);
is_viable_kf = 0; is_viable_kf = 0;
} }
@@ -2312,11 +2312,11 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// load a the next frame's stats // load a the next frame's stats
last_frame = *this_frame; last_frame = *this_frame;
input_stats(cpi, this_frame); input_stats(&cpi->twopass, this_frame);
// Provided that we are not at the end of the file... // Provided that we are not at the end of the file...
if (cpi->oxcf.auto_key if (cpi->oxcf.auto_key &&
&& lookup_next_frame_stats(cpi, &next_frame) != EOF) { lookup_next_frame_stats(&cpi->twopass, &next_frame) != EOF) {
// Normal scene cut check // Normal scene cut check
if (test_candidate_kf(cpi, &last_frame, this_frame, &next_frame)) if (test_candidate_kf(cpi, &last_frame, this_frame, &next_frame))
break; break;
@@ -2367,7 +2367,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
tmp_frame = first_frame; tmp_frame = first_frame;
// Reset to the start of the group // Reset to the start of the group
reset_fpf_position(cpi, start_position); reset_fpf_position(&cpi->twopass, start_position);
kf_group_err = 0; kf_group_err = 0;
kf_group_intra_err = 0; kf_group_intra_err = 0;
@@ -2381,11 +2381,11 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
kf_group_coded_err += tmp_frame.coded_error; kf_group_coded_err += tmp_frame.coded_error;
// Load a the next frame's stats // Load a the next frame's stats
input_stats(cpi, &tmp_frame); input_stats(&cpi->twopass, &tmp_frame);
} }
// Reset to the start of the group // Reset to the start of the group
reset_fpf_position(cpi, current_pos); reset_fpf_position(&cpi->twopass, current_pos);
cpi->rc.next_key_frame_forced = 1; cpi->rc.next_key_frame_forced = 1;
} else { } else {
@@ -2426,7 +2426,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
cpi->twopass.kf_group_bits = 0; cpi->twopass.kf_group_bits = 0;
} }
// Reset the first pass file position // Reset the first pass file position
reset_fpf_position(cpi, start_position); reset_fpf_position(&cpi->twopass, start_position);
// Determine how big to make this keyframe based on how well the subsequent // Determine how big to make this keyframe based on how well the subsequent
// frames use inter blocks. // frames use inter blocks.
@@ -2438,7 +2438,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
for (i = 0; i < cpi->rc.frames_to_key; i++) { for (i = 0; i < cpi->rc.frames_to_key; i++) {
double r; double r;
if (EOF == input_stats(cpi, &next_frame)) if (EOF == input_stats(&cpi->twopass, &next_frame))
break; break;
// Monitor for static sections. // Monitor for static sections.
@@ -2476,10 +2476,10 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
FIRSTPASS_STATS sectionstats; FIRSTPASS_STATS sectionstats;
zero_stats(&sectionstats); zero_stats(&sectionstats);
reset_fpf_position(cpi, start_position); reset_fpf_position(&cpi->twopass, start_position);
for (i = 0; i < cpi->rc.frames_to_key; i++) { for (i = 0; i < cpi->rc.frames_to_key; i++) {
input_stats(cpi, &next_frame); input_stats(&cpi->twopass, &next_frame);
accumulate_stats(&sectionstats, &next_frame); accumulate_stats(&sectionstats, &next_frame);
} }
@@ -2491,7 +2491,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
} }
// Reset the first pass file position // Reset the first pass file position
reset_fpf_position(cpi, start_position); reset_fpf_position(&cpi->twopass, start_position);
// Work out how many bits to allocate for the key frame itself // Work out how many bits to allocate for the key frame itself
if (1) { if (1) {