/* * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// Limits for legacy conference screensharing mode. Currently used for the // lower of the two simulcast streams.
constexpr webrtc::DataRate kScreenshareDefaultTl0Bitrate =
webrtc::DataRate::KilobitsPerSec(200);
constexpr webrtc::DataRate kScreenshareDefaultTl1Bitrate =
webrtc::DataRate::KilobitsPerSec(1000);
// Min/max bitrate for the higher one of the two simulcast stream used for // screen content.
constexpr webrtc::DataRate kScreenshareHighStreamMinBitrate =
webrtc::DataRate::KilobitsPerSec(600);
constexpr webrtc::DataRate kScreenshareHighStreamMaxBitrate =
webrtc::DataRate::KilobitsPerSec(1250);
constexpr int kDefaultNumTemporalLayers = 3;
constexpr int kScreenshareMaxSimulcastLayers = 2;
constexpr int kScreenshareTemporalLayers = 2;
struct SimulcastFormat { int width; int height; // The maximum number of simulcast layers can be used for // resolutions at `widthxheight` for legacy applications.
size_t max_layers; // The maximum bitrate for encoding stream at `widthxheight`, when we are // not sending the next higher spatial stream.
webrtc::DataRate max_bitrate; // The target bitrate for encoding stream at `widthxheight`, when this layer // is not the highest layer (i.e., when we are sending another higher spatial // stream).
webrtc::DataRate target_bitrate; // The minimum bitrate needed for encoding stream at `widthxheight`.
webrtc::DataRate min_bitrate;
};
// These tables describe from which resolution we can use how many // simulcast layers at what bitrates (maximum, target, and minimum). // Important!! Keep this table from high resolution to low resolution.
constexpr const SimulcastFormat kSimulcastFormatsVP8[] = {
{1920, 1080, 3, webrtc::DataRate::KilobitsPerSec(5000),
webrtc::DataRate::KilobitsPerSec(4000),
webrtc::DataRate::KilobitsPerSec(800)},
{1280, 720, 3, webrtc::DataRate::KilobitsPerSec(2500),
webrtc::DataRate::KilobitsPerSec(2500),
webrtc::DataRate::KilobitsPerSec(600)},
{960, 540, 3, webrtc::DataRate::KilobitsPerSec(1200),
webrtc::DataRate::KilobitsPerSec(1200),
webrtc::DataRate::KilobitsPerSec(350)},
{640, 360, 2, webrtc::DataRate::KilobitsPerSec(700),
webrtc::DataRate::KilobitsPerSec(500),
webrtc::DataRate::KilobitsPerSec(150)},
{480, 270, 2, webrtc::DataRate::KilobitsPerSec(450),
webrtc::DataRate::KilobitsPerSec(350),
webrtc::DataRate::KilobitsPerSec(150)},
{320, 180, 1, webrtc::DataRate::KilobitsPerSec(200),
webrtc::DataRate::KilobitsPerSec(150),
webrtc::DataRate::KilobitsPerSec(30)}, // As the resolution goes down, interpolate the target and max bitrates down // towards zero. The min bitrate is still limited at 30 kbps and the target // and the max will be capped from below accordingly.
{0, 0, 1, webrtc::DataRate::KilobitsPerSec(0),
webrtc::DataRate::KilobitsPerSec(0),
webrtc::DataRate::KilobitsPerSec(30)}};
// These tables describe from which resolution we can use how many // simulcast layers at what bitrates (maximum, target, and minimum). // Important!! Keep this table from high resolution to low resolution.
constexpr const SimulcastFormat kSimulcastFormatsVP9[] = {
{1920, 1080, 3, webrtc::DataRate::KilobitsPerSec(3367),
webrtc::DataRate::KilobitsPerSec(3367),
webrtc::DataRate::KilobitsPerSec(769)},
{1280, 720, 3, webrtc::DataRate::KilobitsPerSec(1524),
webrtc::DataRate::KilobitsPerSec(1524),
webrtc::DataRate::KilobitsPerSec(481)},
{960, 540, 3, webrtc::DataRate::KilobitsPerSec(879),
webrtc::DataRate::KilobitsPerSec(879),
webrtc::DataRate::KilobitsPerSec(337)},
{640, 360, 2, webrtc::DataRate::KilobitsPerSec(420),
webrtc::DataRate::KilobitsPerSec(420),
webrtc::DataRate::KilobitsPerSec(193)},
{480, 270, 2, webrtc::DataRate::KilobitsPerSec(257),
webrtc::DataRate::KilobitsPerSec(257),
webrtc::DataRate::KilobitsPerSec(121)},
{320, 180, 1, webrtc::DataRate::KilobitsPerSec(142),
webrtc::DataRate::KilobitsPerSec(142),
webrtc::DataRate::KilobitsPerSec(30)},
{240, 135, 1, webrtc::DataRate::KilobitsPerSec(101),
webrtc::DataRate::KilobitsPerSec(101),
webrtc::DataRate::KilobitsPerSec(30)}, // As the resolution goes down, interpolate the target and max bitrates down // towards zero. The min bitrate is still limited at 30 kbps and the target // and the max will be capped from below accordingly.
{0, 0, 1, webrtc::DataRate::KilobitsPerSec(0),
webrtc::DataRate::KilobitsPerSec(0),
webrtc::DataRate::KilobitsPerSec(30)}};
constexpr webrtc::DataRate Interpolate(const webrtc::DataRate& a, const webrtc::DataRate& b, float rate) { return a * (1.0 - rate) + b * rate;
}
// TODO(webrtc:12415): Flip this to a kill switch when this feature launches. bool EnableLowresBitrateInterpolation(const webrtc::FieldTrialsView& trials) { return absl::StartsWith(
trials.Lookup("WebRTC-LowresSimulcastBitrateInterpolation"), "Enabled");
}
if (s == 0) { // If alternative temporal rate allocation is selected, adjust the // bitrate of the lowest simulcast stream so that absolute bitrate for // the base temporal layer matches the bitrate for the base temporal // layer with the default 3 simulcast streams. Otherwise we risk a // higher threshold for receiving a feed at all. float rate_factor = 1.0; if (num_temporal_layers == 3) { if (base_heavy_tl3_rate_alloc) { // Base heavy allocation increases TL0 bitrate from 40% to 60%.
rate_factor = 0.4 / 0.6;
}
} else {
rate_factor =
webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
3, 0, /*base_heavy_tl3_rate_alloc=*/false) /
webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
num_temporal_layers, 0, /*base_heavy_tl3_rate_alloc=*/false);
}
std::vector<webrtc::VideoStream> layers(num_simulcast_layers); // For legacy screenshare in conference mode, tl0 and tl1 bitrates are // piggybacked on the VideoCodec struct as target and max bitrates, // respectively. See eg. webrtc::LibvpxVp8Encoder::SetRates().
layers[0].width = width;
layers[0].height = height;
layers[0].max_framerate = 5;
layers[0].min_bitrate_bps = webrtc::kDefaultMinVideoBitrateBps;
layers[0].target_bitrate_bps = kScreenshareDefaultTl0Bitrate.bps();
layers[0].max_bitrate_bps = kScreenshareDefaultTl1Bitrate.bps();
layers[0].num_temporal_layers = temporal_layers_supported ? 2 : 1;
// With simulcast enabled, add another spatial layer. This one will have a // more normal layout, with the regular 3 temporal layer pattern and no fps // restrictions. The base simulcast layer will still use legacy setup. if (num_simulcast_layers == kScreenshareMaxSimulcastLayers) { // Add optional upper simulcast layer. int max_bitrate_bps; bool using_boosted_bitrate = false; if (!temporal_layers_supported) { // Set the max bitrate to where the base layer would have been if temporal // layers were enabled.
max_bitrate_bps = static_cast<int>(
kScreenshareHighStreamMaxBitrate.bps() *
webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
kScreenshareTemporalLayers, 0, base_heavy_tl3_rate_alloc));
} else { // Experimental temporal layer mode used, use increased max bitrate.
max_bitrate_bps = kScreenshareHighStreamMaxBitrate.bps();
using_boosted_bitrate = true;
}
size_t LimitSimulcastLayerCount(size_t min_num_layers,
size_t max_num_layers, int width, int height, const webrtc::FieldTrialsView& trials,
webrtc::VideoCodecType codec) { if (!absl::StartsWith(trials.Lookup(kUseLegacySimulcastLayerLimitFieldTrial), "Disabled")) { // Max layers from one higher resolution in kSimulcastFormats will be used // if the ratio (pixels_up - pixels) / (pixels_up - pixels_down) is less // than configured `max_ratio`. pixels_down is the selected index in // kSimulcastFormats based on pixels.
webrtc::FieldTrialOptional<double> max_ratio("max_ratio");
webrtc::ParseFieldTrial({&max_ratio},
trials.Lookup("WebRTC-SimulcastLayerLimitRoundUp"));
// We're still not using all available bits. if (total_bitrate < max_bitrate) { // Spend additional bits to boost the max layer. const webrtc::DataRate bitrate_left = max_bitrate - total_bitrate;
layers->back().max_bitrate_bps += bitrate_left.bps();
}
}
webrtc::DataRate GetTotalMaxBitrate( const std::vector<webrtc::VideoStream>& layers) { if (layers.empty()) return webrtc::DataRate::Zero();
int total_max_bitrate_bps = 0; for (size_t s = 0; s < layers.size() - 1; ++s) {
total_max_bitrate_bps += layers[s].target_bitrate_bps;
}
total_max_bitrate_bps += layers.back().max_bitrate_bps; return webrtc::DataRate::BitsPerSec(total_max_bitrate_bps);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.