blob: afcd162f1276ad5751ebe34bea15c6a33a7960f9 [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
Jonas Olssona4d87372019-07-05 19:08:33 +020011#include "media/engine/simulcast.h"
12
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <stdint.h>
sprang@webrtc.org46d4d292014-12-23 15:19:35 +000014#include <stdio.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Steve Antone78bcb92017-10-31 09:53:08 -070016#include <algorithm>
17#include <string>
sprang@webrtc.org46d4d292014-12-23 15:19:35 +000018
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "absl/types/optional.h"
Erik Språngf93eda12019-01-16 17:10:57 +010020#include "api/video/video_codec_constants.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "media/base/media_constants.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "media/engine/constants.h"
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020023#include "modules/video_coding/utility/simulcast_rate_allocator.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/arraysize.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "rtc_base/checks.h"
Åsa Persson1a35fbd2018-10-12 17:36:57 +020026#include "rtc_base/experiments/normalize_simulcast_size_experiment.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "rtc_base/logging.h"
28#include "system_wrappers/include/field_trial.h"
tfarina5237aaf2015-11-10 23:44:30 -080029
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000030namespace cricket {
31
Rasmus Brandt195d1d72018-05-09 11:28:01 +020032namespace {
33
Rasmus Brandt73d117f2018-10-02 11:12:52 +020034constexpr char kUseBaseHeavyVP8TL3RateAllocationFieldTrial[] =
35 "WebRTC-UseBaseHeavyVP8TL3RateAllocation";
36
Florent Castellia9fbb222019-07-24 16:06:45 +020037constexpr char kUseLegacySimulcastLayerLimitFieldTrial[] =
38 "WebRTC-LegacySimulcastLayerLimit";
39
Erik Språngb6b1cac2018-08-09 16:12:54 +020040// Limits for legacy conference screensharing mode. Currently used for the
41// lower of the two simulcast streams.
Rasmus Brandt195d1d72018-05-09 11:28:01 +020042constexpr int kScreenshareDefaultTl0BitrateKbps = 200;
43constexpr int kScreenshareDefaultTl1BitrateKbps = 1000;
44
Erik Språng661a0c62018-09-11 12:33:21 +020045// Min/max bitrate for the higher one of the two simulcast stream used for
46// screen content.
47constexpr int kScreenshareHighStreamMinBitrateBps = 600000;
Erik Språng58b22842018-08-21 13:15:28 +020048constexpr int kScreenshareHighStreamMaxBitrateBps = 1250000;
Erik Språngb6b1cac2018-08-09 16:12:54 +020049
Rasmus Brandt195d1d72018-05-09 11:28:01 +020050} // namespace
51
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000052struct SimulcastFormat {
53 int width;
54 int height;
Florent Castellia9fbb222019-07-24 16:06:45 +020055 // The maximum number of simulcast layers can be used for
56 // resolutions at |widthxheigh| for legacy applications.
57 size_t max_layers;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000058 // The maximum bitrate for encoding stream at |widthxheight|, when we are
59 // not sending the next higher spatial stream.
pbosbe16f792015-10-16 12:49:39 -070060 int max_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000061 // The target bitrate for encoding stream at |widthxheight|, when this layer
62 // is not the highest layer (i.e., when we are sending another higher spatial
63 // stream).
pbosbe16f792015-10-16 12:49:39 -070064 int target_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000065 // The minimum bitrate needed for encoding stream at |widthxheight|.
pbosbe16f792015-10-16 12:49:39 -070066 int min_bitrate_kbps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000067};
68
69// These tables describe from which resolution we can use how many
70// simulcast layers at what bitrates (maximum, target, and minimum).
71// Important!! Keep this table from high resolution to low resolution.
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020072// clang-format off
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000073const SimulcastFormat kSimulcastFormats[] = {
Florent Castellia9fbb222019-07-24 16:06:45 +020074 {1920, 1080, 3, 5000, 4000, 800},
75 {1280, 720, 3, 2500, 2500, 600},
76 {960, 540, 3, 900, 900, 450},
77 {640, 360, 2, 700, 500, 150},
78 {480, 270, 2, 450, 350, 150},
79 {320, 180, 1, 200, 150, 30},
80 {0, 0, 1, 200, 150, 30}
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +020081};
82// clang-format on
buildbot@webrtc.orga8530772014-12-10 09:01:18 +000083
Seth Hampson1370e302018-02-07 08:50:36 -080084const int kMaxScreenshareSimulcastLayers = 2;
sprang429600d2017-01-26 06:12:26 -080085
Erik Språngbfe3d852018-05-15 09:54:14 +020086// Multiway: Number of temporal layers for each simulcast stream.
Erik Språng58b22842018-08-21 13:15:28 +020087int DefaultNumberOfTemporalLayers(int simulcast_id, bool screenshare) {
Erik Språngbfe3d852018-05-15 09:54:14 +020088 RTC_CHECK_GE(simulcast_id, 0);
89 RTC_CHECK_LT(simulcast_id, webrtc::kMaxSimulcastStreams);
90
91 const int kDefaultNumTemporalLayers = 3;
Erik Språng7461eff2018-09-10 09:43:56 +020092 const int kDefaultNumScreenshareTemporalLayers = 2;
93 int default_num_temporal_layers = screenshare
94 ? kDefaultNumScreenshareTemporalLayers
95 : kDefaultNumTemporalLayers;
Erik Språngbfe3d852018-05-15 09:54:14 +020096
97 const std::string group_name =
Erik Språng58b22842018-08-21 13:15:28 +020098 screenshare ? webrtc::field_trial::FindFullName(
99 "WebRTC-VP8ScreenshareTemporalLayers")
100 : webrtc::field_trial::FindFullName(
101 "WebRTC-VP8ConferenceTemporalLayers");
Erik Språngbfe3d852018-05-15 09:54:14 +0200102 if (group_name.empty())
Erik Språng7461eff2018-09-10 09:43:56 +0200103 return default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +0200104
Erik Språng7461eff2018-09-10 09:43:56 +0200105 int num_temporal_layers = default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +0200106 if (sscanf(group_name.c_str(), "%d", &num_temporal_layers) == 1 &&
107 num_temporal_layers > 0 &&
108 num_temporal_layers <= webrtc::kMaxTemporalStreams) {
109 return num_temporal_layers;
110 }
111
112 RTC_LOG(LS_WARNING) << "Attempt to set number of temporal layers to "
113 "incorrect value: "
114 << group_name;
115
Erik Språng7461eff2018-09-10 09:43:56 +0200116 return default_num_temporal_layers;
Erik Språngbfe3d852018-05-15 09:54:14 +0200117}
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000118
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000119int FindSimulcastFormatIndex(int width, int height) {
Seth Hampson438663e2018-01-09 11:14:14 -0800120 RTC_DCHECK_GE(width, 0);
121 RTC_DCHECK_GE(height, 0);
kjellandera96e2d72016-02-04 23:52:28 -0800122 for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) {
sprang429600d2017-01-26 06:12:26 -0800123 if (width * height >=
124 kSimulcastFormats[i].width * kSimulcastFormats[i].height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000125 return i;
126 }
127 }
Seth Hampson438663e2018-01-09 11:14:14 -0800128 RTC_NOTREACHED();
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000129 return -1;
130}
131
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000132// Simulcast stream width and height must both be dividable by
Rasmus Brandtefbdcb02018-04-26 17:47:42 +0200133// |2 ^ (simulcast_layers - 1)|.
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000134int NormalizeSimulcastSize(int size, size_t simulcast_layers) {
Åsa Persson1a35fbd2018-10-12 17:36:57 +0200135 int base2_exponent = static_cast<int>(simulcast_layers) - 1;
136 const absl::optional<int> experimental_base2_exponent =
137 webrtc::NormalizeSimulcastSizeExperiment::GetBase2Exponent();
138 if (experimental_base2_exponent &&
139 (size > (1 << *experimental_base2_exponent))) {
140 base2_exponent = *experimental_base2_exponent;
141 }
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000142 return ((size >> base2_exponent) << base2_exponent);
143}
144
sprang429600d2017-01-26 06:12:26 -0800145int FindSimulcastMaxBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000146 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700147 return kSimulcastFormats[format_index].max_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000148}
149
sprang429600d2017-01-26 06:12:26 -0800150int FindSimulcastTargetBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000151 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700152 return kSimulcastFormats[format_index].target_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000153}
154
sprang429600d2017-01-26 06:12:26 -0800155int FindSimulcastMinBitrateBps(int width, int height) {
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000156 const int format_index = FindSimulcastFormatIndex(width, height);
pbosbe16f792015-10-16 12:49:39 -0700157 return kSimulcastFormats[format_index].min_bitrate_kbps * 1000;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000158}
159
Seth Hampson1370e302018-02-07 08:50:36 -0800160void BoostMaxSimulcastLayer(int max_bitrate_bps,
161 std::vector<webrtc::VideoStream>* layers) {
Åsa Persson55659812018-06-18 17:51:32 +0200162 if (layers->empty())
163 return;
164
Seth Hampson1370e302018-02-07 08:50:36 -0800165 // Spend additional bits to boost the max layer.
166 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(*layers);
167 if (bitrate_left_bps > 0) {
168 layers->back().max_bitrate_bps += bitrate_left_bps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000169 }
Seth Hampson1370e302018-02-07 08:50:36 -0800170}
171
172int GetTotalMaxBitrateBps(const std::vector<webrtc::VideoStream>& layers) {
Åsa Persson55659812018-06-18 17:51:32 +0200173 if (layers.empty())
174 return 0;
175
Seth Hampson1370e302018-02-07 08:50:36 -0800176 int total_max_bitrate_bps = 0;
177 for (size_t s = 0; s < layers.size() - 1; ++s) {
178 total_max_bitrate_bps += layers[s].target_bitrate_bps;
179 }
180 total_max_bitrate_bps += layers.back().max_bitrate_bps;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000181 return total_max_bitrate_bps;
182}
183
Florent Castellia9fbb222019-07-24 16:06:45 +0200184int LimitSimulcastLayerCount(int width, int height, int layer_count) {
185 if (webrtc::field_trial::IsEnabled(kUseLegacySimulcastLayerLimitFieldTrial)) {
186 int adaptive_layer_count =
187 kSimulcastFormats[FindSimulcastFormatIndex(width, height)].max_layers;
188 if (layer_count > adaptive_layer_count) {
189 RTC_LOG(LS_WARNING) << "Reducing simulcast layer count from "
190 << layer_count << " to " << adaptive_layer_count;
191 layer_count = adaptive_layer_count;
192 }
193 }
194 return layer_count;
195}
196
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200197std::vector<webrtc::VideoStream> GetSimulcastConfig(
198 size_t max_layers,
199 int width,
200 int height,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200201 double bitrate_priority,
202 int max_qp,
Florent Castelli66b38602019-07-10 16:57:57 +0200203 bool is_screenshare_with_conference_mode,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200204 bool temporal_layers_supported) {
Florent Castelli66b38602019-07-10 16:57:57 +0200205 RTC_DCHECK(max_layers > 1 || is_screenshare_with_conference_mode);
Florent Castellia9fbb222019-07-24 16:06:45 +0200206
207 // Some applications rely on the old behavior limiting the simulcast layer
208 // count based on the resolution automatically, which they can get through
209 // the WebRTC-LegacySimulcastLayerLimit field trial until they update.
210 max_layers = LimitSimulcastLayerCount(width, height, max_layers);
211
Florent Castelli66b38602019-07-10 16:57:57 +0200212 if (is_screenshare_with_conference_mode) {
Åsa Persson8c1bf952018-09-13 10:42:19 +0200213 return GetScreenshareLayers(max_layers, width, height, bitrate_priority,
Florent Castelli66b38602019-07-10 16:57:57 +0200214 max_qp, temporal_layers_supported);
sprang429600d2017-01-26 06:12:26 -0800215 } else {
Åsa Persson55659812018-06-18 17:51:32 +0200216 return GetNormalSimulcastLayers(max_layers, width, height, bitrate_priority,
Åsa Persson8c1bf952018-09-13 10:42:19 +0200217 max_qp, temporal_layers_supported);
sprang429600d2017-01-26 06:12:26 -0800218 }
Seth Hampson1370e302018-02-07 08:50:36 -0800219}
sprang429600d2017-01-26 06:12:26 -0800220
Seth Hampson1370e302018-02-07 08:50:36 -0800221std::vector<webrtc::VideoStream> GetNormalSimulcastLayers(
Florent Castelli668ce0c2019-07-04 17:06:04 +0200222 size_t layer_count,
Seth Hampson1370e302018-02-07 08:50:36 -0800223 int width,
224 int height,
Seth Hampson1370e302018-02-07 08:50:36 -0800225 double bitrate_priority,
226 int max_qp,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200227 bool temporal_layers_supported) {
Florent Castelli668ce0c2019-07-04 17:06:04 +0200228 std::vector<webrtc::VideoStream> layers(layer_count);
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000229
Seth Hampson1370e302018-02-07 08:50:36 -0800230 // Format width and height has to be divisible by |2 ^ num_simulcast_layers -
231 // 1|.
Florent Castelli668ce0c2019-07-04 17:06:04 +0200232 width = NormalizeSimulcastSize(width, layer_count);
233 height = NormalizeSimulcastSize(height, layer_count);
Seth Hampson1370e302018-02-07 08:50:36 -0800234 // Add simulcast streams, from highest resolution (|s| = num_simulcast_layers
235 // -1) to lowest resolution at |s| = 0.
Florent Castelli668ce0c2019-07-04 17:06:04 +0200236 for (size_t s = layer_count - 1;; --s) {
Seth Hampson1370e302018-02-07 08:50:36 -0800237 layers[s].width = width;
238 layers[s].height = height;
239 // TODO(pbos): Fill actual temporal-layer bitrate thresholds.
240 layers[s].max_qp = max_qp;
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200241 layers[s].num_temporal_layers =
Erik Språng58b22842018-08-21 13:15:28 +0200242 temporal_layers_supported ? DefaultNumberOfTemporalLayers(s, false) : 0;
Seth Hampson1370e302018-02-07 08:50:36 -0800243 layers[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height);
244 layers[s].target_bitrate_bps = FindSimulcastTargetBitrateBps(width, height);
Erik Språng58b22842018-08-21 13:15:28 +0200245 int num_temporal_layers = DefaultNumberOfTemporalLayers(s, false);
Erik Språngd497e6b2018-07-06 17:17:10 +0200246 if (s == 0) {
Rasmus Brandt73d117f2018-10-02 11:12:52 +0200247 // If alternative temporal rate allocation is selected, adjust the
Erik Språngd92288f2018-07-04 10:07:40 +0200248 // bitrate of the lowest simulcast stream so that absolute bitrate for
249 // the base temporal layer matches the bitrate for the base temporal
250 // layer with the default 3 simulcast streams. Otherwise we risk a
251 // higher threshold for receiving a feed at all.
Erik Språngd497e6b2018-07-06 17:17:10 +0200252 float rate_factor = 1.0;
253 if (num_temporal_layers == 3) {
Rasmus Brandt73d117f2018-10-02 11:12:52 +0200254 if (webrtc::field_trial::IsEnabled(
255 kUseBaseHeavyVP8TL3RateAllocationFieldTrial)) {
256 // Base heavy allocation increases TL0 bitrate from 40% to 60%.
Erik Språngd497e6b2018-07-06 17:17:10 +0200257 rate_factor = 0.4 / 0.6;
258 }
259 } else {
260 rate_factor =
261 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(3, 0) /
262 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
263 num_temporal_layers, 0);
264 }
265
Erik Språng79478ad2018-05-18 09:39:55 +0200266 layers[s].max_bitrate_bps =
267 static_cast<int>(layers[s].max_bitrate_bps * rate_factor);
268 layers[s].target_bitrate_bps =
269 static_cast<int>(layers[s].target_bitrate_bps * rate_factor);
270 }
Seth Hampson1370e302018-02-07 08:50:36 -0800271 layers[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height);
Åsa Persson8c1bf952018-09-13 10:42:19 +0200272 layers[s].max_framerate = kDefaultVideoMaxFramerate;
sprang02569ad2017-07-06 05:05:50 -0700273
Seth Hampson1370e302018-02-07 08:50:36 -0800274 width /= 2;
275 height /= 2;
sprang02569ad2017-07-06 05:05:50 -0700276
Seth Hampson1370e302018-02-07 08:50:36 -0800277 if (s == 0) {
278 break;
sprang02569ad2017-07-06 05:05:50 -0700279 }
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000280 }
Seth Hampson1370e302018-02-07 08:50:36 -0800281 // Currently the relative bitrate priority of the sender is controlled by
282 // the value of the lowest VideoStream.
283 // TODO(bugs.webrtc.org/8630): The web specification describes being able to
284 // control relative bitrate for each individual simulcast layer, but this
285 // is currently just implemented per rtp sender.
286 layers[0].bitrate_priority = bitrate_priority;
287 return layers;
288}
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000289
Seth Hampson1370e302018-02-07 08:50:36 -0800290std::vector<webrtc::VideoStream> GetScreenshareLayers(
291 size_t max_layers,
292 int width,
293 int height,
Seth Hampson1370e302018-02-07 08:50:36 -0800294 double bitrate_priority,
295 int max_qp,
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200296 bool temporal_layers_supported) {
Florent Castelli66b38602019-07-10 16:57:57 +0200297 auto max_screenshare_layers = kMaxScreenshareSimulcastLayers;
Seth Hampson1370e302018-02-07 08:50:36 -0800298 size_t num_simulcast_layers =
Ilya Nikolaevskiy3df1d5d2018-08-22 09:26:51 +0200299 std::min<int>(max_layers, max_screenshare_layers);
Seth Hampson1370e302018-02-07 08:50:36 -0800300
301 std::vector<webrtc::VideoStream> layers(num_simulcast_layers);
Seth Hampson1370e302018-02-07 08:50:36 -0800302 // For legacy screenshare in conference mode, tl0 and tl1 bitrates are
303 // piggybacked on the VideoCodec struct as target and max bitrates,
Erik Språngcc681cc2018-03-14 17:52:55 +0100304 // respectively. See eg. webrtc::LibvpxVp8Encoder::SetRates().
Seth Hampson1370e302018-02-07 08:50:36 -0800305 layers[0].width = width;
306 layers[0].height = height;
307 layers[0].max_qp = max_qp;
308 layers[0].max_framerate = 5;
309 layers[0].min_bitrate_bps = kMinVideoBitrateBps;
Rasmus Brandt195d1d72018-05-09 11:28:01 +0200310 layers[0].target_bitrate_bps = kScreenshareDefaultTl0BitrateKbps * 1000;
311 layers[0].max_bitrate_bps = kScreenshareDefaultTl1BitrateKbps * 1000;
Sergio Garcia Murillo43800f92018-06-21 16:16:38 +0200312 layers[0].num_temporal_layers = temporal_layers_supported ? 2 : 0;
Seth Hampson1370e302018-02-07 08:50:36 -0800313
314 // With simulcast enabled, add another spatial layer. This one will have a
315 // more normal layout, with the regular 3 temporal layer pattern and no fps
316 // restrictions. The base simulcast layer will still use legacy setup.
317 if (num_simulcast_layers == kMaxScreenshareSimulcastLayers) {
318 // Add optional upper simulcast layer.
Erik Språng58b22842018-08-21 13:15:28 +0200319 const int num_temporal_layers = DefaultNumberOfTemporalLayers(1, true);
Erik Språngb6b1cac2018-08-09 16:12:54 +0200320 int max_bitrate_bps;
Erik Språngcf919422018-09-17 16:18:57 +0200321 bool using_boosted_bitrate = false;
Erik Språngb6b1cac2018-08-09 16:12:54 +0200322 if (!temporal_layers_supported) {
323 // Set the max bitrate to where the base layer would have been if temporal
Erik Språng58b22842018-08-21 13:15:28 +0200324 // layers were enabled.
Erik Språngb6b1cac2018-08-09 16:12:54 +0200325 max_bitrate_bps = static_cast<int>(
326 kScreenshareHighStreamMaxBitrateBps *
327 webrtc::SimulcastRateAllocator::GetTemporalRateAllocation(
328 num_temporal_layers, 0));
Erik Språng58b22842018-08-21 13:15:28 +0200329 } else if (DefaultNumberOfTemporalLayers(1, true) != 3 ||
Rasmus Brandt73d117f2018-10-02 11:12:52 +0200330 webrtc::field_trial::IsEnabled(
331 kUseBaseHeavyVP8TL3RateAllocationFieldTrial)) {
Erik Språngb6b1cac2018-08-09 16:12:54 +0200332 // Experimental temporal layer mode used, use increased max bitrate.
333 max_bitrate_bps = kScreenshareHighStreamMaxBitrateBps;
Erik Språngcf919422018-09-17 16:18:57 +0200334 using_boosted_bitrate = true;
Erik Språngb6b1cac2018-08-09 16:12:54 +0200335 } else {
336 // Keep current bitrates with default 3tl/8 frame settings.
337 // Lowest temporal layers of a 3 layer setup will have 40% of the total
338 // bitrate allocation for that simulcast layer. Make sure the gap between
339 // the target of the lower simulcast layer and first temporal layer of the
340 // higher one is at most 2x the bitrate, so that upswitching is not
341 // hampered by stalled bitrate estimates.
342 max_bitrate_bps = 2 * ((layers[0].target_bitrate_bps * 10) / 4);
343 }
344
Seth Hampson1370e302018-02-07 08:50:36 -0800345 layers[1].width = width;
346 layers[1].height = height;
347 layers[1].max_qp = max_qp;
Åsa Persson8c1bf952018-09-13 10:42:19 +0200348 layers[1].max_framerate = kDefaultVideoMaxFramerate;
Erik Språngb6b1cac2018-08-09 16:12:54 +0200349 layers[1].num_temporal_layers =
Erik Språng58b22842018-08-21 13:15:28 +0200350 temporal_layers_supported ? DefaultNumberOfTemporalLayers(1, true) : 0;
Erik Språngcf919422018-09-17 16:18:57 +0200351 layers[1].min_bitrate_bps = using_boosted_bitrate
352 ? kScreenshareHighStreamMinBitrateBps
353 : layers[0].target_bitrate_bps * 2;
354
355 // Cap max bitrate so it isn't overly high for the given resolution.
356 int resolution_limited_bitrate = std::max(
357 FindSimulcastMaxBitrateBps(width, height), layers[1].min_bitrate_bps);
358 max_bitrate_bps =
359 std::min<int>(max_bitrate_bps, resolution_limited_bitrate);
360
Seth Hampson1370e302018-02-07 08:50:36 -0800361 layers[1].target_bitrate_bps = max_bitrate_bps;
362 layers[1].max_bitrate_bps = max_bitrate_bps;
363 }
364
Seth Hampson24722b32017-12-22 09:36:42 -0800365 // The bitrate priority currently implemented on a per-sender level, so we
Seth Hampson1370e302018-02-07 08:50:36 -0800366 // just set it for the first simulcast layer.
367 layers[0].bitrate_priority = bitrate_priority;
368 return layers;
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000369}
370
buildbot@webrtc.orga8530772014-12-10 09:01:18 +0000371} // namespace cricket