[vlc-devel] [PATCH] wasapi: Delegate cleanup to the audio output

Hugo Beauzée-Luyssen hugo at beauzee.fr
Mon Feb 16 12:07:47 CET 2015


---
 modules/audio_output/mmdevice.c | 9 +++++++++
 modules/audio_output/mmdevice.h | 8 ++++++++
 modules/audio_output/wasapi.c   | 5 ++---
 modules/audio_output/winstore.c | 7 +++++++
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index d9d3573..03fb61e 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -1044,6 +1044,13 @@ static HRESULT ActivateDevice(void *opaque, REFIID iid, PROPVARIANT *actparms,
     return IMMDevice_Activate(dev, iid, CLSCTX_ALL, actparms, pv);
 }
 
+static void DeactivateDevice(void* pv)
+{
+    IAudioClient *device = (IAudioClient*)pv;
+    IAudioClient_Stop(device); /* should not be needed */
+    IAudioClient_Release(device);
+}
+
 static int aout_stream_Start(void *func, va_list ap)
 {
     aout_stream_start_t start = func;
@@ -1078,6 +1085,7 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 
     s->owner.device = sys->dev;
     s->owner.activate = ActivateDevice;
+    s->owner.deactivate = DeactivateDevice;
 
     EnterMTA();
     for (;;)
@@ -1116,6 +1124,7 @@ static void Stop(audio_output_t *aout)
 
     vlc_object_release(sys->stream);
     sys->stream = NULL;
+    IAudioClient_Release(sys->client);
 }
 
 static int Open(vlc_object_t *obj)
diff --git a/modules/audio_output/mmdevice.h b/modules/audio_output/mmdevice.h
index 51f5e42..bec4597 100644
--- a/modules/audio_output/mmdevice.h
+++ b/modules/audio_output/mmdevice.h
@@ -40,6 +40,7 @@ struct aout_stream
     {
         void *device;
         HRESULT (*activate)(void *device, REFIID, PROPVARIANT *, void **);
+        void(*deactivate)(void*);
     } owner;
 };
 
@@ -92,4 +93,11 @@ HRESULT aout_stream_Activate(aout_stream_t *s, REFIID iid,
 {
     return s->owner.activate(s->owner.device, iid, actparms, pv);
 }
+
+static inline
+void aout_stream_Deactivate(aout_stream_t *s, void *dev)
+{
+    if (s->owner.deactivate != NULL)
+        s->owner.deactivate(dev);
+}
 #endif
diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index 7a47161..4a3ac71 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -439,7 +439,7 @@ static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict fmt,
     return S_OK;
 error:
     if (sys->client != NULL)
-        IAudioClient_Release(sys->client);
+        aout_stream_Deactivate(s, sys->client);
     free(sys);
     return hr;
 }
@@ -448,8 +448,7 @@ static void Stop(aout_stream_t *s)
 {
     aout_stream_sys_t *sys = s->sys;
 
-    IAudioClient_Stop(sys->client); /* should not be needed */
-    IAudioClient_Release(sys->client);
+    aout_stream_Deactivate(s, sys->client);
 
     free(sys);
 }
diff --git a/modules/audio_output/winstore.c b/modules/audio_output/winstore.c
index 6ae99ef..7769ad7 100644
--- a/modules/audio_output/winstore.c
+++ b/modules/audio_output/winstore.c
@@ -107,6 +107,12 @@ static HRESULT ActivateDevice(void *opaque, REFIID iid, PROPVARIANT *actparms,
     return S_OK;
 }
 
+static void DeactivateDevice(void* device)
+{
+    IAudioClient_Stop((IAudioClient*)device);
+    IAudioClient_Release((IAudioClient*) device);
+}
+
 static int aout_stream_Start(void *func, va_list ap)
 {
     aout_stream_start_t start = func;
@@ -137,6 +143,7 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 
     s->owner.device = sys->client;
     s->owner.activate = ActivateDevice;
+    s->owner.deactivate = DeactivateDevice;
 
     EnterMTA();
     sys->module = vlc_module_load(s, "aout stream", NULL, false,
-- 
2.2.0




More information about the vlc-devel mailing list