diff --git a/dlls/dmusic/port.c b/dlls/dmusic/port.c index 577fb0af2d8..1bff721fcac 100644 --- a/dlls/dmusic/port.c +++ b/dlls/dmusic/port.c @@ -31,11 +31,12 @@ typedef struct SynthPortImpl { IKsControl IKsControl_iface; LONG ref; IDirectMusic8Impl *parent; - IDirectSound *pDirectSound; + IDirectSound *dsound; + IDirectSoundBuffer *dsbuffer; IReferenceClock *pLatencyClock; IDirectMusicSynth *synth; IDirectMusicSynthSink *synth_sink; - BOOL fActive; + BOOL active; DMUS_PORTCAPS caps; DMUS_PORTPARAMS params; int nrofgroups; @@ -198,6 +199,10 @@ static ULONG WINAPI SynthPortImpl_IDirectMusicPort_Release(LPDIRECTMUSICPORT ifa IDirectMusicSynth_Release(This->synth); IDirectMusicSynthSink_Release(This->synth_sink); IReferenceClock_Release(This->pLatencyClock); + if (This->dsbuffer) + IDirectSoundBuffer_Release(This->dsbuffer); + if (This->dsound) + IDirectSound_Release(This->dsound); HeapFree(GetProcessHeap(), 0, This); } @@ -437,7 +442,7 @@ static HRESULT WINAPI SynthPortImpl_IDirectMusicPort_Activate(LPDIRECTMUSICPORT TRACE("(%p/%p)->(%d)\n", iface, This, active); - This->fActive = active; + This->active = active; return S_OK; } @@ -468,11 +473,33 @@ static HRESULT WINAPI SynthPortImpl_IDirectMusicPort_GetChannelPriority(LPDIRECT return S_OK; } -static HRESULT WINAPI SynthPortImpl_IDirectMusicPort_SetDirectSound(LPDIRECTMUSICPORT iface, LPDIRECTSOUND direct_sound, LPDIRECTSOUNDBUFFER direct_sound_buffer) +static HRESULT WINAPI synth_dmport_SetDirectSound(IDirectMusicPort *iface, IDirectSound *dsound, + IDirectSoundBuffer *dsbuffer) { SynthPortImpl *This = impl_from_SynthPortImpl_IDirectMusicPort(iface); - FIXME("(%p/%p)->(%p, %p): stub\n", iface, This, direct_sound, direct_sound_buffer); + FIXME("(%p/%p)->(%p, %p): semi-stub\n", iface, This, dsound, dsbuffer); + + if (This->active) + return DMUS_E_DSOUND_ALREADY_SET; + + if (This->dsound) { + if (This->dsound != This->parent->dsound) + ERR("Not the same dsound in the port (%p) and parent dmusic (%p), expect trouble!\n", + This->dsound, This->parent->dsound); + if (!IDirectSound_Release(This->parent->dsound)) + This->parent->dsound = NULL; + } + if (This->dsbuffer) + IDirectSound_Release(This->dsbuffer); + + This->dsound = dsound; + This->dsbuffer = dsbuffer; + + if (This->dsound) + IDirectSound_AddRef(This->dsound); + if (This->dsbuffer) + IDirectSound_AddRef(This->dsbuffer); return S_OK; } @@ -543,7 +570,7 @@ static const IDirectMusicPortVtbl SynthPortImpl_DirectMusicPort_Vtbl = { SynthPortImpl_IDirectMusicPort_Activate, SynthPortImpl_IDirectMusicPort_SetChannelPriority, SynthPortImpl_IDirectMusicPort_GetChannelPriority, - SynthPortImpl_IDirectMusicPort_SetDirectSound, + synth_dmport_SetDirectSound, SynthPortImpl_IDirectMusicPort_GetFormat }; @@ -785,7 +812,7 @@ HRESULT synth_port_create(IDirectMusic8Impl *parent, DMUS_PORTPARAMS *port_param obj->IKsControl_iface.lpVtbl = &ikscontrol_vtbl; obj->ref = 1; obj->parent = parent; - obj->fActive = FALSE; + obj->active = FALSE; obj->params = *port_params; obj->caps = *port_caps; diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c index f701b2b9333..a96b4f77fd4 100644 --- a/dlls/dmusic/tests/dmusic.c +++ b/dlls/dmusic/tests/dmusic.c @@ -183,11 +183,11 @@ static void test_setdsound(void) /* Releasing dsound from dmusic */ hr = IDirectMusic_SetDirectSound(dmusic, NULL, NULL); - todo_wine ok(hr == DMUS_E_DSOUND_ALREADY_SET, "SetDirectSound failed: %08x\n", hr); + ok(hr == DMUS_E_DSOUND_ALREADY_SET, "SetDirectSound failed: %08x\n", hr); hr = IDirectMusicPort_Activate(port, FALSE); ok(hr == S_OK, "Port Activate 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 = IDirectMusic_SetDirectSound(dmusic, NULL, NULL); ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); ref = get_refcount(dsound); @@ -217,41 +217,41 @@ static void test_setdsound(void) hr = IDirectMusicPort_SetDirectSound(port, 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); ref = get_refcount(dsound2); 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); + ok(ref == 3, "dsound ref count got %d expected 3\n", ref); ref = get_refcount(dsound2); - todo_wine ok(ref == 1, "dsound2 ref count got %d expected 1\n", ref); + 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); - 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); 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); - 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); /* Deactivating the port messes with the dsound refcount in the parent dmusic */ hr = IDirectMusicPort_Activate(port, FALSE); ok(hr == S_OK, "Port Activate returned: %x\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(dsound2); todo_wine ok(ref == 1, "dsound2 ref count got %d expected 1\n", ref); hr = IDirectMusicPort_Activate(port, FALSE); todo_wine ok(hr == S_FALSE, "Port Activate returned: %x\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(dsound2); todo_wine ok(ref == 1, "dsound2 ref count got %d expected 1\n", ref);