Fix target frame rate of spatial layer.

Set target frame rate of spatial layer equal to minimum of two: maximum
frame rate of layer (SpatialLayer::maxFramerate) and maximum frame rate
of codec (VideoCodec::maxFramerate).

Bug: webrtc:9740, webrtc:9739, chromium:882358
Change-Id: I34f36e7fd2889f0417474347abab5327fa2d9d7c
Reviewed-on: https://webrtc-review.googlesource.com/99501
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24686}
This commit is contained in:
Sergey Silkin
2018-09-11 11:40:25 +02:00
committed by Commit Bot
parent 375d35e01b
commit beba1b2766
2 changed files with 45 additions and 2 deletions

View File

@ -677,6 +677,48 @@ TEST_F(TestVp9ImplFrameDropping, DifferentFrameratePerSpatialLayer) {
}
}
TEST_F(TestVp9ImplFrameDropping, LayerMaxFramerateIsCappedByCodecMaxFramerate) {
const float input_framerate_fps = 30.0;
const float layer_max_framerate_fps = 30.0;
const uint32_t codec_max_framerate_fps = layer_max_framerate_fps / 3;
const size_t video_duration_secs = 3;
const size_t num_input_frames = video_duration_secs * input_framerate_fps;
VideoBitrateAllocation bitrate_allocation;
codec_settings_.spatialLayers[0].width = codec_settings_.width;
codec_settings_.spatialLayers[0].height = codec_settings_.height;
codec_settings_.spatialLayers[0].maxFramerate = layer_max_framerate_fps;
codec_settings_.spatialLayers[0].minBitrate = codec_settings_.startBitrate;
codec_settings_.spatialLayers[0].maxBitrate = codec_settings_.startBitrate;
codec_settings_.spatialLayers[0].targetBitrate = codec_settings_.startBitrate;
bitrate_allocation.SetBitrate(
0, 0, codec_settings_.spatialLayers[0].targetBitrate * 1000);
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->InitEncode(&codec_settings_, 1 /* number of cores */,
0 /* max payload size (unused) */));
EXPECT_EQ(
WEBRTC_VIDEO_CODEC_OK,
encoder_->SetRateAllocation(bitrate_allocation, codec_max_framerate_fps));
VideoFrame* input_frame = NextInputFrame();
for (size_t frame_num = 0; frame_num < num_input_frames; ++frame_num) {
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
encoder_->Encode(*input_frame, nullptr, nullptr));
const size_t timestamp = input_frame->timestamp() +
kVideoPayloadTypeFrequency / input_framerate_fps;
input_frame->set_timestamp(static_cast<uint32_t>(timestamp));
}
const size_t num_encoded_frames = GetNumEncodedFrames();
const float encoded_framerate_fps = num_encoded_frames / video_duration_secs;
const float max_framerate_error_fps = codec_max_framerate_fps * 0.1f;
EXPECT_NEAR(encoded_framerate_fps, codec_max_framerate_fps,
max_framerate_error_fps);
}
class TestVp9ImplProfile2 : public TestVp9Impl {
protected:
void SetUp() override {

View File

@ -195,7 +195,7 @@ int VP9EncoderImpl::Release() {
bool VP9EncoderImpl::ExplicitlyConfiguredSpatialLayers() const {
// We check target_bitrate_bps of the 0th layer to see if the spatial layers
// (i.e. bitrates) were explicitly configured.
return num_spatial_layers_ > 1 && codec_.spatialLayers[0].targetBitrate > 0;
return codec_.spatialLayers[0].targetBitrate > 0;
}
bool VP9EncoderImpl::SetSvcRates(
@ -228,7 +228,8 @@ bool VP9EncoderImpl::SetSvcRates(
}
framerate_controller_[sl_idx].SetTargetRate(
codec_.spatialLayers[sl_idx].maxFramerate);
std::min(static_cast<float>(codec_.maxFramerate),
codec_.spatialLayers[sl_idx].maxFramerate));
}
} else {
float rate_ratio[VPX_MAX_LAYERS] = {0};