2 * empathy-gst-audio-src.c - Source for EmpathyGstAudioSrc
3 * Copyright (C) 2008 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <pulse/pulseaudio.h>
26 #include <pulse/glib-mainloop.h>
28 #include <libempathy/empathy-utils.h>
30 #include "empathy-audio-src.h"
32 #include "src-marshal.h"
34 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
35 #include <libempathy/empathy-debug.h>
37 G_DEFINE_TYPE(EmpathyGstAudioSrc, empathy_audio_src, GST_TYPE_BIN)
49 static guint signals[LAST_SIGNAL] = {0};
58 /* private structure */
59 typedef struct _EmpathyGstAudioSrcPrivate EmpathyGstAudioSrcPrivate;
61 struct _EmpathyGstAudioSrcPrivate
63 gboolean dispose_has_run;
68 pa_glib_mainloop *loop;
72 /* 0 if not known yet */
73 guint source_output_idx;
74 /* G_MAXUINT if not known yet */
84 #define EMPATHY_GST_AUDIO_SRC_GET_PRIVATE(o) \
85 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_GST_AUDIO_SRC, \
86 EmpathyGstAudioSrcPrivate))
89 empathy_audio_src_supports_changing_mic (EmpathyGstAudioSrc *self)
91 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
92 GObjectClass *object_class;
94 object_class = G_OBJECT_GET_CLASS (priv->src);
96 return (g_object_class_find_property (object_class,
97 "source-output-index") != NULL);
100 typedef void (*OperationFunc) (EmpathyGstAudioSrc *, GSimpleAsyncResult *);
105 GSimpleAsyncResult *result;
109 operation_new (OperationFunc func,
110 GSimpleAsyncResult *result)
112 Operation *o = g_slice_new0 (Operation);
121 operation_free (Operation *o,
126 g_simple_async_result_set_error (o->result,
127 G_IO_ERROR, G_IO_ERROR_CANCELLED,
128 "The audio source was disposed");
129 g_simple_async_result_complete (o->result);
130 g_object_unref (o->result);
133 g_slice_free (Operation, o);
137 operation_get_microphones_free (gpointer data)
139 GQueue *queue = data;
142 for (l = queue->head; l != NULL; l = l->next)
144 EmpathyAudioSrcMicrophone *mic = l->data;
147 g_free (mic->description);
148 g_slice_free (EmpathyAudioSrcMicrophone, mic);
151 g_queue_free (queue);
155 operation_get_microphones_cb (pa_context *context,
156 const pa_source_info *info,
160 GSimpleAsyncResult *result = userdata;
161 EmpathyAudioSrcMicrophone *mic;
166 g_simple_async_result_complete (result);
167 g_object_unref (result);
171 mic = g_slice_new0 (EmpathyAudioSrcMicrophone);
172 mic->index = info->index;
173 mic->name = g_strdup (info->name);
174 mic->description = g_strdup (info->description);
175 mic->is_monitor = (info->monitor_of_sink != PA_INVALID_INDEX);
177 /* add it to the queue */
178 queue = g_simple_async_result_get_op_res_gpointer (result);
179 g_queue_push_tail (queue, mic);
183 operation_get_microphones (EmpathyGstAudioSrc *self,
184 GSimpleAsyncResult *result)
186 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
188 g_assert_cmpuint (pa_context_get_state (priv->context), ==, PA_CONTEXT_READY);
190 g_simple_async_result_set_op_res_gpointer (result, g_queue_new (),
191 operation_get_microphones_free);
193 pa_context_get_source_info_list (priv->context,
194 operation_get_microphones_cb, result);
198 operation_change_microphone_cb (pa_context *context,
202 GSimpleAsyncResult *result = userdata;
206 g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_FAILED,
207 "Failed to change microphone. Reason unknown.");
210 g_simple_async_result_complete (result);
211 g_object_unref (result);
215 operation_change_microphone (EmpathyGstAudioSrc *self,
216 GSimpleAsyncResult *result)
218 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
219 guint source_output_idx, microphone;
221 g_object_get (priv->src, "source-output-index", &source_output_idx, NULL);
223 g_assert_cmpuint (pa_context_get_state (priv->context), ==, PA_CONTEXT_READY);
224 g_assert_cmpuint (source_output_idx, !=, PA_INVALID_INDEX);
226 microphone = GPOINTER_TO_UINT (
227 g_simple_async_result_get_op_res_gpointer (result));
229 pa_context_move_source_output_by_index (priv->context, source_output_idx, microphone,
230 operation_change_microphone_cb, result);
234 operations_run (EmpathyGstAudioSrc *self)
236 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
237 pa_context_state_t state = pa_context_get_state (priv->context);
240 if (state != PA_CONTEXT_READY)
243 for (l = priv->operations->head; l != NULL; l = l->next)
245 Operation *o = l->data;
247 o->func (self, o->result);
249 operation_free (o, FALSE);
252 g_queue_clear (priv->operations);
256 empathy_audio_src_source_output_info_cb (pa_context *context,
257 const pa_source_output_info *info,
261 EmpathyGstAudioSrc *self = userdata;
262 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
267 /* There should only be one call here. */
269 if (priv->source_idx == info->source)
272 priv->source_idx = info->source;
273 g_object_notify (G_OBJECT (self), "microphone");
277 empathy_audio_src_source_info_cb (pa_context *context,
278 const pa_source_info *info,
282 EmpathyGstAudioSrc *self = userdata;
288 is_monitor = (info->monitor_of_sink != PA_INVALID_INDEX);
290 g_signal_emit (self, signals[MICROPHONE_ADDED], 0,
291 info->index, info->name, info->description, is_monitor);
295 empathy_audio_src_pa_event_cb (pa_context *context,
296 pa_subscription_event_type_t type,
300 EmpathyGstAudioSrc *self = userdata;
301 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
303 if ((type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT
304 && (type & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE
305 && idx == priv->source_output_idx)
307 /* Microphone in the source output has changed */
308 pa_context_get_source_output_info (context, idx,
309 empathy_audio_src_source_output_info_cb, self);
311 else if ((type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SOURCE
312 && (type & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE)
314 /* A mic has been removed */
315 g_signal_emit (self, signals[MICROPHONE_REMOVED], 0, idx);
317 else if ((type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SOURCE
318 && (type & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW)
320 /* A mic has been plugged in */
321 pa_context_get_source_info_by_index (context, idx,
322 empathy_audio_src_source_info_cb, self);
327 empathy_audio_src_pa_subscribe_cb (pa_context *context,
332 DEBUG ("Failed to subscribe to PulseAudio events");
336 empathy_audio_src_pa_state_change_cb (pa_context *context,
339 EmpathyGstAudioSrc *self = userdata;
340 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
341 pa_context_state_t state = pa_context_get_state (priv->context);
343 if (state == PA_CONTEXT_READY)
345 /* Listen to pulseaudio events so we know when sources are
346 * added and when the microphone is changed. */
347 pa_context_set_subscribe_callback (priv->context,
348 empathy_audio_src_pa_event_cb, self);
349 pa_context_subscribe (priv->context,
350 PA_SUBSCRIPTION_MASK_SOURCE | PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT,
351 empathy_audio_src_pa_subscribe_cb, NULL);
353 operations_run (self);
358 empathy_audio_src_source_output_index_notify (GObject *object,
360 EmpathyGstAudioSrc *self)
362 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
363 guint source_output_idx = PA_INVALID_INDEX;
365 g_object_get (priv->src, "source-output-index", &source_output_idx, NULL);
367 if (source_output_idx == PA_INVALID_INDEX)
370 if (priv->source_output_idx == source_output_idx)
373 /* It's actually changed. */
374 priv->source_output_idx = source_output_idx;
376 pa_context_get_source_output_info (priv->context, source_output_idx,
377 empathy_audio_src_source_output_info_cb, self);
381 empathy_audio_src_init (EmpathyGstAudioSrc *obj)
383 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (obj);
385 const gchar *src_element;
387 priv->peak_level = -G_MAXDOUBLE;
388 priv->lock = g_mutex_new ();
390 src_element = g_getenv ("EMPATHY_AUDIO_SRC");
391 if (src_element == NULL)
392 src_element = "pulsesrc";
394 priv->src = gst_element_factory_make (src_element, NULL);
395 gst_bin_add (GST_BIN (obj), priv->src);
397 priv->volume = gst_element_factory_make ("volume", NULL);
398 g_object_ref (priv->volume);
400 gst_bin_add (GST_BIN (obj), priv->volume);
401 gst_element_link (priv->src, priv->volume);
403 priv->level = gst_element_factory_make ("level", NULL);
404 gst_bin_add (GST_BIN (obj), priv->level);
405 gst_element_link (priv->volume, priv->level);
407 src = gst_element_get_static_pad (priv->level, "src");
409 ghost = gst_ghost_pad_new ("src", src);
410 gst_element_add_pad (GST_ELEMENT (obj), ghost);
412 gst_object_unref (G_OBJECT (src));
414 /* PulseAudio stuff: We need to create a dummy pa_glib_mainloop* so
415 * Pulse can use the mainloop that GTK has created for us. */
416 priv->loop = pa_glib_mainloop_new (NULL);
417 priv->context = pa_context_new (pa_glib_mainloop_get_api (priv->loop),
420 /* Listen to changes to GstPulseSrc:source-output-index so we know when
421 * it's no longer PA_INVALID_INDEX (starting for the first time) or if it
422 * changes (READY->NULL->READY...) */
423 g_signal_connect (priv->src, "notify::source-output-index",
424 G_CALLBACK (empathy_audio_src_source_output_index_notify),
427 /* Finally listen for state changes so we know when we've
429 pa_context_set_state_callback (priv->context,
430 empathy_audio_src_pa_state_change_cb, obj);
431 pa_context_connect (priv->context, NULL, 0, NULL);
433 priv->operations = g_queue_new ();
436 static void empathy_audio_src_dispose (GObject *object);
437 static void empathy_audio_src_finalize (GObject *object);
438 static void empathy_audio_src_handle_message (GstBin *bin,
439 GstMessage *message);
441 static gboolean empathy_audio_src_levels_updated (gpointer user_data);
444 empathy_audio_src_set_property (GObject *object,
445 guint property_id, const GValue *value, GParamSpec *pspec)
450 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (object),
451 g_value_get_double (value));
454 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
459 empathy_audio_src_get_property (GObject *object,
460 guint property_id, GValue *value, GParamSpec *pspec)
462 EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (object);
463 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
468 g_value_set_double (value,
469 empathy_audio_src_get_volume (self));
471 case PROP_PEAK_LEVEL:
472 g_mutex_lock (priv->lock);
473 g_value_set_double (value, priv->peak_level);
474 g_mutex_unlock (priv->lock);
477 g_mutex_lock (priv->lock);
478 g_value_set_double (value, priv->rms_level);
479 g_mutex_unlock (priv->lock);
481 case PROP_MICROPHONE:
482 g_value_set_uint (value, priv->source_idx);
485 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
490 empathy_audio_src_class_init (EmpathyGstAudioSrcClass
491 *empathy_audio_src_class)
493 GObjectClass *object_class = G_OBJECT_CLASS (empathy_audio_src_class);
494 GstBinClass *gstbin_class = GST_BIN_CLASS (empathy_audio_src_class);
495 GParamSpec *param_spec;
497 g_type_class_add_private (empathy_audio_src_class,
498 sizeof (EmpathyGstAudioSrcPrivate));
500 object_class->dispose = empathy_audio_src_dispose;
501 object_class->finalize = empathy_audio_src_finalize;
503 object_class->set_property = empathy_audio_src_set_property;
504 object_class->get_property = empathy_audio_src_get_property;
506 gstbin_class->handle_message =
507 GST_DEBUG_FUNCPTR (empathy_audio_src_handle_message);
509 param_spec = g_param_spec_double ("volume", "Volume", "volume contol",
511 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
512 g_object_class_install_property (object_class, PROP_VOLUME, param_spec);
514 param_spec = g_param_spec_double ("peak-level", "peak level", "peak level",
515 -G_MAXDOUBLE, G_MAXDOUBLE, 0,
516 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
517 g_object_class_install_property (object_class, PROP_PEAK_LEVEL, param_spec);
519 param_spec = g_param_spec_uint ("microphone", "microphone", "microphone",
520 0, G_MAXUINT, G_MAXUINT,
521 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
522 g_object_class_install_property (object_class, PROP_MICROPHONE, param_spec);
524 signals[PEAK_LEVEL_CHANGED] = g_signal_new ("peak-level-changed",
525 G_TYPE_FROM_CLASS (empathy_audio_src_class),
529 g_cclosure_marshal_VOID__DOUBLE,
530 G_TYPE_NONE, 1, G_TYPE_DOUBLE);
532 param_spec = g_param_spec_double ("rms-level", "RMS level", "RMS level",
533 -G_MAXDOUBLE, G_MAXDOUBLE, 0,
534 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
535 g_object_class_install_property (object_class, PROP_RMS_LEVEL, param_spec);
538 signals[RMS_LEVEL_CHANGED] = g_signal_new ("rms-level-changed",
539 G_TYPE_FROM_CLASS (empathy_audio_src_class),
543 g_cclosure_marshal_VOID__DOUBLE,
544 G_TYPE_NONE, 1, G_TYPE_DOUBLE);
546 signals[MICROPHONE_ADDED] = g_signal_new ("microphone-added",
547 G_TYPE_FROM_CLASS (empathy_audio_src_class),
551 _src_marshal_VOID__UINT_STRING_STRING_BOOLEAN,
552 G_TYPE_NONE, 4, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
554 signals[MICROPHONE_REMOVED] = g_signal_new ("microphone-removed",
555 G_TYPE_FROM_CLASS (empathy_audio_src_class),
559 g_cclosure_marshal_VOID__UINT,
560 G_TYPE_NONE, 1, G_TYPE_UINT);
564 empathy_audio_src_dispose (GObject *object)
566 EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (object);
567 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
569 if (priv->dispose_has_run)
572 priv->dispose_has_run = TRUE;
574 if (priv->idle_id != 0)
575 g_source_remove (priv->idle_id);
579 if (priv->context != NULL)
580 pa_context_unref (priv->context);
581 priv->context = NULL;
583 if (priv->loop != NULL)
584 pa_glib_mainloop_free (priv->loop);
587 /* release any references held by the object here */
589 if (G_OBJECT_CLASS (empathy_audio_src_parent_class)->dispose)
590 G_OBJECT_CLASS (empathy_audio_src_parent_class)->dispose (object);
594 empathy_audio_src_finalize (GObject *object)
596 EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (object);
597 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
599 /* free any data held directly by the object here */
600 g_mutex_free (priv->lock);
602 g_queue_foreach (priv->operations, (GFunc) operation_free,
603 GUINT_TO_POINTER (TRUE));
604 g_queue_free (priv->operations);
606 G_OBJECT_CLASS (empathy_audio_src_parent_class)->finalize (object);
610 empathy_audio_src_levels_updated (gpointer user_data)
612 EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (user_data);
613 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
615 g_mutex_lock (priv->lock);
617 g_signal_emit (self, signals[PEAK_LEVEL_CHANGED], 0, priv->peak_level);
618 g_signal_emit (self, signals[RMS_LEVEL_CHANGED], 0, priv->rms_level);
621 g_mutex_unlock (priv->lock);
627 empathy_audio_src_handle_message (GstBin *bin, GstMessage *message)
629 EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (bin);
630 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
632 if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT &&
633 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->level))
635 const GstStructure *s;
639 gdouble peak = -G_MAXDOUBLE;
640 gdouble rms = -G_MAXDOUBLE;
642 s = gst_message_get_structure (message);
643 name = gst_structure_get_name (s);
645 if (g_strcmp0 ("level", name) != 0)
648 list = gst_structure_get_value (s, "peak");
649 len = gst_value_list_get_size (list);
651 for (i =0 ; i < len; i++)
656 value = gst_value_list_get_value (list, i);
657 db = g_value_get_double (value);
658 peak = MAX (db, peak);
661 list = gst_structure_get_value (s, "rms");
662 len = gst_value_list_get_size (list);
664 for (i =0 ; i < len; i++)
669 value = gst_value_list_get_value (list, i);
670 db = g_value_get_double (value);
674 g_mutex_lock (priv->lock);
676 priv->peak_level = peak;
677 priv->rms_level = rms;
678 if (priv->idle_id == 0)
679 priv->idle_id = g_idle_add (empathy_audio_src_levels_updated, self);
681 g_mutex_unlock (priv->lock);
685 GST_BIN_CLASS (empathy_audio_src_parent_class)->handle_message (bin,
690 empathy_audio_src_new (void)
692 static gboolean registered = FALSE;
695 if (!gst_element_register (NULL, "empathyaudiosrc",
696 GST_RANK_NONE, EMPATHY_TYPE_GST_AUDIO_SRC))
700 return gst_element_factory_make ("empathyaudiosrc", NULL);
704 empathy_audio_src_set_volume (EmpathyGstAudioSrc *src, gdouble volume)
706 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
708 GParamSpecDouble *pspec_double;
710 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (priv->volume),
713 g_assert (pspec != NULL);
715 pspec_double = G_PARAM_SPEC_DOUBLE (pspec);
717 volume = CLAMP (volume, pspec_double->minimum, pspec_double->maximum);
719 g_object_set (G_OBJECT (priv->volume), "volume", volume, NULL);
723 empathy_audio_src_get_volume (EmpathyGstAudioSrc *src)
725 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
728 g_object_get (G_OBJECT (priv->volume), "volume", &volume, NULL);
734 empathy_audio_src_get_microphones_async (EmpathyGstAudioSrc *src,
735 GAsyncReadyCallback callback,
738 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
739 Operation *operation;
740 GSimpleAsyncResult *simple;
742 simple = g_simple_async_result_new (G_OBJECT (src), callback, user_data,
743 empathy_audio_src_get_microphones_async);
745 /* If we can't change mic let's not pretend we can by returning the
746 * list of available mics. */
747 if (!empathy_audio_src_supports_changing_mic (src))
749 g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
750 "pulsesrc is not new enough to support changing microphone");
751 g_simple_async_result_complete_in_idle (simple);
752 g_object_unref (simple);
756 operation = operation_new (operation_get_microphones, simple);
757 g_queue_push_tail (priv->operations, operation);
760 operations_run (src);
764 empathy_audio_src_get_microphones_finish (EmpathyGstAudioSrc *src,
765 GAsyncResult *result,
768 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
771 if (g_simple_async_result_propagate_error (simple, error))
774 g_return_val_if_fail (g_simple_async_result_is_valid (result,
775 G_OBJECT (src), empathy_audio_src_get_microphones_async),
778 queue = g_simple_async_result_get_op_res_gpointer (simple);
783 empathy_audio_src_get_microphone (EmpathyGstAudioSrc *src)
785 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
787 return priv->source_idx;
791 empathy_audio_src_change_microphone_async (EmpathyGstAudioSrc *src,
793 GAsyncReadyCallback callback,
796 EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
797 guint source_output_idx;
798 GSimpleAsyncResult *simple;
799 Operation *operation;
801 simple = g_simple_async_result_new (G_OBJECT (src), callback, user_data,
802 empathy_audio_src_change_microphone_async);
804 if (!empathy_audio_src_supports_changing_mic (src))
806 g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
807 "pulsesrc is not new enough to support changing microphone");
808 g_simple_async_result_complete_in_idle (simple);
809 g_object_unref (simple);
813 g_object_get (priv->src, "source-output-index", &source_output_idx, NULL);
815 if (source_output_idx == PA_INVALID_INDEX)
817 g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
818 "pulsesrc is not yet PLAYING");
819 g_simple_async_result_complete_in_idle (simple);
820 g_object_unref (simple);
824 g_simple_async_result_set_op_res_gpointer (simple,
825 GUINT_TO_POINTER (microphone), NULL);
827 operation = operation_new (operation_change_microphone, simple);
828 g_queue_push_tail (priv->operations, operation);
831 operations_run (src);
835 empathy_audio_src_change_microphone_finish (EmpathyGstAudioSrc *src,
836 GAsyncResult *result,
839 empathy_implement_finish_void (src,
840 empathy_audio_src_change_microphone_async);