]> git.0d.be Git - empathy.git/commitdiff
audio-src: add API for getting the mic source ID
authorJonny Lamb <jonny.lamb@collabora.co.uk>
Wed, 27 Jul 2011 10:54:52 +0000 (11:54 +0100)
committerJonny Lamb <jonny.lamb@collabora.co.uk>
Fri, 29 Jul 2011 10:02:01 +0000 (11:02 +0100)
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
src/empathy-audio-src.h

index fee1e46cfac919689b534c5e3797ab911a9ce057..96caae9703ac5b339660881ff4bef13fb320a24d 100644 (file)
@@ -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;
 
@@ -239,6 +243,50 @@ empathy_audio_src_pa_state_change_cb (pa_context *c,
   operations_run (self);
 }
 
+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)
 {
@@ -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,
index c65f3696a5fd70ac6865217c55a2835fcf4142c5..286a34f9a7f0a8d00df8f977e66042cc531432ac 100644 (file)
@@ -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,