]> git.0d.be Git - empathy.git/blob - src/empathy-audio-src.c
Implement input audio control
[empathy.git] / src / empathy-audio-src.c
1 /*
2  * empathy-gst-audio-src.c - Source for EmpathyGstAudioSrc
3  * Copyright (C) 2008 Collabora Ltd.
4  * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #include <gst/interfaces/mixer.h>
27
28 #include <libempathy/empathy-utils.h>
29 #include <libempathy-gtk/empathy-call-utils.h>
30
31 #include "empathy-audio-src.h"
32
33 #include "empathy-mic-monitor.h"
34
35 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
36 #include <libempathy/empathy-debug.h>
37
38 G_DEFINE_TYPE(EmpathyGstAudioSrc, empathy_audio_src, GST_TYPE_BIN)
39
40 /* signal enum */
41 enum
42 {
43     PEAK_LEVEL_CHANGED,
44     RMS_LEVEL_CHANGED,
45     LAST_SIGNAL
46 };
47
48 static guint signals[LAST_SIGNAL] = {0};
49
50 enum {
51     PROP_VOLUME = 1,
52     PROP_RMS_LEVEL,
53     PROP_PEAK_LEVEL,
54     PROP_MICROPHONE,
55 };
56
57 /* private structure */
58 struct _EmpathyGstAudioSrcPrivate
59 {
60   gboolean dispose_has_run;
61   GstElement *src;
62   GstElement *level;
63
64   EmpathyMicMonitor *mic_monitor;
65
66   /* 0 if not known yet */
67   guint source_output_idx;
68   /* G_MAXUINT if not known yet */
69   guint source_idx;
70
71   gdouble peak_level;
72   gdouble rms_level;
73
74   gdouble volume;
75   /* the mixer track on src we follow and adjust */
76   GstMixerTrack *track;
77
78   GMutex *lock;
79   guint level_idle_id;
80   guint volume_idle_id;
81 };
82
83 #define EMPATHY_GST_AUDIO_SRC_GET_PRIVATE(o) \
84   (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_GST_AUDIO_SRC, \
85   EmpathyGstAudioSrcPrivate))
86
87 /* There is no predefined maximum channels by gstreamer, just pick 32, which is
88  * the same as the pulseaudio maximum */
89 #define MAX_MIC_CHANNELS 32
90
91 static void
92 empathy_audio_src_set_hw_volume (EmpathyGstAudioSrc *self, gdouble volume)
93 {
94   gint volumes[MAX_MIC_CHANNELS];
95   int i;
96
97   g_mutex_lock (self->priv->lock);
98   /* If there is no mixer available ignore the setting */
99   if (self->priv->track == NULL)
100     goto out;
101
102   for (i = 0; i < MAX_MIC_CHANNELS; i++)
103     volumes[i] = self->priv->track->max_volume * volume;
104
105   gst_mixer_set_volume (GST_MIXER (self->priv->src),
106     self->priv->track, volumes);
107
108 out:
109    g_mutex_unlock (self->priv->lock);
110
111   self->priv->volume = volume;
112 }
113
114 static gdouble
115 empathy_audio_src_get_hw_volume (EmpathyGstAudioSrc *self)
116 {
117   gint volumes[MAX_MIC_CHANNELS];
118   gdouble result = self->priv->volume;
119
120   g_mutex_lock (self->priv->lock);
121   if (self->priv->track == NULL)
122     goto out;
123
124   gst_mixer_get_volume (GST_MIXER (self->priv->src),
125     self->priv->track, volumes);
126   result = volumes[0]/(gdouble)self->priv->track->max_volume;
127
128 out:
129   g_mutex_unlock (self->priv->lock);
130
131   return result;
132 }
133
134
135 gboolean
136 empathy_audio_src_supports_changing_mic (EmpathyGstAudioSrc *self)
137 {
138   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
139   GObjectClass *object_class;
140
141   object_class = G_OBJECT_GET_CLASS (priv->src);
142
143   return (g_object_class_find_property (object_class,
144           "source-output-index") != NULL);
145 }
146
147 static guint
148 empathy_audio_src_get_mic_index (EmpathyGstAudioSrc *self)
149 {
150   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
151   guint audio_src_idx = PA_INVALID_INDEX;
152
153   if (empathy_audio_src_supports_changing_mic (self))
154     g_object_get (priv->src,
155       "source-output-index", &audio_src_idx,
156       NULL);
157
158   return audio_src_idx;
159 }
160
161 static void
162 empathy_audio_src_microphone_changed_cb (EmpathyMicMonitor *monitor,
163     guint source_output_idx,
164     guint source_idx,
165     gpointer user_data)
166 {
167   EmpathyGstAudioSrc *self = user_data;
168   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
169   guint audio_src_idx;
170
171   audio_src_idx = empathy_audio_src_get_mic_index (self);
172
173   if (source_output_idx == PA_INVALID_INDEX
174       || source_output_idx != audio_src_idx)
175     return;
176
177   if (priv->source_idx == source_idx)
178     return;
179
180   priv->source_idx = source_idx;
181   g_object_notify (G_OBJECT (self), "microphone");
182 }
183
184 static void
185 empathy_audio_src_get_current_mic_cb (GObject *source_object,
186     GAsyncResult *result,
187     gpointer user_data)
188 {
189   EmpathyMicMonitor *monitor = EMPATHY_MIC_MONITOR (source_object);
190   EmpathyGstAudioSrc *self = user_data;
191   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
192   guint source_idx;
193   GError *error = NULL;
194
195   source_idx = empathy_mic_monitor_get_current_mic_finish (monitor, result, &error);
196
197   if (error != NULL)
198     {
199       DEBUG ("Failed to get current mic: %s", error->message);
200       g_clear_error (&error);
201       return;
202     }
203
204   if (priv->source_idx == source_idx)
205     return;
206
207   priv->source_idx = source_idx;
208   g_object_notify (G_OBJECT (self), "microphone");
209 }
210
211 static void
212 empathy_audio_src_source_output_index_notify (GObject *object,
213     GParamSpec *pspec,
214     EmpathyGstAudioSrc *self)
215 {
216   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
217   guint source_output_idx;
218
219   source_output_idx = empathy_audio_src_get_mic_index (self);
220
221   if (source_output_idx == PA_INVALID_INDEX)
222     return;
223
224   if (priv->source_output_idx == source_output_idx)
225     return;
226
227   /* It's actually changed. */
228   priv->source_output_idx = source_output_idx;
229
230   empathy_mic_monitor_get_current_mic_async (priv->mic_monitor,
231       source_output_idx, empathy_audio_src_get_current_mic_cb, self);
232 }
233
234 static GstMixerTrack *
235 empathy_audio_src_get_track (GstElement *src)
236 {
237   const GList *t;
238   GstMixerTrack *track = NULL;
239
240   if (!gst_element_implements_interface (src, GST_TYPE_MIXER))
241     {
242       g_warning ("No mixer interface implementation, can't control volume");
243       return NULL;
244     }
245
246   for (t = gst_mixer_list_tracks (GST_MIXER (src));
247       t != NULL; t = g_list_next (t))
248     {
249       GstMixerTrack *tr = t->data;
250       if (!tp_strdiff (tr->label, "Master"))
251         {
252           track = tr;
253           break;
254         }
255     }
256
257   if (track == NULL)
258     {
259       g_warning ("No suitable track found");
260     }
261   else if (track->num_channels > MAX_MIC_CHANNELS)
262     {
263       g_warning ("Microphones with more then %d channels not supported ",
264         MAX_MIC_CHANNELS);
265       track = NULL;
266     }
267
268   return track;
269 }
270
271 static GstElement *
272 create_src (void)
273 {
274   GstElement *src;
275   const gchar *description;
276
277   description = g_getenv ("EMPATHY_AUDIO_SRC");
278
279   if (description != NULL)
280     {
281       GError *error = NULL;
282
283       src = gst_parse_bin_from_description (description, TRUE, &error);
284       if (src == NULL)
285         {
286           DEBUG ("Failed to create bin %s: %s", description, error->message);
287           g_error_free (error);
288         }
289
290       return src;
291     }
292
293   /* Use pulsesrc as default */
294   src = gst_element_factory_make ("pulsesrc", NULL);
295   if (src == NULL)
296     return NULL;
297
298   empathy_call_set_stream_properties (src, TRUE);
299
300   return src;
301 }
302
303 static void
304 empathy_audio_src_init (EmpathyGstAudioSrc *obj)
305 {
306   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (obj);
307   GstPad *ghost, *src;
308   GstElement *capsfilter;
309   GstCaps *caps;
310
311   obj->priv = priv;
312   priv->peak_level = -G_MAXDOUBLE;
313   priv->lock = g_mutex_new ();
314   priv->volume = 1.0;
315
316   priv->src = create_src ();
317   if (priv->src == NULL)
318     return;
319
320   gst_bin_add (GST_BIN (obj), priv->src);
321
322   /* Explicitly state what format we want from pulsesrc. This pushes resampling
323    * and format conversion as early as possible, lowering the amount of data
324    * transferred and thus improving performance. When moving to GStreamer
325    * 0.11/1.0, this should change so that we actually request what the encoder
326    * wants downstream. */
327   caps = gst_caps_new_simple ("audio/x-raw-int",
328       "channels", G_TYPE_INT, 1,
329       "width", G_TYPE_INT, 16,
330       "depth", G_TYPE_INT, 16,
331       "rate", G_TYPE_INT, 32000,
332       NULL);
333   capsfilter = gst_element_factory_make ("capsfilter", NULL);
334   g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
335   gst_bin_add (GST_BIN (obj), capsfilter);
336   gst_element_link (priv->src, capsfilter);
337
338   priv->level = gst_element_factory_make ("level", NULL);
339   gst_bin_add (GST_BIN (obj), priv->level);
340   gst_element_link (capsfilter, priv->level);
341
342   src = gst_element_get_static_pad (priv->level, "src");
343
344   ghost = gst_ghost_pad_new ("src", src);
345   gst_element_add_pad (GST_ELEMENT (obj), ghost);
346
347   gst_object_unref (G_OBJECT (src));
348
349   /* Listen to changes to GstPulseSrc:source-output-index so we know when
350    * it's no longer PA_INVALID_INDEX (starting for the first time) or if it
351    * changes (READY->NULL->READY...) */
352   g_signal_connect (priv->src, "notify::source-output-index",
353       G_CALLBACK (empathy_audio_src_source_output_index_notify),
354       obj);
355
356   priv->mic_monitor = empathy_mic_monitor_new ();
357   g_signal_connect (priv->mic_monitor, "microphone-changed",
358       G_CALLBACK (empathy_audio_src_microphone_changed_cb), obj);
359
360   priv->source_idx = PA_INVALID_INDEX;
361 }
362
363 static void empathy_audio_src_dispose (GObject *object);
364 static void empathy_audio_src_finalize (GObject *object);
365 static void empathy_audio_src_handle_message (GstBin *bin,
366   GstMessage *message);
367
368 static gboolean empathy_audio_src_levels_updated (gpointer user_data);
369
370 static void
371 empathy_audio_src_set_property (GObject *object,
372   guint property_id, const GValue *value, GParamSpec *pspec)
373 {
374   switch (property_id)
375     {
376       case PROP_VOLUME:
377         empathy_audio_src_set_hw_volume (EMPATHY_GST_AUDIO_SRC (object),
378           g_value_get_double (value));
379         break;
380       default:
381         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
382     }
383 }
384
385 static void
386 empathy_audio_src_get_property (GObject *object,
387   guint property_id, GValue *value, GParamSpec *pspec)
388 {
389   EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (object);
390   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
391
392   switch (property_id)
393     {
394       case PROP_VOLUME:
395         g_value_set_double (value, priv->volume);
396         break;
397       case PROP_PEAK_LEVEL:
398         g_mutex_lock (priv->lock);
399         g_value_set_double (value, priv->peak_level);
400         g_mutex_unlock (priv->lock);
401         break;
402       case PROP_RMS_LEVEL:
403         g_mutex_lock (priv->lock);
404         g_value_set_double (value, priv->rms_level);
405         g_mutex_unlock (priv->lock);
406         break;
407       case PROP_MICROPHONE:
408         g_value_set_uint (value, priv->source_idx);
409         break;
410       default:
411         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
412     }
413 }
414
415 static void
416 empathy_audio_src_class_init (EmpathyGstAudioSrcClass
417   *empathy_audio_src_class)
418 {
419   GObjectClass *object_class = G_OBJECT_CLASS (empathy_audio_src_class);
420   GstBinClass *gstbin_class = GST_BIN_CLASS (empathy_audio_src_class);
421   GParamSpec *param_spec;
422
423   g_type_class_add_private (empathy_audio_src_class,
424     sizeof (EmpathyGstAudioSrcPrivate));
425
426   object_class->dispose = empathy_audio_src_dispose;
427   object_class->finalize = empathy_audio_src_finalize;
428
429   object_class->set_property = empathy_audio_src_set_property;
430   object_class->get_property = empathy_audio_src_get_property;
431
432   gstbin_class->handle_message =
433     GST_DEBUG_FUNCPTR (empathy_audio_src_handle_message);
434
435   param_spec = g_param_spec_double ("volume", "Volume", "volume contol",
436     0.0, 5.0, 1.0,
437     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
438   g_object_class_install_property (object_class, PROP_VOLUME, param_spec);
439
440   param_spec = g_param_spec_double ("peak-level", "peak level", "peak level",
441     -G_MAXDOUBLE, G_MAXDOUBLE, 0,
442     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
443   g_object_class_install_property (object_class, PROP_PEAK_LEVEL, param_spec);
444
445   param_spec = g_param_spec_uint ("microphone", "microphone", "microphone",
446     0, G_MAXUINT, G_MAXUINT,
447     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
448   g_object_class_install_property (object_class, PROP_MICROPHONE, param_spec);
449
450   signals[PEAK_LEVEL_CHANGED] = g_signal_new ("peak-level-changed",
451     G_TYPE_FROM_CLASS (empathy_audio_src_class),
452     G_SIGNAL_RUN_LAST,
453     0,
454     NULL, NULL,
455     g_cclosure_marshal_generic,
456     G_TYPE_NONE, 1, G_TYPE_DOUBLE);
457
458   param_spec = g_param_spec_double ("rms-level", "RMS level", "RMS level",
459     -G_MAXDOUBLE, G_MAXDOUBLE, 0,
460     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
461   g_object_class_install_property (object_class, PROP_RMS_LEVEL, param_spec);
462
463   signals[RMS_LEVEL_CHANGED] = g_signal_new ("rms-level-changed",
464     G_TYPE_FROM_CLASS (empathy_audio_src_class),
465     G_SIGNAL_RUN_LAST,
466     0,
467     NULL, NULL,
468     g_cclosure_marshal_generic,
469     G_TYPE_NONE, 1, G_TYPE_DOUBLE);
470 }
471
472 void
473 empathy_audio_src_dispose (GObject *object)
474 {
475   EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (object);
476   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
477
478   if (priv->dispose_has_run)
479     return;
480
481   priv->dispose_has_run = TRUE;
482
483   if (priv->level_idle_id != 0)
484     g_source_remove (priv->level_idle_id);
485   priv->level_idle_id = 0;
486
487   if (priv->volume_idle_id != 0)
488     g_source_remove (priv->volume_idle_id);
489   priv->volume_idle_id = 0;
490
491   tp_clear_object (&priv->mic_monitor);
492
493   /* release any references held by the object here */
494
495   if (G_OBJECT_CLASS (empathy_audio_src_parent_class)->dispose)
496     G_OBJECT_CLASS (empathy_audio_src_parent_class)->dispose (object);
497 }
498
499 void
500 empathy_audio_src_finalize (GObject *object)
501 {
502   EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (object);
503   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
504
505   /* free any data held directly by the object here */
506   g_mutex_free (priv->lock);
507
508   G_OBJECT_CLASS (empathy_audio_src_parent_class)->finalize (object);
509 }
510
511 static gboolean
512 empathy_audio_src_levels_updated (gpointer user_data)
513 {
514   EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (user_data);
515   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
516
517   g_mutex_lock (priv->lock);
518
519   g_signal_emit (self, signals[PEAK_LEVEL_CHANGED], 0, priv->peak_level);
520   g_signal_emit (self, signals[RMS_LEVEL_CHANGED], 0, priv->rms_level);
521   priv->level_idle_id = 0;
522
523   g_mutex_unlock (priv->lock);
524
525   return FALSE;
526 }
527
528 static gboolean
529 empathy_audio_src_volume_changed (gpointer user_data)
530 {
531   EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (user_data);
532   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
533   gdouble volume;
534
535   g_mutex_lock (priv->lock);
536   priv->volume_idle_id = 0;
537   g_mutex_unlock (priv->lock);
538
539   volume = empathy_audio_src_get_hw_volume (self);
540
541   if (volume != priv->volume)
542     {
543       priv->volume = volume;
544       g_object_notify (G_OBJECT (self), "volume");
545     }
546
547   return FALSE;
548 }
549
550 static void
551 empathy_audio_src_handle_message (GstBin *bin, GstMessage *message)
552 {
553   EmpathyGstAudioSrc *self = EMPATHY_GST_AUDIO_SRC (bin);
554   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
555
556   if  (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT &&
557         GST_MESSAGE_SRC (message) == GST_OBJECT (priv->level))
558     {
559       const GstStructure *s;
560       const gchar *name;
561       const GValue *list;
562       guint i, len;
563       gdouble peak = -G_MAXDOUBLE;
564       gdouble rms = -G_MAXDOUBLE;
565
566       s = gst_message_get_structure (message);
567       name = gst_structure_get_name (s);
568
569       if (g_strcmp0 ("level", name) != 0)
570         goto out;
571
572       list = gst_structure_get_value (s, "peak");
573       len = gst_value_list_get_size (list);
574
575       for (i =0 ; i < len; i++)
576         {
577           const GValue *value;
578           gdouble db;
579
580           value = gst_value_list_get_value (list, i);
581           db = g_value_get_double (value);
582           peak = MAX (db, peak);
583         }
584
585       list = gst_structure_get_value (s, "rms");
586       len = gst_value_list_get_size (list);
587
588       for (i =0 ; i < len; i++)
589         {
590           const GValue *value;
591           gdouble db;
592
593           value = gst_value_list_get_value (list, i);
594           db = g_value_get_double (value);
595           rms = MAX (db, rms);
596         }
597
598       g_mutex_lock (priv->lock);
599
600       priv->peak_level = peak;
601       priv->rms_level = rms;
602       if (priv->level_idle_id == 0)
603         priv->level_idle_id = g_idle_add (
604           empathy_audio_src_levels_updated, self);
605
606       g_mutex_unlock (priv->lock);
607     }
608   else if  (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT &&
609         GST_MESSAGE_SRC (message) == GST_OBJECT (priv->src))
610     {
611       /* Listen for volume changes on the src element */
612       if (gst_mixer_message_get_type (message) ==
613           GST_MIXER_MESSAGE_VOLUME_CHANGED)
614         {
615           GstMixerTrack *track;
616
617           gst_mixer_message_parse_volume_changed (message, &track,
618             NULL, NULL);
619
620           g_mutex_lock (priv->lock);
621
622           if (track == priv->track && priv->volume_idle_id == 0)
623             priv->volume_idle_id = g_idle_add (
624                 empathy_audio_src_volume_changed, self);
625           g_mutex_unlock (priv->lock);
626         }
627     }
628   else if  (GST_MESSAGE_TYPE (message) == GST_MESSAGE_STATE_CHANGED &&
629       GST_MESSAGE_SRC (message) == GST_OBJECT (priv->src))
630     {
631       GstState old, new;
632
633       gst_message_parse_state_changed (message, &old, &new, NULL);
634
635       /* GstMixer is only available in state >= READY, so only start
636        * controlling the source element when going to ready state and stop
637        * doing so when going below ready. Furthermore once we have mixer read
638        * the current volume level from it and remove the settings done by
639        * Empathy. We want to pick up the level pulseaudio saved */
640       if (old == GST_STATE_NULL && new == GST_STATE_READY)
641         {
642           g_mutex_lock (priv->lock);
643           priv->track = empathy_audio_src_get_track (priv->src);
644           if (priv->track != NULL)
645             priv->volume_idle_id = g_idle_add (
646               empathy_audio_src_volume_changed, self);
647           g_mutex_unlock (priv->lock);
648         }
649       else if (old == GST_STATE_READY && new == GST_STATE_NULL)
650         {
651           g_mutex_lock (priv->lock);
652           priv->track = NULL;
653           g_mutex_unlock (priv->lock);
654         }
655     }
656
657 out:
658    GST_BIN_CLASS (empathy_audio_src_parent_class)->handle_message (bin,
659     message);
660 }
661
662 GstElement *
663 empathy_audio_src_new (void)
664 {
665   static gboolean registered = FALSE;
666
667   if (!registered) {
668     if (!gst_element_register (NULL, "empathyaudiosrc",
669             GST_RANK_NONE, EMPATHY_TYPE_GST_AUDIO_SRC))
670       return NULL;
671     registered = TRUE;
672   }
673   return gst_element_factory_make ("empathyaudiosrc", NULL);
674 }
675
676 void
677 empathy_audio_src_set_echo_cancel (EmpathyGstAudioSrc *src,
678   gboolean enable)
679 {
680   DEBUG ("Src echo cancellation setting: %s", enable ? "on" : "off");
681   empathy_call_set_stream_properties (src->priv->src, enable);
682 }
683
684 void
685 empathy_audio_src_set_volume (EmpathyGstAudioSrc *src, gdouble volume)
686 {
687   g_object_set (src, "volume", volume, NULL);
688 }
689
690 gdouble
691 empathy_audio_src_get_volume (EmpathyGstAudioSrc *src)
692 {
693   return src->priv->volume;
694 }
695
696 guint
697 empathy_audio_src_get_microphone (EmpathyGstAudioSrc *src)
698 {
699   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
700
701   return priv->source_idx;
702 }
703
704 static void
705 empathy_audio_src_change_microphone_cb (GObject *source_object,
706     GAsyncResult *result,
707     gpointer user_data)
708 {
709   EmpathyMicMonitor *monitor = EMPATHY_MIC_MONITOR (source_object);
710   GSimpleAsyncResult *simple = user_data;
711   GError *error = NULL;
712
713   if (!empathy_mic_monitor_change_microphone_finish (monitor,
714           result, &error))
715     {
716       g_simple_async_result_take_error (simple, error);
717     }
718
719   g_simple_async_result_complete (simple);
720   g_object_unref (simple);
721 }
722
723 void
724 empathy_audio_src_change_microphone_async (EmpathyGstAudioSrc *src,
725     guint microphone,
726     GAsyncReadyCallback callback,
727     gpointer user_data)
728 {
729   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
730   guint source_output_idx;
731   GSimpleAsyncResult *simple;
732
733   simple = g_simple_async_result_new (G_OBJECT (src), callback, user_data,
734       empathy_audio_src_change_microphone_async);
735
736   if (!empathy_audio_src_supports_changing_mic (src))
737     {
738       g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
739           "pulsesrc is not new enough to support changing microphone");
740       g_simple_async_result_complete_in_idle (simple);
741       g_object_unref (simple);
742       return;
743     }
744
745   source_output_idx = empathy_audio_src_get_mic_index (src);
746
747   if (source_output_idx == PA_INVALID_INDEX)
748     {
749       g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
750           "pulsesrc is not yet PLAYING");
751       g_simple_async_result_complete_in_idle (simple);
752       g_object_unref (simple);
753       return;
754     }
755
756   empathy_mic_monitor_change_microphone_async (priv->mic_monitor,
757       source_output_idx, microphone, empathy_audio_src_change_microphone_cb,
758       simple);
759 }
760
761 gboolean
762 empathy_audio_src_change_microphone_finish (EmpathyGstAudioSrc *src,
763     GAsyncResult *result,
764     GError **error)
765 {
766   empathy_implement_finish_void (src,
767       empathy_audio_src_change_microphone_async);
768 }