Skip to content

Commit

Permalink
Fix to VP8 external RC for dynamic update of layers
Browse files Browse the repository at this point in the history
On change/update of rc_cfg: when number of temporal
layers change call vp8_reset_temporal_layer_change(),
which in turn will call vp8_init_temporal_layer_context()
only for the new layers.

Bug:b/249644737

Change-Id: Ib20d746c7eacd10b78806ca6a5362c750d9ca0b3
  • Loading branch information
marco99zz committed Oct 14, 2022
1 parent 5c9d20c commit 4007a05
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
6 changes: 3 additions & 3 deletions vp8/encoder/onyx_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ void vp8_init_temporal_layer_context(VP8_COMP *cpi, VP8_CONFIG *oxcf,
// for any "new" layers. For "existing" layers, let them inherit the parameters
// from the previous layer state (at the same layer #). In future we may want
// to better map the previous layer state(s) to the "new" ones.
static void reset_temporal_layer_change(VP8_COMP *cpi, VP8_CONFIG *oxcf,
const int prev_num_layers) {
void vp8_reset_temporal_layer_change(VP8_COMP *cpi, VP8_CONFIG *oxcf,
const int prev_num_layers) {
int i;
double prev_layer_framerate = 0;
const int curr_num_layers = cpi->oxcf.number_of_layers;
Expand Down Expand Up @@ -1643,7 +1643,7 @@ void vp8_change_config(VP8_COMP *cpi, VP8_CONFIG *oxcf) {
cpi->temporal_layer_id = 0;
}
cpi->temporal_pattern_counter = 0;
reset_temporal_layer_change(cpi, oxcf, prev_number_of_layers);
vp8_reset_temporal_layer_change(cpi, oxcf, prev_number_of_layers);
}

if (!cpi->initial_width) {
Expand Down
2 changes: 2 additions & 0 deletions vp8/encoder/onyx_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ void vp8_initialize_enc(void);

void vp8_alloc_compressor_data(VP8_COMP *cpi);
int vp8_reverse_trans(int x);
void vp8_reset_temporal_layer_change(VP8_COMP *cpi, VP8_CONFIG *oxcf,
const int prev_num_layers);
void vp8_init_temporal_layer_context(VP8_COMP *cpi, VP8_CONFIG *oxcf,
const int layer,
double prev_layer_framerate);
Expand Down
29 changes: 23 additions & 6 deletions vp8/vp8_ratectrl_rtc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void VP8RateControlRTC::UpdateRateControl(
const VP8RateControlRtcConfig &rc_cfg) {
VP8_COMMON *cm = &cpi_->common;
VP8_CONFIG *oxcf = &cpi_->oxcf;
const unsigned int prev_number_of_layers = oxcf->number_of_layers;
vpx_clear_system_state();
cm->Width = rc_cfg.width;
cm->Height = rc_cfg.height;
Expand Down Expand Up @@ -124,17 +125,33 @@ void VP8RateControlRTC::UpdateRateControl(
static_cast<int>(cpi_->output_framerate);
}

if (oxcf->number_of_layers > 1) {
if (oxcf->number_of_layers > 1 || prev_number_of_layers > 1) {
memcpy(oxcf->target_bitrate, rc_cfg.layer_target_bitrate,
sizeof(rc_cfg.layer_target_bitrate));
memcpy(oxcf->rate_decimator, rc_cfg.ts_rate_decimator,
sizeof(rc_cfg.ts_rate_decimator));
oxcf->periodicity = 2;
if (cm->current_video_frame == 0) {
double prev_layer_framerate = 0;
for (unsigned int i = 0; i < oxcf->number_of_layers; ++i) {
vp8_init_temporal_layer_context(cpi_, oxcf, i, prev_layer_framerate);
prev_layer_framerate = cpi_->output_framerate / oxcf->rate_decimator[i];
}
} else if (oxcf->number_of_layers != prev_number_of_layers) {
// The number of temporal layers has changed, so reset/initialize the
// temporal layer context for the new layer configuration: this means
// calling vp8_reset_temporal_layer_change() below.

// Start at the base of the pattern cycle, so set the layer id to 0 and
// reset the temporal pattern counter.
// TODO(marpan/jianj): don't think lines 148-151 are needed (user controls
// the layer_id) so remove.
if (cpi_->temporal_layer_id > 0) {
cpi_->temporal_layer_id = 0;
}
cpi_->temporal_pattern_counter = 0;

double prev_layer_framerate = 0;
for (unsigned int i = 0; i < oxcf->number_of_layers; ++i) {
vp8_init_temporal_layer_context(cpi_, oxcf, i, prev_layer_framerate);
prev_layer_framerate = cpi_->output_framerate / oxcf->rate_decimator[i];
vp8_reset_temporal_layer_change(cpi_, oxcf,
static_cast<int>(prev_number_of_layers));
}
}

Expand Down

0 comments on commit 4007a05

Please sign in to comment.