[gstreamermm] Gst::Memory: wrap unwrapped methods



commit 75e31417f6461ba69d7585b253ac697729ffa7dd
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Sat Feb 28 19:44:23 2015 +0100

    Gst::Memory: wrap unwrapped methods
    
        * .gitignore: add test bin files to ignored list.
        * gstreamer/src/gst_extra_objects.defs: add definition of GstMemory
          object to a *.defs file.
        * gstreamer/src/mapinfo.hg: remove unnecessary header.
        * gstreamer/src/memory.{ccg|hg}: wrap methods: gst_memory_{is_type|
          share|resize|is_span|map|unmap|copy|init|get_sizes|make_mapped}.
        * tests/Makefile.am: add memory test to makefile.
        * tests/test-memory.cc: simple memory testcase.
        * tools/m4/convert_gst.m4: define additional conversions for allocator
          and memory classes.

 .gitignore                           |    2 ++
 gstreamer/src/gst_extra_objects.defs |    6 ++++++
 gstreamer/src/mapinfo.hg             |    1 -
 gstreamer/src/memory.ccg             |    8 ++++++++
 gstreamer/src/memory.hg              |   26 ++++++++++++++++++++++++++
 tests/Makefile.am                    |    3 ++-
 tests/test-memory.cc                 |   22 ++++++++++++++++++++++
 tools/m4/convert_gst.m4              |    4 ++++
 8 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index de26be5..3ad2a07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -493,6 +493,8 @@ tests/test-caps
 tests/test-capsfeatures
 tests/test-ghostpad
 tests/test-init
+tests/test-memory
+tests/test-message
 tests/test-miniobject
 tests/test-pad
 tests/test-pipeline
diff --git a/gstreamer/src/gst_extra_objects.defs b/gstreamer/src/gst_extra_objects.defs
index 8bd2b60..1d95a9f 100644
--- a/gstreamer/src/gst_extra_objects.defs
+++ b/gstreamer/src/gst_extra_objects.defs
@@ -28,6 +28,12 @@
   (c-name "GstIterator")
 )
 
+(define-object Memory
+  (in-module "Gst")
+  (c-name "GstMemory")
+  (gtype-id "GST_TYPE_MEMORY")
+)
+
 (define-object MiniObject
   (in-module "Gst")
   (c-name "GstMiniObject")
diff --git a/gstreamer/src/mapinfo.hg b/gstreamer/src/mapinfo.hg
index bc7cf41..81cf6c3 100644
--- a/gstreamer/src/mapinfo.hg
+++ b/gstreamer/src/mapinfo.hg
@@ -24,7 +24,6 @@
  */
 
 #include <gst/gst.h>
-#include <gstreamermm/memory.h>
 #include <gstreamermm/object.h>
 
 _DEFS(gstreamermm,gst)
diff --git a/gstreamer/src/memory.ccg b/gstreamer/src/memory.ccg
index dc0943d..c27d5e4 100644
--- a/gstreamer/src/memory.ccg
+++ b/gstreamer/src/memory.ccg
@@ -18,6 +18,7 @@
  */
 
 _PINCLUDE(gstreamermm/private/miniobject_p.h)
+#include <gstreamermm/allocator.h>
 
 namespace Gst
 {
@@ -27,4 +28,11 @@ Glib::RefPtr<Gst::Memory> Memory::create(Gst::MemoryFlags flags, gpointer data,
     return Glib::RefPtr<Memory>(reinterpret_cast<Memory*>(gst_memory_new_wrapped(GstMemoryFlags(flags), 
data, maxsize, offset, size, 0, 0)));
 }
 
+Glib::RefPtr<Gst::Memory> Memory::make_mapped(const Glib::RefPtr<Gst::MapInfo>& info, Gst::MapFlags flags)
+{
+  reference();
+  GstMemory* new_mem = gst_memory_make_mapped(gobj(), info->gobj(), static_cast<GstMapFlags>(flags));
+  return Glib::wrap(new_mem, gobj() != new_mem);
+}
+
 }
diff --git a/gstreamer/src/memory.hg b/gstreamer/src/memory.hg
index 6efa0bb..3575376 100644
--- a/gstreamer/src/memory.hg
+++ b/gstreamer/src/memory.hg
@@ -19,6 +19,7 @@
 
 #include <gst/gst.h>
 #include <gstreamermm/miniobject.h>
+#include <gstreamermm/mapinfo.h>
 
 _DEFS(gstreamermm,gst)
 
@@ -27,6 +28,8 @@ namespace Gst
 
 _WRAP_ENUM(MemoryFlags, GstMemoryFlags)
 
+class Allocator;
+
 /**
  * GstMemory is a lightweight refcounted object that wraps a region of memory.
  * They are typically used to manage the data of a #GstBuffer.
@@ -61,6 +64,29 @@ public:
   _MEMBER_GET(align, align, gsize, gsize)
   _MEMBER_GET(offset, offset, gsize, gsize)
   _MEMBER_GET(size, size, gsize, gsize)
+
+  _WRAP_METHOD(bool is_type(const Glib::ustring& mem_type) const, gst_memory_is_type)
+  _WRAP_METHOD(Glib::RefPtr<Gst::Memory> share(gssize offset, gssize size), gst_memory_share)
+  _WRAP_METHOD(void resize(gssize offset, gsize size), gst_memory_resize)
+  _WRAP_METHOD(bool is_span(const Glib::RefPtr<Gst::Memory>& mem2, gsize& offset), gst_memory_is_span)
+  _WRAP_METHOD(bool map(const Glib::RefPtr<Gst::MapInfo>& info, Gst::MapFlags flags), gst_memory_map)
+  _WRAP_METHOD(void unmap(const Glib::RefPtr<Gst::MapInfo>& info), gst_memory_unmap)
+  _WRAP_METHOD(Glib::RefPtr<Gst::Memory> copy(gssize offset, gssize size), gst_memory_copy)
+  _WRAP_METHOD(void init(Gst::MemoryFlags flags, const Glib::RefPtr<Gst::Allocator>& allocator, const 
Glib::RefPtr<Gst::Memory>& parent, gsize maxsize, gsize align, gsize offset, gsize size), gst_memory_init)
+  _WRAP_METHOD(gsize get_sizes(gsize& offset, gsize& maxsize), gst_memory_get_sizes)
+
+  /** Create a Gst::Memory object that is mapped with @flags. If @mem is mappable
+   * with @flags, this function returns the mapped @mem directly. Otherwise a
+   * mapped copy of @mem is returned.
+   *
+   * @param info Pointer for info.
+   * @param flags Mapping flags.
+   *
+   * @return a Gst::Memory object mapped.
+   */
+  Glib::RefPtr<Gst::Memory> make_mapped(const Glib::RefPtr<Gst::MapInfo>& info, Gst::MapFlags flags);
+  _IGNORE(gst_memory_make_mapped)
+
 };
 
 }//namespace Gst
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b1f4c3e..5eb2d9e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,7 +22,7 @@ LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm) -lgtest -lpthread
 
 check_PROGRAMS = test-caps test-buffer test-bus test-caps test-pad \
                  test-allocator test-atomicqueue test-bin \
