1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-23 19:20:56 +00:00

Merge branch 'defaultdevice' into 'master'

Fix default audio device switch for PulseAudio backend (#7731)

Closes #7731

See merge request OpenMW/openmw!4505
This commit is contained in:
psi29a 2025-01-10 14:29:17 +00:00
commit 763e88817a

View File

@ -417,20 +417,16 @@ namespace MWSound
{ {
{ {
const std::lock_guard<std::mutex> openLock(mOutput.mReopenMutex); const std::lock_guard<std::mutex> openLock(mOutput.mReopenMutex);
auto defaultName = getDeviceName(nullptr); std::basic_string_view<ALCchar> defaultName = getDeviceName(nullptr);
if (mCurrentName != defaultName) if (mCurrentName != defaultName)
{
Log(Debug::Info) << "Default audio device changed";
ALCboolean reopened
= alcReopenDeviceSOFT(mOutput.mDevice, nullptr, mOutput.mContextAttributes.data());
if (reopened == AL_FALSE)
{ {
mCurrentName = defaultName; mCurrentName = defaultName;
Log(Debug::Info) << "Default audio device changed to \"" << mCurrentName << "\"";
ALCboolean reopened = alcReopenDeviceSOFT(
mOutput.mDevice, mCurrentName.data(), mOutput.mContextAttributes.data());
if (reopened == AL_FALSE)
Log(Debug::Warning) << "Failed to switch to new audio device"; Log(Debug::Warning) << "Failed to switch to new audio device";
} }
else
mCurrentName = getDeviceName(mOutput.mDevice);
}
} }
mCondVar.wait_for(lock, std::chrono::seconds(2)); mCondVar.wait_for(lock, std::chrono::seconds(2));
} }