gnomemm r1816 - in gstreamermm/trunk: . gstreamer/src tests



Author: jaalburqu
Date: Sun Nov 30 03:16:01 2008
New Revision: 1816
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1816&view=rev

Log:
2008-11-29  Josà Alburquerque  <jaalburqu svn gnome org>

	* gstreamer/src/bin.ccg: Modified add() to take extra reference of
	element if it is still floating.  This is necessary because bins like
	to destroy the elements themselves so we can't let the Glib::RefPtr<>
	to the element do this (see comments in add method).
	* tests/test-create-bin.cc: Added lines to test removal and
	re-addition of element to a bin.
	* tests/test-interface.cc: Modified to use a Glib::RefPtr<> to hold
	the copy of the element gobject so it is properly destroyed when
	Glib::RefPtr<> goes out of scope.

Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/gstreamer/src/bin.ccg
   gstreamermm/trunk/tests/test-create-bin.cc
   gstreamermm/trunk/tests/test-interface.cc

Modified: gstreamermm/trunk/gstreamer/src/bin.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/bin.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/bin.ccg	Sun Nov 30 03:16:01 2008
@@ -38,20 +38,22 @@
 
 Glib::RefPtr<Bin> Bin::add(const Glib::RefPtr<Element>& element)
 {
+  // The following is needed because when adding an element to a bin, the bin
+  // likes to have the last reference and then destroy it when the bin itself
+  // is destroyed.  Without the extra reference, when the last Glib::RefPtr<>
+  // to the element goes out of scope, the element may be destroyed before the
+  // bin and GStreamer complains about it.  The extra reference to the element
+  // is removed when the bin is destroyed or when the element is removed from
+  // the bin (see gst_bin_remove).
+  if (G_LIKELY(GST_OBJECT_IS_FLOATING(element->gobj())))
+    element->reference();
+
   const bool result = gst_bin_add(gobj(), element->gobj());
 
   // If addition successful, return RefPtr<..> to this bin, otherwise return
   // NULL RefPtr<...>
   if(result)
-   {
-     // When adding bins to a bin/pipeline (yes this is possible), an extra ref
-     // is needed because parent bin takes ownership of element and wants to
-     // unref the child bin itself when the parent bin is destroyed.
-     if (GST_IS_BIN(element->gobj()))
-       element->reference();
-
-      return Glib::wrap(gobj(), true);
-   }
+    return Glib::wrap(gobj(), true);
   else
     throw std::runtime_error("Failed to add " + element->get_name() + " element");
 }

Modified: gstreamermm/trunk/tests/test-create-bin.cc
==============================================================================
--- gstreamermm/trunk/tests/test-create-bin.cc	(original)
+++ gstreamermm/trunk/tests/test-create-bin.cc	Sun Nov 30 03:16:01 2008
@@ -41,6 +41,9 @@
   pipeline->add(bin);
   source->link(sink);
 
+  pipeline->remove(bin);
+  pipeline->add(bin);
+
   std::cout << "Successfully added elements '" << source->get_name() <<
     "' and '" << sink->get_name() << "' to bin '" <<
       bin->get_name() << "'." << std::endl;

Modified: gstreamermm/trunk/tests/test-interface.cc
==============================================================================
--- gstreamermm/trunk/tests/test-interface.cc	(original)
+++ gstreamermm/trunk/tests/test-interface.cc	Sun Nov 30 03:16:01 2008
@@ -46,9 +46,9 @@
     // Test ambiguity of ElementInterfaced<>::gobj() methods
     GstElement* gstElement = handler->gobj();
     const GstElement* constGstElement = handler->gobj();
-    GstElement* gstElementCopy = handler->gobj_copy();
+    Glib::RefPtr<Gst::Element> element_copy = Glib::wrap(handler->gobj_copy());
 
-    if (!gstElement || !constGstElement || !gstElementCopy)
+    if (!gstElement || !constGstElement || !element_copy)
     {
       std::cout << "Underlying gobject methods of cast object didn't work." <<
         std::endl;



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