OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 // No automatic resizing when using simulcast or screencast. | 481 // No automatic resizing when using simulcast or screencast. |
482 bool automatic_resize = | 482 bool automatic_resize = |
483 !is_screencast && parameters_.config.rtp.ssrcs.size() == 1; | 483 !is_screencast && parameters_.config.rtp.ssrcs.size() == 1; |
484 bool frame_dropping = !is_screencast; | 484 bool frame_dropping = !is_screencast; |
485 bool denoising; | 485 bool denoising; |
486 bool codec_default_denoising = false; | 486 bool codec_default_denoising = false; |
487 if (is_screencast) { | 487 if (is_screencast) { |
488 denoising = false; | 488 denoising = false; |
489 } else { | 489 } else { |
490 // Use codec default if video_noise_reduction is unset. | 490 // Use codec default if video_noise_reduction is unset. |
491 codec_default_denoising = !options.video_noise_reduction.Get(&denoising); | 491 codec_default_denoising = !options.video_noise_reduction; |
| 492 denoising = options.video_noise_reduction.value_or(false); |
492 } | 493 } |
493 | 494 |
494 if (CodecNamesEq(codec.name, kVp8CodecName)) { | 495 if (CodecNamesEq(codec.name, kVp8CodecName)) { |
495 encoder_settings_.vp8 = webrtc::VideoEncoder::GetDefaultVp8Settings(); | 496 encoder_settings_.vp8 = webrtc::VideoEncoder::GetDefaultVp8Settings(); |
496 encoder_settings_.vp8.automaticResizeOn = automatic_resize; | 497 encoder_settings_.vp8.automaticResizeOn = automatic_resize; |
497 // VP8 denoising is enabled by default. | 498 // VP8 denoising is enabled by default. |
498 encoder_settings_.vp8.denoisingOn = | 499 encoder_settings_.vp8.denoisingOn = |
499 codec_default_denoising ? true : denoising; | 500 codec_default_denoising ? true : denoising; |
500 encoder_settings_.vp8.frameDroppingOn = frame_dropping; | 501 encoder_settings_.vp8.frameDroppingOn = frame_dropping; |
501 return &encoder_settings_.vp8; | 502 return &encoder_settings_.vp8; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 const std::vector<VideoCodec>& recv_codecs, | 770 const std::vector<VideoCodec>& recv_codecs, |
770 WebRtcVideoEncoderFactory* external_encoder_factory, | 771 WebRtcVideoEncoderFactory* external_encoder_factory, |
771 WebRtcVideoDecoderFactory* external_decoder_factory) | 772 WebRtcVideoDecoderFactory* external_decoder_factory) |
772 : call_(call), | 773 : call_(call), |
773 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), | 774 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), |
774 external_encoder_factory_(external_encoder_factory), | 775 external_encoder_factory_(external_encoder_factory), |
775 external_decoder_factory_(external_decoder_factory) { | 776 external_decoder_factory_(external_decoder_factory) { |
776 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 777 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
777 SetDefaultOptions(); | 778 SetDefaultOptions(); |
778 options_.SetAll(options); | 779 options_.SetAll(options); |
779 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); | 780 if (options_.cpu_overuse_detection) |
| 781 signal_cpu_adaptation_ = *options_.cpu_overuse_detection; |
780 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; | 782 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; |
781 sending_ = false; | 783 sending_ = false; |
782 default_send_ssrc_ = 0; | 784 default_send_ssrc_ = 0; |
783 SetRecvCodecs(recv_codecs); | 785 SetRecvCodecs(recv_codecs); |
784 } | 786 } |
785 | 787 |
786 void WebRtcVideoChannel2::SetDefaultOptions() { | 788 void WebRtcVideoChannel2::SetDefaultOptions() { |
787 options_.cpu_overuse_detection.Set(true); | 789 options_.cpu_overuse_detection = true; |
788 options_.dscp.Set(false); | 790 options_.dscp = false; |
789 options_.suspend_below_min_bitrate.Set(false); | 791 options_.suspend_below_min_bitrate = false; |
790 options_.screencast_min_bitrate.Set(0); | 792 options_.screencast_min_bitrate = 0; |
791 } | 793 } |
792 | 794 |
793 WebRtcVideoChannel2::~WebRtcVideoChannel2() { | 795 WebRtcVideoChannel2::~WebRtcVideoChannel2() { |
794 for (auto& kv : send_streams_) | 796 for (auto& kv : send_streams_) |
795 delete kv.second; | 797 delete kv.second; |
796 for (auto& kv : receive_streams_) | 798 for (auto& kv : receive_streams_) |
797 delete kv.second; | 799 delete kv.second; |
798 } | 800 } |
799 | 801 |
800 bool WebRtcVideoChannel2::CodecIsExternallySupported( | 802 bool WebRtcVideoChannel2::CodecIsExternallySupported( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 const std::vector<VideoCodecSettings> supported_codecs = | 946 const std::vector<VideoCodecSettings> supported_codecs = |
945 FilterSupportedCodecs(MapCodecs(codecs)); | 947 FilterSupportedCodecs(MapCodecs(codecs)); |
946 | 948 |
947 if (supported_codecs.empty()) { | 949 if (supported_codecs.empty()) { |
948 LOG(LS_ERROR) << "No video codecs supported."; | 950 LOG(LS_ERROR) << "No video codecs supported."; |
949 return false; | 951 return false; |
950 } | 952 } |
951 | 953 |
952 LOG(LS_INFO) << "Using codec: " << supported_codecs.front().codec.ToString(); | 954 LOG(LS_INFO) << "Using codec: " << supported_codecs.front().codec.ToString(); |
953 | 955 |
954 VideoCodecSettings old_codec; | 956 if (send_codec_ && supported_codecs.front() == *send_codec_) { |
955 if (send_codec_.Get(&old_codec) && supported_codecs.front() == old_codec) { | |
956 LOG(LS_INFO) << "Ignore call to SetSendCodecs because first supported " | 957 LOG(LS_INFO) << "Ignore call to SetSendCodecs because first supported " |
957 "codec hasn't changed."; | 958 "codec hasn't changed."; |
958 // Using same codec, avoid reconfiguring. | 959 // Using same codec, avoid reconfiguring. |
959 return true; | 960 return true; |
960 } | 961 } |
961 | 962 |
962 send_codec_.Set(supported_codecs.front()); | 963 send_codec_ = supported_codecs.front(); |
963 | 964 |
964 rtc::CritScope stream_lock(&stream_crit_); | 965 rtc::CritScope stream_lock(&stream_crit_); |
965 LOG(LS_INFO) << "Change the send codec because SetSendCodecs has a different " | 966 LOG(LS_INFO) << "Change the send codec because SetSendCodecs has a different " |
966 "first supported codec."; | 967 "first supported codec."; |
967 for (auto& kv : send_streams_) { | 968 for (auto& kv : send_streams_) { |
968 RTC_DCHECK(kv.second != nullptr); | 969 RTC_DCHECK(kv.second != nullptr); |
969 kv.second->SetCodec(supported_codecs.front()); | 970 kv.second->SetCodec(supported_codecs.front()); |
970 } | 971 } |
971 LOG(LS_INFO) << "SetNackAndRemb on all the receive streams because the send " | 972 LOG(LS_INFO) << "SetNackAndRemb on all the receive streams because the send " |
972 "codec has changed."; | 973 "codec has changed."; |
(...skipping 25 matching lines...) Expand all Loading... |
998 bitrate_config_.max_bitrate_bps = bitrate_kbps * 1000; | 999 bitrate_config_.max_bitrate_bps = bitrate_kbps * 1000; |
999 } else { | 1000 } else { |
1000 bitrate_config_.max_bitrate_bps = -1; | 1001 bitrate_config_.max_bitrate_bps = -1; |
1001 } | 1002 } |
1002 call_->SetBitrateConfig(bitrate_config_); | 1003 call_->SetBitrateConfig(bitrate_config_); |
1003 | 1004 |
1004 return true; | 1005 return true; |
1005 } | 1006 } |
1006 | 1007 |
1007 bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) { | 1008 bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) { |
1008 VideoCodecSettings codec_settings; | 1009 if (!send_codec_) { |
1009 if (!send_codec_.Get(&codec_settings)) { | |
1010 LOG(LS_VERBOSE) << "GetSendCodec: No send codec set."; | 1010 LOG(LS_VERBOSE) << "GetSendCodec: No send codec set."; |
1011 return false; | 1011 return false; |
1012 } | 1012 } |
1013 *codec = codec_settings.codec; | 1013 *codec = send_codec_->codec; |
1014 return true; | 1014 return true; |
1015 } | 1015 } |
1016 | 1016 |
1017 bool WebRtcVideoChannel2::SetSendStreamFormat(uint32_t ssrc, | 1017 bool WebRtcVideoChannel2::SetSendStreamFormat(uint32_t ssrc, |
1018 const VideoFormat& format) { | 1018 const VideoFormat& format) { |
1019 LOG(LS_VERBOSE) << "SetSendStreamFormat:" << ssrc << " -> " | 1019 LOG(LS_VERBOSE) << "SetSendStreamFormat:" << ssrc << " -> " |
1020 << format.ToString(); | 1020 << format.ToString(); |
1021 rtc::CritScope stream_lock(&stream_crit_); | 1021 rtc::CritScope stream_lock(&stream_crit_); |
1022 if (send_streams_.find(ssrc) == send_streams_.end()) { | 1022 if (send_streams_.find(ssrc) == send_streams_.end()) { |
1023 return false; | 1023 return false; |
1024 } | 1024 } |
1025 return send_streams_[ssrc]->SetVideoFormat(format); | 1025 return send_streams_[ssrc]->SetVideoFormat(format); |
1026 } | 1026 } |
1027 | 1027 |
1028 bool WebRtcVideoChannel2::SetSend(bool send) { | 1028 bool WebRtcVideoChannel2::SetSend(bool send) { |
1029 LOG(LS_VERBOSE) << "SetSend: " << (send ? "true" : "false"); | 1029 LOG(LS_VERBOSE) << "SetSend: " << (send ? "true" : "false"); |
1030 if (send && !send_codec_.IsSet()) { | 1030 if (send && !send_codec_) { |
1031 LOG(LS_ERROR) << "SetSend(true) called before setting codec."; | 1031 LOG(LS_ERROR) << "SetSend(true) called before setting codec."; |
1032 return false; | 1032 return false; |
1033 } | 1033 } |
1034 if (send) { | 1034 if (send) { |
1035 StartAllSendStreams(); | 1035 StartAllSendStreams(); |
1036 } else { | 1036 } else { |
1037 StopAllSendStreams(); | 1037 StopAllSendStreams(); |
1038 } | 1038 } |
1039 sending_ = send; | 1039 sending_ = send; |
1040 return true; | 1040 return true; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1216 |
1217 for (uint32_t used_ssrc : sp.ssrcs) | 1217 for (uint32_t used_ssrc : sp.ssrcs) |
1218 receive_ssrcs_.insert(used_ssrc); | 1218 receive_ssrcs_.insert(used_ssrc); |
1219 | 1219 |
1220 webrtc::VideoReceiveStream::Config config(this); | 1220 webrtc::VideoReceiveStream::Config config(this); |
1221 ConfigureReceiverRtp(&config, sp); | 1221 ConfigureReceiverRtp(&config, sp); |
1222 | 1222 |
1223 // Set up A/V sync group based on sync label. | 1223 // Set up A/V sync group based on sync label. |
1224 config.sync_group = sp.sync_label; | 1224 config.sync_group = sp.sync_label; |
1225 | 1225 |
1226 config.rtp.remb = false; | 1226 config.rtp.remb = send_codec_ ? HasRemb(send_codec_->codec) : false; |
1227 VideoCodecSettings send_codec; | |
1228 if (send_codec_.Get(&send_codec)) { | |
1229 config.rtp.remb = HasRemb(send_codec.codec); | |
1230 } | |
1231 | 1227 |
1232 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( | 1228 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( |
1233 call_, sp, config, external_decoder_factory_, default_stream, | 1229 call_, sp, config, external_decoder_factory_, default_stream, |
1234 recv_codecs_); | 1230 recv_codecs_); |
1235 | 1231 |
1236 return true; | 1232 return true; |
1237 } | 1233 } |
1238 | 1234 |
1239 void WebRtcVideoChannel2::ConfigureReceiverRtp( | 1235 void WebRtcVideoChannel2::ConfigureReceiverRtp( |
1240 webrtc::VideoReceiveStream::Config* config, | 1236 webrtc::VideoReceiveStream::Config* config, |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetOptions"); | 1599 TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetOptions"); |
1604 LOG(LS_INFO) << "SetOptions: " << options.ToString(); | 1600 LOG(LS_INFO) << "SetOptions: " << options.ToString(); |
1605 VideoOptions old_options = options_; | 1601 VideoOptions old_options = options_; |
1606 options_.SetAll(options); | 1602 options_.SetAll(options); |
1607 if (options_ == old_options) { | 1603 if (options_ == old_options) { |
1608 // No new options to set. | 1604 // No new options to set. |
1609 return true; | 1605 return true; |
1610 } | 1606 } |
1611 { | 1607 { |
1612 rtc::CritScope lock(&capturer_crit_); | 1608 rtc::CritScope lock(&capturer_crit_); |
1613 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); | 1609 if (options_.cpu_overuse_detection) |
| 1610 signal_cpu_adaptation_ = *options_.cpu_overuse_detection; |
1614 } | 1611 } |
1615 rtc::DiffServCodePoint dscp = options_.dscp.GetWithDefaultIfUnset(false) | 1612 rtc::DiffServCodePoint dscp = |
1616 ? rtc::DSCP_AF41 | 1613 options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT; |
1617 : rtc::DSCP_DEFAULT; | |
1618 MediaChannel::SetDscp(dscp); | 1614 MediaChannel::SetDscp(dscp); |
1619 rtc::CritScope stream_lock(&stream_crit_); | 1615 rtc::CritScope stream_lock(&stream_crit_); |
1620 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = | 1616 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = |
1621 send_streams_.begin(); | 1617 send_streams_.begin(); |
1622 it != send_streams_.end(); ++it) { | 1618 it != send_streams_.end(); ++it) { |
1623 it->second->SetOptions(options_); | 1619 it->second->SetOptions(options_); |
1624 } | 1620 } |
1625 return true; | 1621 return true; |
1626 } | 1622 } |
1627 | 1623 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 it != send_streams_.end(); ++it) { | 1695 it != send_streams_.end(); ++it) { |
1700 it->second->Stop(); | 1696 it->second->Stop(); |
1701 } | 1697 } |
1702 } | 1698 } |
1703 | 1699 |
1704 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: | 1700 WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: |
1705 VideoSendStreamParameters( | 1701 VideoSendStreamParameters( |
1706 const webrtc::VideoSendStream::Config& config, | 1702 const webrtc::VideoSendStream::Config& config, |
1707 const VideoOptions& options, | 1703 const VideoOptions& options, |
1708 int max_bitrate_bps, | 1704 int max_bitrate_bps, |
1709 const Settable<VideoCodecSettings>& codec_settings) | 1705 const rtc::Maybe<VideoCodecSettings>& codec_settings) |
1710 : config(config), | 1706 : config(config), |
1711 options(options), | 1707 options(options), |
1712 max_bitrate_bps(max_bitrate_bps), | 1708 max_bitrate_bps(max_bitrate_bps), |
1713 codec_settings(codec_settings) { | 1709 codec_settings(codec_settings) {} |
1714 } | |
1715 | 1710 |
1716 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( | 1711 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( |
1717 webrtc::VideoEncoder* encoder, | 1712 webrtc::VideoEncoder* encoder, |
1718 webrtc::VideoCodecType type, | 1713 webrtc::VideoCodecType type, |
1719 bool external) | 1714 bool external) |
1720 : encoder(encoder), | 1715 : encoder(encoder), |
1721 external_encoder(nullptr), | 1716 external_encoder(nullptr), |
1722 type(type), | 1717 type(type), |
1723 external(external) { | 1718 external(external) { |
1724 if (external) { | 1719 if (external) { |
1725 external_encoder = encoder; | 1720 external_encoder = encoder; |
1726 this->encoder = | 1721 this->encoder = |
1727 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); | 1722 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); |
1728 } | 1723 } |
1729 } | 1724 } |
1730 | 1725 |
1731 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1726 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
1732 webrtc::Call* call, | 1727 webrtc::Call* call, |
1733 const StreamParams& sp, | 1728 const StreamParams& sp, |
1734 const webrtc::VideoSendStream::Config& config, | 1729 const webrtc::VideoSendStream::Config& config, |
1735 WebRtcVideoEncoderFactory* external_encoder_factory, | 1730 WebRtcVideoEncoderFactory* external_encoder_factory, |
1736 const VideoOptions& options, | 1731 const VideoOptions& options, |
1737 int max_bitrate_bps, | 1732 int max_bitrate_bps, |
1738 const Settable<VideoCodecSettings>& codec_settings, | 1733 const rtc::Maybe<VideoCodecSettings>& codec_settings, |
1739 const std::vector<webrtc::RtpExtension>& rtp_extensions) | 1734 const std::vector<webrtc::RtpExtension>& rtp_extensions) |
1740 : ssrcs_(sp.ssrcs), | 1735 : ssrcs_(sp.ssrcs), |
1741 ssrc_groups_(sp.ssrc_groups), | 1736 ssrc_groups_(sp.ssrc_groups), |
1742 call_(call), | 1737 call_(call), |
1743 external_encoder_factory_(external_encoder_factory), | 1738 external_encoder_factory_(external_encoder_factory), |
1744 stream_(NULL), | 1739 stream_(NULL), |
1745 parameters_(config, options, max_bitrate_bps, codec_settings), | 1740 parameters_(config, options, max_bitrate_bps, codec_settings), |
1746 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), | 1741 allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), |
1747 capturer_(NULL), | 1742 capturer_(NULL), |
1748 sending_(false), | 1743 sending_(false), |
1749 muted_(false), | 1744 muted_(false), |
1750 old_adapt_changes_(0), | 1745 old_adapt_changes_(0), |
1751 first_frame_timestamp_ms_(0), | 1746 first_frame_timestamp_ms_(0), |
1752 last_frame_timestamp_ms_(0) { | 1747 last_frame_timestamp_ms_(0) { |
1753 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1748 parameters_.config.rtp.max_packet_size = kVideoMtu; |
1754 | 1749 |
1755 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1750 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
1756 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1751 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
1757 ¶meters_.config.rtp.rtx.ssrcs); | 1752 ¶meters_.config.rtp.rtx.ssrcs); |
1758 parameters_.config.rtp.c_name = sp.cname; | 1753 parameters_.config.rtp.c_name = sp.cname; |
1759 parameters_.config.rtp.extensions = rtp_extensions; | 1754 parameters_.config.rtp.extensions = rtp_extensions; |
1760 | 1755 |
1761 VideoCodecSettings params; | 1756 if (codec_settings) { |
1762 if (codec_settings.Get(¶ms)) { | 1757 SetCodec(*codec_settings); |
1763 SetCodec(params); | |
1764 } | 1758 } |
1765 } | 1759 } |
1766 | 1760 |
1767 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { | 1761 WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
1768 DisconnectCapturer(); | 1762 DisconnectCapturer(); |
1769 if (stream_ != NULL) { | 1763 if (stream_ != NULL) { |
1770 call_->DestroyVideoSendStream(stream_); | 1764 call_->DestroyVideoSendStream(stream_); |
1771 } | 1765 } |
1772 DestroyVideoEncoder(&allocated_encoder_); | 1766 DestroyVideoEncoder(&allocated_encoder_); |
1773 } | 1767 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 rtc::CritScope cs(&lock_); | 1925 rtc::CritScope cs(&lock_); |
1932 if (capturer_ == NULL) | 1926 if (capturer_ == NULL) |
1933 return; | 1927 return; |
1934 | 1928 |
1935 capturer_->SetApplyRotation(apply_rotation); | 1929 capturer_->SetApplyRotation(apply_rotation); |
1936 } | 1930 } |
1937 | 1931 |
1938 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( | 1932 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
1939 const VideoOptions& options) { | 1933 const VideoOptions& options) { |
1940 rtc::CritScope cs(&lock_); | 1934 rtc::CritScope cs(&lock_); |
1941 VideoCodecSettings codec_settings; | 1935 if (parameters_.codec_settings) { |
1942 if (parameters_.codec_settings.Get(&codec_settings)) { | |
1943 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" | 1936 LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" |
1944 << options.ToString(); | 1937 << options.ToString(); |
1945 SetCodecAndOptions(codec_settings, options); | 1938 SetCodecAndOptions(*parameters_.codec_settings, options); |
1946 } else { | 1939 } else { |
1947 parameters_.options = options; | 1940 parameters_.options = options; |
1948 } | 1941 } |
1949 } | 1942 } |
1950 | 1943 |
1951 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec( | 1944 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec( |
1952 const VideoCodecSettings& codec_settings) { | 1945 const VideoCodecSettings& codec_settings) { |
1953 rtc::CritScope cs(&lock_); | 1946 rtc::CritScope cs(&lock_); |
1954 LOG(LS_INFO) << "SetCodecAndOptions because of SetCodec."; | 1947 LOG(LS_INFO) << "SetCodecAndOptions because of SetCodec."; |
1955 SetCodecAndOptions(codec_settings, parameters_.options); | 1948 SetCodecAndOptions(codec_settings, parameters_.options); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 "payload type. Ignoring."; | 2033 "payload type. Ignoring."; |
2041 parameters_.config.rtp.rtx.ssrcs.clear(); | 2034 parameters_.config.rtp.rtx.ssrcs.clear(); |
2042 } else { | 2035 } else { |
2043 parameters_.config.rtp.rtx.payload_type = codec_settings.rtx_payload_type; | 2036 parameters_.config.rtp.rtx.payload_type = codec_settings.rtx_payload_type; |
2044 } | 2037 } |
2045 } | 2038 } |
2046 | 2039 |
2047 parameters_.config.rtp.nack.rtp_history_ms = | 2040 parameters_.config.rtp.nack.rtp_history_ms = |
2048 HasNack(codec_settings.codec) ? kNackHistoryMs : 0; | 2041 HasNack(codec_settings.codec) ? kNackHistoryMs : 0; |
2049 | 2042 |
2050 options.suspend_below_min_bitrate.Get( | 2043 RTC_CHECK(options.suspend_below_min_bitrate); |
2051 ¶meters_.config.suspend_below_min_bitrate); | 2044 parameters_.config.suspend_below_min_bitrate = |
| 2045 *options.suspend_below_min_bitrate; |
2052 | 2046 |
2053 parameters_.codec_settings.Set(codec_settings); | 2047 parameters_.codec_settings = codec_settings; |
2054 parameters_.options = options; | 2048 parameters_.options = options; |
2055 | 2049 |
2056 LOG(LS_INFO) | 2050 LOG(LS_INFO) |
2057 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options=" | 2051 << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options=" |
2058 << options.ToString(); | 2052 << options.ToString(); |
2059 RecreateWebRtcStream(); | 2053 RecreateWebRtcStream(); |
2060 if (allocated_encoder_.encoder != new_encoder.encoder) { | 2054 if (allocated_encoder_.encoder != new_encoder.encoder) { |
2061 DestroyVideoEncoder(&allocated_encoder_); | 2055 DestroyVideoEncoder(&allocated_encoder_); |
2062 allocated_encoder_ = new_encoder; | 2056 allocated_encoder_ = new_encoder; |
2063 } | 2057 } |
2064 } | 2058 } |
2065 | 2059 |
2066 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpExtensions( | 2060 void WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpExtensions( |
2067 const std::vector<webrtc::RtpExtension>& rtp_extensions) { | 2061 const std::vector<webrtc::RtpExtension>& rtp_extensions) { |
2068 rtc::CritScope cs(&lock_); | 2062 rtc::CritScope cs(&lock_); |
2069 parameters_.config.rtp.extensions = rtp_extensions; | 2063 parameters_.config.rtp.extensions = rtp_extensions; |
2070 if (stream_ != nullptr) { | 2064 if (stream_ != nullptr) { |
2071 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetRtpExtensions"; | 2065 LOG(LS_INFO) << "RecreateWebRtcStream (send) because of SetRtpExtensions"; |
2072 RecreateWebRtcStream(); | 2066 RecreateWebRtcStream(); |
2073 } | 2067 } |
2074 } | 2068 } |
2075 | 2069 |
2076 webrtc::VideoEncoderConfig | 2070 webrtc::VideoEncoderConfig |
2077 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( | 2071 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
2078 const Dimensions& dimensions, | 2072 const Dimensions& dimensions, |
2079 const VideoCodec& codec) const { | 2073 const VideoCodec& codec) const { |
2080 webrtc::VideoEncoderConfig encoder_config; | 2074 webrtc::VideoEncoderConfig encoder_config; |
2081 if (dimensions.is_screencast) { | 2075 if (dimensions.is_screencast) { |
2082 int screencast_min_bitrate_kbps; | 2076 RTC_CHECK(parameters_.options.screencast_min_bitrate); |
2083 parameters_.options.screencast_min_bitrate.Get( | |
2084 &screencast_min_bitrate_kbps); | |
2085 encoder_config.min_transmit_bitrate_bps = | 2077 encoder_config.min_transmit_bitrate_bps = |
2086 screencast_min_bitrate_kbps * 1000; | 2078 *parameters_.options.screencast_min_bitrate * 1000; |
2087 encoder_config.content_type = | 2079 encoder_config.content_type = |
2088 webrtc::VideoEncoderConfig::ContentType::kScreen; | 2080 webrtc::VideoEncoderConfig::ContentType::kScreen; |
2089 } else { | 2081 } else { |
2090 encoder_config.min_transmit_bitrate_bps = 0; | 2082 encoder_config.min_transmit_bitrate_bps = 0; |
2091 encoder_config.content_type = | 2083 encoder_config.content_type = |
2092 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; | 2084 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
2093 } | 2085 } |
2094 | 2086 |
2095 // Restrict dimensions according to codec max. | 2087 // Restrict dimensions according to codec max. |
2096 int width = dimensions.width; | 2088 int width = dimensions.width; |
(...skipping 15 matching lines...) Expand all Loading... |
2112 size_t stream_count = parameters_.config.rtp.ssrcs.size(); | 2104 size_t stream_count = parameters_.config.rtp.ssrcs.size(); |
2113 if (IsCodecBlacklistedForSimulcast(codec.name) || dimensions.is_screencast) { | 2105 if (IsCodecBlacklistedForSimulcast(codec.name) || dimensions.is_screencast) { |
2114 stream_count = 1; | 2106 stream_count = 1; |
2115 } | 2107 } |
2116 | 2108 |
2117 encoder_config.streams = | 2109 encoder_config.streams = |
2118 CreateVideoStreams(clamped_codec, parameters_.options, | 2110 CreateVideoStreams(clamped_codec, parameters_.options, |
2119 parameters_.max_bitrate_bps, stream_count); | 2111 parameters_.max_bitrate_bps, stream_count); |
2120 | 2112 |
2121 // Conference mode screencast uses 2 temporal layers split at 100kbit. | 2113 // Conference mode screencast uses 2 temporal layers split at 100kbit. |
2122 if (parameters_.options.conference_mode.GetWithDefaultIfUnset(false) && | 2114 if (parameters_.options.conference_mode.value_or(false) && |
2123 dimensions.is_screencast && encoder_config.streams.size() == 1) { | 2115 dimensions.is_screencast && encoder_config.streams.size() == 1) { |
2124 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); | 2116 ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |
2125 | 2117 |
2126 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked | 2118 // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked |
2127 // on the VideoCodec struct as target and max bitrates, respectively. | 2119 // on the VideoCodec struct as target and max bitrates, respectively. |
2128 // See eg. webrtc::VP8EncoderImpl::SetRates(). | 2120 // See eg. webrtc::VP8EncoderImpl::SetRates(). |
2129 encoder_config.streams[0].target_bitrate_bps = | 2121 encoder_config.streams[0].target_bitrate_bps = |
2130 config.tl0_bitrate_kbps * 1000; | 2122 config.tl0_bitrate_kbps * 1000; |
2131 encoder_config.streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; | 2123 encoder_config.streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; |
2132 encoder_config.streams[0].temporal_layer_thresholds_bps.clear(); | 2124 encoder_config.streams[0].temporal_layer_thresholds_bps.clear(); |
(...skipping 14 matching lines...) Expand all Loading... |
2147 } | 2139 } |
2148 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height | 2140 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height |
2149 << (is_screencast ? " (screencast)" : " (not screencast)"); | 2141 << (is_screencast ? " (screencast)" : " (not screencast)"); |
2150 | 2142 |
2151 last_dimensions_.width = width; | 2143 last_dimensions_.width = width; |
2152 last_dimensions_.height = height; | 2144 last_dimensions_.height = height; |
2153 last_dimensions_.is_screencast = is_screencast; | 2145 last_dimensions_.is_screencast = is_screencast; |
2154 | 2146 |
2155 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); | 2147 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |
2156 | 2148 |
2157 VideoCodecSettings codec_settings; | 2149 RTC_CHECK(parameters_.codec_settings); |
2158 parameters_.codec_settings.Get(&codec_settings); | 2150 VideoCodecSettings codec_settings = *parameters_.codec_settings; |
2159 | 2151 |
2160 webrtc::VideoEncoderConfig encoder_config = | 2152 webrtc::VideoEncoderConfig encoder_config = |
2161 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); | 2153 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
2162 | 2154 |
2163 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( | 2155 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( |
2164 codec_settings.codec, parameters_.options, is_screencast); | 2156 codec_settings.codec, parameters_.options, is_screencast); |
2165 | 2157 |
2166 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); | 2158 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); |
2167 | 2159 |
2168 encoder_config.encoder_specific_settings = NULL; | 2160 encoder_config.encoder_specific_settings = NULL; |
(...skipping 24 matching lines...) Expand all Loading... |
2193 | 2185 |
2194 VideoSenderInfo | 2186 VideoSenderInfo |
2195 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { | 2187 WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
2196 VideoSenderInfo info; | 2188 VideoSenderInfo info; |
2197 webrtc::VideoSendStream::Stats stats; | 2189 webrtc::VideoSendStream::Stats stats; |
2198 { | 2190 { |
2199 rtc::CritScope cs(&lock_); | 2191 rtc::CritScope cs(&lock_); |
2200 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) | 2192 for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
2201 info.add_ssrc(ssrc); | 2193 info.add_ssrc(ssrc); |
2202 | 2194 |
2203 VideoCodecSettings codec_settings; | 2195 if (parameters_.codec_settings) |
2204 if (parameters_.codec_settings.Get(&codec_settings)) | 2196 info.codec_name = parameters_.codec_settings->codec.name; |
2205 info.codec_name = codec_settings.codec.name; | |
2206 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { | 2197 for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { |
2207 if (i == parameters_.encoder_config.streams.size() - 1) { | 2198 if (i == parameters_.encoder_config.streams.size() - 1) { |
2208 info.preferred_bitrate += | 2199 info.preferred_bitrate += |
2209 parameters_.encoder_config.streams[i].max_bitrate_bps; | 2200 parameters_.encoder_config.streams[i].max_bitrate_bps; |
2210 } else { | 2201 } else { |
2211 info.preferred_bitrate += | 2202 info.preferred_bitrate += |
2212 parameters_.encoder_config.streams[i].target_bitrate_bps; | 2203 parameters_.encoder_config.streams[i].target_bitrate_bps; |
2213 } | 2204 } |
2214 } | 2205 } |
2215 | 2206 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2307 int width = last_dimensions_.width; | 2298 int width = last_dimensions_.width; |
2308 last_dimensions_.width = 0; | 2299 last_dimensions_.width = 0; |
2309 SetDimensions(width, last_dimensions_.height, last_dimensions_.is_screencast); | 2300 SetDimensions(width, last_dimensions_.height, last_dimensions_.is_screencast); |
2310 } | 2301 } |
2311 | 2302 |
2312 void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { | 2303 void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { |
2313 if (stream_ != NULL) { | 2304 if (stream_ != NULL) { |
2314 call_->DestroyVideoSendStream(stream_); | 2305 call_->DestroyVideoSendStream(stream_); |
2315 } | 2306 } |
2316 | 2307 |
2317 VideoCodecSettings codec_settings; | 2308 RTC_CHECK(parameters_.codec_settings); |
2318 parameters_.codec_settings.Get(&codec_settings); | |
2319 parameters_.encoder_config.encoder_specific_settings = | 2309 parameters_.encoder_config.encoder_specific_settings = |
2320 ConfigureVideoEncoderSettings( | 2310 ConfigureVideoEncoderSettings( |
2321 codec_settings.codec, parameters_.options, | 2311 parameters_.codec_settings->codec, parameters_.options, |
2322 parameters_.encoder_config.content_type == | 2312 parameters_.encoder_config.content_type == |
2323 webrtc::VideoEncoderConfig::ContentType::kScreen); | 2313 webrtc::VideoEncoderConfig::ContentType::kScreen); |
2324 | 2314 |
2325 webrtc::VideoSendStream::Config config = parameters_.config; | 2315 webrtc::VideoSendStream::Config config = parameters_.config; |
2326 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { | 2316 if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { |
2327 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " | 2317 LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " |
2328 "payload type the set codec. Ignoring RTX."; | 2318 "payload type the set codec. Ignoring RTX."; |
2329 config.rtp.rtx.ssrcs.clear(); | 2319 config.rtp.rtx.ssrcs.clear(); |
2330 } | 2320 } |
2331 stream_ = call_->CreateVideoSendStream(config, parameters_.encoder_config); | 2321 stream_ = call_->CreateVideoSendStream(config, parameters_.encoder_config); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2749 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2739 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2750 } | 2740 } |
2751 } | 2741 } |
2752 | 2742 |
2753 return video_codecs; | 2743 return video_codecs; |
2754 } | 2744 } |
2755 | 2745 |
2756 } // namespace cricket | 2746 } // namespace cricket |
2757 | 2747 |
2758 #endif // HAVE_WEBRTC_VIDEO | 2748 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |