summaryrefslogtreecommitdiff
path: root/indra/newview/llvoicewebrtc.cpp
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2025-09-29 16:29:19 +0800
committerErik Kundiman <erik@megapahit.org>2025-10-01 16:56:56 +0800
commita954d290674db08ecaf3c1e6484a0cb6647b88b5 (patch)
tree3b672bac3e7d6807cd485ad5f041f69a5c729f46 /indra/newview/llvoicewebrtc.cpp
parente6eaa7e29990431b5207dbb4f8ae5560cf884acb (diff)
parenta6d4c1d394eef2cea41f6c6bcd751fec746ec17d (diff)
Merge tag 'Second_Life_Release#a6d4c1d3-2025.07' into 2025.07
Diffstat (limited to 'indra/newview/llvoicewebrtc.cpp')
-rw-r--r--indra/newview/llvoicewebrtc.cpp143
1 files changed, 102 insertions, 41 deletions
diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp
index 30f899877a..f13d4caa19 100644
--- a/indra/newview/llvoicewebrtc.cpp
+++ b/indra/newview/llvoicewebrtc.cpp
@@ -82,9 +82,15 @@ const std::string WEBRTC_VOICE_SERVER_TYPE = "webrtc";
namespace {
- const F32 MAX_AUDIO_DIST = 50.0f;
- const F32 VOLUME_SCALE_WEBRTC = 0.01f;
- const F32 LEVEL_SCALE_WEBRTC = 0.008f;
+ const F32 MAX_AUDIO_DIST = 50.0f;
+ const F32 VOLUME_SCALE_WEBRTC = 0.01f;
+ const F32 TUNING_LEVEL_SCALE = 0.01f;
+ const F32 TUNING_LEVEL_START_POINT = 0.8f;
+ const F32 LEVEL_SCALE = 0.005f;
+ const F32 LEVEL_START_POINT = 0.18f;
+ const uint32_t SET_HIDDEN_RESTORE_DELAY_MS = 200; // 200 ms to unmute again after hiding during teleport
+ const uint32_t MUTE_FADE_DELAY_MS = 500; // 20ms fade followed by 480ms silence gets rid of the click just after unmuting.
+ // This is because the buffers and processing is cleared by the silence.
const F32 SPEAKING_AUDIO_LEVEL = 0.30;
@@ -201,7 +207,6 @@ bool LLWebRTCVoiceClient::sShuttingDown = false;
LLWebRTCVoiceClient::LLWebRTCVoiceClient() :
mHidden(false),
- mTuningMode(false),
mTuningMicGain(0.0),
mTuningSpeakerVolume(50), // Set to 50 so the user can hear themselves when he sets his mic volume
mDevicesListUpdated(false),
@@ -348,25 +353,45 @@ void LLWebRTCVoiceClient::updateSettings()
static LLCachedControl<std::string> sOutputDevice(gSavedSettings, "VoiceOutputAudioDevice");
setRenderDevice(sOutputDevice);
- LL_INFOS("Voice") << "Input device: " << std::quoted(sInputDevice()) << ", output device: " << std::quoted(sOutputDevice()) << LL_ENDL;
+ LL_INFOS("Voice") << "Input device: " << std::quoted(sInputDevice()) << ", output device: " << std::quoted(sOutputDevice())
+ << LL_ENDL;
static LLCachedControl<F32> sMicLevel(gSavedSettings, "AudioLevelMic");
setMicGain(sMicLevel);
llwebrtc::LLWebRTCDeviceInterface::AudioConfig config;
+ bool audioConfigChanged = false;
+
static LLCachedControl<bool> sEchoCancellation(gSavedSettings, "VoiceEchoCancellation", true);
- config.mEchoCancellation = sEchoCancellation;
+ if (sEchoCancellation != config.mEchoCancellation)
+ {
+ config.mEchoCancellation = sEchoCancellation;
+ audioConfigChanged = true;
+ }
static LLCachedControl<bool> sAGC(gSavedSettings, "VoiceAutomaticGainControl", true);
- config.mAGC = sAGC;
+ if (sAGC != config.mAGC)
+ {
+ config.mAGC = sAGC;
+ audioConfigChanged = true;
+ }
- static LLCachedControl<U32> sNoiseSuppressionLevel(gSavedSettings,
+ static LLCachedControl<U32> sNoiseSuppressionLevel(
+ gSavedSettings,
"VoiceNoiseSuppressionLevel",
llwebrtc::LLWebRTCDeviceInterface::AudioConfig::ENoiseSuppressionLevel::NOISE_SUPPRESSION_LEVEL_VERY_HIGH);
- config.mNoiseSuppressionLevel = (llwebrtc::LLWebRTCDeviceInterface::AudioConfig::ENoiseSuppressionLevel)(U32)sNoiseSuppressionLevel;
-
- mWebRTCDeviceInterface->setAudioConfig(config);
+ auto noiseSuppressionLevel =
+ (llwebrtc::LLWebRTCDeviceInterface::AudioConfig::ENoiseSuppressionLevel)(U32)sNoiseSuppressionLevel;
+ if (noiseSuppressionLevel != config.mNoiseSuppressionLevel)
+ {
+ config.mNoiseSuppressionLevel = noiseSuppressionLevel;
+ audioConfigChanged = true;
+ }
+ if (audioConfigChanged)
+ {
+ mWebRTCDeviceInterface->setAudioConfig(config);
+ }
}
}
@@ -695,21 +720,38 @@ void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDevi
std::string outputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
LL_DEBUGS("Voice") << "Setting devices to-input: '" << inputDevice << "' output: '" << outputDevice << "'" << LL_ENDL;
- clearRenderDevices();
- for (auto &device : render_devices)
+
+ // only set the render device if the device list has changed.
+ if (mRenderDevices.size() != render_devices.size() || !std::equal(mRenderDevices.begin(),
+ mRenderDevices.end(),
+ render_devices.begin(),
+ [](const LLVoiceDevice& a, const llwebrtc::LLWebRTCVoiceDevice& b) {
+ return a.display_name == b.mDisplayName && a.full_name == b.mID; }))
{
- addRenderDevice(LLVoiceDevice(device.mDisplayName, device.mID));
+ clearRenderDevices();
+ for (auto& device : render_devices)
+ {
+ addRenderDevice(LLVoiceDevice(device.mDisplayName, device.mID));
+ }
+ setRenderDevice(outputDevice);
}
- setRenderDevice(outputDevice);
- clearCaptureDevices();
- for (auto &device : capture_devices)
+ // only set the capture device if the device list has changed.
+ if (mCaptureDevices.size() != capture_devices.size() ||!std::equal(mCaptureDevices.begin(),
+ mCaptureDevices.end(),
+ capture_devices.begin(),
+ [](const LLVoiceDevice& a, const llwebrtc::LLWebRTCVoiceDevice& b)
+ { return a.display_name == b.mDisplayName && a.full_name == b.mID; }))
{
- LL_DEBUGS("Voice") << "Checking capture device:'" << device.mID << "'" << LL_ENDL;
+ clearCaptureDevices();
+ for (auto& device : capture_devices)
+ {
+ LL_DEBUGS("Voice") << "Checking capture device:'" << device.mID << "'" << LL_ENDL;
- addCaptureDevice(LLVoiceDevice(device.mDisplayName, device.mID));
+ addCaptureDevice(LLVoiceDevice(device.mDisplayName, device.mID));
+ }
+ setCaptureDevice(inputDevice);
}
- setCaptureDevice(inputDevice);
setDevicesListUpdated(true);
}
@@ -762,7 +804,14 @@ bool LLWebRTCVoiceClient::inTuningMode()
void LLWebRTCVoiceClient::tuningSetMicVolume(float volume)
{
- mTuningMicGain = volume;
+ if (volume != mTuningMicGain)
+ {
+ mTuningMicGain = volume;
+ if (mWebRTCDeviceInterface)
+ {
+ mWebRTCDeviceInterface->setTuningMicGain(volume);
+ }
+ }
}
void LLWebRTCVoiceClient::tuningSetSpeakerVolume(float volume)
@@ -774,21 +823,10 @@ void LLWebRTCVoiceClient::tuningSetSpeakerVolume(float volume)
}
}
-float LLWebRTCVoiceClient::getAudioLevel()
-{
- if (mIsInTuningMode)
- {
- return (1.0f - mWebRTCDeviceInterface->getTuningAudioLevel() * LEVEL_SCALE_WEBRTC) * mTuningMicGain / 2.1f;
- }
- else
- {
- return (1.0f - mWebRTCDeviceInterface->getPeerConnectionAudioLevel() * LEVEL_SCALE_WEBRTC) * mMicGain / 2.1f;
- }
-}
-
float LLWebRTCVoiceClient::tuningGetEnergy(void)
{
- return getAudioLevel();
+ float rms = mWebRTCDeviceInterface->getTuningAudioLevel();
+ return TUNING_LEVEL_START_POINT - TUNING_LEVEL_SCALE * rms;
}
bool LLWebRTCVoiceClient::deviceSettingsAvailable()
@@ -824,6 +862,11 @@ void LLWebRTCVoiceClient::setHidden(bool hidden)
if (inSpatialChannel())
{
+ if (mWebRTCDeviceInterface)
+ {
+ mWebRTCDeviceInterface->setMute(mHidden || mMuteMic,
+ mHidden ? 0 : SET_HIDDEN_RESTORE_DELAY_MS); // delay 200ms so as to not pile up mutes/unmutes.
+ }
if (mHidden)
{
// get out of the channel entirely
@@ -990,7 +1033,6 @@ void LLWebRTCVoiceClient::updatePosition(void)
{
if (participant->mRegion != region->getRegionID()) {
participant->mRegion = region->getRegionID();
- setMuteMic(mMuteMic);
}
}
}
@@ -1115,13 +1157,14 @@ void LLWebRTCVoiceClient::sendPositionUpdate(bool force)
// Update our own volume on our participant, so it'll show up
// in the UI. This is done on all sessions, so switching
// sessions retains consistent volume levels.
-void LLWebRTCVoiceClient::updateOwnVolume() {
- F32 audio_level = 0.0;
- if (!mMuteMic && !mTuningMode)
+void LLWebRTCVoiceClient::updateOwnVolume()
+{
+ F32 audio_level = 0.0f;
+ if (!mMuteMic)
{
- audio_level = getAudioLevel();
+ float rms = mWebRTCDeviceInterface->getPeerConnectionAudioLevel();
+ audio_level = LEVEL_START_POINT - LEVEL_SCALE * rms;
}
-
sessionState::for_each(boost::bind(predUpdateOwnVolume, _1, audio_level));
}
@@ -1518,6 +1561,17 @@ void LLWebRTCVoiceClient::setMuteMic(bool muted)
}
mMuteMic = muted;
+
+ if (mIsInTuningMode)
+ {
+ return;
+ }
+
+ if (mWebRTCDeviceInterface)
+ {
+ mWebRTCDeviceInterface->setMute(muted, muted ? MUTE_FADE_DELAY_MS : 0); // delay for 40ms on mute to allow buffers to empty
+ }
+
// when you're hidden, your mic is always muted.
if (!mHidden)
{
@@ -1556,7 +1610,10 @@ void LLWebRTCVoiceClient::setMicGain(F32 gain)
if (gain != mMicGain)
{
mMicGain = gain;
- mWebRTCDeviceInterface->setPeerConnectionGain(gain);
+ if (mWebRTCDeviceInterface)
+ {
+ mWebRTCDeviceInterface->setMicGain(gain);
+ }
}
}
@@ -2900,9 +2957,13 @@ bool LLVoiceWebRTCConnection::connectionStateMachine()
}
// else was already posted by llwebrtc::terminate().
break;
+ }
+
case VOICE_STATE_WAIT_FOR_CLOSE:
break;
+
case VOICE_STATE_CLOSED:
+ {
if (!mShutDown)
{
mVoiceConnectionState = VOICE_STATE_START_SESSION;