Skip to content

Commit

Permalink
Try to handle an unsupported with WASAPI exclusive mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Dec 24, 2024
1 parent 11803da commit cc92fc5
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions alc/backends/wasapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1992,8 +1992,32 @@ HRESULT WasapiPlayback::resetProxy()
hr = audio.mClient->IsFormatSupported(sharemode, &OutputType.Format, al::out_ptr(wfx));
if(FAILED(hr))
{
WARN("Failed to check format support: {:#x}", as_unsigned(hr));
hr = audio.mClient->GetMixFormat(al::out_ptr(wfx));
if(sharemode == AUDCLNT_SHAREMODE_EXCLUSIVE)
{
/* For exclusive mode, IAudioClient::IsFormatSupported won't give
* back a supported format. However, a common failure is an
* unsupported sample type, so try a fallback to 16-bit int.
*/
if(hr == AUDCLNT_E_UNSUPPORTED_FORMAT && mDevice->FmtType != DevFmtShort)
{
OutputType.Format.wBitsPerSample = 16;
OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
/* NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) */
OutputType.Samples.wValidBitsPerSample = OutputType.Format.wBitsPerSample;
OutputType.Format.nBlockAlign = static_cast<WORD>(OutputType.Format.nChannels
* OutputType.Format.wBitsPerSample / 8);
OutputType.Format.nAvgBytesPerSec = OutputType.Format.nSamplesPerSec
* OutputType.Format.nBlockAlign;

hr = audio.mClient->IsFormatSupported(sharemode, &OutputType.Format,
al::out_ptr(wfx));
}
}
else
{
WARN("Failed to check format support: {:#x}", as_unsigned(hr));
hr = audio.mClient->GetMixFormat(al::out_ptr(wfx));
}
}
if(FAILED(hr))
{
Expand Down

0 comments on commit cc92fc5

Please sign in to comment.