Remove heap alloc of FIRSTPASS_STATS

There is only one instance of these structures, no need for them
to be allocated separately on the heap.

Change-Id: I1333cc92d06bbe21be643c2b2f0e3936f0264cac
This commit is contained in:
John Koleszar 2013-05-06 14:07:18 -07:00
Родитель 8dd8287e16
Коммит 6462eebbdd
4 изменённых файлов: 36 добавлений и 61 удалений

Просмотреть файл

@ -247,8 +247,8 @@ static void avg_stats(FIRSTPASS_STATS *section) {
// Calculate a modified Error used in distributing bits between easier and harder frames
static double calculate_modified_err(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
double av_err = (cpi->twopass.total_stats->ssim_weighted_pred_err /
cpi->twopass.total_stats->count);
double av_err = (cpi->twopass.total_stats.ssim_weighted_pred_err /
cpi->twopass.total_stats.count);
double this_err = this_frame->ssim_weighted_pred_err;
double modified_err;
@ -328,7 +328,7 @@ static int frame_max_bits(VP9_COMP *cpi) {
// For VBR base this on the bits and frames left plus the
// two_pass_vbrmax_section rate passed in by the user.
max_bits = (int) (((double) cpi->twopass.bits_left
/ (cpi->twopass.total_stats->count - (double) cpi->common
/ (cpi->twopass.total_stats.count - (double) cpi->common
.current_video_frame))
* ((double) cpi->oxcf.two_pass_vbrmax_section / 100.0));
@ -340,11 +340,11 @@ static int frame_max_bits(VP9_COMP *cpi) {
}
void vp9_init_first_pass(VP9_COMP *cpi) {
zero_stats(cpi->twopass.total_stats);
zero_stats(&cpi->twopass.total_stats);
}
void vp9_end_first_pass(VP9_COMP *cpi) {
output_stats(cpi, cpi->output_pkt_list, cpi->twopass.total_stats);
output_stats(cpi, cpi->output_pkt_list, &cpi->twopass.total_stats);
}
static void zz_motion_search(VP9_COMP *cpi, MACROBLOCK *x, YV12_BUFFER_CONFIG *recon_buffer, int *best_motion_err, int recon_yoffset) {
@ -754,20 +754,20 @@ void vp9_first_pass(VP9_COMP *cpi) {
- cpi->source->ts_start);
// don't want to do output stats with a stack variable!
memcpy(cpi->twopass.this_frame_stats,
memcpy(&cpi->twopass.this_frame_stats,
&fps,
sizeof(FIRSTPASS_STATS));
output_stats(cpi, cpi->output_pkt_list, cpi->twopass.this_frame_stats);
accumulate_stats(cpi->twopass.total_stats, &fps);
output_stats(cpi, cpi->output_pkt_list, &cpi->twopass.this_frame_stats);
accumulate_stats(&cpi->twopass.total_stats, &fps);
}
// Copy the previous Last Frame back into gf and and arf buffers if
// the prediction is good enough... but also dont allow it to lag too far
if ((cpi->twopass.sr_update_lag > 3) ||
((cm->current_video_frame > 0) &&
(cpi->twopass.this_frame_stats->pcnt_inter > 0.20) &&
((cpi->twopass.this_frame_stats->intra_error /
DOUBLE_DIVIDE_CHECK(cpi->twopass.this_frame_stats->coded_error)) >
(cpi->twopass.this_frame_stats.pcnt_inter > 0.20) &&
((cpi->twopass.this_frame_stats.intra_error /
DOUBLE_DIVIDE_CHECK(cpi->twopass.this_frame_stats.coded_error)) >
2.0))) {
vp8_yv12_copy_frame(lst_yv12, gld_yv12);
cpi->twopass.sr_update_lag = 1;
@ -998,7 +998,7 @@ static int estimate_max_q(VP9_COMP *cpi,
// Give average a chance to settle though.
// PGW TODO.. This code is broken for the extended Q range
if ((cpi->ni_frames >
((int)cpi->twopass.total_stats->count >> 8)) &&
((int)cpi->twopass.total_stats.count >> 8)) &&
(cpi->ni_frames > 25)) {
adjust_maxq_qrange(cpi);
}
@ -1055,8 +1055,8 @@ static int estimate_cq(VP9_COMP *cpi,
}
// II ratio correction factor for clip as a whole
clip_iiratio = cpi->twopass.total_stats->intra_error /
DOUBLE_DIVIDE_CHECK(cpi->twopass.total_stats->coded_error);
clip_iiratio = cpi->twopass.total_stats.intra_error /
DOUBLE_DIVIDE_CHECK(cpi->twopass.total_stats.coded_error);
clip_iifactor = 1.0 - ((clip_iiratio - 10.0) * 0.025);
if (clip_iifactor < 0.80)
clip_iifactor = 0.80;
@ -1101,14 +1101,14 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
if (two_pass_min_rate < lower_bounds_min_rate)
two_pass_min_rate = lower_bounds_min_rate;
zero_stats(cpi->twopass.total_stats);
zero_stats(cpi->twopass.total_left_stats);
zero_stats(&cpi->twopass.total_stats);
zero_stats(&cpi->twopass.total_left_stats);
if (!cpi->twopass.stats_in_end)
return;
*cpi->twopass.total_stats = *cpi->twopass.stats_in_end;
*cpi->twopass.total_left_stats = *cpi->twopass.total_stats;
cpi->twopass.total_stats = *cpi->twopass.stats_in_end;
cpi->twopass.total_left_stats = cpi->twopass.total_stats;
// each frame can have a different duration, as the frame rate in the source
// isn't guaranteed to be constant. The frame rate prior to the first frame
@ -1116,13 +1116,13 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
// Its calculated based on the actual durations of all frames from the first
// pass.
vp9_new_frame_rate(cpi,
10000000.0 * cpi->twopass.total_stats->count /
cpi->twopass.total_stats->duration);
10000000.0 * cpi->twopass.total_stats.count /
cpi->twopass.total_stats.duration);
cpi->output_frame_rate = cpi->oxcf.frame_rate;
cpi->twopass.bits_left = (int64_t)(cpi->twopass.total_stats->duration *
cpi->twopass.bits_left = (int64_t)(cpi->twopass.total_stats.duration *
cpi->oxcf.target_bandwidth / 10000000.0);
cpi->twopass.bits_left -= (int64_t)(cpi->twopass.total_stats->duration *
cpi->twopass.bits_left -= (int64_t)(cpi->twopass.total_stats.duration *
two_pass_min_rate / 10000000.0);
// Calculate a minimum intra value to be used in determining the IIratio
@ -1148,7 +1148,8 @@ void vp9_init_second_pass(VP9_COMP *cpi) {
sum_iiratio += IIRatio;
}
cpi->twopass.avg_iiratio = sum_iiratio / DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats->count);
cpi->twopass.avg_iiratio = sum_iiratio /
DOUBLE_DIVIDE_CHECK((double)cpi->twopass.total_stats.count);
// Reset file position
reset_fpf_position(cpi, start_pos);
@ -1831,7 +1832,7 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// where cpi->twopass.kf_group_bits is tied to cpi->twopass.bits_left.
// This is also important for short clips where there may only be one
// key frame.
if (cpi->twopass.frames_to_key >= (int)(cpi->twopass.total_stats->count -
if (cpi->twopass.frames_to_key >= (int)(cpi->twopass.total_stats.count -
cpi->common.current_video_frame)) {
cpi->twopass.kf_group_bits =
(cpi->twopass.bits_left > 0) ? cpi->twopass.bits_left : 0;
@ -2099,7 +2100,7 @@ static int adjust_active_maxq(int old_maxqi, int new_maxqi) {
void vp9_second_pass(VP9_COMP *cpi) {
int tmp_q;
int frames_left = (int)(cpi->twopass.total_stats->count -
int frames_left = (int)(cpi->twopass.total_stats.count -
cpi->common.current_video_frame);
FIRSTPASS_STATS this_frame;
@ -2124,7 +2125,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
est_cq =
estimate_cq(cpi,
cpi->twopass.total_left_stats,
&cpi->twopass.total_left_stats,
(int)(cpi->twopass.bits_left / frames_left));
cpi->cq_target_quality = cpi->oxcf.cq_level;
@ -2138,7 +2139,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
tmp_q = estimate_max_q(
cpi,
cpi->twopass.total_left_stats,
&cpi->twopass.total_left_stats,
(int)(cpi->twopass.bits_left / frames_left));
cpi->active_worst_quality = tmp_q;
@ -2161,15 +2162,15 @@ void vp9_second_pass(VP9_COMP *cpi) {
// radical adjustments to the allowed quantizer range just to use up a
// few surplus bits or get beneath the target rate.
else if ((cpi->common.current_video_frame <
(((unsigned int)cpi->twopass.total_stats->count * 255) >> 8)) &&
(((unsigned int)cpi->twopass.total_stats.count * 255) >> 8)) &&
((cpi->common.current_video_frame + cpi->baseline_gf_interval) <
(unsigned int)cpi->twopass.total_stats->count)) {
(unsigned int)cpi->twopass.total_stats.count)) {
if (frames_left < 1)
frames_left = 1;
tmp_q = estimate_max_q(
cpi,
cpi->twopass.total_left_stats,
&cpi->twopass.total_left_stats,
(int)(cpi->twopass.bits_left / frames_left));
// Make a damped adjustment to active max Q
@ -2248,7 +2249,7 @@ void vp9_second_pass(VP9_COMP *cpi) {
cpi->twopass.frames_to_key--;
// Update the total stats remaining structure
subtract_stats(cpi->twopass.total_left_stats, &this_frame);
subtract_stats(&cpi->twopass.total_left_stats, &this_frame);
}
static int test_candidate_kf(VP9_COMP *cpi,

Просмотреть файл

@ -332,15 +332,6 @@ static void dealloc_compressor_data(VP9_COMP *cpi) {
vpx_free(cpi->mb.pip);
cpi->mb.pip = 0;
vpx_free(cpi->twopass.total_stats);
cpi->twopass.total_stats = 0;
vpx_free(cpi->twopass.total_left_stats);
cpi->twopass.total_left_stats = 0;
vpx_free(cpi->twopass.this_frame_stats);
cpi->twopass.this_frame_stats = 0;
}
// Computes a q delta (in "q index" terms) to get from a starting q value
@ -960,23 +951,6 @@ void vp9_alloc_compressor_data(VP9_COMP *cpi) {
CHECK_MEM_ERROR(cpi->mb_norm_activity_map,
vpx_calloc(sizeof(unsigned int),
cm->mb_rows * cm->mb_cols));
vpx_free(cpi->twopass.total_stats);
cpi->twopass.total_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
vpx_free(cpi->twopass.total_left_stats);
cpi->twopass.total_left_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
vpx_free(cpi->twopass.this_frame_stats);
cpi->twopass.this_frame_stats = vpx_calloc(1, sizeof(FIRSTPASS_STATS));
if (!cpi->twopass.total_stats ||
!cpi->twopass.total_left_stats ||
!cpi->twopass.this_frame_stats)
vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,
"Failed to allocate firstpass stats");
}

Просмотреть файл

@ -578,10 +578,10 @@ typedef struct VP9_COMP {
unsigned int section_intra_rating;
unsigned int next_iiratio;
unsigned int this_iiratio;
FIRSTPASS_STATS *total_stats;
FIRSTPASS_STATS *this_frame_stats;
FIRSTPASS_STATS total_stats;
FIRSTPASS_STATS this_frame_stats;
FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
FIRSTPASS_STATS *total_left_stats;
FIRSTPASS_STATS total_left_stats;
int first_pass_done;
int64_t bits_left;
int64_t clip_bits_total;

Просмотреть файл

@ -481,7 +481,7 @@ void configure_arnr_filter(VP9_COMP *cpi, const unsigned int this_frame,
// Note: this_frame->frame has been updated in the loop
// so it now points at the ARF frame.
half_gf_int = cpi->baseline_gf_interval >> 1;
frames_after_arf = (int)(cpi->twopass.total_stats->count - this_frame - 1);
frames_after_arf = (int)(cpi->twopass.total_stats.count - this_frame - 1);
switch (cpi->oxcf.arnr_type) {
case 1: // Backward filter