]> git.0d.be Git - empathy.git/commitdiff
audio-src: Add a caps filter to select appropriate input format
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 31 Oct 2011 13:12:56 +0000 (18:42 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 9 Nov 2011 09:40:34 +0000 (15:10 +0530)
Instead of relying on the default caps that the pipeline selects (which
will usually end up being float32 stereo at 44.1kHz), this sets a caps
filter to select the format we want from pulsesrc -- s16ne mono at 32kHz.

The point of this is to do resampling/conversion as early in the
pipeline as possible, decreasing the amount of data that needs to be
carried around and thus improving performance a bit.

src/empathy-audio-src.c

index bd3c433fad5ced3dba01ad6dfe5851c7f7a5ca84..350a29a8d161a608bb157217f0cb6e863e1d346e 100644 (file)
@@ -217,6 +217,8 @@ empathy_audio_src_init (EmpathyGstAudioSrc *obj)
 {
   EmpathyGstAudioSrcPrivate *priv = EMPATHY_GST_AUDIO_SRC_GET_PRIVATE (obj);
   GstPad *ghost, *src;
+  GstElement *capsfilter;
+  GstCaps *caps;
 
   priv->peak_level = -G_MAXDOUBLE;
   priv->lock = g_mutex_new ();
@@ -227,11 +229,27 @@ empathy_audio_src_init (EmpathyGstAudioSrc *obj)
 
   gst_bin_add (GST_BIN (obj), priv->src);
 
+  /* Explicitly state what format we want from pulsesrc. This pushes resampling
+   * and format conversion as early as possible, lowering the amount of data
+   * transferred and thus improving performance. When moving to GStreamer
+   * 0.11/1.0, this should change so that we actually request what the encoder
+   * wants downstream. */
+  caps = gst_caps_new_simple ("audio/x-raw-int",
+      "channels", G_TYPE_INT, 1,
+      "width", G_TYPE_INT, 16,
+      "depth", G_TYPE_INT, 16,
+      "rate", G_TYPE_INT, 32000,
+      NULL);
+  capsfilter = gst_element_factory_make ("capsfilter", NULL);
+  g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
+  gst_bin_add (GST_BIN (obj), capsfilter);
+  gst_element_link (priv->src, capsfilter);
+
   priv->volume = gst_element_factory_make ("volume", NULL);
   g_object_ref (priv->volume);
 
   gst_bin_add (GST_BIN (obj), priv->volume);
-  gst_element_link (priv->src, priv->volume);
+  gst_element_link (capsfilter, priv->volume);
 
   priv->level = gst_element_factory_make ("level", NULL);
   gst_bin_add (GST_BIN (obj), priv->level);