gstmeta.h 6.24 KB
Newer Older
1 2 3
/* GStreamer
 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.be>
 *
Wim Taymans's avatar
Wim Taymans committed
4
 * gstmeta.h: Header for Metadata structures
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


Wim Taymans's avatar
Wim Taymans committed
23 24
#ifndef __GST_META_H__
#define __GST_META_H__
25 26 27

G_BEGIN_DECLS

Wim Taymans's avatar
Wim Taymans committed
28 29
typedef struct _GstMeta GstMeta;
typedef struct _GstMetaInfo GstMetaInfo;
30

Wim Taymans's avatar
Wim Taymans committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#define GST_META_CAST(meta)   ((GstMeta *)(meta))

/**
 * GstMetaFlags:
 * @GST_META_FLAG_NONE: no flags
 * @GST_META_FLAG_READONLY: metadata should not be modified
 * @GST_META_FLAG_POOLED: metadata is managed by a bufferpool and should not
 *    be removed
 * @GST_META_FLAG_LAST: additional flags can be added starting from this flag.
 *
 * Extra metadata flags.
 */
typedef enum {
  GST_META_FLAG_NONE        = 0,
  GST_META_FLAG_READONLY    = (1 << 0),
  GST_META_FLAG_POOLED      = (1 << 1),

  GST_META_FLAG_LAST        = (1 << 16)
} GstMetaFlags;

/**
 * GST_META_FLAGS:
 * @meta: a #GstMeta.
 *
Wim Taymans's avatar
Wim Taymans committed
55
 * A flags word containing #GstMetaFlags flags set on @meta
Wim Taymans's avatar
Wim Taymans committed
56 57 58 59 60
 */
#define GST_META_FLAGS(meta)  (GST_META_CAST (meta)->flags)
/**
 * GST_META_FLAG_IS_SET:
 * @meta: a #GstMeta.
Wim Taymans's avatar
Wim Taymans committed
61
 * @flag: the #GstMetaFlags to check.
Wim Taymans's avatar
Wim Taymans committed
62 63 64 65 66 67 68
 *
 * Gives the status of a specific flag on a metadata.
 */
#define GST_META_FLAG_IS_SET(meta,flag)        !!(GST_META_FLAGS (meta) & (flag))
/**
 * GST_META_FLAG_SET:
 * @meta: a #GstMeta.
Wim Taymans's avatar
Wim Taymans committed
69
 * @flag: the #GstMetaFlags to set.
Wim Taymans's avatar
Wim Taymans committed
70 71 72 73 74 75 76
 *
 * Sets a metadata flag on a metadata.
 */
#define GST_META_FLAG_SET(meta,flag)           (GST_META_FLAGS (meta) |= (flag))
/**
 * GST_META_FLAG_UNSET:
 * @meta: a #GstMeta.
Wim Taymans's avatar
Wim Taymans committed
77
 * @flag: the #GstMetaFlags to clear.
Wim Taymans's avatar
Wim Taymans committed
78 79 80 81 82
 *
 * Clears a metadata flag.
 */
#define GST_META_FLAG_UNSET(meta,flag)         (GST_META_FLAGS (meta) &= ~(flag))

83
/**
Wim Taymans's avatar
Wim Taymans committed
84
 * GstMeta:
Wim Taymans's avatar
Wim Taymans committed
85
 * @flags: extra flags for the metadata
Wim Taymans's avatar
Wim Taymans committed
86
 * @info: pointer to the #GstMetaInfo
87
 *
Wim Taymans's avatar
Wim Taymans committed
88
 * Base structure for metadata. Custom metadata will put this structure
89 90
 * as the first member of their structure.
 */
Wim Taymans's avatar
Wim Taymans committed
91
struct _GstMeta {
Wim Taymans's avatar
Wim Taymans committed
92
  GstMetaFlags       flags;
Wim Taymans's avatar
Wim Taymans committed
93
  const GstMetaInfo *info;
94 95 96 97 98
};

/**
 * GstMetaInitFunction:
 * @meta: a #GstMeta
Wim Taymans's avatar
Wim Taymans committed
99
 * @params: parameters passed to the init function
100 101 102 103
 * @buffer: a #GstBuffer
 *
 * Function called when @meta is initialized in @buffer.
 */
104
typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuffer *buffer);
105 106 107 108 109 110 111 112

/**
 * GstMetaFreeFunction:
 * @meta: a #GstMeta
 * @buffer: a #GstBuffer
 *
 * Function called when @meta is freed in @buffer.
 */
Wim Taymans's avatar
Wim Taymans committed
113
typedef void (*GstMetaFreeFunction)     (GstMeta *meta, GstBuffer *buffer);
114

