Merge "Cleanups on refresh flags"

This commit is contained in:
Deb Mukherjee 2014-01-09 17:38:45 -08:00 committed by Gerrit Code Review
commit 36c8daed58
4 changed files with 90 additions and 86 deletions

View File

@ -2038,8 +2038,8 @@ void vp9_get_first_pass_params(VP9_COMP *cpi) {
} else {
cm->frame_type = INTER_FRAME;
}
cpi->rc.frames_to_key = INT_MAX;
// Do not use periodic key frames
cpi->rc.frames_to_key = INT_MAX;
}
void vp9_get_second_pass_params(VP9_COMP *cpi) {

View File

@ -1262,8 +1262,6 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
// cpi->use_golden_frame_only = 0;
// cpi->use_last_frame_only = 0;
cpi->refresh_golden_frame = 0;
cpi->refresh_last_frame = 1;
cm->refresh_frame_context = 1;
@ -1365,6 +1363,9 @@ void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
#endif
set_tile_limits(cpi);
cpi->ext_refresh_frame_flags_pending = 0;
cpi->ext_refresh_frame_context_pending = 0;
}
#define M_LOG2_E 0.693147180559945309417
@ -2160,19 +2161,20 @@ int vp9_update_reference(VP9_PTR ptr, int ref_frame_flags) {
if (ref_frame_flags > 7)
return -1;
cpi->refresh_golden_frame = 0;
cpi->refresh_alt_ref_frame = 0;
cpi->refresh_last_frame = 0;
cpi->ext_refresh_golden_frame = 0;
cpi->ext_refresh_alt_ref_frame = 0;
cpi->ext_refresh_last_frame = 0;
if (ref_frame_flags & VP9_LAST_FLAG)
cpi->refresh_last_frame = 1;
cpi->ext_refresh_last_frame = 1;
if (ref_frame_flags & VP9_GOLD_FLAG)
cpi->refresh_golden_frame = 1;
cpi->ext_refresh_golden_frame = 1;
if (ref_frame_flags & VP9_ALT_FLAG)
cpi->refresh_alt_ref_frame = 1;
cpi->ext_refresh_alt_ref_frame = 1;
cpi->ext_refresh_frame_flags_pending = 1;
return 0;
}
@ -2228,7 +2230,8 @@ int vp9_set_reference_enc(VP9_PTR ptr, VP9_REFFRAME ref_frame_flag,
}
int vp9_update_entropy(VP9_PTR comp, int update) {
((VP9_COMP *)comp)->common.refresh_frame_context = update;
((VP9_COMP *)comp)->ext_refresh_frame_context = update;
((VP9_COMP *)comp)->ext_refresh_frame_context_pending = 1;
return 0;
}
@ -2878,6 +2881,23 @@ static void get_ref_frame_flags(VP9_COMP *cpi) {
cpi->ref_frame_flags &= ~VP9_ALT_FLAG;
}
static void set_ext_overrides(VP9_COMP *cpi) {
// Overrides the defaults with the externally supplied values with
// vp9_update_reference() and vp9_update_entropy() calls
// Note: The overrides are valid only for the next frame passed
// to encode_frame_to_data_rate() function
if (cpi->ext_refresh_frame_context_pending) {
cpi->common.refresh_frame_context = cpi->ext_refresh_frame_context;
cpi->ext_refresh_frame_context_pending = 0;
}
if (cpi->ext_refresh_frame_flags_pending) {
cpi->refresh_last_frame = cpi->ext_refresh_last_frame;
cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame;
cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
cpi->ext_refresh_frame_flags_pending = 0;
}
}
static void encode_frame_to_data_rate(VP9_COMP *cpi,
size_t *size,
uint8_t *dest,
@ -2894,6 +2914,8 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
unsigned int max_mv_def = MIN(cpi->common.width, cpi->common.height);
struct segmentation *const seg = &cm->seg;
set_ext_overrides(cpi);
/* Scale the source buffer, if required. */
if (cm->mi_cols * 8 != cpi->un_scaled_source->y_width ||
cm->mi_rows * 8 != cpi->un_scaled_source->y_height) {
@ -3069,6 +3091,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
cpi->ambient_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm));
}
// If the encoder forced a KEY_FRAME decision
if (cm->frame_type == KEY_FRAME)
cpi->refresh_last_frame = 1;
@ -3299,6 +3322,44 @@ int is_next_frame_arf(VP9_COMP *cpi) {
}
#endif
void adjust_frame_rate(VP9_COMP *cpi) {
int64_t this_duration;
int step = 0;
if (cpi->source->ts_start == cpi->first_time_stamp_ever) {
this_duration = cpi->source->ts_end - cpi->source->ts_start;
step = 1;
} else {
int64_t last_duration = cpi->last_end_time_stamp_seen
- cpi->last_time_stamp_seen;
this_duration = cpi->source->ts_end - cpi->last_end_time_stamp_seen;
// do a step update if the duration changes by 10%
if (last_duration)
step = (int)((this_duration - last_duration) * 10 / last_duration);
}
if (this_duration) {
if (step) {
vp9_new_framerate(cpi, 10000000.0 / this_duration);
} else {
// Average this frame's rate into the last second's average
// frame rate. If we haven't seen 1 second yet, then average
// over the whole interval seen.
const double interval = MIN((double)(cpi->source->ts_end
- cpi->first_time_stamp_ever), 10000000.0);
double avg_duration = 10000000.0 / cpi->oxcf.framerate;
avg_duration *= (interval - avg_duration + this_duration);
avg_duration /= interval;
vp9_new_framerate(cpi, 10000000.0 / avg_duration);
}
}
cpi->last_time_stamp_seen = cpi->source->ts_start;
cpi->last_end_time_stamp_seen = cpi->source->ts_end;
}
int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
size_t *size, uint8_t *dest,
int64_t *time_stamp, int64_t *time_end, int flush) {
@ -3318,6 +3379,13 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV);
// Normal defaults
cm->reset_frame_context = 0;
cm->refresh_frame_context = 1;
cpi->refresh_last_frame = 1;
cpi->refresh_golden_frame = 0;
cpi->refresh_alt_ref_frame = 0;
// Should we code an alternate reference frame.
if (cpi->oxcf.play_alternate && cpi->rc.source_alt_ref_pending) {
int frames_to_arf;
@ -3328,7 +3396,7 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
if (cpi->multi_arf_enabled && (cpi->pass == 2))
frames_to_arf = (-cpi->frame_coding_order[cpi->sequence_number])
- cpi->next_frame_in_order;
- cpi->next_frame_in_order;
else
#endif
frames_to_arf = cpi->rc.frames_till_gf_update_due;
@ -3412,18 +3480,6 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
*time_end = cpi->source->ts_end;
*frame_flags = cpi->source->flags;
// fprintf(fp_out, " Frame:%d", cm->current_video_frame);
#if CONFIG_MULTIPLE_ARF
if (cpi->multi_arf_enabled) {
// fprintf(fp_out, " seq_no:%d this_frame_weight:%d",
// cpi->sequence_number, cpi->this_frame_weight);
} else {
// fprintf(fp_out, "\n");
}
#else
// fprintf(fp_out, "\n");
#endif
#if CONFIG_MULTIPLE_ARF
if ((cm->frame_type != KEY_FRAME) && (cpi->pass == 2))
cpi->rc.source_alt_ref_pending = is_next_frame_arf(cpi);
@ -3445,43 +3501,8 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
}
// adjust frame rates based on timestamps given
if (!cpi->refresh_alt_ref_frame) {
int64_t this_duration;
int step = 0;
if (cpi->source->ts_start == cpi->first_time_stamp_ever) {
this_duration = cpi->source->ts_end - cpi->source->ts_start;
step = 1;
} else {
int64_t last_duration = cpi->last_end_time_stamp_seen
- cpi->last_time_stamp_seen;
this_duration = cpi->source->ts_end - cpi->last_end_time_stamp_seen;
// do a step update if the duration changes by 10%
if (last_duration)
step = (int)((this_duration - last_duration) * 10 / last_duration);
}
if (this_duration) {
if (step) {
vp9_new_framerate(cpi, 10000000.0 / this_duration);
} else {
// Average this frame's rate into the last second's average
// frame rate. If we haven't seen 1 second yet, then average
// over the whole interval seen.
const double interval = MIN((double)(cpi->source->ts_end
- cpi->first_time_stamp_ever), 10000000.0);
double avg_duration = 10000000.0 / cpi->oxcf.framerate;
avg_duration *= (interval - avg_duration + this_duration);
avg_duration /= interval;
vp9_new_framerate(cpi, 10000000.0 / avg_duration);
}
}
cpi->last_time_stamp_seen = cpi->source->ts_start;
cpi->last_end_time_stamp_seen = cpi->source->ts_end;
if (cm->show_frame) {
adjust_frame_rate(cpi);
}
// start with a 0 size frame
@ -3507,21 +3528,6 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
}
#endif
#if 0 // CONFIG_MULTIPLE_ARF
if (cpi->multi_arf_enabled) {
fprintf(fp_out, " idx(%d, %d, %d, %d) active(%d, %d, %d)",
cpi->lst_fb_idx, cpi->gld_fb_idx, cpi->alt_fb_idx, cm->new_fb_idx,
cm->ref_frame_map[cpi->lst_fb_idx],
cm->ref_frame_map[cpi->gld_fb_idx],
cm->ref_frame_map[cpi->alt_fb_idx]);
if (cpi->refresh_alt_ref_frame)
fprintf(fp_out, " type:ARF");
if (cpi->rc.is_src_frame_alt_ref)
fprintf(fp_out, " type:OVERLAY[%d]", cpi->alt_fb_idx);
fprintf(fp_out, "\n");
}
#endif
cm->frame_flags = *frame_flags;
// Reset the frame pointers to the current frame size
@ -3572,15 +3578,7 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
}
if (*size > 0) {
// if its a dropped frame honor the requests on subsequent frames
cpi->droppable = !frame_is_reference(cpi);
// return to normal state
cm->reset_frame_context = 0;
cm->refresh_frame_context = 1;
cpi->refresh_alt_ref_frame = 0;
cpi->refresh_golden_frame = 0;
cpi->refresh_last_frame = 1;
}
vpx_usec_timer_mark(&cmptimer);

