buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 4 | * 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.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | #include <string> |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "media/base/streamparams.h" |
| 16 | #include "media/engine/constants.h" |
| 17 | #include "media/engine/simulcast.h" |
| 18 | #include "rtc_base/arraysize.h" |
| 19 | #include "rtc_base/logging.h" |
| 20 | #include "system_wrappers/include/field_trial.h" |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 21 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 22 | namespace cricket { |
| 23 | |
| 24 | struct SimulcastFormat { |
| 25 | int width; |
| 26 | int height; |
| 27 | // The maximum number of simulcast layers can be used for |
| 28 | // resolutions at |widthxheigh|. |
| 29 | size_t max_layers; |
| 30 | // The maximum bitrate for encoding stream at |widthxheight|, when we are |
| 31 | // not sending the next higher spatial stream. |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 32 | int max_bitrate_kbps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 33 | // The target bitrate for encoding stream at |widthxheight|, when this layer |
| 34 | // is not the highest layer (i.e., when we are sending another higher spatial |
| 35 | // stream). |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 36 | int target_bitrate_kbps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 37 | // The minimum bitrate needed for encoding stream at |widthxheight|. |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 38 | int min_bitrate_kbps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | // These tables describe from which resolution we can use how many |
| 42 | // simulcast layers at what bitrates (maximum, target, and minimum). |
| 43 | // Important!! Keep this table from high resolution to low resolution. |
| 44 | const SimulcastFormat kSimulcastFormats[] = { |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 45 | {1920, 1080, 3, 5000, 4000, 800}, |
| 46 | {1280, 720, 3, 2500, 2500, 600}, |
| 47 | {960, 540, 3, 900, 900, 450}, |
| 48 | {640, 360, 2, 700, 500, 150}, |
| 49 | {480, 270, 2, 450, 350, 150}, |
| 50 | {320, 180, 1, 200, 150, 30}, |
| 51 | {0, 0, 1, 200, 150, 30} |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 54 | const int kMaxScreenshareSimulcastStreams = 2; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 55 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 56 | // Multiway: Number of temporal layers for each simulcast stream, for maximum |
| 57 | // possible number of simulcast streams |kMaxSimulcastStreams|. The array |
| 58 | // goes from lowest resolution at position 0 to highest resolution. |
| 59 | // For example, first three elements correspond to say: QVGA, VGA, WHD. |
| 60 | static const int |
| 61 | kDefaultConferenceNumberOfTemporalLayers[webrtc::kMaxSimulcastStreams] = |
| 62 | {3, 3, 3, 3}; |
| 63 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 64 | void GetSimulcastSsrcs(const StreamParams& sp, std::vector<uint32_t>* ssrcs) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 65 | const SsrcGroup* sim_group = sp.get_ssrc_group(kSimSsrcGroupSemantics); |
| 66 | if (sim_group) { |
| 67 | ssrcs->insert( |
| 68 | ssrcs->end(), sim_group->ssrcs.begin(), sim_group->ssrcs.end()); |
| 69 | } |
| 70 | } |
| 71 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 72 | void MaybeExchangeWidthHeight(int* width, int* height) { |
| 73 | // |kSimulcastFormats| assumes |width| >= |height|. If not, exchange them |
| 74 | // before comparing. |
| 75 | if (*width < *height) { |
| 76 | int temp = *width; |
| 77 | *width = *height; |
| 78 | *height = temp; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | int FindSimulcastFormatIndex(int width, int height) { |
| 83 | MaybeExchangeWidthHeight(&width, &height); |
| 84 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 85 | for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 86 | if (width * height >= |
| 87 | kSimulcastFormats[i].width * kSimulcastFormats[i].height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 88 | return i; |
| 89 | } |
| 90 | } |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | int FindSimulcastFormatIndex(int width, int height, size_t max_layers) { |
| 95 | MaybeExchangeWidthHeight(&width, &height); |
| 96 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 97 | for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 98 | if (width * height >= |
| 99 | kSimulcastFormats[i].width * kSimulcastFormats[i].height && |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 100 | max_layers == kSimulcastFormats[i].max_layers) { |
| 101 | return i; |
| 102 | } |
| 103 | } |
| 104 | return -1; |
| 105 | } |
| 106 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 107 | // Simulcast stream width and height must both be dividable by |
| 108 | // |2 ^ simulcast_layers - 1|. |
| 109 | int NormalizeSimulcastSize(int size, size_t simulcast_layers) { |
| 110 | const int base2_exponent = static_cast<int>(simulcast_layers) - 1; |
| 111 | return ((size >> base2_exponent) << base2_exponent); |
| 112 | } |
| 113 | |
| 114 | size_t FindSimulcastMaxLayers(int width, int height) { |
| 115 | int index = FindSimulcastFormatIndex(width, height); |
| 116 | if (index == -1) { |
| 117 | return -1; |
| 118 | } |
| 119 | return kSimulcastFormats[index].max_layers; |
| 120 | } |
| 121 | |
| 122 | // TODO(marpan): Investigate if we should return 0 instead of -1 in |
| 123 | // FindSimulcast[Max/Target/Min]Bitrate functions below, since the |
| 124 | // codec struct max/min/targeBitrates are unsigned. |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 125 | int FindSimulcastMaxBitrateBps(int width, int height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 126 | const int format_index = FindSimulcastFormatIndex(width, height); |
| 127 | if (format_index == -1) { |
| 128 | return -1; |
| 129 | } |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 130 | return kSimulcastFormats[format_index].max_bitrate_kbps * 1000; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 131 | } |
| 132 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 133 | int FindSimulcastTargetBitrateBps(int width, int height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 134 | const int format_index = FindSimulcastFormatIndex(width, height); |
| 135 | if (format_index == -1) { |
| 136 | return -1; |
| 137 | } |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 138 | return kSimulcastFormats[format_index].target_bitrate_kbps * 1000; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 139 | } |
| 140 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 141 | int FindSimulcastMinBitrateBps(int width, int height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 142 | const int format_index = FindSimulcastFormatIndex(width, height); |
| 143 | if (format_index == -1) { |
| 144 | return -1; |
| 145 | } |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 146 | return kSimulcastFormats[format_index].min_bitrate_kbps * 1000; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | bool SlotSimulcastMaxResolution(size_t max_layers, int* width, int* height) { |
| 150 | int index = FindSimulcastFormatIndex(*width, *height, max_layers); |
| 151 | if (index == -1) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 152 | RTC_LOG(LS_ERROR) << "SlotSimulcastMaxResolution"; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 153 | return false; |
| 154 | } |
| 155 | |
| 156 | *width = kSimulcastFormats[index].width; |
| 157 | *height = kSimulcastFormats[index].height; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 158 | RTC_LOG(LS_INFO) << "SlotSimulcastMaxResolution to width:" << *width |
| 159 | << " height:" << *height; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 160 | return true; |
| 161 | } |
| 162 | |
| 163 | int GetTotalMaxBitrateBps(const std::vector<webrtc::VideoStream>& streams) { |
| 164 | int total_max_bitrate_bps = 0; |
| 165 | for (size_t s = 0; s < streams.size() - 1; ++s) { |
| 166 | total_max_bitrate_bps += streams[s].target_bitrate_bps; |
| 167 | } |
| 168 | total_max_bitrate_bps += streams.back().max_bitrate_bps; |
| 169 | return total_max_bitrate_bps; |
| 170 | } |
| 171 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 172 | // TODO(shampson): This is a fix to not break downstream tests. Remove this |
| 173 | // after updating downstream tests. |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 174 | std::vector<webrtc::VideoStream> GetSimulcastConfig(size_t max_streams, |
| 175 | int width, |
| 176 | int height, |
| 177 | int max_bitrate_bps, |
| 178 | int max_qp, |
| 179 | int max_framerate, |
| 180 | bool is_screencast) { |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 181 | return GetSimulcastConfig(max_streams, width, height, max_bitrate_bps, 1.0, |
| 182 | max_qp, max_framerate, is_screencast); |
| 183 | } |
| 184 | |
| 185 | std::vector<webrtc::VideoStream> GetSimulcastConfig(size_t max_streams, |
| 186 | int width, |
| 187 | int height, |
| 188 | int max_bitrate_bps, |
| 189 | double bitrate_priority, |
| 190 | int max_qp, |
| 191 | int max_framerate, |
| 192 | bool is_screencast) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 193 | size_t num_simulcast_layers; |
| 194 | if (is_screencast) { |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 195 | if (UseSimulcastScreenshare()) { |
| 196 | num_simulcast_layers = |
| 197 | std::min<int>(max_streams, kMaxScreenshareSimulcastStreams); |
| 198 | } else { |
| 199 | num_simulcast_layers = 1; |
| 200 | } |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 201 | } else { |
| 202 | num_simulcast_layers = FindSimulcastMaxLayers(width, height); |
| 203 | } |
| 204 | |
| 205 | if (num_simulcast_layers > max_streams) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 206 | // If the number of SSRCs in the group differs from our target |
| 207 | // number of simulcast streams for current resolution, switch down |
| 208 | // to a resolution that matches our number of SSRCs. |
| 209 | if (!SlotSimulcastMaxResolution(max_streams, &width, &height)) { |
| 210 | return std::vector<webrtc::VideoStream>(); |
| 211 | } |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 212 | num_simulcast_layers = max_streams; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 213 | } |
| 214 | std::vector<webrtc::VideoStream> streams; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 215 | streams.resize(num_simulcast_layers); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 216 | |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 217 | if (is_screencast) { |
| 218 | ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |
| 219 | // For legacy screenshare in conference mode, tl0 and tl1 bitrates are |
| 220 | // piggybacked on the VideoCodec struct as target and max bitrates, |
| 221 | // respectively. See eg. webrtc::VP8EncoderImpl::SetRates(). |
| 222 | streams[0].width = width; |
| 223 | streams[0].height = height; |
| 224 | streams[0].max_qp = max_qp; |
| 225 | streams[0].max_framerate = 5; |
Åsa Persson | 45bbc8a | 2017-11-13 10:16:47 +0100 | [diff] [blame] | 226 | streams[0].min_bitrate_bps = kMinVideoBitrateBps; |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 227 | streams[0].target_bitrate_bps = config.tl0_bitrate_kbps * 1000; |
| 228 | streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; |
| 229 | streams[0].temporal_layer_thresholds_bps.clear(); |
| 230 | streams[0].temporal_layer_thresholds_bps.push_back(config.tl0_bitrate_kbps * |
| 231 | 1000); |
| 232 | |
| 233 | // With simulcast enabled, add another spatial layer. This one will have a |
| 234 | // more normal layout, with the regular 3 temporal layer pattern and no fps |
| 235 | // restrictions. The base simulcast stream will still use legacy setup. |
| 236 | if (num_simulcast_layers == kMaxScreenshareSimulcastStreams) { |
| 237 | // Add optional upper simulcast layer. |
| 238 | // Lowest temporal layers of a 3 layer setup will have 40% of the total |
| 239 | // bitrate allocation for that stream. Make sure the gap between the |
| 240 | // target of the lower stream and first temporal layer of the higher one |
| 241 | // is at most 2x the bitrate, so that upswitching is not hampered by |
| 242 | // stalled bitrate estimates. |
| 243 | int max_bitrate_bps = 2 * ((streams[0].target_bitrate_bps * 10) / 4); |
| 244 | // Cap max bitrate so it isn't overly high for the given resolution. |
| 245 | max_bitrate_bps = std::min<int>( |
| 246 | max_bitrate_bps, FindSimulcastMaxBitrateBps(width, height)); |
| 247 | |
| 248 | streams[1].width = width; |
| 249 | streams[1].height = height; |
| 250 | streams[1].max_qp = max_qp; |
| 251 | streams[1].max_framerate = max_framerate; |
| 252 | // Three temporal layers means two thresholds. |
| 253 | streams[1].temporal_layer_thresholds_bps.resize(2); |
| 254 | streams[1].min_bitrate_bps = streams[0].target_bitrate_bps * 2; |
| 255 | streams[1].target_bitrate_bps = max_bitrate_bps; |
| 256 | streams[1].max_bitrate_bps = max_bitrate_bps; |
| 257 | } |
| 258 | } else { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 259 | // Format width and height has to be divisible by |2 ^ number_streams - 1|. |
| 260 | width = NormalizeSimulcastSize(width, num_simulcast_layers); |
| 261 | height = NormalizeSimulcastSize(height, num_simulcast_layers); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 262 | |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 263 | // Add simulcast sub-streams from lower resolution to higher resolutions. |
| 264 | // Add simulcast streams, from highest resolution (|s| = number_streams -1) |
| 265 | // to lowest resolution at |s| = 0. |
| 266 | for (size_t s = num_simulcast_layers - 1;; --s) { |
| 267 | streams[s].width = width; |
| 268 | streams[s].height = height; |
| 269 | // TODO(pbos): Fill actual temporal-layer bitrate thresholds. |
| 270 | streams[s].max_qp = max_qp; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 271 | streams[s].temporal_layer_thresholds_bps.resize( |
| 272 | kDefaultConferenceNumberOfTemporalLayers[s] - 1); |
| 273 | streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height); |
| 274 | streams[s].target_bitrate_bps = |
| 275 | FindSimulcastTargetBitrateBps(width, height); |
| 276 | streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height); |
| 277 | streams[s].max_framerate = max_framerate; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 278 | |
sprang | 3ebabf1 | 2017-02-16 07:35:22 -0800 | [diff] [blame] | 279 | width /= 2; |
| 280 | height /= 2; |
sprang | 317005a | 2017-06-08 07:12:17 -0700 | [diff] [blame] | 281 | |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 282 | if (s == 0) |
| 283 | break; |
| 284 | } |
| 285 | |
| 286 | // Spend additional bits to boost the max stream. |
| 287 | int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams); |
| 288 | if (bitrate_left_bps > 0) { |
| 289 | streams.back().max_bitrate_bps += bitrate_left_bps; |
| 290 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 293 | // The bitrate priority currently implemented on a per-sender level, so we |
| 294 | // just set it for the first video stream. |
| 295 | streams[0].bitrate_priority = bitrate_priority; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 296 | return streams; |
| 297 | } |
| 298 | |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 299 | static const int kScreenshareMinBitrateKbps = 50; |
| 300 | static const int kScreenshareMaxBitrateKbps = 6000; |
Erik Språng | 2c4c914 | 2015-06-24 11:24:44 +0200 | [diff] [blame] | 301 | static const int kScreenshareDefaultTl0BitrateKbps = 200; |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 302 | static const int kScreenshareDefaultTl1BitrateKbps = 1000; |
| 303 | |
| 304 | static const char* kScreencastLayerFieldTrialName = |
| 305 | "WebRTC-ScreenshareLayerRates"; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 306 | static const char* kSimulcastScreenshareFieldTrialName = |
| 307 | "WebRTC-SimulcastScreenshare"; |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 308 | |
| 309 | ScreenshareLayerConfig::ScreenshareLayerConfig(int tl0_bitrate, int tl1_bitrate) |
| 310 | : tl0_bitrate_kbps(tl0_bitrate), tl1_bitrate_kbps(tl1_bitrate) { |
| 311 | } |
| 312 | |
| 313 | ScreenshareLayerConfig ScreenshareLayerConfig::GetDefault() { |
| 314 | std::string group = |
| 315 | webrtc::field_trial::FindFullName(kScreencastLayerFieldTrialName); |
| 316 | |
| 317 | ScreenshareLayerConfig config(kScreenshareDefaultTl0BitrateKbps, |
| 318 | kScreenshareDefaultTl1BitrateKbps); |
| 319 | if (!group.empty() && !FromFieldTrialGroup(group, &config)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 320 | RTC_LOG(LS_WARNING) << "Unable to parse WebRTC-ScreenshareLayerRates" |
| 321 | " field trial group: '" |
| 322 | << group << "'."; |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 323 | } |
| 324 | return config; |
| 325 | } |
| 326 | |
| 327 | bool ScreenshareLayerConfig::FromFieldTrialGroup( |
| 328 | const std::string& group, |
| 329 | ScreenshareLayerConfig* config) { |
| 330 | // Parse field trial group name, containing bitrates for tl0 and tl1. |
| 331 | int tl0_bitrate; |
| 332 | int tl1_bitrate; |
| 333 | if (sscanf(group.c_str(), "%d-%d", &tl0_bitrate, &tl1_bitrate) != 2) { |
| 334 | return false; |
| 335 | } |
| 336 | |
| 337 | // Sanity check. |
| 338 | if (tl0_bitrate < kScreenshareMinBitrateKbps || |
| 339 | tl0_bitrate > kScreenshareMaxBitrateKbps || |
| 340 | tl1_bitrate < kScreenshareMinBitrateKbps || |
| 341 | tl1_bitrate > kScreenshareMaxBitrateKbps || tl0_bitrate > tl1_bitrate) { |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | config->tl0_bitrate_kbps = tl0_bitrate; |
| 346 | config->tl1_bitrate_kbps = tl1_bitrate; |
| 347 | |
| 348 | return true; |
| 349 | } |
| 350 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 351 | bool UseSimulcastScreenshare() { |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame] | 352 | return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 353 | } |
| 354 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 355 | } // namespace cricket |