-                 test-capsfeatures test-message \
+                 test-capsfeatures test-message test-memory \
                  test-urihandler test-ghostpad test-init test-miniobject \
                  test-query test-structure test-taglist test-plugin-appsink \
                  test-plugin-appsrc test-plugin-register test-plugin-pushsrc \
@@ -45,6 +45,7 @@ test_buffer_SOURCES                   = test-buffer.cc $(TEST_MAIN_SOURCE)
 test_bus_SOURCES                       = test-bus.cc $(TEST_MAIN_SOURCE)
 test_ghostpad_SOURCES          = test-ghostpad.cc $(TEST_MAIN_SOURCE)
 test_init_SOURCES                      = test-init.cc $(TEST_MAIN_SOURCE)
+test_memory_SOURCES                    = test-memory.cc $(TEST_MAIN_SOURCE)
 test_message_SOURCES           = test-message.cc $(TEST_MAIN_SOURCE)
 test_miniobject_SOURCES                = test-miniobject.cc $(TEST_MAIN_SOURCE)
 test_pad_SOURCES                       = test-pad.cc $(TEST_MAIN_SOURCE)
diff --git a/tests/test-memory.cc b/tests/test-memory.cc
new file mode 100644
index 0000000..d16a9fe
--- /dev/null
+++ b/tests/test-memory.cc
@@ -0,0 +1,22 @@
+/*
+ * test-message.cc
+ *
+ *  Created on: Feb 28, 2015
+ *      Author: m.kolny
+ */
+#include <gtest/gtest.h>
+#include <gstreamermm.h>
+
+using namespace Gst;
+
+TEST(MemoryTest, CheckMemoryMappedRefcount)
+{
+  guint* data = new guint[10];
+  Glib::RefPtr<Memory> mem = Memory::create(MEMORY_FLAG_READONLY, data, 10, 0, 10);
+  Glib::RefPtr<MapInfo> info(new MapInfo());
+  Glib::RefPtr<Memory> mp = mem->make_mapped(info, MAP_READ);
+  mp->unmap(info);
+  ASSERT_EQ(2, mem->get_refcount());
+  ASSERT_EQ(2, mp->get_refcount());
+  delete data;
+}
diff --git a/tools/m4/convert_gst.m4 b/tools/m4/convert_gst.m4
index 181031e..8ecb922 100644
--- a/tools/m4/convert_gst.m4
+++ b/tools/m4/convert_gst.m4
@@ -68,6 +68,9 @@ dnl AllocationParams
 _CONVERSION(`AllocationParams', `GstAllocationParams*', `$3.gobj()')
 _CONVERSION(`GstAllocationParams*', `AllocationParams', `AllocationParams($3, true)')
 
+dnl Allocator
+_CONVERSION(`const Glib::RefPtr<Gst::Allocator>&',`GstAllocator*', `Glib::unwrap($3)')
+
 dnl Buffer
 _CONVERSION(`GstBuffer*',`Glib::RefPtr<Gst::Buffer>',`Glib::wrap($3)')
 _CONVERSION(`const Glib::RefPtr<Gst::Buffer>&',`GstBuffer*', `Glib::unwrap($3)')
@@ -167,6 +170,7 @@ dnl Memory
 _CONVERSION(`GstMemory*',`Glib::RefPtr<Gst::Memory>&',`Glib::wrap($3)')
 _CONVERSION(`GstMemory*',`Glib::RefPtr<Gst::Memory>',`Glib::wrap($3)')
 _CONVERSION(`Glib::RefPtr<Gst::Memory>&',`GstMemory*', `Glib::unwrap($3)')
+_CONVERSION(`const Glib::RefPtr<Gst::Memory>&',`GstMemory*', `Glib::unwrap($3)')
 _CONVERSION(`Glib::RefPtr<Gst::Memory>',`GstMemory*', `Glib::unwrap($3)')
 
 dnl Message


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