[gstreamermm] C++11: use rvalue references for transfer-full method parameters - part 2



commit 1667021a4475f4d2eccce3ba79a9c9b70c4762a6
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Sat Aug 22 15:12:12 2015 +0000

    C++11: use rvalue references for transfer-full method parameters - part 2
    
    This commit breaks the API. But version 1.6 of gstreamermm enables C++11
    flag in compilers, so it's good time to change API slightly. Since
    version 1.6 gstreamermm's API will be marked as 'stable'.
    
        * .gitignore: update ignore list.
        * gstreamer/src/bufferlist.hg:
        * gstreamer/src/clock.hg:
        * gstreamer/src/element.ccg:
        * gstreamer/src/element.hg:
        * gstreamer/src/registry.hg: update some method interfaces.
        * tests/Makefile.am:
        * tests/test-bufferlist.cc: add test for bufferlist class.
        * tools/m4/convert_gst.m4: add some conversion definitions.

 .gitignore                  |    1 +
 gstreamer/src/bufferlist.hg |    2 +-
 gstreamer/src/clock.hg      |    2 +-
 gstreamer/src/element.ccg   |    8 --------
 gstreamer/src/element.hg    |   12 +-----------
 gstreamer/src/registry.hg   |    4 ++--
 tests/Makefile.am           |    4 +++-
 tests/test-bufferlist.cc    |   23 +++++++++++++++++++++++
 tools/m4/convert_gst.m4     |    3 +++
 9 files changed, 35 insertions(+), 24 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index f810086..d35597a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -539,6 +539,7 @@ tests/test-allocator
 tests/test-atomicqueue
 tests/test-bin
 tests/test-buffer
+tests/test-bufferlist
 tests/test-bus
 tests/test-caps
 tests/test-capsfeatures
diff --git a/gstreamer/src/bufferlist.hg b/gstreamer/src/bufferlist.hg
index 33f7356..9ce2974 100644
--- a/gstreamer/src/bufferlist.hg
+++ b/gstreamer/src/bufferlist.hg
@@ -73,7 +73,7 @@ public:
 
   _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> remove(guint idx), gst_buffer_list_get)
 
-  _WRAP_METHOD(void add(gint idx, const Glib::RefPtr<Gst::Buffer>& buffer), gst_buffer_list_insert)
+  _WRAP_METHOD(void insert(gint idx, Glib::RefPtr<Gst::Buffer>&& buffer), gst_buffer_list_insert)
 
   /** Tests if you can safely add buffers and groups into a buffer list.
    * @return <tt>true</tt> if the buffer list is writable, <tt>false</tt>
diff --git a/gstreamer/src/clock.hg b/gstreamer/src/clock.hg
index 2cb274e..fe38082 100644
--- a/gstreamer/src/clock.hg
+++ b/gstreamer/src/clock.hg
@@ -227,7 +227,7 @@ class Clock : public Object
   _CLASS_GOBJECT(Clock, GstClock, GST_CLOCK, Object, GstObject)
 
 public:
-  _WRAP_METHOD(bool add_observation(Gst::ClockTime slave_time, Gst::ClockTime master_time, gdouble* result), 
gst_clock_add_observation)
+  _WRAP_METHOD(bool add_observation(Gst::ClockTime slave_time, Gst::ClockTime master_time, gdouble& result), 
gst_clock_add_observation)
   _WRAP_METHOD(bool set_master(const Clock& master_clock), gst_clock_set_master)
   _WRAP_METHOD(Glib::RefPtr<Gst::Clock> get_master(), gst_clock_get_master)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Clock> get_master() const, gst_clock_get_master, constversion)
diff --git a/gstreamer/src/element.ccg b/gstreamer/src/element.ccg
index 3889e8a..4a1e4fb 100644
--- a/gstreamer/src/element.ccg
+++ b/gstreamer/src/element.ccg
@@ -106,14 +106,6 @@ bool Element::query_duration(Format format) const
   return gst_element_query_duration(const_cast<GstElement*>(gobj()), (GstFormat)format, nullptr);
 }
 
-// This method is written manually because an extra ref is necessary. See
-// gst_element_send_event() docs
-bool Element::send_event(const Glib::RefPtr<Gst::Event>& event)
-{
-  event->reference();
-  return gst_element_send_event(gobj(), Glib::unwrap(event));
-}
-
 gboolean Element_Class::set_clock_vfunc_callback(GstElement* self, GstClock* clock)
 {
   Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
diff --git a/gstreamer/src/element.hg b/gstreamer/src/element.hg
index d256174..96351ef 100644
--- a/gstreamer/src/element.hg
+++ b/gstreamer/src/element.hg
@@ -305,17 +305,7 @@ public:
   _WRAP_METHOD(bool seek(Format format, SeekFlags seek_flags, gint64 seek_pos), gst_element_seek_simple)
   _WRAP_METHOD(bool seek(double rate, Format format, SeekFlags flags, SeekType cur_type, gint64 cur, 
SeekType stop_type, gint64 stop), gst_element_seek)
 
-  /** Sends an event to an element. If the element doesn't implement an event
-   * handler, the event will be pushed on a random linked sink pad for upstream
-   * events or a random linked source pad for downstream events.
-   *
-   * This function takes owership of the provided event.
-   *
-   * @param event The Gst::Event to send to the element.
-   * @return true if the event was handled. MT safe. 
-   */
-  bool send_event(const Glib::RefPtr<Gst::Event>& event);
-  _IGNORE(gst_element_send_event)
+  _WRAP_METHOD(bool send_event(Glib::RefPtr<Gst::Event>&& event), gst_element_send_event)
 
   _WRAP_SIGNAL(void no_more_pads(), "no-more-pads")
 
