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>
30 typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
31 typedef struct _GstAllocatorClass GstAllocatorClass;
33 #define GST_TYPE_ALLOCATOR (gst_allocator_get_type())
34 #define GST_IS_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_ALLOCATOR))
35 #define GST_IS_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_ALLOCATOR))
36 #define GST_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_ALLOCATOR, GstAllocatorClass))
37 #define GST_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_ALLOCATOR, GstAllocator))
38 #define GST_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_ALLOCATOR, GstAllocatorClass))
39 #define GST_ALLOCATOR_CAST(obj) ((GstAllocator *)(obj))
41 #define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
42 GType gst_allocation_params_get_type(void);
44 typedef struct _GstAllocationParams GstAllocationParams;
47 * gst_memory_alignment:
49 * The default memory alignment in bytes - 1
50 * an alignment of 7 would be the same as what malloc() guarantees.
52 GST_EXPORT gsize gst_memory_alignment;
55 * GST_ALLOCATOR_SYSMEM:
57 * The allocator name for the default system memory allocator
59 #define GST_ALLOCATOR_SYSMEM "SystemMemory"
62 * GstAllocationParams:
63 * @flags: flags to control allocation
64 * @align: the desired alignment of the memory
65 * @prefix: the desired prefix
66 * @padding: the desired padding
68 * Parameters to control the allocation of memory
70 struct _GstAllocationParams {
77 gpointer _gst_reserved[GST_PADDING];
82 * @GST_ALLOCATOR_FLAG_CUSTOM_ALLOC: The allocator has a custom alloc function.
83 * @GST_ALLOCATOR_FLAG_LAST: first flag that can be used for custom purposes
85 * Flags for allocators.
88 GST_ALLOCATOR_FLAG_CUSTOM_ALLOC = (GST_OBJECT_FLAG_LAST << 0),
90 GST_ALLOCATOR_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 16)
95 * @object: parent structure
96 * @mem_type: the memory type this allocator provides
97 * @mem_map: the implementation of the GstMemoryMapFunction
98 * @mem_unmap: the implementation of the GstMemoryUnmapFunction
99 * @mem_copy: the implementation of the GstMemoryCopyFunction
100 * @mem_share: the implementation of the GstMemoryShareFunction
101 * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
103 * The #GstAllocator is used to create new memory.
109 const gchar *mem_type;
111 GstMemoryMapFunction mem_map;
112 GstMemoryUnmapFunction mem_unmap;
114 GstMemoryCopyFunction mem_copy;
115 GstMemoryShareFunction mem_share;
116 GstMemoryIsSpanFunction mem_is_span;
119 gpointer _gst_reserved[GST_PADDING];
121 GstAllocatorPrivate *priv;
124 struct _GstAllocatorClass {
125 GstObjectClass object_class;
127 GstMemory * (*alloc) (GstAllocator *allocator, gsize size,
128 GstAllocationParams *params);
129 void (*free) (GstAllocator *allocator, GstMemory *memory);
132 gpointer _gst_reserved[GST_PADDING];
135 GType gst_allocator_get_type(void);
138 void gst_allocator_register (const gchar *name, GstAllocator *allocator);
139 GstAllocator * gst_allocator_find (const gchar *name);
140 void gst_allocator_set_default (GstAllocator * allocator);
142 /* allocation parameters */
143 void gst_allocation_params_init (GstAllocationParams *params);
144 GstAllocationParams *
145 gst_allocation_params_copy (const GstAllocationParams *params) G_GNUC_MALLOC;
146 void gst_allocation_params_free (GstAllocationParams *params);
148 /* allocating memory blocks */
149 GstMemory * gst_allocator_alloc (GstAllocator * allocator, gsize size,
150 GstAllocationParams *params);
151 void gst_allocator_free (GstAllocator * allocator, GstMemory *memory);
153 GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, gsize maxsize,
154 gsize offset, gsize size, gpointer user_data,
155 GDestroyNotify notify);
159 #endif /* __GST_ALLOCATOR_H__ */