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 From 63d17b395b8b4c4ca32a09d64754a99b13abedb1 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Sat, 17 Aug 2024 20:11:46 -0700 Subject: Microphone was being prematurely enabled on login for a short period. The microphone issue was causing a short moment of sound, and was causing bluetooth headsets to switch to hands-free/one channel mode which is disruptive. Also, update webrtc to deal with issue where airpods were garbled after coming out of hands-free mode. --- indra/llwebrtc/llwebrtc.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'indra') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index d154bfb8eb..dd7883f973 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -206,10 +206,10 @@ void LLWebRTCImpl::init() mTuningDeviceModule->SetAudioDeviceSink(this); mTuningDeviceModule->InitMicrophone(); mTuningDeviceModule->InitSpeaker(); + mTuningDeviceModule->SetStereoRecording(false); + mTuningDeviceModule->SetStereoPlayout(true); mTuningDeviceModule->InitRecording(); mTuningDeviceModule->InitPlayout(); - mTuningDeviceModule->SetStereoRecording(true); - mTuningDeviceModule->SetStereoPlayout(true); updateDevices(); }); @@ -227,10 +227,6 @@ void LLWebRTCImpl::init() mPeerDeviceModule->EnableBuiltInAEC(false); mPeerDeviceModule->InitMicrophone(); mPeerDeviceModule->InitSpeaker(); - mPeerDeviceModule->InitRecording(); - mPeerDeviceModule->InitPlayout(); - mPeerDeviceModule->SetStereoRecording(true); - mPeerDeviceModule->SetStereoPlayout(true); }); // The custom processor allows us to retrieve audio data (and levels) @@ -253,6 +249,8 @@ void LLWebRTCImpl::init() apm_config.pipeline.multi_channel_render = true; apm_config.pipeline.multi_channel_capture = false; + mAudioProcessingModule->ApplyConfig(apm_config); + webrtc::ProcessingConfig processing_config; processing_config.input_stream().set_num_channels(2); processing_config.input_stream().set_sample_rate_hz(48000); @@ -263,10 +261,8 @@ void LLWebRTCImpl::init() processing_config.reverse_output_stream().set_num_channels(2); processing_config.reverse_output_stream().set_sample_rate_hz(48000); - mAudioProcessingModule->ApplyConfig(apm_config); mAudioProcessingModule->Initialize(processing_config); - mPeerConnectionFactory = webrtc::CreatePeerConnectionFactory(mNetworkThread.get(), mWorkerThread.get(), mSignalingThread.get(), @@ -329,6 +325,8 @@ void LLWebRTCImpl::setRecording(bool recording) { if (recording) { + mPeerDeviceModule->SetStereoRecording(false); + mPeerDeviceModule->InitRecording(); mPeerDeviceModule->StartRecording(); } else @@ -345,6 +343,8 @@ void LLWebRTCImpl::setPlayout(bool playing) { if (playing) { + mPeerDeviceModule->SetStereoPlayout(true); + mPeerDeviceModule->InitPlayout(); mPeerDeviceModule->StartPlayout(); } else @@ -430,9 +430,9 @@ void ll_set_device_module_capture_device(rtc::scoped_refptrSetRecordingDevice(device + 1); #endif + device_module->SetStereoRecording(false); device_module->InitMicrophone(); device_module->InitRecording(); - device_module->SetStereoRecording(false); } void LLWebRTCImpl::setCaptureDevice(const std::string &id) @@ -494,9 +494,9 @@ void ll_set_device_module_render_device(rtc::scoped_refptrSetPlayoutDevice(device + 1); #endif + device_module->SetStereoPlayout(true); device_module->InitSpeaker(); device_module->InitPlayout(); - device_module->SetStereoPlayout(true); } void LLWebRTCImpl::setRenderDevice(const std::string &id) @@ -626,6 +626,8 @@ void LLWebRTCImpl::setTuningMode(bool enable) //mTuningDeviceModule->StopPlayout(); ll_set_device_module_render_device(mPeerDeviceModule, mPlayoutDevice); ll_set_device_module_capture_device(mPeerDeviceModule, mRecordingDevice); + mPeerDeviceModule->SetStereoPlayout(true); + mPeerDeviceModule->SetStereoRecording(false); mPeerDeviceModule->InitPlayout(); mPeerDeviceModule->InitRecording(); mPeerDeviceModule->StartPlayout(); @@ -667,13 +669,13 @@ LLWebRTCPeerConnectionInterface *LLWebRTCImpl::newPeerConnection() rtc::scoped_refptr peerConnection = rtc::scoped_refptr(new rtc::RefCountedObject()); peerConnection->init(this); + mPeerConnections.emplace_back(peerConnection); + peerConnection->enableSenderTracks(!mMute); if (mPeerConnections.empty()) { setRecording(true); setPlayout(true); } - mPeerConnections.emplace_back(peerConnection); - peerConnection->enableSenderTracks(!mMute); return peerConnection.get(); } @@ -702,7 +704,7 @@ void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnectionInterface* peer_conn LLWebRTCPeerConnectionImpl::LLWebRTCPeerConnectionImpl() : mWebRTCImpl(nullptr), mPeerConnection(nullptr), - mMute(false), + mMute(true), mAnswerReceived(false) { } @@ -724,8 +726,8 @@ void LLWebRTCPeerConnectionImpl::init(LLWebRTCImpl * webrtc_impl) } void LLWebRTCPeerConnectionImpl::terminate() { - mWebRTCImpl->PostSignalingTask( - [=]() + mWebRTCImpl->SignalingBlockingCall( + [this]() { if (mPeerConnection) { @@ -847,7 +849,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti codecparam.clock_rate = 48000; codecparam.num_channels = 2; codecparam.parameters["stereo"] = "1"; - codecparam.parameters["sprop-stereo"] = "1"; + codecparam.parameters["sprop-stereo"] = "0"; params.codecs.push_back(codecparam); sender->SetParameters(params); } @@ -862,7 +864,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti codecparam.clock_rate = 48000; codecparam.num_channels = 2; codecparam.parameters["stereo"] = "1"; - codecparam.parameters["sprop-stereo"] = "1"; + codecparam.parameters["sprop-stereo"] = "0"; params.codecs.push_back(codecparam); receiver->SetParameters(params); } @@ -1009,7 +1011,7 @@ void LLWebRTCPeerConnectionImpl::OnAddTrack(rtc::scoped_refptrSetParameters(params); } @@ -1200,7 +1202,7 @@ void LLWebRTCPeerConnectionImpl::OnSuccess(webrtc::SessionDescriptionInterface * else if (sdp_line.find("a=fmtp:" + opus_payload) == 0) { sdp_mangled_stream << sdp_line << "a=fmtp:" << opus_payload - << " minptime=10;useinbandfec=1;stereo=1;sprop-stereo=1;maxplaybackrate=48000;sprop-maxplaybackrate=48000;sprop-maxcapturerate=48000\n"; + << " minptime=10;useinbandfec=1;stereo=1;sprop-stereo=0;maxplaybackrate=48000;sprop-maxplaybackrate=48000;sprop-maxcapturerate=48000\n"; } else { -- cgit v1.2.3 From 28fdd6e78658f9935eeb2b122265e05aecb548ed Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Sun, 18 Aug 2024 00:30:16 -0700 Subject: Update webrtc to fix loss of stereo in bluetooth issue. When transitioning from mic-on hands-free mode to mic off, it's expected that the audio stream would return to stereo. Inproper logic in the mac device code in webrtc was preventing that. --- indra/llwebrtc/llwebrtc.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra') diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index dd7883f973..0daa767766 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -849,7 +849,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti codecparam.clock_rate = 48000; codecparam.num_channels = 2; codecparam.parameters["stereo"] = "1"; - codecparam.parameters["sprop-stereo"] = "0"; + codecparam.parameters["sprop-stereo"] = "1"; params.codecs.push_back(codecparam); sender->SetParameters(params); } @@ -864,7 +864,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection(const LLWebRTCPeerConnecti codecparam.clock_rate = 48000; codecparam.num_channels = 2; codecparam.parameters["stereo"] = "1"; - codecparam.parameters["sprop-stereo"] = "0"; + codecparam.parameters["sprop-stereo"] = "1"; params.codecs.push_back(codecparam); receiver->SetParameters(params); } @@ -1011,7 +1011,7 @@ void LLWebRTCPeerConnectionImpl::OnAddTrack(rtc::scoped_refptrSetParameters(params); } @@ -1202,7 +1202,7 @@ void LLWebRTCPeerConnectionImpl::OnSuccess(webrtc::SessionDescriptionInterface * else if (sdp_line.find("a=fmtp:" + opus_payload) == 0) { sdp_mangled_stream << sdp_line << "a=fmtp:" << opus_payload - << " minptime=10;useinbandfec=1;stereo=1;sprop-stereo=0;maxplaybackrate=48000;sprop-maxplaybackrate=48000;sprop-maxcapturerate=48000\n"; + << " minptime=10;useinbandfec=1;stereo=1;sprop-stereo=1;maxplaybackrate=48000;sprop-maxplaybackrate=48000;sprop-maxcapturerate=48000\n"; } else { -- cgit v1.2.3 From 226f7bc5b78bbaf13485f2e94b4e185ccd1c5608 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Sun, 18 Aug 2024 23:07:29 -0700 Subject: Use the release build of webrtc to avoid pedantic asserts which are handled properly anyway. --- indra/llwebrtc/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra') diff --git a/indra/llwebrtc/CMakeLists.txt b/indra/llwebrtc/CMakeLists.txt index 30aaec1265..a18b716003 100644 --- a/indra/llwebrtc/CMakeLists.txt +++ b/indra/llwebrtc/CMakeLists.txt @@ -31,6 +31,7 @@ add_library (llwebrtc SHARED ${llwebrtc_SOURCE_FILES}) set_target_properties(llwebrtc PROPERTIES PUBLIC_HEADER llwebrtc.h) if (WINDOWS) + cmake_policy(SET CMP0091 NEW) set_target_properties(llwebrtc PROPERTIES LINK_FLAGS "/debug /LARGEADDRESSAWARE" @@ -42,7 +43,10 @@ if (WINDOWS) wmcodecdspuuid msdmo strmiids - iphlpapi) + iphlpapi + libcmt) + # as the webrtc libraries are release, build this binary as release as well. + target_compile_options(llwebrtc PRIVATE "/MT") if (USE_BUGSPLAT) set_target_properties(llwebrtc PROPERTIES PDB_OUTPUT_DIRECTORY "${SYMBOLS_STAGING_DIR}") endif (USE_BUGSPLAT) -- cgit v1.2.3