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 | |
Rasmus Brandt | 195d1d7 | 2018-05-09 11:28:01 +0200 | [diff] [blame^] | 24 | namespace { |
| 25 | |
| 26 | constexpr int kScreenshareDefaultTl0BitrateKbps = 200; |
| 27 | constexpr int kScreenshareDefaultTl1BitrateKbps = 1000; |
| 28 | |
| 29 | static const char* kSimulcastScreenshareFieldTrialName = |
| 30 | "WebRTC-SimulcastScreenshare"; |
| 31 | |
| 32 | } // namespace |
| 33 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 34 | struct SimulcastFormat { |
| 35 | int width; |
| 36 | int height; |
| 37 | // The maximum number of simulcast layers can be used for |
| 38 | // resolutions at |widthxheigh|. |
| 39 | size_t max_layers; |
| 40 | // The maximum bitrate for encoding stream at |widthxheight|, when we are |
| 41 | // not sending the next higher spatial stream. |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 42 | int max_bitrate_kbps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 43 | // The target bitrate for encoding stream at |widthxheight|, when this layer |
| 44 | // is not the highest layer (i.e., when we are sending another higher spatial |
| 45 | // stream). |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 46 | int target_bitrate_kbps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 47 | // The minimum bitrate needed for encoding stream at |widthxheight|. |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 48 | int min_bitrate_kbps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // These tables describe from which resolution we can use how many |
| 52 | // simulcast layers at what bitrates (maximum, target, and minimum). |
| 53 | // Important!! Keep this table from high resolution to low resolution. |
| 54 | const SimulcastFormat kSimulcastFormats[] = { |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 55 | {1920, 1080, 3, 5000, 4000, 800}, |
| 56 | {1280, 720, 3, 2500, 2500, 600}, |
| 57 | {960, 540, 3, 900, 900, 450}, |
| 58 | {640, 360, 2, 700, 500, 150}, |
| 59 | {480, 270, 2, 450, 350, 150}, |
| 60 | {320, 180, 1, 200, 150, 30}, |
| 61 | {0, 0, 1, 200, 150, 30} |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 64 | const int kMaxScreenshareSimulcastLayers = 2; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 65 | |
Erik Språng | bfe3d85 | 2018-05-15 09:54:14 +0200 | [diff] [blame] | 66 | // Multiway: Number of temporal layers for each simulcast stream. |
| 67 | int DefaultNumberOfTemporalLayers(int simulcast_id) { |
| 68 | RTC_CHECK_GE(simulcast_id, 0); |
| 69 | RTC_CHECK_LT(simulcast_id, webrtc::kMaxSimulcastStreams); |
| 70 | |
| 71 | const int kDefaultNumTemporalLayers = 3; |
| 72 | |
| 73 | const std::string group_name = |
| 74 | webrtc::field_trial::FindFullName("WebRTC-VP8ConferenceTemporalLayers"); |
| 75 | if (group_name.empty()) |
| 76 | return kDefaultNumTemporalLayers; |
| 77 | |
| 78 | int num_temporal_layers = kDefaultNumTemporalLayers; |
| 79 | if (sscanf(group_name.c_str(), "%d", &num_temporal_layers) == 1 && |
| 80 | num_temporal_layers > 0 && |
| 81 | num_temporal_layers <= webrtc::kMaxTemporalStreams) { |
| 82 | return num_temporal_layers; |
| 83 | } |
| 84 | |
| 85 | RTC_LOG(LS_WARNING) << "Attempt to set number of temporal layers to " |
| 86 | "incorrect value: " |
| 87 | << group_name; |
| 88 | |
| 89 | return kDefaultNumTemporalLayers; |
| 90 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 91 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 92 | int FindSimulcastFormatIndex(int width, int height) { |
Seth Hampson | 438663e | 2018-01-09 11:14:14 -0800 | [diff] [blame] | 93 | RTC_DCHECK_GE(width, 0); |
| 94 | RTC_DCHECK_GE(height, 0); |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 95 | for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 96 | if (width * height >= |
| 97 | kSimulcastFormats[i].width * kSimulcastFormats[i].height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 98 | return i; |
| 99 | } |
| 100 | } |
Seth Hampson | 438663e | 2018-01-09 11:14:14 -0800 | [diff] [blame] | 101 | RTC_NOTREACHED(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | int FindSimulcastFormatIndex(int width, int height, size_t max_layers) { |
Seth Hampson | 438663e | 2018-01-09 11:14:14 -0800 | [diff] [blame] | 106 | RTC_DCHECK_GE(width, 0); |
| 107 | RTC_DCHECK_GE(height, 0); |
| 108 | RTC_DCHECK_GT(max_layers, 0); |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 109 | for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 110 | if (width * height >= |
| 111 | kSimulcastFormats[i].width * kSimulcastFormats[i].height && |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 112 | max_layers == kSimulcastFormats[i].max_layers) { |
| 113 | return i; |
| 114 | } |
| 115 | } |
Seth Hampson | 438663e | 2018-01-09 11:14:14 -0800 | [diff] [blame] | 116 | RTC_NOTREACHED(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 117 | return -1; |
| 118 | } |
| 119 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 120 | // Simulcast stream width and height must both be dividable by |
Rasmus Brandt | efbdcb0 | 2018-04-26 17:47:42 +0200 | [diff] [blame] | 121 | // |2 ^ (simulcast_layers - 1)|. |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 122 | int NormalizeSimulcastSize(int size, size_t simulcast_layers) { |
| 123 | const int base2_exponent = static_cast<int>(simulcast_layers) - 1; |
| 124 | return ((size >> base2_exponent) << base2_exponent); |
| 125 | } |
| 126 | |
| 127 | size_t FindSimulcastMaxLayers(int width, int height) { |
| 128 | int index = FindSimulcastFormatIndex(width, height); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 129 | return kSimulcastFormats[index].max_layers; |
| 130 | } |
| 131 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 132 | int FindSimulcastMaxBitrateBps(int width, int height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 133 | const int format_index = FindSimulcastFormatIndex(width, height); |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 134 | return kSimulcastFormats[format_index].max_bitrate_kbps * 1000; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 135 | } |
| 136 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 137 | int FindSimulcastTargetBitrateBps(int width, int height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 138 | const int format_index = FindSimulcastFormatIndex(width, height); |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 139 | return kSimulcastFormats[format_index].target_bitrate_kbps * 1000; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 140 | } |
| 141 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 142 | int FindSimulcastMinBitrateBps(int width, int height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 143 | const int format_index = FindSimulcastFormatIndex(width, height); |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 144 | return kSimulcastFormats[format_index].min_bitrate_kbps * 1000; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Seth Hampson | 438663e | 2018-01-09 11:14:14 -0800 | [diff] [blame] | 147 | void SlotSimulcastMaxResolution(size_t max_layers, int* width, int* height) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 148 | int index = FindSimulcastFormatIndex(*width, *height, max_layers); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 149 | *width = kSimulcastFormats[index].width; |
| 150 | *height = kSimulcastFormats[index].height; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 151 | RTC_LOG(LS_INFO) << "SlotSimulcastMaxResolution to width:" << *width |
| 152 | << " height:" << *height; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 155 | void BoostMaxSimulcastLayer(int max_bitrate_bps, |
| 156 | std::vector<webrtc::VideoStream>* layers) { |
| 157 | // Spend additional bits to boost the max layer. |
| 158 | int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(*layers); |
| 159 | if (bitrate_left_bps > 0) { |
| 160 | layers->back().max_bitrate_bps += bitrate_left_bps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 161 | } |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | int GetTotalMaxBitrateBps(const std::vector<webrtc::VideoStream>& layers) { |
| 165 | int total_max_bitrate_bps = 0; |
| 166 | for (size_t s = 0; s < layers.size() - 1; ++s) { |
| 167 | total_max_bitrate_bps += layers[s].target_bitrate_bps; |
| 168 | } |
| 169 | total_max_bitrate_bps += layers.back().max_bitrate_bps; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 170 | return total_max_bitrate_bps; |
| 171 | } |
| 172 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 173 | std::vector<webrtc::VideoStream> GetSimulcastConfig(size_t max_layers, |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 174 | int width, |
| 175 | int height, |
| 176 | int max_bitrate_bps, |
| 177 | double bitrate_priority, |
| 178 | int max_qp, |
| 179 | int max_framerate, |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 180 | bool is_screenshare) { |
| 181 | if (is_screenshare) { |
| 182 | return GetScreenshareLayers(max_layers, width, height, max_bitrate_bps, |
| 183 | bitrate_priority, max_qp, max_framerate, |
| 184 | ScreenshareSimulcastFieldTrialEnabled()); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 185 | } else { |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 186 | return GetNormalSimulcastLayers(max_layers, width, height, max_bitrate_bps, |
| 187 | bitrate_priority, max_qp, max_framerate); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 188 | } |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 189 | } |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 190 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 191 | std::vector<webrtc::VideoStream> GetNormalSimulcastLayers( |
| 192 | size_t max_layers, |
| 193 | int width, |
| 194 | int height, |
| 195 | int max_bitrate_bps, |
| 196 | double bitrate_priority, |
| 197 | int max_qp, |
| 198 | int max_framerate) { |
| 199 | // TODO(bugs.webrtc.org/8785): Currently if the resolution isn't large enough |
| 200 | // (defined in kSimulcastFormats) we scale down the number of simulcast |
| 201 | // layers. Consider changing this so that the application can have more |
| 202 | // control over exactly how many simulcast layers are used. |
| 203 | size_t num_simulcast_layers = FindSimulcastMaxLayers(width, height); |
| 204 | if (num_simulcast_layers > max_layers) { |
| 205 | // TODO(bugs.webrtc.org/8486): This scales down the resolution if the |
| 206 | // number of simulcast layers created by the application isn't sufficient |
| 207 | // (defined in kSimulcastFormats). For example if the input frame's |
| 208 | // resolution is HD, but there are only 2 simulcast layers, the |
| 209 | // resolution gets scaled down to VGA. Consider taking this logic out to |
| 210 | // allow the application more control over the resolutions. |
| 211 | SlotSimulcastMaxResolution(max_layers, &width, &height); |
| 212 | num_simulcast_layers = max_layers; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 213 | } |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 214 | std::vector<webrtc::VideoStream> layers(num_simulcast_layers); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 215 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 216 | // Format width and height has to be divisible by |2 ^ num_simulcast_layers - |
| 217 | // 1|. |
| 218 | width = NormalizeSimulcastSize(width, num_simulcast_layers); |
| 219 | height = NormalizeSimulcastSize(height, num_simulcast_layers); |
| 220 | // Add simulcast streams, from highest resolution (|s| = num_simulcast_layers |
| 221 | // -1) to lowest resolution at |s| = 0. |
| 222 | for (size_t s = num_simulcast_layers - 1;; --s) { |
| 223 | layers[s].width = width; |
| 224 | layers[s].height = height; |
| 225 | // TODO(pbos): Fill actual temporal-layer bitrate thresholds. |
| 226 | layers[s].max_qp = max_qp; |
Erik Språng | bfe3d85 | 2018-05-15 09:54:14 +0200 | [diff] [blame] | 227 | layers[s].num_temporal_layers = DefaultNumberOfTemporalLayers(s); |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 228 | layers[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height); |
| 229 | layers[s].target_bitrate_bps = FindSimulcastTargetBitrateBps(width, height); |
| 230 | layers[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height); |
| 231 | layers[s].max_framerate = max_framerate; |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 232 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 233 | width /= 2; |
| 234 | height /= 2; |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 235 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 236 | if (s == 0) { |
| 237 | break; |
sprang | 02569ad | 2017-07-06 05:05:50 -0700 | [diff] [blame] | 238 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 239 | } |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 240 | // If there is bitrate leftover, give it to the largest layer. |
| 241 | BoostMaxSimulcastLayer(max_bitrate_bps, &layers); |
| 242 | // Currently the relative bitrate priority of the sender is controlled by |
| 243 | // the value of the lowest VideoStream. |
| 244 | // TODO(bugs.webrtc.org/8630): The web specification describes being able to |
| 245 | // control relative bitrate for each individual simulcast layer, but this |
| 246 | // is currently just implemented per rtp sender. |
| 247 | layers[0].bitrate_priority = bitrate_priority; |
| 248 | return layers; |
| 249 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 250 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 251 | std::vector<webrtc::VideoStream> GetScreenshareLayers( |
| 252 | size_t max_layers, |
| 253 | int width, |
| 254 | int height, |
| 255 | int max_bitrate_bps, |
| 256 | double bitrate_priority, |
| 257 | int max_qp, |
| 258 | int max_framerate, |
| 259 | bool screenshare_simulcast_enabled) { |
| 260 | auto max_screenshare_layers = |
| 261 | screenshare_simulcast_enabled ? kMaxScreenshareSimulcastLayers : 1; |
| 262 | size_t num_simulcast_layers = |
| 263 | std::min<int>(max_layers, max_screenshare_layers); |
| 264 | |
| 265 | std::vector<webrtc::VideoStream> layers(num_simulcast_layers); |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 266 | // For legacy screenshare in conference mode, tl0 and tl1 bitrates are |
| 267 | // piggybacked on the VideoCodec struct as target and max bitrates, |
Erik Språng | cc681cc | 2018-03-14 17:52:55 +0100 | [diff] [blame] | 268 | // respectively. See eg. webrtc::LibvpxVp8Encoder::SetRates(). |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 269 | layers[0].width = width; |
| 270 | layers[0].height = height; |
| 271 | layers[0].max_qp = max_qp; |
| 272 | layers[0].max_framerate = 5; |
| 273 | layers[0].min_bitrate_bps = kMinVideoBitrateBps; |
Rasmus Brandt | 195d1d7 | 2018-05-09 11:28:01 +0200 | [diff] [blame^] | 274 | layers[0].target_bitrate_bps = kScreenshareDefaultTl0BitrateKbps * 1000; |
| 275 | layers[0].max_bitrate_bps = kScreenshareDefaultTl1BitrateKbps * 1000; |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 276 | layers[0].num_temporal_layers = 2; |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 277 | |
| 278 | // With simulcast enabled, add another spatial layer. This one will have a |
| 279 | // more normal layout, with the regular 3 temporal layer pattern and no fps |
| 280 | // restrictions. The base simulcast layer will still use legacy setup. |
| 281 | if (num_simulcast_layers == kMaxScreenshareSimulcastLayers) { |
| 282 | // Add optional upper simulcast layer. |
| 283 | // Lowest temporal layers of a 3 layer setup will have 40% of the total |
| 284 | // bitrate allocation for that simulcast layer. Make sure the gap between |
| 285 | // the target of the lower simulcast layer and first temporal layer of the |
| 286 | // higher one is at most 2x the bitrate, so that upswitching is not hampered |
| 287 | // by stalled bitrate estimates. |
| 288 | int max_bitrate_bps = 2 * ((layers[0].target_bitrate_bps * 10) / 4); |
| 289 | // Cap max bitrate so it isn't overly high for the given resolution. |
| 290 | max_bitrate_bps = std::min<int>(max_bitrate_bps, |
| 291 | FindSimulcastMaxBitrateBps(width, height)); |
| 292 | |
| 293 | layers[1].width = width; |
| 294 | layers[1].height = height; |
| 295 | layers[1].max_qp = max_qp; |
| 296 | layers[1].max_framerate = max_framerate; |
Sergey Silkin | ca09125 | 2018-03-14 17:00:50 +0100 | [diff] [blame] | 297 | layers[1].num_temporal_layers = 3; |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 298 | layers[1].min_bitrate_bps = layers[0].target_bitrate_bps * 2; |
| 299 | layers[1].target_bitrate_bps = max_bitrate_bps; |
| 300 | layers[1].max_bitrate_bps = max_bitrate_bps; |
| 301 | } |
| 302 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 303 | // The bitrate priority currently implemented on a per-sender level, so we |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 304 | // just set it for the first simulcast layer. |
| 305 | layers[0].bitrate_priority = bitrate_priority; |
| 306 | return layers; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Seth Hampson | 1370e30 | 2018-02-07 08:50:36 -0800 | [diff] [blame] | 309 | bool ScreenshareSimulcastFieldTrialEnabled() { |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame] | 310 | return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 311 | } |
| 312 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 313 | } // namespace cricket |