[gstreamermm: 82/167] [peper0] plugin registering test
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gstreamermm: 82/167] [peper0] plugin registering test
- Date: Tue, 3 Sep 2013 19:25:58 +0000 (UTC)
commit f9e5e73e90d8e6b43f56df0efa95d35756a7b858
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date: Tue Jul 30 13:28:41 2013 +0200
[peper0] plugin registering test
tests/Makefile.am | 3 +-
tests/test-plugin-register.cc | 139 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 141 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6957365..30ea1f5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,7 @@ check_PROGRAMS = test-caps test-create-element test-pipeline-add-element \
test-ghost-pad test-init-check test-init \
test-init-check-noargs test-init-noargs test-iterator \
test-property-caps test-plugin-gen test-plugin-signals \
- test-buffer-list-iterator test-base-src
+ test-plugin-register test-buffer-list-iterator test-base-src
# Include run of test programs in check:
TESTS = $(check_PROGRAMS)
@@ -58,5 +58,6 @@ test_iterator_SOURCES = test-iterator.cc
test_property_caps_SOURCES = test-property-caps.cc
test_plugin_gen_SOURCES = test-plugin-gen.cc
test_plugin_signals_SOURCES = test-plugin-signals.cc
+test_plugin_register_SOURCES = test-plugin-register.cc
test_buffer_list_iterator_SOURCES = test-buffer-list-iterator.cc
test_base_src_SOURCES = test-base-src.cc
diff --git a/tests/test-plugin-register.cc b/tests/test-plugin-register.cc
new file mode 100644
index 0000000..fa13842
--- /dev/null
+++ b/tests/test-plugin-register.cc
@@ -0,0 +1,139 @@
+/*
+ * test2.cpp
+ *
+ * Created on: Feb 22, 2013
+ * Author: t.lakota
+ */
+
+/* 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 Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <iostream>
+#include <cassert>
+#include <algorithm>
+
+//this is a bit hacky, but for now necessary for Gst::Element_Class::class_init_function which is used by
register_mm_type
+#include <gstreamermm/private/element_p.h>
+
+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;
+ }
+
+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");
+ }
+};
+
+bool register_foo(Glib::RefPtr<Gst::Plugin> plugin)
+{
+ 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"
+ );
+
+ Glib::RefPtr<Gst::Pipeline> pipeline;
+ Glib::RefPtr<Gst::Element> source, filter1, filter2, sink;
+
+ pipeline = Gst::Pipeline::create("my-pipeline");
+
+ source = Gst::ElementFactory::create_element("fdsrc", "source");
+ filter1 = Gst::ElementFactory::create_element("foomm", "filter1");
+ sink = Gst::ElementFactory::create_element("fdsink", "sink");
+
+ assert(source);
+ assert(filter1);
+ assert(sink);
+
+ pipeline->add(source)->add(filter1)->add(sink);
+ source->link(filter1)->link(sink);
+
+ std::cout << "Successfully linked elements '" << source->get_name() <<
+ "', '" << filter1->get_name() << "' and '" << sink->get_name() <<
+ "'." << std::endl;
+
+ pipeline->set_state(Gst::STATE_PLAYING);
+ pipeline->get_bus()->poll(Gst::MESSAGE_EOS, -1);
+ pipeline->set_state(Gst::STATE_NULL);
+ pipeline.reset();
+ filter1.reset();
+ filter2.reset();
+
+ return 0;
+}
+
+
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]