Wim Taymans's avatar
Wim Taymans committed
115
/**
116 117
 * gst_meta_transform_copy:
 *
Wim Taymans's avatar
Wim Taymans committed
118
 * GQuark for the "gst-copy" transform.
119 120 121
 */
GST_EXPORT GQuark _gst_meta_transform_copy;

Wim Taymans's avatar
Wim Taymans committed
122 123 124 125 126 127
/**
 * GST_META_TRANSFORM_IS_COPY:
 * @type: a transform type
 *
 * Check if the transform type is a copy transform
 */
128 129 130
#define GST_META_TRANSFORM_IS_COPY(type) ((type) == _gst_meta_transform_copy)

/**
Wim Taymans's avatar
Wim Taymans committed
131
 * GstMetaTransformCopy:
132 133 134
 * @region: %TRUE if only region is copied
 * @offset: the offset to copy, 0 if @region is %FALSE, otherwise > 0
 * @size: the size to copy, -1 or the buffer size when @region is %FALSE
Wim Taymans's avatar
Wim Taymans committed
135
 *
Wim Taymans's avatar
Wim Taymans committed
136
 * Extra data passed to a "gst-copy" transform #GstMetaTransformFunction.
Wim Taymans's avatar
Wim Taymans committed
137
 */
138
typedef struct {
139
  gboolean region;
140 141 142 143
  gsize offset;
  gsize size;
} GstMetaTransformCopy;

144 145 146
/**
 * GstMetaTransformFunction:
 * @transbuf: a #GstBuffer
147 148
 * @meta: a #GstMeta
 * @buffer: a #GstBuffer
149
 * @type: the transform type
150 151 152
 * @data: transform specific data.
 *
 * Function called for each @meta in @buffer as a result of performing a
153 154
 * transformation on @transbuf. Additional @type specific transform data
 * is passed to the function as @data.
155
 *
156 157 158
 * Implementations should check the @type of the transform and parse
 * additional type specific fields in @data that should be used to update
 * the metadata on @transbuf.
159 160
 *
 * Returns: %TRUE if the transform could be performed
161
 */
162 163 164
typedef gboolean (*GstMetaTransformFunction) (GstBuffer *transbuf,
                                              GstMeta *meta, GstBuffer *buffer,
                                              GQuark type, gpointer data);
165 166

/**
Wim Taymans's avatar
Wim Taymans committed
167 168
 * GstMetaInfo:
 * @api: tag indentifying the metadata structure and api
169
 * @type: type indentifying the implementor of the api
170 171 172
 * @size: size of the metadata
 * @init_func: function for initializing the metadata
 * @free_func: function for freeing the metadata
Wim Taymans's avatar
Wim Taymans committed
173
 * @transform_func: function for transforming the metadata
174
 *
Wim Taymans's avatar
Wim Taymans committed
175
 * The #GstMetaInfo provides information about a specific metadata
176 177
 * structure.
 */
Wim Taymans's avatar
Wim Taymans committed
178
struct _GstMetaInfo {
179
  GType                      api;
180
  GType                      type;
181 182 183 184
  gsize                      size;

  GstMetaInitFunction        init_func;
  GstMetaFreeFunction        free_func;
185
  GstMetaTransformFunction   transform_func;
Wim Taymans's avatar
Wim Taymans committed
186

Wim Taymans's avatar
Wim Taymans committed
187
  /*< private >*/
Wim Taymans's avatar
Wim Taymans committed
188
  gpointer _gst_reserved[GST_PADDING];
189 190
};

191 192 193 194 195 196 197 198 199 200
GType                gst_meta_api_type_register (const gchar *api,
                                                 const gchar **tags);
gboolean             gst_meta_api_type_has_tag  (GType api, GQuark tag);

const GstMetaInfo *  gst_meta_register          (GType api, const gchar *impl,
                                                 gsize size,
                                                 GstMetaInitFunction      init_func,
                                                 GstMetaFreeFunction      free_func,
                                                 GstMetaTransformFunction transform_func);
const GstMetaInfo *  gst_meta_get_info          (const gchar * impl);
201

202 203 204 205 206 207 208 209 210 211
/* some default tags */
GST_EXPORT GQuark _gst_meta_tag_memory;

/**
 * GST_META_TAG_MEMORY:
 *
 * Metadata tagged with this tag depends on the particular memory
 * or buffer that it is on.
 */
#define GST_META_TAG_MEMORY (_gst_meta_tag_memory)
212

213 214
G_END_DECLS

Wim Taymans's avatar
Wim Taymans committed
215
#endif /* __GST_META_H__ */