gstmm add element to pipeline test



Hi. I was trying add the following test for adding an element to a pipeline to gstmm:

--------------------test-pipeline-add-element.cc-------------------------------
#include <gstmm.h>
#include <iostream>

int main (int argc, char* argv[])
{
 Gst::init(argc, argv);

Glib::RefPtr<Gst::Pipeline> pipeline = Gst::Pipeline::create("my-pipeline"); Glib::RefPtr<Gst::Element> source = Gst::Element::create("fakesrc", "source");

 pipeline->add(source);

 Glib::RefPtr<Gst::Element> sourceCopy = pipeline->get_by_name("source");

 if (sourceCopy)
   std::cout << "Successfully added element '" << sourceCopy->get_name() <<
    "' to pipeline '" << pipeline->get_name() << "'." << std::endl;
}
--------------------test-pipeline-add-element.cc-------------------------------

I found that <gstmm/pipeline.h> had to be added to <gstmm.h> and the "pipeline->add()" line was causing a segfault error. By debugging I found that the adding was successful, but just before the the return of Gst::Bin::add (see following lines), the RefPtr<Gst::Bin>::~RefPrt() is called, which "unreferences" the object and produces a "Segmentation fault":

Glib::RefPtr<Bin> Bin::add(const Glib::RefPtr<Element>& element)
{
 bool result = gst_bin_add(gobj(), element->gobj());

 if(result)
   return Glib::RefPtr<Bin>(this);
 else
throw std::runtime_error("Bin '" + get_name() + "' does not want to accept Element '" + element->get_name() + "'");
}

I fixed the segfault error changing the "return" line to read "return Glib::wrap(gobj(), true)". Is this correct? I'm submitting a patch. Thanks.

-Jose
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 89)
+++ ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2007-11-30  José Alburquerque  <jaalburquerque cox net>
+
+	* gst/gstmm.h: added <gstmm/pipeline.h>
+	* gst/src/bin.ccg: removed 2nd arg from Glib::wrap in
+	Gst::Bin::create()
+	* gst/src/pipeline.ccg: removed 2nd arg from Glib::wrap in
+	Gst::Pipeline::create() and fixed Gst:Pipeline::add() unref error
+	* tests/Makefile.am: added test to add element to pipeline
+	* tests/test-pipeline-add-element.cc:
+
 2007-11-28  Siavash Safi  <siavash safi gmail com>
 
 	* gst/src/element.hg: seek_simple(), seek()
Index: gst/src/pipeline.ccg
===================================================================
--- gst/src/pipeline.ccg	(revision 89)
+++ gst/src/pipeline.ccg	(working copy)
@@ -6,7 +6,7 @@
 Glib::RefPtr<Pipeline> Pipeline::create(const std::string& name)
 {
   GstElement* pipeline = gst_pipeline_new(name.c_str());
-  return Glib::wrap((GstPipeline*) pipeline, false);
+  return Glib::wrap((GstPipeline*) pipeline);
 }
 
 } //namespace Gst
Index: gst/src/bin.ccg
===================================================================
--- gst/src/bin.ccg	(revision 89)
+++ gst/src/bin.ccg	(working copy)
@@ -6,7 +6,7 @@
 Glib::RefPtr<Bin> Bin::create(const std::string& name)
 {
   GstElement* bin = gst_bin_new(name.c_str());
-  return Glib::wrap((GstBin*) bin, false);
+  return Glib::wrap((GstBin*) bin);
 }
 
 Glib::RefPtr<Bin> Bin::add(const Glib::RefPtr<Element>& element)
@@ -14,7 +14,7 @@
   bool result = gst_bin_add(gobj(), element->gobj());
 
   if(result)
-    return Glib::RefPtr<Bin>(this);
+    return Glib::wrap(gobj(), true);
   else
     throw std::runtime_error("Bin '" + get_name() + "' does not want to accept Element '" + element->get_name() + "'");
 }
Index: gst/gstmm.h
===================================================================
--- gst/gstmm.h	(revision 89)
+++ gst/gstmm.h	(working copy)
@@ -8,6 +8,7 @@
 #include <gstmm/iterator.h>
 #include <gstmm/object.h>
 #include <gstmm/pad.h>
+#include <gstmm/pipeline.h>
 #include <gstmm/structure.h>
 #include <gstmm/systemclock.h>
 
Index: tests/test-pipeline-add-element.cc
===================================================================
--- tests/test-pipeline-add-element.cc	(revision 0)
+++ tests/test-pipeline-add-element.cc	(revision 0)
@@ -0,0 +1,18 @@
+#include <gstmm.h>
+#include <iostream>
+
+int main (int argc, char* argv[])
+{
+  Gst::init(argc, argv);
+
+  Glib::RefPtr<Gst::Pipeline> pipeline = Gst::Pipeline::create("my-pipeline");
+  Glib::RefPtr<Gst::Element> source = Gst::Element::create("fakesrc", "source");
+
+  pipeline->add(source);
+
+  Glib::RefPtr<Gst::Element> sourceCopy = pipeline->get_by_name("source");
+
+  if (sourceCopy)
+    std::cout << "Successfully added element '" << sourceCopy->get_name() <<
+     "' to pipeline '" << pipeline->get_name() << "'." << std::endl;
+}
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 89)
+++ tests/Makefile.am	(working copy)
@@ -2,11 +2,14 @@
 
 LDADD=$(top_builddir)/gst/gstmm/libgstmm-1.0.la
 
-noinst_PROGRAMS = test-create-element
+noinst_PROGRAMS = test-create-element test-pipeline-add-element
 
 test_create_element_SOURCES=test-create-element.cc
 test_create_element_LDFLAGS= GSTMM_LIBS@
 
+test_pipeline_add_element_SOURCES=test-pipeline-add-element.cc
+test_pipeline_add_element_LDFLAGS= GSTMM_LIBS@
+
 #runtestbasic runtestlangs \
 #runtestsearch runtestmimetypes \
 #runtestgetbuffer


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