[ekiga] Factorized out the main gstreamer features



commit 2582fdbc47ab7ba12fd4d467ea726e6bfa8a8299
Author: Julien Puydt <jpuydt newton localdomain>
Date:   Wed Feb 1 18:28:23 2012 +0100

    Factorized out the main gstreamer features
    
    Now that I have made the video input, audio input and audio output
    look that much alike, I can factorize things in a header-source pair.
    
    That doesn't work better, but it works as good and is shorter.

 plugins/gstreamer/Makefile.am         |    2 +
 plugins/gstreamer/gst-audioinput.cpp  |  116 +----------------------
 plugins/gstreamer/gst-audioinput.h    |    4 +-
 plugins/gstreamer/gst-audiooutput.cpp |  112 ++---------------------
 plugins/gstreamer/gst-audiooutput.h   |    5 +-
 plugins/gstreamer/gst-helper.cpp      |  162 +++++++++++++++++++++++++++++++++
 plugins/gstreamer/gst-helper.h        |   74 +++++++++++++++
 plugins/gstreamer/gst-videoinput.cpp  |   77 +---------------
 plugins/gstreamer/gst-videoinput.h    |    4 +-
 9 files changed, 263 insertions(+), 293 deletions(-)
---
diff --git a/plugins/gstreamer/Makefile.am b/plugins/gstreamer/Makefile.am
index 5adf90d..4172ca9 100644
--- a/plugins/gstreamer/Makefile.am
+++ b/plugins/gstreamer/Makefile.am
@@ -14,6 +14,8 @@ INCLUDES = 						\
 	-I$(top_srcdir)/lib/engine/hal
 
 libgmgstreamer_la_SOURCES = \
+	$(gstreamer_dir)/gst-helper.h \
+	$(gstreamer_dir)/gst-helper.cpp \
 	$(gstreamer_dir)/gst-main.h \
 	$(gstreamer_dir)/gst-main.cpp \
 	$(gstreamer_dir)/gst-videoinput.h \
diff --git a/plugins/gstreamer/gst-audioinput.cpp b/plugins/gstreamer/gst-audioinput.cpp
index 3af8036..9a512df 100644
--- a/plugins/gstreamer/gst-audioinput.cpp
+++ b/plugins/gstreamer/gst-audioinput.cpp
@@ -45,105 +45,6 @@
 
 #include <string.h>
 
