bufferpool: split bufferpool configuration
[platform/upstream/gstreamer.git] / gst / gstmeta.h
1 /* GStreamer
2  * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
3  *
4  * gstmeta.h: Header for Metadata structures
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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22
23 #ifndef __GST_META_H__
24 #define __GST_META_H__
25
26 G_BEGIN_DECLS
27
28 typedef struct _GstMeta GstMeta;
29 typedef struct _GstMetaInfo GstMetaInfo;
30
31 #define GST_META_CAST(meta)   ((GstMeta *)(meta))
32
33 /**
34  * GstMetaFlags:
35  * @GST_META_FLAG_NONE: no flags
36  * @GST_META_FLAG_READONLY: metadata should not be modified
37  * @GST_META_FLAG_POOLED: metadata is managed by a bufferpool and should not
38  *    be removed
39  * @GST_META_FLAG_LAST: additional flags can be added starting from this flag.
40  *
41  * Extra metadata flags.
42  */
43 typedef enum {
44   GST_META_FLAG_NONE        = 0,
45   GST_META_FLAG_READONLY    = (1 << 0),
46   GST_META_FLAG_POOLED      = (1 << 1),
47
48   GST_META_FLAG_LAST        = (1 << 16)
49 } GstMetaFlags;
50
51 /**
52  * GST_META_FLAGS:
53  * @meta: a #GstMeta.
54  *
55  * A flags word containing #GstMetaFlags flags set on @meta
56  */
57 #define GST_META_FLAGS(meta)  (GST_META_CAST (meta)->flags)
58 /**
59  * GST_META_FLAG_IS_SET:
60  * @meta: a #GstMeta.
61  * @flag: the #GstMetaFlags to check.
62  *
63  * Gives the status of a specific flag on a metadata.
64  */
65 #define GST_META_FLAG_IS_SET(meta,flag)        !!(GST_META_FLAGS (meta) & (flag))
66 /**
67  * GST_META_FLAG_SET:
68  * @meta: a #GstMeta.
69  * @flag: the #GstMetaFlags to set.
70  *
71  * Sets a metadata flag on a metadata.
72  */
73 #define GST_META_FLAG_SET(meta,flag)           (GST_META_FLAGS (meta) |= (flag))
74 /**
75  * GST_META_FLAG_UNSET:
76  * @meta: a #GstMeta.
77  * @flag: the #GstMetaFlags to clear.
78  *
79  * Clears a metadata flag.
80  */
81 #define GST_META_FLAG_UNSET(meta,flag)         (GST_META_FLAGS (meta) &= ~(flag))
82
83 /**
84  * GstMeta:
85  * @flags: extra flags for the metadata
86  * @info: pointer to the #GstMetaInfo
87  *
88  * Base structure for metadata. Custom metadata will put this structure
89  * as the first member of their structure.
90  */
91 struct _GstMeta {
92   GstMetaFlags       flags;
93   const GstMetaInfo *info;
94 };
95
96 /**
97  * GstMetaInitFunction:
98  * @meta: a #GstMeta
99  * @params: parameters passed to the init function
100  * @buffer: a #GstBuffer
101  *
102  * Function called when @meta is initialized in @buffer.
103  */
104 typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuffer *buffer);
105
106 /**
107  * GstMetaFreeFunction:
108  * @meta: a #GstMeta
109  * @buffer: a #GstBuffer
110  *
111  * Function called when @meta is freed in @buffer.
112  */
113 typedef void (*GstMetaFreeFunction)     (GstMeta *meta, GstBuffer *buffer);
114
115 /**
116  * gst_meta_transform_copy:
117  *
118  * GQuark for the "gst-copy" transform.
119  */
120 GST_EXPORT GQuark _gst_meta_transform_copy;
121
122 #define GST_META_TRANSFORM_IS_COPY(type) ((type) == _gst_meta_transform_copy)
123
124 /**
125  * GstMetaTransformCopy:
126  * @region: %TRUE if only region is copied
127  * @offset: the offset to copy, 0 if @region is %FALSE, otherwise > 0
128  * @size: the size to copy, -1 or the buffer size when @region is %FALSE
129  *
130  * Extra data passed to a "gst-copy" transform #GstMetaTransformFunction.
131  */
132 typedef struct {
133   gboolean region;
134   gsize offset;
135   gsize size;
136 } GstMetaTransformCopy;
137
138 /**
139  * GstMetaTransformFunction:
140  * @transbuf: a #GstBuffer
141  * @meta: a #GstMeta
142  * @buffer: a #GstBuffer
143  * @type: the transform type
144  * @data: transform specific data.
145  *
146  * Function called for each @meta in @buffer as a result of performing a
147  * transformation on @transbuf. Additional @type specific transform data
148  * is passed to the function as @data.
149  *
150  * Implementations should check the @type of the transform and parse
151  * additional type specific fields in @data that should be used to update
152  * the metadata on @transbuf.
153  *
154  * Returns: %TRUE if the transform could be performed
155  */
156 typedef gboolean (*GstMetaTransformFunction) (GstBuffer *transbuf,
157                                               GstMeta *meta, GstBuffer *buffer,
158                                               GQuark type, gpointer data);
159
160 /**
161  * GstMetaInfo:
162  * @api: tag indentifying the metadata structure and api
163  * @type: type indentifying the implementor of the api
164  * @size: size of the metadata
165  * @init_func: function for initializing the metadata
166  * @free_func: function for freeing the metadata
167  * @transform_func: function for transforming the metadata
168  *
169  * The #GstMetaInfo provides information about a specific metadata
170  * structure.
171  */
172 struct _GstMetaInfo {
173   GType                      api;
174   GType                      type;
175   gsize                      size;
176
177   GstMetaInitFunction        init_func;
178   GstMetaFreeFunction        free_func;
179   GstMetaTransformFunction   transform_func;
180
181   /*< private >*/
182   gpointer _gst_reserved[GST_PADDING];
183 };
184
185 GType                gst_meta_api_type_register (const gchar *api,
186                                                  const gchar **tags);
187 gboolean             gst_meta_api_type_has_tag  (GType api, GQuark tag);
188
189 const GstMetaInfo *  gst_meta_register          (GType api, const gchar *impl,
190                                                  gsize size,
191                                                  GstMetaInitFunction      init_func,
192                                                  GstMetaFreeFunction      free_func,
193                                                  GstMetaTransformFunction transform_func);
194 const GstMetaInfo *  gst_meta_get_info          (const gchar * impl);
195
196 /* some default tags */
197 GST_EXPORT GQuark _gst_meta_tag_memory;
198
199 /**
200  * GST_META_TAG_MEMORY:
201  *
202  * Metadata tagged with this tag depends on the particular memory
203  * or buffer that it is on.
204  */
205 #define GST_META_TAG_MEMORY (_gst_meta_tag_memory)
206
207 G_END_DECLS
208
209 #endif /* __GST_META_H__ */