]> git.0d.be Git - empathy.git/blobdiff - src/empathy-audio-sink.c
Merge branch 'gnome-3-8'
[empathy.git] / src / empathy-audio-sink.c
index 372e9f99176a6ae2013c0c90b5a2d87e53f6cb44..985a1fa36d83d8f825277b1676dc543601e40cd6 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include "config.h"
+#include "empathy-audio-sink.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <gst/audio/audio.h>
+#ifdef HAVE_GST1
+#include <gst/audio/streamvolume.h>
+#else
 #include <gst/interfaces/streamvolume.h>
+#endif
 
-#include <telepathy-glib/telepathy-glib.h>
-
-#include <libempathy-gtk/empathy-call-utils.h>
-
-#include "empathy-audio-sink.h"
+#include "empathy-audio-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 G_DEFINE_TYPE(EmpathyGstAudioSink, empathy_audio_sink, GST_TYPE_BIN)
 
@@ -50,8 +48,12 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE(
     "sink%d",
     GST_PAD_SINK,
     GST_PAD_REQUEST,
+#ifdef HAVE_GST1
+    GST_STATIC_CAPS ( "audio/x-raw" )
+#else
     GST_STATIC_CAPS ( GST_AUDIO_INT_PAD_TEMPLATE_CAPS " ; "
         GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS)
+#endif
 );
 
 enum {
@@ -64,7 +66,7 @@ struct _EmpathyGstAudioSinkPrivate
   gboolean echo_cancel;
   gdouble volume;
   gint volume_idle_id;
-  GStaticMutex volume_mutex;
+  GMutex volume_mutex;
 };
 
 #define EMPATHY_GST_AUDIO_SINK_GET_PRIVATE(o) \
@@ -76,12 +78,19 @@ empathy_audio_sink_init (EmpathyGstAudioSink *self)
 {
   self->priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
   self->priv->echo_cancel = TRUE;
-  g_static_mutex_init (&self->priv->volume_mutex);
+  g_mutex_init (&self->priv->volume_mutex);
 }
 
+#ifdef HAVE_GST1
+static GstPad * empathy_audio_sink_request_new_pad (GstElement *self,
+  GstPadTemplate *templ,
+  const gchar* name,
+  const GstCaps *caps);
+#else
 static GstPad * empathy_audio_sink_request_new_pad (GstElement *self,
   GstPadTemplate *templ,
   const gchar* name);
+#endif
 
 static void empathy_audio_sink_release_pad (GstElement *self,
   GstPad *pad);
