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

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

Issue 2953053002: Reland of Periodically update codec bit/frame rate settings. (Closed)
Patch Set: Fix bug and add test Created 3 years, 6 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 | « webrtc/call/rampup_tests.cc ('k') | webrtc/modules/video_coding/media_optimization.cc » ('j') | no next file with comments »
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 kMaxScreenshareSimulcastStreams = 2; 52 const int kDefaultScreenshareSimulcastStreams = 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...) 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 if (UseSimulcastScreenshare()) { 179 num_simulcast_layers =
180 num_simulcast_layers = 180 UseSimulcastScreenshare() ? kDefaultScreenshareSimulcastStreams : 1;
181 std::min<int>(max_streams, kMaxScreenshareSimulcastStreams);
182 } else {
183 num_simulcast_layers = 1;
184 }
185 } else { 181 } else {
186 num_simulcast_layers = FindSimulcastMaxLayers(width, height); 182 num_simulcast_layers = FindSimulcastMaxLayers(width, height);
187 } 183 }
188 184
189 if (num_simulcast_layers > max_streams) { 185 if (num_simulcast_layers > max_streams) {
190 // If the number of SSRCs in the group differs from our target 186 // If the number of SSRCs in the group differs from our target
191 // number of simulcast streams for current resolution, switch down 187 // number of simulcast streams for current resolution, switch down
192 // to a resolution that matches our number of SSRCs. 188 // to a resolution that matches our number of SSRCs.
193 if (!SlotSimulcastMaxResolution(max_streams, &width, &height)) { 189 if (!SlotSimulcastMaxResolution(max_streams, &width, &height)) {
194 return std::vector<webrtc::VideoStream>(); 190 return std::vector<webrtc::VideoStream>();
195 } 191 }
196 num_simulcast_layers = max_streams; 192 num_simulcast_layers = max_streams;
197 } 193 }
198 std::vector<webrtc::VideoStream> streams; 194 std::vector<webrtc::VideoStream> streams;
199 streams.resize(num_simulcast_layers); 195 streams.resize(num_simulcast_layers);
200 196
201 if (is_screencast) { 197 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 {
243 // Format width and height has to be divisible by |2 ^ number_streams - 1|. 198 // Format width and height has to be divisible by |2 ^ number_streams - 1|.
244 width = NormalizeSimulcastSize(width, num_simulcast_layers); 199 width = NormalizeSimulcastSize(width, num_simulcast_layers);
245 height = NormalizeSimulcastSize(height, num_simulcast_layers); 200 height = NormalizeSimulcastSize(height, num_simulcast_layers);
201 }
246 202
247 // Add simulcast sub-streams from lower resolution to higher resolutions. 203 // Add simulcast sub-streams from lower resolution to higher resolutions.
248 // Add simulcast streams, from highest resolution (|s| = number_streams -1) 204 // Add simulcast streams, from highest resolution (|s| = number_streams -1)
249 // to lowest resolution at |s| = 0. 205 // to lowest resolution at |s| = 0.
250 for (size_t s = num_simulcast_layers - 1;; --s) { 206 for (size_t s = num_simulcast_layers - 1;; --s) {
251 streams[s].width = width; 207 streams[s].width = width;
252 streams[s].height = height; 208 streams[s].height = height;
253 // TODO(pbos): Fill actual temporal-layer bitrate thresholds. 209 // TODO(pbos): Fill actual temporal-layer bitrate thresholds.
254 streams[s].max_qp = max_qp; 210 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 {
255 streams[s].temporal_layer_thresholds_bps.resize( 224 streams[s].temporal_layer_thresholds_bps.resize(
256 kDefaultConferenceNumberOfTemporalLayers[s] - 1); 225 kDefaultConferenceNumberOfTemporalLayers[s] - 1);
257 streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height); 226 streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height);
258 streams[s].target_bitrate_bps = 227 streams[s].target_bitrate_bps =
259 FindSimulcastTargetBitrateBps(width, height); 228 FindSimulcastTargetBitrateBps(width, height);
260 streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height); 229 streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height);
261 streams[s].max_framerate = max_framerate; 230 streams[s].max_framerate = max_framerate;
231 }
262 232
233 if (!is_screencast) {
263 width /= 2; 234 width /= 2;
264 height /= 2; 235 height /= 2;
236 }
237 if (s == 0)
238 break;
239 }
265 240
266 if (s == 0) 241 // Spend additional bits to boost the max stream.
267 break; 242 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams);
268 } 243 if (bitrate_left_bps > 0) {
269 244 streams.back().max_bitrate_bps += bitrate_left_bps;
270 // Spend additional bits to boost the max stream.
271 int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams);
272 if (bitrate_left_bps > 0) {
273 streams.back().max_bitrate_bps += bitrate_left_bps;
274 }
275 } 245 }
276 246
277 return streams; 247 return streams;
278 } 248 }
279 249
280 static const int kScreenshareMinBitrateKbps = 50; 250 static const int kScreenshareMinBitrateKbps = 50;
281 static const int kScreenshareMaxBitrateKbps = 6000; 251 static const int kScreenshareMaxBitrateKbps = 6000;
282 static const int kScreenshareDefaultTl0BitrateKbps = 200; 252 static const int kScreenshareDefaultTl0BitrateKbps = 200;
283 static const int kScreenshareDefaultTl1BitrateKbps = 1000; 253 static const int kScreenshareDefaultTl1BitrateKbps = 1000;
284 254
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 config->tl1_bitrate_kbps = tl1_bitrate; 296 config->tl1_bitrate_kbps = tl1_bitrate;
327 297
328 return true; 298 return true;
329 } 299 }
330 300
331 bool UseSimulcastScreenshare() { 301 bool UseSimulcastScreenshare() {
332 return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName); 302 return webrtc::field_trial::IsEnabled(kSimulcastScreenshareFieldTrialName);
333 } 303 }
334 304
335 } // namespace cricket 305 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/call/rampup_tests.cc ('k') | webrtc/modules/video_coding/media_optimization.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698