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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 279 } |
280 | 280 |
281 int GetDefaultVp9TemporalLayers() { | 281 int GetDefaultVp9TemporalLayers() { |
282 int num_sl; | 282 int num_sl; |
283 int num_tl; | 283 int num_tl; |
284 if (GetVp9LayersFromFieldTrialGroup(&num_sl, &num_tl)) { | 284 if (GetVp9LayersFromFieldTrialGroup(&num_sl, &num_tl)) { |
285 return num_tl; | 285 return num_tl; |
286 } | 286 } |
287 return 1; | 287 return 1; |
288 } | 288 } |
289 | |
290 class EncoderStreamFactory | |
291 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface { | |
292 public: | |
293 EncoderStreamFactory(std::string codec_name, | |
294 int max_qp, | |
295 int max_framerate, | |
296 bool is_screencast, | |
297 bool conference_mode) | |
298 : codec_name_(codec_name), | |
299 max_qp_(max_qp), | |
300 max_framerate_(max_framerate), | |
301 is_screencast_(is_screencast), | |
302 conference_mode_(conference_mode) {} | |
303 | |
304 private: | |
305 std::vector<webrtc::VideoStream> CreateEncoderStreams( | |
306 int width, | |
307 int height, | |
308 const webrtc::VideoEncoderConfig& encoder_config) override { | |
309 if (is_screencast_ && | |
310 (!conference_mode_ || !cricket::UseSimulcastScreenshare())) { | |
311 RTC_DCHECK_EQ(1, encoder_config.number_of_streams); | |
312 } | |
313 if (encoder_config.number_of_streams > 1 || | |
314 (CodecNamesEq(codec_name_, kVp8CodecName) && is_screencast_ && | |
315 conference_mode_)) { | |
316 return GetSimulcastConfig(encoder_config.number_of_streams, width, height, | |
317 encoder_config.max_bitrate_bps, max_qp_, | |
318 max_framerate_, is_screencast_); | |
319 } | |
320 | |
321 // For unset max bitrates set default bitrate for non-simulcast. | |
322 int max_bitrate_bps = | |
323 (encoder_config.max_bitrate_bps > 0) | |
324 ? encoder_config.max_bitrate_bps | |
325 : GetMaxDefaultVideoBitrateKbps(width, height) * 1000; | |
326 | |
327 webrtc::VideoStream stream; | |
328 stream.width = width; | |
329 stream.height = height; | |
330 stream.max_framerate = max_framerate_; | |
331 stream.min_bitrate_bps = kMinVideoBitrateKbps * 1000; | |
332 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; | |
333 stream.max_qp = max_qp_; | |
334 | |
335 if (CodecNamesEq(codec_name_, kVp9CodecName) && !is_screencast_) { | |
336 stream.temporal_layer_thresholds_bps.resize( | |
337 GetDefaultVp9TemporalLayers() - 1); | |
338 } | |
339 | |
340 std::vector<webrtc::VideoStream> streams; | |
341 streams.push_back(stream); | |
342 return streams; | |
343 } | |
344 | |
345 const std::string codec_name_; | |
346 const int max_qp_; | |
347 const int max_framerate_; | |
348 const bool is_screencast_; | |
349 const bool conference_mode_; | |
350 }; | |
351 | |
352 } // namespace | 289 } // namespace |
353 | 290 |
354 // Constants defined in webrtc/media/engine/constants.h | 291 // Constants defined in webrtc/media/engine/constants.h |
355 // TODO(pbos): Move these to a separate constants.cc file. | 292 // TODO(pbos): Move these to a separate constants.cc file. |
356 const int kMinVideoBitrateKbps = 30; | 293 const int kMinVideoBitrateKbps = 30; |
357 | 294 |
358 const int kVideoMtu = 1200; | 295 const int kVideoMtu = 1200; |
359 const int kVideoRtpBufferSize = 65536; | 296 const int kVideoRtpBufferSize = 65536; |
360 | 297 |
361 // This constant is really an on/off, lower-level configurable NACK history | 298 // This constant is really an on/off, lower-level configurable NACK history |
(...skipping 2309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2671 if (rtx_mapping[video_codecs[i].codec.id] != 0 && | 2608 if (rtx_mapping[video_codecs[i].codec.id] != 0 && |
2672 rtx_mapping[video_codecs[i].codec.id] != | 2609 rtx_mapping[video_codecs[i].codec.id] != |
2673 ulpfec_config.red_payload_type) { | 2610 ulpfec_config.red_payload_type) { |
2674 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2611 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2675 } | 2612 } |
2676 } | 2613 } |
2677 | 2614 |
2678 return video_codecs; | 2615 return video_codecs; |
2679 } | 2616 } |
2680 | 2617 |
| 2618 EncoderStreamFactory::EncoderStreamFactory(std::string codec_name, |
| 2619 int max_qp, |
| 2620 int max_framerate, |
| 2621 bool is_screencast, |
| 2622 bool conference_mode) |
| 2623 : codec_name_(codec_name), |
| 2624 max_qp_(max_qp), |
| 2625 max_framerate_(max_framerate), |
| 2626 is_screencast_(is_screencast), |
| 2627 conference_mode_(conference_mode) {} |
| 2628 |
| 2629 std::vector<webrtc::VideoStream> EncoderStreamFactory::CreateEncoderStreams( |
| 2630 int width, |
| 2631 int height, |
| 2632 const webrtc::VideoEncoderConfig& encoder_config) { |
| 2633 if (is_screencast_ && |
| 2634 (!conference_mode_ || !cricket::UseSimulcastScreenshare())) { |
| 2635 RTC_DCHECK_EQ(1, encoder_config.number_of_streams); |
| 2636 } |
| 2637 if (encoder_config.number_of_streams > 1 || |
| 2638 (CodecNamesEq(codec_name_, kVp8CodecName) && is_screencast_ && |
| 2639 conference_mode_)) { |
| 2640 return GetSimulcastConfig(encoder_config.number_of_streams, width, height, |
| 2641 encoder_config.max_bitrate_bps, max_qp_, |
| 2642 max_framerate_, is_screencast_); |
| 2643 } |
| 2644 |
| 2645 // For unset max bitrates set default bitrate for non-simulcast. |
| 2646 int max_bitrate_bps = |
| 2647 (encoder_config.max_bitrate_bps > 0) |
| 2648 ? encoder_config.max_bitrate_bps |
| 2649 : GetMaxDefaultVideoBitrateKbps(width, height) * 1000; |
| 2650 |
| 2651 webrtc::VideoStream stream; |
| 2652 stream.width = width; |
| 2653 stream.height = height; |
| 2654 stream.max_framerate = max_framerate_; |
| 2655 stream.min_bitrate_bps = kMinVideoBitrateKbps * 1000; |
| 2656 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; |
| 2657 stream.max_qp = max_qp_; |
| 2658 |
| 2659 if (CodecNamesEq(codec_name_, kVp9CodecName) && !is_screencast_) { |
| 2660 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - |
| 2661 1); |
| 2662 } |
| 2663 |
| 2664 std::vector<webrtc::VideoStream> streams; |
| 2665 streams.push_back(stream); |
| 2666 return streams; |
| 2667 } |
| 2668 |
2681 } // namespace cricket | 2669 } // namespace cricket |
OLD | NEW |