summaryrefslogtreecommitdiff
path: root/backends/pulse/pulse-source.c
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2016-01-09 22:50:44 +0100
committerraveit65 <[email protected]>2017-02-21 11:55:59 +0100
commitffbaee33908adccfe1afb1d7d6c0fcb79fbca6ca (patch)
treec87c3fbe28ab588cddb5c7b46cc056ff21ac15e4 /backends/pulse/pulse-source.c
parent9cbe39ab7c55bcad401de32716c5c8106f166291 (diff)
downloadlibmatemixer-wip.tar.bz2
libmatemixer-wip.tar.xz
pulse: Handle moving of sink inputs and source outputswip
Diffstat (limited to 'backends/pulse/pulse-source.c')
-rw-r--r--backends/pulse/pulse-source.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/backends/pulse/pulse-source.c b/backends/pulse/pulse-source.c
index 1c4e01a..fdc3e4c 100644
--- a/backends/pulse/pulse-source.c
+++ b/backends/pulse/pulse-source.c
@@ -178,7 +178,53 @@ pulse_source_new (PulseConnection *connection,
}
gboolean
-pulse_source_add_output (PulseSource *source, const pa_source_output_info *info)
+pulse_source_add_output (PulseSource *source,
+ PulseSourceOutput *output,
+ const pa_source_output_info *info)
+{
+ guint32 index;
+ gboolean ret;
+
+ g_return_val_if_fail (PULSE_IS_SOURCE (source), FALSE);
+ g_return_val_if_fail (PULSE_IS_SOURCE_OUTPUT (output), FALSE);
+
+ index = pulse_stream_control_get_index (PULSE_STREAM_CONTROL (output));
+
+ /* The input might get replaced here, but that is not a problem as PulseAudio
+ * does not reuse indices */
+ ret = g_hash_table_insert (source->priv->outputs,
+ GUINT_TO_POINTER (index),
+ g_object_ref (output));
+ if (ret == TRUE) {
+ /* Allows NULL info */
+ pulse_source_output_update (output, info, source);
+
+ _mate_mixer_clear_object_list (&source->priv->outputs_list);
+
+ g_signal_emit_by_name (G_OBJECT (source),
+ "control-added",
+ MATE_MIXER_STREAM_CONTROL (output));
+ return TRUE;
+ }
+
+ g_debug ("Pulse source output %s already exists in source %s",
+ mate_mixer_stream_control_get_name (MATE_MIXER_STREAM_CONTROL (output)),
+ mate_mixer_stream_get_name (MATE_MIXER_STREAM (source)));
+
+ return FALSE;
+}
+
+PulseSourceOutput *
+pulse_source_get_output (PulseSource *source, guint32 index)
+{
+ g_return_val_if_fail (PULSE_IS_SOURCE (source), FALSE);
+ g_return_val_if_fail (index != PA_INVALID_INDEX, FALSE);
+
+ return g_hash_table_lookup (source->priv->outputs, GUINT_TO_POINTER (index));
+}
+
+gboolean
+pulse_source_read_output (PulseSource *source, const pa_source_output_info *info)
{
PulseSourceOutput *output;
@@ -189,24 +235,21 @@ pulse_source_add_output (PulseSource *source, const pa_source_output_info *info)
output = g_hash_table_lookup (source->priv->outputs, GUINT_TO_POINTER (info->index));
if (output == NULL) {
PulseConnection *connection;
+ gboolean ret;
connection = pulse_stream_get_connection (PULSE_STREAM (source));
output = pulse_source_output_new (connection,
info,
source);
- g_hash_table_insert (source->priv->outputs,
- GUINT_TO_POINTER (info->index),
- output);
- _mate_mixer_clear_object_list (&source->priv->outputs_list);
+ /* Pass NULL info as there is no need to re-read the output values */
+ ret = pulse_source_add_output (source, output, NULL);
- g_signal_emit_by_name (G_OBJECT (source),
- "control-added",
- MATE_MIXER_STREAM_CONTROL (output));
- return TRUE;
+ g_object_unref (output);
+ return ret; /* Returns TRUE when added */
}
- pulse_source_output_update (output, info);
+ pulse_source_output_update (output, info, source);
return FALSE;
}
@@ -216,6 +259,7 @@ pulse_source_remove_output (PulseSource *source, guint32 index)
PulseSourceOutput *output;
g_return_if_fail (PULSE_IS_SOURCE (source));
+ g_return_if_fail (index != PA_INVALID_INDEX);
output = g_hash_table_lookup (source->priv->outputs, GUINT_TO_POINTER (index));
if G_UNLIKELY (output == NULL)