Index: source/libvpx/vp9/encoder/vp9_encoder.c |
=================================================================== |
--- source/libvpx/vp9/encoder/vp9_encoder.c (revision 291087) |
+++ source/libvpx/vp9/encoder/vp9_encoder.c (working copy) |
@@ -489,14 +489,6 @@ |
vp9_rc_update_framerate(cpi); |
} |
-int64_t vp9_rescale(int64_t val, int64_t num, int denom) { |
- int64_t llnum = num; |
- int64_t llden = denom; |
- int64_t llval = val; |
- |
- return (llval * llnum / llden); |
-} |
- |
static void set_tile_limits(VP9_COMP *cpi) { |
VP9_COMMON *const cm = &cpi->common; |
@@ -533,10 +525,8 @@ |
// Temporal scalability. |
cpi->svc.number_temporal_layers = oxcf->ts_number_layers; |
- if ((cpi->svc.number_temporal_layers > 1 && |
- cpi->oxcf.rc_mode == VPX_CBR) || |
- (cpi->svc.number_spatial_layers > 1 && |
- cpi->oxcf.mode == TWO_PASS_SECOND_BEST)) { |
+ if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) || |
+ (cpi->svc.number_spatial_layers > 1 && cpi->oxcf.pass == 2)) { |
vp9_init_layer_context(cpi); |
} |
@@ -551,6 +541,20 @@ |
set_tile_limits(cpi); |
} |
+static void set_rc_buffer_sizes(RATE_CONTROL *rc, |
+ const VP9EncoderConfig *oxcf) { |
+ const int64_t bandwidth = oxcf->target_bandwidth; |
+ const int64_t starting = oxcf->starting_buffer_level_ms; |
+ const int64_t optimal = oxcf->optimal_buffer_level_ms; |
+ const int64_t maximum = oxcf->maximum_buffer_size_ms; |
+ |
+ rc->starting_buffer_level = starting * bandwidth / 1000; |
+ rc->optimal_buffer_level = (optimal == 0) ? bandwidth / 8 |
+ : optimal * bandwidth / 1000; |
+ rc->maximum_buffer_size = (maximum == 0) ? bandwidth / 8 |
+ : maximum * bandwidth / 1000; |
+} |
+ |
void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { |
VP9_COMMON *const cm = &cpi->common; |
RATE_CONTROL *const rc = &cpi->rc; |
@@ -584,28 +588,8 @@ |
} |
cpi->encode_breakout = cpi->oxcf.encode_breakout; |
- // local file playback mode == really big buffer |
- if (cpi->oxcf.rc_mode == VPX_VBR) { |
- cpi->oxcf.starting_buffer_level_ms = 60000; |
- cpi->oxcf.optimal_buffer_level_ms = 60000; |
- cpi->oxcf.maximum_buffer_size_ms = 240000; |
- } |
+ set_rc_buffer_sizes(rc, &cpi->oxcf); |
- rc->starting_buffer_level = vp9_rescale(cpi->oxcf.starting_buffer_level_ms, |
- cpi->oxcf.target_bandwidth, 1000); |
- |
- // Set or reset optimal and maximum buffer levels. |
- if (cpi->oxcf.optimal_buffer_level_ms == 0) |
- rc->optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; |
- else |
- rc->optimal_buffer_level = vp9_rescale(cpi->oxcf.optimal_buffer_level_ms, |
- cpi->oxcf.target_bandwidth, 1000); |
- |
- if (cpi->oxcf.maximum_buffer_size_ms == 0) |
- rc->maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; |
- else |
- rc->maximum_buffer_size = vp9_rescale(cpi->oxcf.maximum_buffer_size_ms, |
- cpi->oxcf.target_bandwidth, 1000); |
// Under a configuration change, where maximum_buffer_size may change, |
// keep buffer level clipped to the maximum allowed buffer size. |
rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size); |
@@ -731,11 +715,6 @@ |
vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
cm->current_video_frame = 0; |
- |
- cpi->gold_is_last = 0; |
- cpi->alt_is_last = 0; |
- cpi->gold_is_alt = 0; |
- |
cpi->skippable_frame = 0; |
// Create the encoder segmentation map and set all entries to 0 |
@@ -1916,36 +1895,27 @@ |
} while (loop); |
} |
-static void get_ref_frame_flags(VP9_COMP *cpi) { |
- if (cpi->refresh_last_frame & cpi->refresh_golden_frame) |
- cpi->gold_is_last = 1; |
- else if (cpi->refresh_last_frame ^ cpi->refresh_golden_frame) |
- cpi->gold_is_last = 0; |
+static int get_ref_frame_flags(const VP9_COMP *cpi) { |
+ const int *const map = cpi->common.ref_frame_map; |
+ const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
+ const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
+ const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
+ int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
- if (cpi->refresh_last_frame & cpi->refresh_alt_ref_frame) |
- cpi->alt_is_last = 1; |
- else if (cpi->refresh_last_frame ^ cpi->refresh_alt_ref_frame) |
- cpi->alt_is_last = 0; |
+ if (gold_is_last) |
+ flags &= ~VP9_GOLD_FLAG; |
- if (cpi->refresh_alt_ref_frame & cpi->refresh_golden_frame) |
- cpi->gold_is_alt = 1; |
- else if (cpi->refresh_alt_ref_frame ^ cpi->refresh_golden_frame) |
- cpi->gold_is_alt = 0; |
- |
- cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
- |
- if (cpi->gold_is_last) |
- cpi->ref_frame_flags &= ~VP9_GOLD_FLAG; |
- |
if (cpi->rc.frames_till_gf_update_due == INT_MAX && |
!is_spatial_svc(cpi)) |
- cpi->ref_frame_flags &= ~VP9_GOLD_FLAG; |
+ flags &= ~VP9_GOLD_FLAG; |
- if (cpi->alt_is_last) |
- cpi->ref_frame_flags &= ~VP9_ALT_FLAG; |
+ if (alt_is_last) |
+ flags &= ~VP9_ALT_FLAG; |
- if (cpi->gold_is_alt) |
- cpi->ref_frame_flags &= ~VP9_ALT_FLAG; |
+ if (gold_is_alt) |
+ flags &= ~VP9_ALT_FLAG; |
+ |
+ return flags; |
} |
static void set_ext_overrides(VP9_COMP *cpi) { |
@@ -2014,19 +1984,41 @@ |
cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
} |
+static void set_mv_search_params(VP9_COMP *cpi) { |
+ const VP9_COMMON *const cm = &cpi->common; |
+ const unsigned int max_mv_def = MIN(cm->width, cm->height); |
+ |
+ // Default based on max resolution. |
+ cpi->mv_step_param = vp9_init_search_range(max_mv_def); |
+ |
+ if (cpi->sf.mv.auto_mv_step_size) { |
+ if (frame_is_intra_only(cm)) { |
+ // Initialize max_mv_magnitude for use in the first INTER frame |
+ // after a key/intra-only frame. |
+ cpi->max_mv_magnitude = max_mv_def; |
+ } else { |
+ if (cm->show_frame) |
+ // Allow mv_steps to correspond to twice the max mv magnitude found |
+ // in the previous frame, capped by the default max_mv_magnitude based |
+ // on resolution. |
+ cpi->mv_step_param = |
+ vp9_init_search_range(MIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
+ cpi->max_mv_magnitude = 0; |
+ } |
+ } |
+} |
+ |
static void encode_frame_to_data_rate(VP9_COMP *cpi, |
size_t *size, |
uint8_t *dest, |
unsigned int *frame_flags) { |
VP9_COMMON *const cm = &cpi->common; |
+ struct segmentation *const seg = &cm->seg; |
TX_SIZE t; |
int q; |
int top_index; |
int bottom_index; |
- const SPEED_FEATURES *const sf = &cpi->sf; |
- const unsigned int max_mv_def = MIN(cm->width, cm->height); |
- struct segmentation *const seg = &cm->seg; |
set_ext_overrides(cpi); |
cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, |
@@ -2052,24 +2044,7 @@ |
// Set default state for segment based loop filter update flags. |
cm->lf.mode_ref_delta_update = 0; |
- // Initialize cpi->mv_step_param to default based on max resolution. |
- cpi->mv_step_param = vp9_init_search_range(max_mv_def); |
- // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. |
- if (sf->mv.auto_mv_step_size) { |
- if (frame_is_intra_only(cm)) { |
- // Initialize max_mv_magnitude for use in the first INTER frame |
- // after a key/intra-only frame. |
- cpi->max_mv_magnitude = max_mv_def; |
- } else { |
- if (cm->show_frame) |
- // Allow mv_steps to correspond to twice the max mv magnitude found |
- // in the previous frame, capped by the default max_mv_magnitude based |
- // on resolution. |
- cpi->mv_step_param = vp9_init_search_range(MIN(max_mv_def, 2 * |
- cpi->max_mv_magnitude)); |
- cpi->max_mv_magnitude = 0; |
- } |
- } |
+ set_mv_search_params(cpi); |
// Set various flags etc to special state if it is a key frame. |
if (frame_is_intra_only(cm)) { |
@@ -2247,7 +2222,7 @@ |
else |
cpi->frame_flags &= ~FRAMEFLAGS_ALTREF; |
- get_ref_frame_flags(cpi); |
+ cpi->ref_frame_flags = get_ref_frame_flags(cpi); |
cm->last_frame_type = cm->frame_type; |
vp9_rc_postencode_update(cpi, *size); |