[ekiga] Various improvements in the gstreamer code



commit 2d6b53c7179ccd904203bc13fe22a62378a5f64a
Author: Julien Puydt <jpuydt gnome org>
Date:   Mon Aug 31 13:00:59 2009 +0200

    Various improvements in the gstreamer code
    
    - avoid unnecessary device detection at startup ;
    - really close devices when asked to close (!)

 lib/engine/components/gstreamer/gst-audioinput.cpp |   11 +++++++++--
 lib/engine/components/gstreamer/gst-audioinput.h   |    1 +
 .../components/gstreamer/gst-audiooutput.cpp       |   12 ++++++++++--
 lib/engine/components/gstreamer/gst-audiooutput.h  |    1 +
 lib/engine/components/gstreamer/gst-videoinput.cpp |   12 ++++++++++--
 lib/engine/components/gstreamer/gst-videoinput.h   |    1 +
 6 files changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/lib/engine/components/gstreamer/gst-audioinput.cpp b/lib/engine/components/gstreamer/gst-audioinput.cpp
index 2b93778..da15266 100644
--- a/lib/engine/components/gstreamer/gst-audioinput.cpp
+++ b/lib/engine/components/gstreamer/gst-audioinput.cpp
@@ -44,9 +44,9 @@
 
 #include <string.h>
 
-GST::AudioInputManager::AudioInputManager ()
+GST::AudioInputManager::AudioInputManager ():
+  already_detected_devices(false), pipeline(NULL)
 {
-  detect_devices ();
 }
 
 GST::AudioInputManager::~AudioInputManager ()
