[gstreamermm] Gst::BaseTransform: fix refs of {fixate, transform}_caps() return values
- From: Marcin Kolny <mkolny src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gstreamermm] Gst::BaseTransform: fix refs of {fixate, transform}_caps() return values
- Date: Mon, 29 Jun 2015 09:27:12 +0000 (UTC)
commit cb123e9def0cca0e958718783c049b755b2337ba
Author: Michał Wróbel <michal wrobel flytronic pl>
Date: Sat Jun 27 23:06:16 2015 +0200
Gst::BaseTransform: fix refs of {fixate,transform}_caps() return values
This is https://bugzilla.gnome.org/show_bug.cgi?id=751601 in progress.
* gstreamer/src/basetransform.hg: fix virtual methods transform_caps
and fixate_caps.
* tests/Makefile.am: add basetransform test to a build.
* tests/plugins/derivedfrombasetransform.h:
* tests/plugins/test-plugin-derivedfrombasetransform.cc: add
basetransformunit tests which should fail if the fix done in
gstreamer/src/basetransform.hg is not applied.
gstreamer/src/basetransform.hg | 4 +-
tests/Makefile.am | 2 +
tests/plugins/derivedfrombasetransform.h | 33 ++++++
.../test-plugin-derivedfrombasetransform.cc | 115 ++++++++++++++++++++
4 files changed, 152 insertions(+), 2 deletions(-)
---
diff --git a/gstreamer/src/basetransform.hg b/gstreamer/src/basetransform.hg
index b1b8128..003e76f 100644
--- a/gstreamer/src/basetransform.hg
+++ b/gstreamer/src/basetransform.hg
@@ -170,12 +170,12 @@ public:
/** Optional. Given the pad in this direction and the given caps, what caps
* are allowed on the other pad in this element ?
*/
- _WRAP_VFUNC(Glib::RefPtr<Gst::Caps> transform_caps(PadDirection direction, const Glib::RefPtr<Gst::Caps>&
caps, const Glib::RefPtr<Gst::Caps>& filter), "transform_caps")
+ _WRAP_VFUNC(Glib::RefPtr<Gst::Caps> transform_caps(PadDirection direction, const Glib::RefPtr<Gst::Caps>&
caps, const Glib::RefPtr<Gst::Caps>& filter), "transform_caps", refreturn_ctype)
/** Optional. Given the pad in this direction and the given caps, fixate the
* caps on the other pad.
*/
- _WRAP_VFUNC(Glib::RefPtr<Gst::Caps> fixate_caps(PadDirection direction, const Glib::RefPtr<Gst::Caps>&
caps, const Glib::RefPtr<Gst::Caps>& othercaps), "fixate_caps")
+ _WRAP_VFUNC(Glib::RefPtr<Gst::Caps> fixate_caps(PadDirection direction, const Glib::RefPtr<Gst::Caps>&
caps, const Glib::RefPtr<Gst::Caps>& othercaps), "fixate_caps", refreturn_ctype)
//TODO: This virtual function can't be wrapped without causing execution
//errors with the ogg_player_gtkmm example.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 15a76b9..aff11d3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -43,6 +43,7 @@ check_PROGRAMS = \
\
test-plugin-appsink \
test-plugin-appsrc \
+ test-plugin-derivedfrombasetransform \
test-plugin-pushsrc \
test-plugin-register \
\
@@ -79,6 +80,7 @@ test_urihandler_SOURCES = test-urihandler.cc
test_plugin_appsink_SOURCES = plugins/test-plugin-appsink.cc
$(TEST_MAIN_SOURCE)
test_plugin_appsrc_SOURCES = plugins/test-plugin-appsrc.cc
$(TEST_MAIN_SOURCE)
+test_plugin_derivedfrombasetransform_SOURCES = plugins/test-plugin-derivedfrombasetransform.cc
$(TEST_MAIN_SOURCE)
test_plugin_pushsrc_SOURCES = plugins/test-plugin-pushsrc.cc
$(TEST_MAIN_SOURCE)
test_plugin_register_SOURCES = plugins/test-plugin-register.cc
$(TEST_MAIN_SOURCE)
diff --git a/tests/plugins/derivedfrombasetransform.h b/tests/plugins/derivedfrombasetransform.h
new file mode 100644
index 0000000..82eb8f5
--- /dev/null
+++ b/tests/plugins/derivedfrombasetransform.h
@@ -0,0 +1,33 @@
+#ifndef TESTS_PLUGINS_DERIVEDFROMBASETRANSFORM_H_
+#define TESTS_PLUGINS_DERIVEDFROMBASETRANSFORM_H_
+
+#include <gstreamermm.h>
+#include <gstreamermm/private/basetransform_p.h>
+#include <assert.h>
+
+class DerivedFromBaseTransform : public Gst::BaseTransform
+{
+public:
+ static void base_init(Gst::ElementClass<DerivedFromBaseTransform> *klass)
+ {
+ klass->set_metadata("derivedfrombasetransform_longname",
+ "derivedfrombasetransform_classification", "derivedfrombasetransform_detail_description",
"derivedfrombasetransform_detail_author");
+
+ 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()));
+ }
+
+ explicit DerivedFromBaseTransform(GstBaseTransform *gobj)
+ : Glib::ObjectBase(typeid (DerivedFromBaseTransform)), // type must be registered before use
+ Gst::BaseTransform(gobj)
+ {
+ set_passthrough(true);
+ }
+
+ static bool register_element(Glib::RefPtr<Gst::Plugin> plugin)
+ {
+ return Gst::ElementFactory::register_element(plugin, "derivedfrombasetransform", 10,
Gst::register_mm_type<DerivedFromBaseTransform>("derivedfrombasetransform"));
+ }
+};
+
+#endif /* TESTS_PLUGINS_DERIVEDFROMBASETRANSFORM_H_ */
diff --git a/tests/plugins/test-plugin-derivedfrombasetransform.cc
b/tests/plugins/test-plugin-derivedfrombasetransform.cc
new file mode 100644
index 0000000..b39e336
--- /dev/null
+++ b/tests/plugins/test-plugin-derivedfrombasetransform.cc
@@ -0,0 +1,115 @@
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+#include <gstreamermm/appsink.h>
+#include <gstreamermm/appsrc.h>
+#include <vector>
+#include "derivedfrombasetransform.h"
+
+using namespace Gst;
+using Glib::RefPtr;
+
+class DerivedFromBaseTransformPluginTest : public ::testing::Test
+{
+protected:
+ RefPtr<AppSrc> source;
+ RefPtr<Element> filter;
+ RefPtr<AppSink> sink;
+ RefPtr<Gst::Pipeline> pipeline;
+
+ virtual void SetUp()
+ {
+ Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "derivedfrombasetransform",
+ "derivedfrombasetransfrom is an example of C++ element derived from Gst::BaseTransform",
+ sigc::ptr_fun(&DerivedFromBaseTransform::register_element), "0.123",
+ "LGPL", "source?", "package?", "http://example.com");
+ }
+
+ void CreatePipelineWithElements()
+ {
+ pipeline = Gst::Pipeline::create("my-pipeline");
+
+ source = AppSrc::create("source");
+ filter = ElementFactory::create_element("derivedfrombasetransform", "filter");
+ sink = AppSink::create("sink");
+
+ ASSERT_TRUE(source);
+ ASSERT_TRUE(filter);
+ ASSERT_TRUE(sink);
+
+ EXPECT_NO_THROW(pipeline->add(source)->add(filter)->add(sink));
+ EXPECT_NO_THROW(source->link(filter)->link(sink));
+ }
+};
+
+TEST_F(DerivedFromBaseTransformPluginTest, CreateRegisteredElement)
+{
+ RefPtr<Element> filter_element = Gst::ElementFactory::create_element("derivedfrombasetransform",
"filter");
+
+ ASSERT_TRUE(filter_element);
+}
+
+TEST_F(DerivedFromBaseTransformPluginTest, CreatePipelineWithRegisteredElement)
+{
+ CreatePipelineWithElements();
+}
+
+TEST_F(DerivedFromBaseTransformPluginTest, VFuncsShouldReturnProperlyRefcountedGobjs)
+{
+ bool plugin_registered = Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR,
"derivedfrombasetransform", "exemplary element C++-derived from Gst::BaseTransform",
+ sigc::ptr_fun(&DerivedFromBaseTransform::register_element), "0.123", "LGPL", "source?",
"package?",
+ "http://example.com");
+ ASSERT_TRUE(plugin_registered);
+
+ Glib::RefPtr<Gst::Element> element = Gst::ElementFactory::create_element("derivedfrombasetransform");
+ ASSERT_TRUE(element);
+
+ Glib::RefPtr<DerivedFromBaseTransform> derived_from_base_transform =
Glib::RefPtr<DerivedFromBaseTransform>::cast_dynamic(element);
+ ASSERT_TRUE(derived_from_base_transform);
+
+ {
+ Glib::RefPtr<Caps> caps = derived_from_base_transform->transform_caps_vfunc(PAD_SINK,
Caps::create_any(), Glib::RefPtr<Caps>());
+ ASSERT_TRUE(caps);
+ ASSERT_TRUE(caps->gobj());
+ ASSERT_TRUE(GST_IS_CAPS(caps->gobj()));
+ ASSERT_EQ(1, caps->gobj()->mini_object.refcount);
+ }
+
+ {
+ GstBaseTransform *gobj = derived_from_base_transform->gobj();
+ Glib::RefPtr<Caps> caps = Glib::wrap(GST_BASE_TRANSFORM_GET_CLASS(gobj)->transform_caps(gobj,
GST_PAD_SINK, Glib::unwrap(Caps::create_any()), NULL));
+ ASSERT_TRUE(caps);
+ ASSERT_TRUE(caps->gobj());
+ ASSERT_TRUE(GST_IS_CAPS(caps->gobj()));
+ ASSERT_EQ(1, caps->get_refcount());
+ }
+}
+
+TEST_F(DerivedFromBaseTransformPluginTest, CheckDataFlowThroughCreatedElement)
+{
+ CreatePipelineWithElements();
+
+ EXPECT_EQ(STATE_CHANGE_ASYNC, pipeline->set_state(STATE_PLAYING));
+
+ std::vector<guint8> data = {4, 5, 2, 7, 1};
+ RefPtr<Buffer> buf = Buffer::create(data.size());
+ ASSERT_TRUE(buf);
+ RefPtr<Gst::MapInfo> mapinfo(new Gst::MapInfo());
+
+ ASSERT_TRUE(buf->map(mapinfo, MAP_WRITE));
+ std::copy(data.begin(), data.end(), mapinfo->get_data());
+ EXPECT_EQ(FLOW_OK, source->push_buffer(buf));
+ buf->unmap(mapinfo);
+
+ RefPtr<Gst::Buffer> buf_out;
+ RefPtr<Gst::Sample> samp = sink->pull_preroll();
+
+ ASSERT_TRUE(samp);
+ buf_out = samp->get_buffer();
+ ASSERT_TRUE(buf_out->map(mapinfo, MAP_READ));
+ ASSERT_TRUE(mapinfo->get_data());
+ ASSERT_TRUE(std::equal(data.begin(), data.end(), mapinfo->get_data()));
+ buf_out->unmap(mapinfo);
+ EXPECT_EQ(FLOW_OK, source->end_of_stream());
+
+ EXPECT_EQ(STATE_CHANGE_SUCCESS, pipeline->set_state(Gst::STATE_NULL));
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]