From e92e4d762ec5b2c122f17edb1a18b21ef6166e8b Mon Sep 17 00:00:00 2001
From: Roxie Linden <roxie@lindenlab.com>
Date: Mon, 4 Dec 2023 14:22:40 -0800
Subject: Mute using enable.

Muting using the device module microphone mute was muting other
applications, speakers, and so on.  Instead, we mute by enabling/disabling
the input and output streams.
---
 indra/llwebrtc/llwebrtc.cpp     | 34 ++++++++++++++++++----------------
 indra/newview/llvoicewebrtc.cpp | 16 ----------------
 indra/newview/llvoicewebrtc.h   |  1 -
 3 files changed, 18 insertions(+), 33 deletions(-)

(limited to 'indra')

diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp
index 2bcbb135c0..9fd8fd8ee6 100644
--- a/indra/llwebrtc/llwebrtc.cpp
+++ b/indra/llwebrtc/llwebrtc.cpp
@@ -287,16 +287,11 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id)
                                         break;
                                     }
                                 }
-                                mTuningDeviceModule->SetSpeakerMute(true);
                                 bool was_tuning_playing = mTuningDeviceModule->Playing();
                                 if (was_tuning_playing)
                                 {
                                     mTuningDeviceModule->StopPlayout();
                                 }
-                                if (mPeerDeviceModule)
-                                {
-                                    mPeerDeviceModule->SetSpeakerMute(true);
-                                }
                                 
                                 mTuningDeviceModule->SetPlayoutDevice(tuningPlayoutDevice);
                                 mTuningDeviceModule->InitSpeaker();
@@ -326,10 +321,8 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id)
                                     mPeerDeviceModule->InitSpeaker();
                                     mPeerDeviceModule->InitPlayout();
                                     mPeerDeviceModule->StartPlayout();
-                                    mPeerDeviceModule->SetSpeakerMute(false);
                                     
                                 }
-                                mTuningDeviceModule->SetSpeakerMute(false);
                             });
 }
 
@@ -369,29 +362,25 @@ void LLWebRTCImpl::setTuningMode(bool enable)
                                     {
                                         
                                         mTuningDeviceModule->StartRecording();
-                                        mTuningDeviceModule->SetMicrophoneMute(false);
-                                        
-                                        
-                                        mTuningDeviceModule->SetSpeakerMute(false);
                                         
                                         if (mPeerDeviceModule)
                                         {
                                             mPeerDeviceModule->StopRecording();
-                                            mPeerDeviceModule->SetSpeakerMute(true);
                                         }
                                     }
                                     else
                                     {
+                                        mTuningDeviceModule->StartRecording();
                                         if (mPeerDeviceModule)
                                         {
                                             mPeerDeviceModule->StartRecording();
-                                            mPeerDeviceModule->SetSpeakerMute(false);
                                         }
                                     }
                                 });
     for (auto& connection : mPeerConnections)
     {
-        connection->enableTracks(enable ? false : !mMute);
+        connection->enableSenderTracks(enable ? false : !mMute);
+        connection->enableReceiverTracks(!enable);
     }
 }
 
@@ -409,7 +398,7 @@ LLWebRTCPeerConnection * LLWebRTCImpl::newPeerConnection()
     peerConnection->init(this);
         
     mPeerConnections.emplace_back(peerConnection);
-    peerConnection->enableTracks(!mMute);
+    peerConnection->enableSenderTracks(!mMute);
     return peerConnection.get();
 }
 
@@ -570,7 +559,7 @@ void LLWebRTCPeerConnectionImpl::shutdownConnection()
                                  });
 }
 
-void LLWebRTCPeerConnectionImpl::enableTracks(bool enable)
+void LLWebRTCPeerConnectionImpl::enableSenderTracks(bool enable)
 {
     // set_enabled shouldn't be done on the worker thread
     if (mPeerConnection)
@@ -583,6 +572,19 @@ void LLWebRTCPeerConnectionImpl::enableTracks(bool enable)
     }
 }
 
+void LLWebRTCPeerConnectionImpl::enableReceiverTracks(bool enable)
+{
+    // set_enabled shouldn't be done on the worker thread
+    if (mPeerConnection)
+    {
+        auto receivers = mPeerConnection->GetReceivers();
+        for (auto &receiver : receivers)
+        {
+            receiver->track()->set_enabled(enable);
+        }
+    }
+}
+
 void LLWebRTCPeerConnectionImpl::AnswerAvailable(const std::string &sdp)
 {
     RTC_LOG(LS_INFO) << __FUNCTION__ << " Remote SDP: " << sdp;
diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp
index 435e2e1245..ddd757c39f 100644
--- a/indra/newview/llvoicewebrtc.cpp
+++ b/indra/newview/llvoicewebrtc.cpp
@@ -261,7 +261,6 @@ LLWebRTCVoiceClient::LLWebRTCVoiceClient() :
 
     mEarLocation(0),
     mSpeakerVolumeDirty(true),
-    mSpeakerMuteDirty(true),
     mMicVolume(0),
     mMicVolumeDirty(true),
 
@@ -583,16 +582,7 @@ LLVoiceDeviceList& LLWebRTCVoiceClient::getCaptureDevices()
 
 void LLWebRTCVoiceClient::setCaptureDevice(const std::string& name)
 {
-    bool inTuningMode = mIsInTuningMode;
-    if (inTuningMode)
-    {
-        tuningStop();
-	}
     mWebRTCDeviceInterface->setCaptureDevice(name);
-    if (inTuningMode)
-    {
-        tuningStart();
-    }
 }
 void LLWebRTCVoiceClient::setDevicesListUpdated(bool state)
 {
@@ -1863,12 +1853,6 @@ void LLWebRTCVoiceClient::setVoiceVolume(F32 volume)
 	if (volume != mSpeakerVolume)
 	{
         {
-            int         min_volume = 0.0;
-            if ((volume == min_volume) || (mSpeakerVolume == min_volume))
-            {
-                mSpeakerMuteDirty = true;
-            }
-
             mSpeakerVolume      = volume;
             mSpeakerVolumeDirty = true;
         }
diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h
index f0549495e1..2eb74ed2cb 100644
--- a/indra/newview/llvoicewebrtc.h
+++ b/indra/newview/llvoicewebrtc.h
@@ -645,7 +645,6 @@ private:
 	S32			mEarLocation;  
 	
 	bool		mSpeakerVolumeDirty;
-	bool		mSpeakerMuteDirty;
 	float		mSpeakerVolume;
 
 	int			mMicVolume;
-- 
cgit v1.2.3