[gstreamermm: 97/167] wrapped GstMapInfo, added simple test, implemented some methods in Buffer



commit 9f04fe76e863cb8a2e377ccff3a74ab2a7f83d37
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Wed Jul 31 11:37:35 2013 +0200

    wrapped GstMapInfo, added simple test, implemented some methods in Buffer

 .gitignore                   |    3 ++
 gstreamer/src/buffer.ccg     |    5 +++
 gstreamer/src/buffer.hg      |    9 ++++-
 gstreamer/src/filelist.am    |    1 +
 gstreamer/src/mapinfo.ccg    |   57 ++++++++++++++++++++++++++++++++++
 gstreamer/src/mapinfo.hg     |   69 ++++++++++++++++++++++++++++++++++++++++++
 tests/Makefile.am            |    3 +-
 tests/test-buffer-mapinfo.cc |   28 +++++++++++++++++
 tools/m4/convert_gst.m4      |    1 +
 9 files changed, 173 insertions(+), 3 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b9bdcf2..57ec67a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -110,6 +110,8 @@ gstreamer/gstreamermm/interface.cc
 gstreamer/gstreamermm/interface.h
 gstreamer/gstreamermm/iterator.cc
 gstreamer/gstreamermm/iterator.h
+gstreamer/gstreamermm/mapinfo.cc
+gstreamer/gstreamermm/mapinfo.h
 gstreamer/gstreamermm/memory.cc
 gstreamer/gstreamermm/memory.h
 gstreamer/gstreamermm/message.cc
@@ -461,6 +463,7 @@ gstreamer/src/xvimagesink.ccg
 gstreamer/src/xvimagesink.hg
 
 # tests/
+tests/test-buffer-mapinfo
 tests/test-caps
 tests/test-caps-structures
 tests/test-create-bin
diff --git a/gstreamer/src/buffer.ccg b/gstreamer/src/buffer.ccg
index 9ff5695..f55af0b 100644
--- a/gstreamer/src/buffer.ccg
+++ b/gstreamer/src/buffer.ccg
@@ -35,4 +35,9 @@ Glib::RefPtr<Gst::Buffer> Buffer::create_writable()
   return Glib::wrap(gst_buffer_make_writable(gobj()));
 }
 
+Glib::RefPtr<Gst::Buffer> Buffer::create(guint size)
+{
+  return Glib::wrap(gst_buffer_new_allocate(NULL, size, NULL));
+}
+
 } // namespace Gst
diff --git a/gstreamer/src/buffer.hg b/gstreamer/src/buffer.hg
index 7292946..3f4c4af 100644
--- a/gstreamer/src/buffer.hg
+++ b/gstreamer/src/buffer.hg
@@ -21,6 +21,7 @@
 #include <gstreamermm/miniobject.h>
 #include <gstreamermm/clock.h>
 #include <gstreamermm/memory.h>
+#include <gstreamermm/mapinfo.h>
 
 _DEFS(gstreamermm,gst)
 
@@ -48,8 +49,6 @@ class Buffer : public MiniObject
   _IGNORE(gst_buffer_ref, gst_buffer_unref)
 
 public:
-  _WRAP_METHOD(static Glib::RefPtr<Gst::Buffer> create(guint size), gst_buffer_try_new_and_alloc)
-
   /** Create a copy of the given buffer. This will also make a newly allocated
    * copy of the data the source buffer contains.
    * @return The Gst::Buffer copy.
@@ -59,6 +58,8 @@ public:
   _WRAP_METHOD(void copy_into(const Glib::RefPtr<Gst::Buffer>& source_buffer, BufferCopyFlags flags, gsize 
offset, gsize size), gst_buffer_copy_into)
   _WRAP_METHOD(bool is_metadata_writable() const, gst_buffer_is_metadata_writable)
 
+  static Glib::RefPtr<Gst::Buffer> create(guint size);
+
   /** Makes a writable buffer from the given buffer. If the source buffer is
    * already writable, this will simply return the same buffer. A copy will
    * otherwise be made.
@@ -87,6 +88,10 @@ public:
    */
   _MEMBER_GET(duration, duration, ClockTime, GstClockTime)
 
+#m4 _CONVERSION(`Gst::MapInfo*', `GstMapInfo*', `$3->gobj()')
+  _WRAP_METHOD(bool map(Gst::MapInfo* info, MapFlags flags), gst_buffer_map);
+
+  _WRAP_METHOD(void unmap(Gst::MapInfo* info), gst_buffer_unmap);
   /** Get the offset of this buffer.
    * @return The offset in the source file of the beginning of this buffer.
    */
diff --git a/gstreamer/src/filelist.am b/gstreamer/src/filelist.am
index 8963466..9a71c13 100644
--- a/gstreamer/src/filelist.am
+++ b/gstreamer/src/filelist.am
@@ -108,6 +108,7 @@ files_hg  =                     \
         format.hg               \
         ghostpad.hg             \
         iterator.hg             \
+        mapinfo.hg              \
         message.hg              \
         memory.hg               \
         miniobject.hg           \
