Commit Graph

96 Commits (574dc5b65ac72da28e2ef931598073a11e164f05)

Author SHA1 Message Date
minerjr 9ee2595ac1 Reduced the time_mutx lock to 1 second from 3 seconds
Originally setup with 3 second as a was not sure how long it would take to recover, but 1 second should be good to recover and enumerate devices.
2025-10-29 21:39:57 -03:00
minerjr b37a210e38 Fixed up the i prefix to g to follow coding standards
Changed iWebRTCUpdateDevices and iAudioDeviceMutex to gWebRTCUpdateDevicesand gAudioDeviceMutex to follow Firestorm coding standards.

They are global static variables.
2025-10-29 15:37:55 -03:00
minerjr f6ce46c726 Fixed up not python operator to proper C++ operator
Fixed up the follow Firestorm coding standards.
2025-10-29 15:21:51 -03:00
minerjr 6ad9a57c39 FIRE-36022 - Removing my USB headset crashes entire viewer - audio device mutex
As with the previous change, this is to address the issue FIRE-36022 where users who remove their USB headsets with microphones are having the viewer lock up.

This introduces a new inline mutex called iAudioDeviceMutex. This is stored in a shared header file located on llcommon. iAudioDeviceMutex is a timed_mutex which allows for a time limit to be placed on a wait for a lock. Once the time runs out or the lock is achiveved the code moves on. With a check after the lock, if the owner is the current thread, then the lock was successful, otherwise it's still being used by another thread and the function should exit to try again later on.

This logic is wrapping WebRTC, FMOD and Vinvox calls to the audio hardware by the Viewer. OpenAL does not currently support changing of audio hardware and always defaults to the default audio hardware.

Added exceptions handling for the new unique_lock with the timed_mutex as they can throw 2 exceptions if the thread is already locked by the current thread and if the mutex is invalid.

Further testing may reveal other areas which would need the timed_mutex added to protect from threads locking up.
2025-10-28 23:22:13 -03:00
minerjr 0cdae450d8 FIRE-36022- Removing my USB headset crashes entire viewer - WebRTC fix
This is created to address the issue of USB headsets being removed or Bluetooth headsets with bad connections causing the viewer to lock up.

First Part: WebRTC

WebRTC now has an added inline atomic bool used to track when the worker thread is accessing the audio hardware. If the coroutine that is always running detects 10 consecutive true flag values, it will set WebRTC to exit and exit itself.

This coroutine was what was locking up the viewer as it spammed the mMainQueue with messages every update, but the worker thread was locked up and unable to receive the messages. Once the queue reached 1024 messages, it would lock up.

Underlying issue is the Windows Core Audio driver system crashes if too many threads have requests to get audio updates upon hardware changes. And with a USB headset having 2 devices in 1, it multiples the updates by 2x. The WebRTC audio system itself locks a mutex as it calls the core audio system to get set the input, but if it is already being processed by another thread, it then gets an exception to try again. The audio driver is not handling the message and crashes and does not return leaving the WebRTC worker thread locked.
2025-10-28 23:05:53 -03:00
Ansariel 3410a182c5 initWebRTC() can get multiple times - make sure to unset previous observers before re-adding 2025-10-18 13:32:44 +02:00
Ansariel d733bef269 Restore original indentation 2025-10-18 12:42:20 +02:00
Ansariel 9fe6e65aed Continue keeping built-in audio effects disabled - only disable duplicate call to updateDevices() which is already called via
LLWebRTCVoiceClient::initWebRTC() -> LLWebRTCVoiceClient::refreshDeviceLists() -> LLWebRTCImpl::refreshDevices()

and duplicate to

LLWebRTCVoiceClient::initWebRTC() -> llwebrtc::init() -> LLWebRTCImpl::init()
2025-10-18 12:26:47 +02:00
minerjr 4a6975a944 FIRE-36022 - Removing my USB headset crashes entire viewer
Commented out a block of new code recently added which was also being called by one of the callback functions.
This had the side effect of having 2 LLWebRTCDevicesObserver listening to the hardware removal events and cause both to trigger events at the same time, which may be the source of the queue being locked up in a race condition.