@@ -94,9 +103,9 @@ empathy_audio_sink_set_property (GObject *object,
   switch (property_id)
     {
       case PROP_VOLUME:
-        g_static_mutex_lock (&self->priv->volume_mutex);
+        g_mutex_lock (&self->priv->volume_mutex);
         self->priv->volume = g_value_get_double (value);
-        g_static_mutex_unlock (&self->priv->volume_mutex);
+        g_mutex_unlock (&self->priv->volume_mutex);
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -128,7 +137,7 @@ empathy_audio_sink_dispose (GObject *object)
     g_source_remove (priv->volume_idle_id);
   priv->volume_idle_id = 0;
 
-  g_static_mutex_free (&self->priv->volume_mutex);
+  g_mutex_clear (&self->priv->volume_mutex);
 
   /* release any references held by the object here */
   if (G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose)
@@ -218,7 +227,14 @@ create_sink (EmpathyGstAudioSink *self)
   if (sink == NULL)
     return NULL;
 
-  empathy_call_set_stream_properties (sink, self->priv->echo_cancel);
+  empathy_audio_set_stream_properties (sink, self->priv->echo_cancel);
+
+  /* Set latency (buffering on the PulseAudio side) of 40ms and transfer data
+   * in 10ms chunks */
+  g_object_set (sink,
+      "buffer-time", (gint64) 40000,
+      "latency-time", (gint64) 10000,
+      NULL);
 
   return sink;
 }
@@ -228,9 +244,9 @@ empathy_audio_sink_volume_idle_updated (gpointer user_data)
 {
   EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (user_data);
 
-  g_static_mutex_lock (&self->priv->volume_mutex);
+  g_mutex_lock (&self->priv->volume_mutex);
   self->priv->volume_idle_id = 0;
-  g_static_mutex_unlock (&self->priv->volume_mutex);
+  g_mutex_unlock (&self->priv->volume_mutex);
 
   g_object_notify (G_OBJECT (self), "volume");
 
@@ -245,7 +261,7 @@ empathy_audio_sink_volume_updated (GObject *object,
   EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (user_data);
   gdouble volume;
 
-  g_static_mutex_lock (&self->priv->volume_mutex);
+  g_mutex_lock (&self->priv->volume_mutex);
 
   g_object_get (object, "volume", &volume, NULL);
   if (self->priv->volume == volume)
@@ -257,13 +273,46 @@ empathy_audio_sink_volume_updated (GObject *object,
       empathy_audio_sink_volume_idle_updated, self);
 
 out:
-  g_static_mutex_unlock (&self->priv->volume_mutex);
+  g_mutex_unlock (&self->priv->volume_mutex);
+}
+
+static gboolean
+empathy_audio_sink_volume_idle_setup (gpointer user_data)
+{
+  EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (user_data);
+  gdouble volume;
+
+  g_mutex_lock (&self->priv->volume_mutex);
+  self->priv->volume_idle_id = 0;
+  g_mutex_unlock (&self->priv->volume_mutex);
+
+  /* We can't do a bidirection bind as the ::notify comes from another
+   * thread, for other bits of empathy it's most simpler if it comes from
+   * the main thread */
+  g_object_bind_property (self, "volume", self->priv->sink, "volume",
+    G_BINDING_DEFAULT);
+
+  /* sync and callback for bouncing */
+  g_object_get (self->priv->sink, "volume", &volume, NULL);
+  g_object_set (self, "volume", volume, NULL);
+  g_signal_connect (self->priv->sink, "notify::volume",
+    G_CALLBACK (empathy_audio_sink_volume_updated), self);
+
+  return FALSE;
 }
 
+#ifdef HAVE_GST1
+static GstPad *
+empathy_audio_sink_request_new_pad (GstElement *element,
+  GstPadTemplate *templ,
+  const gchar* name,
+  const GstCaps *caps)
+#else
 static GstPad *
 empathy_audio_sink_request_new_pad (GstElement *element,
   GstPadTemplate *templ,
   const gchar* name)
+#endif
 {
   EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (element);
   GstElement *bin, *resample, *audioconvert0, *audioconvert1;
@@ -296,18 +345,11 @@ empathy_audio_sink_request_new_pad (GstElement *element,
 
   if (GST_IS_STREAM_VOLUME (self->priv->sink))
     {
-      gdouble volume;
-      /* We can't do a bidirection bind as the ::notify comes from another
-       * thread, for other bits of empathy it's most simpler if it comes from
-       * the main thread */
-      g_object_bind_property (self, "volume", self->priv->sink, "volume",
-        G_BINDING_DEFAULT);
-
-      /* sync and callback for bouncing */
-      g_object_get (self->priv->sink, "volume", &volume, NULL);
-      g_object_set (self, "volume", volume, NULL);
-      g_signal_connect (self->priv->sink, "notify::volume",
-        G_CALLBACK (empathy_audio_sink_volume_updated), self);
+      g_mutex_lock (&self->priv->volume_mutex);
+      if (self->priv->volume_idle_id == 0)
+        self->priv->volume_idle_id = g_idle_add (
+          empathy_audio_sink_volume_idle_setup, self);
+      g_mutex_unlock (&self->priv->volume_mutex);
     }
   else
     {
@@ -329,6 +371,8 @@ empathy_audio_sink_request_new_pad (GstElement *element,
     goto error;
 
   subpad = gst_ghost_pad_new ("sink", filterpad);
+  gst_object_unref (filterpad);
+
   if (!gst_element_add_pad (GST_ELEMENT (bin), subpad))
     goto error;
 
@@ -374,6 +418,6 @@ empathy_audio_sink_set_echo_cancel (EmpathyGstAudioSink *sink,
   DEBUG ("Sink echo cancellation setting: %s", echo_cancel ? "on" : "off");
   sink->priv->echo_cancel = echo_cancel;
   if (sink->priv->sink != NULL)
-    empathy_call_set_stream_properties (sink->priv->sink,
+    empathy_audio_set_stream_properties (sink->priv->sink,
       sink->priv->echo_cancel);
 }