@@ -76,6 +76,9 @@ GST::AudioInputManager::set_device (const Ekiga::AudioInputDevice& device)
 {
   bool result = false;
 
+  if ( !already_detected_devices)
+    detect_devices ();
+
   if (device.type == "GStreamer"
       && devices_by_name.find (std::pair<std::string, std::string>(device.source, device.name)) != devices_by_name.end ()) {
 
@@ -96,6 +99,9 @@ GST::AudioInputManager::open (unsigned channels,
   GError* error = NULL;
   GstState current;
 
+  if ( !already_detected_devices)
+    detect_devices ();
+
   command = g_strdup_printf ("%s ! appsink max_buffers=2 drop=true"
 			     " caps=audio/x-raw-int"
 			     ",rate=%d"
@@ -253,6 +259,7 @@ GST::AudioInputManager::has_device (const std::string& source,
 void
 GST::AudioInputManager::detect_devices ()
 {
+  already_detected_devices = true;
   devices_by_name.clear ();
   detect_audiotestsrc_devices ();
   detect_alsasrc_devices ();
diff --git a/lib/engine/components/gstreamer/gst-audioinput.h b/lib/engine/components/gstreamer/gst-audioinput.h
index a13b48c..da3770a 100644
--- a/lib/engine/components/gstreamer/gst-audioinput.h
+++ b/lib/engine/components/gstreamer/gst-audioinput.h
@@ -78,6 +78,7 @@ namespace GST
 		     Ekiga::AudioInputDevice& device);
   private:
 
+    bool already_detected_devices;
     void detect_devices ();
     void detect_audiotestsrc_devices ();
     void detect_alsasrc_devices ();
diff --git a/lib/engine/components/gstreamer/gst-audiooutput.cpp b/lib/engine/components/gstreamer/gst-audiooutput.cpp
index 83aea45..d81a5cf 100644
--- a/lib/engine/components/gstreamer/gst-audiooutput.cpp
+++ b/lib/engine/components/gstreamer/gst-audiooutput.cpp
@@ -64,9 +64,9 @@ pipeline_cleaner (GstBus* /*bus*/,
 }
 
 
-GST::AudioOutputManager::AudioOutputManager ()
+GST::AudioOutputManager::AudioOutputManager ():
+  already_detected_devices(false)
 {
-  detect_devices ();
 }
 
 GST::AudioOutputManager::~AudioOutputManager ()
@@ -97,6 +97,9 @@ GST::AudioOutputManager::set_device (Ekiga::AudioOutputPS ps,
 {
   bool result = false;
 
+  if ( !already_detected_devices)
+    detect_devices ();
+
   if (device.type == "GStreamer"
       && devices_by_name.find (std::pair<std::string,std::string>(device.source, device.name)) != devices_by_name.end ()) {
 
@@ -119,6 +122,10 @@ GST::AudioOutputManager::open (Ekiga::AudioOutputPS ps,
   gchar* command = NULL;
   GError* error = NULL;
   GstState current;
+
+  if ( !already_detected_devices)
+    detect_devices ();
+
   command = g_strdup_printf ("appsrc is-live=true name=ekiga_src"
 			     " ! audio/x-raw-int"
 			     ",rate=%d"
@@ -210,6 +217,7 @@ GST::AudioOutputManager::close (Ekiga::AudioOutputPS ps)
       GstBus* bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline[ii]));
       gst_bus_add_watch (bus, pipeline_cleaner, pipeline[ii]);
       gst_object_unref (bus);
+      gst_element_set_state (pipeline[ii], GST_STATE_NULL);
       pipeline[ii] = NULL;
       device_closed (ps, current_state[ii].device);
     }
diff --git a/lib/engine/components/gstreamer/gst-audiooutput.h b/lib/engine/components/gstreamer/gst-audiooutput.h
index 11036da..16cd2af 100644
--- a/lib/engine/components/gstreamer/gst-audiooutput.h
+++ b/lib/engine/components/gstreamer/gst-audiooutput.h
@@ -82,6 +82,7 @@ namespace GST
 		     Ekiga::AudioOutputDevice& device);
   private:
 
+    bool already_detected_devices;
     void detect_devices ();
     void detect_fakesink_devices ();
     void detect_alsasink_devices ();
diff --git a/lib/engine/components/gstreamer/gst-videoinput.cpp b/lib/engine/components/gstreamer/gst-videoinput.cpp
index 0c804fc..7bbbb77 100644
--- a/lib/engine/components/gstreamer/gst-videoinput.cpp
+++ b/lib/engine/components/gstreamer/gst-videoinput.cpp
@@ -44,9 +44,9 @@
 
 #include <string.h>
 
-GST::VideoInputManager::VideoInputManager (): pipeline(NULL)
+GST::VideoInputManager::VideoInputManager ():
+  already_detected_devices(false), pipeline(NULL)
 {
-  detect_devices (); // or we won't recognize the devices we'll be asked to use
 }
 
 GST::VideoInputManager::~VideoInputManager ()
@@ -81,6 +81,9 @@ GST::VideoInputManager::set_device (const Ekiga::VideoInputDevice& device,
 {
   bool result = false;
 
+  if ( !already_detected_devices)
+    detect_devices ();
+
   if (device.type == "GStreamer"
       && devices_by_name.find (std::pair<std::string, std::string>(device.source, device.name)) != devices_by_name.end ()) {
 
@@ -108,6 +111,9 @@ GST::VideoInputManager::open (unsigned width,
   GError* error = NULL;
   GstState current;
 
+  if ( !already_detected_devices)
+    detect_devices ();
+
   command = g_strdup_printf ("%s ! appsink max_buffers=2 drop=true"
 			     " caps=video/x-raw-yuv"
 			     ",format=(fourcc)I420"
@@ -159,6 +165,7 @@ GST::VideoInputManager::close ()
 {
   if (pipeline != NULL) {
 
+    gst_element_set_state (pipeline, GST_STATE_NULL);
     device_closed (current_state.device);
     g_object_unref (pipeline);
     pipeline = NULL;
@@ -207,6 +214,7 @@ GST::VideoInputManager::has_device (const std::string& source,
 void
 GST::VideoInputManager::detect_devices ()
 {
+  already_detected_devices = true;
   devices_by_name.clear ();
   detect_videotestsrc_devices ();
   detect_v4l2src_devices ();
diff --git a/lib/engine/components/gstreamer/gst-videoinput.h b/lib/engine/components/gstreamer/gst-videoinput.h
index 1ca6f60..0f45837 100644
--- a/lib/engine/components/gstreamer/gst-videoinput.h
+++ b/lib/engine/components/gstreamer/gst-videoinput.h
@@ -72,6 +72,7 @@ namespace GST
 		     Ekiga::VideoInputDevice& device);
   private:
 
+    bool already_detected_devices;
     void detect_devices ();
     void detect_videotestsrc_devices ();
     void detect_v4l2src_devices ();



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