gnomemm r1593 - in gstreamermm/trunk: . gstreamer/gstreamermm gstreamerbase/gstreamerbasemm tests



Author: jaalburqu
Date: Mon Jun 30 20:37:00 2008
New Revision: 1593
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1593&view=rev

Log:
2008-06-30  Josà Alburquerque  <jaalburqu svn gnome org>

	* gstreamer/gstreamermm/init.cc:
	* gstreamer/gstreamermm/init.h: Added Gst::init() and
	Gst::init_check() with no arguments to fix bug #539059.
	* tests/Makefile.am:
	* tests/test-init-check-noargs.cc:
	* tests/test-init-check.cc:
	* tests/test-init-noargs.cc:
	* tests/test-init.cc: Added init tests to test Gst::init() and
	Gst::init_check() methods (arguments and no argument versions).

	* gstreamerbase/gstreamerbasemm/init.h: Made it clear in the
	GstBase::init() function docs that Gst::init() functions already
	initialize gstreamerbasemm (no need to call GstBase::init() directly).

Added:
   gstreamermm/trunk/tests/test-init-check-noargs.cc
   gstreamermm/trunk/tests/test-init-noargs.cc
   gstreamermm/trunk/tests/test-init.cc
Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/gstreamer/gstreamermm/init.cc
   gstreamermm/trunk/gstreamer/gstreamermm/init.h
   gstreamermm/trunk/gstreamerbase/gstreamerbasemm/init.h
   gstreamermm/trunk/tests/Makefile.am
   gstreamermm/trunk/tests/test-init-check.cc

Modified: gstreamermm/trunk/gstreamer/gstreamermm/init.cc
==============================================================================
--- gstreamermm/trunk/gstreamer/gstreamermm/init.cc	(original)
+++ gstreamermm/trunk/gstreamer/gstreamermm/init.cc	Mon Jun 30 20:37:00 2008
@@ -28,14 +28,11 @@
 namespace Gst
 {
 
-void init(int& argc, char**& argv)
+void initialize_wrap_system()
 {
   static bool s_init = false;
   if(!s_init)
   {
-    Glib::init();
-    gst_init(&argc, &argv);
-
     //For Glib::wrap(), for Glib::Object-derived classes.
     Gst::wrap_init(); 
 
@@ -50,6 +47,32 @@
   }
 }
 
+void init(int& argc, char**& argv)
+{
+  static bool s_init = false;
+  if(!s_init)
+  {
+    Glib::init();
+    gst_init(&argc, &argv);
+    initialize_wrap_system();
+
+    s_init = true;
+  }
+}
+
+void init()
+{
+  static bool s_init = false;
+  if(!s_init)
+  {
+    Glib::init();
+    gst_init(NULL, NULL);
+    initialize_wrap_system();
+
+    s_init = true;
+  }
+}
+
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
 bool init_check(int& argc, char**& argv)
 #else
@@ -74,16 +97,38 @@
 
   if(!s_init)
   {
-    //For Glib::wrap(), for Glib::Object-derived classes.
-    Gst::wrap_init();
+    initialize_wrap_system();
+    s_init = true;
+  }
 
-    //For Gst::wrap(), for Gst::MiniObject-derived classes.
-    Gst::wrap_register_init();
-    Gst::gst_wrap_init();
+  return result;
+}
 