Was able to reproduce issue 2x without code change by moving mouse around a lot while on  rezing and then pulling USB headset out of the USB port. Direct motherboard USB port seemed to work the best as could not trigger while headset was in USB hub.
2025-10-17 22:01:17 -03:00
Andrey Kleshchev dc54661b3a #4819 WebRTC crashes after a failed login 2025-10-14 10:04:56 +02:00
Andrey Kleshchev 0dcade5e1d #4695 Fix missing voice cleanup
Cleanup is in LLVoiceClient::terminate()
gWebRTCImpl was never deleted
Added mDeviceModule security
2025-10-12 16:34:56 +10:00
Roxanne Skelly 81c01ab5bc Fix indexing problem with mac devices (#4676)
* Fix indexing problem with mac devices

This resulted in the wrong device being selected.

Also, fix a shutdown crash where recording was not being stopped, hence the recording
thread was still running on shutdown and crashed because it lost access to resources.

Fix an issue with p2p calls where they're coming up muted even though the button indicates
they are unmuted.

* Always refresh device list on notification of device changes

Even when the selected device doesn't change, we need to
re-deploy it as it might have had characteristics (sampling rate, etc.) changed.

Also, we need to redeploy when the Default device has changed
2025-10-12 16:34:22 +10:00
Roxanne Skelly d070b996bd [WebRTC] Rework device handling sequence so that we can handle unplugging/re-plugging devices (#4593)
* [WebRTC] Rework device handling sequence so that we can handle unplugging/re-plugging devices

The device handling was not processing device updates in the proper sequence as
things like AEC use both input and output devices.  Devices like headsets are both
so unplugging them resulted in various mute conditions and sometimes even a crash.

Now, we update both capture and render devices at once in the proper sequence.

Test Guidance:
* Bring two users in the same place in webrtc regions.
* The 'listening' one should have a headset or something set oas 'Default'
* Press 'talk' on one, and verify the other can hear.
* Unplug the headset from the listening one.
* Validate that audio changes from the headset to the speakers.
* Plug the headset back in.
* Validate that audio changes from speakers to headset.
* Do the same type of test with the headset viewer talking.
* The microphone used should switch from the headset to the computer (it should have one)

Do other various device tests, such as setting devices explicitly, messing with the device selector, etc.

* Fix race condition when multiple change device requests might come in at once

* Update to m137

The primary feature of this commit is to update libwebrtc from m114
to m137.  This is needed to make webrtc buildable, as m114 is not buildable
by the current toolset.

m137 had some changes to the API, which required renaming or changing namespace
of some of the calls.

Additionally, this PR moves from a callback mechanism for gathering the energy
levels for tuning to a wrapper AudioDeviceModule, which gives us more control
over the audio stream.

Finally, the new m137-based webrtc has been updated to allow for 192khz audio
streams.

* Properly pass the observer setting into the inner audio device module

* Update to m137 and get rid of some noise

    This change updates to m137 from m114, which required a few API changes.

    Additionally, this fixes the hiss that happens shortly after someone unmutes: https://github.com/secondlife/server/issues/2094

    There was also an issue with a slight amount of repeated after unmuting if there was audio right before unmuting.  This is because
    the audio processing and buffering still had audio from the previous speaking session.  Now, we inject nearly a half second of
    silence into the audio buffers/processor after unmuting to flush things.

* Install nsis on windows

* Use the newer digital AGC pipeline

m137 improved the AGC pipeline and the existing analog style is going away
so move to the new digital pipeline.

Also, some tweaking for audio levels so that we don't see inworld bars when tuning,
so one's own bars seem a reasonable size, etc.

* Install NSIS during windows sisgning and package build step

* Try pinning the packaging to windows 2022 to deal with missing nsis

* Adjust gain calculation and audio level calculations for tuning and peer connections

* Update with mac universal webrtc build

* Tuning of voice indicators for both tuning mode and inworld for self.

* Redo device deployment to handle cases where multiple deploy requests pile up

Also, mute when leaving webrtc-enabled regions or parcels,
and unmute when voice comes back.

* pre commit issue
2025-10-12 16:32:18 +10:00
Ansariel 478a51f8e3 Merge branch 'release/2025.06' of https://github.com/secondlife/viewer
# Conflicts:
#	indra/llxml/llcontrol.cpp
#	indra/newview/llfloaterpreference.cpp
#	indra/newview/lllogchat.cpp
#	indra/newview/llreflectionmap.h
2025-08-13 20:52:47 +02:00
Roxie Linden bab2c12d04 Straighten out muting to prevent echo when crossing from vivox to webrtc regions.
Muting was a bit random in the code, so it's now been straightened out and should
prevent echo.

Also, code was added to not attempt connection to non-webrtc regions in the webrtc code.
2025-08-08 14:37:46 -07:00
Ansariel a4e8af0dce Merge branch 'develop' of https://github.com/secondlife/viewer
# Conflicts:
#	.github/pull_request_template.md
#	CONTRIBUTING.md
#	indra/newview/CMakeLists.txt
#	indra/newview/app_settings/settings.xml
#	indra/newview/llappviewer.cpp
#	indra/newview/llfloaterimagepreview.cpp
#	indra/newview/llfloatersettingsdebug.cpp
#	indra/newview/llfloatersettingsdebug.h
#	indra/newview/llstatusbar.cpp
#	indra/newview/llstatusbar.h
#	indra/newview/res/viewerRes.rc
#	indra/newview/skins/default/xui/de/panel_login_first.xml
#	indra/newview/skins/default/xui/en/notifications.xml
#	indra/newview/skins/default/xui/en/panel_login_first.xml
#	indra/newview/skins/default/xui/en/panel_preferences_advanced.xml
#	indra/newview/skins/default/xui/en/panel_preferences_privacy.xml
#	indra/newview/skins/default/xui/en/panel_status_bar.xml
#	indra/newview/skins/default/xui/es/panel_login_first.xml
#	indra/newview/skins/default/xui/fr/panel_login_first.xml
#	indra/newview/skins/default/xui/it/panel_login_first.xml
#	indra/newview/skins/default/xui/ja/panel_login_first.xml
#	indra/newview/skins/default/xui/pl/panel_login_first.xml
#	indra/newview/skins/default/xui/pt/panel_login_first.xml
#	indra/newview/skins/default/xui/ru/panel_login_first.xml
#	indra/newview/skins/default/xui/tr/panel_login_first.xml
#	indra/newview/skins/default/xui/zh/panel_login_first.xml
#	indra/newview/viewer_manifest.py
2025-07-30 10:52:39 +02:00
Andrey Kleshchev be04175579 #4358 Fix 'Microphone in use' task bar icon
1. set_enabled(false) failed to apply, force set it to trigger observers
and remove the icon
2. Don't set audio devices if voice was disabled
2025-07-16 20:05:23 +03:00
Ansariel 469795979f Merge branch 'release/2025.04' of https://github.com/secondlife/viewer
# Conflicts:
#	indra/newview/llinventorybridge.cpp
#	indra/newview/llmodelpreview.cpp
#	indra/newview/llpanelface.cpp
#	indra/newview/llviewercamera.cpp
#	indra/newview/llviewerregion.cpp
#	indra/newview/skins/default/colors.xml
2025-05-14 21:56:38 +02:00
Andrey Kleshchev edb0032c95 #3542 Microphone doesn't switch after plugging in an audio device 2025-05-10 10:11:53 +03:00
Beq 549dc802a8 Tentative fix for Linux WebRTC hang from Roxie. 2024-10-28 15:48:59 +00:00
Roxie Linden 28fdd6e786 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.
2024-08-18 00:30:16 -07:00
Roxie Linden 63d17b395b 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.
2024-08-17 20:11:46 -07:00
Roxie Linden 2efad2182a 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.
2024-08-17 00:26:07 -07:00
Roxie Linden b9c222dfae Implement a Logging Sink for WebRTC
WebRTC logs now pass out of the webrtc library into a logging sink,
which converts them into SecondLife.log compatable logging calls.

This includes fatal errors and asserts, which are now logged into
SecondLife.log, and should be available in the crash logger.
2024-07-31 21:23:30 -06:00
Andrey Lihatskiy b746e78c78 Fix trailing whitespaces in webrtc code to pass pre-commit 2024-07-29 12:28:33 +03:00
Roxie Linden 34a2fd525f [WebRTC] control microphone gain via custom audio processor.
Previously, there were two places audio gain could be controlled:
- the device manager
- the audio track

The device manager audio gain control sets the system gain for all applications,
not just the webrtc application.

The audio track gain happens well after the audio processing where we want it to happen.

So, gain control was added to the existing custom audio processor, which previously only
handled calculating and retrieving the audio levels.

After these changes, the microphone gain slider does impact the audio volume heard by peers.
2024-06-24 14:42:30 -07:00
Roxie Linden ddbd1ab47e More session shutdown cleanup 2024-05-19 02:30:45 -07:00
Roxie Linden 2b275d43fb Clean up some shutdown code. 2024-05-17 13:27:45 -07:00
Roxie Linden c6e147ff22 Race condition resulted in close causing removal of peer connection while other jobs might be using it. 2024-05-16 12:00:45 -07:00
Roxie Linden 07c3095a78 Unregister requested data channel when using the negotiated one.
When creating a new connection, the viewer builds a data channel interface.
It then gets a new one, which is a proxy.  The viewer uses the new one,
and therefore must unregister the callbacks from the old one.

Also, update the position data before sending it after the join is sent.
2024-05-02 11:07:36 -07:00
Roxie Linden cf13866da9 Don't default the tracks to unmuted 2024-04-28 18:43:48 -07:00
Roxie Linden d4fce4990a Reconnects to the voice server weren't happening. 2024-04-28 17:43:15 -07:00
Roxie Linden 98322d5f07 Reconnect when parcel voice params change.
When parcel voice permissions and region/parcel-only voice
settings change, a callback will be made to the viewer with
new voice credential information.  For webrtc, this means
either just the uuid of the voice channel, or nothing if
voice is disabled.

This change looks at that callback and the channel id,
and sets the appropriate flags on the parcel/region as needed
which will cause voice to be renegotiated.

Also, there was a race condition if the voice connect attempt
was made before caps were retrieved, which would have resulted
in full renegotiate attempts.  Now, just wait until the cap
comes in and continue.
2024-04-21 21:12:06 -07:00
Roxie Linden 648741470f CR suggestions 2024-04-07 19:23:00 -07:00
Roxie Linden 34ed990fa3 Show 'decline' when peer declines p2p voice
The simulator will send a chatterbox notification that
voice is no longer in use for a given channel, and
the viewer should take that as a case where the peer
does not want voice, hence it's a decline.
2024-04-07 14:13:00 -07:00
Roxie Linden fdf0fbce5b oopse 2024-04-01 22:39:59 -07:00
Roxie Linden c826aea079 Fix "default" audio device handling.
Windows and Mac/Linux behave slightly differently with respect
to Default devices, in that mac/linux (I think) simply assumes
the device at index 0 is the default one, and windows has a
separate API for enabling the default device.
2024-04-01 21:39:17 -07:00
Roxie Linden c6e673cda1 Fix windows crashes
* sampling rate was set to 8khz for audio processing, which was
  causing a 'bands' mismatch with the echo cancler.

* Some funnybusiness with lambdas and captures and such was causing
  a heap crash with respect to function parameters.
2024-03-30 23:19:38 -07:00
Roxie Linden 567180508f Merge branch 'roxie/webrtc-voice' of https://github.com/secondlife/viewer into roxie/webrtc-voice 2024-03-30 22:03:59 -07:00
Roxie Linden b3bb3d2d51 Renegotiate on remote description error 2024-03-30 22:03:30 -07:00
Roxie Linden cdae5ebc16 Add UI for managing echo cancellation, AGC, and noise control.
Plumb audio settings through from webrtc to the sound preferences
UI (still needs some tweaking, of course.)

Also, choose stun servers based on grid.  Ultimately, the stun
stun servers will be passed up via login or something.
2024-03-30 21:58:00 -07:00
Roxie Linden e242c129f9 Add Tracy categories for WebRTC Voice
Also:
* Fix a few crashes.
* Only send position data when it changes.
2024-03-22 16:21:02 -07:00
Roxie Linden 4b709e7944 Turn procesIceUpdates into a coroutine to chop up the work a bit. 2024-03-20 11:15:12 -07:00
Roxie Linden 0e2fc4d35e Clear out observers when terminating a connection 2024-03-19 17:05:56 -07:00
Roxie Linden 5bc92b8031 Simplify workqueue calls. Fix issue with webrtc blocking on destruction. 2024-03-19 15:23:43 -07:00
Roxie Linden e4dee511ca Use LL::WorkQueue to handle transitions from llwebrtc threads to the main thread 2024-03-18 17:47:56 -07:00
Roxie Linden dbbbbc55af Refactor device selection logic
This refactor fixed a few bugs.  There is an annoying 'click' when
changing devices, however.  This will be addressed in the future.
2024-03-14 20:04:39 -07:00
Roxie Linden fc462b2b0f Remove trailing spaces. Other code cleanup. 2024-03-10 00:11:43 -08:00
Roxie Linden 7714850fbe code beautification/comments 2024-03-09 23:00:00 -08:00
Roxie Linden 70044b9d2b The response from the provision account call was being called twice for some reason 2024-03-05 18:57:22 -08:00