diff options
author | Roxie Linden <roxie@lindenlab.com> | 2023-10-03 15:51:37 -0700 |
---|---|---|
committer | Roxie Linden <roxie@lindenlab.com> | 2024-02-08 18:34:01 -0800 |
commit | 6b29ced7071baf3fcf5fa2f12fd92cd2cbeda9a8 (patch) | |
tree | 81c5579ca4bd71449a32d522e0574b95ac44b4e4 /indra/llwebrtc | |
parent | 8bd96753113a95aaa8c92fe78713498cbc42a437 (diff) |
fix device selection while speaking.
Diffstat (limited to 'indra/llwebrtc')
-rw-r--r-- | indra/llwebrtc/llwebrtc.cpp | 107 | ||||
-rw-r--r-- | indra/llwebrtc/llwebrtc_impl.h | 3 |
2 files changed, 57 insertions, 53 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 95f87ed65b..eda25a3641 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -131,10 +131,12 @@ void LLWebRTCImpl::terminate() { if (mTuningDeviceModule) { + mTuningDeviceModule->StopRecording(); mTuningDeviceModule->Terminate(); } if (mPeerDeviceModule) { + mPeerDeviceModule->StopRecording(); mPeerDeviceModule->Terminate(); } mTuningDeviceModule = nullptr; @@ -174,43 +176,32 @@ void LLWebRTCImpl::setCaptureDevice(const std::string &id) mWorkerThread->PostTask( [this, id]() { - bool was_tuning_recording = mTuningDeviceModule->Recording(); - - if (was_tuning_recording) - { - mTuningDeviceModule->StopRecording(); - } - bool was_peer_recording = false; - if (mPeerDeviceModule) - { - was_peer_recording = mPeerDeviceModule->Recording(); - if (was_peer_recording) - { - mPeerDeviceModule->StopRecording(); - } - } int16_t captureDeviceCount = mTuningDeviceModule->RecordingDevices(); for (int16_t i = 0; i < captureDeviceCount; i++) { char name[webrtc::kAdmMaxDeviceNameSize]; char guid[webrtc::kAdmMaxGuidSize]; mTuningDeviceModule->RecordingDeviceName(i, name, guid); - if (id == guid || id == "Default") // first one in list is default + if (id == guid || id == "Default") // first one in list is default { RTC_LOG(LS_INFO) << __FUNCTION__ << "Set recording device to " << name << " " << guid << " " << i; mRecordingDevice = i; break; } } + mTuningDeviceModule->StopRecording(); mTuningDeviceModule->SetRecordingDevice(mRecordingDevice); mTuningDeviceModule->InitMicrophone(); mTuningDeviceModule->InitRecording(); - if (was_tuning_recording) - { - mTuningDeviceModule->StartRecording(); - } + mTuningDeviceModule->StartRecording(); + bool was_peer_recording = false; if (mPeerDeviceModule) { + was_peer_recording = mPeerDeviceModule->Recording(); + if (was_peer_recording) + { + mPeerDeviceModule->StopRecording(); + } mPeerDeviceModule->SetRecordingDevice(mRecordingDevice); mPeerDeviceModule->InitMicrophone(); mPeerDeviceModule->InitRecording(); @@ -227,20 +218,6 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id) mWorkerThread->PostTask( [this, id]() { - bool was_tuning_playing = mTuningDeviceModule->Playing(); - if (was_tuning_playing) - { - mTuningDeviceModule->StopPlayout(); - } - bool was_peer_playing = false; - if (mPeerDeviceModule) - { - was_peer_playing = mPeerDeviceModule->Playing(); - if (was_tuning_playing) - { - mPeerDeviceModule->StopPlayout(); - } - } int16_t renderDeviceCount = mTuningDeviceModule->PlayoutDevices(); for (int16_t i = 0; i < renderDeviceCount; i++) { @@ -254,6 +231,22 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id) break; } } + mTuningDeviceModule->SetSpeakerMute(true); + bool was_tuning_playing = mTuningDeviceModule->Playing(); + if (was_tuning_playing) + { + mTuningDeviceModule->StopPlayout(); + } + bool was_peer_mute = false; + if (mPeerDeviceModule) + { + mPeerDeviceModule->SpeakerMute(&was_peer_mute); + if (!was_peer_mute) + { + mPeerDeviceModule->SetSpeakerMute(true); + } + } + mTuningDeviceModule->SetPlayoutDevice(mPlayoutDevice); mTuningDeviceModule->InitSpeaker(); mTuningDeviceModule->InitPlayout(); @@ -266,11 +259,11 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id) mPeerDeviceModule->SetPlayoutDevice(mPlayoutDevice); mPeerDeviceModule->InitSpeaker(); mPeerDeviceModule->InitPlayout(); - if (was_peer_playing) - { - mPeerDeviceModule->StartPlayout(); - } + mPeerDeviceModule->StartPlayout(); + mPeerDeviceModule->SetSpeakerMute(was_peer_mute); + } + mTuningDeviceModule->SetSpeakerMute(false); }); } @@ -303,29 +296,42 @@ void LLWebRTCImpl::updateDevices() void LLWebRTCImpl::setTuningMode(bool enable) { - mWorkerThread->PostTask( + mWorkerThread->BlockingCall( [this, enable]() { if (enable) { + mTuningDeviceModule->StartRecording(); mTuningDeviceModule->SetMicrophoneMute(false); + + + mTuningDeviceModule->SetSpeakerMute(false); + if (mPeerDeviceModule) { mPeerDeviceModule->StopRecording(); - mPeerDeviceModule->StopPlayout(); + mPeerDeviceModule->SetSpeakerMute(true); } } else { - mTuningDeviceModule->StopRecording(); if (mPeerDeviceModule) { - mPeerDeviceModule->StartPlayout(); mPeerDeviceModule->StartRecording(); + mPeerDeviceModule->SetSpeakerMute(false); } } }); + // set_enabled shouldn't be done on the worker thread + if (mPeerConnection) + { + auto senders = mPeerConnection->GetSenders(); + for (auto &sender : senders) + { + sender->track()->set_enabled(enable ? false : !mMute); + } + } } // @@ -538,18 +544,15 @@ void LLWebRTCImpl::AnswerAvailable(const std::string &sdp) void LLWebRTCImpl::setMute(bool mute) { - mSignalingThread->PostTask( - [this, mute]() - { - auto senders = mPeerConnection->GetSenders(); + mMute = mute; + auto senders = mPeerConnection->GetSenders(); - RTC_LOG(LS_INFO) << __FUNCTION__ << (mute ? "disabling" : "enabling") << " streams count " << senders.size(); + RTC_LOG(LS_INFO) << __FUNCTION__ << (mute ? "disabling" : "enabling") << " streams count " << senders.size(); - for (auto &sender : senders) - { - sender->track()->set_enabled(!mute); - } - }); + for (auto &sender : senders) + { + sender->track()->set_enabled(!mMute); + } } void LLWebRTCImpl::setSpeakerVolume(float volume) diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h index 947b417923..24edd6eaa2 100644 --- a/indra/llwebrtc/llwebrtc_impl.h +++ b/indra/llwebrtc/llwebrtc_impl.h @@ -100,7 +100,7 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, { public: LLWebRTCImpl() : - mTuningAudioDeviceObserver(nullptr), mPeerAudioDeviceObserver(nullptr) + mTuningAudioDeviceObserver(nullptr), mPeerAudioDeviceObserver(nullptr), mMute(true) { } ~LLWebRTCImpl() {} @@ -209,6 +209,7 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, // accessors in webrtc aren't apparently implemented yet. int32_t mPlayoutDevice; int32_t mRecordingDevice; + bool mMute; LLAudioDeviceObserver * mTuningAudioDeviceObserver; LLAudioDeviceObserver * mPeerAudioDeviceObserver; |