2 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
4 * gstallocator.h: Header for memory allocation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef __GST_ALLOCATOR_H__
24 #define __GST_ALLOCATOR_H__
26 #include <gst/gstmemory.h>
27 #include <gst/gstobject.h>
31 typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
32 typedef struct _GstAllocatorClass GstAllocatorClass;
34 #define GST_TYPE_ALLOCATOR (gst_allocator_get_type())
35 #define GST_IS_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ALLOCATOR))
36 #define GST_IS_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ALLOCATOR))
37 #define GST_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ALLOCATOR, GstAllocatorClass))
38 #define GST_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ALLOCATOR, GstAllocator))
39 #define GST_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ALLOCATOR, GstAllocatorClass))
40 #define GST_ALLOCATOR_CAST(obj) ((GstAllocator *)(obj))
42 #define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
43 GType gst_allocation_params_get_type(void);
45 typedef struct _GstAllocationParams GstAllocationParams;
48 * gst_memory_alignment:
50 * The default memory alignment in bytes - 1
51 * an alignment of 7 would be the same as what malloc() guarantees.
53 GST_EXPORT gsize gst_memory_alignment;
56 * GST_ALLOCATOR_SYSMEM:
58 * The allocator name for the default system memory allocator
60 #define GST_ALLOCATOR_SYSMEM "SystemMemory"
63 * GstAllocationParams:
64 * @flags: flags to control allocation
65 * @align: the desired alignment of the memory
66 * @prefix: the desired prefix
67 * @padding: the desired padding
69 * Parameters to control the allocation of memory
71 struct _GstAllocationParams {
78 gpointer _gst_reserved[GST_PADDING];
83 * @GST_ALLOCATOR_FLAG_CUSTOM_ALLOC: The allocator has a custom alloc function.
84 * @GST_ALLOCATOR_FLAG_LAST: first flag that can be used for custom purposes
86 * Flags for allocators.
89 GST_ALLOCATOR_FLAG_CUSTOM_ALLOC = (GST_OBJECT_FLAG_LAST << 0),
91 GST_ALLOCATOR_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 16)
96 * @mem_map: the implementation of the GstMemoryMapFunction
97 * @mem_unmap: the implementation of the GstMemoryUnmapFunction
98 * @mem_copy: the implementation of the GstMemoryCopyFunction
99 * @mem_share: the implementation of the GstMemoryShareFunction
100 * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
101 * @mem_map_full: the implementation of the GstMemoryMapFullFunction.
102 * Will be used instead of @mem_map if present. (Since 1.6)
103 * @mem_unmap_full: the implementation of the GstMemoryUnmapFullFunction.
104 * Will be used instead of @mem_unmap if present. (Since 1.6)
106 * The #GstAllocator is used to create new memory.
112 const gchar *mem_type;
115 GstMemoryMapFunction mem_map;
116 GstMemoryUnmapFunction mem_unmap;
118 GstMemoryCopyFunction mem_copy;
119 GstMemoryShareFunction mem_share;
120 GstMemoryIsSpanFunction mem_is_span;
122 GstMemoryMapFullFunction mem_map_full;
123 GstMemoryUnmapFullFunction mem_unmap_full;
126 gpointer _gst_reserved[GST_PADDING - 2];
128 GstAllocatorPrivate *priv;
133 * @object_class: Object parent class
134 * @alloc: implementation that acquires memory
135 * @free: implementation that releases memory
137 * The #GstAllocator is used to create new memory.
139 struct _GstAllocatorClass {
140 GstObjectClass object_class;
143 GstMemory * (*alloc) (GstAllocator *allocator, gsize size,
144 GstAllocationParams *params);
145 void (*free) (GstAllocator *allocator, GstMemory *memory);
148 gpointer _gst_reserved[GST_PADDING];
151 GType gst_allocator_get_type(void);
154 void gst_allocator_register (const gchar *name, GstAllocator *allocator);
155 GstAllocator * gst_allocator_find (const gchar *name);
156 void gst_allocator_set_default (GstAllocator * allocator);
158 /* allocation parameters */
159 void gst_allocation_params_init (GstAllocationParams *params);
160 GstAllocationParams *
161 gst_allocation_params_copy (const GstAllocationParams *params) G_GNUC_MALLOC;
162 void gst_allocation_params_free (GstAllocationParams *params);
164 /* allocating memory blocks */
165 GstMemory * gst_allocator_alloc (GstAllocator * allocator, gsize size,
166 GstAllocationParams *params);
167 void gst_allocator_free (GstAllocator * allocator, GstMemory *memory);
169 GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, gsize maxsize,
170 gsize offset, gsize size, gpointer user_data,
171 GDestroyNotify notify);
173 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
174 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocationParams, gst_allocation_params_free)
179 #endif /* __GST_ALLOCATOR_H__ */