gstvalue: Do more checks when guessing at flagset strings
[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., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22
23 #ifndef __GST_META_H__
24 #define __GST_META_H__
25
26 #include <glib.h>
27
28 G_BEGIN_DECLS
29
30 typedef struct _GstMeta GstMeta;
31 typedef struct _GstMetaInfo GstMetaInfo;
32
33 #define GST_META_CAST(meta)   ((GstMeta *)(meta))
34
35 /**
36  * GstMetaFlags:
37  * @GST_META_FLAG_NONE: no flags
38  * @GST_META_FLAG_READONLY: metadata should not be modified
39  * @GST_META_FLAG_POOLED: metadata is managed by a bufferpool
40  * @GST_META_FLAG_LOCKED: metadata should not be removed
41  * @GST_META_FLAG_LAST: additional flags can be added starting from this flag.
42  *
43  * Extra metadata flags.
44  */
45 typedef enum {
46   GST_META_FLAG_NONE        = 0,
47   GST_META_FLAG_READONLY    = (1 << 0),
48   GST_META_FLAG_POOLED      = (1 << 1),
49   GST_META_FLAG_LOCKED      = (1 << 2),
50
51   GST_META_FLAG_LAST        = (1 << 16)
52 } GstMetaFlags;
53
54 /**
55  * GST_META_FLAGS:
56  * @meta: a #GstMeta.
57  *
58  * A flags word containing #GstMetaFlags flags set on @meta
59  */
60 #define GST_META_FLAGS(meta)  (GST_META_CAST (meta)->flags)
61 /**
62  * GST_META_FLAG_IS_SET:
63  * @meta: a #GstMeta.
64  * @flag: the #GstMetaFlags to check.
65  *
66  * Gives the status of a specific flag on a metadata.
67  */
68 #define GST_META_FLAG_IS_SET(meta,flag)        !!(GST_META_FLAGS (meta) & (flag))
69 /**
70  * GST_META_FLAG_SET:
71  * @meta: a #GstMeta.
72  * @flag: the #GstMetaFlags to set.
73  *
74  * Sets a metadata flag on a metadata.
75  */
76 #define GST_META_FLAG_SET(meta,flag)           (GST_META_FLAGS (meta) |= (flag))
77 /**
78  * GST_META_FLAG_UNSET:
79  * @meta: a #GstMeta.
80  * @flag: the #GstMetaFlags to clear.
81  *
82  * Clears a metadata flag.
83  */
84 #define GST_META_FLAG_UNSET(meta,flag)         (GST_META_FLAGS (meta) &= ~(flag))
85
86 /**
87  * GST_META_TAG_MEMORY_STR:
88  *
89  * This metadata stays relevant as long as memory layout is unchanged.
90  *
91  * Since: 1.2
92  */
93 #define GST_META_TAG_MEMORY_STR "memory"
94
95 /**
96  * GstMeta:
97  * @flags: extra flags for the metadata
98  * @info: pointer to the #GstMetaInfo
99  *
100  * Base structure for metadata. Custom metadata will put this structure
101  * as the first member of their structure.
102  */
103 struct _GstMeta {
104   GstMetaFlags       flags;
105   const GstMetaInfo *info;
106 };
107
108 #include <gst/gstbuffer.h>
109
110 /**
111  * GstMetaInitFunction:
112  * @meta: a #GstMeta
113  * @params: parameters passed to the init function
114  * @buffer: a #GstBuffer
115  *
116  * Function called when @meta is initialized in @buffer.
117  */
118 typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuffer *buffer);
119
120 /**
121  * GstMetaFreeFunction:
122  * @meta: a #GstMeta
123  * @buffer: a #GstBuffer
124  *
125  * Function called when @meta is freed in @buffer.
126  */
127 typedef void (*GstMetaFreeFunction)     (GstMeta *meta, GstBuffer *buffer);
128
129 /**
130  * gst_meta_transform_copy:
131  *
132  * GQuark for the "gst-copy" transform.
133  */
134 GST_EXPORT GQuark _gst_meta_transform_copy;
135
136 /**
137  * GST_META_TRANSFORM_IS_COPY:
138  * @type: a transform type
139  *
140  * Check if the transform type is a copy transform
141  */
142 #define GST_META_TRANSFORM_IS_COPY(type) ((type) == _gst_meta_transform_copy)
143
144 /**
145  * GstMetaTransformCopy:
146  * @region: %TRUE if only region is copied
147  * @offset: the offset to copy, 0 if @region is %FALSE, otherwise > 0
148  * @size: the size to copy, -1 or the buffer size when @region is %FALSE
149  *
150  * Extra data passed to a "gst-copy" transform #GstMetaTransformFunction.
151  */
152 typedef struct {
153   gboolean region;
154   gsize offset;
155   gsize size;
156 } GstMetaTransformCopy;
157
158 /**
159  * GstMetaTransformFunction:
160  * @transbuf: a #GstBuffer
161  * @meta: a #GstMeta
162  * @buffer: a #GstBuffer
163  * @type: the transform type
164  * @data: transform specific data.
165  *
166  * Function called for each @meta in @buffer as a result of performing a
167  * transformation on @transbuf. Additional @type specific transform data
168  * is passed to the function as @data.
169  *
170  * Implementations should check the @type of the transform and parse
171  * additional type specific fields in @data that should be used to update
172  * the metadata on @transbuf.
173  *
174  * Returns: %TRUE if the transform could be performed
175  */
176 typedef gboolean (*GstMetaTransformFunction) (GstBuffer *transbuf,
177                                               GstMeta *meta, GstBuffer *buffer,
178                                               GQuark type, gpointer data);
179
180 /**
181  * GstMetaInfo:
182  * @api: tag identifying the metadata structure and api
183  * @type: type identifying the implementor of the api
184  * @size: size of the metadata
185  * @init_func: function for initializing the metadata
186  * @free_func: function for freeing the metadata
187  * @transform_func: function for transforming the metadata
188  *
189  * The #GstMetaInfo provides information about a specific metadata
190  * structure.
191  */
192 struct _GstMetaInfo {
193   GType                      api;
194   GType                      type;
195   gsize                      size;
196
197   GstMetaInitFunction        init_func;
198   GstMetaFreeFunction        free_func;
199   GstMetaTransformFunction   transform_func;
200
201   /* No padding needed, GstMetaInfo is always allocated by GStreamer and is
202    * not subclassable or stack-allocatable, so we can extend it as we please
203    * just like interfaces */
204 };
205
206 GType                gst_meta_api_type_register (const gchar *api,
207                                                  const gchar **tags);
208 gboolean             gst_meta_api_type_has_tag  (GType api, GQuark tag);
209
210 const GstMetaInfo *  gst_meta_register          (GType api, const gchar *impl,
211                                                  gsize size,
212                                                  GstMetaInitFunction      init_func,
213                                                  GstMetaFreeFunction      free_func,
214                                                  GstMetaTransformFunction transform_func);
215 const GstMetaInfo *  gst_meta_get_info          (const gchar * impl);
216 const gchar* const*  gst_meta_api_type_get_tags (GType api);
217
218 /* some default tags */
219 GST_EXPORT GQuark _gst_meta_tag_memory;
220
221 /**
222  * GST_META_TAG_MEMORY:
223  *
224  * Metadata tagged with this tag depends on the particular memory
225  * or buffer that it is on.
226  *
227  * Deprecated: The GQuarks are not exported by any public API, use
228  *   GST_META_TAG_MEMORY_STR instead.
229  */
230 #ifndef GST_DISABLE_DEPRECATED
231 #define GST_META_TAG_MEMORY (_gst_meta_tag_memory)
232 #endif
233
234 G_END_DECLS
235
236 #endif /* __GST_META_H__ */