| 1 | // Generated by gmmproc 2.50.1 -- DO NOT MODIFY! |
| 2 | #ifndef _GSTREAMERMM_MEMORY_H |
| 3 | #define _GSTREAMERMM_MEMORY_H |
| 4 | |
| 5 | |
| 6 | #include <glibmm/ustring.h> |
| 7 | #include <sigc++/sigc++.h> |
| 8 | |
| 9 | /* gstreamermm - a C++ wrapper for gstreamer |
| 10 | * |
| 11 | * Copyright 2008-2016 The gstreamermm Development Team |
| 12 | * |
| 13 | * This library is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU Lesser General Public |
| 15 | * License as published by the Free Software Foundation; either |
| 16 | * version 2.1 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This library is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * Lesser General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU Lesser General Public |
| 24 | * License along with this library; if not, write to the Free |
| 25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <gst/gst.h> |
| 29 | #include <gstreamermm/miniobject.h> |
| 30 | #include <gstreamermm/mapinfo.h> |
| 31 | |
| 32 | |
| 33 | namespace Gst |
| 34 | { |
| 35 | |
| 36 | /** @addtogroup gstreamermmEnums gstreamermm Enums and Flags */ |
| 37 | |
| 38 | /** |
| 39 | * @var MemoryFlags MEMORY_FLAG_READONLY |
| 40 | * Memory is readonly. It is not allowed to map the |
| 41 | * memory with Gst::MAP_WRITE. |
| 42 | * |
| 43 | * @var MemoryFlags MEMORY_FLAG_NO_SHARE |
| 44 | * Memory must not be shared. Copies will have to be |
| 45 | * made when this memory needs to be shared between buffers. |
| 46 | * |
| 47 | * @var MemoryFlags MEMORY_FLAG_ZERO_PREFIXED |
| 48 | * The memory prefix is filled with 0 bytes. |
| 49 | * |
| 50 | * @var MemoryFlags MEMORY_FLAG_ZERO_PADDED |
| 51 | * The memory padding is filled with 0 bytes. |
| 52 | * |
| 53 | * @var MemoryFlags MEMORY_FLAG_PHYSICALLY_CONTIGUOUS |
| 54 | * The memory is physically contiguous. (Since 1.2). |
| 55 | * |
| 56 | * @var MemoryFlags MEMORY_FLAG_NOT_MAPPABLE |
| 57 | * The memory can't be mapped via Gst::Memory::map() without any preconditions. (Since 1.2). |
| 58 | * |
| 59 | * @var MemoryFlags MEMORY_FLAG_LAST |
| 60 | * First flag that can be used for custom purposes. |
| 61 | * |
| 62 | * @enum MemoryFlags |
| 63 | * |
| 64 | * Flags for wrapped memory. |
| 65 | * |
| 66 | * @ingroup gstreamermmEnums |
| 67 | * @par Bitwise operators: |
| 68 | * <tt>%MemoryFlags operator|(MemoryFlags, MemoryFlags)</tt><br> |
| 69 | * <tt>%MemoryFlags operator&(MemoryFlags, MemoryFlags)</tt><br> |
| 70 | * <tt>%MemoryFlags operator^(MemoryFlags, MemoryFlags)</tt><br> |
| 71 | * <tt>%MemoryFlags operator~(MemoryFlags)</tt><br> |
| 72 | * <tt>%MemoryFlags& operator|=(MemoryFlags&, MemoryFlags)</tt><br> |
| 73 | * <tt>%MemoryFlags& operator&=(MemoryFlags&, MemoryFlags)</tt><br> |
| 74 | * <tt>%MemoryFlags& operator^=(MemoryFlags&, MemoryFlags)</tt><br> |
| 75 | */ |
| 76 | enum MemoryFlags |
| 77 | { |
| 78 | MEMORY_FLAG_READONLY = GST_MINI_OBJECT_FLAG_LOCK_READONLY, |
| 79 | MEMORY_FLAG_NO_SHARE = (GST_MINI_OBJECT_FLAG_LAST << 0), |
| 80 | MEMORY_FLAG_ZERO_PREFIXED = (GST_MINI_OBJECT_FLAG_LAST << 1), |
| 81 | MEMORY_FLAG_ZERO_PADDED = (GST_MINI_OBJECT_FLAG_LAST << 2), |
| 82 | MEMORY_FLAG_PHYSICALLY_CONTIGUOUS = (GST_MINI_OBJECT_FLAG_LAST << 3), |
| 83 | MEMORY_FLAG_NOT_MAPPABLE = (GST_MINI_OBJECT_FLAG_LAST << 4), |
| 84 | MEMORY_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 16) |
| 85 | }; |
| 86 | |
| 87 | /** @ingroup gstreamermmEnums */ |
| 88 | inline MemoryFlags operator|(MemoryFlags lhs, MemoryFlags rhs) |
| 89 | { return static_cast<MemoryFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); } |
| 90 | |
| 91 | /** @ingroup gstreamermmEnums */ |
| 92 | inline MemoryFlags operator&(MemoryFlags lhs, MemoryFlags rhs) |
| 93 | { return static_cast<MemoryFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); } |
| 94 | |
| 95 | /** @ingroup gstreamermmEnums */ |
| 96 | inline MemoryFlags operator^(MemoryFlags lhs, MemoryFlags rhs) |
| 97 | { return static_cast<MemoryFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); } |
| 98 | |
| 99 | /** @ingroup gstreamermmEnums */ |
| 100 | inline MemoryFlags operator~(MemoryFlags flags) |
| 101 | { return static_cast<MemoryFlags>(~static_cast<unsigned>(flags)); } |
| 102 | |
| 103 | /** @ingroup gstreamermmEnums */ |
| 104 | inline MemoryFlags& operator|=(MemoryFlags& lhs, MemoryFlags rhs) |
| 105 | { return (lhs = static_cast<MemoryFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); } |
| 106 | |
| 107 | /** @ingroup gstreamermmEnums */ |
| 108 | inline MemoryFlags& operator&=(MemoryFlags& lhs, MemoryFlags rhs) |
| 109 | { return (lhs = static_cast<MemoryFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); } |
| 110 | |
| 111 | /** @ingroup gstreamermmEnums */ |
| 112 | inline MemoryFlags& operator^=(MemoryFlags& lhs, MemoryFlags rhs) |
| 113 | { return (lhs = static_cast<MemoryFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); } |
| 114 | |
| 115 | } // namespace Gst |
| 116 | |
| 117 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 118 | namespace Glib |
| 119 | { |
| 120 | |
| 121 | template <> |
| 122 | class Value<Gst::MemoryFlags> : public Glib::Value_Flags<Gst::MemoryFlags> |
| 123 | { |
| 124 | public: |
| 125 | static GType value_type() G_GNUC_CONST; |
| 126 | }; |
| 127 | |
| 128 | } // namespace Glib |
| 129 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 130 | |
| 131 | namespace Gst |
| 132 | { |
| 133 | |
| 134 | |
| 135 | class Allocator; |
| 136 | |
| 137 | /** |
| 138 | * GstMemory is a lightweight refcounted object that wraps a region of memory. |
| 139 | * They are typically used to manage the data of a Gst::Buffer. |
| 140 | * |
| 141 | * A GstMemory object has an allocated region of memory of maxsize. The maximum |
| 142 | * size does not change during the lifetime of the memory object. The memory |
| 143 | * also has an offset and size property that specifies the valid range of memory |
| 144 | * in the allocated region. |
| 145 | * |
| 146 | * Memory is usually created by allocators with a Gst::Allocator::alloc() |
| 147 | * method call. |
| 148 | * |
| 149 | * New memory can be created with Gst::Memory::create() that wraps the memory |
| 150 | * allocated elsewhere. |
| 151 | * |
| 152 | * The size of the memory can be retrieved and changed with get_sizes() |
| 153 | * and resize() respectively. |
| 154 | * |
| 155 | * Getting access to the data of the memory is performed with map(). |
| 156 | * The call will return a pointer to offset bytes into the region of memory. |
| 157 | * After the memory access is completed, unmap() should be called. |
| 158 | * |
| 159 | * Memory can be copied with copy(), which will return a writable |
| 160 | * copy. share() will create a new memory block that shares the |
| 161 | * memory with an existing memory block at a custom offset and with a custom |
| 162 | * size. |
| 163 | * |
| 164 | * Memory can be efficiently merged when is_span() returns %TRUE. |
| 165 | * |
| 166 | * Last reviewed on 2016-06-05 (1.8.0) |
| 167 | */ |
| 168 | class Memory : public MiniObject |
| 169 | { |
| 170 | public: |
| 171 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 172 | using CppObjectType = Memory; |
| 173 | using BaseObjectType = GstMemory; |
| 174 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 175 | |
| 176 | |
| 177 | /** Increment the reference count for this object. |
| 178 | * You should never need to do this manually - use the object via a RefPtr instead. |
| 179 | */ |
| 180 | void reference() const; |
| 181 | |
| 182 | /** Decrement the reference count for this object. |
| 183 | * You should never need to do this manually - use the object via a RefPtr instead. |
| 184 | */ |
| 185 | void unreference() const; |
| 186 | |
| 187 | ///Provides access to the underlying C instance. |
| 188 | GstMemory* gobj(); |
| 189 | |
| 190 | ///Provides access to the underlying C instance. |
| 191 | const GstMemory* gobj() const; |
| 192 | |
| 193 | ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. |
| 194 | GstMemory* gobj_copy() const; |
| 195 | |
| 196 | Memory() = delete; |
| 197 | |
| 198 | // noncopyable |
| 199 | Memory(const Memory&) = delete; |
| 200 | Memory& operator=(const Memory&) = delete; |
| 201 | |
| 202 | protected: |
| 203 | // Do not derive this. Gst::Memory can neither be constructed nor deleted. |
| 204 | |
| 205 | void operator delete(void*, std::size_t); |
| 206 | |
| 207 | private: |
| 208 | |
| 209 | |
| 210 | public: |
| 211 | |
| 212 | /* |
| 213 | * Allocate a new memory block that wraps the given @a data. |
| 214 | * |
| 215 | * @param flags: Gst::MemoryFlags. |
| 216 | * @param data Data to wrap. |
| 217 | * @param maxsize Allocated size of @a data. |
| 218 | * @param offset Offset in @data. |
| 219 | * @param size Size of valid data. |
| 220 | * |
| 221 | * @returns a new #Gst::Memory. |
| 222 | */ |
| 223 | static Glib::RefPtr<Memory> create(Gst::MemoryFlags flags, gpointer data, gsize maxsize, gsize offset, gsize size); |
| 224 | |
| 225 | /** Get the maximum size allocated. |
| 226 | */ |
| 227 | gsize get_maxsize() const; |
| 228 | |
| 229 | /** Get the alignment of the memory. |
| 230 | */ |
| 231 | gsize get_align() const; |
| 232 | |
| 233 | /** Get the offset where valid data starts. |
| 234 | */ |
| 235 | gsize get_offset() const; |
| 236 | |
| 237 | /** Get the size of valid data. |
| 238 | */ |
| 239 | gsize get_size() const; |
| 240 | |
| 241 | /** Get parent memory block. |
| 242 | */ |
| 243 | Glib::RefPtr<Gst::Memory> get_parent(); |
| 244 | Glib::RefPtr<const Gst::Memory> get_parent() const; |
| 245 | |
| 246 | /** Get the Gst::Allocator. |
| 247 | */ |
| 248 | Glib::RefPtr<Gst::Allocator> get_allocator(); |
| 249 | Glib::RefPtr<const Gst::Allocator> get_allocator() const; |
| 250 | |
| 251 | |
| 252 | /** Check if @a mem if allocated with an allocator for @a mem_type. |
| 253 | * |
| 254 | * @param mem_type A memory type. |
| 255 | * @return <tt>true</tt> if @a mem was allocated from an allocator for @a mem_type. |
| 256 | */ |
| 257 | bool is_type(const Glib::ustring& mem_type) const; |
| 258 | |
| 259 | /** Return a shared copy of @a size bytes from @a mem starting from @a offset. No |
| 260 | * memory copy is performed and the memory region is simply shared. The result |
| 261 | * is guaranteed to be non-writable. @a size can be set to -1 to return a shared |
| 262 | * copy from @a offset to the end of the memory region. |
| 263 | * |
| 264 | * @param offset Offset to share from. |
| 265 | * @param size Size to share, or -1 to share to the end of the memory region. |
| 266 | * @return A new Gst::Memory. |
| 267 | */ |
| 268 | Glib::RefPtr<Gst::Memory> share(gssize offset, gssize size); |
| 269 | |
| 270 | /** Resize the memory region. @a mem should be writable and offset + size should be |
| 271 | * less than the maxsize of @a mem. |
| 272 | * |
| 273 | * Gst::MEMORY_FLAG_ZERO_PREFIXED and Gst::MEMORY_FLAG_ZERO_PADDED will be |
| 274 | * cleared when offset or padding is increased respectively. |
| 275 | * |
| 276 | * @param offset A new offset. |
| 277 | * @param size A new size. |
| 278 | */ |
| 279 | void resize(gssize offset, gsize size); |
| 280 | |
| 281 | /** Check if @a mem1 and mem2 share the memory with a common parent memory object |
| 282 | * and that the memory is contiguous. |
| 283 | * |
| 284 | * If this is the case, the memory of @a mem1 and @a mem2 can be merged |
| 285 | * efficiently by performing share() on the parent object from |
| 286 | * the returned @a offset. |
| 287 | * |
| 288 | * @param mem2 A Gst::Memory. |
| 289 | * @param offset A pointer to a result offset. |
| 290 | * @return <tt>true</tt> if the memory is contiguous and of a common parent. |
| 291 | */ |
| 292 | bool is_span(const Glib::RefPtr<Gst::Memory>& mem2, gsize& offset); |
| 293 | |
| 294 | /** Fill @a info with the pointer and sizes of the memory in @a mem that can be |
| 295 | * accessed according to @a flags. |
| 296 | * |
| 297 | * This function can return <tt>false</tt> for various reasons: |
| 298 | * - the memory backed by @a mem is not accessible with the given @a flags. |
| 299 | * - the memory was already mapped with a different mapping. |
| 300 | * |
| 301 | * @a info and its contents remain valid for as long as @a mem is valid and |
| 302 | * until unmap() is called. |
| 303 | * |
| 304 | * For each map() call, a corresponding unmap() call |
| 305 | * should be done. |
| 306 | * |
| 307 | * @param info Pointer for info. |
| 308 | * @param flags Mapping flags. |
| 309 | * @return <tt>true</tt> if the map operation was successful. |
| 310 | */ |
| 311 | bool map(Gst::MapInfo& info, Gst::MapFlags flags); |
| 312 | |
| 313 | /** Release the memory obtained with map() |
| 314 | * |
| 315 | * @param info A Gst::MapInfo. |
| 316 | */ |
| 317 | void unmap(Gst::MapInfo& info); |
| 318 | |
| 319 | /** Return a copy of @a size bytes from @a mem starting from @a offset. This copy is |
| 320 | * guaranteed to be writable. @a size can be set to -1 to return a copy |
| 321 | * from @a offset to the end of the memory region. |
| 322 | * |
| 323 | * @param offset Offset to copy from. |
| 324 | * @param size Size to copy, or -1 to copy to the end of the memory region. |
| 325 | * @return A new Gst::Memory. |
| 326 | */ |
| 327 | Glib::RefPtr<Gst::Memory> copy(gssize offset, gssize size); |
| 328 | |
| 329 | /** Initializes a newly allocated @a mem with the given parameters. This function |
| 330 | * will call Gst::MiniObject::init() with the default memory parameters. |
| 331 | * |
| 332 | * @param flags Gst::MemoryFlags. |
| 333 | * @param allocator The Gst::Allocator. |
| 334 | * @param parent The parent of @a mem. |
| 335 | * @param maxsize The total size of the memory. |
| 336 | * @param align The alignment of the memory. |
| 337 | * @param offset The offset in the memory. |
| 338 | * @param size The size of valid data in the memory. |
| 339 | */ |
| 340 | 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); |
| 341 | |
| 342 | /** Get the current @a size, @a offset and @a maxsize of @a mem. |
| 343 | * |
| 344 | * @param offset Pointer to offset. |
| 345 | * @param maxsize Pointer to maxsize. |
| 346 | * @return The current sizes of @a mem. |
| 347 | */ |
| 348 | gsize get_sizes(gsize& offset, gsize& maxsize); |
| 349 | |
| 350 | /** Create a Gst::Memory object that is mapped with @a flags. If @a mem is mappable |
| 351 | * with @a flags, this function returns the mapped @a mem directly. Otherwise a |
| 352 | * mapped copy of @a mem is returned. |
| 353 | * |
| 354 | * @param info Pointer for info. |
| 355 | * @param flags Mapping flags. |
| 356 | * |
| 357 | * @return a Gst::Memory object mapped. |
| 358 | */ |
| 359 | Glib::RefPtr<Gst::Memory> make_mapped(Gst::MapInfo& info, Gst::MapFlags flags); |
| 360 | |
| 361 | |
| 362 | }; |
| 363 | |
| 364 | }//namespace Gst |
| 365 | |
| 366 | |
| 367 | namespace Glib |
| 368 | { |
| 369 | |
| 370 | /** A Glib::wrap() method for this object. |
| 371 | * |
| 372 | * @param object The C instance. |
| 373 | * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref. |
| 374 | * @result A C++ instance that wraps this C instance. |
| 375 | * |
| 376 | * @relates Gst::Memory |
| 377 | */ |
| 378 | Glib::RefPtr<Gst::Memory> wrap(GstMemory* object, bool take_copy = false); |
| 379 | |
| 380 | } // namespace Glib |
| 381 | |
| 382 | |
| 383 | #endif /* _GSTREAMERMM_MEMORY_H */ |
| 384 |