[gstreamermm] Gst::Element: fix refcounting in post_message()



commit 2ef31550191f5e3aff0714907abec0befb0115c5
Author: Michał Wróbel <michal wrobel flytronic pl>
Date:   Sat Aug 8 11:46:16 2015 +0000

    Gst::Element: fix refcounting in post_message()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752790
    
        * .gitignore: add test-element output file to ignored list.
        * gstreamer/src/element.hg: fix refcounting post_message() by changing
          its argument type to rvalue reference which will make the wrapper
          use transfer full convention.
        * gstreamer/src/pad.ccg: provide an rvalue to post_message().
        * tests/Makefile.am:
        * tests/test-element.cc: add
          PostMessageShouldProperlyRefcountGivenMessage.

 .gitignore               |    3 ++-
 gstreamer/src/element.hg |    2 +-
 gstreamer/src/pad.ccg    |    2 +-
 tests/Makefile.am        |    4 +++-
 tests/test-element.cc    |   22 ++++++++++++++++++++++
 5 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index a011f66..f810086 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-       # wildcard patterns
+# wildcard patterns
 Makefile
 Makefile.in
 .deps
@@ -542,6 +542,7 @@ tests/test-buffer
 tests/test-bus
 tests/test-caps
 tests/test-capsfeatures
+tests/test-element
 tests/test-ghostpad
 tests/test-init
 tests/test-memory
diff --git a/gstreamer/src/element.hg b/gstreamer/src/element.hg
index 6af7448..d256174 100644
--- a/gstreamer/src/element.hg
+++ b/gstreamer/src/element.hg
@@ -278,7 +278,7 @@ public:
     const Glib::ustring& function = Glib::ustring());
   _IGNORE(gst_element_message_full)
 
-  _WRAP_METHOD(bool post_message(const Glib::RefPtr<Gst::Message>& message), gst_element_post_message)
+  _WRAP_METHOD(bool post_message(Glib::RefPtr<Gst::Message>&& message), gst_element_post_message)
 
   _WRAP_METHOD(bool query(const Glib::RefPtr<Gst::Query>& query) const, gst_element_query)
   _WRAP_METHOD(bool query_convert(Gst::Format src_format, gint64 src_val, Format dest_format, gint64& 
dest_val) const, gst_element_query_convert)
diff --git a/gstreamer/src/pad.ccg b/gstreamer/src/pad.ccg
index ef66692..bd5f026 100644
--- a/gstreamer/src/pad.ccg
+++ b/gstreamer/src/pad.ccg
@@ -128,7 +128,7 @@ void Pad::exception_handler()
     error_msg = MessageError::create(parent, err, "unknown error type");
   }
 
-  parent->post_message(error_msg);
+  parent->post_message(std::move(error_msg));
 }
 
 gulong Pad::add_probe(PadProbeType mask, const SlotProbe& slot)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e961d5b..25489e7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@ check_PROGRAMS =                                \
         test-caps                               \
         test-caps                               \
         test-capsfeatures                       \
+       test-element                            \
         test-ghostpad                           \
         test-init                               \
         test-memory                             \
@@ -70,6 +71,7 @@ test_buffer_SOURCES                             = $(TEST_GTEST_SOURCES) test-buf
 test_bus_SOURCES                                = $(TEST_GTEST_SOURCES) test-bus.cc
 test_capsfeatures_SOURCES                       = $(TEST_GTEST_SOURCES) test-capsfeatures.cc
 test_caps_SOURCES                               = $(TEST_GTEST_SOURCES) test-caps.cc
+test_element_SOURCES                            = $(TEST_GTEST_SOURCES) test-element.cc
 test_ghostpad_SOURCES                           = $(TEST_GTEST_SOURCES) test-ghostpad.cc
 test_init_SOURCES                               = $(TEST_GTEST_SOURCES) test-init.cc
 test_memory_SOURCES                             = $(TEST_GTEST_SOURCES) test-memory.cc
@@ -117,4 +119,4 @@ gtest: gtest.zip
 check_DATA = gtest
 CLEANFILES = gtest.zip
 clean-local:
-       rm -rf gtest
\ No newline at end of file
+       rm -rf gtest
diff --git a/tests/test-element.cc b/tests/test-element.cc
new file mode 100644
index 0000000..4d47b70
--- /dev/null
+++ b/tests/test-element.cc
@@ -0,0 +1,22 @@
+#include <gtest/gtest.h>
+#include <glibmm/threads.h>
+#include <gstreamermm/identity.h>
+#include <gstreamermm/iterator.h>
+#include <gstreamermm/bus.h>
+
+using namespace Gst;
+using namespace Glib;
+
+TEST(ElementTest, PostMessageShouldProperlyRefcountGivenMessage)
+{
+  RefPtr<Bus> bus = Bus::create();
+  ASSERT_TRUE(bus);
+  RefPtr<Element> element = Identity::create();
+  ASSERT_TRUE(element);
+  element->set_bus(bus);
+  ASSERT_TRUE(element->post_message(MessageStateDirty::create(element)));
+  RefPtr<Message> msg = bus->pop();
+  ASSERT_TRUE(msg);
+  ASSERT_TRUE(GST_IS_MESSAGE(msg->gobj()));
+  ASSERT_EQ(1, msg->get_refcount());
+}


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