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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 } | 71 } |
72 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) && | 72 if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) && |
73 bitrate_kbps > 0) { | 73 bitrate_kbps > 0) { |
74 config.start_bitrate_bps = bitrate_kbps * 1000; | 74 config.start_bitrate_bps = bitrate_kbps * 1000; |
75 } else { | 75 } else { |
76 // Do not reconfigure start bitrate unless it's specified and positive. | 76 // Do not reconfigure start bitrate unless it's specified and positive. |
77 config.start_bitrate_bps = -1; | 77 config.start_bitrate_bps = -1; |
78 } | 78 } |
79 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) && | 79 if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) && |
80 bitrate_kbps > 0) { | 80 bitrate_kbps > 0) { |
81 config.max_bitrate_bps = bitrate_kbps * 1000; | 81 config.max_bitrate_bps = rtc::Optional<int>(bitrate_kbps * 1000); |
82 } else { | 82 } else { |
83 config.max_bitrate_bps = -1; | 83 config.max_bitrate_bps = rtc::Optional<int>(); |
84 } | 84 } |
85 return config; | 85 return config; |
86 } | 86 } |
87 | 87 |
88 // An encoder factory that wraps Create requests for simulcastable codec types | 88 // An encoder factory that wraps Create requests for simulcastable codec types |
89 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type | 89 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type |
90 // requests are just passed through to the contained encoder factory. | 90 // requests are just passed through to the contained encoder factory. |
91 class WebRtcSimulcastEncoderFactory | 91 class WebRtcSimulcastEncoderFactory |
92 : public cricket::WebRtcVideoEncoderFactory { | 92 : public cricket::WebRtcVideoEncoderFactory { |
93 public: | 93 public: |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 codecs.push_back( | 355 codecs.push_back( |
356 VideoCodec::CreateRtxCodec(kDefaultRtxRedPlType, kDefaultRedPlType)); | 356 VideoCodec::CreateRtxCodec(kDefaultRtxRedPlType, kDefaultRedPlType)); |
357 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); | 357 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); |
358 return codecs; | 358 return codecs; |
359 } | 359 } |
360 | 360 |
361 std::vector<webrtc::VideoStream> | 361 std::vector<webrtc::VideoStream> |
362 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( | 362 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( |
363 const VideoCodec& codec, | 363 const VideoCodec& codec, |
364 const VideoOptions& options, | 364 const VideoOptions& options, |
365 int max_bitrate_bps, | 365 rtc::Optional<int> max_bitrate_bps, |
366 size_t num_streams) { | 366 size_t num_streams) { |
367 int max_qp = kDefaultQpMax; | 367 int max_qp = kDefaultQpMax; |
368 codec.GetParam(kCodecParamMaxQuantization, &max_qp); | 368 codec.GetParam(kCodecParamMaxQuantization, &max_qp); |
369 | 369 |
370 // TODO(skvlad): Consider replacing special case constants with | |
371 // rtc::Optional<int> | |
370 return GetSimulcastConfig( | 372 return GetSimulcastConfig( |
371 num_streams, codec.width, codec.height, max_bitrate_bps, max_qp, | 373 num_streams, codec.width, codec.height, max_bitrate_bps, max_qp, |
372 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); | 374 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); |
373 } | 375 } |
374 | 376 |
375 std::vector<webrtc::VideoStream> | 377 std::vector<webrtc::VideoStream> |
376 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( | 378 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( |
377 const VideoCodec& codec, | 379 const VideoCodec& codec, |
378 const VideoOptions& options, | 380 const VideoOptions& options, |
379 int max_bitrate_bps, | 381 rtc::Optional<int> max_bitrate_bps, |
380 size_t num_streams) { | 382 size_t num_streams) { |
381 int codec_max_bitrate_kbps; | 383 int codec_max_bitrate_kbps; |
382 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { | 384 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { |
383 max_bitrate_bps = codec_max_bitrate_kbps * 1000; | 385 max_bitrate_bps = rtc::Optional<int>(codec_max_bitrate_kbps * 1000); |
384 } | 386 } |
385 if (num_streams != 1) { | 387 if (num_streams != 1) { |
386 return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, | 388 return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, |
387 num_streams); | 389 num_streams); |
388 } | 390 } |
389 | 391 |
390 // For unset max bitrates set default bitrate for non-simulcast. | 392 // For unset max bitrates set default bitrate for non-simulcast. |
391 if (max_bitrate_bps <= 0) { | 393 if (!max_bitrate_bps) { |
392 max_bitrate_bps = | 394 max_bitrate_bps = rtc::Optional<int>( |
393 GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000; | 395 GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000); |
394 } | 396 } |
395 | 397 |
396 webrtc::VideoStream stream; | 398 webrtc::VideoStream stream; |
397 stream.width = codec.width; | 399 stream.width = codec.width; |
398 stream.height = codec.height; | 400 stream.height = codec.height; |
399 stream.max_framerate = | 401 stream.max_framerate = |
400 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; | 402 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; |
401 | 403 |
402 stream.min_bitrate_bps = kMinVideoBitrate * 1000; | 404 stream.min_bitrate_bps = kMinVideoBitrate * 1000; |
403 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; | 405 stream.target_bitrate_bps = stream.max_bitrate_bps = *max_bitrate_bps; |
404 | 406 |
405 int max_qp = kDefaultQpMax; | 407 int max_qp = kDefaultQpMax; |
406 codec.GetParam(kCodecParamMaxQuantization, &max_qp); | 408 codec.GetParam(kCodecParamMaxQuantization, &max_qp); |
407 stream.max_qp = max_qp; | 409 stream.max_qp = max_qp; |
408 std::vector<webrtc::VideoStream> streams; | 410 std::vector<webrtc::VideoStream> streams; |
409 streams.push_back(stream); | 411 streams.push_back(stream); |
410 return streams; | 412 return streams; |
411 } | 413 } |
412 | 414 |
413 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( | 415 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 | 721 |
720 // Handle RTP header extensions. | 722 // Handle RTP header extensions. |
721 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( | 723 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( |
722 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); | 724 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); |
723 if (send_rtp_extensions_ != filtered_extensions) { | 725 if (send_rtp_extensions_ != filtered_extensions) { |
724 changed_params->rtp_header_extensions = | 726 changed_params->rtp_header_extensions = |
725 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); | 727 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); |
726 } | 728 } |
727 | 729 |
728 // Handle max bitrate. | 730 // Handle max bitrate. |
729 if (params.max_bandwidth_bps != bitrate_config_.max_bitrate_bps && | 731 if (params.max_bitrate_bps != bitrate_config_.max_bitrate_bps) { |
730 params.max_bandwidth_bps >= 0) { | 732 changed_params->max_bandwidth_bps = |
731 // 0 uncaps max bitrate (-1). | 733 rtc::Optional<rtc::Optional<int>>(params.max_bitrate_bps); |
732 changed_params->max_bandwidth_bps = rtc::Optional<int>( | |
733 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps); | |
Taylor Brandstetter
2016/03/29 02:26:58
Are we taking away the behavior where 0 uncaps max
skvlad
2016/03/30 19:40:44
Yes, that is the intention. An unset Optional<int>
| |
734 } | 734 } |
735 | 735 |
736 // Handle conference mode. | 736 // Handle conference mode. |
737 if (params.conference_mode != send_params_.conference_mode) { | 737 if (params.conference_mode != send_params_.conference_mode) { |
738 changed_params->conference_mode = | 738 changed_params->conference_mode = |
739 rtc::Optional<bool>(params.conference_mode); | 739 rtc::Optional<bool>(params.conference_mode); |
740 } | 740 } |
741 | 741 |
742 // Handle RTCP mode. | 742 // Handle RTCP mode. |
743 if (params.rtcp.reduced_size != send_params_.rtcp.reduced_size) { | 743 if (params.rtcp.reduced_size != send_params_.rtcp.reduced_size) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 | 776 |
777 if (changed_params.rtp_header_extensions) { | 777 if (changed_params.rtp_header_extensions) { |
778 send_rtp_extensions_ = *changed_params.rtp_header_extensions; | 778 send_rtp_extensions_ = *changed_params.rtp_header_extensions; |
779 } | 779 } |
780 | 780 |
781 if (changed_params.max_bandwidth_bps) { | 781 if (changed_params.max_bandwidth_bps) { |
782 // TODO(pbos): Figure out whether b=AS means max bitrate for this | 782 // TODO(pbos): Figure out whether b=AS means max bitrate for this |
783 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in | 783 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in |
784 // which case this should not set a Call::BitrateConfig but rather | 784 // which case this should not set a Call::BitrateConfig but rather |
785 // reconfigure all senders. | 785 // reconfigure all senders. |
786 int max_bitrate_bps = *changed_params.max_bandwidth_bps; | |
787 bitrate_config_.start_bitrate_bps = -1; | 786 bitrate_config_.start_bitrate_bps = -1; |
788 bitrate_config_.max_bitrate_bps = max_bitrate_bps; | 787 bitrate_config_.max_bitrate_bps = *changed_params.max_bandwidth_bps; |
789 if (max_bitrate_bps > 0 && | 788 if (bitrate_config_.max_bitrate_bps && |
790 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { | 789 (bitrate_config_.min_bitrate_bps > *bitrate_config_.max_bitrate_bps)) { |
791 bitrate_config_.min_bitrate_bps = max_bitrate_bps; | 790 bitrate_config_.min_bitrate_bps = *bitrate_config_.max_bitrate_bps; |
792 } | 791 } |
793 bitrate_config_changed = true; | 792 bitrate_config_changed = true; |
794 } | 793 } |
795 | 794 |
796 if (bitrate_config_changed) { | 795 if (bitrate_config_changed) { |
797 call_->SetBitrateConfig(bitrate_config_); | 796 call_->SetBitrateConfig(bitrate_config_); |
798 } | 797 } |
799 | 798 |
800 { | 799 { |
801 rtc::CritScope stream_lock(&stream_crit_); | 800 rtc::CritScope stream_lock(&stream_crit_); |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1450 send_streams_.begin(); | 1449 send_streams_.begin(); |
1451 it != send_streams_.end(); ++it) { | 1450 it != send_streams_.end(); ++it) { |
1452 it->second->Stop(); | 1451 it->second->Stop(); |
1453 } | 1452 } |
1454 } | 1453 } |
1455 | 1454 |
1456 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: | 1455 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: |
1457 VideoSendStreamParameters( | 1456 VideoSendStreamParameters( |
1458 const webrtc::VideoSendStream::Config& config, | 1457 const webrtc::VideoSendStream::Config& config, |
1459 const VideoOptions& options, | 1458 const VideoOptions& options, |
1460 int max_bitrate_bps, | 1459 rtc::Optional<int> max_bitrate_bps, |
1461 const rtc::Optional<VideoCodecSettings>& codec_settings) | 1460 const rtc::Optional<VideoCodecSettings>& codec_settings) |
1462 : config(config), | 1461 : config(config), |
1463 options(options), | 1462 options(options), |
1464 max_bitrate_bps(max_bitrate_bps), | 1463 max_bitrate_bps(max_bitrate_bps), |
1465 codec_settings(codec_settings) {} | 1464 codec_settings(codec_settings) {} |
1466 | 1465 |
1467 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( | 1466 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( |
1468 webrtc::VideoEncoder* encoder, | 1467 webrtc::VideoEncoder* encoder, |
1469 webrtc::VideoCodecType type, | 1468 webrtc::VideoCodecType type, |
1470 bool external) | 1469 bool external) |
1471 : encoder(encoder), | 1470 : encoder(encoder), |
1472 external_encoder(nullptr), | 1471 external_encoder(nullptr), |
1473 type(type), | 1472 type(type), |
1474 external(external) { | 1473 external(external) { |
1475 if (external) { | 1474 if (external) { |
1476 external_encoder = encoder; | 1475 external_encoder = encoder; |
1477 this->encoder = | 1476 this->encoder = |
1478 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); | 1477 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); |
1479 } | 1478 } |
1480 } | 1479 } |
1481 | 1480 |
1482 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1481 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
1483 webrtc::Call* call, | 1482 webrtc::Call* call, |
1484 const StreamParams& sp, | 1483 const StreamParams& sp, |
1485 const webrtc::VideoSendStream::Config& config, | 1484 const webrtc::VideoSendStream::Config& config, |
1486 const VideoOptions& options, | 1485 const VideoOptions& options, |
1487 WebRtcVideoEncoderFactory* external_encoder_factory, | 1486 WebRtcVideoEncoderFactory* external_encoder_factory, |
1488 bool enable_cpu_overuse_detection, | 1487 bool enable_cpu_overuse_detection, |
1489 int max_bitrate_bps, | 1488 rtc::Optional<int> max_bitrate_bps, |
1490 const rtc::Optional<VideoCodecSettings>& codec_settings, | 1489 const rtc::Optional<VideoCodecSettings>& codec_settings, |
1491 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1490 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1492 // TODO(deadbeef): Don't duplicate information between send_params, | 1491 // TODO(deadbeef): Don't duplicate information between send_params, |
1493 // rtp_extensions, options, etc. | 1492 // rtp_extensions, options, etc. |
1494 const VideoSendParameters& send_params) | 1493 const VideoSendParameters& send_params) |
1495 : worker_thread_(rtc::Thread::Current()), | 1494 : worker_thread_(rtc::Thread::Current()), |
1496 ssrcs_(sp.ssrcs), | 1495 ssrcs_(sp.ssrcs), |
1497 ssrc_groups_(sp.ssrc_groups), | 1496 ssrc_groups_(sp.ssrc_groups), |
1498 call_(call), | 1497 call_(call), |
1499 cpu_restricted_counter_(0), | 1498 cpu_restricted_counter_(0), |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1838 return true; | 1837 return true; |
1839 } | 1838 } |
1840 | 1839 |
1841 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( | 1840 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( |
1842 const webrtc::RtpParameters& rtp_parameters) { | 1841 const webrtc::RtpParameters& rtp_parameters) { |
1843 if (rtp_parameters.encodings.size() != 1) { | 1842 if (rtp_parameters.encodings.size() != 1) { |
1844 LOG(LS_ERROR) | 1843 LOG(LS_ERROR) |
1845 << "Attempted to set RtpParameters without exactly one encoding"; | 1844 << "Attempted to set RtpParameters without exactly one encoding"; |
1846 return false; | 1845 return false; |
1847 } | 1846 } |
1847 if (rtp_parameters.encodings[0].max_bitrate_bps && | |
1848 (*rtp_parameters.encodings[0].max_bitrate_bps <= 0)) { | |
1849 LOG(LS_ERROR) << "Attempted to set a negative bitrate limit"; | |
1850 return false; | |
1851 } | |
1848 return true; | 1852 return true; |
1849 } | 1853 } |
1850 | 1854 |
1851 webrtc::VideoEncoderConfig | 1855 webrtc::VideoEncoderConfig |
1852 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 1856 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
1853 const Dimensions& dimensions, | 1857 const Dimensions& dimensions, |
1854 const VideoCodec& codec) const { | 1858 const VideoCodec& codec) const { |
1855 webrtc::VideoEncoderConfig encoder_config; | 1859 webrtc::VideoEncoderConfig encoder_config; |
1856 bool is_screencast = parameters_.options.is_screencast.value_or(false); | 1860 bool is_screencast = parameters_.options.is_screencast.value_or(false); |
1857 if (is_screencast) { | 1861 if (is_screencast) { |
(...skipping 22 matching lines...) Expand all Loading... | |
1880 clamped_codec.height = height; | 1884 clamped_codec.height = height; |
1881 | 1885 |
1882 // By default, the stream count for the codec configuration should match the | 1886 // By default, the stream count for the codec configuration should match the |
1883 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast | 1887 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast |
1884 // or a screencast, only configure a single stream. | 1888 // or a screencast, only configure a single stream. |
1885 size_t stream_count = parameters_.config.rtp.ssrcs.size(); | 1889 size_t stream_count = parameters_.config.rtp.ssrcs.size(); |
1886 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 1890 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { |
1887 stream_count = 1; | 1891 stream_count = 1; |
1888 } | 1892 } |
1889 | 1893 |
1890 int stream_max_bitrate = | 1894 rtc::Optional<int> stream_max_bitrate = |
1891 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, | 1895 OptionalMin(rtp_parameters_.encodings[0].max_bitrate_bps, |
1892 parameters_.max_bitrate_bps); | 1896 parameters_.max_bitrate_bps); |
1893 encoder_config.streams = CreateVideoStreams( | 1897 encoder_config.streams = CreateVideoStreams( |
1894 clamped_codec, parameters_.options, stream_max_bitrate, stream_count); | 1898 clamped_codec, parameters_.options, stream_max_bitrate, stream_count); |
1895 | 1899 |
1896 // Conference mode screencast uses 2 temporal layers split at 100kbit. | 1900 // Conference mode screencast uses 2 temporal layers split at 100kbit. |
1897 if (parameters_.conference_mode && is_screencast && | 1901 if (parameters_.conference_mode && is_screencast && |
1898 encoder_config.streams.size() == 1) { | 1902 encoder_config.streams.size() == 1) { |
1899 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | 1903 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |
1900 | 1904 |
1901 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked | 1905 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2567 rtx_mapping[video_codecs[i].codec.id] != | 2571 rtx_mapping[video_codecs[i].codec.id] != |
2568 fec_settings.red_payload_type) { | 2572 fec_settings.red_payload_type) { |
2569 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2573 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2570 } | 2574 } |
2571 } | 2575 } |
2572 | 2576 |
2573 return video_codecs; | 2577 return video_codecs; |
2574 } | 2578 } |
2575 | 2579 |
2576 } // namespace cricket | 2580 } // namespace cricket |
OLD | NEW |