summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/pulse/pulse-backend.c19
-rw-r--r--backends/pulse/pulse-connection.c3
-rw-r--r--backends/pulse/pulse-monitor.c42
-rw-r--r--backends/pulse/pulse-monitor.h4
-rw-r--r--backends/pulse/pulse-stream.c32
-rw-r--r--docs/reference/libmatemixer-sections.txt1
-rw-r--r--libmatemixer/matemixer-control.c156
-rw-r--r--libmatemixer/matemixer-stream.c15
-rw-r--r--libmatemixer/matemixer-stream.h4
9 files changed, 203 insertions, 73 deletions
diff --git a/backends/pulse/pulse-backend.c b/backends/pulse/pulse-backend.c
index 1794018..da73396 100644
--- a/backends/pulse/pulse-backend.c
+++ b/backends/pulse/pulse-backend.c
@@ -529,8 +529,12 @@ backend_set_default_input_stream (MateMixerBackend *backend, MateMixerStream *st
return FALSE;
}
- return pulse_connection_set_default_source (pulse->priv->connection,
- mate_mixer_stream_get_name (stream));
+ if (!pulse_connection_set_default_source (pulse->priv->connection,
+ mate_mixer_stream_get_name (stream)))
+ return FALSE;
+
+ g_object_notify (G_OBJECT (pulse), "default-input");
+ return TRUE;
}
static MateMixerStream *
@@ -556,8 +560,12 @@ backend_set_default_output_stream (MateMixerBackend *backend, MateMixerStream *s
return FALSE;
}
- return pulse_connection_set_default_sink (pulse->priv->connection,
- mate_mixer_stream_get_name (stream));
+ if (!pulse_connection_set_default_sink (pulse->priv->connection,
+ mate_mixer_stream_get_name (stream)))
+ return FALSE;
+
+ g_object_notify (G_OBJECT (pulse), "default-output");
+ return TRUE;
}
static void
@@ -626,6 +634,9 @@ backend_server_info_cb (PulseConnection *connection,
if (pulse->priv->default_source != NULL)
name_source = mate_mixer_stream_get_name (pulse->priv->default_source);
+ // XXX
+ // default input might be monitor !!!
+
if (g_strcmp0 (name_source, info->default_source_name)) {
if (pulse->priv->default_source != NULL)
g_clear_object (&pulse->priv->default_source);
diff --git a/backends/pulse/pulse-connection.c b/backends/pulse/pulse-connection.c
index 184047f..9002f09 100644
--- a/backends/pulse/pulse-connection.c
+++ b/backends/pulse/pulse-connection.c
@@ -486,6 +486,9 @@ pulse_connection_create_monitor (PulseConnection *connection,
index_sink_input);
}
+// XXX watch for some operation failures and eventually reload data
+// to restore the previous state
+
gboolean
pulse_connection_set_default_sink (PulseConnection *connection,
const gchar *name)
diff --git a/backends/pulse/pulse-monitor.c b/backends/pulse/pulse-monitor.c
index 4b83368..041f903 100644
--- a/backends/pulse/pulse-monitor.c
+++ b/backends/pulse/pulse-monitor.c
@@ -27,6 +27,7 @@ struct _PulseMonitorPrivate
pa_context *context;
pa_proplist *proplist;
pa_stream *stream;
+ gchar *name;
guint32 index_source;
guint32 index_sink_input;
gboolean enabled;
@@ -143,6 +144,11 @@ pulse_monitor_disable (PulseMonitor *monitor)
pa_stream_disconnect (monitor->priv->stream);
+ // XXX stream must be destroyed on disable, re-enabling does not work, this
+ // is just a quick temporary solution
+ pa_stream_unref (monitor->priv->stream);
+ monitor->priv->stream = NULL;
+
monitor->priv->enabled = FALSE;
}
@@ -182,17 +188,43 @@ pulse_monitor_update_index (PulseMonitor *monitor,
return TRUE;
}
+const gchar *
+pulse_monitor_get_name (PulseMonitor *monitor)
+{
+ g_return_val_if_fail (PULSE_IS_MONITOR (monitor), NULL);
+
+ return monitor->priv->name;
+}
+
+gboolean
+pulse_monitor_set_name (PulseMonitor *monitor, const gchar *name)
+{
+ g_return_val_if_fail (PULSE_IS_MONITOR (monitor), FALSE);
+
+ g_free (monitor->priv->name);
+
+ monitor->priv->name = g_strdup (name);
+ return TRUE;
+}
+
static gboolean
monitor_prepare (PulseMonitor *monitor)
{
- pa_sample_spec spec;
+ pa_sample_spec spec;
+ const gchar *name;
+
+ spec.channels = 1;
+ spec.format = PA_SAMPLE_FLOAT32;
+ spec.rate = 25;
- spec.channels = 1;
- spec.format = PA_SAMPLE_FLOAT32;
- spec.rate = 25;
+ if (monitor->priv->name != NULL)
+ name = monitor->priv->name;
+ else
+ name = "Peak detect";
monitor->priv->stream =
- pa_stream_new_with_proplist (monitor->priv->context, "Peak detect",
+ pa_stream_new_with_proplist (monitor->priv->context,
+ name,
&spec,
NULL,
monitor->priv->proplist);
diff --git a/backends/pulse/pulse-monitor.h b/backends/pulse/pulse-monitor.h
index d82d5cf..b3f6f89 100644
--- a/backends/pulse/pulse-monitor.h
+++ b/backends/pulse/pulse-monitor.h
@@ -70,6 +70,10 @@ gboolean pulse_monitor_enable (PulseMonitor *monitor);
void pulse_monitor_disable (PulseMonitor *monitor);
gboolean pulse_monitor_is_enabled (PulseMonitor *monitor);
+const gchar * pulse_monitor_get_name (PulseMonitor *monitor);
+gboolean pulse_monitor_set_name (PulseMonitor *monitor,
+ const gchar *name);
+
gboolean pulse_monitor_update_index (PulseMonitor *monitor,
guint32 index_source,
guint32 index_sink_input);
diff --git a/backends/pulse/pulse-stream.c b/backends/pulse/pulse-stream.c
index ec3939f..c7ac52a 100644
--- a/backends/pulse/pulse-stream.c
+++ b/backends/pulse/pulse-stream.c
@@ -56,6 +56,7 @@ struct _PulseStreamPrivate
MateMixerPort *port;
PulseConnection *connection;
PulseMonitor *monitor;
+ gchar *monitor_name;
};
enum {
@@ -139,6 +140,8 @@ static gboolean stream_resume (MateMixerStream
static gboolean stream_monitor_start (MateMixerStream *stream);
static void stream_monitor_stop (MateMixerStream *stream);
static gboolean stream_monitor_is_running (MateMixerStream *stream);
+static gboolean stream_monitor_set_name (MateMixerStream *stream,
+ const gchar *name);
static void stream_monitor_value (PulseMonitor *monitor,
gdouble value,
MateMixerStream *stream);
@@ -192,6 +195,7 @@ mate_mixer_stream_interface_init (MateMixerStreamInterface *iface)
iface->monitor_start = stream_monitor_start;
iface->monitor_stop = stream_monitor_stop;
iface->monitor_is_running = stream_monitor_is_running;
+ iface->monitor_set_name = stream_monitor_set_name;
iface->list_ports = stream_list_ports;
iface->get_active_port = stream_get_active_port;
iface->set_active_port = stream_set_active_port;
@@ -942,7 +946,6 @@ stream_resume (MateMixerStream *stream)
return PULSE_STREAM_GET_CLASS (stream)->resume (stream);
}
-// XXX allow to provide custom translated monitor name
static gboolean
stream_monitor_start (MateMixerStream *stream)
{
@@ -958,11 +961,16 @@ stream_monitor_start (MateMixerStream *stream)
if (G_UNLIKELY (pulse->priv->monitor == NULL))
return FALSE;
+ pulse_monitor_set_name (pulse->priv->monitor,
+ pulse->priv->monitor_name);
+
g_signal_connect (G_OBJECT (pulse->priv->monitor),
"value",
G_CALLBACK (stream_monitor_value),
stream);
}
+ g_debug ("Enabling monitor for stream %s", pulse->priv->name);
+
return pulse_monitor_enable (pulse->priv->monitor);
}
@@ -975,8 +983,12 @@ stream_monitor_stop (MateMixerStream *stream)
pulse = PULSE_STREAM (stream);
- if (pulse->priv->monitor)
+ if (pulse->priv->monitor &&
+ pulse_monitor_is_enabled (pulse->priv->monitor)) {
+ g_debug ("Disabling monitor for stream %s", pulse->priv->name);
+
pulse_monitor_disable (pulse->priv->monitor);
+ }
}
static gboolean
@@ -994,6 +1006,22 @@ stream_monitor_is_running (MateMixerStream *stream)
return FALSE;
}
+static gboolean
+stream_monitor_set_name (MateMixerStream *stream, const gchar *name)
+{
+ PulseStream *pulse;
+
+ g_return_val_if_fail (PULSE_IS_STREAM (stream), FALSE);
+
+ pulse = PULSE_STREAM (stream);
+
+ if (pulse->priv->monitor)
+ pulse_monitor_set_name (pulse->priv->monitor, name);
+
+ pulse->priv->monitor_name = g_strdup (name);
+ return TRUE;
+}
+
static void
stream_monitor_value (PulseMonitor *monitor, gdouble value, MateMixerStream *stream)
{
diff --git a/docs/reference/libmatemixer-sections.txt b/docs/reference/libmatemixer-sections.txt
index dd2d1ce..b719470 100644
--- a/docs/reference/libmatemixer-sections.txt
+++ b/docs/reference/libmatemixer-sections.txt
@@ -172,6 +172,7 @@ mate_mixer_stream_resume
mate_mixer_stream_monitor_start
mate_mixer_stream_monitor_stop
mate_mixer_stream_monitor_is_running
+mate_mixer_stream_monitor_set_name
mate_mixer_stream_list_ports
mate_mixer_stream_get_active_port
mate_mixer_stream_set_active_port
diff --git a/libmatemixer/matemixer-control.c b/libmatemixer/matemixer-control.c
index 06b938a..6aac624 100644
--- a/libmatemixer/matemixer-control.c
+++ b/libmatemixer/matemixer-control.c
@@ -90,40 +90,47 @@ static void mate_mixer_control_finalize (GObject *object);
G_DEFINE_TYPE (MateMixerControl, mate_mixer_control, G_TYPE_OBJECT);
-static void control_state_changed_cb (MateMixerBackend *backend,
- GParamSpec *pspec,
- MateMixerControl *control);
-
-static void control_device_added_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control);
-static void control_device_changed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control);
-static void control_device_removed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control);
-
-static void control_stream_added_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control);
-static void control_stream_changed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control);
-static void control_stream_removed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control);
-
-static gboolean control_try_next_backend (MateMixerControl *control);
-
-static void control_change_state (MateMixerControl *control,
- MateMixerState state);
-
-static void control_close (MateMixerControl *control);
-
-static void control_free_backend (MateMixerControl *control);
-static void control_free_devices (MateMixerControl *control);
-static void control_free_streams (MateMixerControl *control);
+static void control_backend_state_cb (MateMixerBackend *backend,
+ GParamSpec *pspec,
+ MateMixerControl *control);
+
+static void control_backend_device_added_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control);
+static void control_backend_device_changed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control);
+static void control_backend_device_removed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control);
+
+static void control_backend_stream_added_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control);
+static void control_backend_stream_changed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control);
+static void control_backend_stream_removed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control);
+
+static void control_backend_default_input_cb (MateMixerBackend *backend,
+ GParamSpec *pspec,
+ MateMixerControl *control);
+static void control_backend_default_output_cb (MateMixerBackend *backend,
+ GParamSpec *pspec,
+ MateMixerControl *control);
+
+static gboolean control_try_next_backend (MateMixerControl *control);
+
+static void control_change_state (MateMixerControl *control,
+ MateMixerState state);
+
+static void control_close (MateMixerControl *control);
+
+static void control_free_backend (MateMixerControl *control);
+static void control_free_devices (MateMixerControl *control);
+static void control_free_streams (MateMixerControl *control);
static void
mate_mixer_control_class_init (MateMixerControlClass *klass)
@@ -773,7 +780,7 @@ mate_mixer_control_open (MateMixerControl *control)
g_signal_connect (control->priv->backend,
"notify::state",
- G_CALLBACK (control_state_changed_cb),
+ G_CALLBACK (control_backend_state_cb),
control);
control_change_state (control, state);
@@ -1033,7 +1040,7 @@ mate_mixer_control_set_default_output_stream (MateMixerControl *control,
return FALSE;
}
- return mate_mixer_backend_set_default_input_stream (control->priv->backend, stream);
+ return mate_mixer_backend_set_default_output_stream (control->priv->backend, stream);
}
/**
@@ -1077,7 +1084,7 @@ mate_mixer_control_get_backend_type (MateMixerControl *control)
}
static void
-control_state_changed_cb (MateMixerBackend *backend,
+control_backend_state_cb (MateMixerBackend *backend,
GParamSpec *pspec,
MateMixerControl *control)
{
@@ -1123,9 +1130,9 @@ control_state_changed_cb (MateMixerBackend *backend,
}
static void
-control_device_added_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control)
+control_backend_device_added_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control)
{
control_free_devices (control);
@@ -1136,9 +1143,9 @@ control_device_added_cb (MateMixerBackend *backend,
}
static void
-control_device_changed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control)
+control_backend_device_changed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control)
{
g_signal_emit (G_OBJECT (control),
signals[DEVICE_CHANGED],
@@ -1147,9 +1154,9 @@ control_device_changed_cb (MateMixerBackend *backend,
}
static void
-control_device_removed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control)
+control_backend_device_removed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control)
{
control_free_devices (control);
@@ -1160,9 +1167,9 @@ control_device_removed_cb (MateMixerBackend *backend,
}
static void
-control_stream_added_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control)
+control_backend_stream_added_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control)
{
control_free_streams (control);
@@ -1173,9 +1180,9 @@ control_stream_added_cb (MateMixerBackend *backend,
}
static void
-control_stream_changed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control)
+control_backend_stream_changed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control)
{
g_signal_emit (G_OBJECT (control),
signals[STREAM_CHANGED],
@@ -1184,9 +1191,9 @@ control_stream_changed_cb (MateMixerBackend *backend,
}
static void
-control_stream_removed_cb (MateMixerBackend *backend,
- const gchar *name,
- MateMixerControl *control)
+control_backend_stream_removed_cb (MateMixerBackend *backend,
+ const gchar *name,
+ MateMixerControl *control)
{
control_free_streams (control);
@@ -1196,6 +1203,22 @@ control_stream_removed_cb (MateMixerBackend *backend,
name);
}
+static void
+control_backend_default_input_cb (MateMixerBackend *backend,
+ GParamSpec *pspec,
+ MateMixerControl *control)
+{
+ g_object_notify_by_pspec (G_OBJECT (control), properties[PROP_DEFAULT_INPUT]);
+}
+
+static void
+control_backend_default_output_cb (MateMixerBackend *backend,
+ GParamSpec *pspec,
+ MateMixerControl *control)
+{
+ g_object_notify_by_pspec (G_OBJECT (control), properties[PROP_DEFAULT_OUTPUT]);
+}
+
static gboolean
control_try_next_backend (MateMixerControl *control)
{
@@ -1246,7 +1269,7 @@ control_try_next_backend (MateMixerControl *control)
g_signal_connect (control->priv->backend,
"notify::state",
- G_CALLBACK (control_state_changed_cb),
+ G_CALLBACK (control_backend_state_cb),
control);
control_change_state (control, state);
@@ -1268,27 +1291,36 @@ control_change_state (MateMixerControl *control, MateMixerState state)
* then missing a notification about a change in the list */
g_signal_connect (control->priv->backend,
"device-added",
- G_CALLBACK (control_device_added_cb),
+ G_CALLBACK (control_backend_device_added_cb),
control);
g_signal_connect (control->priv->backend,
"device-changed",
- G_CALLBACK (control_device_changed_cb),
+ G_CALLBACK (control_backend_device_changed_cb),
control);
g_signal_connect (control->priv->backend,
"device-removed",
- G_CALLBACK (control_device_removed_cb),
+ G_CALLBACK (control_backend_device_removed_cb),
control);
g_signal_connect (control->priv->backend,
"stream-added",
- G_CALLBACK (control_stream_added_cb),
+ G_CALLBACK (control_backend_stream_added_cb),
control);
g_signal_connect (control->priv->backend,
"stream-changed",
- G_CALLBACK (control_stream_changed_cb),
+ G_CALLBACK (control_backend_stream_changed_cb),
control);
g_signal_connect (control->priv->backend,
"stream-removed",
- G_CALLBACK (control_stream_removed_cb),
+ G_CALLBACK (control_backend_stream_removed_cb),
+ control);
+
+ g_signal_connect (control->priv->backend,
+ "notify::default-input",
+ G_CALLBACK (control_backend_default_input_cb),
+ control);
+ g_signal_connect (control->priv->backend,
+ "notify::default-output",
+ G_CALLBACK (control_backend_default_output_cb),
control);
control->priv->backend_chosen = TRUE;
diff --git a/libmatemixer/matemixer-stream.c b/libmatemixer/matemixer-stream.c
index b4da26f..6f63217 100644
--- a/libmatemixer/matemixer-stream.c
+++ b/libmatemixer/matemixer-stream.c
@@ -624,6 +624,21 @@ mate_mixer_stream_monitor_is_running (MateMixerStream *stream)
return FALSE;
}
+gboolean
+mate_mixer_stream_monitor_set_name (MateMixerStream *stream, const gchar *name)
+{
+ MateMixerStreamInterface *iface;
+
+ g_return_val_if_fail (MATE_MIXER_IS_STREAM (stream), FALSE);
+
+ iface = MATE_MIXER_STREAM_GET_INTERFACE (stream);
+
+ if (iface->monitor_set_name)
+ return iface->monitor_set_name (stream, name);
+
+ return FALSE;
+}
+
const GList *
mate_mixer_stream_list_ports (MateMixerStream *stream)
{
diff --git a/libmatemixer/matemixer-stream.h b/libmatemixer/matemixer-stream.h
index 527c470..40a4463 100644
--- a/libmatemixer/matemixer-stream.h
+++ b/libmatemixer/matemixer-stream.h
@@ -101,6 +101,8 @@ struct _MateMixerStreamInterface
gboolean (*monitor_start) (MateMixerStream *stream);
void (*monitor_stop) (MateMixerStream *stream);
gboolean (*monitor_is_running) (MateMixerStream *stream);
+ gboolean (*monitor_set_name) (MateMixerStream *stream,
+ const gchar *name);
const GList * (*list_ports) (MateMixerStream *stream);
MateMixerPort * (*get_active_port) (MateMixerStream *stream);
gboolean (*set_active_port) (MateMixerStream *stream,
@@ -182,6 +184,8 @@ gboolean mate_mixer_stream_monitor_start (MateMixerStre
void mate_mixer_stream_monitor_stop (MateMixerStream *stream);
gboolean mate_mixer_stream_monitor_is_running (MateMixerStream *stream);
+gboolean mate_mixer_stream_monitor_set_name (MateMixerStream *stream,
+ const gchar *name);
const GList * mate_mixer_stream_list_ports (MateMixerStream *stream);