Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: webrtc/media/engine/simulcast.cc

Issue 2791273002: Update screen simulcast config and fix periodic encoder param update (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/test/fake_encoder.h » ('j') | webrtc/video/vie_encoder.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, kDefaultScreenshareSimulcastStreams);
stefan-webrtc 2017/04/05 15:06:48 kDefaultScreenshareSimulcastStreams should maybe b
sprang_webrtc 2017/05/08 08:50:53 Sure.
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) {
stefan-webrtc 2017/04/05 15:06:48 I think it would be good to have a general comment
sprang_webrtc 2017/05/08 08:50:53 Added comments. In both cases we use the legacy sc
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);
stefan-webrtc 2017/04/05 15:06:48 Looks like we're doing 2 temporal layers here, and
sprang_webrtc 2017/05/08 08:50:53 Yes, that's the idea.
216
217 if (num_simulcast_layers == 2) {
stefan-webrtc 2017/04/05 15:06:48 Should this be kDefaultScreenshareSimulcastStreams
sprang_webrtc 2017/05/08 08:50:53 Done.
218 // Add optional upper simulcast layer.
219 // Lowest temporal layers of a 3 layer setup will have 40% of the total
220 // bitrate allocation for that stream. Make sure the gap between the
221 // target of the lower stream and first temporal layer of the higher one
222 // is at most 2x the bitrate, so that upswitching is not hampered by
223 // stalled bitrate estimates.
stefan-webrtc 2017/04/05 15:06:48 I don't fully understand this. Why would the bitra
sprang_webrtc 2017/05/08 08:50:53 We do at the source, yes. But there is no guarante
224 int max_bitrate_bps = 2 * ((streams[0].target_bitrate_bps * 10) / 4);
225 // Cap max bitrate so it isn't overly high for the given resolution.
226 max_bitrate_bps = std::min<int>(
227 max_bitrate_bps, FindSimulcastMaxBitrateBps(width, height));
228
229 streams[1].width = width;
230 streams[1].height = height;
231 streams[1].max_qp = max_qp;
232 streams[1].max_framerate = max_framerate;
233 // Three temporal layers means two thresholds.
234 streams[1].temporal_layer_thresholds_bps.resize(2);
235 streams[1].min_bitrate_bps = streams[0].target_bitrate_bps * 2;
236 streams[1].target_bitrate_bps = max_bitrate_bps;
237 streams[1].max_bitrate_bps = max_bitrate_bps;
238 }
239 } else {
198 // Format width and height has to be divisible by |2 ^ number_streams - 1|. 240 // Format width and height has to be divisible by |2 ^ number_streams - 1|.
199 width = NormalizeSimulcastSize(width, num_simulcast_layers); 241 width = NormalizeSimulcastSize(width, num_simulcast_layers);
200 height = NormalizeSimulcastSize(height, num_simulcast_layers); 242 height = NormalizeSimulcastSize(height, num_simulcast_layers);
201 }
202 243
203 // Add simulcast sub-streams from lower resolution to higher resolutions. 244 // Add simulcast sub-streams from lower resolution to higher resolutions.
204 // Add simulcast streams, from highest resolution (|s| = number_streams -1) 245 // Add simulcast streams, from highest resolution (|s| = number_streams -1)
205 // to lowest resolution at |s| = 0. 246 // to lowest resolution at |s| = 0.
206 for (size_t s = num_simulcast_layers - 1;; --s) { 247 for (size_t s = num_simulcast_layers - 1;; --s) {
207 streams[s].width = width; 248 streams[s].width = width;
208 streams[s].height = height; 249 streams[s].height = height;
209 // TODO(pbos): Fill actual temporal-layer bitrate thresholds. 250 // TODO(pbos): Fill actual temporal-layer bitrate thresholds.
210 streams[s].max_qp = max_qp; 251 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( 252 streams[s].temporal_layer_thresholds_bps.resize(
225 kDefaultConferenceNumberOfTemporalLayers[s] - 1); 253 kDefaultConferenceNumberOfTemporalLayers[s] - 1);
226 streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height); 254 streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height);
227 streams[s].target_bitrate_bps = 255 streams[s].target_bitrate_bps =
228 FindSimulcastTargetBitrateBps(width, height); 256 FindSimulcastTargetBitrateBps(width, height);
229 streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height); 257 streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height);
230 streams[s].max_framerate = max_framerate; 258 streams[s].max_framerate = max_framerate;
259
260 if (!is_screencast) {
stefan-webrtc 2017/04/05 15:06:48 This is always true AFAICT?
sprang_webrtc 2017/05/08 08:50:53 Done.
261 width /= 2;
262 height /= 2;
263 }
264 if (s == 0)
265 break;
231 } 266 }
232 267
233 if (!is_screencast) { 268 // Spend additional bits to boost the max stream.
234 width /= 2; 269 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams);
235 height /= 2; 270 if (bitrate_left_bps > 0) {
271 streams.back().max_bitrate_bps += bitrate_left_bps;
236 } 272 }
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 } 273 }
246 274
247 return streams; 275 return streams;
248 } 276 }
249 277
250 static const int kScreenshareMinBitrateKbps = 50; 278 static const int kScreenshareMinBitrateKbps = 50;
251 static const int kScreenshareMaxBitrateKbps = 6000; 279 static const int kScreenshareMaxBitrateKbps = 6000;
252 static const int kScreenshareDefaultTl0BitrateKbps = 200; 280 static const int kScreenshareDefaultTl0BitrateKbps = 200;
253 static const int kScreenshareDefaultTl1BitrateKbps = 1000; 281 static const int kScreenshareDefaultTl1BitrateKbps = 1000;
254 282
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 config->tl1_bitrate_kbps = tl1_bitrate; 324 config->tl1_bitrate_kbps = tl1_bitrate;
297 325
298 return true; 326 return true;
299 } 327 }
300 328
301 bool UseSimulcastScreenshare() { 329 bool UseSimulcastScreenshare() {
302 return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName); 330 return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName);
303 } 331 }
304 332
305 } // namespace cricket 333 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | webrtc/test/fake_encoder.h » ('j') | webrtc/video/vie_encoder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698