diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-07-27 18:54:52 +0800 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-07-29 18:02:01 +0800 |
commit | 1de1a894194a0fa355ef382783fa54f25ddca75c (patch) | |
tree | a95adc44663712ce733050e2f6434cd041122d54 /src | |
parent | 2223a2eb1e505b857ad13a44bc888149dc3f0334 (diff) | |
download | gsoc2013-empathy-1de1a894194a0fa355ef382783fa54f25ddca75c.tar gsoc2013-empathy-1de1a894194a0fa355ef382783fa54f25ddca75c.tar.gz gsoc2013-empathy-1de1a894194a0fa355ef382783fa54f25ddca75c.tar.bz2 gsoc2013-empathy-1de1a894194a0fa355ef382783fa54f25ddca75c.tar.lz gsoc2013-empathy-1de1a894194a0fa355ef382783fa54f25ddca75c.tar.xz gsoc2013-empathy-1de1a894194a0fa355ef382783fa54f25ddca75c.tar.zst gsoc2013-empathy-1de1a894194a0fa355ef382783fa54f25ddca75c.zip |
audio-src: add API for getting the mic source ID
Also listen out for changes in the source output ID (but that'll only
happen if we go READY -> NULL -> READY again).
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-audio-src.c | 68 | ||||
-rw-r--r-- | src/empathy-audio-src.h | 2 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/empathy-audio-src.c b/src/empathy-audio-src.c index fee1e46cf..96caae970 100644 --- a/src/empathy-audio-src.c +++ b/src/empathy-audio-src.c @@ -45,6 +45,7 @@ enum { PROP_VOLUME = 1, PROP_RMS_LEVEL, PROP_PEAK_LEVEL, + PROP_MICROPHONE, }; /* private structure */ @@ -61,6 +62,9 @@ struct _EmpathyGstAudioSrcPrivate pa_context *context; GQueue *operations; + guint source_output_idx; + guint source_idx; + gdouble peak_level; gdouble rms_level; @@ -240,6 +244,50 @@ empathy_audio_src_pa_state_change_cb (pa_context *c, } static void +empathy_audio_src_source_output_info_cb (pa_context *context, + const pa_source_output_info *info, + int eol, + void *userdata) +{ + EmpathyGstAudioSrc *self = userdata; + EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self); + + if (eol) + return; + + /* There should only be one call here. */ + + if (priv->source_idx == info->source) + return; + + priv->source_idx = info->source; + g_object_notify (G_OBJECT (self), "microphone"); +} + +static void +empathy_audio_src_stream_index_notify (GObject *object, + GParamSpec *pspec, + EmpathyGstAudioSrc *self) +{ + EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self); + guint stream_idx = G_MAXUINT; + + g_object_get (priv->src, "stream-index", &stream_idx, NULL); + + if (stream_idx == G_MAXUINT) + return; + + if (priv->source_output_idx == stream_idx) + return; + + /* It's actually changed. */ + priv->source_output_idx = stream_idx; + + pa_context_get_source_output_info (priv->context, stream_idx, + empathy_audio_src_source_output_info_cb, self); +} + +static void empathy_audio_src_init (EmpathyGstAudioSrc *obj) { EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (obj); @@ -281,6 +329,10 @@ empathy_audio_src_init (EmpathyGstAudioSrc *obj) empathy_audio_src_pa_state_change_cb, obj); pa_context_connect (priv->context, NULL, 0, NULL); + g_signal_connect (priv->src, "notify::stream-index", + G_CALLBACK (empathy_audio_src_stream_index_notify), + obj); + priv->operations = g_queue_new (); } @@ -329,6 +381,9 @@ empathy_audio_src_get_property (GObject *object, g_value_set_double (value, priv->rms_level); g_mutex_unlock (priv->lock); break; + case PROP_MICROPHONE: + g_value_set_uint (value, priv->source_idx); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -364,6 +419,11 @@ empathy_audio_src_class_init (EmpathyGstAudioSrcClass G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_VOLUME, param_spec); + param_spec = g_param_spec_uint ("microphone", "microphone", "microphone", + 0, G_MAXUINT, G_MAXUINT, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_MICROPHONE, param_spec); + signals[PEAK_LEVEL_CHANGED] = g_signal_new ("peak-level-changed", G_TYPE_FROM_CLASS (empathy_audio_src_class), G_SIGNAL_RUN_LAST, @@ -595,6 +655,14 @@ empathy_audio_src_get_microphones_finish (EmpathyGstAudioSrc *src, return queue->head; } +guint +empathy_audio_src_get_microphone (EmpathyGstAudioSrc *src) +{ + EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src); + + return priv->source_idx; +} + void empathy_audio_src_change_microphone_async (EmpathyGstAudioSrc *src, guint microphone, diff --git a/src/empathy-audio-src.h b/src/empathy-audio-src.h index c65f3696a..286a34f9a 100644 --- a/src/empathy-audio-src.h +++ b/src/empathy-audio-src.h @@ -74,6 +74,8 @@ void empathy_audio_src_get_microphones_async (EmpathyGstAudioSrc *src, const GList * empathy_audio_src_get_microphones_finish (EmpathyGstAudioSrc *src, GAsyncResult *result, GError **error); +guint empathy_audio_src_get_microphone (EmpathyGstAudioSrc *src); + void empathy_audio_src_change_microphone_async (EmpathyGstAudioSrc *src, guint microphone, GAsyncReadyCallback callback, gpointer user_data); gboolean empathy_audio_src_change_microphone_finish (EmpathyGstAudioSrc *src, |