wasapi: split gst_wasapi_util_get_device_client()
authorJakub Janků <jjanku@redhat.com>
Wed, 17 Mar 2021 21:45:57 +0000 (22:45 +0100)
committerJakub Janků <janku.jakub.jj@gmail.com>
Mon, 12 Jul 2021 11:47:06 +0000 (13:47 +0200)
The functionality now resides in
gst_wasapi_util_get_device() and
gst_wasapi_util_get_audio_client().

This is a preparatory patch. It will be used in the following
patch to init/deinit the AudioClient separately from the device.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2096>

sys/wasapi/gstwasapisink.c
sys/wasapi/gstwasapisrc.c
sys/wasapi/gstwasapiutil.c
sys/wasapi/gstwasapiutil.h

index 1d114a2..8758897 100644 (file)
@@ -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"));
index db69170..016f862 100644 (file)
@@ -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"));
index 5d7ff38..73442f7 100644 (file)
@@ -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;
 }
 
index 4e560e6..8cd5d32 100644 (file)
@@ -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,