diff options
author | Roxie Linden <roxie@lindenlab.com> | 2023-12-01 01:14:33 -0800 |
---|---|---|
committer | Roxie Linden <roxie@lindenlab.com> | 2024-02-08 18:34:01 -0800 |
commit | 7a6c7964520d185eefedfedc340b0cc07365ff88 (patch) | |
tree | 11fc551dab8b5741f0b7cfd9a932819f0d11c1bf /indra | |
parent | 82c9e528658412293c264c1e80573e1abc496768 (diff) |
Using the device module to set speaker/mic volume set the system mic/volume
for all applications. Instead, modify the volume on the various streams.
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llwebrtc/llwebrtc.cpp | 56 | ||||
-rw-r--r-- | indra/llwebrtc/llwebrtc.h | 6 | ||||
-rw-r--r-- | indra/llwebrtc/llwebrtc_impl.h | 10 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.cpp | 92 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.h | 18 |
5 files changed, 148 insertions, 34 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index b2f5e0212e..4741ed92a3 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -399,11 +399,6 @@ float LLWebRTCImpl::getTuningAudioLevel() { return 20 * mTuningAudioDeviceObserv float LLWebRTCImpl::getPeerAudioLevel() { return 20 * mPeerAudioDeviceObserver->getMicrophoneEnergy(); } -void LLWebRTCImpl::setSpeakerVolume(float volume) { mPeerDeviceModule->SetSpeakerVolume( (uint32_t)(volume * VOLUME_SCALE_WEBRTC));} -void LLWebRTCImpl::setMicrophoneVolume(float volume) { mPeerDeviceModule->SetMicrophoneVolume((uint32_t)(volume * VOLUME_SCALE_WEBRTC));} - -void LLWebRTCImpl::setMute(bool mute) { mPeerDeviceModule->SetMicrophoneMute(mute); } - // // Helpers // @@ -417,6 +412,7 @@ LLWebRTCPeerConnection * LLWebRTCImpl::newPeerConnection() peerConnection->enableTracks(!mMute); return peerConnection.get(); } + void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnection * peer_connection) { std::vector<rtc::scoped_refptr<LLWebRTCPeerConnectionImpl>>::iterator it = @@ -506,12 +502,11 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection() audioOptions.echo_cancellation = false; // incompatible with opus stereo audioOptions.noise_suppression = true; - rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = mPeerConnectionFactory->CreateLocalMediaStream("SLStream"); - + mLocalStream = mPeerConnectionFactory->CreateLocalMediaStream("SLStream"); rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( mPeerConnectionFactory->CreateAudioTrack("SLAudio", mPeerConnectionFactory->CreateAudioSource(audioOptions).get())); audio_track->set_enabled(true); - stream->AddTrack(audio_track); + mLocalStream->AddTrack(audio_track); mPeerConnection->AddTrack(audio_track, {"SLStream"}); @@ -545,6 +540,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection() params.codecs.push_back(codecparam); receiver->SetParameters(params); } + webrtc::PeerConnectionInterface::RTCOfferAnswerOptions offerOptions; mPeerConnection->CreateOffer(this, offerOptions); @@ -606,13 +602,47 @@ void LLWebRTCPeerConnectionImpl::AnswerAvailable(const std::string &sdp) void LLWebRTCPeerConnectionImpl::setMute(bool mute) { mMute = mute; - auto senders = mPeerConnection->GetSenders(); - - RTC_LOG(LS_INFO) << __FUNCTION__ << (mute ? "disabling" : "enabling") << " streams count " << senders.size(); + if (mPeerConnection) + { + auto senders = mPeerConnection->GetSenders(); + + RTC_LOG(LS_INFO) << __FUNCTION__ << (mute ? "disabling" : "enabling") << " streams count " << senders.size(); + for (auto &sender : senders) + { + auto track = sender->track(); + if(track) + { + track->set_enabled(!mMute); + } + } + } +} + +void LLWebRTCPeerConnectionImpl::setReceiveVolume(float volume) +{ + auto receivers = mPeerConnection->GetReceivers(); - for (auto &sender : senders) + for (auto &receiver : receivers) { - sender->track()->set_enabled(!mMute); + for (auto& stream : receiver->streams()) + { + for (auto& track : stream->GetAudioTracks()) + { + track->GetSource()->SetVolume(volume); + } + } + } +} + +void LLWebRTCPeerConnectionImpl::setSendVolume(float volume) +{ + if (mLocalStream) + { + auto track = mLocalStream->FindAudioTrack("SLStream"); + if (track) + { + track->GetSource()->SetVolume(volume); + } } } diff --git a/indra/llwebrtc/llwebrtc.h b/indra/llwebrtc/llwebrtc.h index ed80fa5648..9766f2f231 100644 --- a/indra/llwebrtc/llwebrtc.h +++ b/indra/llwebrtc/llwebrtc.h @@ -85,10 +85,6 @@ class LLWebRTCDeviceInterface virtual void setTuningMode(bool enable) = 0; virtual float getTuningAudioLevel() = 0; - - virtual void setSpeakerVolume(float volume) = 0; // volume between 0.0 and 1.0 - virtual void setMicrophoneVolume(float volume) = 0; // volume between 0.0 and 1.0 - virtual void setMute(bool mute) = 0; virtual float getPeerAudioLevel() = 0; }; @@ -96,6 +92,8 @@ class LLWebRTCAudioInterface { public: virtual void setMute(bool mute) = 0; + virtual void setReceiveVolume(float volume) = 0; // volume between 0.0 and 1.0 + virtual void setSendVolume(float volume) = 0; // volume between 0.0 and 1.0 }; class LLWebRTCDataObserver diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h index 76e29c63fb..efb0d3add3 100644 --- a/indra/llwebrtc/llwebrtc_impl.h +++ b/indra/llwebrtc/llwebrtc_impl.h @@ -116,10 +116,6 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface void setTuningMode(bool enable) override; float getTuningAudioLevel() override; float getPeerAudioLevel() override; - - void setSpeakerVolume(float volume) override; // range 0.0-1.0 - void setMicrophoneVolume(float volume) override; // range 0.0-1.0 - void setMute(bool mute) override; // // Helpers @@ -224,12 +220,13 @@ class LLWebRTCPeerConnectionImpl : public LLWebRTCPeerConnection, void shutdownConnection() override; void AnswerAvailable(const std::string &sdp) override; - // // LLWebRTCAudioInterface // void setMute(bool mute) override; - + void setReceiveVolume(float volume) override; // volume between 0.0 and 1.0 + void setSendVolume(float volume) override; // volume between 0.0 and 1.0 + // // LLWebRTCDataInterface // @@ -291,6 +288,7 @@ class LLWebRTCPeerConnectionImpl : public LLWebRTCPeerConnection, bool mAnswerReceived; rtc::scoped_refptr<webrtc::PeerConnectionInterface> mPeerConnection; + rtc::scoped_refptr<webrtc::MediaStreamInterface> mLocalStream; std::vector<LLWebRTCDataObserver *> mDataObserverList; rtc::scoped_refptr<webrtc::DataChannelInterface> mDataChannel; diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp index 26b617bde4..435e2e1245 100644 --- a/indra/newview/llvoicewebrtc.cpp +++ b/indra/newview/llvoicewebrtc.cpp @@ -746,7 +746,7 @@ void LLWebRTCVoiceClient::sendPositionAndVolumeUpdate(bool force) if (!mMuteMic) { - audio_level = (F32) mWebRTCDeviceInterface->getPeerAudioLevel(); + audio_level = (F32) mWebRTCDeviceInterface->getPeerAudioLevel() * mMicVolume; uint_audio_level = (uint32_t) (audio_level * 128); } @@ -853,6 +853,33 @@ void LLWebRTCVoiceClient::sessionState::sendData(const std::string &data) } } +void LLWebRTCVoiceClient::sessionState::setMuteMic(bool muted) +{ + mMuted = muted; + for (auto& connection : mWebRTCConnections) + { + connection.second->setMuteMic(muted); + } +} + +void LLWebRTCVoiceClient::sessionState::setMicGain(F32 gain) +{ + mMicGain = gain; + for (auto& connection : mWebRTCConnections) + { + connection.second->setMicGain(gain); + } +} + +void LLWebRTCVoiceClient::sessionState::setSpeakerVolume(F32 volume) +{ + mSpeakerVolume = volume; + for (auto& connection : mWebRTCConnections) + { + connection.second->setSpeakerVolume(volume); + } +} + void LLWebRTCVoiceClient::sendLocalAudioUpdates() { } @@ -1723,10 +1750,6 @@ void LLWebRTCVoiceClient::leaveChannel(void) void LLWebRTCVoiceClient::setMuteMic(bool muted) { - if (mWebRTCDeviceInterface) - { - mWebRTCDeviceInterface->setMute(muted); - } mMuteMic = muted; sessionState::for_each(boost::bind(predSetMuteMic, _1, muted)); } @@ -1738,6 +1761,17 @@ void LLWebRTCVoiceClient::predSetMuteMic(const LLWebRTCVoiceClient::sessionState { participant->mPower = 0.0; } + session->setMuteMic(muted); +} + +void LLWebRTCVoiceClient::predSetSpeakerVolume(const LLWebRTCVoiceClient::sessionStatePtr_t &session, F32 volume) +{ + session->setSpeakerVolume(volume); +} + +void LLWebRTCVoiceClient::predSetMicGain(const LLWebRTCVoiceClient::sessionStatePtr_t &session, F32 volume) +{ + session->setMicGain(volume); } void LLWebRTCVoiceClient::setVoiceEnabled(bool enabled) @@ -1838,10 +1872,7 @@ void LLWebRTCVoiceClient::setVoiceVolume(F32 volume) mSpeakerVolume = volume; mSpeakerVolumeDirty = true; } - if (mWebRTCDeviceInterface) - { - mWebRTCDeviceInterface->setSpeakerVolume(volume); - } + sessionState::for_each(boost::bind(predSetSpeakerVolume, _1, volume)); } } @@ -1854,6 +1885,7 @@ void LLWebRTCVoiceClient::setMicGain(F32 volume) mMicVolume = scaled_volume; mMicVolumeDirty = true; } + sessionState::for_each(boost::bind(predSetMicGain, _1, scaled_volume)); } ///////////////////////////// @@ -2059,7 +2091,9 @@ LLWebRTCVoiceClient::sessionState::ptr_t LLWebRTCVoiceClient::sessionState::crea sessionState::ptr_t session(new sessionState()); session->mChannelID = channelID; - session->mWebRTCConnections[channelID] = connectionPtr_t(new LLVoiceWebRTCConnection(region_id, parcelLocalID, channelID)); + connectionPtr_t connection = connectionPtr_t(new LLVoiceWebRTCConnection(region_id, parcelLocalID, channelID)); + session->mWebRTCConnections[channelID] = connection; + session->mPrimaryConnectionID = channelID; // add agent as participant @@ -2190,6 +2224,9 @@ LLWebRTCVoiceClient::sessionStatePtr_t LLWebRTCVoiceClient::addSession(const std LL_DEBUGS("Voice") << "adding new session: CHANNEL " << channel_id << LL_ENDL; result = sessionState::createSession(channel_id, parcel_local_id); + result->setMuteMic(mMuteMic); + result->setMicGain(mMicVolume); + result->setSpeakerVolume(mSpeakerVolume); if (LLVoiceClient::instance().getVoiceEffectEnabled()) { @@ -2442,7 +2479,10 @@ LLVoiceWebRTCConnection::LLVoiceWebRTCConnection(const LLUUID ®ionID, S32 par mChannelID(channelID), mRegionID(regionID), mParcelLocalID(parcelLocalID), - mShutDown(false) + mShutDown(false), + mMuted(true), + mSpeakerVolume(0.0), + mMicGain(0.0) { mWebRTCPeerConnection = llwebrtc::newPeerConnection(); mWebRTCPeerConnection->setSignalingObserver(this); @@ -2821,6 +2861,9 @@ bool LLVoiceWebRTCConnection::connectionStateMachine() case VOICE_STATE_SESSION_ESTABLISHED: { + mWebRTCAudioInterface->setMute(mMuted); + mWebRTCAudioInterface->setReceiveVolume(mSpeakerVolume); + mWebRTCAudioInterface->setSendVolume(mMicGain); LLWebRTCVoiceClient::getInstance()->OnConnectionEstablished(mChannelID); setVoiceConnectionState(VOICE_STATE_SESSION_UP); } @@ -2958,3 +3001,30 @@ void LLVoiceWebRTCConnection::OnVoiceDisconnectionRequestFailure(std::string url } setVoiceConnectionState(VOICE_STATE_SESSION_EXIT); } + +void LLVoiceWebRTCConnection::setMuteMic(bool muted) +{ + mMuted = true; + if (mWebRTCAudioInterface) + { + mWebRTCAudioInterface->setMute(muted); + } +} + +void LLVoiceWebRTCConnection::setMicGain(F32 gain) +{ + mMicGain = gain; + if (mWebRTCAudioInterface) + { + mWebRTCAudioInterface->setSendVolume(gain); + } +} + +void LLVoiceWebRTCConnection::setSpeakerVolume(F32 volume) +{ + mSpeakerVolume = volume; + if (mWebRTCAudioInterface) + { + mWebRTCAudioInterface->setReceiveVolume(volume); + } +} diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h index 456681ed25..f0549495e1 100644 --- a/indra/newview/llvoicewebrtc.h +++ b/indra/newview/llvoicewebrtc.h @@ -336,6 +336,10 @@ public: void OnConnectionFailure(const std::string &channelID); void sendData(const std::string &data); + + void setMuteMic(bool muted); + void setMicGain(F32 volume); + void setSpeakerVolume(F32 volume); static void for_each(sessionFunc_t func); @@ -350,6 +354,10 @@ public: std::string mName; std::string mErrorStatusString; std::queue<std::string> mTextMsgQueue; + + bool mMuted; + F32 mMicGain; + F32 mSpeakerVolume; LLUUID mIMSessionID; LLUUID mCallerID; @@ -404,6 +412,9 @@ public: static void predSendData(const LLWebRTCVoiceClient::sessionStatePtr_t &session, const std::string& spatial_data, const std::string& volume_data); static void predUpdateOwnVolume(const LLWebRTCVoiceClient::sessionStatePtr_t &session, F32 audio_level); static void predSetMuteMic(const LLWebRTCVoiceClient::sessionStatePtr_t &session, bool mute); + static void predSetMicGain(const LLWebRTCVoiceClient::sessionStatePtr_t &session, F32 volume); + static void predSetSpeakerVolume(const LLWebRTCVoiceClient::sessionStatePtr_t &session, F32 volume); + ////////////////////////////// /// @name TVC/Server management and communication //@{ @@ -746,6 +757,9 @@ class LLVoiceWebRTCConnection : bool connectionStateMachine(); void sendData(const std::string &data); + void setMuteMic(bool muted); + void setMicGain(F32 volume); + void setSpeakerVolume(F32 volume); void shutDown() { @@ -811,6 +825,10 @@ protected: bool mShutDown; + bool mMuted; + F32 mMicGain; + F32 mSpeakerVolume; + std::vector<llwebrtc::LLWebRTCIceCandidate> mIceCandidates; bool mIceCompleted; bool mTrickling; |