docs: unhide docs for allocator
[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
28 G_BEGIN_DECLS
29
30 typedef struct _GstAllocatorPrivate GstAllocatorPrivate;
31 typedef struct _GstAllocatorClass GstAllocatorClass;
32
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))
40
41 #define GST_TYPE_ALLOCATION_PARAMS (gst_allocation_params_get_type())
42 GType gst_allocation_params_get_type(void);
43
44 typedef struct _GstAllocationParams GstAllocationParams;
45
46 /**
47  * gst_memory_alignment:
48  *
49  * The default memory alignment in bytes - 1
50  * an alignment of 7 would be the same as what malloc() guarantees.
51  */
52 GST_EXPORT gsize gst_memory_alignment;
53
54 /**
55  * GST_ALLOCATOR_SYSMEM:
56  *
57  * The allocator name for the default system memory allocator
58  */
59 #define GST_ALLOCATOR_SYSMEM   "SystemMemory"
60
61 /**
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
67  *
68  * Parameters to control the allocation of memory
69  */
70 struct _GstAllocationParams {
71   GstMemoryFlags flags;
72   gsize          align;
73   gsize          prefix;
74   gsize          padding;
75
76   /*< private >*/
77   gpointer _gst_reserved[GST_PADDING];
78 };
79
80 /**
81  * GstAllocatorFlags:
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
84  *
85  * Flags for allocators.
86  */
87 typedef enum {
88   GST_ALLOCATOR_FLAG_CUSTOM_ALLOC  = (GST_OBJECT_FLAG_LAST << 0),
89
90   GST_ALLOCATOR_FLAG_LAST          = (GST_OBJECT_FLAG_LAST << 16)
91 } GstAllocatorFlags;
92
93 /**
94  * GstAllocator:
95  * @mem_map: the implementation of the GstMemoryMapFunction
96  * @mem_unmap: the implementation of the GstMemoryUnmapFunction
97  * @mem_copy: the implementation of the GstMemoryCopyFunction
98  * @mem_share: the implementation of the GstMemoryShareFunction
99  * @mem_is_span: the implementation of the GstMemoryIsSpanFunction
100  *
101  * The #GstAllocator is used to create new memory.
102  */
103 struct _GstAllocator
104 {
105   GstObject  object;
106
107   const gchar              *mem_type;
108
109   /*< public >*/
110   GstMemoryMapFunction      mem_map;
111   GstMemoryUnmapFunction    mem_unmap;
112
113   GstMemoryCopyFunction     mem_copy;
114   GstMemoryShareFunction    mem_share;
115   GstMemoryIsSpanFunction   mem_is_span;
116
117   /*< private >*/
118   gpointer _gst_reserved[GST_PADDING];
119
120   GstAllocatorPrivate *priv;
121 };
122
123 /**
124  * GstAllocatorClass:
125  * @object_class:  Object parent class
126  * @alloc: implementation that acquires memory
127  * @free: implementation that releases memory
128  *
129  * The #GstAllocator is used to create new memory.
130  */
131 struct _GstAllocatorClass {
132   GstObjectClass object_class;
133
134   /*< public >*/
135   GstMemory *  (*alloc)      (GstAllocator *allocator, gsize size,
136                               GstAllocationParams *params);
137   void         (*free)       (GstAllocator *allocator, GstMemory *memory);
138
139   /*< private >*/
140   gpointer _gst_reserved[GST_PADDING];
141 };
142
143 GType gst_allocator_get_type(void);
144
145 /* allocators */
146 void           gst_allocator_register        (const gchar *name, GstAllocator *allocator);
147 GstAllocator * gst_allocator_find            (const gchar *name);
148 void           gst_allocator_set_default     (GstAllocator * allocator);
149
150 /* allocation parameters */
151 void           gst_allocation_params_init    (GstAllocationParams *params);
152 GstAllocationParams *
153                gst_allocation_params_copy    (const GstAllocationParams *params) G_GNUC_MALLOC;
154 void           gst_allocation_params_free    (GstAllocationParams *params);
155
156 /* allocating memory blocks */
157 GstMemory *    gst_allocator_alloc           (GstAllocator * allocator, gsize size,
158                                               GstAllocationParams *params);
159 void           gst_allocator_free            (GstAllocator * allocator, GstMemory *memory);
160
161 GstMemory *    gst_memory_new_wrapped  (GstMemoryFlags flags, gpointer data, gsize maxsize,
162                                         gsize offset, gsize size, gpointer user_data,
163                                         GDestroyNotify notify);
164
165 G_END_DECLS
166
167 #endif /* __GST_ALLOCATOR_H__ */