blob: daa63a667f5b6a49cd711357dfde76b3a89d91d9 [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ång661a0c62018-09-11 12:33:21 +020032// Min/max bitrate for the higher one of the two simulcast stream used for
33// screen content.
34constexpr int kScreenshareHighStreamMinBitrateBps = 600000;
Erik Språng58b22842018-08-21 13:15:28 +020035constexpr int kScreenshareHighStreamMaxBitrateBps = 1250000;
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +020036static const char* kSimulcastScreenshareFieldTrialName =
37 "WebRTC-SimulcastScreenshare";
Erik Språngb6b1cac2018-08-09 16:12:54 +020038
Rasmus Brandt195d1d72018-05-09 11:28:01 +020039} // namespace
40
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000041struct SimulcastFormat {
42 int width;
43 int height;
44 // The maximum number of simulcast layers can be used for
45 // resolutions at |widthxheigh|.
46 size_t max_layers;
47 // The maximum bitrate for encoding stream at |widthxheight|, when we are
48 // not sending the next higher spatial stream.
pbosbe16f792015-10-16 12:49:39 -070049 int max_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000050 // The target bitrate for encoding stream at |widthxheight|, when this layer
51 // is not the highest layer (i.e., when we are sending another higher spatial
52 // stream).
pbosbe16f792015-10-16 12:49:39 -070053 int target_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000054 // The minimum bitrate needed for encoding stream at |widthxheight|.
pbosbe16f792015-10-16 12:49:39 -070055 int min_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000056};
57
58// These tables describe from which resolution we can use how many
59// simulcast layers at what bitrates (maximum, target, and minimum).
60// Important!! Keep this table from high resolution to low resolution.
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020061// clang-format off
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000062const SimulcastFormat kSimulcastFormats[] = {
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020063 {1920, 1080, 3, 5000, 4000, 800},
64 {1280, 720, 3, 2500, 2500, 600},
65 {960, 540, 3, 900, 900, 450},
66 {640, 360, 2, 700, 500, 150},
67 {480, 270, 2, 450, 350, 150},
68 {320, 180, 1, 200, 150, 30},
69 {0, 0, 1, 200, 150, 30}
70};
71// clang-format on
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000072
Seth Hampson1370e302018-02-07 08:50:36 -080073const int kMaxScreenshareSimulcastLayers = 2;
sprang429600d2017-01-26 06:12:26 -080074
Erik Språngbfe3d852018-05-15 09:54:14 +020075// Multiway: Number of temporal layers for each simulcast stream.
Erik Språng58b22842018-08-21 13:15:28 +020076int DefaultNumberOfTemporalLayers(int simulcast_id, bool screenshare) {
Erik Språngbfe3d852018-05-15 09:54:14 +020077 RTC_CHECK_GE(simulcast_id, 0);
78 RTC_CHECK_LT(simulcast_id, webrtc::kMaxSimulcastStreams);
79
80 const int kDefaultNumTemporalLayers = 3;
Erik Språng7461eff2018-09-10 09:43:56 +020081 const int kDefaultNumScreenshareTemporalLayers = 2;
82 int default_num_temporal_layers = screenshare
83 ? kDefaultNumScreenshareTemporalLayers
84 : kDefaultNumTemporalLayers;
Erik Språngbfe3d852018-05-15 09:54:14 +020085
86 const std::string group_name =
Erik Språng58b22842018-08-21 13:15:28 +020087 screenshare ? webrtc::field_trial::FindFullName(
88 "WebRTC-VP8ScreenshareTemporalLayers")
89 : webrtc::field_trial::FindFullName(
90 "WebRTC-VP8ConferenceTemporalLayers");
Erik Språngbfe3d852018-05-15 09:54:14 +020091 if (group_name.empty())
Erik Språng7461eff2018-09-10 09:43:56 +020092 return default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +020093
Erik Språng7461eff2018-09-10 09:43:56 +020094 int num_temporal_layers = default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +020095 if (sscanf(group_name.c_str(), "%d", &num_temporal_layers) == 1 &&
96 num_temporal_layers > 0 &&
97 num_temporal_layers <= webrtc::kMaxTemporalStreams) {
98 return num_temporal_layers;
99 }
100
101 RTC_LOG(LS_WARNING) << "Attempt to set number of temporal layers to "
102 "incorrect value: "
103 << group_name;
104
Erik Språng7461eff2018-09-10 09:43:56 +0200105 return default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +0200106}
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000107
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000108int FindSimulcastFormatIndex(int width, int height) {
Seth Hampson438663e2018-01-09 11:14:14 -0800109 RTC_DCHECK_GE(width, 0);
110 RTC_DCHECK_GE(height, 0);
kjellandera96e2d72016-02-04 23:52:28 -0800111 for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) {
sprang429600d2017-01-26 06:12:26 -0800112 if (width * height >=
113 kSimulcastFormats[i].width * kSimulcastFormats[i].height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000114 return i;
115 }
116 }
Seth Hampson438663e2018-01-09 11:14:14 -0800117 RTC_NOTREACHED();
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000118 return -1;
119}
120
121int FindSimulcastFormatIndex(int width, int height, size_t max_layers) {
Seth Hampson438663e2018-01-09 11:14:14 -0800122 RTC_DCHECK_GE(width, 0);
123 RTC_DCHECK_GE(height, 0);
124 RTC_DCHECK_GT(max_layers, 0);
kjellandera96e2d72016-02-04 23:52:28 -0800125 for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) {
sprang429600d2017-01-26 06:12:26 -0800126 if (width * height >=
127 kSimulcastFormats[i].width * kSimulcastFormats[i].height &&
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000128 max_layers == kSimulcastFormats[i].max_layers) {
129 return i;
130 }
131 }
Seth Hampson438663e2018-01-09 11:14:14 -0800132 RTC_NOTREACHED();
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000133 return -1;
134}
135
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000136// Simulcast stream width and height must both be dividable by
Rasmus Brandtefbdcb02018-04-26 17:47:42 +0200137// |2 ^ (simulcast_layers - 1)|.
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000138int NormalizeSimulcastSize(int size, size_t simulcast_layers) {
139 const int base2_exponent = static_cast<int>(simulcast_layers) - 1;
140 return ((size >> base2_exponent) << base2_exponent);
141}
142
143size_t FindSimulcastMaxLayers(int width, int height) {
144 int index = FindSimulcastFormatIndex(width, height);
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000145 return kSimulcastFormats[index].max_layers;
146}
147
sprang429600d2017-01-26 06:12:26 -0800148int FindSimulcastMaxBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000149 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700150 return kSimulcastFormats[format_index].max_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000151}
152
sprang429600d2017-01-26 06:12:26 -0800153int FindSimulcastTargetBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000154 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700155 return kSimulcastFormats[format_index].target_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000156}
157
sprang429600d2017-01-26 06:12:26 -0800158int FindSimulcastMinBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000159 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700160 return kSimulcastFormats[format_index].min_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000161}
162
Seth Hampson438663e2018-01-09 11:14:14 -0800163void SlotSimulcastMaxResolution(size_t max_layers, int* width, int* height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000164 int index = FindSimulcastFormatIndex(*width, *height, max_layers);
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000165 *width = kSimulcastFormats[index].width;
166 *height = kSimulcastFormats[index].height;
Mirko Bonadei675513b2017-11-09 11:09:25 +0100167 RTC_LOG(LS_INFO) << "SlotSimulcastMaxResolution to width:" << *width
168 << " height:" << *height;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000169}
170
Seth Hampson1370e302018-02-07 08:50:36 -0800171void BoostMaxSimulcastLayer(int max_bitrate_bps,
172 std::vector<webrtc::VideoStream>* layers) {
Åsa Persson55659812018-06-18 17:51:32 +0200173 if (layers->empty())
174 return;
175
Seth Hampson1370e302018-02-07 08:50:36 -0800176 // Spend additional bits to boost the max layer.
177 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(*layers);
178 if (bitrate_left_bps > 0) {
179 layers->back().max_bitrate_bps += bitrate_left_bps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000180 }
Seth Hampson1370e302018-02-07 08:50:36 -0800181}
182
183int GetTotalMaxBitrateBps(const std::vector<webrtc::VideoStream>& layers) {
Åsa Persson55659812018-06-18 17:51:32 +0200184 if (layers.empty())
185 return 0;
186
Seth Hampson1370e302018-02-07 08:50:36 -0800187 int total_max_bitrate_bps = 0;
188 for (size_t s = 0; s < layers.size() - 1; ++s) {
189 total_max_bitrate_bps += layers[s].target_bitrate_bps;
190 }
191 total_max_bitrate_bps += layers.back().max_bitrate_bps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000192 return total_max_bitrate_bps;
193}
194
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200195std::vector<webrtc::VideoStream> GetSimulcastConfig(
196 size_t max_layers,
197 int width,
198 int height,
199 int /*max_bitrate_bps*/,
200 double bitrate_priority,
201 int max_qp,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000202 int max_framerate,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200203 bool is_screenshare,
204 bool temporal_layers_supported) {
Seth Hampson1370e302018-02-07 08:50:36 -0800205 if (is_screenshare) {
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200206 return GetScreenshareLayers(
207 max_layers, width, height, bitrate_priority, max_qp, max_framerate,
208 ScreenshareSimulcastFieldTrialEnabled(), temporal_layers_supported);
sprang429600d2017-01-26 06:12:26 -0800209 } else {
Åsa Persson55659812018-06-18 17:51:32 +0200210 return GetNormalSimulcastLayers(max_layers, width, height, bitrate_priority,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000211 max_qp, max_framerate,
212 temporal_layers_supported);
sprang429600d2017-01-26 06:12:26 -0800213 }
Seth Hampson1370e302018-02-07 08:50:36 -0800214}
sprang429600d2017-01-26 06:12:26 -0800215
Seth Hampson1370e302018-02-07 08:50:36 -0800216std::vector<webrtc::VideoStream> GetNormalSimulcastLayers(
217 size_t max_layers,
218 int width,
219 int height,
Seth Hampson1370e302018-02-07 08:50:36 -0800220 double bitrate_priority,
221 int max_qp,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000222 int max_framerate,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200223 bool temporal_layers_supported) {
Seth Hampson1370e302018-02-07 08:50:36 -0800224 // TODO(bugs.webrtc.org/8785): Currently if the resolution isn't large enough
225 // (defined in kSimulcastFormats) we scale down the number of simulcast
226 // layers. Consider changing this so that the application can have more
227 // control over exactly how many simulcast layers are used.
228 size_t num_simulcast_layers = FindSimulcastMaxLayers(width, height);
229 if (num_simulcast_layers > max_layers) {
230 // TODO(bugs.webrtc.org/8486): This scales down the resolution if the
231 // number of simulcast layers created by the application isn't sufficient
232 // (defined in kSimulcastFormats). For example if the input frame's
233 // resolution is HD, but there are only 2 simulcast layers, the
234 // resolution gets scaled down to VGA. Consider taking this logic out to
235 // allow the application more control over the resolutions.
236 SlotSimulcastMaxResolution(max_layers, &width, &height);
237 num_simulcast_layers = max_layers;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000238 }
Seth Hampson1370e302018-02-07 08:50:36 -0800239 std::vector<webrtc::VideoStream> layers(num_simulcast_layers);
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000240
Seth Hampson1370e302018-02-07 08:50:36 -0800241 // Format width and height has to be divisible by |2 ^ num_simulcast_layers -
242 // 1|.
243 width = NormalizeSimulcastSize(width, num_simulcast_layers);
244 height = NormalizeSimulcastSize(height, num_simulcast_layers);
245 // Add simulcast streams, from highest resolution (|s| = num_simulcast_layers
246 // -1) to lowest resolution at |s| = 0.
247 for (size_t s = num_simulcast_layers - 1;; --s) {
248 layers[s].width = width;
249 layers[s].height = height;
250 // TODO(pbos): Fill actual temporal-layer bitrate thresholds.
251 layers[s].max_qp = max_qp;
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200252 layers[s].num_temporal_layers =
Erik Språng58b22842018-08-21 13:15:28 +0200253 temporal_layers_supported ? DefaultNumberOfTemporalLayers(s, false) : 0;
Seth Hampson1370e302018-02-07 08:50:36 -0800254 layers[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height);
255 layers[s].target_bitrate_bps = FindSimulcastTargetBitrateBps(width, height);
Erik Språng58b22842018-08-21 13:15:28 +0200256 int num_temporal_layers = DefaultNumberOfTemporalLayers(s, false);
Erik Språngd497e6b2018-07-06 17:17:10 +0200257 if (s == 0) {
Erik Språng79478ad2018-05-18 09:39:55 +0200258 // If alternative number temporal layers is selected, adjust the
Erik Språngd92288f2018-07-04 10:07:40 +0200259 // bitrate of the lowest simulcast stream so that absolute bitrate for
260 // the base temporal layer matches the bitrate for the base temporal
261 // layer with the default 3 simulcast streams. Otherwise we risk a
262 // higher threshold for receiving a feed at all.
Erik Språngd497e6b2018-07-06 17:17:10 +0200263 float rate_factor = 1.0;
264 if (num_temporal_layers == 3) {
265 if (webrtc::field_trial::IsEnabled("WebRTC-UseShortVP8TL3Pattern")) {
266 // Shortened pattern increases TL0 bitrate from 40% to 60%.
267 rate_factor = 0.4 / 0.6;
268 }
269 } else {
270 rate_factor =
271 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(3, 0) /
272 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
273 num_temporal_layers, 0);
274 }
275
Erik Språng79478ad2018-05-18 09:39:55 +0200276 layers[s].max_bitrate_bps =
277 static_cast<int>(layers[s].max_bitrate_bps * rate_factor);
278 layers[s].target_bitrate_bps =
279 static_cast<int>(layers[s].target_bitrate_bps * rate_factor);
280 }
Seth Hampson1370e302018-02-07 08:50:36 -0800281 layers[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height);
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000282 layers[s].max_framerate = max_framerate;
sprang02569ad2017-07-06 05:05:50 -0700283
Seth Hampson1370e302018-02-07 08:50:36 -0800284 width /= 2;
285 height /= 2;
sprang02569ad2017-07-06 05:05:50 -0700286
Seth Hampson1370e302018-02-07 08:50:36 -0800287 if (s == 0) {
288 break;
sprang02569ad2017-07-06 05:05:50 -0700289 }
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000290 }
Seth Hampson1370e302018-02-07 08:50:36 -0800291 // Currently the relative bitrate priority of the sender is controlled by
292 // the value of the lowest VideoStream.
293 // TODO(bugs.webrtc.org/8630): The web specification describes being able to
294 // control relative bitrate for each individual simulcast layer, but this
295 // is currently just implemented per rtp sender.
296 layers[0].bitrate_priority = bitrate_priority;
297 return layers;
298}
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000299
Seth Hampson1370e302018-02-07 08:50:36 -0800300std::vector<webrtc::VideoStream> GetScreenshareLayers(
301 size_t max_layers,
302 int width,
303 int height,
Seth Hampson1370e302018-02-07 08:50:36 -0800304 double bitrate_priority,
305 int max_qp,
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000306 int max_framerate,
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200307 bool screenshare_simulcast_enabled,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200308 bool temporal_layers_supported) {
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200309 auto max_screenshare_layers =
310 screenshare_simulcast_enabled ? kMaxScreenshareSimulcastLayers : 1;
Seth Hampson1370e302018-02-07 08:50:36 -0800311 size_t num_simulcast_layers =
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200312 std::min<int>(max_layers, max_screenshare_layers);
Seth Hampson1370e302018-02-07 08:50:36 -0800313
314 std::vector<webrtc::VideoStream> layers(num_simulcast_layers);
Seth Hampson1370e302018-02-07 08:50:36 -0800315 // For legacy screenshare in conference mode, tl0 and tl1 bitrates are
316 // piggybacked on the VideoCodec struct as target and max bitrates,
Erik Språngcc681cc2018-03-14 17:52:55 +0100317 // respectively. See eg. webrtc::LibvpxVp8Encoder::SetRates().
Seth Hampson1370e302018-02-07 08:50:36 -0800318 layers[0].width = width;
319 layers[0].height = height;
320 layers[0].max_qp = max_qp;
321 layers[0].max_framerate = 5;
322 layers[0].min_bitrate_bps = kMinVideoBitrateBps;
Rasmus Brandt195d1d72018-05-09 11:28:01 +0200323 layers[0].target_bitrate_bps = kScreenshareDefaultTl0BitrateKbps * 1000;
324 layers[0].max_bitrate_bps = kScreenshareDefaultTl1BitrateKbps * 1000;
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200325 layers[0].num_temporal_layers = temporal_layers_supported ? 2 : 0;
Seth Hampson1370e302018-02-07 08:50:36 -0800326
327 // With simulcast enabled, add another spatial layer. This one will have a
328 // more normal layout, with the regular 3 temporal layer pattern and no fps
329 // restrictions. The base simulcast layer will still use legacy setup.
330 if (num_simulcast_layers == kMaxScreenshareSimulcastLayers) {
331 // Add optional upper simulcast layer.
Erik Språng58b22842018-08-21 13:15:28 +0200332 const int num_temporal_layers = DefaultNumberOfTemporalLayers(1, true);
Erik Språngb6b1cac2018-08-09 16:12:54 +0200333 int max_bitrate_bps;
334 if (!temporal_layers_supported) {
335 // Set the max bitrate to where the base layer would have been if temporal
Erik Språng58b22842018-08-21 13:15:28 +0200336 // layers were enabled.
Erik Språngb6b1cac2018-08-09 16:12:54 +0200337 max_bitrate_bps = static_cast<int>(
338 kScreenshareHighStreamMaxBitrateBps *
339 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
340 num_temporal_layers, 0));
Erik Språng58b22842018-08-21 13:15:28 +0200341 } else if (DefaultNumberOfTemporalLayers(1, true) != 3 ||
Erik Språngb6b1cac2018-08-09 16:12:54 +0200342 webrtc::field_trial::IsEnabled("WebRTC-UseShortVP8TL3Pattern")) {
343 // Experimental temporal layer mode used, use increased max bitrate.
344 max_bitrate_bps = kScreenshareHighStreamMaxBitrateBps;
345 } else {
346 // Keep current bitrates with default 3tl/8 frame settings.
347 // Lowest temporal layers of a 3 layer setup will have 40% of the total
348 // bitrate allocation for that simulcast layer. Make sure the gap between
349 // the target of the lower simulcast layer and first temporal layer of the
350 // higher one is at most 2x the bitrate, so that upswitching is not
351 // hampered by stalled bitrate estimates.
352 max_bitrate_bps = 2 * ((layers[0].target_bitrate_bps * 10) / 4);
353 }
354
Seth Hampson1370e302018-02-07 08:50:36 -0800355 // Cap max bitrate so it isn't overly high for the given resolution.
356 max_bitrate_bps = std::min<int>(max_bitrate_bps,
357 FindSimulcastMaxBitrateBps(width, height));
Seth Hampson1370e302018-02-07 08:50:36 -0800358 layers[1].width = width;
359 layers[1].height = height;
360 layers[1].max_qp = max_qp;
Mirko Bonadei948b7e32018-08-14 07:23:21 +0000361 layers[1].max_framerate = max_framerate;
Erik Språngb6b1cac2018-08-09 16:12:54 +0200362 layers[1].num_temporal_layers =
Erik Språng58b22842018-08-21 13:15:28 +0200363 temporal_layers_supported ? DefaultNumberOfTemporalLayers(1, true) : 0;
Erik Språng661a0c62018-09-11 12:33:21 +0200364 layers[1].min_bitrate_bps =
365 max_bitrate_bps == kScreenshareHighStreamMaxBitrateBps
366 ? kScreenshareHighStreamMinBitrateBps
367 : layers[0].target_bitrate_bps * 2;
Seth Hampson1370e302018-02-07 08:50:36 -0800368 layers[1].target_bitrate_bps = max_bitrate_bps;
369 layers[1].max_bitrate_bps = max_bitrate_bps;
370 }
371
Seth Hampson24722b32017-12-22 09:36:42 -0800372 // The bitrate priority currently implemented on a per-sender level, so we
Seth Hampson1370e302018-02-07 08:50:36 -0800373 // just set it for the first simulcast layer.
374 layers[0].bitrate_priority = bitrate_priority;
375 return layers;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000376}
377
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200378bool ScreenshareSimulcastFieldTrialEnabled() {
379 return !webrtc::field_trial::IsDisabled(kSimulcastScreenshareFieldTrialName);
380}
381
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000382} // namespace cricket