]> git.0d.be Git - empathy.git/commitdiff
Use gst_parse_bin_from_description() when EMPATHY_AUDIO_* vars are set
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 15 Aug 2011 09:23:35 +0000 (11:23 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 15 Aug 2011 12:38:12 +0000 (14:38 +0200)
Also factor out empathy_call_set_stream_properties().

libempathy-gtk/empathy-call-utils.c
libempathy-gtk/empathy-call-utils.h
src/empathy-audio-sink.c
src/empathy-audio-src.c

index 2991784f137ca69c866ce1aaccfe5c1b2ad79720..333d9026768e464b13acb6f62b2c260bcce131a9 100644 (file)
@@ -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);
+}
index 99a97f202233bc57952f5cf810c22937fc64ff38..87676161c698d176dcb5b92ba7e1dac536fc80c3 100644 (file)
@@ -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__ */
index f8b5d1c39ecf7205d245217c5a87c015d422915b..c9d7203107a3523fb01b15de888b811d751586ce 100644 (file)
@@ -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,
index 98ff24eca8ecef156c7f08966d71558d26665bb5..5da42481042670fdb329621f14da13d49ec6bfa7 100644 (file)
@@ -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);