OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 31 matching lines...) Loading... |
42 const SimulcastFormat kSimulcastFormats[] = { | 42 const SimulcastFormat kSimulcastFormats[] = { |
43 {1920, 1080, 3, 5000, 4000, 800}, | 43 {1920, 1080, 3, 5000, 4000, 800}, |
44 {1280, 720, 3, 2500, 2500, 600}, | 44 {1280, 720, 3, 2500, 2500, 600}, |
45 {960, 540, 3, 900, 900, 450}, | 45 {960, 540, 3, 900, 900, 450}, |
46 {640, 360, 2, 700, 500, 150}, | 46 {640, 360, 2, 700, 500, 150}, |
47 {480, 270, 2, 450, 350, 150}, | 47 {480, 270, 2, 450, 350, 150}, |
48 {320, 180, 1, 200, 150, 30}, | 48 {320, 180, 1, 200, 150, 30}, |
49 {0, 0, 1, 200, 150, 30} | 49 {0, 0, 1, 200, 150, 30} |
50 }; | 50 }; |
51 | 51 |
52 const int kDefaultScreenshareSimulcastStreams = 2; | 52 const int kMaxScreenshareSimulcastStreams = 2; |
53 | 53 |
54 // Multiway: Number of temporal layers for each simulcast stream, for maximum | 54 // Multiway: Number of temporal layers for each simulcast stream, for maximum |
55 // possible number of simulcast streams |kMaxSimulcastStreams|. The array | 55 // possible number of simulcast streams |kMaxSimulcastStreams|. The array |
56 // goes from lowest resolution at position 0 to highest resolution. | 56 // goes from lowest resolution at position 0 to highest resolution. |
57 // For example, first three elements correspond to say: QVGA, VGA, WHD. | 57 // For example, first three elements correspond to say: QVGA, VGA, WHD. |
58 static const int | 58 static const int |
59 kDefaultConferenceNumberOfTemporalLayers[webrtc::kMaxSimulcastStreams] = | 59 kDefaultConferenceNumberOfTemporalLayers[webrtc::kMaxSimulcastStreams] = |
60 {3, 3, 3, 3}; | 60 {3, 3, 3, 3}; |
61 | 61 |
62 void GetSimulcastSsrcs(const StreamParams& sp, std::vector<uint32_t>* ssrcs) { | 62 void GetSimulcastSsrcs(const StreamParams& sp, std::vector<uint32_t>* ssrcs) { |
(...skipping 106 matching lines...) Loading... |
169 | 169 |
170 std::vector<webrtc::VideoStream> GetSimulcastConfig(size_t max_streams, | 170 std::vector<webrtc::VideoStream> GetSimulcastConfig(size_t max_streams, |
171 int width, | 171 int width, |
172 int height, | 172 int height, |
173 int max_bitrate_bps, | 173 int max_bitrate_bps, |
174 int max_qp, | 174 int max_qp, |
175 int max_framerate, | 175 int max_framerate, |
176 bool is_screencast) { | 176 bool is_screencast) { |
177 size_t num_simulcast_layers; | 177 size_t num_simulcast_layers; |
178 if (is_screencast) { | 178 if (is_screencast) { |
179 num_simulcast_layers = | 179 if (UseSimulcastScreenshare()) { |
180 UseSimulcastScreenshare() ? kDefaultScreenshareSimulcastStreams : 1; | 180 num_simulcast_layers = |
| 181 std::min<int>(max_streams, kMaxScreenshareSimulcastStreams); |
| 182 } else { |
| 183 num_simulcast_layers = 1; |
| 184 } |
181 } else { | 185 } else { |
182 num_simulcast_layers = FindSimulcastMaxLayers(width, height); | 186 num_simulcast_layers = FindSimulcastMaxLayers(width, height); |
183 } | 187 } |
184 | 188 |
185 if (num_simulcast_layers > max_streams) { | 189 if (num_simulcast_layers > max_streams) { |
186 // If the number of SSRCs in the group differs from our target | 190 // If the number of SSRCs in the group differs from our target |
187 // number of simulcast streams for current resolution, switch down | 191 // number of simulcast streams for current resolution, switch down |
188 // to a resolution that matches our number of SSRCs. | 192 // to a resolution that matches our number of SSRCs. |
189 if (!SlotSimulcastMaxResolution(max_streams, &width, &height)) { | 193 if (!SlotSimulcastMaxResolution(max_streams, &width, &height)) { |
190 return std::vector<webrtc::VideoStream>(); | 194 return std::vector<webrtc::VideoStream>(); |
191 } | 195 } |
192 num_simulcast_layers = max_streams; | 196 num_simulcast_layers = max_streams; |
193 } | 197 } |
194 std::vector<webrtc::VideoStream> streams; | 198 std::vector<webrtc::VideoStream> streams; |
195 streams.resize(num_simulcast_layers); | 199 streams.resize(num_simulcast_layers); |
196 | 200 |
197 if (!is_screencast) { | 201 if (is_screencast) { |
| 202 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |
| 203 // For legacy screenshare in conference mode, tl0 and tl1 bitrates are |
| 204 // piggybacked on the VideoCodec struct as target and max bitrates, |
| 205 // respectively. See eg. webrtc::VP8EncoderImpl::SetRates(). |
| 206 streams[0].width = width; |
| 207 streams[0].height = height; |
| 208 streams[0].max_qp = max_qp; |
| 209 streams[0].max_framerate = 5; |
| 210 streams[0].min_bitrate_bps = kMinVideoBitrateKbps * 1000; |
| 211 streams[0].target_bitrate_bps = config.tl0_bitrate_kbps * 1000; |
| 212 streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; |
| 213 streams[0].temporal_layer_thresholds_bps.clear(); |
| 214 streams[0].temporal_layer_thresholds_bps.push_back(config.tl0_bitrate_kbps * |
| 215 1000); |
| 216 |
| 217 // With simulcast enabled, add another spatial layer. This one will have a |
| 218 // more normal layout, with the regular 3 temporal layer pattern and no fps |
| 219 // restrictions. The base simulcast stream will still use legacy setup. |
| 220 if (num_simulcast_layers == kMaxScreenshareSimulcastStreams) { |
| 221 // Add optional upper simulcast layer. |
| 222 // Lowest temporal layers of a 3 layer setup will have 40% of the total |
| 223 // bitrate allocation for that stream. Make sure the gap between the |
| 224 // target of the lower stream and first temporal layer of the higher one |
| 225 // is at most 2x the bitrate, so that upswitching is not hampered by |
| 226 // stalled bitrate estimates. |
| 227 int max_bitrate_bps = 2 * ((streams[0].target_bitrate_bps * 10) / 4); |
| 228 // Cap max bitrate so it isn't overly high for the given resolution. |
| 229 max_bitrate_bps = std::min<int>( |
| 230 max_bitrate_bps, FindSimulcastMaxBitrateBps(width, height)); |
| 231 |
| 232 streams[1].width = width; |
| 233 streams[1].height = height; |
| 234 streams[1].max_qp = max_qp; |
| 235 streams[1].max_framerate = max_framerate; |
| 236 // Three temporal layers means two thresholds. |
| 237 streams[1].temporal_layer_thresholds_bps.resize(2); |
| 238 streams[1].min_bitrate_bps = streams[0].target_bitrate_bps * 2; |
| 239 streams[1].target_bitrate_bps = max_bitrate_bps; |
| 240 streams[1].max_bitrate_bps = max_bitrate_bps; |
| 241 } |
| 242 } else { |
198 // Format width and height has to be divisible by |2 ^ number_streams - 1|. | 243 // Format width and height has to be divisible by |2 ^ number_streams - 1|. |
199 width = NormalizeSimulcastSize(width, num_simulcast_layers); | 244 width = NormalizeSimulcastSize(width, num_simulcast_layers); |
200 height = NormalizeSimulcastSize(height, num_simulcast_layers); | 245 height = NormalizeSimulcastSize(height, num_simulcast_layers); |
201 } | |
202 | 246 |
203 // Add simulcast sub-streams from lower resolution to higher resolutions. | 247 // Add simulcast sub-streams from lower resolution to higher resolutions. |
204 // Add simulcast streams, from highest resolution (|s| = number_streams -1) | 248 // Add simulcast streams, from highest resolution (|s| = number_streams -1) |
205 // to lowest resolution at |s| = 0. | 249 // to lowest resolution at |s| = 0. |
206 for (size_t s = num_simulcast_layers - 1;; --s) { | 250 for (size_t s = num_simulcast_layers - 1;; --s) { |
207 streams[s].width = width; | 251 streams[s].width = width; |
208 streams[s].height = height; | 252 streams[s].height = height; |
209 // TODO(pbos): Fill actual temporal-layer bitrate thresholds. | 253 // TODO(pbos): Fill actual temporal-layer bitrate thresholds. |
210 streams[s].max_qp = max_qp; | 254 streams[s].max_qp = max_qp; |
211 if (is_screencast && s == 0) { | |
212 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | |
213 // For legacy screenshare in conference mode, tl0 and tl1 bitrates are | |
214 // piggybacked on the VideoCodec struct as target and max bitrates, | |
215 // respectively. See eg. webrtc::VP8EncoderImpl::SetRates(). | |
216 streams[s].min_bitrate_bps = kMinVideoBitrateKbps * 1000; | |
217 streams[s].target_bitrate_bps = config.tl0_bitrate_kbps * 1000; | |
218 streams[s].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; | |
219 streams[s].temporal_layer_thresholds_bps.clear(); | |
220 streams[s].temporal_layer_thresholds_bps.push_back( | |
221 config.tl0_bitrate_kbps * 1000); | |
222 streams[s].max_framerate = 5; | |
223 } else { | |
224 streams[s].temporal_layer_thresholds_bps.resize( | 255 streams[s].temporal_layer_thresholds_bps.resize( |
225 kDefaultConferenceNumberOfTemporalLayers[s] - 1); | 256 kDefaultConferenceNumberOfTemporalLayers[s] - 1); |
226 streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height); | 257 streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height); |
227 streams[s].target_bitrate_bps = | 258 streams[s].target_bitrate_bps = |
228 FindSimulcastTargetBitrateBps(width, height); | 259 FindSimulcastTargetBitrateBps(width, height); |
229 streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height); | 260 streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height); |
230 streams[s].max_framerate = max_framerate; | 261 streams[s].max_framerate = max_framerate; |
| 262 |
| 263 width /= 2; |
| 264 height /= 2; |
| 265 |
| 266 if (s == 0) |
| 267 break; |
231 } | 268 } |
232 | 269 |
233 if (!is_screencast) { | 270 // Spend additional bits to boost the max stream. |
234 width /= 2; | 271 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams); |
235 height /= 2; | 272 if (bitrate_left_bps > 0) { |
| 273 streams.back().max_bitrate_bps += bitrate_left_bps; |
236 } | 274 } |
237 if (s == 0) | |
238 break; | |
239 } | |
240 | |
241 // Spend additional bits to boost the max stream. | |
242 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams); | |
243 if (bitrate_left_bps > 0) { | |
244 streams.back().max_bitrate_bps += bitrate_left_bps; | |
245 } | 275 } |
246 | 276 |
247 return streams; | 277 return streams; |
248 } | 278 } |
249 | 279 |
250 static const int kScreenshareMinBitrateKbps = 50; | 280 static const int kScreenshareMinBitrateKbps = 50; |
251 static const int kScreenshareMaxBitrateKbps = 6000; | 281 static const int kScreenshareMaxBitrateKbps = 6000; |
252 static const int kScreenshareDefaultTl0BitrateKbps = 200; | 282 static const int kScreenshareDefaultTl0BitrateKbps = 200; |
253 static const int kScreenshareDefaultTl1BitrateKbps = 1000; | 283 static const int kScreenshareDefaultTl1BitrateKbps = 1000; |
254 | 284 |
(...skipping 41 matching lines...) Loading... |
296 config->tl1_bitrate_kbps = tl1_bitrate; | 326 config->tl1_bitrate_kbps = tl1_bitrate; |
297 | 327 |
298 return true; | 328 return true; |
299 } | 329 } |
300 | 330 |
301 bool UseSimulcastScreenshare() { | 331 bool UseSimulcastScreenshare() { |
302 return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName); | 332 return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName); |
303 } | 333 } |
304 | 334 |
305 } // namespace cricket | 335 } // namespace cricket |
OLD | NEW |