From 0ce9eb7ba5cc8c886cebd23fd29627c476ad649c Mon Sep 17 00:00:00 2001 From: Christian Costa Date: Thu, 3 May 2012 23:05:33 +0200 Subject: [PATCH] dmsynth: Create default clock for SynthSink object and assign it to Synth object when callink SetSynthSink. --- dlls/dmsynth/dmsynth_private.h | 1 + dlls/dmsynth/synth.c | 18 ++++++++--- dlls/dmsynth/synthsink.c | 57 +++++++++++++++++++++++++--------- dlls/dmsynth/tests/dmsynth.c | 18 ++++++----- 4 files changed, 69 insertions(+), 25 deletions(-) diff --git a/dlls/dmsynth/dmsynth_private.h b/dlls/dmsynth/dmsynth_private.h index 1cc24acfd38..aec547a7f1f 100644 --- a/dlls/dmsynth/dmsynth_private.h +++ b/dlls/dmsynth/dmsynth_private.h @@ -76,6 +76,7 @@ struct IDirectMusicSynthSinkImpl { LONG ref; /* IDirectMusicSynthSinkImpl fields */ + IReferenceClock* latency_clock; }; /********************************************************************** diff --git a/dlls/dmsynth/synth.c b/dlls/dmsynth/synth.c index 952bb624229..aadb72f76cd 100644 --- a/dlls/dmsynth/synth.c +++ b/dlls/dmsynth/synth.c @@ -64,6 +64,8 @@ static ULONG WINAPI IDirectMusicSynth8Impl_Release(LPDIRECTMUSICSYNTH8 iface) TRACE("(%p)->(ref before=%u)\n", This, refCount + 1); if (!refCount) { + if (This->pLatencyClock) + IReferenceClock_Release(This->pLatencyClock); HeapFree(GetProcessHeap(), 0, This); } @@ -160,9 +162,16 @@ static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 { IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); - TRACE("(%p)->(%p)\n", This, clock); + TRACE("(%p)->(%p)\n", iface, clock); + + if (!clock) + return E_POINTER; + + if (!This->pSynthSink) + return DMUS_E_NOSYNTHSINK; *clock = This->pLatencyClock; + IReferenceClock_AddRef(This->pLatencyClock); return S_OK; } @@ -182,10 +191,13 @@ static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 if { IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); - TRACE("(%p)->(%p)\n", This, synth_sink); + TRACE("(%p)->(%p)\n", iface, synth_sink); This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink; + if (synth_sink) + return IDirectMusicSynthSink_GetLatencyClock(synth_sink, &This->pLatencyClock); + return S_OK; } @@ -337,8 +349,6 @@ HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj obj->pCaps.dwMaxAudioChannels = 2; obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB; MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR)); - /* assign latency clock */ - /*DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&This->pLatencyClock, NULL); */ return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj); } diff --git a/dlls/dmsynth/synthsink.c b/dlls/dmsynth/synthsink.c index 82ed894d3ac..268f6e85663 100644 --- a/dlls/dmsynth/synthsink.c +++ b/dlls/dmsynth/synthsink.c @@ -19,6 +19,8 @@ */ #include "dmsynth_private.h" +#include "initguid.h" +#include "uuids.h" WINE_DEFAULT_DEBUG_CHANNEL(dmsynth); @@ -63,6 +65,8 @@ static ULONG WINAPI IDirectMusicSynthSinkImpl_Release(LPDIRECTMUSICSYNTHSINK ifa TRACE("(%p)->(ref before=%u)\n", This, refCount + 1); if (!refCount) { + if (This->latency_clock) + IReferenceClock_Release(This->latency_clock); HeapFree(GetProcessHeap(), 0, This); } @@ -94,7 +98,13 @@ static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYN { IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface); - FIXME("(%p)->(%p): stub\n", This, clock); + TRACE("(%p)->(%p)\n", iface, clock); + + if (!clock) + return E_POINTER; + + *clock = This->latency_clock; + IReferenceClock_AddRef(This->latency_clock); return S_OK; } @@ -159,17 +169,36 @@ static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = { }; /* for ClassFactory */ -HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) { - IDirectMusicSynthSinkImpl *obj; - - TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter); - obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl)); - if (NULL == obj) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } - obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl; - obj->ref = 0; - - return IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK)obj, lpcGUID, ppobj); +HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter) +{ + IDirectMusicSynthSinkImpl *obj; + HRESULT hr; + + TRACE("(%p,%p,%p)\n", riid, ret_iface, unkouter); + + *ret_iface = NULL; + + obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl)); + if (!obj) + return E_OUTOFMEMORY; + + obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl; + obj->ref = 0; + + hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock); + if (FAILED(hr)) + { + HeapFree(GetProcessHeap(), 0, obj); + return hr; + } + + hr = IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK)obj, riid, ret_iface); + if (FAILED(hr)) + { + IReferenceClock_Release(obj->latency_clock); + HeapFree(GetProcessHeap(), 0, obj); + return hr; + } + + return S_OK; } diff --git a/dlls/dmsynth/tests/dmsynth.c b/dlls/dmsynth/tests/dmsynth.c index 161018e29a0..df67cd47f7f 100644 --- a/dlls/dmsynth/tests/dmsynth.c +++ b/dlls/dmsynth/tests/dmsynth.c @@ -33,7 +33,7 @@ static void test_dmsynth(void) { IDirectMusicSynth *dmsynth = NULL; IDirectMusicSynthSink *dmsynth_sink = NULL; - IReferenceClock* clock = NULL; + IReferenceClock* clock_synth = NULL; IReferenceClock* clock_sink = NULL; HRESULT hr; @@ -48,24 +48,28 @@ static void test_dmsynth(void) ok(hr == S_OK, "CoCreateInstance returned: %x\n", hr); /* Synth has no default clock */ - hr = IDirectMusicSynth_GetLatencyClock(dmsynth, &clock); - todo_wine ok(hr == DMUS_E_NOSYNTHSINK, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr); + hr = IDirectMusicSynth_GetLatencyClock(dmsynth, &clock_synth); + ok(hr == DMUS_E_NOSYNTHSINK, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr); /* SynthSink has a default clock */ hr = IDirectMusicSynthSink_GetLatencyClock(dmsynth_sink, &clock_sink); ok(hr == S_OK, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr); - todo_wine ok(clock_sink != NULL, "No clock returned\n"); + ok(clock_sink != NULL, "No clock returned\n"); /* This will set clock to Synth */ hr = IDirectMusicSynth_SetSynthSink(dmsynth, dmsynth_sink); ok(hr == S_OK, "IDirectMusicSynth_SetSynthSink returned: %x\n", hr); /* Check clocks are the same */ - hr = IDirectMusicSynth_GetLatencyClock(dmsynth, &clock); + hr = IDirectMusicSynth_GetLatencyClock(dmsynth, &clock_synth); ok(hr == S_OK, "IDirectMusicSynth_GetLatencyClock returned: %x\n", hr); - todo_wine ok(clock != NULL, "No clock returned\n"); - ok(clock == clock_sink, "Synth and SynthSink clocks are not the same\n"); + ok(clock_synth != NULL, "No clock returned\n"); + ok(clock_synth == clock_sink, "Synth and SynthSink clocks are not the same\n"); + if (clock_synth) + IReferenceClock_Release(clock_synth); + if (clock_sink) + IReferenceClock_Release(clock_sink); if (dmsynth_sink) IDirectMusicSynthSink_Release(dmsynth_sink); IDirectMusicSynth_Release(dmsynth);