1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = gstreamer-GstMemory.html
27  * outPack = gstreamer
28  * outFile = Memory
29  * strct   = GstMemory
30  * realStrct=
31  * ctorStrct=
32  * clss    = Memory
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_memory_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gstreamer.Allocator
48  * structWrap:
49  * 	- GstAllocator* -> Allocator
50  * 	- GstMemory* -> Memory
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module gstreamer.Memory;
57 
58 public  import gstreamerc.gstreamertypes;
59 
60 private import gstreamerc.gstreamer;
61 private import glib.ConstructionException;
62 private import gobject.ObjectG;
63 
64 private import glib.Str;
65 private import gstreamer.Allocator;
66 
67 
68 
69 /**
70  * GstMemory is a lightweight refcounted object that wraps a region of memory.
71  * They are typically used to manage the data of a GstBuffer.
72  *
73  * A GstMemory object has an allocated region of memory of maxsize. The maximum
74  * size does not change during the lifetime of the memory object. The memory
75  * also has an offset and size property that specifies the valid range of memory
76  * in the allocated region.
77  *
78  * Memory is usually created by allocators with a gst_allocator_alloc()
79  * method call. When NULL is used as the allocator, the default allocator will
80  * be used.
81  *
82  * New allocators can be registered with gst_allocator_register().
83  * Allocators are identified by name and can be retrieved with
84  * gst_allocator_find(). gst_allocator_set_default() can be used to change the
85  * default allocator.
86  *
87  * New memory can be created with gst_memory_new_wrapped() that wraps the memory
88  * allocated elsewhere.
89  *
90  * Refcounting of the memory block is performed with gst_memory_ref() and
91  * gst_memory_unref().
92  *
93  * The size of the memory can be retrieved and changed with
94  * gst_memory_get_sizes() and gst_memory_resize() respectively.
95  *
96  * Getting access to the data of the memory is performed with gst_memory_map().
97  * The call will return a pointer to offset bytes into the region of memory.
98  * After the memory access is completed, gst_memory_unmap() should be called.
99  *
100  * Memory can be copied with gst_memory_copy(), which will return a writable
101  * copy. gst_memory_share() will create a new memory block that shares the
102  * memory with an existing memory block at a custom offset and with a custom
103  * size.
104  *
105  * Memory can be efficiently merged when gst_memory_is_span() returns TRUE.
106  *
107  * Last reviewed on 2012-03-28 (0.11.3)
108  */
109 public class Memory
110 {
111 	
112 	/** the main Gtk struct */
113 	protected GstMemory* gstMemory;
114 	
115 	
116 	/** Get the main Gtk struct */
117 	public GstMemory* getMemoryStruct()
118 	{
119 		return gstMemory;
120 	}
121 	
122 	
123 	/** the main Gtk struct as a void* */
124 	protected void* getStruct()
125 	{
126 		return cast(void*)gstMemory;
127 	}
128 	
129 	/**
130 	 * Sets our main struct and passes it to the parent class
131 	 */
132 	public this (GstMemory* gstMemory)
133 	{
134 		this.gstMemory = gstMemory;
135 	}
136 	
137 	/**
138 	 */
139 	
140 	/**
141 	 * Initializes a newly allocated mem with the given parameters. This function
142 	 * will call gst_mini_object_init() with the default memory parameters.
143 	 * Params:
144 	 * flags = GstMemoryFlags
145 	 * allocator = the GstAllocator
146 	 * parent = the parent of mem
147 	 * maxsize = the total size of the memory
148 	 * offset = The offset in the memory
149 	 * size = the size of valid data in the memory
150 	 */
151 	public void init(GstMemoryFlags flags, Allocator allocator, Memory parent, gsize maxsize, gsize alig, gsize offset, gsize size)
152 	{
153 		// void gst_memory_init (GstMemory *mem,  GstMemoryFlags flags,  GstAllocator *allocator,  GstMemory *parent,  gsize maxsize,  gsize align,  gsize offset,  gsize size);
154 		gst_memory_init(gstMemory, flags, (allocator is null) ? null : allocator.getAllocatorStruct(), (parent is null) ? null : parent.getMemoryStruct(), maxsize, alig, offset, size);
155 	}
156 	
157 	/**
158 	 * Check if mem if allocated with an allocator for mem_type.
159 	 * Since 1.2
160 	 * Params:
161 	 * mem = a GstMemory
162 	 * memType = a memory type
163 	 * Returns: TRUE if mem was allocated from an allocator for mem_type.
164 	 */
165 	public int isType(string memType)
166 	{
167 		// gboolean gst_memory_is_type (GstMemory *mem,  const gchar *mem_type);
168 		return gst_memory_is_type(gstMemory, Str.toStringz(memType));
169 	}
170 	
171 	/**
172 	 * Increase the refcount of this memory.
173 	 * Returns: memory (for convenience when doing assignments). [transfer full]
174 	 */
175 	public Memory doref()
176 	{
177 		// GstMemory * gst_memory_ref (GstMemory *memory);
178 		auto p = gst_memory_ref(gstMemory);
179 		
180 		if(p is null)
181 		{
182 			return null;
183 		}
184 		
185 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
186 	}
187 	
188 	/**
189 	 * Decrease the refcount of an memory, freeing it if the refcount reaches 0.
190 	 */
191 	public void unref()
192 	{
193 		// void gst_memory_unref (GstMemory *memory);
194 		gst_memory_unref(gstMemory);
195 	}
196 	
197 	/**
198 	 * Get the current size, offset and maxsize of mem.
199 	 * Params:
200 	 * offset = pointer to offset
201 	 * maxsize = pointer to maxsize
202 	 * Returns: the current sizes of mem
203 	 */
204 	public gsize getSizes(ref gsize offset, ref gsize maxsize)
205 	{
206 		// gsize gst_memory_get_sizes (GstMemory *mem,  gsize *offset,  gsize *maxsize);
207 		return gst_memory_get_sizes(gstMemory, &offset, &maxsize);
208 	}
209 	
210 	/**
211 	 * Resize the memory region. mem should be writable and offset + size should be
212 	 * less than the maxsize of mem.
213 	 * GST_MEMORY_FLAG_ZERO_PREFIXED and GST_MEMORY_FLAG_ZERO_PADDED will be
214 	 * cleared when offset or padding is increased respectively.
215 	 * Params:
216 	 * offset = a new offset
217 	 * size = a new size
218 	 */
219 	public void resize(gssize offset, gsize size)
220 	{
221 		// void gst_memory_resize (GstMemory *mem,  gssize offset,  gsize size);
222 		gst_memory_resize(gstMemory, offset, size);
223 	}
224 	
225 	/**
226 	 * Create a GstMemory object that is mapped with flags. If mem is mappable
227 	 * with flags, this function returns the mapped mem directly. Otherwise a
228 	 * mapped copy of mem is returned.
229 	 * This function takes ownership of old mem and returns a reference to a new
230 	 * GstMemory.
231 	 * Params:
232 	 * info = pointer for info. [out]
233 	 * flags = mapping flags
234 	 * Returns: a GstMemory object mapped with flags or NULL when a mapping is not possible. [transfer full]
235 	 */
236 	public Memory makeMapped(out GstMapInfo info, GstMapFlags flags)
237 	{
238 		// GstMemory * gst_memory_make_mapped (GstMemory *mem,  GstMapInfo *info,  GstMapFlags flags);
239 		auto p = gst_memory_make_mapped(gstMemory, &info, flags);
240 		
241 		if(p is null)
242 		{
243 			return null;
244 		}
245 		
246 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
247 	}
248 	
249 	/**
250 	 * Fill info with the pointer and sizes of the memory in mem that can be
251 	 * accessed according to flags.
252 	 * Params:
253 	 * info = pointer for info. [out]
254 	 * flags = mapping flags
255 	 * Returns: TRUE if the map operation was successful.
256 	 */
257 	public int map(out GstMapInfo info, GstMapFlags flags)
258 	{
259 		// gboolean gst_memory_map (GstMemory *mem,  GstMapInfo *info,  GstMapFlags flags);
260 		return gst_memory_map(gstMemory, &info, flags);
261 	}
262 	
263 	/**
264 	 * Release the memory obtained with gst_memory_map()
265 	 * Params:
266 	 * info = a GstMapInfo
267 	 */
268 	public void unmap(ref GstMapInfo info)
269 	{
270 		// void gst_memory_unmap (GstMemory *mem,  GstMapInfo *info);
271 		gst_memory_unmap(gstMemory, &info);
272 	}
273 	
274 	/**
275 	 * Return a copy of size bytes from mem starting from offset. This copy is
276 	 * guaranteed to be writable. size can be set to -1 to return a copy all bytes
277 	 * from offset.
278 	 * Params:
279 	 * offset = an offset to copy
280 	 * size = size to copy or -1 to copy all bytes from offset
281 	 * Returns: a new GstMemory.
282 	 */
283 	public Memory copy(gssize offset, gssize size)
284 	{
285 		// GstMemory * gst_memory_copy (GstMemory *mem,  gssize offset,  gssize size);
286 		auto p = gst_memory_copy(gstMemory, offset, size);
287 		
288 		if(p is null)
289 		{
290 			return null;
291 		}
292 		
293 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
294 	}
295 	
296 	/**
297 	 * Return a shared copy of size bytes from mem starting from offset. No
298 	 * memory copy is performed and the memory region is simply shared. The result
299 	 * is guaranteed to be not-writable. size can be set to -1 to return a share
300 	 * all bytes from offset.
301 	 * Params:
302 	 * offset = an offset to share
303 	 * size = size to share or -1 to share bytes from offset
304 	 * Returns: a new GstMemory.
305 	 */
306 	public Memory share(gssize offset, gssize size)
307 	{
308 		// GstMemory * gst_memory_share (GstMemory *mem,  gssize offset,  gssize size);
309 		auto p = gst_memory_share(gstMemory, offset, size);
310 		
311 		if(p is null)
312 		{
313 			return null;
314 		}
315 		
316 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
317 	}
318 	
319 	/**
320 	 * Check if mem1 and mem2 share the memory with a common parent memory object
321 	 * and that the memory is contiguous.
322 	 * If this is the case, the memory of mem1 and mem2 can be merged
323 	 * efficiently by performing gst_memory_share() on the parent object from
324 	 * the returned offset.
325 	 * Params:
326 	 * mem2 = a GstMemory
327 	 * offset = a pointer to a result offset
328 	 * Returns: TRUE if the memory is contiguous and of a common parent.
329 	 */
330 	public int isSpan(Memory mem2, out gsize offset)
331 	{
332 		// gboolean gst_memory_is_span (GstMemory *mem1,  GstMemory *mem2,  gsize *offset);
333 		return gst_memory_is_span(gstMemory, (mem2 is null) ? null : mem2.getMemoryStruct(), &offset);
334 	}
335 }