last_pts_ref_ = 0;
middle_bitrate_ = 0;
top_bitrate_ = 0;
+ superframe_count_ = -1;
+ key_frame_spacing_ = 9999;
}
virtual void BeginPassHook(unsigned int /*pass*/) {}
encoder->Control(VP9E_SET_TUNE_CONTENT, tune_content_);
}
+ superframe_count_++;
+ temporal_layer_id_ = 0;
+ if (number_temporal_layers_ == 2)
+ temporal_layer_id_ = (superframe_count_ % 2 != 0);
+ else if (number_temporal_layers_ == 3) {
+ if (superframe_count_ % 2 != 0) temporal_layer_id_ = 2;
+ if (superframe_count_ > 1) {
+ if ((superframe_count_ - 2) % 4 == 0) temporal_layer_id_ = 1;
+ }
+ }
+
if (update_pattern_ && video->frame() >= 100) {
vpx_svc_layer_id_t layer_id;
if (video->frame() == 100) {
// Set layer id since the pattern changed.
layer_id.spatial_layer_id = 0;
layer_id.temporal_layer_id = (video->frame() % 2 != 0);
+ temporal_layer_id_ = layer_id.temporal_layer_id;
encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id);
set_frame_flags_bypass_mode(layer_id.temporal_layer_id,
number_spatial_layers_, 0, &ref_frame_config);
duration_ = 0;
}
- virtual void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) {
- vpx_svc_layer_id_t layer_id;
- encoder->Control(VP9E_GET_SVC_LAYER_ID, &layer_id);
- spatial_layer_id_ = layer_id.spatial_layer_id;
- temporal_layer_id_ = layer_id.temporal_layer_id;
- // Update buffer with per-layer target frame bandwidth, this is done
- // for every frame passed to the encoder (encoded or dropped).
- // For temporal layers, update the cumulative buffer level.
+ virtual void PostEncodeFrameHook() {
for (int sl = 0; sl < number_spatial_layers_; ++sl) {
for (int tl = temporal_layer_id_; tl < number_temporal_layers_; ++tl) {
const int layer = sl * number_temporal_layers_ + tl;
last_pts_ = pkt->data.frame.pts;
const bool key_frame =
(pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
+ if (key_frame) {
+ temporal_layer_id_ = 0;
+ superframe_count_ = 0;
+ }
parse_superframe_index(static_cast<const uint8_t *>(pkt->data.frame.buf),
pkt->data.frame.sz, sizes, &count);
- if (!dynamic_drop_layer_) ASSERT_EQ(count, number_spatial_layers_);
+ // Count may be less than number of spatial layers because of frame drops.
+ ASSERT_LE(count, number_spatial_layers_);
for (int sl = 0; sl < number_spatial_layers_; ++sl) {
sizes[sl] = sizes[sl] << 3;
// Update the total encoded bits per layer.
bits_in_buffer_model_[layer] -= static_cast<int64_t>(sizes[sl]);
// There should be no buffer underrun, except on the base
// temporal layer, since there may be key frames there.
- if (!key_frame && tl > 0) {
+ // Fo short key frame spacing, buffer can underrun on individual frames.
+ if (!key_frame && tl > 0 && key_frame_spacing_ < 100) {
ASSERT_GE(bits_in_buffer_model_[layer], 0)
<< "Buffer Underrun at frame " << pkt->data.frame.pts;
}
vpx_codec_pts_t last_pts_ref_;
int middle_bitrate_;
int top_bitrate_;
+ int superframe_count_;
+ int key_frame_spacing_;
};
// Check basic rate targeting for 1 pass CBR SVC: 2 spatial layers and 1
svc_params_.scaling_factor_den[0] = 288;
svc_params_.scaling_factor_num[1] = 288;
svc_params_.scaling_factor_den[1] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
svc_params_.scaling_factor_den[0] = 288;
svc_params_.scaling_factor_num[1] = 288;
svc_params_.scaling_factor_den[1] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
// 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
for (int j = 64; j <= 67; j++) {
cfg_.kf_max_dist = j;
+ key_frame_spacing_ = j;
ResetModel();
assign_layer_bitrates(&cfg_, &svc_params_, cfg_.ss_number_layers,
cfg_.ts_number_layers, cfg_.temporal_layering_mode,
svc_params_.scaling_factor_den[0] = 288;
svc_params_.scaling_factor_num[1] = 288;
svc_params_.scaling_factor_den[1] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
svc_params_.scaling_factor_den[1] = 288;
svc_params_.scaling_factor_num[2] = 288;
svc_params_.scaling_factor_den[2] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
svc_params_.scaling_factor_den[1] = 288;
svc_params_.scaling_factor_num[2] = 288;
svc_params_.scaling_factor_den[2] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
svc_params_.scaling_factor_den[1] = 288;
svc_params_.scaling_factor_num[2] = 288;
svc_params_.scaling_factor_den[2] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
// the fly switching to 1 and then 2 and back to 3 spatial layers. This switch
// is done by setting spatial layer bitrates to 0, and then back to non-zero,
// during the sequence.
-TEST_P(DatarateOnePassCbrSvc, OnePassCbrSvc3SL_dynamic) {
+TEST_P(DatarateOnePassCbrSvc, OnePassCbrSvc3SL_DisableEnableLayers) {
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
svc_params_.scaling_factor_den[1] = 288;
svc_params_.scaling_factor_num[2] = 288;
svc_params_.scaling_factor_den[2] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
// 4 key neighboring key frame periods (so key frame will land on 0-2-1-2).
for (int j = 32; j <= 35; j++) {
cfg_.kf_max_dist = j;
+ key_frame_spacing_ = j;
ResetModel();
assign_layer_bitrates(&cfg_, &svc_params_, cfg_.ss_number_layers,
cfg_.ts_number_layers, cfg_.temporal_layering_mode,
svc_params_.scaling_factor_den[1] = 288;
svc_params_.scaling_factor_num[2] = 288;
svc_params_.scaling_factor_den[2] = 288;
- cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_dropframe_thresh = 30;
cfg_.kf_max_dist = 9999;
number_spatial_layers_ = cfg_.ss_number_layers;
number_temporal_layers_ = cfg_.ts_number_layers;
// SVC: skip encoding of enhancement layer if the layer target bandwidth = 0.
if (cpi->use_svc && cpi->svc.spatial_layer_id > 0 &&
- !cpi->svc.rc_drop_superframe && cpi->oxcf.target_bandwidth == 0) {
+ cpi->oxcf.target_bandwidth == 0) {
cpi->svc.skip_enhancement_layer = 1;
vp9_rc_postencode_update_drop_frame(cpi);
vp9_inc_frame_in_layer(cpi);
}
// For 1 pass CBR, check if we are dropping this frame.
- // For spatial layers, for now only check for frame-dropping on first spatial
- // layer, and if decision is to drop, we drop whole super-frame.
+ // For spatial layers, for now if we decide to drop current spatial
+ // layer then we will also drop all upper spatial layers.
+ // TODO(marpan): Allow for the case of dropping single layer only without
+ // dropping all upper layers.
if (oxcf->pass == 0 && oxcf->rc_mode == VPX_CBR &&
cm->frame_type != KEY_FRAME) {
if (vp9_rc_drop_frame(cpi) ||
- (is_one_pass_cbr_svc(cpi) && cpi->svc.rc_drop_superframe == 1)) {
+ (is_one_pass_cbr_svc(cpi) &&
+ cpi->svc.rc_drop_spatial_layer[cpi->svc.spatial_layer_id] == 1)) {
vp9_rc_postencode_update_drop_frame(cpi);
cpi->ext_refresh_frame_flags_pending = 0;
- cpi->svc.rc_drop_superframe = 1;
cpi->last_frame_dropped = 1;
- // TODO(marpan): Advancing the svc counters on dropped frames can break
- // the referencing scheme for the fixed svc patterns defined in
- // vp9_one_pass_cbr_svc_start_layer(). Look into fixing this issue, but
- // for now, don't advance the svc frame counters on dropped frame.
- // if (cpi->use_svc)
- // vp9_inc_frame_in_layer(cpi);
-
+ if (cpi->use_svc) {
+ int i;
+ // If we are dropping this spatial layer, then we will drop all
+ // upper spatial layers.
+ for (i = cpi->svc.spatial_layer_id; i < cpi->svc.number_spatial_layers;
+ i++)
+ cpi->svc.rc_drop_spatial_layer[i] = 1;
+ vp9_inc_frame_in_layer(cpi);
+ if (cpi->svc.rc_drop_spatial_layer[0] == 0)
+ cpi->svc.skip_enhancement_layer = 1;
+ }
return;
}
}
}
cpi->last_frame_dropped = 0;
+ cpi->svc.last_layer_encoded = cpi->svc.spatial_layer_id;
// Disable segmentation if it decrease rate/distortion ratio
if (cpi->oxcf.aq_mode == LOOKAHEAD_AQ)