[empathy] Use gst_parse_bin_from_description() when EMPATHY_AUDIO_* vars are set



commit be5274444c54eb5c529e592d130e362fd1728b4d
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Aug 15 11:23:35 2011 +0200

    Use gst_parse_bin_from_description() when EMPATHY_AUDIO_* vars are set
    
    Also factor out empathy_call_set_stream_properties().

 libempathy-gtk/empathy-call-utils.c |   11 ++++++++
 libempathy-gtk/empathy-call-utils.h |    4 +++
 src/empathy-audio-sink.c            |   47 +++++++++++++++++++++++-----------
 src/empathy-audio-src.c             |   47 ++++++++++++++++++++++++----------
 4 files changed, 80 insertions(+), 29 deletions(-)
---
diff --git a/libempathy-gtk/empathy-call-utils.c b/libempathy-gtk/empathy-call-utils.c
index 2991784..333d902 100644
--- a/libempathy-gtk/empathy-call-utils.c
+++ b/libempathy-gtk/empathy-call-utils.c
@@ -192,3 +192,14 @@ empathy_call_new_with_streams (const gchar *contact,
   g_hash_table_unref (streamed_media_request);
   g_object_unref (call_req);
 }
+
+void
+empathy_call_set_stream_properties (GstElement *element)
+{
+  GstStructure *props;
+
+  props = gst_structure_from_string (
+      "props,media.role=phone", NULL);
+  g_object_set (element, "stream-properties", props, NULL);
+  gst_structure_free (props);
+}
diff --git a/libempathy-gtk/empathy-call-utils.h b/libempathy-gtk/empathy-call-utils.h
index 99a97f2..8767616 100644
--- a/libempathy-gtk/empathy-call-utils.h
+++ b/libempathy-gtk/empathy-call-utils.h
@@ -21,6 +21,8 @@
 #ifndef __EMPATHY_CALL_UTILS_H__
 #define __EMPATHY_CALL_UTILS_H__
 
+#include <gst/gst.h>
+
 G_BEGIN_DECLS
 
 /* Calls */
@@ -38,6 +40,8 @@ GHashTable * empathy_call_create_streamed_media_request (const gchar *contact,
     gboolean initial_audio,
     gboolean initial_video);
 
+void empathy_call_set_stream_properties (GstElement *element);
+
 G_END_DECLS
 
 #endif /*  __EMPATHY_CALL_UTILS_H__ */
diff --git a/src/empathy-audio-sink.c b/src/empathy-audio-sink.c
index f8b5d1c..c9d7203 100644
--- a/src/empathy-audio-sink.c
+++ b/src/empathy-audio-sink.c
@@ -25,6 +25,8 @@
 #include <gst/audio/audio.h>
 #include <telepathy-glib/telepathy-glib.h>
 
+#include <libempathy-gtk/empathy-call-utils.h>
+
 #include "empathy-audio-sink.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
@@ -187,6 +189,35 @@ empathy_audio_sink_get_volume (EmpathyGstAudioSink *sink)
   return volume;
 }
 
+static GstElement *
+create_sink (const gchar *description)
+{
+  GstElement *sink;
+
+  if (description != NULL)
+    {
+      GError *error = NULL;
+
+      sink = gst_parse_bin_from_description (description, TRUE, &error);
+      if (sink == NULL)
+        {
+          DEBUG ("Failed to create bin %s: %s", description, error->message);
+          g_error_free (error);
+        }
+
+      return sink;
+    }
+
+  /* Use pulsesink as default */
+  sink = gst_element_factory_make ("pulsesink", NULL);
+  if (sink == NULL)
+    return NULL;
+
+  empathy_call_set_stream_properties (sink);
+
+  return sink;
+}
+
 static GstPad *
 empathy_audio_sink_request_new_pad (GstElement *element,
   GstPadTemplate *templ,
@@ -196,7 +227,6 @@ empathy_audio_sink_request_new_pad (GstElement *element,
   GstElement *bin, *volume, *resample, *audioconvert0, *audioconvert1;
   GstPad *pad = NULL;
   GstPad *subpad, *filterpad;
-  const gchar *sink_element;
 
   bin = gst_bin_new (NULL);
 
@@ -224,23 +254,10 @@ empathy_audio_sink_request_new_pad (GstElement *element,
 
   gst_bin_add (GST_BIN (bin), volume);
 
-  sink_element = g_getenv ("EMPATHY_AUDIO_SINK");
-  if (sink_element == NULL)
-    sink_element = "pulsesink";
-
-  self->priv->sink = gst_element_factory_make (sink_element, NULL);
+  self->priv->sink = create_sink (g_getenv ("EMPATHY_AUDIO_SINK"));
   if (self->priv->sink == NULL)
     goto error;
 
-  if (!tp_strdiff (sink_element, "pulsesink"))
-    {
-      GstStructure *props;
-
-      props = gst_structure_from_string ("props,media.role=phone", NULL);
-      g_object_set (self->priv->sink, "stream-properties", props, NULL);
-      gst_structure_free (props);
-    }
-
   gst_bin_add (GST_BIN (bin), self->priv->sink);
 
   if (!gst_element_link_many (audioconvert0, resample, audioconvert1,
diff --git a/src/empathy-audio-src.c b/src/empathy-audio-src.c
index 98ff24e..5da4248 100644
--- a/src/empathy-audio-src.c
+++ b/src/empathy-audio-src.c
@@ -26,6 +26,7 @@
 #include <pulse/glib-mainloop.h>
 
 #include <libempathy/empathy-utils.h>
+#include <libempathy-gtk/empathy-call-utils.h>
 
 #include "empathy-audio-src.h"
 
@@ -377,32 +378,50 @@ empathy_audio_src_source_output_index_notify (GObject *object,
       empathy_audio_src_source_output_info_cb, self);
 }
 
+static GstElement *
+create_src (const gchar *description)
+{
+  GstElement *src;
+
+  if (description != NULL)
+    {
+      GError *error = NULL;
+
+      src = gst_parse_bin_from_description (description, TRUE, &error);
+      if (src == NULL)
+        {
+          DEBUG ("Failed to create bin %s: %s", description, error->message);
+          g_error_free (error);
+        }
+
+      return src;
+    }
+
+  /* Use pulsesrc as default */
+  src = gst_element_factory_make ("pulsesrc", NULL);
+  if (src == NULL)
+    return NULL;
+
+  empathy_call_set_stream_properties (src);
+
+  return src;
+}
+
 static void
 empathy_audio_src_init (EmpathyGstAudioSrc *obj)
 {
   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (obj);
   GstPad *ghost, *src;
-  const gchar *src_element;
 
   priv->peak_level = -G_MAXDOUBLE;
   priv->lock = g_mutex_new ();
 
-  src_element = g_getenv ("EMPATHY_AUDIO_SRC");
-  if (src_element == NULL)
-    src_element = "pulsesrc";
+  priv->src = create_src (g_getenv ("EMPATHY_AUDIO_SRC"));
+  if (priv->src == NULL)
+    return;
 
-  priv->src = gst_element_factory_make (src_element, NULL);
   gst_bin_add (GST_BIN (obj), priv->src);
 
-  if (!tp_strdiff (src_element, "pulsesrc"))
-    {
-      GstStructure *props;
-
-      props = gst_structure_from_string ("props,media.role=phone", NULL);
-      g_object_set (priv->src, "stream-properties", props, NULL);
-      gst_structure_free (props);
-    }
-
   priv->volume = gst_element_factory_make ("volume", NULL);
   g_object_ref (priv->volume);
 



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