| 1 |
/* gstreamermm - a C++ wrapper for gstreamer |
| 2 |
* |
| 3 |
* Copyright 2008-2016 The gstreamermm Development Team |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free |
| 17 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <gst/gst.h> |
| 21 |
#include <gstreamermm/miniobject.h> |
| 22 |
#include <gstreamermm/mapinfo.h> |
| 23 |
|
| 24 |
_DEFS(gstreamermm,gst) |
| 25 |
|
| 26 |
namespace Gst |
| 27 |
{ |
| 28 |
|
| 29 |
_WRAP_ENUM(MemoryFlags, GstMemoryFlags) |
| 30 |
|
| 31 |
class Allocator; |
| 32 |
|
| 33 |
/** |
| 34 |
* GstMemory is a lightweight refcounted object that wraps a region of memory. |
| 35 |
* They are typically used to manage the data of a Gst::Buffer. |
| 36 |
* |
| 37 |
* A GstMemory object has an allocated region of memory of maxsize. The maximum |
| 38 |
* size does not change during the lifetime of the memory object. The memory |
| 39 |
* also has an offset and size property that specifies the valid range of memory |
| 40 |
* in the allocated region. |
| 41 |
* |
| 42 |
* Memory is usually created by allocators with a Gst::Allocator::alloc() |
| 43 |
* method call. |
| 44 |
* |
| 45 |
* New memory can be created with Gst::Memory::create() that wraps the memory |
| 46 |
* allocated elsewhere. |
| 47 |
* |
| 48 |
* The size of the memory can be retrieved and changed with get_sizes() |
| 49 |
* and resize() respectively. |
| 50 |
* |
| 51 |
* Getting access to the data of the memory is performed with map(). |
| 52 |
* The call will return a pointer to offset bytes into the region of memory. |
| 53 |
* After the memory access is completed, unmap() should be called. |
| 54 |
* |
| 55 |
* Memory can be copied with copy(), which will return a writable |
| 56 |
* copy. share() will create a new memory block that shares the |
| 57 |
* memory with an existing memory block at a custom offset and with a custom |
| 58 |
* size. |
| 59 |
* |
| 60 |
* Memory can be efficiently merged when is_span() returns %TRUE. |
| 61 |
* |
| 62 |
* Last reviewed on 2016-06-05 (1.8.0) |
| 63 |
*/ |
| 64 |
class Memory : public MiniObject |
| 65 |
{ |
| 66 |
_CLASS_OPAQUE_REFCOUNTED(Memory, GstMemory, NONE, gst_memory_ref, gst_memory_unref) |
| 67 |
_IGNORE(gst_memory_ref, gst_memory_unref) |
| 68 |
|
| 69 |
public: |
| 70 |
|
| 71 |
/* |
| 72 |
* Allocate a new memory block that wraps the given @a data. |
| 73 |
* |
| 74 |
* @param flags: Gst::MemoryFlags. |
| 75 |
* @param data Data to wrap. |
| 76 |
* @param maxsize Allocated size of @a data. |
| 77 |
* @param offset Offset in @data. |
| 78 |
* @param size Size of valid data. |
| 79 |
* |
| 80 |
* @returns a new #Gst::Memory. |
| 81 |
*/ |
| 82 |
static Glib::RefPtr<Memory> create(Gst::MemoryFlags flags, gpointer data, gsize maxsize, gsize offset, gsize size); |
| 83 |
|
| 84 |
/** Get the maximum size allocated. |
| 85 |
*/ |
| 86 |
_MEMBER_GET(maxsize, maxsize, gsize, gsize) |
| 87 |
|
| 88 |
/** Get the alignment of the memory. |
| 89 |
*/ |
| 90 |
_MEMBER_GET(align, align, gsize, gsize) |
| 91 |
|
| 92 |
/** Get the offset where valid data starts. |
| 93 |
*/ |
| 94 |
_MEMBER_GET(offset, offset, gsize, gsize) |
| 95 |
|
| 96 |
/** Get the size of valid data. |
| 97 |
*/ |
| 98 |
_MEMBER_GET(size, size, gsize, gsize) |
| 99 |
|
| 100 |
/** Get parent memory block. |
| 101 |
*/ |
| 102 |
_MEMBER_GET_GOBJECT(parent, parent, Gst::Memory, GstMemory*) |
| 103 |
|
| 104 |
/** Get the Gst::Allocator. |
| 105 |
*/ |
| 106 |
_MEMBER_GET_GOBJECT(allocator, allocator, Gst::Allocator, GstAllocator*) |
| 107 |
|
| 108 |
_WRAP_METHOD(bool is_type(const Glib::ustring& mem_type) const, gst_memory_is_type) |
| 109 |
_WRAP_METHOD(Glib::RefPtr<Gst::Memory> share(gssize offset, gssize size), gst_memory_share) |
| 110 |
_WRAP_METHOD(void resize(gssize offset, gsize size), gst_memory_resize) |
| 111 |
_WRAP_METHOD(bool is_span(const Glib::RefPtr<Gst::Memory>& mem2, gsize& offset), gst_memory_is_span) |
| 112 |
_WRAP_METHOD(bool map(Gst::MapInfo& info, Gst::MapFlags flags), gst_memory_map) |
| 113 |
_WRAP_METHOD(void unmap(Gst::MapInfo& info), gst_memory_unmap) |
| 114 |
_WRAP_METHOD(Glib::RefPtr<Gst::Memory> copy(gssize offset, gssize size), gst_memory_copy) |
| 115 |
_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) |
| 116 |
_WRAP_METHOD(gsize get_sizes(gsize& offset, gsize& maxsize), gst_memory_get_sizes) |
| 117 |
|
| 118 |
/** Create a Gst::Memory object that is mapped with @a flags. If @a mem is mappable |
| 119 |
* with @a flags, this function returns the mapped @a mem directly. Otherwise a |
| 120 |
* mapped copy of @a mem is returned. |
| 121 |
* |
| 122 |
* @param info Pointer for info. |
| 123 |
* @param flags Mapping flags. |
| 124 |
* |
| 125 |
* @return a Gst::Memory object mapped. |
| 126 |
*/ |
| 127 |
Glib::RefPtr<Gst::Memory> make_mapped(Gst::MapInfo& info, Gst::MapFlags flags); |
| 128 |
_IGNORE(gst_memory_make_mapped) |
| 129 |
|
| 130 |
}; |
| 131 |
|
| 132 |
}//namespace Gst |