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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 codecs.push_back( | 393 codecs.push_back( |
394 VideoCodec::CreateRtxCodec(kDefaultRtxRedPlType, kDefaultRedPlType)); | 394 VideoCodec::CreateRtxCodec(kDefaultRtxRedPlType, kDefaultRedPlType)); |
395 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); | 395 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); |
396 return codecs; | 396 return codecs; |
397 } | 397 } |
398 | 398 |
399 std::vector<webrtc::VideoStream> | 399 std::vector<webrtc::VideoStream> |
400 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( | 400 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( |
401 const VideoCodec& codec, | 401 const VideoCodec& codec, |
402 const VideoOptions& options, | 402 const VideoOptions& options, |
403 int max_bitrate_bps, | 403 rtc::Optional<int> max_bitrate_bps, |
404 size_t num_streams) { | 404 size_t num_streams) { |
405 int max_qp = kDefaultQpMax; | 405 int max_qp = kDefaultQpMax; |
406 codec.GetParam(kCodecParamMaxQuantization, &max_qp); | 406 codec.GetParam(kCodecParamMaxQuantization, &max_qp); |
407 | 407 |
| 408 // TODO(skvlad): Consider replacing special case constants with |
| 409 // rtc::Optional<int> |
408 return GetSimulcastConfig( | 410 return GetSimulcastConfig( |
409 num_streams, codec.width, codec.height, max_bitrate_bps, max_qp, | 411 num_streams, codec.width, codec.height, max_bitrate_bps, max_qp, |
410 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); | 412 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); |
411 } | 413 } |
412 | 414 |
413 std::vector<webrtc::VideoStream> | 415 std::vector<webrtc::VideoStream> |
414 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( | 416 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( |
415 const VideoCodec& codec, | 417 const VideoCodec& codec, |
416 const VideoOptions& options, | 418 const VideoOptions& options, |
417 int max_bitrate_bps, | 419 rtc::Optional<int> max_bitrate_bps, |
418 size_t num_streams) { | 420 size_t num_streams) { |
419 int codec_max_bitrate_kbps; | 421 int codec_max_bitrate_kbps; |
420 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { | 422 if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { |
421 max_bitrate_bps = codec_max_bitrate_kbps * 1000; | 423 max_bitrate_bps = rtc::Optional<int>(codec_max_bitrate_kbps * 1000); |
422 } | 424 } |
423 if (num_streams != 1) { | 425 if (num_streams != 1) { |
424 return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, | 426 return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, |
425 num_streams); | 427 num_streams); |
426 } | 428 } |
427 | 429 |
428 // For unset max bitrates set default bitrate for non-simulcast. | 430 // For unset max bitrates set default bitrate for non-simulcast. |
429 if (max_bitrate_bps <= 0) { | 431 if (!max_bitrate_bps) { |
430 max_bitrate_bps = | 432 max_bitrate_bps = rtc::Optional<int>( |
431 GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000; | 433 GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000); |
432 } | 434 } |
433 | 435 |
434 webrtc::VideoStream stream; | 436 webrtc::VideoStream stream; |
435 stream.width = codec.width; | 437 stream.width = codec.width; |
436 stream.height = codec.height; | 438 stream.height = codec.height; |
437 stream.max_framerate = | 439 stream.max_framerate = |
438 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; | 440 codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; |
439 | 441 |
440 stream.min_bitrate_bps = kMinVideoBitrate * 1000; | 442 stream.min_bitrate_bps = kMinVideoBitrate * 1000; |
441 stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; | 443 stream.target_bitrate_bps = stream.max_bitrate_bps = *max_bitrate_bps; |
442 | 444 |
443 int max_qp = kDefaultQpMax; | 445 int max_qp = kDefaultQpMax; |
444 codec.GetParam(kCodecParamMaxQuantization, &max_qp); | 446 codec.GetParam(kCodecParamMaxQuantization, &max_qp); |
445 stream.max_qp = max_qp; | 447 stream.max_qp = max_qp; |
446 std::vector<webrtc::VideoStream> streams; | 448 std::vector<webrtc::VideoStream> streams; |
447 streams.push_back(stream); | 449 streams.push_back(stream); |
448 return streams; | 450 return streams; |
449 } | 451 } |
450 | 452 |
451 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( | 453 void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 | 766 |
765 // Handle RTP header extensions. | 767 // Handle RTP header extensions. |
766 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( | 768 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( |
767 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); | 769 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); |
768 if (send_rtp_extensions_ != filtered_extensions) { | 770 if (send_rtp_extensions_ != filtered_extensions) { |
769 changed_params->rtp_header_extensions = | 771 changed_params->rtp_header_extensions = |
770 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); | 772 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); |
771 } | 773 } |
772 | 774 |
773 // Handle max bitrate. | 775 // Handle max bitrate. |
774 if (params.max_bandwidth_bps != bitrate_config_.max_bitrate_bps && | 776 if (params.max_bitrate_bps != bitrate_config_.max_bitrate_bps) { |
775 params.max_bandwidth_bps >= 0) { | 777 changed_params->max_bandwidth_bps = |
776 // 0 uncaps max bitrate (-1). | 778 rtc::Optional<rtc::Optional<int>>(params.max_bitrate_bps); |
777 changed_params->max_bandwidth_bps = rtc::Optional<int>( | |
778 params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps); | |
779 } | 779 } |
780 | 780 |
781 // Handle conference mode. | 781 // Handle conference mode. |
782 if (params.conference_mode != send_params_.conference_mode) { | 782 if (params.conference_mode != send_params_.conference_mode) { |
783 changed_params->conference_mode = | 783 changed_params->conference_mode = |
784 rtc::Optional<bool>(params.conference_mode); | 784 rtc::Optional<bool>(params.conference_mode); |
785 } | 785 } |
786 | 786 |
787 // Handle RTCP mode. | 787 // Handle RTCP mode. |
788 if (params.rtcp.reduced_size != send_params_.rtcp.reduced_size) { | 788 if (params.rtcp.reduced_size != send_params_.rtcp.reduced_size) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 | 821 |
822 if (changed_params.rtp_header_extensions) { | 822 if (changed_params.rtp_header_extensions) { |
823 send_rtp_extensions_ = *changed_params.rtp_header_extensions; | 823 send_rtp_extensions_ = *changed_params.rtp_header_extensions; |
824 } | 824 } |
825 | 825 |
826 if (changed_params.max_bandwidth_bps) { | 826 if (changed_params.max_bandwidth_bps) { |
827 // TODO(pbos): Figure out whether b=AS means max bitrate for this | 827 // TODO(pbos): Figure out whether b=AS means max bitrate for this |
828 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in | 828 // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in |
829 // which case this should not set a Call::BitrateConfig but rather | 829 // which case this should not set a Call::BitrateConfig but rather |
830 // reconfigure all senders. | 830 // reconfigure all senders. |
831 int max_bitrate_bps = *changed_params.max_bandwidth_bps; | |
832 bitrate_config_.start_bitrate_bps = -1; | 831 bitrate_config_.start_bitrate_bps = -1; |
833 bitrate_config_.max_bitrate_bps = max_bitrate_bps; | 832 bitrate_config_.max_bitrate_bps = *changed_params.max_bandwidth_bps; |
834 if (max_bitrate_bps > 0 && | 833 if (bitrate_config_.max_bitrate_bps && |
835 bitrate_config_.min_bitrate_bps > max_bitrate_bps) { | 834 (bitrate_config_.min_bitrate_bps > *bitrate_config_.max_bitrate_bps)) { |
836 bitrate_config_.min_bitrate_bps = max_bitrate_bps; | 835 bitrate_config_.min_bitrate_bps = *bitrate_config_.max_bitrate_bps; |
837 } | 836 } |
838 bitrate_config_changed = true; | 837 bitrate_config_changed = true; |
839 } | 838 } |
840 | 839 |
841 if (bitrate_config_changed) { | 840 if (bitrate_config_changed) { |
842 call_->SetBitrateConfig(bitrate_config_); | 841 call_->SetBitrateConfig(bitrate_config_); |
843 } | 842 } |
844 | 843 |
845 { | 844 { |
846 rtc::CritScope stream_lock(&stream_crit_); | 845 rtc::CritScope stream_lock(&stream_crit_); |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 | 1471 |
1473 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { | 1472 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { |
1474 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen); | 1473 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen); |
1475 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions()); | 1474 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions()); |
1476 } | 1475 } |
1477 | 1476 |
1478 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: | 1477 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: |
1479 VideoSendStreamParameters( | 1478 VideoSendStreamParameters( |
1480 const webrtc::VideoSendStream::Config& config, | 1479 const webrtc::VideoSendStream::Config& config, |
1481 const VideoOptions& options, | 1480 const VideoOptions& options, |
1482 int max_bitrate_bps, | 1481 rtc::Optional<int> max_bitrate_bps, |
1483 const rtc::Optional<VideoCodecSettings>& codec_settings) | 1482 const rtc::Optional<VideoCodecSettings>& codec_settings) |
1484 : config(config), | 1483 : config(config), |
1485 options(options), | 1484 options(options), |
1486 max_bitrate_bps(max_bitrate_bps), | 1485 max_bitrate_bps(max_bitrate_bps), |
1487 codec_settings(codec_settings) {} | 1486 codec_settings(codec_settings) {} |
1488 | 1487 |
1489 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( | 1488 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( |
1490 webrtc::VideoEncoder* encoder, | 1489 webrtc::VideoEncoder* encoder, |
1491 webrtc::VideoCodecType type, | 1490 webrtc::VideoCodecType type, |
1492 bool external) | 1491 bool external) |
1493 : encoder(encoder), | 1492 : encoder(encoder), |
1494 external_encoder(nullptr), | 1493 external_encoder(nullptr), |
1495 type(type), | 1494 type(type), |
1496 external(external) { | 1495 external(external) { |
1497 if (external) { | 1496 if (external) { |
1498 external_encoder = encoder; | 1497 external_encoder = encoder; |
1499 this->encoder = | 1498 this->encoder = |
1500 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); | 1499 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); |
1501 } | 1500 } |
1502 } | 1501 } |
1503 | 1502 |
1504 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1503 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
1505 webrtc::Call* call, | 1504 webrtc::Call* call, |
1506 const StreamParams& sp, | 1505 const StreamParams& sp, |
1507 const webrtc::VideoSendStream::Config& config, | 1506 const webrtc::VideoSendStream::Config& config, |
1508 const VideoOptions& options, | 1507 const VideoOptions& options, |
1509 WebRtcVideoEncoderFactory* external_encoder_factory, | 1508 WebRtcVideoEncoderFactory* external_encoder_factory, |
1510 bool enable_cpu_overuse_detection, | 1509 bool enable_cpu_overuse_detection, |
1511 int max_bitrate_bps, | 1510 rtc::Optional<int> max_bitrate_bps, |
1512 const rtc::Optional<VideoCodecSettings>& codec_settings, | 1511 const rtc::Optional<VideoCodecSettings>& codec_settings, |
1513 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 1512 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
1514 // TODO(deadbeef): Don't duplicate information between send_params, | 1513 // TODO(deadbeef): Don't duplicate information between send_params, |
1515 // rtp_extensions, options, etc. | 1514 // rtp_extensions, options, etc. |
1516 const VideoSendParameters& send_params) | 1515 const VideoSendParameters& send_params) |
1517 : worker_thread_(rtc::Thread::Current()), | 1516 : worker_thread_(rtc::Thread::Current()), |
1518 ssrcs_(sp.ssrcs), | 1517 ssrcs_(sp.ssrcs), |
1519 ssrc_groups_(sp.ssrc_groups), | 1518 ssrc_groups_(sp.ssrc_groups), |
1520 call_(call), | 1519 call_(call), |
1521 cpu_restricted_counter_(0), | 1520 cpu_restricted_counter_(0), |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 return rtp_parameters_; | 1867 return rtp_parameters_; |
1869 } | 1868 } |
1870 | 1869 |
1871 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( | 1870 bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters( |
1872 const webrtc::RtpParameters& rtp_parameters) { | 1871 const webrtc::RtpParameters& rtp_parameters) { |
1873 if (rtp_parameters.encodings.size() != 1) { | 1872 if (rtp_parameters.encodings.size() != 1) { |
1874 LOG(LS_ERROR) | 1873 LOG(LS_ERROR) |
1875 << "Attempted to set RtpParameters without exactly one encoding"; | 1874 << "Attempted to set RtpParameters without exactly one encoding"; |
1876 return false; | 1875 return false; |
1877 } | 1876 } |
| 1877 if (rtp_parameters.encodings[0].max_bitrate_bps && |
| 1878 (*rtp_parameters.encodings[0].max_bitrate_bps <= 0)) { |
| 1879 LOG(LS_ERROR) << "Attempted to set a negative bitrate limit"; |
| 1880 return false; |
| 1881 } |
1878 return true; | 1882 return true; |
1879 } | 1883 } |
1880 | 1884 |
1881 void WebRtcVideoChannel2::WebRtcVideoSendStream::UpdateSendState() { | 1885 void WebRtcVideoChannel2::WebRtcVideoSendStream::UpdateSendState() { |
1882 // TODO(deadbeef): Need to handle more than one encoding in the future. | 1886 // TODO(deadbeef): Need to handle more than one encoding in the future. |
1883 RTC_DCHECK(rtp_parameters_.encodings.size() == 1u); | 1887 RTC_DCHECK(rtp_parameters_.encodings.size() == 1u); |
1884 if (sending_ && rtp_parameters_.encodings[0].active) { | 1888 if (sending_ && rtp_parameters_.encodings[0].active) { |
1885 RTC_DCHECK(stream_ != nullptr); | 1889 RTC_DCHECK(stream_ != nullptr); |
1886 stream_->Start(); | 1890 stream_->Start(); |
1887 } else { | 1891 } else { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 clamped_codec.height = height; | 1927 clamped_codec.height = height; |
1924 | 1928 |
1925 // By default, the stream count for the codec configuration should match the | 1929 // By default, the stream count for the codec configuration should match the |
1926 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast | 1930 // number of negotiated ssrcs. But if the codec is blacklisted for simulcast |
1927 // or a screencast, only configure a single stream. | 1931 // or a screencast, only configure a single stream. |
1928 size_t stream_count = parameters_.config.rtp.ssrcs.size(); | 1932 size_t stream_count = parameters_.config.rtp.ssrcs.size(); |
1929 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { | 1933 if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { |
1930 stream_count = 1; | 1934 stream_count = 1; |
1931 } | 1935 } |
1932 | 1936 |
1933 int stream_max_bitrate = | 1937 rtc::Optional<int> stream_max_bitrate = |
1934 MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps, | 1938 OptionalMin(rtp_parameters_.encodings[0].max_bitrate_bps, |
1935 parameters_.max_bitrate_bps); | 1939 parameters_.max_bitrate_bps); |
1936 encoder_config.streams = CreateVideoStreams( | 1940 encoder_config.streams = CreateVideoStreams( |
1937 clamped_codec, parameters_.options, stream_max_bitrate, stream_count); | 1941 clamped_codec, parameters_.options, stream_max_bitrate, stream_count); |
1938 | 1942 |
1939 // Conference mode screencast uses 2 temporal layers split at 100kbit. | 1943 // Conference mode screencast uses 2 temporal layers split at 100kbit. |
1940 if (parameters_.conference_mode && is_screencast && | 1944 if (parameters_.conference_mode && is_screencast && |
1941 encoder_config.streams.size() == 1) { | 1945 encoder_config.streams.size() == 1) { |
1942 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | 1946 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |
1943 | 1947 |
1944 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked | 1948 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2593 rtx_mapping[video_codecs[i].codec.id] != | 2597 rtx_mapping[video_codecs[i].codec.id] != |
2594 fec_settings.red_payload_type) { | 2598 fec_settings.red_payload_type) { |
2595 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2599 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2596 } | 2600 } |
2597 } | 2601 } |
2598 | 2602 |
2599 return video_codecs; | 2603 return video_codecs; |
2600 } | 2604 } |
2601 | 2605 |
2602 } // namespace cricket | 2606 } // namespace cricket |
OLD | NEW |