1/* GStreamer
2 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
3 *
4 * gstallocator.h: Header for memory allocation
5 *
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.
10 *
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.
15 *
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.
20 */
21
22
23#ifndef __GST_ALLOCATOR_H__
24#define __GST_ALLOCATOR_H__
25
26#include <gst/gstmemory.h>
27#include <gst/gstobject.h>
28
29G_BEGIN_DECLS
30
31typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
32typedef struct _GstAllocatorClass GstAllocatorClass;
33
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))
41
42#define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
43
44GST_API
45GType gst_allocation_params_get_type(void);
46
47typedef struct _GstAllocationParams GstAllocationParams;
48
49/**
50 * gst_memory_alignment:
51 *
52 * The default memory alignment in bytes - 1
53 * an alignment of 7 would be the same as what malloc() guarantees.
54 */
55
56GST_API gsize gst_memory_alignment;
57
58/**
59 * GST_ALLOCATOR_SYSMEM:
60 *
61 * The allocator name for the default system memory allocator
62 */
63#define GST_ALLOCATOR_SYSMEM "SystemMemory"
64
65/**
66 * GstAllocationParams:
67 * @flags: flags to control allocation
68 * @align: the desired alignment of the memory
69 * @prefix: the desired prefix
70 * @padding: the desired padding
71 *
72 * Parameters to control the allocation of memory
73 */
74struct _GstAllocationParams {
75 GstMemoryFlags flags;
76 gsize align;
77 gsize prefix;
78 gsize padding;
79
80 /*< private >*/
81 gpointer _gst_reserved[GST_PADDING];
82};
83
84/**
85 * GstAllocatorFlags:
86 * @GST_ALLOCATOR_FLAG_CUSTOM_ALLOC: The allocator has a custom alloc function.
87 * Only elements designed to work with this allocator should be using it,
88 * other elements should ignore it from allocation propositions.
89 * This implies %GST_ALLOCATOR_FLAG_NO_COPY.
90 * @GST_ALLOCATOR_FLAG_NO_COPY: When copying a #GstMemory allocated with this
91 * allocator, the copy will instead be allocated using the default allocator.
92 * Use this when allocating a new memory is an heavy opperation that should
93 * only be done with a #GstBufferPool for example. (Since: 1.24)
94 * @GST_ALLOCATOR_FLAG_LAST: first flag that can be used for custom purposes
95 *
96 * Flags for allocators.
97 */
98/**
99 * GST_ALLOCATOR_FLAG_NO_COPY:
100 *
101 * When copying a #GstMemory allocated with this allocator, the copy will
102 * instead be allocated using the default allocator. Use this when allocating a
103 * new memory is an heavy opperation that should only be done with a
104 * #GstBufferPool for example.
105 *
106 * Since: 1.24
107 */
108typedef enum {
109 GST_ALLOCATOR_FLAG_CUSTOM_ALLOC = (GST_OBJECT_FLAG_LAST << 0),
110 GST_ALLOCATOR_FLAG_NO_COPY = (GST_OBJECT_FLAG_LAST << 1),
111
112 GST_ALLOCATOR_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 16)
113} GstAllocatorFlags;
114
115/**
116 * GstAllocator:
117 * @mem_map: the implementation of the GstMemoryMapFunction
118 * @mem_unmap: the implementation of the GstMemoryUnmapFunction
119 * @mem_copy: the implementation of the GstMemoryCopyFunction
120 * @mem_share: the implementation of the GstMemoryShareFunction
121 * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
122 * @mem_map_full: the implementation of the GstMemoryMapFullFunction.
123 * Will be used instead of @mem_map if present. (Since: 1.6)
124 * @mem_unmap_full: the implementation of the GstMemoryUnmapFullFunction.
125 * Will be used instead of @mem_unmap if present. (Since: 1.6)
126 *
127 * The #GstAllocator is used to create new memory.
128 */
129struct _GstAllocator
130{
131 GstObject object;
132
133 const gchar *mem_type;
134
135 /*< public >*/
136 GstMemoryMapFunction mem_map;
137 GstMemoryUnmapFunction mem_unmap;
138
139 GstMemoryCopyFunction mem_copy;
140 GstMemoryShareFunction mem_share;
141 GstMemoryIsSpanFunction mem_is_span;
142
143 GstMemoryMapFullFunction mem_map_full;
144 GstMemoryUnmapFullFunction mem_unmap_full;
145
146 /*< private >*/
147 gpointer _gst_reserved[GST_PADDING - 2];
148
149 GstAllocatorPrivate *priv;
150};
151
152/**
153 * GstAllocatorClass:
154 * @object_class: Object parent class
155 * @alloc: implementation that acquires memory
156 * @free: implementation that releases memory
157 *
158 * The #GstAllocator is used to create new memory.
159 */
160struct _GstAllocatorClass {
161 GstObjectClass object_class;
162
163 /*< public >*/
164 GstMemory * (*alloc) (GstAllocator *allocator, gsize size,
165 GstAllocationParams *params);
166 void (*free) (GstAllocator *allocator, GstMemory *memory);
167
168 /*< private >*/
169 gpointer _gst_reserved[GST_PADDING];
170};
171
172GST_API
173GType gst_allocator_get_type (void);
174
175/* allocators */
176
177GST_API
178void gst_allocator_register (const gchar *name, GstAllocator *allocator);
179
180GST_API
181GstAllocator * gst_allocator_find (const gchar *name);
182
183GST_API
184void gst_allocator_set_default (GstAllocator * allocator);
185
186/* allocation parameters */
187
188GST_API
189GstAllocationParams * gst_allocation_params_new (void) G_GNUC_MALLOC;
190
191GST_API
192void gst_allocation_params_init (GstAllocationParams *params);
193
194GST_API
195GstAllocationParams *
196 gst_allocation_params_copy (const GstAllocationParams *params) G_GNUC_MALLOC;
197
198GST_API
199void gst_allocation_params_free (GstAllocationParams *params);
200
201/* allocating memory blocks */
202
203GST_API
204GstMemory * gst_allocator_alloc (GstAllocator * allocator, gsize size,
205 GstAllocationParams *params);
206
207GST_API
208void gst_allocator_free (GstAllocator * allocator, GstMemory *memory);
209
210GST_API
211GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, gsize maxsize,
212 gsize offset, gsize size, gpointer user_data,
213 GDestroyNotify notify);
214
215G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocationParams, gst_allocation_params_free)
216
217G_END_DECLS
218
219#endif /* __GST_ALLOCATOR_H__ */
220

source code of include/gstreamer-1.0/gst/gstallocator.h