[gstreamermm] wrapped elementclass class (simplified writting plugins)
- From: Marcin Kolny <mkolny src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gstreamermm] wrapped elementclass class (simplified writting plugins)
- Date: Fri, 29 Nov 2013 12:22:48 +0000 (UTC)
commit b909987e2032b40ca3b73d7fa9e8bc0e494aca69
Author: Marcin Kolny <marcin kolny flytronic pl>
Date: Fri Nov 29 13:05:42 2013 +0100
wrapped elementclass class
(simplified writting plugins)
gstreamer/gstreamermm/register.h | 38 ++++++++++++++++++++++++++++++++-
tests/plugins/test-foo.h | 17 +++++---------
tests/plugins/test-plugin-pushsrc.cc | 8 +++---
tests/regression/pluginbin.h | 2 +-
4 files changed, 47 insertions(+), 18 deletions(-)
---
diff --git a/gstreamer/gstreamermm/register.h b/gstreamer/gstreamermm/register.h
index ccd45b2..5b79bab 100644
--- a/gstreamer/gstreamermm/register.h
+++ b/gstreamer/gstreamermm/register.h
@@ -22,12 +22,42 @@
#include <glib-object.h>
#include <glibmm/property.h>
+#include <gstreamermm/padtemplate.h>
namespace Gst
{
template<class DerivedCppType>
static GType
+register_mm_type(const gchar * type_name=typeid(DerivedCppType).name());
+
+template<typename DerivedCppType>
+class ElementClass
+{
+ friend GType register_mm_type<DerivedCppType>(const gchar * type_name);
+ GstElementClass* klass;
+ ElementClass(typename DerivedCppType::BaseClassType* klass): klass((GstElementClass*)klass){}
+ ElementClass(ElementClass const&);
+ void operator=(ElementClass const&);
+public:
+ void add_pad_template(const Glib::RefPtr<Gst::PadTemplate>& tpl)
+ {
+ gst_element_class_add_pad_template(klass, tpl->gobj());
+ }
+ void set_metadata(const Glib::ustring& longname, const Glib::ustring& classification,
+ const Glib::ustring& description, const Glib::ustring& author)
+ {
+ gst_element_class_set_metadata(klass, longname.c_str(), classification.c_str(), description.c_str(),
author.c_str());
+ }
+
+ void add_metadata(const Glib::ustring& key, const Glib::ustring& value)
+ {
+ gst_element_class_add_metadata(klass ,key.c_str(), value.c_str());
+ }
+};
+
+template<class DerivedCppType>
+static GType
register_mm_type(const gchar * type_name=typeid(DerivedCppType).name())
{
struct GlibCppType
@@ -40,7 +70,11 @@ register_mm_type(const gchar * type_name=typeid(DerivedCppType).name())
instance->self = new DerivedCppType(&instance->parent);
}
-
+ static void base_init(typename DerivedCppType::BaseClassType *klass)
+ {
+ Gst::ElementClass<DerivedCppType> element_class(klass);
+ DerivedCppType::base_init(&element_class);
+ }
static void finalize(GObject *object)
{
//the following will destroy q_data, among which MM wrapper to this "object" is stored. This
will cause implicit delete on "self", since it is registered as wrapper of "object".
@@ -83,7 +117,7 @@ register_mm_type(const gchar * type_name=typeid(DerivedCppType).name())
GTypeInfo info;
info.class_size = sizeof(GlibCppTypeClass);
- info.base_init = (GBaseInitFunc)&DerivedCppType::base_init;
+ info.base_init = (GBaseInitFunc)&GlibCppType::base_init;
info.base_finalize = 0;
info.class_init = (GClassInitFunc) &GlibCppTypeClass::init;
info.class_finalize = 0;
diff --git a/tests/plugins/test-foo.h b/tests/plugins/test-foo.h
index e6dc28a..182ca99 100644
--- a/tests/plugins/test-foo.h
+++ b/tests/plugins/test-foo.h
@@ -19,20 +19,15 @@ class Foo : public Gst::Element
Glib::Property<Glib::ustring> sample_property;
public:
- static void base_init(BaseClassType *klass)
+ static void base_init(Gst::ElementClass<Foo> *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",
+ klass->set_metadata("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());
+ klass->add_pad_template(Gst::PadTemplate::create("sink", Gst::PAD_SINK, Gst::PAD_ALWAYS,
+ Gst::Caps::create_any()));
+ klass->add_pad_template(Gst::PadTemplate::create("src", Gst::PAD_SRC, Gst::PAD_ALWAYS,
+ Gst::Caps::create_any()));
}
Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, Glib::RefPtr<Gst::Buffer> &buf)
diff --git a/tests/plugins/test-plugin-pushsrc.cc b/tests/plugins/test-plugin-pushsrc.cc
index 1525808..138e95b 100644
--- a/tests/plugins/test-plugin-pushsrc.cc
+++ b/tests/plugins/test-plugin-pushsrc.cc
@@ -20,13 +20,13 @@ class FooSrc : public Gst::PushSrc
public:
static const int COUNT = 5;
- static void base_init(BaseClassType *klass)
+ static void base_init(Gst::ElementClass<FooSrc> *klass)
{
- gst_element_class_set_details_simple(GST_ELEMENT_CLASS(klass), "foosrc_longname",
+ klass->set_metadata("foosrc_longname",
"foosrc_classification", "foosrc_detail_description", "foosrc_detail_author");
- gst_element_class_add_pad_template(GST_ELEMENT_CLASS(klass),
- Gst::PadTemplate::create("src", Gst::PAD_SRC,
Gst::PAD_ALWAYS,Gst::Caps::create_from_string("x-application/x-foo1"))->gobj());
+ klass->add_pad_template(Gst::PadTemplate::create("src", Gst::PAD_SRC, Gst::PAD_ALWAYS,
+ Gst::Caps::create_from_string("x-application/x-foo1")));
}
explicit FooSrc(GstPushSrc *gobj)
diff --git a/tests/regression/pluginbin.h b/tests/regression/pluginbin.h
index 865969f..0ee95b2 100644
--- a/tests/regression/pluginbin.h
+++ b/tests/regression/pluginbin.h
@@ -23,7 +23,7 @@ private:
Glib::Property<Glib::ustring> location;
public:
- static void base_init(BaseClassType *klass)
+ static void base_init(Gst::ElementClass<PluginBin> *klass)
{
GstElementClass* element_klass = (GstElementClass*)klass;
gst_element_class_set_details_simple(element_klass, "Custom test bin",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]