diff options
author | Michal Ratajsky <[email protected]> | 2014-06-07 01:07:02 +0200 |
---|---|---|
committer | Michal Ratajsky <[email protected]> | 2014-06-07 01:07:02 +0200 |
commit | d2c3a4be634018a2b63f4c80a26f9024a0d3de47 (patch) | |
tree | f0f8128aa2e914de6c1449bf5ef999dfebbc9767 /backends/pulse/pulse-device.c | |
parent | 9b4cafb0b47c6ec453d301bd812ae7001955dc2a (diff) | |
download | libmatemixer-d2c3a4be634018a2b63f4c80a26f9024a0d3de47.tar.bz2 libmatemixer-d2c3a4be634018a2b63f4c80a26f9024a0d3de47.tar.xz |
Weekly update
Diffstat (limited to 'backends/pulse/pulse-device.c')
-rw-r--r-- | backends/pulse/pulse-device.c | 251 |
1 files changed, 164 insertions, 87 deletions
diff --git a/backends/pulse/pulse-device.c b/backends/pulse/pulse-device.c index dbc287c..a411d7f 100644 --- a/backends/pulse/pulse-device.c +++ b/backends/pulse/pulse-device.c @@ -19,30 +19,31 @@ #include <glib-object.h> #include <libmatemixer/matemixer-device.h> -#include <libmatemixer/matemixer-device-port.h> -#include <libmatemixer/matemixer-device-profile.h> +#include <libmatemixer/matemixer-port.h> +#include <libmatemixer/matemixer-profile.h> #include <pulse/pulseaudio.h> +#include "pulse-connection.h" #include "pulse-device.h" struct _MateMixerPulseDevicePrivate { - guint32 index; - GList *profiles; - GList *ports; - gchar *identifier; - gchar *name; - gchar *icon; - - MateMixerDeviceProfile *active_profile; + guint32 index; + gchar *name; + gchar *description; + GList *profiles; + GList *ports; + gchar *icon; + MateMixerProfile *profile; + MateMixerPulseConnection *connection; }; enum { PROP_0, - PROP_IDENTIFIER, PROP_NAME, + PROP_DESCRIPTION, PROP_ICON, PROP_ACTIVE_PROFILE, N_PROPERTIES @@ -57,9 +58,12 @@ G_DEFINE_TYPE_WITH_CODE (MateMixerPulseDevice, mate_mixer_pulse_device, G_TYPE_O static void mate_mixer_device_interface_init (MateMixerDeviceInterface *iface) { - iface->list_tracks = mate_mixer_pulse_device_list_tracks; - iface->get_ports = mate_mixer_pulse_device_get_ports; - iface->get_profiles = mate_mixer_pulse_device_get_profiles; + iface->get_name = mate_mixer_pulse_device_get_name; + iface->get_description = mate_mixer_pulse_device_get_description; + iface->get_icon = mate_mixer_pulse_device_get_icon; + iface->list_streams = mate_mixer_pulse_device_list_streams; + iface->list_ports = mate_mixer_pulse_device_list_ports; + iface->list_profiles = mate_mixer_pulse_device_list_profiles; iface->get_active_profile = mate_mixer_pulse_device_get_active_profile; iface->set_active_profile = mate_mixer_pulse_device_set_active_profile; } @@ -67,10 +71,9 @@ mate_mixer_device_interface_init (MateMixerDeviceInterface *iface) static void mate_mixer_pulse_device_init (MateMixerPulseDevice *device) { - device->priv = G_TYPE_INSTANCE_GET_PRIVATE ( - device, - MATE_MIXER_TYPE_PULSE_DEVICE, - MateMixerPulseDevicePrivate); + device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device, + MATE_MIXER_TYPE_PULSE_DEVICE, + MateMixerPulseDevicePrivate); } static void @@ -84,17 +87,17 @@ mate_mixer_pulse_device_get_property (GObject *object, device = MATE_MIXER_PULSE_DEVICE (object); switch (param_id) { - case PROP_IDENTIFIER: - g_value_set_string (value, device->priv->identifier); - break; case PROP_NAME: g_value_set_string (value, device->priv->name); break; + case PROP_DESCRIPTION: + g_value_set_string (value, device->priv->description); + break; case PROP_ICON: g_value_set_string (value, device->priv->icon); break; case PROP_ACTIVE_PROFILE: - g_value_set_object (value, device->priv->active_profile); + g_value_set_object (value, device->priv->profile); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -113,20 +116,15 @@ mate_mixer_pulse_device_set_property (GObject *object, device = MATE_MIXER_PULSE_DEVICE (object); switch (param_id) { - case PROP_IDENTIFIER: - device->priv->identifier = g_strdup (g_value_get_string (value)); - break; case PROP_NAME: device->priv->name = g_strdup (g_value_get_string (value)); break; + case PROP_DESCRIPTION: + device->priv->description = g_strdup (g_value_get_string (value)); + break; case PROP_ICON: device->priv->icon = g_strdup (g_value_get_string (value)); break; - case PROP_ACTIVE_PROFILE: - mate_mixer_pulse_device_set_active_profile ( - MATE_MIXER_DEVICE (device), - g_value_get_object (value)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -134,24 +132,38 @@ mate_mixer_pulse_device_set_property (GObject *object, } static void -mate_mixer_pulse_device_finalize (GObject *object) +mate_mixer_pulse_device_dispose (GObject *object) { MateMixerPulseDevice *device; device = MATE_MIXER_PULSE_DEVICE (object); - g_free (device->priv->identifier); - g_free (device->priv->name); - g_free (device->priv->icon); - - if (device->priv->profiles != NULL) + if (device->priv->profiles != NULL) { g_list_free_full (device->priv->profiles, g_object_unref); + device->priv->profiles = NULL; + } - if (device->priv->ports != NULL) + if (device->priv->ports != NULL) { g_list_free_full (device->priv->ports, g_object_unref); + device->priv->ports = NULL; + } + + g_clear_object (&device->priv->profile); + g_clear_object (&device->priv->connection); + + G_OBJECT_CLASS (mate_mixer_pulse_device_parent_class)->dispose (object); +} + +static void +mate_mixer_pulse_device_finalize (GObject *object) +{ + MateMixerPulseDevice *device; - if (device->priv->active_profile != NULL) - g_object_unref (device->priv->active_profile); + device = MATE_MIXER_PULSE_DEVICE (object); + + g_free (device->priv->name); + g_free (device->priv->description); + g_free (device->priv->icon); G_OBJECT_CLASS (mate_mixer_pulse_device_parent_class)->finalize (object); } @@ -162,12 +174,13 @@ mate_mixer_pulse_device_class_init (MateMixerPulseDeviceClass *klass) GObjectClass *object_class; object_class = G_OBJECT_CLASS (klass); + object_class->dispose = mate_mixer_pulse_device_dispose; object_class->finalize = mate_mixer_pulse_device_finalize; object_class->get_property = mate_mixer_pulse_device_get_property; object_class->set_property = mate_mixer_pulse_device_set_property; - g_object_class_override_property (object_class, PROP_IDENTIFIER, "identifier"); g_object_class_override_property (object_class, PROP_NAME, "name"); + g_object_class_override_property (object_class, PROP_DESCRIPTION, "description"); g_object_class_override_property (object_class, PROP_ICON, "icon"); g_object_class_override_property (object_class, PROP_ACTIVE_PROFILE, "active-profile"); @@ -175,19 +188,19 @@ mate_mixer_pulse_device_class_init (MateMixerPulseDeviceClass *klass) } MateMixerPulseDevice * -mate_mixer_pulse_device_new (const pa_card_info *info) +mate_mixer_pulse_device_new (MateMixerPulseConnection *connection, const pa_card_info *info) { - MateMixerPulseDevice *device; - MateMixerDeviceProfile *active_profile = NULL; - GList *profiles = NULL; - GList *ports = NULL; - guint32 i; + MateMixerPulseDevice *device; + MateMixerProfile *active_profile = NULL; + GList *profiles = NULL; + GList *ports = NULL; + guint32 i; g_return_val_if_fail (info != NULL, NULL); /* Create a list of card profiles */ for (i = 0; i < info->n_profiles; i++) { - MateMixerDeviceProfile *profile; + MateMixerProfile *profile; #if PA_CHECK_VERSION(5, 0, 0) pa_card_profile_info2 *p_info = info->profiles2[i]; @@ -199,9 +212,9 @@ mate_mixer_pulse_device_new (const pa_card_info *info) continue; #else /* The old profile list is an array of structs, not pointers */ - pa_card_profile_info *p_info = &info->profiles[i]; + pa_card_profile_info *p_info = &info->profiles[i]; #endif - profile = mate_mixer_device_profile_new ( + profile = mate_mixer_profile_new ( p_info->name, p_info->description, p_info->priority); @@ -222,28 +235,27 @@ mate_mixer_pulse_device_new (const pa_card_info *info) /* Create a list of card ports */ for (i = 0; i < info->n_ports; i++) { - MateMixerDevicePort *port; - MateMixerDevicePortDirection direction = 0; - MateMixerDevicePortStatus status = 0; - pa_card_port_info *p_info = info->ports[i]; - - if (p_info->direction & PA_DIRECTION_INPUT) - direction |= MATE_MIXER_DEVICE_PORT_DIRECTION_INPUT; - - if (p_info->direction & PA_DIRECTION_OUTPUT) - direction |= MATE_MIXER_DEVICE_PORT_DIRECTION_OUTPUT; + MateMixerPort *port; + MateMixerPortStatus status = MATE_MIXER_PORT_UNKNOWN_STATUS; + pa_card_port_info *p_info = info->ports[i]; #if PA_CHECK_VERSION(2, 0, 0) - if (p_info->available == PA_PORT_AVAILABLE_YES) - status |= MATE_MIXER_DEVICE_PORT_STATUS_AVAILABLE; + switch (p_info->available) { + case PA_PORT_AVAILABLE_YES: + status = MATE_MIXER_PORT_AVAILABLE; + break; + case PA_PORT_AVAILABLE_NO: + status = MATE_MIXER_PORT_UNAVAILABLE; + break; + default: + break; + } #endif - port = mate_mixer_device_port_new ( - p_info->name, - p_info->description, - pa_proplist_gets (p_info->proplist, "device.icon_name"), - p_info->priority, - direction, - status); + port = mate_mixer_port_new (p_info->name, + p_info->description, + pa_proplist_gets (p_info->proplist, "device.icon_name"), + p_info->priority, + status); ports = g_list_prepend (ports, port); } @@ -253,15 +265,21 @@ mate_mixer_pulse_device_new (const pa_card_info *info) ports = g_list_reverse (ports); device = g_object_new (MATE_MIXER_TYPE_PULSE_DEVICE, - "identifier", info->name, - "name", pa_proplist_gets (info->proplist, "device.description"), - "icon", pa_proplist_gets (info->proplist, "device.icon_name"), - "active-profile", active_profile, - NULL); + "name", info->name, + "description", pa_proplist_gets (info->proplist, "device.description"), + "icon", pa_proplist_gets (info->proplist, "device.icon_name"), + NULL); + + if (profiles) { + device->priv->profiles = profiles; + + if (G_LIKELY (active_profile)) + device->priv->profile = g_object_ref (active_profile); + } device->priv->index = info->index; - device->priv->profiles = profiles; device->priv->ports = ports; + device->priv->connection = g_object_ref (connection); return device; } @@ -276,45 +294,104 @@ mate_mixer_pulse_device_update (MateMixerPulseDevice *device, const pa_card_info return TRUE; } +MateMixerPulseConnection * +mate_mixer_pulse_device_get_connection (MateMixerPulseDevice *device) +{ + g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), NULL); + + return device->priv->connection; +} + +guint32 +mate_mixer_pulse_device_get_index (MateMixerPulseDevice *device) +{ + g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), 0); + + return device->priv->index; +} + +const gchar * +mate_mixer_pulse_device_get_name (MateMixerDevice *device) +{ + g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), NULL); + + return MATE_MIXER_PULSE_DEVICE (device)->priv->name; +} + +const gchar * +mate_mixer_pulse_device_get_description (MateMixerDevice *device) +{ + g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), NULL); + + return MATE_MIXER_PULSE_DEVICE (device)->priv->description; +} + +const gchar * +mate_mixer_pulse_device_get_icon (MateMixerDevice *device) +{ + g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), NULL); + + return MATE_MIXER_PULSE_DEVICE (device)->priv->icon; +} + const GList * -mate_mixer_pulse_device_list_tracks (MateMixerDevice *device) +mate_mixer_pulse_device_list_streams (MateMixerDevice *device) { // TODO return NULL; } const GList * -mate_mixer_pulse_device_get_ports (MateMixerDevice *device) +mate_mixer_pulse_device_list_ports (MateMixerDevice *device) { g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), NULL); - return MATE_MIXER_PULSE_DEVICE (device)->priv->ports; + return (const GList *) MATE_MIXER_PULSE_DEVICE (device)->priv->ports; } const GList * -mate_mixer_pulse_device_get_profiles (MateMixerDevice *device) +mate_mixer_pulse_device_list_profiles (MateMixerDevice *device) { g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), NULL); - return MATE_MIXER_PULSE_DEVICE (device)->priv->profiles; + return (const GList *) MATE_MIXER_PULSE_DEVICE (device)->priv->profiles; } -MateMixerDeviceProfile * +MateMixerProfile * mate_mixer_pulse_device_get_active_profile (MateMixerDevice *device) { g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), NULL); - return MATE_MIXER_PULSE_DEVICE (device)->priv->active_profile; + return MATE_MIXER_PULSE_DEVICE (device)->priv->profile; } gboolean -mate_mixer_pulse_device_set_active_profile (MateMixerDevice *device, - MateMixerDeviceProfile *profile) +mate_mixer_pulse_device_set_active_profile (MateMixerDevice *device, const gchar *name) { + gboolean ret; + MateMixerPulseDevicePrivate *priv; + g_return_val_if_fail (MATE_MIXER_IS_PULSE_DEVICE (device), FALSE); - g_return_val_if_fail (MATE_MIXER_IS_DEVICE_PROFILE (profile), FALSE); + g_return_val_if_fail (name != NULL, FALSE); - // TODO - // pa_context_set_card_profile_by_index () - return TRUE; + priv = MATE_MIXER_PULSE_DEVICE (device)->priv; + ret = mate_mixer_pulse_connection_set_card_profile (priv->connection, + priv->name, + name); + + // XXX decide to either confirm the change during the connection call or + // wait for a notification from Pulse +/* + if (ret) { + if (priv->profile) + g_object_unref (priv->profile); + + priv->profile = g_object_ref (profile); + + g_object_notify_by_pspec ( + G_OBJECT (device), + properties[PROP_ACTIVE_PROFILE]); + } +*/ + return ret; } |