From ff17a404b31d214952c248885bd957fcf5bcf5a0 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 16 Apr 2018 19:35:07 +0530 Subject: [PATCH] wasapi: Call CoIn/Uninitialize() around prepare() Seems to be required for exclusive mode and also for all initialization on Windows 7 https://bugzilla.gnome.org/show_bug.cgi?id=795274 --- sys/wasapi/gstwasapisink.c | 8 +++++--- sys/wasapi/gstwasapisrc.c | 8 ++++---- sys/wasapi/gstwasapiutil.c | 4 ---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sys/wasapi/gstwasapisink.c b/sys/wasapi/gstwasapisink.c index 77720be326..3fa370dc4a 100644 --- a/sys/wasapi/gstwasapisink.c +++ b/sys/wasapi/gstwasapisink.c @@ -474,6 +474,8 @@ gst_wasapi_sink_prepare (GstAudioSink * asink, GstAudioRingBufferSpec * spec) guint bpf, rate, devicep_frames; HRESULT hr; + CoInitialize (NULL); + if (gst_wasapi_sink_can_audioclient3 (self)) { if (!gst_wasapi_util_initialize_audioclient3 (GST_ELEMENT (self), spec, (IAudioClient3 *) self->client, self->mix_format, self->low_latency, @@ -577,9 +579,7 @@ gst_wasapi_sink_unprepare (GstAudioSink * asink) { GstWasapiSink *self = GST_WASAPI_SINK (asink); - if (self->sharemode == AUDCLNT_SHAREMODE_EXCLUSIVE && - !gst_wasapi_sink_can_audioclient3 (self)) - CoUninitialize (); + CoUninitialize (); if (self->thread_priority_handle != NULL) { gst_wasapi_util_revert_thread_characteristics @@ -596,6 +596,8 @@ gst_wasapi_sink_unprepare (GstAudioSink * asink) self->render_client = NULL; } + CoUninitialize (); + return TRUE; } diff --git a/sys/wasapi/gstwasapisrc.c b/sys/wasapi/gstwasapisrc.c index 4c51a40241..c57d577fbe 100644 --- a/sys/wasapi/gstwasapisrc.c +++ b/sys/wasapi/gstwasapisrc.c @@ -436,6 +436,8 @@ gst_wasapi_src_prepare (GstAudioSrc * asrc, GstAudioRingBufferSpec * spec) guint bpf, rate, devicep_frames, buffer_frames; HRESULT hr; + CoInitialize (NULL); + if (gst_wasapi_src_can_audioclient3 (self)) { if (!gst_wasapi_util_initialize_audioclient3 (GST_ELEMENT (self), spec, (IAudioClient3 *) self->client, self->mix_format, self->low_latency, @@ -517,10 +519,6 @@ gst_wasapi_src_unprepare (GstAudioSrc * asrc) { GstWasapiSrc *self = GST_WASAPI_SRC (asrc); - if (self->sharemode == AUDCLNT_SHAREMODE_EXCLUSIVE && - !gst_wasapi_src_can_audioclient3 (self)) - CoUninitialize (); - if (self->thread_priority_handle != NULL) { gst_wasapi_util_revert_thread_characteristics (self->thread_priority_handle); @@ -543,6 +541,8 @@ gst_wasapi_src_unprepare (GstAudioSrc * asrc) self->client_clock_freq = 0; + CoUninitialize (); + return TRUE; } diff --git a/sys/wasapi/gstwasapiutil.c b/sys/wasapi/gstwasapiutil.c index 9507c25eef..824b3a77b5 100644 --- a/sys/wasapi/gstwasapiutil.c +++ b/sys/wasapi/gstwasapiutil.c @@ -870,10 +870,6 @@ gst_wasapi_util_initialize_audioclient (GstElement * self, min_period, &device_period, &device_buffer_duration); } - /* For some reason, we need to call this a second time for exclusive mode */ - if (sharemode == AUDCLNT_SHAREMODE_EXCLUSIVE) - CoInitialize (NULL); - stream_flags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK; if (loopback) stream_flags |= AUDCLNT_STREAMFLAGS_LOOPBACK;