-struct gstreamer_worker
-{
-  GstElement* pipeline;
-  GstElement* volume;
-  GstElement* sink;
-};
-
-static void
-gstreamer_worker_setup (gstreamer_worker* self,
-			const gchar* command)
-{
-  g_message ("%s\t%s\n", __PRETTY_FUNCTION__, command);
-  self->pipeline = gst_parse_launch (command, NULL);
-  (void)gst_element_set_state (self->pipeline, GST_STATE_PLAYING);
-  self->volume = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_volume");
-  self->sink = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_sink");
-}
-
-static void
-gstreamer_worker_destroy (gstreamer_worker* self)
-{
-  g_object_unref (self->sink);
-  self->sink = NULL;
-  if (self->volume)
-    g_object_unref (self->volume);
-  self->volume = NULL;
-  g_object_unref (self->pipeline);
-  self->pipeline = NULL;
-  g_free (self);
-}
-
-static void
-gstreamer_worker_close (gstreamer_worker* self)
-{
-  g_message ("%s\n", __PRETTY_FUNCTION__);
-  gst_element_set_state (self->pipeline, GST_STATE_NULL);
-  Ekiga::Runtime::run_in_main (boost::bind(&gstreamer_worker_destroy, self), 1);
-}
-
-static void
-gstreamer_worker_set_volume (gstreamer_worker* self,
-			     gfloat valf)
-{
-  g_message ("%s\t%f\n", __PRETTY_FUNCTION__, valf);
-  if (self->volume)
-    g_object_set (G_OBJECT (self->volume),
-		  "volume", valf,
-		  NULL);
-}
-
-static gfloat
-gstreamer_worker_get_volume (gstreamer_worker* self)
-{
-  gfloat result = -1;
-  if (self->volume)
-    g_object_get (G_OBJECT (self->volume),
-		  "volume", &result,
-		  NULL);
-
-  return result;
-}
-
-static void
-gstreamer_worker_set_buffer_size (gstreamer_worker* self,
-				  unsigned size)
-{
-  g_message ("%s\t%d\n", __PRETTY_FUNCTION__, size);
-  if (self->sink)
-    g_object_set (G_OBJECT (self->sink),
-		  "blocksize", size,
-		  NULL);
-}
-
-
-
-bool
-gstreamer_worker_get_frame_data (gstreamer_worker* self,
-				 char* data,
-				 unsigned size,
-				 unsigned& read)
-{
-  bool result = false;
-  GstBuffer* buffer = NULL;
-
-  read = 0;
-
-  buffer = gst_app_sink_pull_buffer (GST_APP_SINK (self->sink));
-
-  if (buffer != NULL) {
-
-    read = MIN (GST_BUFFER_SIZE (buffer), size);
-    memcpy (data, GST_BUFFER_DATA (buffer), read);
-    result = true;
-    gst_buffer_unref (buffer);
-  }
-
-  return result;
-}
-
 GST::AudioInputManager::AudioInputManager ():
   already_detected_devices(false), worker(NULL)
 {
@@ -194,11 +95,8 @@ GST::AudioInputManager::open (unsigned channels,
 			      unsigned samplerate,
 			      unsigned bits_per_sample)
 {
-  g_message ("%s\n", __PRETTY_FUNCTION__);
   gchar* command = NULL;
 
-  worker = g_new0 (gstreamer_worker, 1);
-
   if ( !already_detected_devices)
     detect_devices ();
 
@@ -211,11 +109,11 @@ GST::AudioInputManager::open (unsigned channels,
 			     devices_by_name[std::pair<std::string,std::string>(current_state.device.source, current_state.device.name)].c_str (),
 			     samplerate, channels, bits_per_sample);
 
-  gstreamer_worker_setup (worker, command);
+  worker = gst_helper_new (command);
   g_free (command);
 
   Ekiga::AudioInputSettings settings;
-  gfloat vol = gstreamer_worker_get_volume (worker);
+  gfloat vol = gst_helper_get_volume (worker);
   if (vol >= 0) {
 
     settings.volume = (unsigned)(255*vol);
@@ -234,10 +132,8 @@ GST::AudioInputManager::open (unsigned channels,
 void
 GST::AudioInputManager::close ()
 {
-  g_message ("%s\n", __PRETTY_FUNCTION__);
-
   if (worker)
-      gstreamer_worker_close (worker);
+    gst_helper_close (worker);
   Ekiga::Runtime::run_in_main (boost::bind (boost::ref(device_closed),
 					    current_state.device));
   current_state.opened = false;
@@ -249,7 +145,7 @@ GST::AudioInputManager::set_buffer_size (unsigned buffer_size,
 					 unsigned /*num_buffers*/)
 {
   if (worker)
-    gstreamer_worker_set_buffer_size (worker, buffer_size);
+    gst_helper_set_buffer_size (worker, buffer_size);
 }
 
 bool
@@ -260,7 +156,7 @@ GST::AudioInputManager::get_frame_data (char* data,
   bool result = false;
   read = 0;
   if (worker)
-    result = gstreamer_worker_get_frame_data (worker, data, size, read);
+    result = gst_helper_get_frame_data (worker, data, size, read);
 
   return result;
 }
@@ -268,7 +164,7 @@ GST::AudioInputManager::get_frame_data (char* data,
 void
 GST::AudioInputManager::set_volume (unsigned valu)
 {
-  gstreamer_worker_set_volume (worker, valu / 255.0);
+  gst_helper_set_volume (worker, valu / 255.0);
 }
 
 bool
diff --git a/plugins/gstreamer/gst-audioinput.h b/plugins/gstreamer/gst-audioinput.h
index 0009190..915cf97 100644
--- a/plugins/gstreamer/gst-audioinput.h
+++ b/plugins/gstreamer/gst-audioinput.h
@@ -44,7 +44,7 @@
 
 #include <map>
 
-struct gstreamer_worker;
+#include "gst-helper.h"
 
 namespace GST
 {
@@ -90,7 +90,7 @@ namespace GST
      * the actual device */
     std::map<std::pair<std::string, std::string>, std::string> devices_by_name;
 
-    gstreamer_worker* worker;
+    gst_helper* worker;
   };
 };
 
diff --git a/plugins/gstreamer/gst-audiooutput.cpp b/plugins/gstreamer/gst-audiooutput.cpp
index f02bb79..f577dd4 100644
--- a/plugins/gstreamer/gst-audiooutput.cpp
+++ b/plugins/gstreamer/gst-audiooutput.cpp
@@ -40,108 +40,16 @@
 #include <glib/gi18n.h>
 
 #include <gst/interfaces/propertyprobe.h>
-#include <gst/app/gstappsrc.h>
-#include <gst/app/gstappbuffer.h>
 
 #include "runtime.h"
 
 #include "gst-audiooutput.h"
 
-struct gstreamer_worker
-{
-  GstElement* pipeline;
-  GstElement* volume;
-  GstElement* src;
-};
-
-static void
-gstreamer_worker_setup (gstreamer_worker* self,
-			const gchar* command)
-{
-  g_message ("%s\t%s\n", __PRETTY_FUNCTION__, command);
-  self->pipeline = gst_parse_launch (command, NULL);
-  (void)gst_element_set_state (self->pipeline, GST_STATE_PLAYING);
-  self->volume = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_volume");
-  self->src = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_src");
-}
-
-static void
-gstreamer_worker_destroy (gstreamer_worker* self)
-{
-  g_object_unref (self->src);
-  self->src = NULL;
-  if (self->volume)
-    g_object_unref (self->volume);
-  self->volume = NULL;
-  g_object_unref (self->pipeline);
-  self->pipeline = NULL;
-  g_free (self);
-}
-
-static void
-gstreamer_worker_close (gstreamer_worker* self)
-{
-  g_message ("%s\n", __PRETTY_FUNCTION__);
-  if (self->src)
-    gst_app_src_end_of_stream (GST_APP_SRC (self->src));
-  Ekiga::Runtime::run_in_main (boost::bind(&gstreamer_worker_destroy, self), 1);
-}
-
-static void
-gstreamer_worker_set_volume (gstreamer_worker* self,
-			     gfloat valf)
-{
-  g_message ("%s\t%f\n", __PRETTY_FUNCTION__, valf);
-  if (self->volume)
-    g_object_set (G_OBJECT (self->volume),
-		  "volume", valf,
-		  NULL);
-}
-
-static gfloat
-gstreamer_worker_get_volume (gstreamer_worker* self)
-{
-  gfloat result = -1;
-  if (self->volume)
-    g_object_get (G_OBJECT (self->volume),
-		  "volume", &result,
-		  NULL);
-
-  return result;
-}
-
-static void
-gstreamer_worker_set_buffer_size (gstreamer_worker* self,
-				  unsigned size)
-{
-  g_message ("%s\t%d\n", __PRETTY_FUNCTION__, size);
-  if (self->src)
-    g_object_set (G_OBJECT (self->src),
-		  "blocksize", size,
-		  NULL);
-}
-
-static void
-gstreamer_worker_set_frame_data (gstreamer_worker* self,
-				 const char* data,
-				 unsigned size)
-{
-  gchar* tmp = NULL;
-  GstBuffer* buffer = NULL;
-
-  if (self->src) {
-
-    tmp = (gchar*)g_malloc0 (size);
-    memcpy (tmp, data, size);
-    buffer = gst_app_buffer_new (tmp, size,
-				 (GstAppBufferFinalizeFunc)g_free, tmp);
-    gst_app_src_push_buffer (GST_APP_SRC (self->src), buffer);
-  }
-}
-
 GST::AudioOutputManager::AudioOutputManager ():
   already_detected_devices(false)
 {
+  worker[0]=NULL;
+  worker[1]=NULL;
 }
 
 GST::AudioOutputManager::~AudioOutputManager ()
@@ -192,12 +100,9 @@ GST::AudioOutputManager::open (Ekiga::AudioOutputPS ps,
 			       unsigned samplerate,
 			       unsigned bits_per_sample)
 {
-  g_message ("%s\n", __PRETTY_FUNCTION__);
   unsigned ii = (ps == Ekiga::primary)?0:1;
   gchar* command = NULL;
 
-  worker[ii] = g_new0 (gstreamer_worker, 1);
-
   if ( !already_detected_devices)
     detect_devices ();
 
@@ -211,11 +116,11 @@ GST::AudioOutputManager::open (Ekiga::AudioOutputPS ps,
 			     " ! audiorate ! %s",
 			     samplerate, channels, bits_per_sample, bits_per_sample,
 			     devices_by_name[std::pair<std::string,std::string>(current_state[ii].device.source, current_state[ii].device.name)].c_str ());
-  gstreamer_worker_setup (worker[ii], command);
+  worker[ii] = gst_helper_new (command);
   g_free (command);
 
   Ekiga::AudioOutputSettings settings;
-  gfloat vol = gstreamer_worker_get_volume (worker[ii]);
+  gfloat vol = gst_helper_get_volume (worker[ii]);
   if (vol >= 0) {
 
     settings.volume = (unsigned)(255*vol);
@@ -236,11 +141,10 @@ GST::AudioOutputManager::open (Ekiga::AudioOutputPS ps,
 void
 GST::AudioOutputManager::close (Ekiga::AudioOutputPS ps)
 {
-  g_message ("%s\n", __PRETTY_FUNCTION__);
   unsigned ii = (ps == Ekiga::primary)?0:1;
 
   if (worker[ii])
-      gstreamer_worker_close (worker[ii]);
+    gst_helper_close (worker[ii]);
   Ekiga::Runtime::run_in_main (boost::bind (boost::ref(device_closed), ps, current_state[ii].device));
   current_state[ii].opened = false;
   worker[ii] = NULL;
@@ -252,7 +156,7 @@ GST::AudioOutputManager::set_buffer_size (Ekiga::AudioOutputPS ps,
 					  unsigned /*num_buffers*/)
 {
   unsigned ii = (ps == Ekiga::primary)?0:1;
-  gstreamer_worker_set_buffer_size (worker[ii], buffer_size);
+  gst_helper_set_buffer_size (worker[ii], buffer_size);
 }
 
 bool
@@ -266,7 +170,7 @@ GST::AudioOutputManager::set_frame_data (Ekiga::AudioOutputPS ps,
 
   if (worker[ii]) {
 
-    gstreamer_worker_set_frame_data (worker[ii], data, size);
+    gst_helper_set_frame_data (worker[ii], data, size);
     written = size;
     result = true;
   } else {
@@ -284,7 +188,7 @@ GST::AudioOutputManager::set_volume (Ekiga::AudioOutputPS ps,
 {
   unsigned ii = (ps == Ekiga::primary)?0:1;
 
-  gstreamer_worker_set_volume (worker[ii], valu / 255.0);
+  gst_helper_set_volume (worker[ii], valu / 255.0);
 }
 
 bool
diff --git a/plugins/gstreamer/gst-audiooutput.h b/plugins/gstreamer/gst-audiooutput.h
index ff4a2e5..52c7fb3 100644
--- a/plugins/gstreamer/gst-audiooutput.h
+++ b/plugins/gstreamer/gst-audiooutput.h
@@ -40,11 +40,10 @@
 
 #include "audiooutput-manager.h"
 #include <gst/gst.h>
+#include "gst-helper.h"
 
 #include <map>
 
-struct gstreamer_worker;
-
 namespace GST
 {
   class AudioOutputManager: public Ekiga::AudioOutputManager
@@ -95,7 +94,7 @@ namespace GST
      * the actual device */
     std::map<std::pair<std::string, std::string>, std::string> devices_by_name;
 
-    gstreamer_worker* worker[2];
+    gst_helper* worker[2];
   };
 };
 
diff --git a/plugins/gstreamer/gst-helper.cpp b/plugins/gstreamer/gst-helper.cpp
new file mode 100644
index 0000000..ed978dc
--- /dev/null
+++ b/plugins/gstreamer/gst-helper.cpp
@@ -0,0 +1,162 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2012 Damien Sandras <dsandras seconix com>
+ *
+ * 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-helper.cpp  -  description
+ *                         ------------------------------------
+ *   begin                : Wed 1 February 2012
+ *   copyright            : (C) 2012 by Julien Puydt
+ *   description          : Gstreamer helper code implementation
+ *
+ */
+
+#include "gst-helper.h"
+#include "runtime.h"
+
+#include <gst/app/gstappsrc.h>
+#include <gst/app/gstappsink.h>
+#include <gst/app/gstappbuffer.h>
+
+struct gst_helper
+{
+  GstElement* pipeline;
+  GstElement* active;
+  GstElement* volume;
+};
+
+
+gst_helper*
+gst_helper_new (const gchar* command)
+{
+  g_message ("%s\t%s\n", __PRETTY_FUNCTION__, command);
+  gst_helper* self = g_new0 (gst_helper, 1);
+  self->pipeline = gst_parse_launch (command, NULL);
+  (void)gst_element_set_state (self->pipeline, GST_STATE_PLAYING);
+  self->volume = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_volume");
+  self->active = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_sink");
+  if (self->active == NULL)
+    self->active = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_src");
+
+  return self;
+}
+
+static void
+gst_helper_destroy (gst_helper* self)
+{
+  gst_element_set_state (self->pipeline, GST_STATE_NULL);
+  g_object_unref (self->active);
+  self->active = NULL;
+  if (self->volume)
+    g_object_unref (self->volume);
+  self->volume = NULL;
+  g_object_unref (self->pipeline);
+  self->pipeline = NULL;
+  g_free (self);
+}
+
+void
+gst_helper_close (gst_helper* self)
+{
+  g_message ("%s\n", __PRETTY_FUNCTION__);
+  Ekiga::Runtime::run_in_main (boost::bind(&gst_helper_destroy, self), 2);
+}
+
+bool
+gst_helper_get_frame_data (gst_helper* self,
+			   char* data,
+			   unsigned size,
+			   unsigned& read)
+{
+  bool result = false;
+  GstBuffer* buffer = NULL;
+
+  read = 0;
+
+  buffer = gst_app_sink_pull_buffer (GST_APP_SINK (self->active));
+
+  if (buffer != NULL) {
+
+    read = MIN (GST_BUFFER_SIZE (buffer), size);
+    memcpy (data, GST_BUFFER_DATA (buffer), read);
+    result = true;
+    gst_buffer_unref (buffer);
+  }
+
+  return result;
+}
+
+void
+gst_helper_set_frame_data (gst_helper* self,
+			   const char* data,
+			   unsigned size)
+{
+  gchar* tmp = NULL;
+  GstBuffer* buffer = NULL;
+
+  if (self->active) {
+
+    tmp = (gchar*)g_malloc0 (size);
+    memcpy (tmp, data, size);
+    buffer = gst_app_buffer_new (tmp, size,
+				 (GstAppBufferFinalizeFunc)g_free, tmp);
+    gst_app_src_push_buffer (GST_APP_SRC (self->active), buffer);
+  }
+}
+
+void
+gst_helper_set_volume (gst_helper* self,
+		       gfloat valf)
+{
+  if (self->volume)
+    g_object_set (G_OBJECT (self->volume),
+		  "volume", valf,
+		  NULL);
+}
+
+gfloat
+gst_helper_get_volume (gst_helper* self)
+{
+  gfloat result = -1;
+  if (self->volume)
+    g_object_get (G_OBJECT (self->volume),
+		  "volume", &result,
+		  NULL);
+
+  return result;
+}
+
+void
+gst_helper_set_buffer_size (gst_helper* self,
+			    unsigned size)
+{
+  g_message ("%s\t%d\n", __PRETTY_FUNCTION__, size);
+  if (self->active)
+    g_object_set (G_OBJECT (self->active),
+		  "blocksize", size,
+		  NULL);
+}
diff --git a/plugins/gstreamer/gst-helper.h b/plugins/gstreamer/gst-helper.h
new file mode 100644
index 0000000..65a1492
--- /dev/null
+++ b/plugins/gstreamer/gst-helper.h
@@ -0,0 +1,74 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2012 Damien Sandras <dsandras seconix com>
+ *
+ * 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-helper.h  -  description
+ *                         ------------------------------------
+ *   begin                : Wed 1 February 2012
+ *   copyright            : (C) 2012 by Julien Puydt
+ *   description          : Gstreamer helper code declaration
+ *
+ */
+
+
+/* This code is a factorization of a pattern common to the three gstreamer
+ * classes in the ekiga plugin code :
+ * - there must be a way to create a new helper, which can have an optional
+ * ekiga_volume element, and a mandatory active element, which is either an
+ * ekiga_sink or an ekiga_src ;
+ * - it should be possible to ask this helper to just kill itself ;
+ * - it should be possible to either put data into it, or get data from it ;
+ * - the optional volume should be modifyable (-1 means the option is disabled) ;
+ * - it should be possible to set the buffer size.
+ */
+
+
+#include <glib/gi18n.h>
+
+struct gst_helper;
+
+gst_helper* gst_helper_new (const gchar* command);
+
+void gst_helper_close (gst_helper* self);
+
+bool gst_helper_get_frame_data (gst_helper* self,
+				char* data,
+				unsigned size,
+				unsigned& read);
+
+void gst_helper_set_frame_data (gst_helper* self,
+				const char* data,
+				unsigned size);
+
+void gst_helper_set_volume (gst_helper* self,
+			    gfloat valf);
+
+gfloat gst_helper_get_volume (gst_helper* self);
+
+void gst_helper_set_buffer_size (gst_helper* self,
+				 unsigned size);
diff --git a/plugins/gstreamer/gst-videoinput.cpp b/plugins/gstreamer/gst-videoinput.cpp
index 7c5c976..2754f74 100644
--- a/plugins/gstreamer/gst-videoinput.cpp
+++ b/plugins/gstreamer/gst-videoinput.cpp
@@ -45,69 +45,6 @@
 
 #include <string.h>
 
-struct gstreamer_worker
-{
-  GstElement* pipeline;
-  GstElement* volume;
-  GstElement* sink;
-};
-
-static void
-gstreamer_worker_setup (gstreamer_worker* self,
-			const gchar* command)
-{
-  g_message ("%s\t%s\n", __PRETTY_FUNCTION__, command);
-  self->pipeline = gst_parse_launch (command, NULL);
-  (void)gst_element_set_state (self->pipeline, GST_STATE_PLAYING);
-  self->volume = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_volume");
-  self->sink = gst_bin_get_by_name (GST_BIN (self->pipeline), "ekiga_sink");
-}
-
-static void
-gstreamer_worker_destroy (gstreamer_worker* self)
-{
-  g_object_unref (self->sink);
-  self->sink = NULL;
-  if (self->volume)
-    g_object_unref (self->volume);
-  self->volume = NULL;
-  g_object_unref (self->pipeline);
-  self->pipeline = NULL;
-  g_free (self);
-}
-
-static void
-gstreamer_worker_close (gstreamer_worker* self)
-{
-  g_message ("%s\n", __PRETTY_FUNCTION__);
-  gst_element_set_state (self->pipeline, GST_STATE_NULL);
-  Ekiga::Runtime::run_in_main (boost::bind(&gstreamer_worker_destroy, self), 1);
-}
-
-static bool
-gstreamer_worker_get_frame_data (gstreamer_worker* self,
-				 char* data,
-				 unsigned size,
-				 unsigned& read)
-{
-  bool result = false;
-  GstBuffer* buffer = NULL;
-
-  read = 0;
-
-  buffer = gst_app_sink_pull_buffer (GST_APP_SINK (self->sink));
-
-  if (buffer != NULL) {
-
-    read = MIN (GST_BUFFER_SIZE (buffer), size);
-    memcpy (data, GST_BUFFER_DATA (buffer), read);
-    result = true;
-    gst_buffer_unref (buffer);
-  }
-
-  return result;
-}
-
 GST::VideoInputManager::VideoInputManager ():
   already_detected_devices(false), worker(NULL)
 {
@@ -169,8 +106,6 @@ GST::VideoInputManager::open (unsigned width,
 {
   gchar* command = NULL;
 
-  worker = g_new0 (gstreamer_worker, 1);
-
   if ( !already_detected_devices)
     detect_devices ();
 
@@ -183,7 +118,7 @@ GST::VideoInputManager::open (unsigned width,
 			     devices_by_name[std::pair<std::string,std::string>(current_state.device.source, current_state.device.name)].c_str (),
 			     width, height, fps);
 
-  gstreamer_worker_setup (worker, command);
+  worker = gst_helper_new (command);
   g_free (command);
 
   Ekiga::VideoInputSettings settings;
@@ -196,10 +131,8 @@ GST::VideoInputManager::open (unsigned width,
 void
 GST::VideoInputManager::close ()
 {
-  g_message ("%s\n", __PRETTY_FUNCTION__);
-
   if (worker)
-      gstreamer_worker_close (worker);
+    gst_helper_close (worker);
   Ekiga::Runtime::run_in_main (boost::bind (boost::ref(device_closed),
 					    current_state.device));
   current_state.opened = false;
@@ -213,9 +146,9 @@ GST::VideoInputManager::get_frame_data (char* data)
   unsigned read;
 
   if (worker)
-    result = gstreamer_worker_get_frame_data (worker, data,
-					      current_state.width * current_state.height * 3 / 2,
-					      read);
+    result = gst_helper_get_frame_data (worker, data,
+					current_state.width * current_state.height * 3 / 2,
+					read);
 
   return result;
 }
diff --git a/plugins/gstreamer/gst-videoinput.h b/plugins/gstreamer/gst-videoinput.h
index 4378357..a9138e8 100644
--- a/plugins/gstreamer/gst-videoinput.h
+++ b/plugins/gstreamer/gst-videoinput.h
@@ -42,7 +42,7 @@
 #include <gst/gst.h>
 #include <map>
 
-struct gstreamer_worker;
+#include "gst-helper.h"
 
 namespace GST
 {
@@ -85,7 +85,7 @@ namespace GST
      * the actual device */
     std::map<std::pair<std::string, std::string>, std::string> devices_by_name;
 
-    gstreamer_worker* worker;
+    gst_helper* worker;
   };
 };
 



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