[PATCH 3/6 v2] dmusic: Implement IDirectMusic8::SetDirectSound()
Michael Stefaniuc
mstefani at winehq.org
Wed May 10 08:13:19 CDT 2017
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
v2: Don't leak a dsound object should SetCooperativeLevel() fail.
Not resending the whole series as the change is minimal and not touching the tests:
interdiff out/0003-dmusic-Implement-IDirectMusic8-SetDirectSound.patch out/0001-dmusic-Implement-IDirectMusic8-SetDirectSound.patch
| diff -u b/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c
| --- b/dlls/dmusic/dmusic.c
| +++ b/dlls/dmusic/dmusic.c
| @@ -298,6 +298,8 @@
| return hr;
| hr = IDirectSound_SetCooperativeLevel(This->dsound, hwnd ? hwnd : GetForegroundWindow(),
| DSSCL_PRIORITY);
| + if (FAILED(hr))
| + IDirectSound_Release(This->dsound);
| return hr;
| }
|
dlls/dmime/tests/performance.c | 8 ++++----
dlls/dmusic/Makefile.in | 2 +-
dlls/dmusic/dmusic.c | 33 +++++++++++++++++++++++++++++++--
dlls/dmusic/dmusic_private.h | 1 +
dlls/dmusic/tests/dmusic.c | 18 +++++++++---------
5 files changed, 46 insertions(+), 16 deletions(-)
diff --git a/dlls/dmime/tests/performance.c b/dlls/dmime/tests/performance.c
index 0932cd9..730ec52 100644
--- a/dlls/dmime/tests/performance.c
+++ b/dlls/dmime/tests/performance.c
@@ -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);
diff --git a/dlls/dmusic/Makefile.in b/dlls/dmusic/Makefile.in
index 98cfaef..a8955a2 100644
--- a/dlls/dmusic/Makefile.in
+++ b/dlls/dmusic/Makefile.in
@@ -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 \
diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c
index b1c0a19..5dcda64 100644
--- a/dlls/dmusic/dmusic.c
+++ b/dlls/dmusic/dmusic.c
@@ -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;
+
+ 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;
+ }
- FIXME("(%p)->(%p, %p): stub\n", This, dsound, wnd);
+ IDirectSound_AddRef(dsound);
+ This->dsound = dsound;
return S_OK;
}
diff --git a/dlls/dmusic/dmusic_private.h b/dlls/dmusic/dmusic_private.h
index 0819687..a470989 100644
--- a/dlls/dmusic/dmusic_private.h
+++ b/dlls/dmusic/dmusic_private.h
@@ -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;
diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c
index 1d1f948..f701b2b 100644
--- a/dlls/dmusic/tests/dmusic.c
+++ b/dlls/dmusic/tests/dmusic.c
@@ -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, ¶ms, &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);
--
2.9.3
More information about the wine-patches
mailing list