[empathy: 7/23] audio-src: add API for changing microphone



commit 2223a2eb1e505b857ad13a44bc888149dc3f0334
Author: Jonny Lamb <jonny lamb collabora co uk>
Date:   Wed Jul 27 11:39:21 2011 +0100

    audio-src: add API for changing microphone
    
    Signed-off-by: Jonny Lamb <jonny lamb collabora co uk>

 src/empathy-audio-src.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
 src/empathy-audio-src.h |    5 +++
 2 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/src/empathy-audio-src.c b/src/empathy-audio-src.c
index 086b0a1..fee1e46 100644
--- a/src/empathy-audio-src.c
+++ b/src/empathy-audio-src.c
@@ -173,6 +173,42 @@ operation_get_microphones (EmpathyGstAudioSrc *self,
 }
 
 static void
+operation_change_microphone_cb (pa_context *context,
+    int success,
+    void *userdata)
+{
+  GSimpleAsyncResult *result = userdata;
+
+  if (!success)
+    {
+      g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_FAILED,
+          "Failed to change microphone. Reason unknown.");
+    }
+
+  g_simple_async_result_complete (result);
+  g_object_unref (result);
+}
+
+static void
+operation_change_microphone (EmpathyGstAudioSrc *self,
+    GSimpleAsyncResult *result)
+{
+  EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
+  guint stream_idx, microphone;
+
+  g_object_get (priv->src, "stream-index", &stream_idx, NULL);
+
+  g_assert_cmpuint (pa_context_get_state (priv->context), ==, PA_CONTEXT_READY);
+  g_assert_cmpuint (stream_idx, !=, G_MAXUINT);
+
+  microphone = GPOINTER_TO_UINT (
+      g_simple_async_result_get_op_res_gpointer (result));
+
+  pa_context_move_source_output_by_index (priv->context, stream_idx, microphone,
+      operation_change_microphone_cb, result);
+}
+
+static void
 operations_run (EmpathyGstAudioSrc *self)
 {
   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (self);
@@ -559,3 +595,46 @@ empathy_audio_src_get_microphones_finish (EmpathyGstAudioSrc *src,
   return queue->head;
 }
 
+void
+empathy_audio_src_change_microphone_async (EmpathyGstAudioSrc *src,
+    guint microphone,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (src);
+  guint stream_idx;
+  GSimpleAsyncResult *simple;
+  Operation *operation;
+
+  simple = g_simple_async_result_new (G_OBJECT (src), callback, user_data,
+      empathy_audio_src_change_microphone_async);
+
+  g_object_get (priv->src, "stream-index", &stream_idx, NULL);
+
+  if (stream_idx == G_MAXUINT)
+    {
+      g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED,
+          "pulsesrc is not yet PLAYING");
+      g_simple_async_result_complete_in_idle (simple);
+      g_object_unref (simple);
+      return;
+    }
+
+  g_simple_async_result_set_op_res_gpointer (simple,
+      GUINT_TO_POINTER (microphone), NULL);
+
+  operation = operation_new (operation_change_microphone, simple);
+  g_queue_push_tail (priv->operations, operation);
+
+  /* gogogogo */
+  operations_run (src);
+}
+
+gboolean
+empathy_audio_src_change_microphone_finish (EmpathyGstAudioSrc *src,
+    GAsyncResult *result,
+    GError **error)
+{
+  empathy_implement_finish_void (src,
+      empathy_audio_src_change_microphone_async);
+}
diff --git a/src/empathy-audio-src.h b/src/empathy-audio-src.h
index 298d59c..c65f369 100644
--- a/src/empathy-audio-src.h
+++ b/src/empathy-audio-src.h
@@ -74,6 +74,11 @@ void empathy_audio_src_get_microphones_async (EmpathyGstAudioSrc *src,
 const GList * empathy_audio_src_get_microphones_finish (EmpathyGstAudioSrc *src,
     GAsyncResult *result, GError **error);
 
+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,
+    GAsyncResult *result, GError **error);
+
 G_END_DECLS
 
 #endif /* #ifndef __EMPATHY_GST_AUDIO_SRC_H__*/



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