-    //Initialize wraping for gstreamerbasemm co-library
-    GstBase::wrap_init();
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+bool init_check()
+#else
+bool init_check(std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  static bool s_init = false;
+
+  if(!s_init)
+    Glib::init();
+
+  GError* gerror = 0;
+  bool result = gst_init_check(NULL, NULL, &gerror);
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
 
+  if(!s_init)
+  {
+    initialize_wrap_system();
     s_init = true;
   }
 

Modified: gstreamermm/trunk/gstreamer/gstreamermm/init.h
==============================================================================
--- gstreamermm/trunk/gstreamer/gstreamermm/init.h	(original)
+++ gstreamermm/trunk/gstreamer/gstreamermm/init.h	Mon Jun 30 20:37:00 2008
@@ -28,12 +28,22 @@
 namespace Gst
 {
 
-/** Initializes the GStreamer library, setting up internal path lists,
- * registering built-in elements, and loading standard plugins.
+/** Initializes gstreamermm parsing command line arguments.
  *
- * This function should be called before calling any other GLib functions. If
- * this is not an option, your program must initialise the GLib thread system
- * using g_thread_init() before any other GLib functions are called.
+ * Either this function or Gst::init_check() with command line parsing should
+ * be called to initialize gstreamermm before calling any other GLib functions.
+ * If this is not an option, your program must initialize the GLib thread
+ * system using Glib::thread_init() before any other GLib functions are called
+ * and use either Gst::init() or Gst::init_check() with no arguments before
+ * calling any gstreamermm functions.  GLib thread initialization can be done
+ * as follows:
+ *
+ * @code
+ * if (!Glib::thread_supported ())
+ *   Glib::thread_init ();
+ * ...
+ * @endcode
+ * 
  *
  * Note: This function will terminate your program if it was unable to
  * initialize GStreamer for some reason. If you want your program to fall back,
@@ -48,20 +58,51 @@
  */
 void init(int& argc, char**& argv);
 
-/** Initializes the GStreamer library, setting up internal path lists,
- * registering built-in elements, and loading standard plugins.
+/** Initializes gstreamermm without parsing command line options.
  *
- * This function will return false if GStreamer could not be initialized for
+ * Either the Gst::init() or Gst::init_check() functions with command line
+ * parsing should be called to initalize gstreamermm before calling any other
+ * GLib functions. If this is not an option, your program must initialize the
+ * GLib thread system using Glib::thread_init() before any other GLib functions
+ * are called and use either this function or Gst::init_check() with no
+ * arguments before calling any gstreamermm functions.  GLib thread
+ * initialization can be done as follows:
+ *
+ * @code
+ * if (!Glib::thread_supported ())
+ *   Glib::thread_init ();
+ * ...
+ * @endcode
+ *
+ * Note: This function will terminate your program if it was unable to
+ * initialize gstreamermm for some reason. If you want your program to fall
+ * back, use Gst::init_check() instead.
+ */
+void init();
+
+/** Initializes gstreamermm gracefully parsing command line arguments.
+ *
+ * Either this function or Gst::init() with command line parsing should be
+ * called to initialize gstreamermm before calling any other GLib functions.
+ * If this is not an option, your program must initialize the GLib thread
+ * system using Glib::thread_init() before any other GLib functions are called
+ * and use either Gst::init() or Gst::init_check() with no arguments before
+ * calling any gstreamermm functions.  GLib thread initialization can be done
+ * as follows:
+ *
+ * @code
+ * if (!Glib::thread_supported ())
+ *   Glib::thread_init ();
+ * ...
+ * @endcode
+ * 
+ * This function will return false if gstreamermm could not be initialized for
  * some reason. If you want your program to fail fatally, use Gst::init()
  * instead.
  *
- * This function should be called before calling any other GLib functions. If
- * this is not an option, your program must initialise the GLib thread system
- * using g_thread_init() before any other GLib functions are called.
- *
  * @param argc Pointer to application's argc.
  * @param argv Pointer to application's argv.
- * @return true if GStreamer could be initialized.
+ * @return true if gstreamermm could be initialized.
  * @throw Glib::Error
  */
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -70,6 +111,35 @@
   bool init_check(int& argc, char**& argv, std::auto_ptr<Glib::Error>& error);
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 
+/** Initializes gstreamermm gracefully without parsing command line arguments.
+ *
+ * Either the Gst::init() or Gst::init_check() functions with command line
+ * parsing should be called to initalize gstreamermm before calling any other
+ * GLib functions. If this is not an option, your program must initialize the
+ * GLib thread system using Glib::thread_init() before any other GLib functions
+ * are called and use either this function or Gst::init() with no arguments
+ * before calling any gstreamermm functions.  GLib thread initialization can be
+ * done as follows:
+ *
+ * @code
+ * if (!Glib::thread_supported ())
+ *   Glib::thread_init ();
+ * ...
+ * @endcode
+ * 
+ * This function will return false if gstreamermm could not be initialized for
+ * some reason. If you want your program to fail fatally, use Gst::init()
+ * instead.
+ *
+ * @return true if gstreamermm could be initialized.
+ * @throw Glib::Error
+ */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  bool init_check();
+#else
+  bool init_check(std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
 /** Returns a Glib::OptionGroup with GStreamer's argument specifications. The
  * group is set up to use standard GOption callbacks, so when using this group
  * in combination with GOption parsing methods, all argument parsing and

Modified: gstreamermm/trunk/gstreamerbase/gstreamerbasemm/init.h
==============================================================================
--- gstreamermm/trunk/gstreamerbase/gstreamerbasemm/init.h	(original)
+++ gstreamermm/trunk/gstreamerbase/gstreamerbasemm/init.h	Mon Jun 30 20:37:00 2008
@@ -25,11 +25,13 @@
 namespace GstBase
 {
 
-/** Initialize gstreamerbasemm.
+/** Initialize gstreamerbasemm.  Gst::init() and Gst::init_check() functions
+ * already initialize gstreamerbasemm so there's no need to use this function
+ * directly.
  */
 void init();
   
-}//end namespace GstBase
+} //namespace GstBase
 
 #endif //_GSTREAMERBASEMM_INIT_H
 

Modified: gstreamermm/trunk/tests/Makefile.am
==============================================================================
--- gstreamermm/trunk/tests/Makefile.am	(original)
+++ gstreamermm/trunk/tests/Makefile.am	Mon Jun 30 20:37:00 2008
@@ -8,7 +8,8 @@
                   test-message-wrap test-event-wrap test-query-wrap \
 		  test-structure test-caps-structures test-interface \
 		  test-create-bus test-taglist test-tagsetter \
-		  test-init-check
+		  test-init-check test-init test-init-check-noargs \
+		  test-init-noargs
 
 #TODO: Add test-pad to tests when bug #539108 is fixed.
 
@@ -62,3 +63,12 @@
 
 test_init_check_SOURCES=test-init-check.cc
 test_init_check_LDFLAGS= GSTREAMERMM_LIBS@
+
+test_init_SOURCES=test-init.cc
+test_init_LDFLAGS= GSTREAMERMM_LIBS@
+
+test_init_check_noargs_SOURCES=test-init-check-noargs.cc
+test_init_check_noargs_LDFLAGS= GSTREAMERMM_LIBS@
+
+test_init_noargs_SOURCES=test-init-noargs.cc
+test_init_noargs_LDFLAGS= GSTREAMERMM_LIBS@

Added: gstreamermm/trunk/tests/test-init-check-noargs.cc
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/tests/test-init-check-noargs.cc	Mon Jun 30 20:37:00 2008
@@ -0,0 +1,63 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gstreamermm.h>
+#include <gstreamerbasemm.h>
+#include <iostream>
+
+int main (int argc, char* argv[])
+{
+  try
+  {
+    bool success = Gst::init_check();
+
+    if (!success)
+    {
+      std::cout << "Error initializing gstreamermm." << std::endl;
+      return -1;
+    }
+
+  }
+  catch (const Glib::Error& error)
+  {
+    std::cout << "Error initializing gstreamermm." << std::endl;
+    return -1;
+  }
+
+  Glib::RefPtr<Gst::Element> element = Gst::ElementFactory::create_element("ximagesink", "videosink");
+
+  if (element)
+    std::cout << "Successfully created gst element '" <<
+      element->get_name() << "'." << std::endl;
+
+  Glib::RefPtr< Gst::ElementInterfaced<GstBase::XOverlay> > xoverlay =
+    Gst::Interface::cast <GstBase::XOverlay>(element);
+
+  if(xoverlay)
+  {
+    std::cout << "element '" << element->get_name() <<
+      "' implements XOverlay interface." << std::endl;
+
+    xoverlay->handle_events(false);
+  }
+
+  return 0;
+}

Modified: gstreamermm/trunk/tests/test-init-check.cc
==============================================================================
--- gstreamermm/trunk/tests/test-init-check.cc	(original)
+++ gstreamermm/trunk/tests/test-init-check.cc	Mon Jun 30 20:37:00 2008
@@ -60,7 +60,6 @@
     std::cout << "element '" << element->get_name() <<
       "' implements XOverlay interface." << std::endl;
 
-    // Use interface methods
     xoverlay->handle_events(false);
   }
 

