Move dataurisrc element from -bad
[platform/upstream/gstreamer.git] / gst / gstallocator.h
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
29 G_BEGIN_DECLS
30
31 typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
32 typedef 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 GType gst_allocation_params_get_type(void);
44
45 typedef struct _GstAllocationParams GstAllocationParams;
46
47 /**
48  * gst_memory_alignment:
49  *
50  * The default memory alignment in bytes - 1
51  * an alignment of 7 would be the same as what malloc() guarantees.
52  */
53 GST_EXPORT gsize gst_memory_alignment;
54
55 /**
56  * GST_ALLOCATOR_SYSMEM:
57  *
58  * The allocator name for the default system memory allocator
59  */
60 #define GST_ALLOCATOR_SYSMEM   "SystemMemory"
61
62 /**
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
68  *
69  * Parameters to control the allocation of memory
70  */
71 struct _GstAllocationParams {
72   GstMemoryFlags flags;
73   gsize          align;
74   gsize          prefix;
75   gsize          padding;
76
77   /*< private >*/
78   gpointer _gst_reserved[GST_PADDING];
79 };
80
81 /**
82  * GstAllocatorFlags:
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
85  *
86  * Flags for allocators.
87  */
88 typedef enum {
89   GST_ALLOCATOR_FLAG_CUSTOM_ALLOC  = (GST_OBJECT_FLAG_LAST << 0),
90
91   GST_ALLOCATOR_FLAG_LAST          = (GST_OBJECT_FLAG_LAST << 16)
92 } GstAllocatorFlags;
93
94 /**
95  * GstAllocator:
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)
105  *
106  * The #GstAllocator is used to create new memory.
107  */
108 struct _GstAllocator
109 {
110   GstObject  object;
111
112   const gchar               *mem_type;
113
114   /*< public >*/
115   GstMemoryMapFunction       mem_map;
116   GstMemoryUnmapFunction     mem_unmap;
117
118   GstMemoryCopyFunction      mem_copy;
119   GstMemoryShareFunction     mem_share;
120   GstMemoryIsSpanFunction    mem_is_span;
121
122   GstMemoryMapFullFunction   mem_map_full;
123   GstMemoryUnmapFullFunction mem_unmap_full;
124
125   /*< private >*/
126   gpointer _gst_reserved[GST_PADDING - 2];
127
128   GstAllocatorPrivate *priv;
129 };
130
131 /**
132  * GstAllocatorClass:
133  * @object_class:  Object parent class
134  * @alloc: implementation that acquires memory
135  * @free: implementation that releases memory
136  *
137  * The #GstAllocator is used to create new memory.
138  */
139 struct _GstAllocatorClass {
140   GstObjectClass object_class;
141
142   /*< public >*/
143   GstMemory *  (*alloc)      (GstAllocator *allocator, gsize size,
144                               GstAllocationParams *params);
145   void         (*free)       (GstAllocator *allocator, GstMemory *memory);
146
147   /*< private >*/
148   gpointer _gst_reserved[GST_PADDING];
149 };
150
151 GType gst_allocator_get_type(void);
152
153 /* allocators */
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);
157
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);
163
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);
168
169 GstMemory *    gst_memory_new_wrapped  (GstMemoryFlags flags, gpointer data, gsize maxsize,
170                                         gsize offset, gsize size, gpointer user_data,
171                                         GDestroyNotify notify);
172
173 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
174 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAllocationParams, gst_allocation_params_free)
175 #endif
176
177 G_END_DECLS
178
179 #endif /* __GST_ALLOCATOR_H__ */