summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2014-07-05 01:35:00 +0200
committerMichal Ratajsky <[email protected]>2014-07-05 01:35:00 +0200
commit85070f3b97a3213d75a7bebf86ad973aaa21c55b (patch)
treefa3a29c788acd6233ca7a201ee9aaebffafa7d4c /backends
parent4793cbd87fed50678215b5dc1ba8e708fd4c9b58 (diff)
downloadlibmatemixer-85070f3b97a3213d75a7bebf86ad973aaa21c55b.tar.bz2
libmatemixer-85070f3b97a3213d75a7bebf86ad973aaa21c55b.tar.xz
Add ability to set monitor name and fix a few problems
Diffstat (limited to 'backends')
-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
5 files changed, 89 insertions, 11 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)
{