View File

@ -400,6 +400,15 @@ typedef struct VP9_COMP {
int refresh_last_frame;
int refresh_golden_frame;
int refresh_alt_ref_frame;
int ext_refresh_frame_flags_pending;
int ext_refresh_last_frame;
int ext_refresh_golden_frame;
int ext_refresh_alt_ref_frame;
int ext_refresh_frame_context_pending;
int ext_refresh_frame_context;
YV12_BUFFER_CONFIG last_frame_uf;
TOKENEXTRA *tok;

View File

@ -184,8 +184,6 @@ void vp9_setup_key_frame(VP9_COMP *cpi) {
vp9_setup_past_independence(cm);
// interval before next GF
cpi->rc.frames_till_gf_update_due = cpi->rc.baseline_gf_interval;
/* All buffers are implicitly updated on key frames. */
cpi->refresh_golden_frame = 1;
cpi->refresh_alt_ref_frame = 1;
@ -855,7 +853,6 @@ static void update_golden_frame_stats(VP9_COMP *cpi) {
// Update the Golden frame usage counts.
if (cpi->refresh_golden_frame) {
// this frame refreshes means next frames don't unless specified by user
cpi->refresh_golden_frame = 0;
cpi->rc.frames_since_golden = 0;
if (!cpi->rc.source_alt_ref_pending)