diff --git a/sys/wasapi/gstwasapisink.c b/sys/wasapi/gstwasapisink.c index 1d114a2d79..87588974b7 100644 --- a/sys/wasapi/gstwasapisink.c +++ b/sys/wasapi/gstwasapisink.c @@ -412,8 +412,10 @@ gst_wasapi_sink_open (GstAudioSink * asink) * even if the old device was unplugged. We need to handle this somehow. * For example, perhaps we should automatically switch to the new device if * the default device is changed and a device isn't explicitly selected. */ - if (!gst_wasapi_util_get_device_client (GST_ELEMENT (self), eRender, - self->role, self->device_strid, &device, &client)) { + if (!gst_wasapi_util_get_device (GST_ELEMENT (self), eRender, + self->role, self->device_strid, &device) + || !gst_wasapi_util_get_audio_client (GST_ELEMENT (self), + device, &client)) { if (!self->device_strid) GST_ELEMENT_ERROR (self, RESOURCE, OPEN_WRITE, (NULL), ("Failed to get default device")); diff --git a/sys/wasapi/gstwasapisrc.c b/sys/wasapi/gstwasapisrc.c index db6917036f..016f862a51 100644 --- a/sys/wasapi/gstwasapisrc.c +++ b/sys/wasapi/gstwasapisrc.c @@ -426,9 +426,11 @@ gst_wasapi_src_open (GstAudioSrc * asrc) * even if the old device was unplugged. We need to handle this somehow. * For example, perhaps we should automatically switch to the new device if * the default device is changed and a device isn't explicitly selected. */ - if (!gst_wasapi_util_get_device_client (GST_ELEMENT (self), + if (!gst_wasapi_util_get_device (GST_ELEMENT (self), self->loopback ? eRender : eCapture, self->role, self->device_strid, - &device, &client)) { + &device) + || !gst_wasapi_util_get_audio_client (GST_ELEMENT (self), + device, &client)) { if (!self->device_strid) GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL), ("Failed to get default device")); @@ -445,9 +447,10 @@ gst_wasapi_src_open (GstAudioSrc * asrc) * we will keep pusing silence data to into wasapi client so that make audio * client report audio data in any case */ - if (!gst_wasapi_util_get_device_client (GST_ELEMENT (self), - eRender, self->role, self->device_strid, - &loopback_device, &self->loopback_client)) { + if (!gst_wasapi_util_get_device (GST_ELEMENT (self), + eRender, self->role, self->device_strid, &loopback_device) + || !gst_wasapi_util_get_audio_client (GST_ELEMENT (self), + loopback_device, &self->loopback_client)) { if (!self->device_strid) GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL), ("Failed to get default device for loopback")); diff --git a/sys/wasapi/gstwasapiutil.c b/sys/wasapi/gstwasapiutil.c index 5d7ff38c4c..73442f7f83 100644 --- a/sys/wasapi/gstwasapiutil.c +++ b/sys/wasapi/gstwasapiutil.c @@ -533,15 +533,14 @@ out: } gboolean -gst_wasapi_util_get_device_client (GstElement * self, +gst_wasapi_util_get_device (GstElement * self, gint data_flow, gint role, const wchar_t * device_strid, - IMMDevice ** ret_device, IAudioClient ** ret_client) + IMMDevice ** ret_device) { gboolean res = FALSE; HRESULT hr; IMMDeviceEnumerator *enumerator = NULL; IMMDevice *device = NULL; - IAudioClient *client = NULL; if (!(enumerator = gst_wasapi_util_get_device_enumerator (GST_OBJECT (self)))) goto beach; @@ -561,6 +560,29 @@ gst_wasapi_util_get_device_client (GstElement * self, } } + IUnknown_AddRef (device); + *ret_device = device; + + res = TRUE; + +beach: + if (device != NULL) + IUnknown_Release (device); + + if (enumerator != NULL) + IUnknown_Release (enumerator); + + return res; +} + +gboolean +gst_wasapi_util_get_audio_client (GstElement * self, + IMMDevice * device, IAudioClient ** ret_client) +{ + IAudioClient *client = NULL; + gboolean res = FALSE; + HRESULT hr; + if (gst_wasapi_util_have_audioclient3 ()) hr = IMMDevice_Activate (device, &IID_IAudioClient3, CLSCTX_ALL, NULL, (void **) &client); @@ -570,9 +592,7 @@ gst_wasapi_util_get_device_client (GstElement * self, HR_FAILED_GOTO (hr, IMMDevice::Activate (IID_IAudioClient), beach); IUnknown_AddRef (client); - IUnknown_AddRef (device); *ret_client = client; - *ret_device = device; res = TRUE; @@ -580,12 +600,6 @@ beach: if (client != NULL) IUnknown_Release (client); - if (device != NULL) - IUnknown_Release (device); - - if (enumerator != NULL) - IUnknown_Release (enumerator); - return res; } diff --git a/sys/wasapi/gstwasapiutil.h b/sys/wasapi/gstwasapiutil.h index 4e560e6bd1..8cd5d32407 100644 --- a/sys/wasapi/gstwasapiutil.h +++ b/sys/wasapi/gstwasapiutil.h @@ -95,9 +95,12 @@ gchar *gst_wasapi_util_hresult_to_string (HRESULT hr); gboolean gst_wasapi_util_get_devices (GstObject * element, gboolean active, GList ** devices); -gboolean gst_wasapi_util_get_device_client (GstElement * element, +gboolean gst_wasapi_util_get_device (GstElement * self, gint data_flow, gint role, const wchar_t * device_strid, - IMMDevice ** ret_device, IAudioClient ** ret_client); + IMMDevice ** ret_device); + +gboolean gst_wasapi_util_get_audio_client (GstElement * self, + IMMDevice * device, IAudioClient ** ret_client); gboolean gst_wasapi_util_get_device_format (GstElement * element, gint device_mode, IMMDevice * device, IAudioClient * client,