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 
65 private import glib.Str;
66 private import gstreamer.Allocator;
67 
68 
69 
70 
71 /**
72  * GstMemory is a lightweight refcounted object that wraps a region of memory.
73  * They are typically used to manage the data of a GstBuffer.
74  *
75  * A GstMemory object has an allocated region of memory of maxsize. The maximum
76  * size does not change during the lifetime of the memory object. The memory
77  * also has an offset and size property that specifies the valid range of memory
78  * in the allocated region.
79  *
80  * Memory is usually created by allocators with a gst_allocator_alloc()
81  * method call. When NULL is used as the allocator, the default allocator will
82  * be used.
83  *
84  * New allocators can be registered with gst_allocator_register().
85  * Allocators are identified by name and can be retrieved with
86  * gst_allocator_find(). gst_allocator_set_default() can be used to change the
87  * default allocator.
88  *
89  * New memory can be created with gst_memory_new_wrapped() that wraps the memory
90  * allocated elsewhere.
91  *
92  * Refcounting of the memory block is performed with gst_memory_ref() and
93  * gst_memory_unref().
94  *
95  * The size of the memory can be retrieved and changed with
96  * gst_memory_get_sizes() and gst_memory_resize() respectively.
97  *
98  * Getting access to the data of the memory is performed with gst_memory_map().
99  * The call will return a pointer to offset bytes into the region of memory.
100  * After the memory access is completed, gst_memory_unmap() should be called.
101  *
102  * Memory can be copied with gst_memory_copy(), which will return a writable
103  * copy. gst_memory_share() will create a new memory block that shares the
104  * memory with an existing memory block at a custom offset and with a custom
105  * size.
106  *
107  * Memory can be efficiently merged when gst_memory_is_span() returns TRUE.
108  *
109  * Last reviewed on 2012-03-28 (0.11.3)
110  */
111 public class Memory
112 {
113 	
114 	/** the main Gtk struct */
115 	protected GstMemory* gstMemory;
116 	
117 	
118 	public GstMemory* getMemoryStruct()
119 	{
120 		return gstMemory;
121 	}
122 	
123 	
124 	/** the main Gtk struct as a void* */
125 	protected void* getStruct()
126 	{
127 		return cast(void*)gstMemory;
128 	}
129 	
130 	/**
131 	 * Sets our main struct and passes it to the parent class
132 	 */
133 	public this (GstMemory* gstMemory)
134 	{
135 		this.gstMemory = gstMemory;
136 	}
137 	
138 	/**
139 	 */
140 	
141 	/**
142 	 * Initializes a newly allocated mem with the given parameters. This function
143 	 * will call gst_mini_object_init() with the default memory parameters.
144 	 * Params:
145 	 * flags = GstMemoryFlags
146 	 * allocator = the GstAllocator
147 	 * parent = the parent of mem
148 	 * maxsize = the total size of the memory
149 	 * offset = The offset in the memory
150 	 * size = the size of valid data in the memory
151 	 */
152 	public void init(GstMemoryFlags flags, Allocator allocator, Memory parent, gsize maxsize, gsize alig, gsize offset, gsize size)
153 	{
154 		// void gst_memory_init (GstMemory *mem,  GstMemoryFlags flags,  GstAllocator *allocator,  GstMemory *parent,  gsize maxsize,  gsize align,  gsize offset,  gsize size);
155 		gst_memory_init(gstMemory, flags, (allocator is null) ? null : allocator.getAllocatorStruct(), (parent is null) ? null : parent.getMemoryStruct(), maxsize, alig, offset, size);
156 	}
157 	
158 	/**
159 	 * Check if mem if allocated with an allocator for mem_type.
160 	 * Since 1.2
161 	 * Params:
162 	 * mem = a GstMemory
163 	 * memType = a memory type
164 	 * Returns: TRUE if mem was allocated from an allocator for mem_type.
165 	 */
166 	public int isType(string memType)
167 	{
168 		// gboolean gst_memory_is_type (GstMemory *mem,  const gchar *mem_type);
169 		return gst_memory_is_type(gstMemory, Str.toStringz(memType));
170 	}
171 	
172 	/**
173 	 * Increase the refcount of this memory.
174 	 * Returns: memory (for convenience when doing assignments). [transfer full]
175 	 */
176 	public Memory doref()
177 	{
178 		// GstMemory * gst_memory_ref (GstMemory *memory);
179 		auto p = gst_memory_ref(gstMemory);
180 		
181 		if(p is null)
182 		{
183 			return null;
184 		}
185 		
186 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
187 	}
188 	
189 	/**
190 	 * Decrease the refcount of an memory, freeing it if the refcount reaches 0.
191 	 */
192 	public void unref()
193 	{
194 		// void gst_memory_unref (GstMemory *memory);
195 		gst_memory_unref(gstMemory);
196 	}
197 	
198 	/**
199 	 * Get the current size, offset and maxsize of mem.
200 	 * Params:
201 	 * offset = pointer to offset
202 	 * maxsize = pointer to maxsize
203 	 * Returns: the current sizes of mem
204 	 */
205 	public gsize getSizes(ref gsize offset, ref gsize maxsize)
206 	{
207 		// gsize gst_memory_get_sizes (GstMemory *mem,  gsize *offset,  gsize *maxsize);
208 		return gst_memory_get_sizes(gstMemory, &offset, &maxsize);
209 	}
210 	
211 	/**
212 	 * Resize the memory region. mem should be writable and offset + size should be
213 	 * less than the maxsize of mem.
214 	 * GST_MEMORY_FLAG_ZERO_PREFIXED and GST_MEMORY_FLAG_ZERO_PADDED will be
215 	 * cleared when offset or padding is increased respectively.
216 	 * Params:
217 	 * offset = a new offset
218 	 * size = a new size
219 	 */
220 	public void resize(gssize offset, gsize size)
221 	{
222 		// void gst_memory_resize (GstMemory *mem,  gssize offset,  gsize size);
223 		gst_memory_resize(gstMemory, offset, size);
224 	}
225 	
226 	/**
227 	 * Create a GstMemory object that is mapped with flags. If mem is mappable
228 	 * with flags, this function returns the mapped mem directly. Otherwise a
229 	 * mapped copy of mem is returned.
230 	 * This function takes ownership of old mem and returns a reference to a new
231 	 * GstMemory.
232 	 * Params:
233 	 * info = pointer for info. [out]
234 	 * flags = mapping flags
235 	 * Returns: a GstMemory object mapped with flags or NULL when a mapping is not possible. [transfer full]
236 	 */
237 	public Memory makeMapped(out GstMapInfo info, GstMapFlags flags)
238 	{
239 		// GstMemory * gst_memory_make_mapped (GstMemory *mem,  GstMapInfo *info,  GstMapFlags flags);
240 		auto p = gst_memory_make_mapped(gstMemory, &info, flags);
241 		
242 		if(p is null)
243 		{
244 			return null;
245 		}
246 		
247 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
248 	}
249 	
250 	/**
251 	 * Fill info with the pointer and sizes of the memory in mem that can be
252 	 * accessed according to flags.
253 	 * Params:
254 	 * info = pointer for info. [out]
255 	 * flags = mapping flags
256 	 * Returns: TRUE if the map operation was successful.
257 	 */
258 	public int map(out GstMapInfo info, GstMapFlags flags)
259 	{
260 		// gboolean gst_memory_map (GstMemory *mem,  GstMapInfo *info,  GstMapFlags flags);
261 		return gst_memory_map(gstMemory, &info, flags);
262 	}
263 	
264 	/**
265 	 * Release the memory obtained with gst_memory_map()
266 	 * Params:
267 	 * info = a GstMapInfo
268 	 */
269 	public void unmap(ref GstMapInfo info)
270 	{
271 		// void gst_memory_unmap (GstMemory *mem,  GstMapInfo *info);
272 		gst_memory_unmap(gstMemory, &info);
273 	}
274 	
275 	/**
276 	 * Return a copy of size bytes from mem starting from offset. This copy is
277 	 * guaranteed to be writable. size can be set to -1 to return a copy all bytes
278 	 * from offset.
279 	 * Params:
280 	 * offset = an offset to copy
281 	 * size = size to copy or -1 to copy all bytes from offset
282 	 * Returns: a new GstMemory.
283 	 */
284 	public Memory copy(gssize offset, gssize size)
285 	{
286 		// GstMemory * gst_memory_copy (GstMemory *mem,  gssize offset,  gssize size);
287 		auto p = gst_memory_copy(gstMemory, offset, size);
288 		
289 		if(p is null)
290 		{
291 			return null;
292 		}
293 		
294 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
295 	}
296 	
297 	/**
298 	 * Return a shared copy of size bytes from mem starting from offset. No
299 	 * memory copy is performed and the memory region is simply shared. The result
300 	 * is guaranteed to be not-writable. size can be set to -1 to return a share
301 	 * all bytes from offset.
302 	 * Params:
303 	 * offset = an offset to share
304 	 * size = size to share or -1 to share bytes from offset
305 	 * Returns: a new GstMemory.
306 	 */
307 	public Memory share(gssize offset, gssize size)
308 	{
309 		// GstMemory * gst_memory_share (GstMemory *mem,  gssize offset,  gssize size);
310 		auto p = gst_memory_share(gstMemory, offset, size);
311 		
312 		if(p is null)
313 		{
314 			return null;
315 		}
316 		
317 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
318 	}
319 	
320 	/**
321 	 * Check if mem1 and mem2 share the memory with a common parent memory object
322 	 * and that the memory is contiguous.
323 	 * If this is the case, the memory of mem1 and mem2 can be merged
324 	 * efficiently by performing gst_memory_share() on the parent object from
325 	 * the returned offset.
326 	 * Params:
327 	 * mem2 = a GstMemory
328 	 * offset = a pointer to a result offset
329 	 * Returns: TRUE if the memory is contiguous and of a common parent.
330 	 */
331 	public int isSpan(Memory mem2, out gsize offset)
332 	{
333 		// gboolean gst_memory_is_span (GstMemory *mem1,  GstMemory *mem2,  gsize *offset);
334 		return gst_memory_is_span(gstMemory, (mem2 is null) ? null : mem2.getMemoryStruct(), &offset);
335 	}
336 }