From a6c8c6f8662c2ce995decab06fb5e0b7b74bd27e Mon Sep 17 00:00:00 2001 From: Jimmy Ohn Date: Sun, 7 Apr 2024 19:39:58 +0900 Subject: [PATCH] pulsedeviceprovider: Add is_default_device_name function and missing lock Add is_default_device_name function to simplify compare device type name and fix the missing lock when accessing default_sink_name and default_source_name. Part-of: --- .../ext/pulse/pulsedeviceprovider.c | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/pulse/pulsedeviceprovider.c b/subprojects/gst-plugins-good/ext/pulse/pulsedeviceprovider.c index 6763ab6eef..85d287a3cf 100644 --- a/subprojects/gst-plugins-good/ext/pulse/pulsedeviceprovider.c +++ b/subprojects/gst-plugins-good/ext/pulse/pulsedeviceprovider.c @@ -193,12 +193,36 @@ context_state_cb (pa_context * c, void *userdata) } } +static gboolean +is_default_device_name (GstPulseDeviceProvider * self, + const char *name, GstPulseDeviceType type) +{ + gboolean ret = FALSE; + + GST_OBJECT_LOCK (self); + switch (type) { + case GST_PULSE_DEVICE_TYPE_SINK: + ret = !g_strcmp0 (name, self->default_sink_name); + break; + case GST_PULSE_DEVICE_TYPE_SOURCE: + ret = !g_strcmp0 (name, self->default_source_name); + break; + default: + GST_ERROR_OBJECT (self, "Unknown pulse device type!"); + break; + } + GST_OBJECT_UNLOCK (self); + + return ret; +} + static GstDevice * new_source (GstPulseDeviceProvider * self, const pa_source_info * info) { GstCaps *caps; GstStructure *props; guint i; + gboolean is_default = FALSE; caps = gst_caps_new_empty (); @@ -211,9 +235,11 @@ new_source (GstPulseDeviceProvider * self, const pa_source_info * info) gst_device_provider_hide_provider (GST_DEVICE_PROVIDER (self), "alsadeviceprovider"); + is_default = is_default_device_name (self, info->name, + GST_PULSE_DEVICE_TYPE_SOURCE); + return gst_pulse_device_new (info->index, info->description, - caps, info->name, GST_PULSE_DEVICE_TYPE_SOURCE, props, - !g_strcmp0 (info->name, self->default_source_name)); + caps, info->name, GST_PULSE_DEVICE_TYPE_SOURCE, props, is_default); } static GstDevice * @@ -222,6 +248,8 @@ new_sink (GstPulseDeviceProvider * self, const pa_sink_info * info) GstCaps *caps; GstStructure *props; guint i; + gboolean is_default = FALSE; + caps = gst_caps_new_empty (); @@ -230,9 +258,11 @@ new_sink (GstPulseDeviceProvider * self, const pa_sink_info * info) props = gst_pulse_make_structure (info->proplist); + is_default = is_default_device_name (self, info->name, + GST_PULSE_DEVICE_TYPE_SINK); + return gst_pulse_device_new (info->index, info->description, - caps, info->name, GST_PULSE_DEVICE_TYPE_SINK, props, - !g_strcmp0 (info->name, self->default_sink_name)); + caps, info->name, GST_PULSE_DEVICE_TYPE_SINK, props, is_default); } static void @@ -280,10 +310,14 @@ get_server_info_cb (pa_context * context, const pa_server_info * info, gst_structure_get_boolean (props, "is-default", &was_default); switch (dev->type) { case GST_PULSE_DEVICE_TYPE_SINK: - is_default = !g_strcmp0 (dev->internal_name, self->default_sink_name); + is_default = + is_default_device_name (self, dev->internal_name, + GST_PULSE_DEVICE_TYPE_SINK); break; case GST_PULSE_DEVICE_TYPE_SOURCE: - is_default = !g_strcmp0 (dev->internal_name, self->default_source_name); + is_default = + is_default_device_name (self, dev->internal_name, + GST_PULSE_DEVICE_TYPE_SOURCE); break; }