2014-12-10 09:01:18 +00:00
|
|
|
/*
|
2016-02-07 20:46:45 -08:00
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
2014-12-10 09:01:18 +00:00
|
|
|
*
|
2016-02-07 20:46:45 -08:00
|
|
|
* 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.
|
2014-12-10 09:01:18 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "media/engine/simulcast.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stdint.h>
|
2014-12-23 15:19:35 +00:00
|
|
|
#include <stdio.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2017-10-31 09:53:08 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <string>
|
2014-12-23 15:19:35 +00:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "absl/types/optional.h"
|
2019-01-16 17:10:57 +01:00
|
|
|
#include "api/video/video_codec_constants.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/media_constants.h"
|
2018-06-21 16:16:38 +02:00
|
|
|
#include "modules/video_coding/utility/simulcast_rate_allocator.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/arraysize.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/checks.h"
|
2019-10-11 16:19:43 +02:00
|
|
|
#include "rtc_base/experiments/min_video_bitrate_experiment.h"
|
2018-10-12 17:36:57 +02:00
|
|
|
#include "rtc_base/experiments/normalize_simulcast_size_experiment.h"
|
2019-10-30 13:01:46 +01:00
|
|
|
#include "rtc_base/experiments/rate_control_settings.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
|
|
|
|
#include "system_wrappers/include/field_trial.h"
|
2015-11-10 23:44:30 -08:00
|
|
|
|
2014-12-10 09:01:18 +00:00
|
|
|
namespace cricket {
|
|
|
|
|
|
2018-05-09 11:28:01 +02:00
|
|
|
namespace {
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
constexpr webrtc::DataRate Interpolate(const webrtc::DataRate& a,
|
|
|
|
|
const webrtc::DataRate& b,
|
|
|
|
|
float rate) {
|
|
|
|
|
return a * (1.0 - rate) + b * rate;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-24 16:06:45 +02:00
|
|
|
constexpr char kUseLegacySimulcastLayerLimitFieldTrial[] =
|
|
|
|
|
"WebRTC-LegacySimulcastLayerLimit";
|
|
|
|
|
|
2018-08-09 16:12:54 +02:00
|
|
|
// Limits for legacy conference screensharing mode. Currently used for the
|
|
|
|
|
// lower of the two simulcast streams.
|
2020-02-12 16:45:53 +01:00
|
|
|
constexpr webrtc::DataRate kScreenshareDefaultTl0Bitrate =
|
2020-02-17 18:46:07 +01:00
|
|
|
webrtc::DataRate::KilobitsPerSec(200);
|
2020-02-12 16:45:53 +01:00
|
|
|
constexpr webrtc::DataRate kScreenshareDefaultTl1Bitrate =
|
2020-02-17 18:46:07 +01:00
|
|
|
webrtc::DataRate::KilobitsPerSec(1000);
|
2018-05-09 11:28:01 +02:00
|
|
|
|
2018-09-11 12:33:21 +02:00
|
|
|
// Min/max bitrate for the higher one of the two simulcast stream used for
|
|
|
|
|
// screen content.
|
2020-02-12 16:45:53 +01:00
|
|
|
constexpr webrtc::DataRate kScreenshareHighStreamMinBitrate =
|
2020-02-17 18:46:07 +01:00
|
|
|
webrtc::DataRate::KilobitsPerSec(600);
|
2020-02-12 16:45:53 +01:00
|
|
|
constexpr webrtc::DataRate kScreenshareHighStreamMaxBitrate =
|
2020-02-17 18:46:07 +01:00
|
|
|
webrtc::DataRate::KilobitsPerSec(1250);
|
2018-08-09 16:12:54 +02:00
|
|
|
|
2018-05-09 11:28:01 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
2014-12-10 09:01:18 +00:00
|
|
|
struct SimulcastFormat {
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
2019-07-24 16:06:45 +02:00
|
|
|
// The maximum number of simulcast layers can be used for
|
|
|
|
|
// resolutions at |widthxheigh| for legacy applications.
|
|
|
|
|
size_t max_layers;
|
2014-12-10 09:01:18 +00:00
|
|
|
// The maximum bitrate for encoding stream at |widthxheight|, when we are
|
|
|
|
|
// not sending the next higher spatial stream.
|
2020-02-12 16:45:53 +01:00
|
|
|
webrtc::DataRate max_bitrate;
|
2014-12-10 09:01:18 +00:00
|
|
|
// 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).
|
2020-02-12 16:45:53 +01:00
|
|
|
webrtc::DataRate target_bitrate;
|
2014-12-10 09:01:18 +00:00
|
|
|
// The minimum bitrate needed for encoding stream at |widthxheight|.
|
2020-02-12 16:45:53 +01:00
|
|
|
webrtc::DataRate min_bitrate;
|
2014-12-10 09:01:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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.
|
2020-02-12 16:45:53 +01:00
|
|
|
constexpr const SimulcastFormat kSimulcastFormats[] = {
|
2020-02-17 18:46:07 +01:00
|
|
|
{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)},
|
|
|
|
|
{0, 0, 1, webrtc::DataRate::KilobitsPerSec(200),
|
|
|
|
|
webrtc::DataRate::KilobitsPerSec(150),
|
|
|
|
|
webrtc::DataRate::KilobitsPerSec(30)}};
|
2014-12-10 09:01:18 +00:00
|
|
|
|
2018-02-07 08:50:36 -08:00
|
|
|
const int kMaxScreenshareSimulcastLayers = 2;
|
2017-01-26 06:12:26 -08:00
|
|
|
|
2018-05-15 09:54:14 +02:00
|
|
|
// Multiway: Number of temporal layers for each simulcast stream.
|
2018-08-21 13:15:28 +02:00
|
|
|
int DefaultNumberOfTemporalLayers(int simulcast_id, bool screenshare) {
|
2018-05-15 09:54:14 +02:00
|
|
|
RTC_CHECK_GE(simulcast_id, 0);
|
|
|
|
|
RTC_CHECK_LT(simulcast_id, webrtc::kMaxSimulcastStreams);
|
|
|
|
|
|
|
|
|
|
const int kDefaultNumTemporalLayers = 3;
|
2018-09-10 09:43:56 +02:00
|
|
|
const int kDefaultNumScreenshareTemporalLayers = 2;
|
|
|
|
|
int default_num_temporal_layers = screenshare
|
|
|
|
|
? kDefaultNumScreenshareTemporalLayers
|
|
|
|
|
: kDefaultNumTemporalLayers;
|
2018-05-15 09:54:14 +02:00
|
|
|
|
|
|
|
|
const std::string group_name =
|
2018-08-21 13:15:28 +02:00
|
|
|
screenshare ? webrtc::field_trial::FindFullName(
|
|
|
|
|
"WebRTC-VP8ScreenshareTemporalLayers")
|
|
|
|
|
: webrtc::field_trial::FindFullName(
|
|
|
|
|
"WebRTC-VP8ConferenceTemporalLayers");
|
2018-05-15 09:54:14 +02:00
|
|
|
if (group_name.empty())
|
2018-09-10 09:43:56 +02:00
|
|
|
return default_num_temporal_layers;
|
2018-05-15 09:54:14 +02:00
|
|
|
|
2018-09-10 09:43:56 +02:00
|
|
|
int num_temporal_layers = default_num_temporal_layers;
|
2018-05-15 09:54:14 +02:00
|
|
|
if (sscanf(group_name.c_str(), "%d", &num_temporal_layers) == 1 &&
|
|
|
|
|
num_temporal_layers > 0 &&
|
|
|
|
|
num_temporal_layers <= webrtc::kMaxTemporalStreams) {
|
|
|
|
|
return num_temporal_layers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTC_LOG(LS_WARNING) << "Attempt to set number of temporal layers to "
|
|
|
|
|
"incorrect value: "
|
|
|
|
|
<< group_name;
|
|
|
|
|
|
2018-09-10 09:43:56 +02:00
|
|
|
return default_num_temporal_layers;
|
2018-05-15 09:54:14 +02:00
|
|
|
}
|
2014-12-10 09:01:18 +00:00
|
|
|
|
|
|
|
|
int FindSimulcastFormatIndex(int width, int height) {
|
2018-01-09 11:14:14 -08:00
|
|
|
RTC_DCHECK_GE(width, 0);
|
|
|
|
|
RTC_DCHECK_GE(height, 0);
|
Move talk/media to webrtc/media
I removed the 'libjingle' target in talk/libjingle.gyp and replaced
all users of it with base/base.gyp:rtc_base. It seems the jsoncpp
and expat dependencies were not used by it's previous references.
The files in talk/media/testdata were uploaded to Google Storage and
added .sha1 files in resources/media instead of simply moving them.
The previously disabled warnings that were inherited from
talk/build/common.gypi are now replaced by target-specific disabling
of only the failing warnings. Additional disabling was needed since the stricter
compilation warnings that applies to code in webrtc/.
License headers will be updated in a follow-up CL in order to not
break Git history.
Other modifications:
* Updated the header guards.
* Sorted the includes using chromium/src/tools/sort-headers.py
except for these files:
talk/app/webrtc/peerconnectionendtoend_unittest.cc
talk/app/webrtc/java/jni/androidmediadecoder_jni.cc
talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
webrtc/media/devices/win32devicemanager.cc.
* Unused GYP reference to libjingle_tests_additional_deps was removed.
* Removed duplicated GYP entries of
webrtc/base/testutils.cc
webrtc/base/testutils.h
The HAVE_WEBRTC_VIDEO and HAVE_WEBRTC_VOICE defines were used by only talk/media,
so they were moved to the media.gyp.
I also checked that none of
EXPAT_RELATIVE_PATH,
FEATURE_ENABLE_VOICEMAIL,
GTEST_RELATIVE_PATH,
JSONCPP_RELATIVE_PATH,
LOGGING=1,
SRTP_RELATIVE_PATH,
FEATURE_ENABLE_SSL,
FEATURE_ENABLE_VOICEMAIL,
FEATURE_ENABLE_PSTN,
HAVE_SCTP,
HAVE_SRTP,
are used by the talk/media code.
For Chromium, the following changes will need to be applied to the roll CL that updates the
DEPS for WebRTC and libjingle: https://codereview.chromium.org/1604303002/
BUG=webrtc:5420
NOPRESUBMIT=True
TBR=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/1587193006
Cr-Commit-Position: refs/heads/master@{#11495}
2016-02-04 23:52:28 -08:00
|
|
|
for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) {
|
2017-01-26 06:12:26 -08:00
|
|
|
if (width * height >=
|
|
|
|
|
kSimulcastFormats[i].width * kSimulcastFormats[i].height) {
|
2014-12-10 09:01:18 +00:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-09 11:14:14 -08:00
|
|
|
RTC_NOTREACHED();
|
2014-12-10 09:01:18 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
// Round size to nearest simulcast-friendly size.
|
2014-12-10 09:01:18 +00:00
|
|
|
// Simulcast stream width and height must both be dividable by
|
2018-04-26 17:47:42 +02:00
|
|
|
// |2 ^ (simulcast_layers - 1)|.
|
2014-12-10 09:01:18 +00:00
|
|
|
int NormalizeSimulcastSize(int size, size_t simulcast_layers) {
|
2018-10-12 17:36:57 +02:00
|
|
|
int base2_exponent = static_cast<int>(simulcast_layers) - 1;
|
|
|
|
|
const absl::optional<int> experimental_base2_exponent =
|
|
|
|
|
webrtc::NormalizeSimulcastSizeExperiment::GetBase2Exponent();
|
|
|
|
|
if (experimental_base2_exponent &&
|
|
|
|
|
(size > (1 << *experimental_base2_exponent))) {
|
|
|
|
|
base2_exponent = *experimental_base2_exponent;
|
|
|
|
|
}
|
2014-12-10 09:01:18 +00:00
|
|
|
return ((size >> base2_exponent) << base2_exponent);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 14:53:29 +02:00
|
|
|
SimulcastFormat InterpolateSimulcastFormat(int width, int height) {
|
|
|
|
|
const int index = FindSimulcastFormatIndex(width, height);
|
|
|
|
|
if (index == 0)
|
|
|
|
|
return kSimulcastFormats[index];
|
|
|
|
|
const int total_pixels_up =
|
|
|
|
|
kSimulcastFormats[index - 1].width * kSimulcastFormats[index - 1].height;
|
|
|
|
|
const int total_pixels_down =
|
|
|
|
|
kSimulcastFormats[index].width * kSimulcastFormats[index].height;
|
|
|
|
|
const int total_pixels = width * height;
|
|
|
|
|
const float rate = (total_pixels_up - total_pixels) /
|
|
|
|
|
static_cast<float>(total_pixels_up - total_pixels_down);
|
2020-02-12 16:45:53 +01:00
|
|
|
|
|
|
|
|
size_t max_layers = kSimulcastFormats[index].max_layers;
|
|
|
|
|
webrtc::DataRate max_bitrate =
|
|
|
|
|
Interpolate(kSimulcastFormats[index - 1].max_bitrate,
|
|
|
|
|
kSimulcastFormats[index].max_bitrate, rate);
|
|
|
|
|
webrtc::DataRate target_bitrate =
|
|
|
|
|
Interpolate(kSimulcastFormats[index - 1].target_bitrate,
|
|
|
|
|
kSimulcastFormats[index].target_bitrate, rate);
|
|
|
|
|
webrtc::DataRate min_bitrate =
|
|
|
|
|
Interpolate(kSimulcastFormats[index - 1].min_bitrate,
|
|
|
|
|
kSimulcastFormats[index].min_bitrate, rate);
|
|
|
|
|
|
|
|
|
|
return {width, height, max_layers, max_bitrate, target_bitrate, min_bitrate};
|
2019-09-16 14:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
webrtc::DataRate FindSimulcastMaxBitrate(int width, int height) {
|
|
|
|
|
return InterpolateSimulcastFormat(width, height).max_bitrate;
|
2014-12-10 09:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
webrtc::DataRate FindSimulcastTargetBitrate(int width, int height) {
|
|
|
|
|
return InterpolateSimulcastFormat(width, height).target_bitrate;
|
2014-12-10 09:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
webrtc::DataRate FindSimulcastMinBitrate(int width, int height) {
|
|
|
|
|
return InterpolateSimulcastFormat(width, height).min_bitrate;
|
2014-12-10 09:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
void BoostMaxSimulcastLayer(webrtc::DataRate max_bitrate,
|
2018-02-07 08:50:36 -08:00
|
|
|
std::vector<webrtc::VideoStream>* layers) {
|
2018-06-18 17:51:32 +02:00
|
|
|
if (layers->empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
const webrtc::DataRate total_bitrate = GetTotalMaxBitrate(*layers);
|
|
|
|
|
|
|
|
|
|
// 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();
|
2018-02-07 08:50:36 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 16:45:53 +01:00
|
|
|
webrtc::DataRate GetTotalMaxBitrate(
|
|
|
|
|
const std::vector<webrtc::VideoStream>& layers) {
|
2018-06-18 17:51:32 +02:00
|
|
|
if (layers.empty())
|
2020-02-12 16:45:53 +01:00
|
|
|
return webrtc::DataRate::Zero();
|
2018-06-18 17:51:32 +02:00
|
|
|
|
2014-12-10 09:01:18 +00:00
|
|
|
int total_max_bitrate_bps = 0;
|
2018-02-07 08:50:36 -08:00
|
|
|
for (size_t s = 0; s < layers.size() - 1; ++s) {
|
|
|
|
|
total_max_bitrate_bps += layers[s].target_bitrate_bps;
|
2014-12-10 09:01:18 +00:00
|
|
|
}
|
2018-02-07 08:50:36 -08:00
|
|
|
total_max_bitrate_bps += layers.back().max_bitrate_bps;
|
2020-02-17 18:46:07 +01:00
|
|
|
return webrtc::DataRate::BitsPerSec(total_max_bitrate_bps);
|
2014-12-10 09:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-11 12:50:38 +01:00
|
|
|
size_t LimitSimulcastLayerCount(int width,
|
|
|
|
|
int height,
|
|
|
|
|
size_t need_layers,
|
|
|
|
|
size_t layer_count) {
|
2019-08-05 17:12:20 +02:00
|
|
|
if (!webrtc::field_trial::IsDisabled(
|
|
|
|
|
kUseLegacySimulcastLayerLimitFieldTrial)) {
|
2020-02-11 12:50:38 +01:00
|
|
|
size_t adaptive_layer_count = std::max(
|
|
|
|
|
need_layers,
|
|
|
|
|
kSimulcastFormats[FindSimulcastFormatIndex(width, height)].max_layers);
|
2019-07-24 16:06:45 +02:00
|
|
|
if (layer_count > adaptive_layer_count) {
|
|
|
|
|
RTC_LOG(LS_WARNING) << "Reducing simulcast layer count from "
|
|
|
|
|
<< layer_count << " to " << adaptive_layer_count;
|
|
|
|
|
layer_count = adaptive_layer_count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return layer_count;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 16:16:38 +02:00
|
|
|
std::vector<webrtc::VideoStream> GetSimulcastConfig(
|
2020-02-11 12:50:38 +01:00
|
|
|
size_t min_layers,
|
2018-06-21 16:16:38 +02:00
|
|
|
size_t max_layers,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
double bitrate_priority,
|
|
|
|
|
int max_qp,
|
2019-07-10 16:57:57 +02:00
|
|
|
bool is_screenshare_with_conference_mode,
|
2018-06-21 16:16:38 +02:00
|
|
|
bool temporal_layers_supported) {
|
2020-02-11 12:50:38 +01:00
|
|
|
RTC_DCHECK_LE(min_layers, max_layers);
|
2019-07-10 16:57:57 +02:00
|
|
|
RTC_DCHECK(max_layers > 1 || is_screenshare_with_conference_mode);
|
2019-07-24 16:06:45 +02:00
|
|
|
|
2019-10-30 13:01:46 +01:00
|
|
|
const bool base_heavy_tl3_rate_alloc =
|
|
|
|
|
webrtc::RateControlSettings::ParseFromFieldTrials()
|
|
|
|
|
.Vp8BaseHeavyTl3RateAllocation();
|
2019-07-10 16:57:57 +02:00
|
|
|
if (is_screenshare_with_conference_mode) {
|
2018-09-13 10:42:19 +02:00
|
|
|
return GetScreenshareLayers(max_layers, width, height, bitrate_priority,
|
2019-10-30 13:01:46 +01:00
|
|
|
max_qp, temporal_layers_supported,
|
|
|
|
|
base_heavy_tl3_rate_alloc);
|
2017-01-26 06:12:26 -08:00
|
|
|
} else {
|
2019-10-01 15:43:14 +02:00
|
|
|
// Some applications rely on the old behavior limiting the simulcast layer
|
|
|
|
|
// count based on the resolution automatically, which they can get through
|
|
|
|
|
// the WebRTC-LegacySimulcastLayerLimit field trial until they update.
|
2020-02-11 12:50:38 +01:00
|
|
|
max_layers =
|
|
|
|
|
LimitSimulcastLayerCount(width, height, min_layers, max_layers);
|
2019-10-01 15:43:14 +02:00
|
|
|
|
2018-06-18 17:51:32 +02:00
|
|
|
return GetNormalSimulcastLayers(max_layers, width, height, bitrate_priority,
|
2019-10-30 13:01:46 +01:00
|
|
|
max_qp, temporal_layers_supported,
|
|
|
|
|
base_heavy_tl3_rate_alloc);
|
2017-01-26 06:12:26 -08:00
|
|
|
}
|
2018-02-07 08:50:36 -08:00
|
|
|
}
|
2017-01-26 06:12:26 -08:00
|
|
|
|
2018-02-07 08:50:36 -08:00
|
|
|
std::vector<webrtc::VideoStream> GetNormalSimulcastLayers(
|
2019-07-04 17:06:04 +02:00
|
|
|
size_t layer_count,
|
2018-02-07 08:50:36 -08:00
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
double bitrate_priority,
|
|
|
|
|
int max_qp,
|
2019-10-30 13:01:46 +01:00
|
|
|
bool temporal_layers_supported,
|
|
|
|
|
bool base_heavy_tl3_rate_alloc) {
|
2019-07-04 17:06:04 +02:00
|
|
|
std::vector<webrtc::VideoStream> layers(layer_count);
|
2018-02-07 08:50:36 -08:00
|
|
|
|
|
|
|
|
// Format width and height has to be divisible by |2 ^ num_simulcast_layers -
|
|
|
|
|
// 1|.
|
2019-07-04 17:06:04 +02:00
|
|
|
width = NormalizeSimulcastSize(width, layer_count);
|
|
|
|
|
height = NormalizeSimulcastSize(height, layer_count);
|
2018-02-07 08:50:36 -08:00
|
|
|
// Add simulcast streams, from highest resolution (|s| = num_simulcast_layers
|
|
|
|
|
// -1) to lowest resolution at |s| = 0.
|
2019-07-04 17:06:04 +02:00
|
|
|
for (size_t s = layer_count - 1;; --s) {
|
2018-02-07 08:50:36 -08:00
|
|
|
layers[s].width = width;
|
|
|
|
|
layers[s].height = height;
|
|
|
|
|
// TODO(pbos): Fill actual temporal-layer bitrate thresholds.
|
|
|
|
|
layers[s].max_qp = max_qp;
|
2018-06-21 16:16:38 +02:00
|
|
|
layers[s].num_temporal_layers =
|
2020-01-21 13:54:11 +01:00
|
|
|
temporal_layers_supported ? DefaultNumberOfTemporalLayers(s, false) : 1;
|
2020-02-12 16:45:53 +01:00
|
|
|
layers[s].max_bitrate_bps = FindSimulcastMaxBitrate(width, height).bps();
|
|
|
|
|
layers[s].target_bitrate_bps =
|
|
|
|
|
FindSimulcastTargetBitrate(width, height).bps();
|
2018-08-21 13:15:28 +02:00
|
|
|
int num_temporal_layers = DefaultNumberOfTemporalLayers(s, false);
|
2018-07-06 17:17:10 +02:00
|
|
|
if (s == 0) {
|
2018-10-02 11:12:52 +02:00
|
|
|
// If alternative temporal rate allocation is selected, adjust the
|
2018-07-04 10:07:40 +02:00
|
|
|
// 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.
|
2018-07-06 17:17:10 +02:00
|
|
|
float rate_factor = 1.0;
|
|
|
|
|
if (num_temporal_layers == 3) {
|
2019-10-30 13:01:46 +01:00
|
|
|
if (base_heavy_tl3_rate_alloc) {
|
2018-10-02 11:12:52 +02:00
|
|
|
// Base heavy allocation increases TL0 bitrate from 40% to 60%.
|
2018-07-06 17:17:10 +02:00
|
|
|
rate_factor = 0.4 / 0.6;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rate_factor =
|
|
|
|
|
webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
|
2019-10-30 13:01:46 +01:00
|
|
|
3, 0, /*base_heavy_tl3_rate_alloc=*/false) /
|
|
|
|
|
webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
|
|
|
|
|
num_temporal_layers, 0, /*base_heavy_tl3_rate_alloc=*/false);
|
2018-07-06 17:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-18 09:39:55 +02:00
|
|
|
layers[s].max_bitrate_bps =
|
|
|
|
|
static_cast<int>(layers[s].max_bitrate_bps * rate_factor);
|
|
|
|
|
layers[s].target_bitrate_bps =
|
|
|
|
|
static_cast<int>(layers[s].target_bitrate_bps * rate_factor);
|
|
|
|
|
}
|
2020-02-12 16:45:53 +01:00
|
|
|
layers[s].min_bitrate_bps = FindSimulcastMinBitrate(width, height).bps();
|
2018-09-13 10:42:19 +02:00
|
|
|
layers[s].max_framerate = kDefaultVideoMaxFramerate;
|
2018-02-07 08:50:36 -08:00
|
|
|
|
|
|
|
|
width /= 2;
|
|
|
|
|
height /= 2;
|
|
|
|
|
|
|
|
|
|
if (s == 0) {
|
|
|
|
|
break;
|
2017-02-16 07:35:22 -08:00
|
|
|
}
|
2018-02-07 08:50:36 -08:00
|
|
|
}
|
|
|
|
|
// Currently the relative bitrate priority of the sender is controlled by
|
|
|
|
|
// the value of the lowest VideoStream.
|
|
|
|
|
// TODO(bugs.webrtc.org/8630): The web specification describes being able to
|
|
|
|
|
// control relative bitrate for each individual simulcast layer, but this
|
|
|
|
|
// is currently just implemented per rtp sender.
|
|
|
|
|
layers[0].bitrate_priority = bitrate_priority;
|
|
|
|
|
return layers;
|
|
|
|
|
}
|
2014-12-10 09:01:18 +00:00
|
|
|
|
2018-02-07 08:50:36 -08:00
|
|
|
std::vector<webrtc::VideoStream> GetScreenshareLayers(
|
|
|
|
|
size_t max_layers,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
double bitrate_priority,
|
|
|
|
|
int max_qp,
|
2019-10-30 13:01:46 +01:00
|
|
|
bool temporal_layers_supported,
|
|
|
|
|
bool base_heavy_tl3_rate_alloc) {
|
2019-07-10 16:57:57 +02:00
|
|
|
auto max_screenshare_layers = kMaxScreenshareSimulcastLayers;
|
2018-02-07 08:50:36 -08:00
|
|
|
size_t num_simulcast_layers =
|
2018-08-22 09:26:51 +02:00
|
|
|
std::min<int>(max_layers, max_screenshare_layers);
|
2018-02-07 08:50:36 -08:00
|
|
|
|
|
|
|
|
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,
|
2018-03-14 17:52:55 +01:00
|
|
|
// respectively. See eg. webrtc::LibvpxVp8Encoder::SetRates().
|
2018-02-07 08:50:36 -08:00
|
|
|
layers[0].width = width;
|
|
|
|
|
layers[0].height = height;
|
|
|
|
|
layers[0].max_qp = max_qp;
|
|
|
|
|
layers[0].max_framerate = 5;
|
2019-10-11 16:19:43 +02:00
|
|
|
layers[0].min_bitrate_bps = webrtc::kDefaultMinVideoBitrateBps;
|
2020-02-12 16:45:53 +01:00
|
|
|
layers[0].target_bitrate_bps = kScreenshareDefaultTl0Bitrate.bps();
|
|
|
|
|
layers[0].max_bitrate_bps = kScreenshareDefaultTl1Bitrate.bps();
|
2020-01-21 13:54:11 +01:00
|
|
|
layers[0].num_temporal_layers = temporal_layers_supported ? 2 : 1;
|
2018-02-07 08:50:36 -08:00
|
|
|
|
|
|
|
|
// 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 == kMaxScreenshareSimulcastLayers) {
|
|
|
|
|
// Add optional upper simulcast layer.
|
2018-08-21 13:15:28 +02:00
|
|
|
const int num_temporal_layers = DefaultNumberOfTemporalLayers(1, true);
|
2018-08-09 16:12:54 +02:00
|
|
|
int max_bitrate_bps;
|
2018-09-17 16:18:57 +02:00
|
|
|
bool using_boosted_bitrate = false;
|
2018-08-09 16:12:54 +02:00
|
|
|
if (!temporal_layers_supported) {
|
|
|
|
|
// Set the max bitrate to where the base layer would have been if temporal
|
2018-08-21 13:15:28 +02:00
|
|
|
// layers were enabled.
|
2018-08-09 16:12:54 +02:00
|
|
|
max_bitrate_bps = static_cast<int>(
|
2020-02-12 16:45:53 +01:00
|
|
|
kScreenshareHighStreamMaxBitrate.bps() *
|
2018-08-09 16:12:54 +02:00
|
|
|
webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
|
2019-10-30 13:01:46 +01:00
|
|
|
num_temporal_layers, 0, base_heavy_tl3_rate_alloc));
|
2018-08-21 13:15:28 +02:00
|
|
|
} else if (DefaultNumberOfTemporalLayers(1, true) != 3 ||
|
2019-10-30 13:01:46 +01:00
|
|
|
base_heavy_tl3_rate_alloc) {
|
2018-08-09 16:12:54 +02:00
|
|
|
// Experimental temporal layer mode used, use increased max bitrate.
|
2020-04-11 16:55:29 +02:00
|
|
|
max_bitrate_bps = kScreenshareHighStreamMaxBitrate.bps();
|
2018-09-17 16:18:57 +02:00
|
|
|
using_boosted_bitrate = true;
|
2018-08-09 16:12:54 +02:00
|
|
|
} else {
|
|
|
|
|
// Keep current bitrates with default 3tl/8 frame settings.
|
|
|
|
|
// Lowest temporal layers of a 3 layer setup will have 40% of the total
|
|
|
|
|
// bitrate allocation for that simulcast layer. Make sure the gap between
|
|
|
|
|
// the target of the lower simulcast layer and first temporal layer of the
|
|
|
|
|
// higher one is at most 2x the bitrate, so that upswitching is not
|
|
|
|
|
// hampered by stalled bitrate estimates.
|
|
|
|
|
max_bitrate_bps = 2 * ((layers[0].target_bitrate_bps * 10) / 4);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 08:50:36 -08:00
|
|
|
layers[1].width = width;
|
|
|
|
|
layers[1].height = height;
|
|
|
|
|
layers[1].max_qp = max_qp;
|
2018-09-13 10:42:19 +02:00
|
|
|
layers[1].max_framerate = kDefaultVideoMaxFramerate;
|
2018-08-09 16:12:54 +02:00
|
|
|
layers[1].num_temporal_layers =
|
2020-01-21 13:54:11 +01:00
|
|
|
temporal_layers_supported ? DefaultNumberOfTemporalLayers(1, true) : 1;
|
2018-09-17 16:18:57 +02:00
|
|
|
layers[1].min_bitrate_bps = using_boosted_bitrate
|
2020-02-12 16:45:53 +01:00
|
|
|
? kScreenshareHighStreamMinBitrate.bps()
|
2018-09-17 16:18:57 +02:00
|
|
|
: layers[0].target_bitrate_bps * 2;
|
|
|
|
|
|
|
|
|
|
// Cap max bitrate so it isn't overly high for the given resolution.
|
2020-02-12 16:45:53 +01:00
|
|
|
int resolution_limited_bitrate =
|
|
|
|
|
std::max<int>(FindSimulcastMaxBitrate(width, height).bps(),
|
|
|
|
|
layers[1].min_bitrate_bps);
|
2018-09-17 16:18:57 +02:00
|
|
|
max_bitrate_bps =
|
|
|
|
|
std::min<int>(max_bitrate_bps, resolution_limited_bitrate);
|
|
|
|
|
|
2018-02-07 08:50:36 -08:00
|
|
|
layers[1].target_bitrate_bps = max_bitrate_bps;
|
|
|
|
|
layers[1].max_bitrate_bps = max_bitrate_bps;
|
2014-12-10 09:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-22 09:36:42 -08:00
|
|
|
// The bitrate priority currently implemented on a per-sender level, so we
|
2018-02-07 08:50:36 -08:00
|
|
|
// just set it for the first simulcast layer.
|
|
|
|
|
layers[0].bitrate_priority = bitrate_priority;
|
|
|
|
|
return layers;
|
2014-12-10 09:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|