From: Shaun Ren sren@codeweavers.com
--- dlls/sapi/stream.c | 27 ++++++++++++++++++++++++--- dlls/sapi/tests/stream.c | 22 ++++++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/dlls/sapi/stream.c b/dlls/sapi/stream.c index f0b4e2cd595..b0e5c2d5d0a 100644 --- a/dlls/sapi/stream.c +++ b/dlls/sapi/stream.c @@ -182,11 +182,32 @@ static HRESULT WINAPI spstream_Clone(ISpStream *iface, IStream **stream) return E_NOTIMPL; }
-static HRESULT WINAPI spstream_GetFormat(ISpStream *iface, GUID *format, WAVEFORMATEX **wave) +static HRESULT WINAPI spstream_GetFormat(ISpStream *iface, GUID *format, WAVEFORMATEX **wfx) { - FIXME("(%p, %p, %p): stub.\n", iface, format, wave); + struct spstream *This = impl_from_ISpStream(iface);
- return E_NOTIMPL; + TRACE("(%p, %p, %p).\n", iface, format, wfx); + + if (!format) + return E_POINTER; + + if (This->closed) + return SPERR_STREAM_CLOSED; + else if (!This->base_stream) + return SPERR_UNINITIALIZED; + + if (This->wfx) + { + if (!wfx) + return E_POINTER; + if (!(*wfx = CoTaskMemAlloc(sizeof(WAVEFORMATEX) + This->wfx->cbSize))) + return E_OUTOFMEMORY; + memcpy(*wfx, This->wfx, sizeof(WAVEFORMATEX) + This->wfx->cbSize); + } + + *format = This->format; + + return S_OK; }
static HRESULT WINAPI spstream_SetBaseStream(ISpStream *iface, IStream *stream, REFGUID format, diff --git a/dlls/sapi/tests/stream.c b/dlls/sapi/tests/stream.c index f7190db202b..5d28ab13d95 100644 --- a/dlls/sapi/tests/stream.c +++ b/dlls/sapi/tests/stream.c @@ -91,8 +91,8 @@ static void test_spstream(void) ISpStream *stream; ISpMMSysAudio *mmaudio; IStream *base_stream, *base_stream2; - GUID fmtid; - WAVEFORMATEX *wfx = NULL; + GUID fmtid, fmtid2; + WAVEFORMATEX *wfx = NULL, *wfx2 = NULL; HRESULT hr;
hr = CoCreateInstance(&CLSID_SpMMAudioOut, NULL, CLSCTX_INPROC_SERVER, @@ -131,6 +131,9 @@ static void test_spstream(void) &IID_ISpStream, (void **)&stream); ok(hr == S_OK, "Failed to create ISpStream interface: %#lx.\n", hr);
+ hr = ISpStream_GetFormat(stream, &fmtid2, &wfx2); + ok(hr == SPERR_UNINITIALIZED, "got %#lx.\n", hr); + hr = ISpStream_SetBaseStream(stream, base_stream, &SPDFID_WaveFormatEx, NULL); ok(hr == E_INVALIDARG, "got %#lx.\n", hr);
@@ -142,6 +145,18 @@ static void test_spstream(void) ok(base_stream2 == base_stream, "got %p.\n", base_stream2); IStream_Release(base_stream2);
+ hr = ISpStream_GetFormat(stream, NULL, NULL); + ok(hr == E_POINTER, "got %#lx.\n", hr); + + hr = ISpStream_GetFormat(stream, &fmtid2, NULL); + ok(hr == E_POINTER, "got %#lx.\n", hr); + + hr = ISpStream_GetFormat(stream, &fmtid2, &wfx2); + ok(hr == S_OK, "got %#lx.\n", hr); + ok(IsEqualGUID(&fmtid2, &SPDFID_WaveFormatEx), "got %s.\n", wine_dbgstr_guid(&fmtid2)); + ok(!memcmp(wfx, wfx2, sizeof(WAVEFORMATEX)), "wfx mismatch.\n"); + CoTaskMemFree(wfx2); + hr = ISpStream_Close(stream); ok(hr == S_OK, "got %#lx.\n", hr);
@@ -151,6 +166,9 @@ static void test_spstream(void) hr = ISpStream_GetBaseStream(stream, &base_stream2); ok(hr == SPERR_STREAM_CLOSED, "got %#lx.\n", hr);
+ hr = ISpStream_GetFormat(stream, &fmtid2, &wfx2); + ok(hr == SPERR_STREAM_CLOSED, "got %#lx.\n", hr); + hr = ISpStream_Close(stream); ok(hr == SPERR_STREAM_CLOSED, "got %#lx.\n", hr);