Commit 454283ec authored by Shaun Ren's avatar Shaun Ren Committed by Alexandre Julliard

sapi: Implement ISpMMSysAudio::Get/SetDeviceId.

parent 682ad1c1
MODULE = sapi.dll
IMPORTS = uuid ole32 user32 advapi32
DELAYIMPORTS = winmm
C_SRCS = \
automation.c \
......
......@@ -47,6 +47,8 @@ struct mmaudio
enum flow_type flow;
ISpObjectToken *token;
UINT device_id;
CRITICAL_SECTION cs;
};
static inline struct mmaudio *impl_from_ISpEventSource(ISpEventSource *iface)
......@@ -356,6 +358,7 @@ static ULONG WINAPI mmsysaudio_Release(ISpMMSysAudio *iface)
if (!ref)
{
if (This->token) ISpObjectToken_Release(This->token);
DeleteCriticalSection(&This->cs);
heap_free(This);
}
......@@ -531,16 +534,33 @@ static HRESULT WINAPI mmsysaudio_SetBufferNotifySize(ISpMMSysAudio *iface, ULONG
static HRESULT WINAPI mmsysaudio_GetDeviceId(ISpMMSysAudio *iface, UINT *id)
{
FIXME("(%p, %p): stub.\n", iface, id);
struct mmaudio *This = impl_from_ISpMMSysAudio(iface);
return E_NOTIMPL;
TRACE("(%p, %p).\n", iface, id);
if (!id) return E_POINTER;
EnterCriticalSection(&This->cs);
*id = This->device_id;
LeaveCriticalSection(&This->cs);
return S_OK;
}
static HRESULT WINAPI mmsysaudio_SetDeviceId(ISpMMSysAudio *iface, UINT id)
{
FIXME("(%p, %u): stub.\n", iface, id);
struct mmaudio *This = impl_from_ISpMMSysAudio(iface);
return E_NOTIMPL;
TRACE("(%p, %u).\n", iface, id);
if (id != WAVE_MAPPER && id >= waveOutGetNumDevs())
return E_INVALIDARG;
EnterCriticalSection(&This->cs);
This->device_id = id;
LeaveCriticalSection(&This->cs);
return S_OK;
}
static HRESULT WINAPI mmsysaudio_GetMMHandle(ISpMMSysAudio *iface, void **handle)
......@@ -620,9 +640,11 @@ static HRESULT mmaudio_create(IUnknown *outer, REFIID iid, void **obj, enum flow
This->flow = flow;
This->token = NULL;
This->device_id = WAVE_MAPPER;
hr = ISpMMSysAudio_QueryInterface(&This->ISpMMSysAudio_iface, iid, obj);
InitializeCriticalSection(&This->cs);
hr = ISpMMSysAudio_QueryInterface(&This->ISpMMSysAudio_iface, iid, obj);
ISpMMSysAudio_Release(&This->ISpMMSysAudio_iface);
return hr;
}
......
TESTDLL = sapi.dll
IMPORTS = ole32 user32 advapi32
IMPORTS = ole32 user32 advapi32 winmm
C_SRCS = \
automation.c \
......
......@@ -60,9 +60,49 @@ static void test_interfaces(void)
ISpObjectWithToken_Release(obj_with_token);
}
static void test_device_id(void)
{
ISpMMSysAudio *mmaudio;
UINT id, num_devs;
HRESULT hr;
hr = CoCreateInstance(&CLSID_SpMMAudioOut, NULL, CLSCTX_INPROC_SERVER,
&IID_ISpMMSysAudio, (void **)&mmaudio);
ok(hr == S_OK, "failed to create SpMMAudioOut instance: %#lx.\n", hr);
id = 0xdeadbeef;
hr = ISpMMSysAudio_GetDeviceId(mmaudio, &id);
ok(hr == S_OK, "got %#lx.\n", hr);
ok(id == WAVE_MAPPER, "got %#x.\n", id);
hr = ISpMMSysAudio_SetDeviceId(mmaudio, WAVE_MAPPER);
ok(hr == S_OK, "got %#lx.\n", hr);
num_devs = waveOutGetNumDevs();
if (num_devs == 0) {
skip("no wave out devices.\n");
ISpMMSysAudio_Release(mmaudio);
return;
}
hr = ISpMMSysAudio_SetDeviceId(mmaudio, num_devs);
ok(hr == E_INVALIDARG, "got %#lx.\n", hr);
hr = ISpMMSysAudio_SetDeviceId(mmaudio, 0);
ok(hr == S_OK || broken(hr == S_FALSE) /* Windows */, "got %#lx.\n", hr);
id = 0xdeadbeef;
hr = ISpMMSysAudio_GetDeviceId(mmaudio, &id);
ok(hr == S_OK, "got %#lx.\n", hr);
ok(id == 0, "got %u.\n", id);
ISpMMSysAudio_Release(mmaudio);
}
START_TEST(mmaudio)
{
CoInitialize(NULL);
test_interfaces();
test_device_id();
CoUninitialize();
}
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