From 2efad2182a5f6b8404afd9ea363b3a9088de3207 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Sat, 17 Aug 2024 00:21:27 -0700 Subject: Fixes to managing device start/stop playout/recording. Fixes prevent attempting to start playout/recording before the devices are set up, to prevent restarting playout/recording, to prevent attempts to stop when not playing/recording, and so on... This should address the case where audio device changes can cause an assert. It should also address the case where audio was unnecessarily played or transmitted when connecting. And, when voice is disabled, the audio devices are not set up to play/record so there should be no disruption of bluetooth music from other apps. --- indra/llwebrtc/llwebrtc.cpp | 58 +++++++++++++++++++++++++++++++++++------- indra/llwebrtc/llwebrtc_impl.h | 2 ++ 2 files changed, 51 insertions(+), 9 deletions(-) (limited to 'indra') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 2c890acbdb..d154bfb8eb 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -251,8 +251,7 @@ void LLWebRTCImpl::init() apm_config.noise_suppression.level = webrtc::AudioProcessing::Config::NoiseSuppression::kVeryHigh; apm_config.transient_suppression.enabled = true; apm_config.pipeline.multi_channel_render = true; - apm_config.pipeline.multi_channel_capture = true; - apm_config.pipeline.multi_channel_capture = true; + apm_config.pipeline.multi_channel_capture = false; webrtc::ProcessingConfig processing_config; processing_config.input_stream().set_num_channels(2); @@ -279,7 +278,6 @@ void LLWebRTCImpl::init() nullptr /* audio_mixer */, mAudioProcessingModule); - mWorkerThread->BlockingCall([this]() { mPeerDeviceModule->StartPlayout(); }); } void LLWebRTCImpl::terminate() @@ -340,6 +338,22 @@ void LLWebRTCImpl::setRecording(bool recording) }); } +void LLWebRTCImpl::setPlayout(bool playing) +{ + mWorkerThread->PostTask( + [this, playing]() + { + if (playing) + { + mPeerDeviceModule->StartPlayout(); + } + else + { + mPeerDeviceModule->StopPlayout(); + } + }); +} + void LLWebRTCImpl::setAudioConfig(LLWebRTCDeviceInterface::AudioConfig config) { webrtc::AudioProcessing::Config apm_config; @@ -402,7 +416,6 @@ void LLWebRTCImpl::unsetDevicesObserver(LLWebRTCDevicesObserver *observer) void ll_set_device_module_capture_device(rtc::scoped_refptr device_module, int16_t device) { - device_module->StopRecording(); #if WEBRTC_WIN if (device < 0) { @@ -420,7 +433,6 @@ void ll_set_device_module_capture_device(rtc::scoped_refptrInitMicrophone(); device_module->InitRecording(); device_module->SetStereoRecording(false); - device_module->StartRecording(); } void LLWebRTCImpl::setCaptureDevice(const std::string &id) @@ -444,18 +456,32 @@ void LLWebRTCImpl::setCaptureDevice(const std::string &id) mRecordingDevice = recordingDevice; if (mTuningMode) { - mWorkerThread->PostTask([this, recordingDevice]() { ll_set_device_module_capture_device(mTuningDeviceModule, recordingDevice); }); + mWorkerThread->PostTask([this, recordingDevice]() + { + ll_set_device_module_capture_device(mTuningDeviceModule, recordingDevice); + }); } else { - mWorkerThread->PostTask([this, recordingDevice]() { ll_set_device_module_capture_device(mPeerDeviceModule, recordingDevice); }); + mWorkerThread->PostTask([this, recordingDevice]() + { + bool recording = mPeerDeviceModule->Recording(); + if (recording) + { + mPeerDeviceModule->StopRecording(); + } + ll_set_device_module_capture_device(mPeerDeviceModule, recordingDevice); + if (recording) + { + mPeerDeviceModule->StartRecording(); + } + }); } } void ll_set_device_module_render_device(rtc::scoped_refptr device_module, int16_t device) { - device_module->StopPlayout(); #if WEBRTC_WIN if (device < 0) { @@ -506,8 +532,16 @@ void LLWebRTCImpl::setRenderDevice(const std::string &id) mWorkerThread->PostTask( [this, playoutDevice]() { + bool playing = mPeerDeviceModule->Playing(); + if (playing) + { + mPeerDeviceModule->StopPlayout(); + } ll_set_device_module_render_device(mPeerDeviceModule, playoutDevice); - mPeerDeviceModule->StartPlayout(); + if (playing) + { + mPeerDeviceModule->StartPlayout(); + } }); } } @@ -633,6 +667,11 @@ LLWebRTCPeerConnectionInterface *LLWebRTCImpl::newPeerConnection() rtc::scoped_refptr peerConnection = rtc::scoped_refptr(new rtc::RefCountedObject()); peerConnection->init(this); + if (mPeerConnections.empty()) + { + setRecording(true); + setPlayout(true); + } mPeerConnections.emplace_back(peerConnection); peerConnection->enableSenderTracks(!mMute); return peerConnection.get(); @@ -649,6 +688,7 @@ void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnectionInterface* peer_conn if (mPeerConnections.empty()) { setRecording(false); + setPlayout(false); } } diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h index c5b32123eb..f8a7873af8 100644 --- a/indra/llwebrtc/llwebrtc_impl.h +++ b/indra/llwebrtc/llwebrtc_impl.h @@ -278,6 +278,8 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceS // enables/disables capture via the capture device void setRecording(bool recording); + void setPlayout(bool playing); + protected: LLWebRTCLogSink* mLogSink; -- cgit v1.2.3