ekiga r7103 - in trunk: . lib/engine/components/gstreamer po



Author: jpuydt
Date: Fri Sep 26 18:01:34 2008
New Revision: 7103
URL: http://svn.gnome.org/viewvc/ekiga?rev=7103&view=rev

Log:
Preliminary gstreamer audio input manager

Added:
   trunk/lib/engine/components/gstreamer/gst-audioinput.cpp
   trunk/lib/engine/components/gstreamer/gst-audioinput.h
Modified:
   trunk/ChangeLog
   trunk/lib/engine/components/gstreamer/Makefile.am
   trunk/lib/engine/components/gstreamer/gst-main.cpp
   trunk/po/POTFILES.in

Modified: trunk/lib/engine/components/gstreamer/Makefile.am
==============================================================================
--- trunk/lib/engine/components/gstreamer/Makefile.am	(original)
+++ trunk/lib/engine/components/gstreamer/Makefile.am	Fri Sep 26 18:01:34 2008
@@ -9,12 +9,16 @@
 	-I$(top_srcdir)/lib/engine/framework		\
 	-I$(top_srcdir)/lib/engine/videoinput/skel	\
 	-I$(top_srcdir)/lib/engine/videooutput/skel	\
+	-I$(top_srcdir)/lib/engine/audioinput/skel	\
+	-I$(top_srcdir)/lib/engine/audiooutput/skel	\
 	-I$(top_srcdir)/lib/engine/hal/skel
 
 libgmgstreamer_la_SOURCES = \
 	$(gstreamer_dir)/gst-main.h \
 	$(gstreamer_dir)/gst-main.cpp \
 	$(gstreamer_dir)/gst-videoinput.h \
-	$(gstreamer_dir)/gst-videoinput.cpp
+	$(gstreamer_dir)/gst-videoinput.cpp \
+	$(gstreamer_dir)/gst-audioinput.h \
+	$(gstreamer_dir)/gst-audioinput.cpp
 
 libgmgstreamer_la_LDFLAGS = -export-dynamic -no-undefined $(SIGC_LIBS) $(GSTREAMER_LIBS) $(PTLIB_LIBS)

