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;
#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
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;
}
}
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;
}
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,
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) {
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;
}
#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) {
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;
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;
*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);
}
// 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
}
#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
}
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);