diff --git a/gstreamer/src/mapinfo.ccg b/gstreamer/src/mapinfo.ccg
new file mode 100644
index 0000000..c7acf6d
--- /dev/null
+++ b/gstreamer/src/mapinfo.ccg
@@ -0,0 +1,57 @@
+/*
+ * mapinfo.ccg
+ *
+ *  Created on: Jul 31, 2013
+ *      Author: m.kolny
+ */
+#include <gstreamermm/handle_error.h>
+_PINCLUDE(gstreamermm/private/object_p.h)
+
+namespace Gst
+{
+MapInfo::MapInfo()
+: m_spec(g_try_new(GstMapInfo, 1)),
+  take_ownership(true)
+{
+  if(!m_spec)
+  {
+    gstreamermm_handle_error(
+      "Failed to allocate a new Gst::MapInfo.");
+    return;
+  }
+}
+
+MapInfo::MapInfo(GstMapInfo& castitem, bool take_ownership)
+: m_spec(&castitem),
+  take_ownership(take_ownership)
+{
+}
+
+MapInfo::MapInfo(const MapInfo& other)
+: m_spec(g_try_new(GstMapInfo, 1)),
+  take_ownership(true)
+{
+  // Handle possible memory allocation failure.
+  if(!m_spec)
+  {
+    gstreamermm_handle_error("Failed to allocate a new Gst::MapInfo.");
+    return;
+  }
+
+  m_spec->memory = other.m_spec->memory;
+  m_spec->data = other.m_spec->data;
+  m_spec->flags = other.m_spec->flags;
+  m_spec->maxsize = other.m_spec->maxsize;
+  m_spec->size = other.m_spec->size;
+
+}
+
+
+MapInfo::~MapInfo()
+{
+  if(take_ownership)
+    g_free(m_spec);
+}
+}
+
+
diff --git a/gstreamer/src/mapinfo.hg b/gstreamer/src/mapinfo.hg
new file mode 100644
index 0000000..3952e1b
--- /dev/null
+++ b/gstreamer/src/mapinfo.hg
@@ -0,0 +1,69 @@
+/*
+ * mapinfo.hg
+ *
+ *  Created on: Jul 31, 2013
+ *      Author: m.kolny
+ */
+/* 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 <gst/gst.h>
+#include <gstreamermm/memory.h>
+#include <gstreamermm/object.h>
+
+_DEFS(gstreamermm,gst)
+
+namespace Gst
+{
+
+_WRAP_ENUM(MapFlags, GstMapFlags)
+
+/* A structure containing the result of a map operation such as
+ * Memory::Map(). It contains the data and size.
+ */
+class MapInfo
+{
+    _CLASS_GENERIC(MapInfo, GstMapInfo)
+public:
+    MapInfo();
+
+    explicit MapInfo(GstMapInfo& castitem,
+      bool take_ownership = false);
+
+    MapInfo(const MapInfo& other);
+
+    virtual ~MapInfo();
+
+
+  _MEMBER_GET(flags, flags, MapFlags, GstMapFlags)
+  _MEMBER_GET(data, data, guint8*, guint8*)
+  _MEMBER_GET(maxsize, maxsize, gsize, gsize)
+  _MEMBER_GET(size, size, gsize, gsize)
+
+  GstMapInfo* gobj() { return m_spec; };
+  const GstMapInfo* gobj() const { return m_spec; };
+
+protected:
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+  GstMapInfo* m_spec;
+  bool take_ownership;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+};
+
+}//namespace Gst
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5c9ab48..4a8b810 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-plugin-register test-plugin-appsrc test-plugin-appsink test-plugin-pushsrc 
test-buffer-list-iterator
+                 test-plugin-register test-buffer-mapinfo test-plugin-appsrc test-plugin-appsink 
test-plugin-pushsrc test-buffer-list-iterator
 
 # Include run of test programs in check:
 TESTS = $(check_PROGRAMS)
@@ -63,3 +63,4 @@ 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_buffer_mapinfo_SOURCES    = test-buffer-mapinfo.cc 
diff --git a/tests/test-buffer-mapinfo.cc b/tests/test-buffer-mapinfo.cc
new file mode 100644
index 0000000..5455288
--- /dev/null
+++ b/tests/test-buffer-mapinfo.cc
@@ -0,0 +1,28 @@
+/*
+ * test-buffer-mapinfo.cc
+ *
+ *  Created on: Jul 31, 2013
+ *      Author: m.kolny
+ */
+
+#include <gstreamermm.h>
+#include <assert.h>
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char* argv[])
+{
+    Gst::init(argc, argv);
+    int buffer_size = 15;
+    cout << "Creating buffer..." << endl;
+    Glib::RefPtr<Gst::Buffer> buffer = Gst::Buffer::create(buffer_size);
+    Gst::MapInfo mapinfo ;
+    Gst::MapFlags flags;
+
+    buffer->map(&mapinfo, flags);
+
+    assert(mapinfo.get_size() == buffer_size);
+
+    cout << "Correct!" << endl;
+}
diff --git a/tools/m4/convert_gst.m4 b/tools/m4/convert_gst.m4
index b85305d..2bc20cf 100644
--- a/tools/m4/convert_gst.m4
+++ b/tools/m4/convert_gst.m4
@@ -26,6 +26,7 @@ _CONV_ENUM(Gst,IndexFlags)
 _CONV_ENUM(Gst,IndexLookupMethod)
 _CONV_ENUM(Gst,IndexResolverMethod)
 _CONV_ENUM(Gst,LockFlags)
+_CONV_ENUM(Gst,MapFlags)
 _CONV_ENUM(Gst,MessageType)
 _CONV_ENUM(Gst,MixerFlags)
 _CONV_ENUM(Gst,MixerType)


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