Added: trunk/lib/engine/components/gstreamer/gst-audioinput.cpp
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/gstreamer/gst-audioinput.cpp	Fri Sep 26 18:01:34 2008
@@ -0,0 +1,302 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         gst-audioinput.cpp  -  description
+ *                         ------------------------------------
+ *   begin                : Tue 23 September 2008
+ *   copyright            : (C) 2008 by Julien Puydt
+ *   description          : Gstreamer audio input code
+ *
+ */
+
+#include "config.h"
+
+#include "gst-audioinput.h"
+
+#include <gst/interfaces/propertyprobe.h>
+#include <gst/app/gstappsink.h>
+
+GST::AudioInputManager::AudioInputManager ()
+{
+  detect_devices ();
+}
+
+GST::AudioInputManager::~AudioInputManager ()
+{
+}
+
+void
+GST::AudioInputManager::get_devices (std::vector<Ekiga::AudioInputDevice>& devices)
+{
+  detect_devices ();
+
+  for (std::map<std::string, std::string>::const_iterator iter
+	 = devices_by_name.begin ();
+       iter != devices_by_name.end ();
+       ++iter) {
+
+    Ekiga::AudioInputDevice device;
+    device.type = "GStreamer";
+    device.source = "GStreamer";
+    device.name = iter->first;
+    devices.push_back (device);
+  }
+}
+
+bool
+GST::AudioInputManager::set_device (const Ekiga::AudioInputDevice& device)
+{
+  bool result = false;
+
+  if (device.type == "GStreamer"
+      && device.source == "GStreamer"
+      && devices_by_name.find (device.name) != devices_by_name.end ()) {
+
+    current_state.opened = false;
+    current_state.device = device;
+    result = true;
+  }
+  return result;
+}
+
+bool
+GST::AudioInputManager::open (unsigned channels,
+			      unsigned samplerate,
+			      unsigned bits_per_sample)
+{
+  bool result = false;
+  gchar* command = NULL;
+  GError* error = NULL;
+  GstState current;
+
+  command = g_strdup_printf ("%s ! appsink max_buffers=2 drop=true"
+			     " caps=audio/x-raw-int"
+			     ",rate=%d"
+			     ",channels=%d"
+			     ",width=%d"
+			     " name=ekiga_sink",
+			     devices_by_name[current_state.device.name].c_str (),
+			     samplerate, channels, bits_per_sample);
+  g_print ("Pipeline: %s\n", command);
+  pipeline = gst_parse_launch (command, &error);
+
+  if (error == NULL) {
+
+    (void)gst_element_set_state (pipeline, GST_STATE_PLAYING);
+
+    // this will make us wait so we can return the right value...
+    (void)gst_element_get_state (pipeline,
+				 &current,
+				 NULL,
+				 GST_SECOND);
+
+    if (current != GST_STATE_PLAYING) {
+
+      gst_element_set_state (pipeline, GST_STATE_NULL);
+      gst_object_unref (GST_OBJECT (pipeline));
+      pipeline = NULL;
+      result = false;
+    } else {
+
+      Ekiga::AudioInputSettings settings;
+      GstElement* volume = NULL;
+      gfloat val;
+
+      volume = gst_bin_get_by_name (GST_BIN (pipeline), "ekiga_volume");
+      if (volume != NULL) {
+
+	g_object_get (G_OBJECT (volume),
+		      "volume", &val,
+		      NULL);
+	settings.volume = (unsigned)(255*val);
+	settings.modifyable = true;
+      } else {
+
+	settings.modifyable = false;
+      }
+      current_state.channels = channels;
+      current_state.samplerate = samplerate;
+      current_state.bits_per_sample = bits_per_sample;
+      device_opened.emit (current_state.device, settings);
+      result = true;
+    }
+
+  } else {
+
+    g_error_free (error);
+    result = false;
+  }
+
+  g_free (command);
+
+  current_state.opened = result;
+  return result;
+}
+
+void
+GST::AudioInputManager::close ()
+{
+  if (pipeline != NULL) {
+
+    gst_element_set_state (pipeline, GST_STATE_NULL);
+    g_object_unref (pipeline);
+    pipeline = NULL;
+    device_closed.emit (current_state.device);
+  }
+  current_state.opened = false;
+}
+
+void
+GST::AudioInputManager::set_buffer_size (unsigned /*buffer_size*/,
+					 unsigned /*num_buffers*/)
+{
+  // FIXME: do I care?
+}
+
+bool
+GST::AudioInputManager::get_frame_data (char* data,
+					unsigned size,
+					unsigned& read)
+{
+  bool result = false;
+  GstBuffer* buffer = NULL;
+  GstElement* sink = NULL;
+
+  read = 0;
+
+  g_return_val_if_fail (GST_IS_BIN (pipeline), false);
+
+  sink = gst_bin_get_by_name (GST_BIN (pipeline), "ekiga_sink");
+
+  if (sink != NULL) {
+
+    buffer = gst_app_sink_pull_buffer (GST_APP_SINK (sink));
+
+    if (buffer != NULL) {
+
+      read = MIN (GST_BUFFER_SIZE (buffer), size);
+      memcpy (data, GST_BUFFER_DATA (buffer), read);
+      result = true;
+      gst_buffer_unref (buffer);
+    }
+    g_object_unref (sink);
+  }
+
+  return result;
+}
+
+void
+GST::AudioInputManager::set_volume (unsigned valu)
+{
+  GstElement* volume = NULL;
+  gfloat valf;
+
+  valf = valu / 255.0;
+
+  volume = gst_bin_get_by_name (GST_BIN (pipeline), "ekiga_volume");
+  if (volume != NULL) {
+
+    g_object_set (G_OBJECT (volume),
+		  "volume", valf,
+		  NULL);
+  }
+}
+
+bool
+GST::AudioInputManager::has_device (const std::string& /*source*/,
+				    const std::string& device_name,
+				    Ekiga::AudioInputDevice& /*device*/)
+{
+  return (devices_by_name.find (device_name) != devices_by_name.end ());
+}
+
+void
+GST::AudioInputManager::detect_devices ()
+{
+  devices_by_name.clear ();
+  detect_audiotestsrc_devices ();
+  detect_alsasrc_devices ();
+}
+
+void
+GST::AudioInputManager::detect_audiotestsrc_devices ()
+{
+  GstElement* elt = NULL;
+
+  elt = gst_element_factory_make ("audiotestsrc", "audiotestsrcpresencetest");
+
+  if (elt != NULL) {
+
+    devices_by_name[_("Audio test")] = "audiotestsrc name=ekiga_volume";
+    gst_object_unref (GST_OBJECT (elt));
+  }
+}
+
+void
+GST::AudioInputManager::detect_alsasrc_devices ()
+{
+  GstElement* elt = NULL;
+
+  elt = gst_element_factory_make ("alsasrc", "alsasrcpresencetest");
+
+  if (elt != NULL) {
+
+    GstPropertyProbe* probe = NULL;
+    const GParamSpec* pspec = NULL;
+    GValueArray* array = NULL;
+
+    gst_element_set_state (elt, GST_STATE_PAUSED);
+    probe = GST_PROPERTY_PROBE (elt);
+    pspec = gst_property_probe_get_property (probe, "device");
+
+    array = gst_property_probe_probe_and_get_values (probe, pspec);
+    if (array != NULL) {
+
+      for (guint index = 0; index < array->n_values; index++) {
+
+	GValue* device = NULL;
+	gchar* name = NULL;
+	gchar* descr = NULL;
+
+	device = g_value_array_get_nth (array, index);
+	g_object_set_property (G_OBJECT (elt), "device", device);
+	g_object_get (G_OBJECT (elt), "device-name", &name, NULL);
+	descr = g_strdup_printf ("alsasrc device=%s ! volume name=ekiga_volume",
+				 g_value_get_string (device));
+
+	devices_by_name[name] = descr;
+	g_free (name);
+	g_free (descr);
+      }
+    }
+    
+    gst_element_set_state (elt, GST_STATE_NULL);
+    gst_object_unref (GST_OBJECT (elt));
+  }
+}