Added: gstreamermm/trunk/tests/test-init-noargs.cc
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/tests/test-init-noargs.cc	Mon Jun 30 20:37:00 2008
@@ -0,0 +1,48 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gstreamermm.h>
+#include <gstreamerbasemm.h>
+#include <iostream>
+
+int main (int argc, char* argv[])
+{
+  Gst::init();
+
+  Glib::RefPtr<Gst::Element> element = Gst::ElementFactory::create_element("ximagesink", "videosink");
+
+  if (element)
+    std::cout << "Successfully created gst element '" <<
+      element->get_name() << "'." << std::endl;
+
+  Glib::RefPtr< Gst::ElementInterfaced<GstBase::XOverlay> > xoverlay =
+    Gst::Interface::cast <GstBase::XOverlay>(element);
+
+  if(xoverlay)
+  {
+    std::cout << "element '" << element->get_name() <<
+      "' implements XOverlay interface." << std::endl;
+
+    xoverlay->handle_events(false);
+  }
+
+  return 0;
+}

Added: gstreamermm/trunk/tests/test-init.cc
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/tests/test-init.cc	Mon Jun 30 20:37:00 2008
@@ -0,0 +1,48 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gstreamermm.h>
+#include <gstreamerbasemm.h>
+#include <iostream>
+
+int main (int argc, char* argv[])
+{
+  Gst::init(argc, argv);
+
+  Glib::RefPtr<Gst::Element> element = Gst::ElementFactory::create_element("ximagesink", "videosink");
+
+  if (element)
+    std::cout << "Successfully created gst element '" <<
+      element->get_name() << "'." << std::endl;
+
+  Glib::RefPtr< Gst::ElementInterfaced<GstBase::XOverlay> > xoverlay =
+    Gst::Interface::cast <GstBase::XOverlay>(element);
+
+  if(xoverlay)
+  {
+    std::cout << "element '" << element->get_name() <<
+      "' implements XOverlay interface." << std::endl;
+
+    xoverlay->handle_events(false);
+  }
+
+  return 0;
+}



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