From 6504b2a0f92456ccd981d7d22473d6ee597ab26a Mon Sep 17 00:00:00 2001 From: Rashad Sookram Date: Wed, 27 Sep 2023 12:16:54 -0400 Subject: [PATCH] Add Rust_setIncomingAudioMuted --- api/neteq/neteq.h | 3 +++ api/peer_connection_interface.h | 3 +++ audio/audio_receive_stream.cc | 5 +++++ audio/audio_receive_stream.h | 3 +++ audio/channel_receive.cc | 7 +++++++ audio/channel_receive.h | 2 ++ call/audio_receive_stream.h | 3 +++ media/base/media_channel.h | 3 +++ media/base/media_channel_shim.h | 5 +++++ media/engine/webrtc_voice_engine.cc | 13 +++++++++++++ media/engine/webrtc_voice_engine.h | 3 +++ modules/audio_coding/acm2/acm_receiver.cc | 5 +++++ modules/audio_coding/acm2/acm_receiver.h | 3 +++ modules/audio_coding/neteq/neteq_impl.cc | 13 +++++++++++++ modules/audio_coding/neteq/neteq_impl.h | 5 +++++ pc/channel.cc | 7 +++++++ pc/channel.h | 3 +++ pc/peer_connection.cc | 8 ++++++++ pc/peer_connection.h | 2 ++ pc/peer_connection_proxy.h | 2 ++ ringrtc/rffi/api/peer_connection_intf.h | 5 +++++ ringrtc/rffi/src/peer_connection.cc | 8 ++++++++ 22 files changed, 111 insertions(+) diff --git a/api/neteq/neteq.h b/api/neteq/neteq.h index 43e0e09784..c56a612f8f 100644 --- a/api/neteq/neteq.h +++ b/api/neteq/neteq.h @@ -302,6 +302,9 @@ class NetEq { // Flushes both the packet buffer and the sync buffer. virtual void FlushBuffers() = 0; + // RingRTC change to disable CNG for muted incoming streams. + virtual void SetIncomingAudioMuted(bool muted) = 0; + // Enables NACK and sets the maximum size of the NACK list, which should be // positive and no larger than Nack::kNackListSizeLimit. If NACK is already // enabled then the maximum NACK list size is modified accordingly. diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index 1edd256d53..84662dd364 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -1217,6 +1217,9 @@ class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface { // the appropriate SDP is also applied. virtual void SetAudioRecording(bool recording) {} + // RingRTC change to disable CNG for muted incoming streams. + virtual void SetIncomingAudioMuted(uint32_t ssrc, bool muted) {} + // Looks up the DtlsTransport associated with a MID value. // In the Javascript API, DtlsTransport is a property of a sender, but // because the PeerConnection owns the DtlsTransport in this implementation, diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc index d417a7475c..6418edafe1 100644 --- a/audio/audio_receive_stream.cc +++ b/audio/audio_receive_stream.cc @@ -182,6 +182,11 @@ void AudioReceiveStreamImpl::ReconfigureForTesting( config_ = config; } +// RingRTC change to disable CNG for muted incoming streams. +void AudioReceiveStreamImpl::SetIncomingAudioMuted(bool muted) { + channel_receive_->SetIncomingAudioMuted(muted); +} + // RingRTC change to get recv audio levels uint16_t AudioReceiveStreamImpl::GetAudioLevel() { return channel_receive_->GetSpeechOutputLevelFullRange(); diff --git a/audio/audio_receive_stream.h b/audio/audio_receive_stream.h index 3555bb9f5b..2d0c0b803e 100644 --- a/audio/audio_receive_stream.h +++ b/audio/audio_receive_stream.h @@ -143,6 +143,9 @@ class AudioReceiveStreamImpl final : public webrtc::AudioReceiveStreamInterface, void ReconfigureForTesting( const webrtc::AudioReceiveStreamInterface::Config& config); + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(bool muted) override; + // RingRTC change to get recv audio levels uint16_t GetAudioLevel() override; diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc index 5f8ac0be7a..5b71fa597d 100644 --- a/audio/channel_receive.cc +++ b/audio/channel_receive.cc @@ -129,6 +129,8 @@ class ChannelReceive : public ChannelReceiveInterface, // Muting, Volume and Level. void SetChannelOutputVolumeScaling(float scaling) override; + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(bool muted) override; int GetSpeechOutputLevelFullRange() const override; // See description of "totalAudioEnergy" in the WebRTC stats spec: // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy @@ -777,6 +779,11 @@ void ChannelReceive::ReceivedRTCPPacket(const uint8_t* data, size_t length) { } } +// RingRTC change to disable CNG for muted incoming streams. +void ChannelReceive::SetIncomingAudioMuted(bool muted) { + acm_receiver_.SetIncomingAudioMuted(muted); +} + int ChannelReceive::GetSpeechOutputLevelFullRange() const { RTC_DCHECK_RUN_ON(&worker_thread_checker_); return _outputAudioLevel.LevelFullRange(); diff --git a/audio/channel_receive.h b/audio/channel_receive.h index 688f092814..ac2c19c1e7 100644 --- a/audio/channel_receive.h +++ b/audio/channel_receive.h @@ -104,6 +104,8 @@ class ChannelReceiveInterface : public RtpPacketSinkInterface { virtual void ReceivedRTCPPacket(const uint8_t* data, size_t length) = 0; virtual void SetChannelOutputVolumeScaling(float scaling) = 0; + // RingRTC change to disable CNG for muted incoming streams. + virtual void SetIncomingAudioMuted(bool muted) = 0; virtual int GetSpeechOutputLevelFullRange() const = 0; // See description of "totalAudioEnergy" in the WebRTC stats spec: // https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy diff --git a/call/audio_receive_stream.h b/call/audio_receive_stream.h index 1b9982cc8e..1af7e44b1f 100644 --- a/call/audio_receive_stream.h +++ b/call/audio_receive_stream.h @@ -199,6 +199,9 @@ class AudioReceiveStreamInterface : public MediaReceiveStreamInterface { // Returns current value of base minimum delay in milliseconds. virtual int GetBaseMinimumPlayoutDelayMs() const = 0; + // RingRTC change to disable CNG for muted incoming streams. + virtual void SetIncomingAudioMuted(bool muted) = 0; + // RingRTC change to get recv audio levels virtual uint16_t GetAudioLevel() { RTC_LOG(LS_WARNING) << "Default AudioReceiveStream::GetAudioLevel() does nothing!"; diff --git a/media/base/media_channel.h b/media/base/media_channel.h index 70cb35ec60..ccfaa99778 100644 --- a/media/base/media_channel.h +++ b/media/base/media_channel.h @@ -919,6 +919,9 @@ class VoiceMediaReceiveChannelInterface : public MediaReceiveChannelInterface { virtual void SetDefaultRawAudioSink( std::unique_ptr sink) = 0; + // RingRTC change to disable CNG for muted incoming streams. + virtual void SetIncomingAudioMuted(uint32_t ssrc, bool muted) = 0; + // RingRTC change to get audio levels virtual void GetReceivedAudioLevels( cricket::ReceivedAudioLevel* received_out, diff --git a/media/base/media_channel_shim.h b/media/base/media_channel_shim.h index c657ea283b..c0e9fb1754 100644 --- a/media/base/media_channel_shim.h +++ b/media/base/media_channel_shim.h @@ -273,6 +273,11 @@ class VoiceMediaShimChannel : public VoiceMediaChannel { return receive_impl()->GetStats(info, reset_legacy); } + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(uint32_t ssrc, bool muted) override { + return receive_impl()->SetIncomingAudioMuted(ssrc, muted); + } + // RingRTC change to get audio levels void GetReceivedAudioLevels( cricket::ReceivedAudioLevel* received_out, diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc index 95b267eb60..593f4508b2 100644 --- a/media/engine/webrtc_voice_engine.cc +++ b/media/engine/webrtc_voice_engine.cc @@ -2769,6 +2769,19 @@ bool WebRtcVoiceReceiveChannel::MaybeDeregisterUnsignaledRecvStream( return false; } +// RingRTC change to disable CNG for muted incoming streams. +void WebRtcVoiceReceiveChannel::SetIncomingAudioMuted(uint32_t ssrc, bool muted) { + auto it = recv_streams_.find(ssrc); + if (it == recv_streams_.end()) { + RTC_LOG(LS_WARNING) + << "Attempting to SetIncomingAudioMuted for stream with ssrc " + << ssrc << " which doesn't exist."; + return; + } + + it->second->stream().SetIncomingAudioMuted(muted); +} + // RingRTC change to get audio levels void WebRtcVoiceReceiveChannel::GetReceivedAudioLevels( cricket::ReceivedAudioLevel* received_out, diff --git a/media/engine/webrtc_voice_engine.h b/media/engine/webrtc_voice_engine.h index 5485dcd7b8..e0d4d39512 100644 --- a/media/engine/webrtc_voice_engine.h +++ b/media/engine/webrtc_voice_engine.h @@ -460,6 +460,9 @@ class WebRtcVoiceReceiveChannel final void SetReceiveNackEnabled(bool enabled) override; void SetReceiveNonSenderRttEnabled(bool enabled) override; + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(uint32_t ssrc, bool muted) override; + // RingRTC change to get audio levels void GetReceivedAudioLevels( cricket::ReceivedAudioLevel* received_out, diff --git a/modules/audio_coding/acm2/acm_receiver.cc b/modules/audio_coding/acm2/acm_receiver.cc index a77e472ec1..d17e9b01c4 100644 --- a/modules/audio_coding/acm2/acm_receiver.cc +++ b/modules/audio_coding/acm2/acm_receiver.cc @@ -322,6 +322,11 @@ void AcmReceiver::GetNetworkStatistics( neteq_operations_and_state.packet_buffer_flushes; } +// RingRTC change to disable CNG for muted incoming streams. +void AcmReceiver::SetIncomingAudioMuted(bool muted) { + neteq_->SetIncomingAudioMuted(muted); +} + int AcmReceiver::EnableNack(size_t max_nack_list_size) { neteq_->EnableNack(max_nack_list_size); return 0; diff --git a/modules/audio_coding/acm2/acm_receiver.h b/modules/audio_coding/acm2/acm_receiver.h index 820150aede..9a56a0d220 100644 --- a/modules/audio_coding/acm2/acm_receiver.h +++ b/modules/audio_coding/acm2/acm_receiver.h @@ -187,6 +187,9 @@ class AcmReceiver { // absl::optional> LastDecoder() const; + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(bool muted); + // // Enable NACK and set the maximum size of the NACK list. If NACK is already // enabled then the maximum NACK list size is modified accordingly. diff --git a/modules/audio_coding/neteq/neteq_impl.cc b/modules/audio_coding/neteq/neteq_impl.cc index 52e8cbad3a..20f4db3a8e 100644 --- a/modules/audio_coding/neteq/neteq_impl.cc +++ b/modules/audio_coding/neteq/neteq_impl.cc @@ -119,6 +119,8 @@ NetEqImpl::NetEqImpl(const NetEq::Config& config, stats_(std::move(deps.stats)), controller_(std::move(deps.neteq_controller)), last_mode_(Mode::kNormal), + // RingRTC change to disable CNG for muted incoming streams. + muted_(false), decoded_buffer_length_(kMaxFrameSize), decoded_buffer_(new int16_t[decoded_buffer_length_]), playout_timestamp_(0), @@ -451,6 +453,12 @@ void NetEqImpl::FlushBuffers() { first_packet_ = true; } +// RingRTC change to disable CNG for muted incoming streams. +void NetEqImpl::SetIncomingAudioMuted(bool muted) { + MutexLock lock(&mutex_); + muted_ = muted; +} + void NetEqImpl::EnableNack(size_t max_nack_list_size) { MutexLock lock(&mutex_); if (!nack_enabled_) { @@ -817,6 +825,11 @@ int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame, return return_value; } + // RingRTC change to disable CNG for muted incoming streams. + if (operation == Operation::kCodecInternalCng && muted_) { + operation = Operation::kExpand; + } + AudioDecoder::SpeechType speech_type; int length = 0; const size_t start_num_packets = packet_list.size(); diff --git a/modules/audio_coding/neteq/neteq_impl.h b/modules/audio_coding/neteq/neteq_impl.h index f27738bcbf..9f293d8426 100644 --- a/modules/audio_coding/neteq/neteq_impl.h +++ b/modules/audio_coding/neteq/neteq_impl.h @@ -188,6 +188,9 @@ class NetEqImpl : public webrtc::NetEq { // Flushes both the packet buffer and the sync buffer. void FlushBuffers() override; + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(bool muted) override; + void EnableNack(size_t max_nack_list_size) override; void DisableNack() override; @@ -376,6 +379,8 @@ class NetEqImpl : public webrtc::NetEq { size_t decoder_frame_length_ RTC_GUARDED_BY(mutex_); Mode last_mode_ RTC_GUARDED_BY(mutex_); Operation last_operation_ RTC_GUARDED_BY(mutex_); + // RingRTC change to disable CNG for muted incoming streams. + bool muted_ RTC_GUARDED_BY(mutex_); absl::optional last_decoded_type_ RTC_GUARDED_BY(mutex_); size_t decoded_buffer_length_ RTC_GUARDED_BY(mutex_); diff --git a/pc/channel.cc b/pc/channel.cc index 67485de2c4..7b44b82ae0 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -1031,6 +1031,13 @@ void VoiceChannel::GetAudioLevels( }); } +// RingRTC change to disable CNG for muted incoming streams. +void VoiceChannel::SetIncomingAudioMuted(uint32_t ssrc, bool muted) { + worker_thread()->BlockingCall([this, ssrc, muted] { + voice_media_receive_channel()->SetIncomingAudioMuted(ssrc, muted); + }); +} + VideoChannel::VideoChannel( rtc::Thread* worker_thread, rtc::Thread* network_thread, diff --git a/pc/channel.h b/pc/channel.h index 465d7e26f6..bb90c9ab19 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -452,6 +452,9 @@ class VoiceChannel : public BaseChannel { // RingRTC change to configure OPUS void ConfigureEncoders(const webrtc::AudioEncoder::Config& config); + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(uint32_t ssrc, bool muted); + // RingRTC change to get audio levels void GetAudioLevels( cricket::AudioLevel* captured_out, diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index fe913710a3..a654820176 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -1747,6 +1747,14 @@ void PeerConnection::SetAudioRecording(bool recording) { audio_state->SetRecording(recording); } +// RingRTC change to disable CNG for muted incoming streams. +void PeerConnection::SetIncomingAudioMuted(uint32_t ssrc, bool muted) { + auto* voice_channel = static_cast(rtp_manager()->GetAudioTransceiver()->internal()->channel()); + if (voice_channel) { + voice_channel->SetIncomingAudioMuted(ssrc, muted); + } +} + void PeerConnection::AddAdaptationResource( rtc::scoped_refptr resource) { if (!worker_thread()->IsCurrent()) { diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 4c06b8c29f..849357de38 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -259,6 +259,8 @@ class PeerConnection : public PeerConnectionInternal, void SetAudioPlayout(bool playout) override; void SetAudioRecording(bool recording) override; + // RingRTC change to disable CNG for muted incoming streams. + void SetIncomingAudioMuted(uint32_t ssrc, bool muted) override; rtc::scoped_refptr LookupDtlsTransportByMid( const std::string& mid) override; diff --git a/pc/peer_connection_proxy.h b/pc/peer_connection_proxy.h index f89edda42c..91e0b45bb5 100644 --- a/pc/peer_connection_proxy.h +++ b/pc/peer_connection_proxy.h @@ -164,6 +164,8 @@ PROXY_METHOD1(bool, SetIncomingRtpEnabled, bool) PROXY_METHOD1(RTCError, SetBitrate, const BitrateSettings&) PROXY_METHOD1(void, SetAudioPlayout, bool) PROXY_METHOD1(void, SetAudioRecording, bool) +// RingRTC change to disable CNG for muted incoming streams. +PROXY_METHOD2(void, SetIncomingAudioMuted, uint32_t, bool) // This method will be invoked on the network thread. See // PeerConnectionFactory::CreatePeerConnectionOrError for more details. PROXY_SECONDARY_METHOD1(rtc::scoped_refptr, diff --git a/ringrtc/rffi/api/peer_connection_intf.h b/ringrtc/rffi/api/peer_connection_intf.h index 7c6d921eeb..5544d2e51c 100644 --- a/ringrtc/rffi/api/peer_connection_intf.h +++ b/ringrtc/rffi/api/peer_connection_intf.h @@ -131,6 +131,11 @@ RUSTEXPORT void Rust_setAudioRecordingEnabled(webrtc::PeerConnectionInterface* peer_connection_borrowed_rc, bool enabled); +RUSTEXPORT void +Rust_setIncomingAudioMuted(webrtc::PeerConnectionInterface* peer_connection_borrowed_rc, + uint32_t ssrc, + bool muted); + RUSTEXPORT bool Rust_addIceCandidateFromSdp(webrtc::PeerConnectionInterface* peer_connection_borrowed_rc, const char* sdp); diff --git a/ringrtc/rffi/src/peer_connection.cc b/ringrtc/rffi/src/peer_connection.cc index 30afda4db2..f58e9c8d78 100644 --- a/ringrtc/rffi/src/peer_connection.cc +++ b/ringrtc/rffi/src/peer_connection.cc @@ -741,6 +741,14 @@ Rust_setAudioRecordingEnabled(webrtc::PeerConnectionInterface* peer_connection_b peer_connection_borrowed_rc->SetAudioRecording(enabled); } +RUSTEXPORT void +Rust_setIncomingAudioMuted(webrtc::PeerConnectionInterface* peer_connection_borrowed_rc, + uint32_t ssrc, + bool muted) { + RTC_LOG(LS_INFO) << "Rust_setIncomingAudioMuted(" << ssrc << ", " << muted << ")"; + peer_connection_borrowed_rc->SetIncomingAudioMuted(ssrc, muted); +} + RUSTEXPORT bool Rust_addIceCandidateFromSdp(PeerConnectionInterface* peer_connection_borrowed_rc, const char* sdp_borrowed) {