Added: trunk/lib/engine/components/gstreamer/gst-audioinput.h
==============================================================================
--- (empty file)
+++ trunk/lib/engine/components/gstreamer/gst-audioinput.h	Fri Sep 26 18:01:34 2008
@@ -0,0 +1,90 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2008 Damien Sandras
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         gst-audioinput.h  -  description
+ *                         ------------------------------------
+ *   begin                : Tue 23 September 2008
+ *   copyright            : (C) 2008 by Julien Puydt
+ *   description          : Gstreamer audio input code
+ *
+ */
+
+#ifndef __GST_AUDIOINPUT_H__
+#define __GST_AUDIOINPUT_H__
+
+#include "audioinput-manager.h"
+#include <gst/gst.h>
+
+namespace GST
+{
+  class AudioInputManager: public Ekiga::AudioInputManager
+  {
+  public:
+
+    AudioInputManager ();
+
+    ~AudioInputManager ();
+
+    void get_devices (std::vector<Ekiga::AudioInputDevice>& devices);
+
+    bool set_device (const Ekiga::AudioInputDevice& device);
+
+    bool open (unsigned channels,
+	       unsigned samplerate,
+	       unsigned bits_per_sample);
+
+    void close ();
+
+    void set_buffer_size (unsigned buffer_size,
+			  unsigned num_buffers);
+
+    bool get_frame_data (char* data,
+			 unsigned size,
+			 unsigned& read);
+
+    void set_volume (unsigned volume);
+
+    bool has_device (const std::string& source,
+		     const std::string& device_name,
+		     Ekiga::AudioInputDevice& device);
+  private:
+
+    void detect_devices ();
+    void detect_audiotestsrc_devices ();
+    void detect_alsasrc_devices ();
+
+    /* we take a user-readable name, and get the string describing
+     * the actual device */
+    std::map<std::string, std::string> devices_by_name;
+
+    GstElement* pipeline;
+  };
+};
+
+#endif

Modified: trunk/lib/engine/components/gstreamer/gst-main.cpp
==============================================================================
--- trunk/lib/engine/components/gstreamer/gst-main.cpp	(original)
+++ trunk/lib/engine/components/gstreamer/gst-main.cpp	Fri Sep 26 18:01:34 2008
@@ -35,9 +35,9 @@
  *
  */
 
-#include "videoinput-core.h"
 #include "gst-main.h"
 #include "gst-videoinput.h"
+#include "gst-audioinput.h"
 
 bool
 gstreamer_init (Ekiga::ServiceCore& core,
@@ -46,16 +46,22 @@
 {
   bool result = false;
   Ekiga::VideoInputCore* videoinput_core = NULL;
+  Ekiga::AudioInputCore* audioinput_core = NULL;
 
   videoinput_core
     = dynamic_cast<Ekiga::VideoInputCore*>(core.get ("videoinput-core"));
 
-  if (videoinput_core != NULL) {
+  audioinput_core
+    = dynamic_cast<Ekiga::AudioInputCore*>(core.get ("audioinput-core"));
 
-    GST::VideoInputManager* manager = new GST::VideoInputManager ();
+  if (videoinput_core != NULL && audioinput_core != NULL) {
+
+    GST::VideoInputManager* video = new GST::VideoInputManager ();
+    GST::AudioInputManager* audio = new GST::AudioInputManager ();
 
     gst_init (argc, argv);
-    videoinput_core->add_manager (*manager);
+    videoinput_core->add_manager (*video);
+    audioinput_core->add_manager (*audio);
     result = true;
   }
 

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Fri Sep 26 18:01:34 2008
@@ -8,6 +8,7 @@
 lib/engine/addressbook/ldap/ldap-source.cpp
 lib/engine/addressbook/ldap/ldap-book.cpp
 lib/engine/addressbook/skel/contact-core.cpp
+lib/engine/components/gstreamer/gst-audioinput.cpp
 lib/engine/components/gstreamer/gst-videoinput.cpp
 lib/engine/gui/gtk-frontend/addressbook-window.cpp
 lib/engine/gui/gtk-frontend/book-view-gtk.cpp



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