Commit 8767422f authored by David Reid's avatar David Reid

WASAPI: Fix a typo and some formatting changes.

parent 1e0ccd62
...@@ -13832,9 +13832,6 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context ...@@ -13832,9 +13832,6 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context
{ {
HRESULT hr; HRESULT hr;
WAVEFORMATEX* pWF = NULL; WAVEFORMATEX* pWF = NULL;
#ifdef MA_WIN32_DESKTOP
ma_IPropertyStore *pProperties;
#endif
MA_ASSERT(pAudioClient != NULL); MA_ASSERT(pAudioClient != NULL);
MA_ASSERT(pInfo != NULL); MA_ASSERT(pInfo != NULL);
...@@ -13848,102 +13845,106 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context ...@@ -13848,102 +13845,106 @@ static ma_result ma_context_get_device_info_from_IAudioClient__wasapi(ma_context
} }
/* /*
Exlcusive Mode. We repeatedly call IsFormatSupported() here. This is not currently support on Exlcusive Mode. We repeatedly call IsFormatSupported() here. This is not currently supported on
UWP. Failure to retrieve the exclusive mode format is not considered an error, so from here UWP. Failure to retrieve the exclusive mode format is not considered an error, so from here on
on out, MA_SUCCESS is guaranteed to be returned. out, MA_SUCCESS is guaranteed to be returned.
*/ */
#ifdef MA_WIN32_DESKTOP #ifdef MA_WIN32_DESKTOP
/* {
The first thing to do is get the format from PKEY_AudioEngine_DeviceFormat. This should give us a channel count we assume is ma_IPropertyStore *pProperties;
correct which will simplify our searching.
*/
hr = ma_IMMDevice_OpenPropertyStore((ma_IMMDevice*)pMMDevice, STGM_READ, &pProperties);
if (SUCCEEDED(hr)) {
PROPVARIANT var;
ma_PropVariantInit(&var);
hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_AudioEngine_DeviceFormat, &var); /*
The first thing to do is get the format from PKEY_AudioEngine_DeviceFormat. This should give us a channel count we assume is
correct which will simplify our searching.
*/
hr = ma_IMMDevice_OpenPropertyStore((ma_IMMDevice*)pMMDevice, STGM_READ, &pProperties);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
pWF = (WAVEFORMATEX*)var.blob.pBlobData; PROPVARIANT var;
ma_PropVariantInit(&var);
/* hr = ma_IPropertyStore_GetValue(pProperties, &MA_PKEY_AudioEngine_DeviceFormat, &var);
In my testing, the format returned by PKEY_AudioEngine_DeviceFormat is suitable for exclusive mode so we check this format
first. If this fails, fall back to a search.
*/
hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, pWF, NULL);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
/* The format returned by PKEY_AudioEngine_DeviceFormat is supported. */ pWF = (WAVEFORMATEX*)var.blob.pBlobData;
ma_add_native_data_format_to_device_info_from_WAVEFORMATEX(pWF, ma_share_mode_exclusive, pInfo);
} else {
/* /*
The format returned by PKEY_AudioEngine_DeviceFormat is not supported, so fall back to a search. We assume the channel In my testing, the format returned by PKEY_AudioEngine_DeviceFormat is suitable for exclusive mode so we check this format
count returned by MA_PKEY_AudioEngine_DeviceFormat is valid and correct. For simplicity we're only returning one format. first. If this fails, fall back to a search.
*/ */
ma_uint32 channels = pInfo->minChannels; hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, pWF, NULL);
ma_channel defaultChannelMap[MA_MAX_CHANNELS]; if (SUCCEEDED(hr)) {
WAVEFORMATEXTENSIBLE wf; /* The format returned by PKEY_AudioEngine_DeviceFormat is supported. */
ma_bool32 found; ma_add_native_data_format_to_device_info_from_WAVEFORMATEX(pWF, ma_share_mode_exclusive, pInfo);
ma_uint32 iFormat; } else {
/*
/* Make sure we don't overflow the channel map. */ The format returned by PKEY_AudioEngine_DeviceFormat is not supported, so fall back to a search. We assume the channel
if (channels > MA_MAX_CHANNELS) { count returned by MA_PKEY_AudioEngine_DeviceFormat is valid and correct. For simplicity we're only returning one format.
channels = MA_MAX_CHANNELS; */
} ma_uint32 channels = pInfo->minChannels;
ma_channel defaultChannelMap[MA_MAX_CHANNELS];
ma_get_standard_channel_map(ma_standard_channel_map_microsoft, channels, defaultChannelMap); WAVEFORMATEXTENSIBLE wf;
ma_bool32 found;
MA_ZERO_OBJECT(&wf); ma_uint32 iFormat;
wf.Format.cbSize = sizeof(wf);
wf.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; /* Make sure we don't overflow the channel map. */
wf.Format.nChannels = (WORD)channels; if (channels > MA_MAX_CHANNELS) {
wf.dwChannelMask = ma_channel_map_to_channel_mask__win32(defaultChannelMap, channels); channels = MA_MAX_CHANNELS;
found = MA_FALSE;
for (iFormat = 0; iFormat < ma_countof(g_maFormatPriorities); ++iFormat) {
ma_format format = g_maFormatPriorities[iFormat];
ma_uint32 iSampleRate;
wf.Format.wBitsPerSample = (WORD)(ma_get_bytes_per_sample(format)*8);
wf.Format.nBlockAlign = (WORD)(wf.Format.nChannels * wf.Format.wBitsPerSample / 8);
wf.Format.nAvgBytesPerSec = wf.Format.nBlockAlign * wf.Format.nSamplesPerSec;
wf.Samples.wValidBitsPerSample = /*(format == ma_format_s24_32) ? 24 :*/ wf.Format.wBitsPerSample;
if (format == ma_format_f32) {
wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
} else {
wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_PCM;
} }
for (iSampleRate = 0; iSampleRate < ma_countof(g_maStandardSampleRatePriorities); ++iSampleRate) { ma_get_standard_channel_map(ma_standard_channel_map_microsoft, channels, defaultChannelMap);
wf.Format.nSamplesPerSec = g_maStandardSampleRatePriorities[iSampleRate];
MA_ZERO_OBJECT(&wf);
wf.Format.cbSize = sizeof(wf);
wf.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wf.Format.nChannels = (WORD)channels;
wf.dwChannelMask = ma_channel_map_to_channel_mask__win32(defaultChannelMap, channels);
found = MA_FALSE;
for (iFormat = 0; iFormat < ma_countof(g_maFormatPriorities); ++iFormat) {
ma_format format = g_maFormatPriorities[iFormat];
ma_uint32 iSampleRate;
wf.Format.wBitsPerSample = (WORD)(ma_get_bytes_per_sample(format)*8);
wf.Format.nBlockAlign = (WORD)(wf.Format.nChannels * wf.Format.wBitsPerSample / 8);
wf.Format.nAvgBytesPerSec = wf.Format.nBlockAlign * wf.Format.nSamplesPerSec;
wf.Samples.wValidBitsPerSample = /*(format == ma_format_s24_32) ? 24 :*/ wf.Format.wBitsPerSample;
if (format == ma_format_f32) {
wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
} else {
wf.SubFormat = MA_GUID_KSDATAFORMAT_SUBTYPE_PCM;
}
hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, (WAVEFORMATEX*)&wf, NULL); for (iSampleRate = 0; iSampleRate < ma_countof(g_maStandardSampleRatePriorities); ++iSampleRate) {
if (SUCCEEDED(hr)) { wf.Format.nSamplesPerSec = g_maStandardSampleRatePriorities[iSampleRate];
ma_add_native_data_format_to_device_info_from_WAVEFORMATEX((WAVEFORMATEX*)&wf, ma_share_mode_exclusive, pInfo);
found = MA_TRUE; hr = ma_IAudioClient_IsFormatSupported((ma_IAudioClient*)pAudioClient, MA_AUDCLNT_SHAREMODE_EXCLUSIVE, (WAVEFORMATEX*)&wf, NULL);
break; if (SUCCEEDED(hr)) {
ma_add_native_data_format_to_device_info_from_WAVEFORMATEX((WAVEFORMATEX*)&wf, ma_share_mode_exclusive, pInfo);
found = MA_TRUE;
break;
}
} }
}
if (found) { if (found) {
break; break;
}
} }
}
ma_PropVariantClear(pContext, &var); ma_PropVariantClear(pContext, &var);
if (!found) { if (!found) {
ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "[WASAPI] Failed to find suitable device format for device info retrieval.", MA_FORMAT_NOT_SUPPORTED); ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "[WASAPI] Failed to find suitable device format for device info retrieval.", MA_FORMAT_NOT_SUPPORTED);
}
} }
} else {
ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "[WASAPI] Failed to retrieve device format for device info retrieval.", ma_result_from_HRESULT(hr));
} }
ma_IPropertyStore_Release(pProperties);
} else { } else {
ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "[WASAPI] Failed to retrieve device format for device info retrieval.", ma_result_from_HRESULT(hr)); ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "[WASAPI] Failed to open property store for device info retrieval.", ma_result_from_HRESULT(hr));
} }
ma_IPropertyStore_Release(pProperties);
} else {
ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "[WASAPI] Failed to open property store for device info retrieval.", ma_result_from_HRESULT(hr));
} }
#endif #endif
return MA_SUCCESS; return MA_SUCCESS;
} }
...@@ -64151,7 +64152,12 @@ REVISION HISTORY ...@@ -64151,7 +64152,12 @@ REVISION HISTORY
================ ================
v0.10.32 - TBD v0.10.32 - TBD
- WASAPI: Fix a deadlock in exclusive mode. - WASAPI: Fix a deadlock in exclusive mode.
- WASAPI: No longer return an error from ma_context_get_device_info() when an exclusive mode format
cannot be retrieved.
- PulseAudio: Yet another refactor, this time to remove the dependency on `pa_threaded_mainloop`. - PulseAudio: Yet another refactor, this time to remove the dependency on `pa_threaded_mainloop`.
- Fix a bug where thread handles are not being freed.
- Fix some static analysis warnings in FLAC, WAV and MP3 decoders.
- Update to latest version of c89atomic.
- Internal refactoring to migrate over to the new backend callback system for the following backends: - Internal refactoring to migrate over to the new backend callback system for the following backends:
- PulseAudio - PulseAudio
- ALSA - ALSA
...@@ -64161,9 +64167,6 @@ v0.10.32 - TBD ...@@ -64161,9 +64167,6 @@ v0.10.32 - TBD
- OSS - OSS
- audio(4) - audio(4)
- sndio - sndio
- Fix a bug where thread handles are not being freed.
- Fix some static analysis warnings in FLAC, WAV and MP3 decoders.
- Update to latest version of c89atomic.
v0.10.31 - 2021-01-17 v0.10.31 - 2021-01-17
- Make some functions const correct. - Make some functions const correct.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment