Adding layering configurator and rate allocator for VP9 SVC.

The configurator decides number of spatial layers, their resolution
and bitrate thresholds based on given input resolution and maximum
number of spatial layers.

The allocator distributes available bitrate across spatial and
temporal layers. If there is not enough bitrate to provide acceptable
quality for all spatial layers allocator disables enhancement layers
one by one until the condition is met or number of layers is reduced
to one.

VP9 SVC related unit tests have been updated. Input resolution and
bitrate in these tests have been increased to the level enough to
provide desirable number of spatial layers.

Bug: webrtc:8518
Change-Id: I9df790920227c7f7dd4d42a50a856c22f0f4389b
Reviewed-on: https://webrtc-review.googlesource.com/60340
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Reviewed-by: Michael Horowitz <mhoro@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22672}
This commit is contained in:
Sergey Silkin
2018-03-28 19:32:37 +02:00
committed by Commit Bot
parent 002e710d07
commit 86684960b3
22 changed files with 785 additions and 146 deletions

View File

@ -191,26 +191,25 @@ size_t Stats::CalcLayerTargetBitrateKbps(size_t first_frame_num,
size_t spatial_layer_idx,
size_t temporal_layer_idx,
bool aggregate_independent_layers) {
std::vector<size_t> target_bitrate_kbps(temporal_layer_idx + 1, 0);
size_t target_bitrate_kbps = 0;
// We don't know if superframe includes all required spatial layers because
// of possible frame drops. Run through all frames required range, track
// maximum target bitrate per temporal layers and return sum of these.
// Assume target bitrate in frame statistic is specified per temporal layer.
// of possible frame drops. Run through all frames in specified range, find
// and return maximum target bitrate. Assume that target bitrate in frame
// statistic is specified per temporal layer.
for (size_t frame_num = first_frame_num; frame_num <= last_frame_num;
++frame_num) {
FrameStatistics superframe = AggregateFrameStatistic(
frame_num, spatial_layer_idx, aggregate_independent_layers);
if (superframe.temporal_layer_idx <= temporal_layer_idx) {
target_bitrate_kbps[superframe.temporal_layer_idx] =
std::max(target_bitrate_kbps[superframe.temporal_layer_idx],
superframe.target_bitrate_kbps);
target_bitrate_kbps =
std::max(target_bitrate_kbps, superframe.target_bitrate_kbps);
}
}
return std::accumulate(target_bitrate_kbps.begin(), target_bitrate_kbps.end(),
std::size_t {0});
RTC_DCHECK_GT(target_bitrate_kbps, 0);
return target_bitrate_kbps;
}
VideoStatistics Stats::SliceAndCalcVideoStatistic(

View File

@ -15,6 +15,7 @@
#include "media/base/h264_profile_level_id.h"
#include "media/base/mediaconstants.h"
#include "media/engine/simulcast.h"
#include "modules/video_coding/codecs/vp9/svc_config.h"
#include "modules/video_coding/include/video_codec_interface.h"
#include "rtc_base/checks.h"
#include "system_wrappers/include/cpu_info.h"
@ -49,6 +50,19 @@ void ConfigureSimulcast(VideoCodec* codec_settings) {
}
}
void ConfigureSvc(VideoCodec* codec_settings) {
RTC_CHECK_EQ(kVideoCodecVP9, codec_settings->codecType);
const std::vector<SpatialLayer> layers =
GetSvcConfig(codec_settings->width, codec_settings->height,
codec_settings->VP9()->numberOfSpatialLayers,
codec_settings->VP9()->numberOfTemporalLayers);
for (size_t i = 0; i < layers.size(); ++i) {
codec_settings->spatialLayers[i] = layers[i];
}
}
std::string CodecSpecificToString(const VideoCodec& codec) {
std::stringstream ss;
switch (codec.codecType) {
@ -124,9 +138,6 @@ void TestConfig::SetCodecSettings(VideoCodecType codec_type,
codec_settings.numberOfSimulcastStreams =
num_simulcast_streams <= 1 ? 0
: static_cast<uint8_t>(num_simulcast_streams);
if (codec_settings.numberOfSimulcastStreams > 1) {
ConfigureSimulcast(&codec_settings);
}
switch (codec_settings.codecType) {
case kVideoCodecVP8:
@ -158,6 +169,13 @@ void TestConfig::SetCodecSettings(VideoCodecType codec_type,
RTC_NOTREACHED();
break;
}
if (codec_settings.numberOfSimulcastStreams > 1) {
ConfigureSimulcast(&codec_settings);
} else if (codec_settings.codecType == kVideoCodecVP9 &&
codec_settings.VP9()->numberOfSpatialLayers > 1) {
ConfigureSvc(&codec_settings);
}
}
size_t TestConfig::NumberOfCores() const {

View File

@ -350,24 +350,18 @@ void VideoProcessor::FrameEncoded(
frame_stat->encoding_successful = true;
frame_stat->encode_time_us =
GetElapsedTimeMicroseconds(frame_stat->encode_start_ns, encode_stop_ns);
if (codec_type == kVideoCodecVP9) {
const CodecSpecificInfoVP9& vp9_info = codec_specific.codecSpecific.VP9;
frame_stat->inter_layer_predicted = vp9_info.inter_layer_predicted;
// TODO(ssilkin): Implement bitrate allocation for VP9 SVC. For now set
// target for base layers equal to total target to avoid devision by zero
// at analysis.
frame_stat->target_bitrate_kbps = bitrate_allocation_.get_sum_kbps();
} else {
frame_stat->target_bitrate_kbps =
(bitrate_allocation_.GetBitrate(simulcast_svc_idx, temporal_idx) +
500) /
1000;
}
frame_stat->target_bitrate_kbps = (bitrate_allocation_.GetTemporalLayerSum(
simulcast_svc_idx, temporal_idx) +
500) /
1000;
frame_stat->length_bytes = encoded_image._length;
frame_stat->frame_type = encoded_image._frameType;
frame_stat->temporal_layer_idx = temporal_idx;
frame_stat->simulcast_svc_idx = simulcast_svc_idx;
if (codec_type == kVideoCodecVP9) {
const CodecSpecificInfoVP9& vp9_info = codec_specific.codecSpecific.VP9;
frame_stat->inter_layer_predicted = vp9_info.inter_layer_predicted;
}
frame_stat->max_nalu_size_bytes = GetMaxNaluSizeBytes(encoded_image, config_);
frame_stat->qp = encoded_image.qp_;