dmusic: Implement IDirectMusic8::SetDirectSound().

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Stefaniuc 2017-05-10 15:13:19 +02:00 committed by Alexandre Julliard
parent b75e8bc6bd
commit 36a88d2841
5 changed files with 46 additions and 16 deletions

View File

@ -169,11 +169,11 @@ static HRESULT test_InitAudio(void)
IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, NULL, NULL, 0, 64, 0, NULL);
ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ref = get_refcount(dmusic);
ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
destroy_performance(performance, dmusic, dsound);
@ -183,11 +183,11 @@ static HRESULT test_InitAudio(void)
IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 3, "dsound ref count got %d expected 3\n", ref);
ok(ref == 3, "dsound ref count got %d expected 3\n", ref);
ref = get_refcount(dmusic);
ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
destroy_performance(performance, dmusic, dsound);

View File

@ -1,5 +1,5 @@
MODULE = dmusic.dll
IMPORTS = dxguid uuid ole32 advapi32 winmm
IMPORTS = dxguid uuid ole32 advapi32 dsound user32 winmm
C_SRCS = \
buffer.c \

View File

@ -73,6 +73,8 @@ static ULONG WINAPI IDirectMusic8Impl_Release(LPDIRECTMUSIC8 iface)
if (!ref) {
IReferenceClock_Release(&This->master_clock->IReferenceClock_iface);
if (This->dsound)
IDirectSound_Release(This->dsound);
HeapFree(GetProcessHeap(), 0, This->system_ports);
HeapFree(GetProcessHeap(), 0, This->ports);
HeapFree(GetProcessHeap(), 0, This);
@ -271,11 +273,38 @@ static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort(LPDIRECTMUSIC8 iface, LPG
return S_OK;
}
static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound(LPDIRECTMUSIC8 iface, LPDIRECTSOUND dsound, HWND wnd)
static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound(IDirectMusic8 *iface, IDirectSound *dsound,
HWND hwnd)
{
IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
HRESULT hr;
int i;
FIXME("(%p)->(%p, %p): stub\n", This, dsound, wnd);
TRACE("(%p)->(%p, %p)\n", This, dsound, hwnd);
for (i = 0; i < This->num_ports; i++)
{
hr = IDirectMusicPort_SetDirectSound(This->ports[i], NULL, NULL);
if (FAILED(hr))
return hr;
}
if (This->dsound)
IDirectSound_Release(This->dsound);
if (!dsound) {
hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&This->dsound, NULL);
if (FAILED(hr))
return hr;
hr = IDirectSound_SetCooperativeLevel(This->dsound, hwnd ? hwnd : GetForegroundWindow(),
DSSCL_PRIORITY);
if (FAILED(hr))
IDirectSound_Release(This->dsound);
return hr;
}
IDirectSound_AddRef(dsound);
This->dsound = dsound;
return S_OK;
}

View File

@ -108,6 +108,7 @@ extern HRESULT DMUSIC_CreateDirectMusicInstrumentImpl (LPCGUID lpcGUID, LPVOID*
struct IDirectMusic8Impl {
IDirectMusic8 IDirectMusic8_iface;
LONG ref;
IDirectSound *dsound;
IReferenceClockImpl *master_clock;
IDirectMusicPort **ports;
int num_ports;

View File

@ -171,11 +171,11 @@ static void test_setdsound(void)
hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, &params, &port, NULL);
ok(hr == S_OK, "CreatePort returned: %x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
hr = IDirectMusicPort_Activate(port, TRUE);
ok(hr == S_OK, "Port Activate returned: %x\n", hr);
ref = get_refcount(dsound);
@ -197,11 +197,11 @@ static void test_setdsound(void)
hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
/* Replacing one dsound with another */
hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&dsound2, NULL);
@ -211,7 +211,7 @@ static void test_setdsound(void)
ref = get_refcount(dsound);
ok(ref == 1, "dsound ref count got %d expected 1\n", ref);
ref = get_refcount(dsound2);
todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
/* Replacing the dsound in the port */
hr = IDirectMusicPort_SetDirectSound(port, dsound, NULL);
@ -219,27 +219,27 @@ static void test_setdsound(void)
ref = get_refcount(dsound);
todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
ref = get_refcount(dsound2);
todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
/* Setting the dsound again on the port will mess with the parent dmusic */
hr = IDirectMusicPort_SetDirectSound(port, dsound, NULL);
ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 3, "dsound ref count got %d expected 3\n", ref);
ref = get_refcount(dsound2);
ok(ref == 1, "dsound2 ref count got %d expected 1\n", ref);
todo_wine ok(ref == 1, "dsound2 ref count got %d expected 1\n", ref);
IDirectSound_AddRef(dsound2); /* Crash prevention */
hr = IDirectMusicPort_Activate(port, TRUE);
ok(hr == S_OK, "Activate returned: %x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 4, "dsound ref count got %d expected 4\n", ref);
ref = get_refcount(dsound2);
ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
hr = IDirectMusicPort_Activate(port, TRUE);
todo_wine ok(hr == S_FALSE, "Activate returned: %x\n", hr);
ref = get_refcount(dsound);
todo_wine ok(ref == 4, "dsound ref count got %d expected 4\n", ref);
ref = get_refcount(dsound2);
ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref);
/* Deactivating the port messes with the dsound refcount in the parent dmusic */
hr = IDirectMusicPort_Activate(port, FALSE);