[PATCH 4/4] dmsynth: Disconnect old sink, addref and init new sink

Michael Stefaniuc mstefani at winehq.org
Wed Jan 19 11:48:50 CST 2022


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 dlls/dmsynth/synth.c         | 21 +++++++++++++++++----
 dlls/dmsynth/tests/dmsynth.c | 12 ++++++++++--
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/dlls/dmsynth/synth.c b/dlls/dmsynth/synth.c
index 7c573ca708c..3d3af80d005 100644
--- a/dlls/dmsynth/synth.c
+++ b/dlls/dmsynth/synth.c
@@ -362,15 +362,28 @@ static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(IDirectMusicSynth8 *if
         IDirectMusicSynthSink *sink)
 {
     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
+    HRESULT hr;
 
     TRACE("(%p)->(%p)\n", iface, sink);
 
-    This->sink = sink;
+    if (sink == This->sink)
+        return S_OK;
+
+    if (!sink || This->sink) {
+        /* Disconnect the sink */
+        if (This->latency_clock)
+            IReferenceClock_Release(This->latency_clock);
+        IDirectMusicSynthSink_Release(This->sink);
+    }
 
-    if (sink)
-        return IDirectMusicSynthSink_GetLatencyClock(sink, &This->latency_clock);
+    This->sink = sink;
+    if (!sink)
+        return S_OK;
 
-    return S_OK;
+    IDirectMusicSynthSink_AddRef(This->sink);
+    if (FAILED(hr = IDirectMusicSynthSink_Init(sink, (IDirectMusicSynth *)iface)))
+        return hr;
+    return IDirectMusicSynthSink_GetLatencyClock(sink, &This->latency_clock);
 }
 
 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(IDirectMusicSynth8 *iface, short *buffer,
diff --git a/dlls/dmsynth/tests/dmsynth.c b/dlls/dmsynth/tests/dmsynth.c
index bb42553469b..1e3e20829b7 100644
--- a/dlls/dmsynth/tests/dmsynth.c
+++ b/dlls/dmsynth/tests/dmsynth.c
@@ -54,7 +54,7 @@ static ULONG get_refcount(void *iface)
 static void test_dmsynth(void)
 {
     IDirectMusicSynth *dmsynth = NULL;
-    IDirectMusicSynthSink *dmsynth_sink = NULL;
+    IDirectMusicSynthSink *dmsynth_sink = NULL, *dmsynth_sink2 = NULL;
     IReferenceClock* clock_synth = NULL;
     IReferenceClock* clock_sink = NULL;
     IKsControl* control_synth = NULL;
@@ -68,7 +68,11 @@ static void test_dmsynth(void)
     hr = CoCreateInstance(&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth, (LPVOID*)&dmsynth);
     ok(hr == S_OK, "CoCreateInstance returned: %x\n", hr);
 
-    hr = CoCreateInstance(&CLSID_DirectMusicSynthSink, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynthSink, (LPVOID*)&dmsynth_sink);
+    hr = CoCreateInstance(&CLSID_DirectMusicSynthSink, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynthSink,
+            (void **)&dmsynth_sink);
+    ok(hr == S_OK, "CoCreateInstance returned: %x\n", hr);
+    hr = CoCreateInstance(&CLSID_DirectMusicSynthSink, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynthSink,
+            (void **)&dmsynth_sink2);
     ok(hr == S_OK, "CoCreateInstance returned: %x\n", hr);
 
     hr = IDirectMusicSynth_QueryInterface(dmsynth, &IID_IKsControl, (LPVOID*)&control_synth);
@@ -127,6 +131,8 @@ static void test_dmsynth(void)
     ref_clock_sink = get_refcount(clock_sink);
 
     /* This will Init() the SynthSink and finish initializing the Synth */
+    hr = IDirectMusicSynth_SetSynthSink(dmsynth, dmsynth_sink2);
+    ok(hr == S_OK, "IDirectMusicSynth_SetSynthSink returned: %x\n", hr);
     hr = IDirectMusicSynth_SetSynthSink(dmsynth, dmsynth_sink);
     ok(hr == S_OK, "IDirectMusicSynth_SetSynthSink returned: %x\n", hr);
 
@@ -148,6 +154,8 @@ static void test_dmsynth(void)
         IReferenceClock_Release(clock_sink);
     if (dmsynth_sink)
         IDirectMusicSynthSink_Release(dmsynth_sink);
+    if (dmsynth_sink2)
+        IDirectMusicSynthSink_Release(dmsynth_sink2);
     IDirectMusicSynth_Release(dmsynth);
 }
 
-- 
2.31.1




More information about the wine-devel mailing list