]> git.0d.be Git - empathy.git/blobdiff - src/empathy-audio-sink.c
remove released flag
[empathy.git] / src / empathy-audio-sink.c
index d912e1d2d44b4369a0c24e561b45fbecf2905540..f3a78bf3fc1ac16906bc80063574fc5c7fc0aaf6 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>
-#include <gst/interfaces/streamvolume.h>
-
-#include <telepathy-glib/telepathy-glib.h>
+#include <gst/audio/streamvolume.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 +44,7 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE(
     "sink%d",
     GST_PAD_SINK,
     GST_PAD_REQUEST,
-    GST_STATIC_CAPS ( GST_AUDIO_INT_PAD_TEMPLATE_CAPS " ; "
-        GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS)
+    GST_STATIC_CAPS ( "audio/x-raw" )
 );
 
 enum {
@@ -64,7 +57,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 +69,13 @@ 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);
 }
 
 static GstPad * empathy_audio_sink_request_new_pad (GstElement *self,
   GstPadTemplate *templ,
-  const gchar* name);
+  const gchar* name,
+  const GstCaps *caps);
 
 static void empathy_audio_sink_release_pad (GstElement *self,
   GstPad *pad);
@@ -94,9 +88,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 +122,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 +212,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 +229,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 +246,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,7 +258,7 @@ 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
@@ -266,9 +267,9 @@ empathy_audio_sink_volume_idle_setup (gpointer user_data)
   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);
   self->priv->volume_idle_id = 0;
-  g_static_mutex_unlock (&self->priv->volume_mutex);
+  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
@@ -288,7 +289,8 @@ empathy_audio_sink_volume_idle_setup (gpointer user_data)
 static GstPad *
 empathy_audio_sink_request_new_pad (GstElement *element,
   GstPadTemplate *templ,
-  const gchar* name)
+  const gchar* name,
+  const GstCaps *caps)
 {
   EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (element);
   GstElement *bin, *resample, *audioconvert0, *audioconvert1;
@@ -321,11 +323,11 @@ empathy_audio_sink_request_new_pad (GstElement *element,
 
   if (GST_IS_STREAM_VOLUME (self->priv->sink))
     {
-      g_static_mutex_lock (&self->priv->volume_mutex);
+      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_static_mutex_unlock (&self->priv->volume_mutex);
+      g_mutex_unlock (&self->priv->volume_mutex);
     }
   else
     {
@@ -347,6 +349,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;
 
@@ -392,6 +396,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);
 }