From: Paul Gofman pgofman@codeweavers.com
--- dlls/mmdevapi/spatialaudio.c | 67 ++++++++++++++++++++---------- dlls/mmdevapi/tests/spatialaudio.c | 21 ++++++++++ 2 files changed, 66 insertions(+), 22 deletions(-)
diff --git a/dlls/mmdevapi/spatialaudio.c b/dlls/mmdevapi/spatialaudio.c index 23f3de31428..bc1b085f3cd 100644 --- a/dlls/mmdevapi/spatialaudio.c +++ b/dlls/mmdevapi/spatialaudio.c @@ -49,6 +49,36 @@ static UINT32 AudioObjectType_to_index(AudioObjectType type) return o - 2; }
+static const char *debugstr_fmtex(const WAVEFORMATEX *fmt) +{ + static char buf[2048]; + + if (!fmt) + { + strcpy(buf, "(null)"); + } + else if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE) + { + const WAVEFORMATEXTENSIBLE *fmtex = (const WAVEFORMATEXTENSIBLE *)fmt; + snprintf(buf, sizeof(buf), "tag: 0x%x (%s), ch: %u (mask: 0x%lx), rate: %lu, depth: %u", + fmt->wFormatTag, debugstr_guid(&fmtex->SubFormat), + fmt->nChannels, fmtex->dwChannelMask, fmt->nSamplesPerSec, + fmt->wBitsPerSample); + } + else + { + snprintf(buf, sizeof(buf), "tag: 0x%x, ch: %u, rate: %lu, depth: %u", + fmt->wFormatTag, fmt->nChannels, fmt->nSamplesPerSec, + fmt->wBitsPerSample); + } + return buf; +} + +static BOOL formats_equal(const WAVEFORMATEX *fmt1, const WAVEFORMATEX *fmt2) +{ + return !memcmp(fmt1, fmt2, sizeof(*fmt1) + fmt1->cbSize); +} + typedef struct SpatialAudioImpl SpatialAudioImpl; typedef struct SpatialAudioStreamImpl SpatialAudioStreamImpl; typedef struct SpatialAudioObjectImpl SpatialAudioObjectImpl; @@ -610,9 +640,20 @@ static HRESULT WINAPI SAC_GetMaxFrameCount(ISpatialAudioClient *iface, static HRESULT WINAPI SAC_IsAudioObjectFormatSupported(ISpatialAudioClient *iface, const WAVEFORMATEX *format) { - SpatialAudioImpl *This = impl_from_ISpatialAudioClient(iface); - FIXME("(%p)->(%p)\n", This, format); - return E_NOTIMPL; + SpatialAudioImpl *sac = impl_from_ISpatialAudioClient(iface); + + TRACE("sac %p, format %s.\n", sac, debugstr_fmtex(format)); + + if (!format) + return E_POINTER; + + if (!formats_equal(&sac->object_fmtex.Format, format)) + { + FIXME("Reporting format %s as unsupported.\n", debugstr_fmtex(format)); + return E_INVALIDARG; + } + + return S_OK; }
static HRESULT WINAPI SAC_IsSpatialAudioStreamAvailable(ISpatialAudioClient *iface, @@ -630,23 +671,6 @@ static WAVEFORMATEX *clone_fmtex(const WAVEFORMATEX *src) return r; }
-static const char *debugstr_fmtex(const WAVEFORMATEX *fmt) -{ - static char buf[2048]; - if(fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE){ - const WAVEFORMATEXTENSIBLE *fmtex = (const WAVEFORMATEXTENSIBLE *)fmt; - snprintf(buf, sizeof(buf), "tag: 0x%x (%s), ch: %u (mask: 0x%lx), rate: %lu, depth: %u", - fmt->wFormatTag, debugstr_guid(&fmtex->SubFormat), - fmt->nChannels, fmtex->dwChannelMask, fmt->nSamplesPerSec, - fmt->wBitsPerSample); - }else{ - snprintf(buf, sizeof(buf), "tag: 0x%x, ch: %u, rate: %lu, depth: %u", - fmt->wFormatTag, fmt->nChannels, fmt->nSamplesPerSec, - fmt->wBitsPerSample); - } - return buf; -} - static void static_mask_to_channels(AudioObjectType static_mask, WORD *count, DWORD *mask, UINT32 *map) { UINT32 out_chan = 0, map_idx = 0; @@ -776,8 +800,7 @@ static HRESULT WINAPI SAC_ActivateSpatialAudioStream(ISpatialAudioClient *iface, return E_INVALIDARG; }
- if(!params->ObjectFormat || - memcmp(params->ObjectFormat, &This->object_fmtex.Format, sizeof(*params->ObjectFormat) + params->ObjectFormat->cbSize)){ + if(!(params->ObjectFormat && formats_equal(params->ObjectFormat, &This->object_fmtex.Format))) { *stream = NULL; return AUDCLNT_E_UNSUPPORTED_FORMAT; } diff --git a/dlls/mmdevapi/tests/spatialaudio.c b/dlls/mmdevapi/tests/spatialaudio.c index a382b57e7a2..4d8073d49ce 100644 --- a/dlls/mmdevapi/tests/spatialaudio.c +++ b/dlls/mmdevapi/tests/spatialaudio.c @@ -64,6 +64,27 @@ static void test_formats(void) ok(fmt->nAvgBytesPerSec == 192000, "Wrong avg bytes per sec, expected 192000 got %lu\n", fmt->nAvgBytesPerSec); ok(fmt->cbSize == 0, "Wrong cbSize for simple format, expected 0, got %hu\n", fmt->cbSize);
+ hr = ISpatialAudioClient_IsAudioObjectFormatSupported(sac, NULL); + ok(hr == E_POINTER, "Got %#lx.\n", hr); + + memcpy(&format, fmt, sizeof(format)); + hr = ISpatialAudioClient_IsAudioObjectFormatSupported(sac, &format); + ok(hr == S_OK, "Got %#lx.\n", hr); + + format.nBlockAlign *= 2; + hr = ISpatialAudioClient_IsAudioObjectFormatSupported(sac, &format); + todo_wine ok(hr == S_OK, "Got %#lx.\n", hr); + + memcpy(&format, fmt, sizeof(format)); + format.wBitsPerSample *= 2; + hr = ISpatialAudioClient_IsAudioObjectFormatSupported(sac, &format); + ok(hr == E_INVALIDARG, "Got %#lx.\n", hr); + + memcpy(&format, fmt, sizeof(format)); + format.nChannels = 2; + hr = ISpatialAudioClient_IsAudioObjectFormatSupported(sac, &format); + ok(hr == E_INVALIDARG, "Got %#lx.\n", hr); + memcpy(&format, fmt, sizeof(format));
IAudioFormatEnumerator_Release(afe);