wasapi: split gst_wasapi_util_get_device_client()

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>
This commit is contained in:
Jakub Janků 2021-03-17 22:45:57 +01:00 committed by Jakub Janků
parent d83881d43a
commit 766a126380
4 changed files with 42 additions and 20 deletions

View 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"));

View 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"));

View 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;
}

View 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,