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