diff --git a/gstreamer/src/registry.hg b/gstreamer/src/registry.hg
index 451b7f8..19652ba 100644
--- a/gstreamer/src/registry.hg
+++ b/gstreamer/src/registry.hg
@@ -110,7 +110,7 @@ public:
 #m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<const Gst::Plugin> >',`$2($3, 
Glib::OWNERSHIP_DEEP)')
   _WRAP_METHOD(Glib::ListHandle< Glib::RefPtr<const Gst::Plugin> > get_plugin_list() const, 
gst_registry_get_plugin_list)
 
-  _WRAP_METHOD(bool add_plugin(const Glib::RefPtr<Gst::Plugin>& plugin), gst_registry_add_plugin)
+  _WRAP_METHOD(bool add_plugin(Glib::RefPtr<Gst::Plugin>&& plugin), gst_registry_add_plugin)
   _WRAP_METHOD(void remove_plugin(const Glib::RefPtr<Gst::Plugin>& plugin), gst_registry_remove_plugin)
 
   /** Runs a filter against all plugins in the registry and returns a List with
@@ -170,7 +170,7 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Gst::Plugin> lookup(const Glib::ustring& filename), gst_registry_lookup)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Plugin> lookup(const Glib::ustring& filename) const, 
gst_registry_lookup, constversion)
   _WRAP_METHOD(void remove_feature(const Glib::RefPtr<Gst::PluginFeature>& feature), 
gst_registry_remove_feature)
-  _WRAP_METHOD(void add_feature(const Glib::RefPtr<Gst::PluginFeature>& feature), gst_registry_add_feature)
+  _WRAP_METHOD(void add_feature(Glib::RefPtr<Gst::PluginFeature>&& feature), gst_registry_add_feature)
   _WRAP_METHOD(static bool check_feature_version(const Glib::ustring& feature_name, guint min_major, guint 
min_minor, guint min_micro), gst_default_registry_check_feature_version)
   
   static Glib::RefPtr<Gst::Registry> get();
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 25489e7..dec6d7a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,11 +25,12 @@ check_PROGRAMS =                                \
         test-atomicqueue                        \
         test-bin                                \
         test-buffer                             \
+        test-bufferlist                         \
         test-bus                                \
         test-caps                               \
         test-caps                               \
         test-capsfeatures                       \
-       test-element                            \
+        test-element                            \
         test-ghostpad                           \
         test-init                               \
         test-memory                             \
@@ -68,6 +69,7 @@ test_allocator_SOURCES                          = $(TEST_GTEST_SOURCES) test-all
 test_atomicqueue_SOURCES                        = $(TEST_GTEST_SOURCES) test-atomicqueue.cc
 test_bin_SOURCES                                = $(TEST_GTEST_SOURCES) test-bin.cc
 test_buffer_SOURCES                             = $(TEST_GTEST_SOURCES) test-buffer.cc
+test_bufferlist_SOURCES                         = $(TEST_GTEST_SOURCES) test-bufferlist.cc
 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
diff --git a/tests/test-bufferlist.cc b/tests/test-bufferlist.cc
new file mode 100644
index 0000000..01b1272
--- /dev/null
+++ b/tests/test-bufferlist.cc
@@ -0,0 +1,23 @@
+/*
+ * test-bufferlist.cc
+ *
+ *  Created on: Aug 22, 2015
+ *      Author: m.kolny
+ */
+
+#include <gtest/gtest.h>
+#include <gstreamermm/bufferlist.h>
+#include <gstreamermm/buffer.h>
+
+using namespace Gst;
+
+TEST(BufferTest, BufferShouldBeReleasedAfterAddToAList)
+{
+  Glib::RefPtr<Gst::BufferList> list = Gst::BufferList::create();
+  Glib::RefPtr<Gst::Buffer> buff = Gst::Buffer::create();
+  Glib::RefPtr<Gst::Buffer> buff2 = buff;
+  list->insert(0, std::move(buff));
+  ASSERT_FALSE(buff);
+  buff = list->get(0);
+  ASSERT_TRUE(buff == buff2);
+}
diff --git a/tools/m4/convert_gst.m4 b/tools/m4/convert_gst.m4
index a43b71d..3f41455 100644
--- a/tools/m4/convert_gst.m4
+++ b/tools/m4/convert_gst.m4
@@ -243,10 +243,12 @@ _CONVERSION(`const Gst::StaticPadTemplate&',`const GstStaticPadTemplate*',($3).g
 dnl Plugin
 _CONVERSION(`const Glib::RefPtr<Gst::Plugin>&',`GstPlugin*',`Glib::unwrap($3)')
 _CONVERSION(`GstPlugin*',`Glib::RefPtr<Gst::Plugin>',`Glib::wrap($3)')
+_CONVERSION(`Glib::RefPtr<Gst::Plugin>&&',`GstPlugin*',`($3) ? $3.release()->gobj() : nullptr')
 
 dnl PluginFeature
 _CONVERSION(`GstPluginFeature*',`Glib::RefPtr<Gst::PluginFeature>',`Glib::wrap($3)')
 _CONVERSION(`const Glib::RefPtr<Gst::PluginFeature>&',`GstPluginFeature*',`Glib::unwrap($3)')
+_CONVERSION(`Glib::RefPtr<Gst::PluginFeature>&&',`GstPluginFeature*',`($3) ? $3.release()->gobj() : nullptr')
 
 dnl Query
 _CONVERSION(`const Glib::RefPtr<Gst::Query>&',`GstQuery*', `Glib::unwrap($3)')
@@ -343,6 +345,7 @@ _CONVERSION(`const guint&',`guint',`$3')
 _CONVERSION(`gsize*',`gsize&',`*$3')
 _CONVERSION(`const guint32&',`guint32',`$3')
 _CONVERSION(`guint8*&',`guint8**',`&$3')
+_CONVERSION(`gdouble&',`gdouble*',`&$3')
 
 dnl Basic Gstreamermm Conversions
 _CONVERSION(`Gst::ClockTime&',`GstClockTime*',`(GstClockTime*)(&$3)')


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