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 module gstreamer.Allocator;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gstreamer.AllocationParams;
30 private import gstreamer.Memory;
31 private import gstreamer.ObjectGst;
32 private import gstreamerc.gstreamer;
33 public  import gstreamerc.gstreamertypes;
34 
35 
36 /**
37  * Memory is usually created by allocators with a gst_allocator_alloc()
38  * method call. When %NULL is used as the allocator, the default allocator will
39  * be used.
40  * 
41  * New allocators can be registered with gst_allocator_register().
42  * Allocators are identified by name and can be retrieved with
43  * gst_allocator_find(). gst_allocator_set_default() can be used to change the
44  * default allocator.
45  * 
46  * New memory can be created with gst_memory_new_wrapped() that wraps the memory
47  * allocated elsewhere.
48  */
49 public class Allocator : ObjectGst
50 {
51 	/** the main Gtk struct */
52 	protected GstAllocator* gstAllocator;
53 
54 	/** Get the main Gtk struct */
55 	public GstAllocator* getAllocatorStruct()
56 	{
57 		return gstAllocator;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gstAllocator;
64 	}
65 
66 	protected override void setStruct(GObject* obj)
67 	{
68 		gstAllocator = cast(GstAllocator*)obj;
69 		super.setStruct(obj);
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GstAllocator* gstAllocator, bool ownedRef = false)
76 	{
77 		this.gstAllocator = gstAllocator;
78 		super(cast(GstObject*)gstAllocator, ownedRef);
79 	}
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gst_allocator_get_type();
86 	}
87 
88 	/**
89 	 * Find a previously registered allocator with @name. When @name is %NULL, the
90 	 * default allocator will be returned.
91 	 *
92 	 * Params:
93 	 *     name = the name of the allocator
94 	 *
95 	 * Return: a #GstAllocator or %NULL when
96 	 *     the allocator with @name was not registered. Use gst_object_unref()
97 	 *     to release the allocator after usage.
98 	 */
99 	public static Allocator find(string name)
100 	{
101 		auto p = gst_allocator_find(Str.toStringz(name));
102 		
103 		if(p is null)
104 		{
105 			return null;
106 		}
107 		
108 		return ObjectG.getDObject!(Allocator)(cast(GstAllocator*) p, true);
109 	}
110 
111 	/**
112 	 * Registers the memory @allocator with @name. This function takes ownership of
113 	 * @allocator.
114 	 *
115 	 * Params:
116 	 *     name = the name of the allocator
117 	 *     allocator = #GstAllocator
118 	 */
119 	public static void register(string name, Allocator allocator)
120 	{
121 		gst_allocator_register(Str.toStringz(name), (allocator is null) ? null : allocator.getAllocatorStruct());
122 	}
123 
124 	/**
125 	 * Use @allocator to allocate a new memory block with memory that is at least
126 	 * @size big.
127 	 *
128 	 * The optional @params can specify the prefix and padding for the memory. If
129 	 * %NULL is passed, no flags, no extra prefix/padding and a default alignment is
130 	 * used.
131 	 *
132 	 * The prefix/padding will be filled with 0 if flags contains
133 	 * #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively.
134 	 *
135 	 * When @allocator is %NULL, the default allocator will be used.
136 	 *
137 	 * The alignment in @params is given as a bitmask so that @align + 1 equals
138 	 * the amount of bytes to align to. For example, to align to 8 bytes,
139 	 * use an alignment of 7.
140 	 *
141 	 * Params:
142 	 *     size = size of the visible memory area
143 	 *     params = optional parameters
144 	 *
145 	 * Return: a new #GstMemory.
146 	 */
147 	public Memory alloc(size_t size, AllocationParams params)
148 	{
149 		auto p = gst_allocator_alloc(gstAllocator, size, (params is null) ? null : params.getAllocationParamsStruct());
150 		
151 		if(p is null)
152 		{
153 			return null;
154 		}
155 		
156 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
157 	}
158 
159 	/**
160 	 * Free @memory that was previously allocated with gst_allocator_alloc().
161 	 *
162 	 * Params:
163 	 *     memory = the memory to free
164 	 */
165 	public void free(Memory memory)
166 	{
167 		gst_allocator_free(gstAllocator, (memory is null) ? null : memory.getMemoryStruct());
168 	}
169 
170 	/**
171 	 * Set the default allocator. This function takes ownership of @allocator.
172 	 */
173 	public void setDefault()
174 	{
175 		gst_allocator_set_default(gstAllocator);
176 	}
177 }