[empathy: 8/23] audio-src: add API for getting the mic source ID



commit 1de1a894194a0fa355ef382783fa54f25ddca75c
Author: Jonny Lamb <jonny lamb collabora co uk>
Date:   Wed Jul 27 11:54:52 2011 +0100

    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>

 src/empathy-audio-src.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++
 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 fee1e46..96caae9 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 c65f369..286a34f 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,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]