diff --git a/sys/wasapi/gstwasapisink.c b/sys/wasapi/gstwasapisink.c index f114eac8c8..a124ba30a5 100644 --- a/sys/wasapi/gstwasapisink.c +++ b/sys/wasapi/gstwasapisink.c @@ -182,7 +182,7 @@ gst_wasapi_sink_finalize (GObject * object) } g_clear_pointer (&self->positions, g_free); - g_clear_pointer (&self->device, g_free); + g_clear_pointer (&self->device_strid, g_free); self->mute = FALSE; G_OBJECT_CLASS (gst_wasapi_sink_parent_class)->finalize (object); @@ -204,8 +204,8 @@ gst_wasapi_sink_set_property (GObject * object, guint prop_id, case PROP_DEVICE: { const gchar *device = g_value_get_string (value); - g_free (self->device); - self->device = + g_free (self->device_strid); + self->device_strid = device ? g_utf8_to_utf16 (device, -1, NULL, NULL, NULL) : NULL; break; } @@ -229,8 +229,8 @@ gst_wasapi_sink_get_property (GObject * object, guint prop_id, g_value_set_boolean (value, self->mute); break; case PROP_DEVICE: - g_value_take_string (value, self->device ? - g_utf16_to_utf8 (self->device, -1, NULL, NULL, NULL) : NULL); + g_value_take_string (value, self->device_strid ? + g_utf16_to_utf8 (self->device_strid, -1, NULL, NULL, NULL) : NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -309,14 +309,18 @@ gst_wasapi_sink_open (GstAudioSink * asink) if (self->client) return TRUE; + /* FIXME: Switching the default device does not switch the stream to it, + * 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), FALSE, - self->role, self->device, &client)) { - if (!self->device) - GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL), + self->role, self->device_strid, &client)) { + if (!self->device_strid) + GST_ELEMENT_ERROR (self, RESOURCE, OPEN_WRITE, (NULL), ("Failed to get default device")); else - GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL), - ("Failed to open device %S", self->device)); + GST_ELEMENT_ERROR (self, RESOURCE, OPEN_WRITE, (NULL), + ("Failed to open device %S", self->device_strid)); goto beach; } diff --git a/sys/wasapi/gstwasapisink.h b/sys/wasapi/gstwasapisink.h index 8af96c01c3..37ba888d59 100644 --- a/sys/wasapi/gstwasapisink.h +++ b/sys/wasapi/gstwasapisink.h @@ -58,7 +58,7 @@ struct _GstWasapiSink /* properties */ gint role; gboolean mute; - wchar_t *device; + wchar_t *device_strid; }; struct _GstWasapiSinkClass diff --git a/sys/wasapi/gstwasapisrc.c b/sys/wasapi/gstwasapisrc.c index 7831a5357d..3eb19cc6c5 100644 --- a/sys/wasapi/gstwasapisrc.c +++ b/sys/wasapi/gstwasapisrc.c @@ -183,7 +183,7 @@ gst_wasapi_src_finalize (GObject * object) g_clear_pointer (&self->cached_caps, gst_caps_unref); g_clear_pointer (&self->positions, g_free); - g_clear_pointer (&self->device, g_free); + g_clear_pointer (&self->device_strid, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -201,8 +201,8 @@ gst_wasapi_src_set_property (GObject * object, guint prop_id, case PROP_DEVICE: { const gchar *device = g_value_get_string (value); - g_free (self->device); - self->device = + g_free (self->device_strid); + self->device_strid = device ? g_utf8_to_utf16 (device, -1, NULL, NULL, NULL) : NULL; break; } @@ -223,8 +223,8 @@ gst_wasapi_src_get_property (GObject * object, guint prop_id, g_value_set_enum (value, gst_wasapi_erole_to_device_role (self->role)); break; case PROP_DEVICE: - g_value_take_string (value, self->device ? - g_utf16_to_utf8 (self->device, -1, NULL, NULL, NULL) : NULL); + g_value_take_string (value, self->device_strid ? + g_utf16_to_utf8 (self->device_strid, -1, NULL, NULL, NULL) : NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -306,13 +306,13 @@ gst_wasapi_src_open (GstAudioSrc * asrc) * 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), TRUE, - self->role, self->device, &client)) { - if (!self->device) + self->role, self->device_strid, &client)) { + if (!self->device_strid) GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL), ("Failed to get default device")); else GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL), - ("Failed to open device %S", self->device)); + ("Failed to open device %S", self->device_strid)); goto beach; } diff --git a/sys/wasapi/gstwasapisrc.h b/sys/wasapi/gstwasapisrc.h index 88be532f28..95087bd262 100644 --- a/sys/wasapi/gstwasapisrc.h +++ b/sys/wasapi/gstwasapisrc.h @@ -59,7 +59,7 @@ struct _GstWasapiSrc /* properties */ gint role; - wchar_t *device; + wchar_t *device_strid; }; struct _GstWasapiSrcClass