blob: f818588ea73e20d5827f964e67842076b9b40b29 [file] [log] [blame]
buildbot@webrtc.orga8530772014-12-10 09:01:18 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
buildbot@webrtc.orga8530772014-12-10 09:01:18 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
buildbot@webrtc.orga8530772014-12-10 09:01:18 +00009 */
10
sprang@webrtc.org46d4d292014-12-23 15:19:35 +000011#include <stdio.h>
Steve Antone78bcb92017-10-31 09:53:08 -070012#include <algorithm>
13#include <string>
sprang@webrtc.org46d4d292014-12-23 15:19:35 +000014
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "media/base/streamparams.h"
16#include "media/engine/constants.h"
17#include "media/engine/simulcast.h"
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020018#include "modules/video_coding/utility/simulcast_rate_allocator.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/arraysize.h"
20#include "rtc_base/logging.h"
21#include "system_wrappers/include/field_trial.h"
tfarina5237aaf2015-11-10 23:44:30 -080022
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000023namespace cricket {
24
Rasmus Brandt195d1d72018-05-09 11:28:01 +020025namespace {
26
Erik Språngb6b1cac2018-08-09 16:12:54 +020027// Limits for legacy conference screensharing mode. Currently used for the
28// lower of the two simulcast streams.
Rasmus Brandt195d1d72018-05-09 11:28:01 +020029constexpr int kScreenshareDefaultTl0BitrateKbps = 200;
30constexpr int kScreenshareDefaultTl1BitrateKbps = 1000;
31
Erik Språngb6b1cac2018-08-09 16:12:54 +020032// Max bitrate for the higher one of the two simulcast stream used for screen
33// content.
Erik Språng58b22842018-08-21 13:15:28 +020034constexpr int kScreenshareHighStreamMaxBitrateBps = 1250000;
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +020035static const char* kSimulcastScreenshareFieldTrialName =
36 "WebRTC-SimulcastScreenshare";
Erik Språngb6b1cac2018-08-09 16:12:54 +020037
Rasmus Brandt195d1d72018-05-09 11:28:01 +020038} // namespace
39
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000040struct SimulcastFormat {
41 int width;
42 int height;
43 // The maximum number of simulcast layers can be used for
44 // resolutions at |widthxheigh|.
45 size_t max_layers;
46 // The maximum bitrate for encoding stream at |widthxheight|, when we are
47 // not sending the next higher spatial stream.
pbosbe16f792015-10-16 12:49:39 -070048 int max_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000049 // The target bitrate for encoding stream at |widthxheight|, when this layer
50 // is not the highest layer (i.e., when we are sending another higher spatial
51 // stream).
pbosbe16f792015-10-16 12:49:39 -070052 int target_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000053 // The minimum bitrate needed for encoding stream at |widthxheight|.
pbosbe16f792015-10-16 12:49:39 -070054 int min_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000055};
56
57// These tables describe from which resolution we can use how many
58// simulcast layers at what bitrates (maximum, target, and minimum).
59// Important!! Keep this table from high resolution to low resolution.
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020060// clang-format off
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000061const SimulcastFormat kSimulcastFormats[] = {
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020062 {1920, 1080, 3, 5000, 4000, 800},
63 {1280, 720, 3, 2500, 2500, 600},
64 {960, 540, 3, 900, 900, 450},
65 {640, 360, 2, 700, 500, 150},
66 {480, 270, 2, 450, 350, 150},
67 {320, 180, 1, 200, 150, 30},
68 {0, 0, 1, 200, 150, 30}
69};
70// clang-format on
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000071
Seth Hampson1370e302018-02-07 08:50:36 -080072const int kMaxScreenshareSimulcastLayers = 2;
sprang429600d2017-01-26 06:12:26 -080073
Erik Språngbfe3d852018-05-15 09:54:14 +020074// Multiway: Number of temporal layers for each simulcast stream.
Erik Språng58b22842018-08-21 13:15:28 +020075int DefaultNumberOfTemporalLayers(int simulcast_id, bool screenshare) {
Erik Språngbfe3d852018-05-15 09:54:14 +020076 RTC_CHECK_GE(simulcast_id, 0);
77 RTC_CHECK_LT(simulcast_id, webrtc::kMaxSimulcastStreams);
78
79 const int kDefaultNumTemporalLayers = 3;
Erik Språng7461eff2018-09-10 09:43:56 +020080 const int kDefaultNumScreenshareTemporalLayers = 2;
81 int default_num_temporal_layers = screenshare
82 ? kDefaultNumScreenshareTemporalLayers
83 : kDefaultNumTemporalLayers;
Erik Språngbfe3d852018-05-15 09:54:14 +020084
85 const std::string group_name =
Erik Språng58b22842018-08-21 13:15:28 +020086 screenshare ? webrtc::field_trial::FindFullName(
87 "WebRTC-VP8ScreenshareTemporalLayers")
88 : webrtc::field_trial::FindFullName(
89 "WebRTC-VP8ConferenceTemporalLayers");
Erik Språngbfe3d852018-05-15 09:54:14 +020090 if (group_name.empty())
Erik Språng7461eff2018-09-10 09:43:56 +020091 return default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +020092
Erik Språng7461eff2018-09-10 09:43:56 +020093 int num_temporal_layers = default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +020094 if (sscanf(group_name.c_str(), "%d", &num_temporal_layers) == 1 &&
95 num_temporal_layers > 0 &&
96 num_temporal_layers <= webrtc::kMaxTemporalStreams) {
97 return num_temporal_layers;
98 }
99
100 RTC_LOG(LS_WARNING) << "Attempt to set number of temporal layers to "
101 "incorrect value: "
102 << group_name;
103
Erik Språng7461eff2018-09-10 09:43:56 +0200104 return default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +0200105}
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000106
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000107int FindSimulcastFormatIndex(int width, int height) {
Seth Hampson438663e2018-01-09 11:14:14 -0800108 RTC_DCHECK_GE(width, 0);
109 RTC_DCHECK_GE(height, 0);
kjellandera96e2d72016-02-04 23:52:28 -0800110 for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) {
sprang429600d2017-01-26 06:12:26 -0800111 if (width * height >=
112 kSimulcastFormats[i].width * kSimulcastFormats[i].height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000113 return i;
114 }
115 }
Seth Hampson438663e2018-01-09 11:14:14 -0800116 RTC_NOTREACHED();
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000117 return -1;
118}
119
120int FindSimulcastFormatIndex(int width, int height, size_t max_layers) {
Seth Hampson438663e2018-01-09 11:14:14 -0800121 RTC_DCHECK_GE(width, 0);
122 RTC_DCHECK_GE(height, 0);
123 RTC_DCHECK_GT(max_layers, 0);
kjellandera96e2d72016-02-04 23:52:28 -0800124 for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) {
sprang429600d2017-01-26 06:12:26 -0800125 if (width * height >=
126 kSimulcastFormats[i].width * kSimulcastFormats[i].height &&
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000127 max_layers == kSimulcastFormats[i].max_layers) {
128 return i;
129 }
130 }
Seth Hampson438663e2018-01-09 11:14:14 -0800131 RTC_NOTREACHED();
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000132 return -1;
133}
134
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000135// Simulcast stream width and height must both be dividable by
Rasmus Brandtefbdcb02018-04-26 17:47:42 +0200136// |2 ^ (simulcast_layers - 1)|.
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000137int NormalizeSimulcastSize(int size, size_t simulcast_layers) {
138 const int base2_exponent = static_cast<int>(simulcast_layers) - 1;
139 return ((size >> base2_exponent) << base2_exponent);
140}
141
142size_t FindSimulcastMaxLayers(int width, int height) {
143 int index = FindSimulcastFormatIndex(width, height);
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000144 return kSimulcastFormats[index].max_layers;
145}
146
sprang429600d2017-01-26 06:12:26 -0800147int FindSimulcastMaxBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000148 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700149 return kSimulcastFormats[format_index].max_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000150}
151
sprang429600d2017-01-26 06:12:26 -0800152int FindSimulcastTargetBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000153 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700154 return kSimulcastFormats[format_index].target_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000155}
156
sprang429600d2017-01-26 06:12:26 -0800157int FindSimulcastMinBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000158 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700159 return kSimulcastFormats[format_index].min_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000160}
161
Seth Hampson438663e2018-01-09 11:14:14 -0800162void SlotSimulcastMaxResolution(size_t max_layers, int* width, int* height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000163 int index = FindSimulcastFormatIndex(*width, *height, max_layers);
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000164 *width = kSimulcastFormats[index].width;
165 *height = kSimulcastFormats[index].height;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100166 RTC_LOG(LS_INFO) << "SlotSimulcastMaxResolution to width:" << *width
167 << " height:" << *height;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000168}
169
Seth Hampson1370e302018-02-07 08:50:36 -0800170void BoostMaxSimulcastLayer(int max_bitrate_bps,
171 std::vector<webrtc::VideoStream>* layers) {
Åsa Persson55659812018-06-18 17:51:32 +0200172 if (layers->empty())
173 return;
174
Seth Hampson1370e302018-02-07 08:50:36 -0800175 // Spend additional bits to boost the max layer.
176 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(*layers);
177 if (bitrate_left_bps > 0) {
178 layers->back().max_bitrate_bps += bitrate_left_bps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000179 }
Seth Hampson1370e302018-02-07 08:50:36 -0800180}
181
182int GetTotalMaxBitrateBps(const std::vector<webrtc::VideoStream>& layers) {
Åsa Persson55659812018-06-18 17:51:32 +0200183 if (layers.empty())
184 return 0;
185
Seth Hampson1370e302018-02-07 08:50:36 -0800186 int total_max_bitrate_bps = 0;
187 for (size_t s = 0; s < layers.size() - 1; ++s) {
188 total_max_bitrate_bps += layers[s].target_bitrate_bps;
189 }
190 total_max_bitrate_bps += layers.back().max_bitrate_bps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000191 return total_max_bitrate_bps;
192}
193
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200194std::vector<webrtc::VideoStream> GetSimulcastConfig(
195 size_t max_layers,
196 int width,
197 int height,
198 int /*max_bitrate_bps*/,
199 double bitrate_priority,
200 int max_qp,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000201 int max_framerate,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200202 bool is_screenshare,
203 bool temporal_layers_supported) {
Seth Hampson1370e302018-02-07 08:50:36 -0800204 if (is_screenshare) {
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200205 return GetScreenshareLayers(
206 max_layers, width, height, bitrate_priority, max_qp, max_framerate,
207 ScreenshareSimulcastFieldTrialEnabled(), temporal_layers_supported);
sprang429600d2017-01-26 06:12:26 -0800208 } else {
Åsa Persson55659812018-06-18 17:51:32 +0200209 return GetNormalSimulcastLayers(max_layers, width, height, bitrate_priority,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000210 max_qp, max_framerate,
211 temporal_layers_supported);
sprang429600d2017-01-26 06:12:26 -0800212 }
Seth Hampson1370e302018-02-07 08:50:36 -0800213}
sprang429600d2017-01-26 06:12:26 -0800214
Seth Hampson1370e302018-02-07 08:50:36 -0800215std::vector<webrtc::VideoStream> GetNormalSimulcastLayers(
216 size_t max_layers,
217 int width,
218 int height,
Seth Hampson1370e302018-02-07 08:50:36 -0800219 double bitrate_priority,
220 int max_qp,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000221 int max_framerate,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200222 bool temporal_layers_supported) {
Seth Hampson1370e302018-02-07 08:50:36 -0800223 // TODO(bugs.webrtc.org/8785): Currently if the resolution isn't large enough
224 // (defined in kSimulcastFormats) we scale down the number of simulcast
225 // layers. Consider changing this so that the application can have more
226 // control over exactly how many simulcast layers are used.
227 size_t num_simulcast_layers = FindSimulcastMaxLayers(width, height);
228 if (num_simulcast_layers > max_layers) {
229 // TODO(bugs.webrtc.org/8486): This scales down the resolution if the
230 // number of simulcast layers created by the application isn't sufficient
231 // (defined in kSimulcastFormats). For example if the input frame's
232 // resolution is HD, but there are only 2 simulcast layers, the
233 // resolution gets scaled down to VGA. Consider taking this logic out to
234 // allow the application more control over the resolutions.
235 SlotSimulcastMaxResolution(max_layers, &width, &height);
236 num_simulcast_layers = max_layers;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000237 }
Seth Hampson1370e302018-02-07 08:50:36 -0800238 std::vector<webrtc::VideoStream> layers(num_simulcast_layers);
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000239
Seth Hampson1370e302018-02-07 08:50:36 -0800240 // Format width and height has to be divisible by |2 ^ num_simulcast_layers -
241 // 1|.
242 width = NormalizeSimulcastSize(width, num_simulcast_layers);
243 height = NormalizeSimulcastSize(height, num_simulcast_layers);
244 // Add simulcast streams, from highest resolution (|s| = num_simulcast_layers
245 // -1) to lowest resolution at |s| = 0.
246 for (size_t s = num_simulcast_layers - 1;; --s) {
247 layers[s].width = width;
248 layers[s].height = height;
249 // TODO(pbos): Fill actual temporal-layer bitrate thresholds.
250 layers[s].max_qp = max_qp;
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200251 layers[s].num_temporal_layers =
Erik Språng58b22842018-08-21 13:15:28 +0200252 temporal_layers_supported ? DefaultNumberOfTemporalLayers(s, false) : 0;
Seth Hampson1370e302018-02-07 08:50:36 -0800253 layers[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height);
254 layers[s].target_bitrate_bps = FindSimulcastTargetBitrateBps(width, height);
Erik Språng58b22842018-08-21 13:15:28 +0200255 int num_temporal_layers = DefaultNumberOfTemporalLayers(s, false);
Erik Språngd497e6b2018-07-06 17:17:10 +0200256 if (s == 0) {
Erik Språng79478ad2018-05-18 09:39:55 +0200257 // If alternative number temporal layers is selected, adjust the
Erik Språngd92288f2018-07-04 10:07:40 +0200258 // bitrate of the lowest simulcast stream so that absolute bitrate for
259 // the base temporal layer matches the bitrate for the base temporal
260 // layer with the default 3 simulcast streams. Otherwise we risk a
261 // higher threshold for receiving a feed at all.
Erik Språngd497e6b2018-07-06 17:17:10 +0200262 float rate_factor = 1.0;
263 if (num_temporal_layers == 3) {
264 if (webrtc::field_trial::IsEnabled("WebRTC-UseShortVP8TL3Pattern")) {
265 // Shortened pattern increases TL0 bitrate from 40% to 60%.
266 rate_factor = 0.4 / 0.6;
267 }
268 } else {
269 rate_factor =
270 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(3, 0) /
271 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
272 num_temporal_layers, 0);
273 }
274
Erik Språng79478ad2018-05-18 09:39:55 +0200275 layers[s].max_bitrate_bps =
276 static_cast<int>(layers[s].max_bitrate_bps * rate_factor);
277 layers[s].target_bitrate_bps =
278 static_cast<int>(layers[s].target_bitrate_bps * rate_factor);
279 }
Seth Hampson1370e302018-02-07 08:50:36 -0800280 layers[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height);
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000281 layers[s].max_framerate = max_framerate;
sprang02569ad2017-07-06 05:05:50 -0700282
Seth Hampson1370e302018-02-07 08:50:36 -0800283 width /= 2;
284 height /= 2;
sprang02569ad2017-07-06 05:05:50 -0700285
Seth Hampson1370e302018-02-07 08:50:36 -0800286 if (s == 0) {
287 break;
sprang02569ad2017-07-06 05:05:50 -0700288 }
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000289 }
Seth Hampson1370e302018-02-07 08:50:36 -0800290 // Currently the relative bitrate priority of the sender is controlled by
291 // the value of the lowest VideoStream.
292 // TODO(bugs.webrtc.org/8630): The web specification describes being able to
293 // control relative bitrate for each individual simulcast layer, but this
294 // is currently just implemented per rtp sender.
295 layers[0].bitrate_priority = bitrate_priority;
296 return layers;
297}
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000298
Seth Hampson1370e302018-02-07 08:50:36 -0800299std::vector<webrtc::VideoStream> GetScreenshareLayers(
300 size_t max_layers,
301 int width,
302 int height,
Seth Hampson1370e302018-02-07 08:50:36 -0800303 double bitrate_priority,
304 int max_qp,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000305 int max_framerate,
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200306 bool screenshare_simulcast_enabled,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200307 bool temporal_layers_supported) {
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200308 auto max_screenshare_layers =
309 screenshare_simulcast_enabled ? kMaxScreenshareSimulcastLayers : 1;
Seth Hampson1370e302018-02-07 08:50:36 -0800310 size_t num_simulcast_layers =
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200311 std::min<int>(max_layers, max_screenshare_layers);
Seth Hampson1370e302018-02-07 08:50:36 -0800312
313 std::vector<webrtc::VideoStream> layers(num_simulcast_layers);
Seth Hampson1370e302018-02-07 08:50:36 -0800314 // For legacy screenshare in conference mode, tl0 and tl1 bitrates are
315 // piggybacked on the VideoCodec struct as target and max bitrates,
Erik Språngcc681cc2018-03-14 17:52:55 +0100316 // respectively. See eg. webrtc::LibvpxVp8Encoder::SetRates().
Seth Hampson1370e302018-02-07 08:50:36 -0800317 layers[0].width = width;
318 layers[0].height = height;
319 layers[0].max_qp = max_qp;
320 layers[0].max_framerate = 5;
321 layers[0].min_bitrate_bps = kMinVideoBitrateBps;
Rasmus Brandt195d1d72018-05-09 11:28:01 +0200322 layers[0].target_bitrate_bps = kScreenshareDefaultTl0BitrateKbps * 1000;
323 layers[0].max_bitrate_bps = kScreenshareDefaultTl1BitrateKbps * 1000;
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200324 layers[0].num_temporal_layers = temporal_layers_supported ? 2 : 0;
Seth Hampson1370e302018-02-07 08:50:36 -0800325
326 // With simulcast enabled, add another spatial layer. This one will have a
327 // more normal layout, with the regular 3 temporal layer pattern and no fps
328 // restrictions. The base simulcast layer will still use legacy setup.
329 if (num_simulcast_layers == kMaxScreenshareSimulcastLayers) {
330 // Add optional upper simulcast layer.
Erik Språng58b22842018-08-21 13:15:28 +0200331 const int num_temporal_layers = DefaultNumberOfTemporalLayers(1, true);
Erik Språngb6b1cac2018-08-09 16:12:54 +0200332 int max_bitrate_bps;
333 if (!temporal_layers_supported) {
334 // Set the max bitrate to where the base layer would have been if temporal
Erik Språng58b22842018-08-21 13:15:28 +0200335 // layers were enabled.
Erik Språngb6b1cac2018-08-09 16:12:54 +0200336 max_bitrate_bps = static_cast<int>(
337 kScreenshareHighStreamMaxBitrateBps *
338 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
339 num_temporal_layers, 0));
Erik Språng58b22842018-08-21 13:15:28 +0200340 } else if (DefaultNumberOfTemporalLayers(1, true) != 3 ||
Erik Språngb6b1cac2018-08-09 16:12:54 +0200341 webrtc::field_trial::IsEnabled("WebRTC-UseShortVP8TL3Pattern")) {
342 // Experimental temporal layer mode used, use increased max bitrate.
343 max_bitrate_bps = kScreenshareHighStreamMaxBitrateBps;
344 } else {
345 // Keep current bitrates with default 3tl/8 frame settings.
346 // Lowest temporal layers of a 3 layer setup will have 40% of the total
347 // bitrate allocation for that simulcast layer. Make sure the gap between
348 // the target of the lower simulcast layer and first temporal layer of the
349 // higher one is at most 2x the bitrate, so that upswitching is not
350 // hampered by stalled bitrate estimates.
351 max_bitrate_bps = 2 * ((layers[0].target_bitrate_bps * 10) / 4);
352 }
353
Seth Hampson1370e302018-02-07 08:50:36 -0800354 // Cap max bitrate so it isn't overly high for the given resolution.
355 max_bitrate_bps = std::min<int>(max_bitrate_bps,
356 FindSimulcastMaxBitrateBps(width, height));
Seth Hampson1370e302018-02-07 08:50:36 -0800357 layers[1].width = width;
358 layers[1].height = height;
359 layers[1].max_qp = max_qp;
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000360 layers[1].max_framerate = max_framerate;
Erik Språngb6b1cac2018-08-09 16:12:54 +0200361 layers[1].num_temporal_layers =
Erik Språng58b22842018-08-21 13:15:28 +0200362 temporal_layers_supported ? DefaultNumberOfTemporalLayers(1, true) : 0;
Seth Hampson1370e302018-02-07 08:50:36 -0800363 layers[1].min_bitrate_bps = layers[0].target_bitrate_bps * 2;
364 layers[1].target_bitrate_bps = max_bitrate_bps;
365 layers[1].max_bitrate_bps = max_bitrate_bps;
366 }
367
Seth Hampson24722b32017-12-22 09:36:42 -0800368 // The bitrate priority currently implemented on a per-sender level, so we
Seth Hampson1370e302018-02-07 08:50:36 -0800369 // just set it for the first simulcast layer.
370 layers[0].bitrate_priority = bitrate_priority;
371 return layers;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000372}
373
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200374bool ScreenshareSimulcastFieldTrialEnabled() {
375 return !webrtc::field_trial::IsDisabled(kSimulcastScreenshareFieldTrialName);
376}
377
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000378} // namespace cricket