[gstreamermm: 83/167] [peper0] gst_element_class_get_pad_template wrapped, which simplified element derivation a bit.



commit 1e117dd374e51d03db1e5a9c751660352866fdcf
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Tue Jul 30 13:31:42 2013 +0200

    [peper0]  gst_element_class_get_pad_template wrapped, which simplified element derivation a bit.

 gstreamer/src/element.ccg     |    5 ++
 gstreamer/src/element.hg      |    2 +
 tests/test-plugin-register.cc |  103 ++++++++++++++++++----------------------
 3 files changed, 53 insertions(+), 57 deletions(-)
---
diff --git a/gstreamer/src/element.ccg b/gstreamer/src/element.ccg
index 5656809..1661109 100644
--- a/gstreamer/src/element.ccg
+++ b/gstreamer/src/element.ccg
@@ -177,4 +177,9 @@ bool Gst::Element::set_clock_vfunc(const Glib::RefPtr<Gst::Clock>& clock)
   return true;
 }
 
+Glib::RefPtr<Gst::PadTemplate> Gst::Element::get_pad_template(const Glib::ustring &factory_name) const
+{
+  return Glib::wrap(gst_element_class_get_pad_template(GST_ELEMENT_GET_CLASS(gobject_), 
factory_name.c_str()), true);
+}
+
 } //namespace Gst
diff --git a/gstreamer/src/element.hg b/gstreamer/src/element.hg
index f1bfc49..52ef16e 100644
--- a/gstreamer/src/element.hg
+++ b/gstreamer/src/element.hg
@@ -391,6 +391,8 @@ public:
    */
   _WRAP_VFUNC(bool query(const Glib::RefPtr<Gst::Query>& query) const, "query")
 
+  Glib::RefPtr<Gst::PadTemplate> get_pad_template(const Glib::ustring &factory_name) const;
+
 protected:
 #m4begin
   _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
diff --git a/tests/test-plugin-register.cc b/tests/test-plugin-register.cc
index fa13842..f25050b 100644
--- a/tests/test-plugin-register.cc
+++ b/tests/test-plugin-register.cc
@@ -34,75 +34,64 @@
 
 class Foo: public Gst::Element
 {
-    Glib::RefPtr<Gst::Pad> sinkpad;
-    Glib::RefPtr<Gst::Pad> srcpad;
-
-    static Glib::RefPtr<Gst::PadTemplate> sink_factory()
-    {
-        static Glib::RefPtr<Gst::PadTemplate> res = Gst::PadTemplate::create("sink", Gst::PAD_SINK, 
Gst::PAD_ALWAYS, Gst::Caps::create_any());
-        return res;
-    }
-    static Glib::RefPtr<Gst::PadTemplate> src_factory()
-    {
-        static Glib::RefPtr<Gst::PadTemplate> res = Gst::PadTemplate::create("src", Gst::PAD_SRC, 
Gst::PAD_ALWAYS, Gst::Caps::create_any());
-        return res;
-    }
+       Glib::RefPtr<Gst::Pad> sinkpad;
+       Glib::RefPtr<Gst::Pad> srcpad;
 
 public:
-    static void base_init(BaseClassType *klass)
-    {
-        /* This is another hack.
-         * For now it uses pure C functions, which should be wrapped then.
-         */
-        gst_element_class_set_details_simple(klass,
-                "foo_longname",
-                "foo_classification",
-                "foo_detail_description",
-                "foo_detail_author");
-
-
-        gst_element_class_add_pad_template(klass, sink_factory()->gobj());
-        gst_element_class_add_pad_template(klass, src_factory()->gobj());
-    }
-
-    Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, Glib::RefPtr<Gst::Buffer> &buf)
-    {
-        assert(buf->gobj()->mini_object.refcount==1);
-        buf=buf->create_writable();
-        //run some C++ function
-        std::sort(buf->get_data(), buf->get_data() + buf->get_size());
-        assert(buf->gobj()->mini_object.refcount==1);
-        return srcpad->push(buf);
-    }
-      explicit Foo(GstElement *gobj) :
-              Gst::Element(gobj)
-      {
-            add_pad(sinkpad=Gst::Pad::create(sink_factory(), "sink"));
-            add_pad(srcpad=Gst::Pad::create(src_factory(), "src"));
-            sinkpad->set_chain_function(sigc::mem_fun(*this, &Foo::chain));
-      }
-      ~Foo()
-      {
-          printf("destroying foo\n");
-      }
+       static void base_init(BaseClassType *klass)
+       {
+               /* This is another hack.
+                * For now it uses pure C functions, which should be wrapped then.
+                */
+               gst_element_class_set_details_simple(klass,
+                               "foo_longname",
+                               "foo_classification",
+                               "foo_detail_description",
+                               "foo_detail_author");
+
+
+               gst_element_class_add_pad_template(klass, Gst::PadTemplate::create("sink", Gst::PAD_SINK, 
Gst::PAD_ALWAYS, Gst::Caps::create_any())->gobj());
+               gst_element_class_add_pad_template(klass, Gst::PadTemplate::create("src", Gst::PAD_SRC, 
Gst::PAD_ALWAYS, Gst::Caps::create_any())->gobj());
+       }
+
+       Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, Glib::RefPtr<Gst::Buffer> &buf)
+       {
+       assert(buf->gobj()->mini_object.refcount==1);
+       buf=buf->create_writable();
+       //run some C++ function
+       std::sort(buf->get_data(), buf->get_data() + buf->get_size());
+       assert(buf->gobj()->mini_object.refcount==1);
+       return srcpad->push(buf);
+       }
+         explicit Foo(GstElement *gobj) :
+                         Gst::Element(gobj)
+         {
+                       add_pad(sinkpad=Gst::Pad::create(get_pad_template("sink"), "sink"));
+                       add_pad(srcpad=Gst::Pad::create(get_pad_template("src"), "src"));
+                       sinkpad->set_chain_function(sigc::mem_fun(*this, &Foo::chain));
+         }
+         ~Foo()
+         {
+                 printf("destroying foo\n");
+         }
 };
 
 bool register_foo(Glib::RefPtr<Gst::Plugin> plugin)
 {
-    Gst::ElementFactory::register_element(plugin, "foomm", 10, Gst::register_mm_type<Foo>("foomm"));
-    return true;
+       Gst::ElementFactory::register_element(plugin, "foomm", 10, Gst::register_mm_type<Foo>("foomm"));
+       return true;
 
 }
 
 int main(int argc, char** argv)
 {
   Gst::init(argc, argv);
-    Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR,
-            "foo", "foo is example of C++ element",
-            sigc::ptr_fun(register_foo), "0.123",
-            "LGPL", "source?",
-            "package?", "http://example.com";
-            );
+       Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR,
+                       "foo", "foo is example of C++ element",
+                       sigc::ptr_fun(register_foo), "0.123",
+                       "LGPL", "source?",
+                       "package?", "http://example.com";
+                       );
 
   Glib::RefPtr<Gst::Pipeline> pipeline;
   Glib::RefPtr<Gst::Element> source, filter1, filter2, sink;


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