gstmeta.h 7.27 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 31

/**
Wim Taymans's avatar
Wim Taymans committed
32 33
 * GstMeta:
 * @info: pointer to the #GstMetaInfo
34
 *
Wim Taymans's avatar
Wim Taymans committed
35
 * Base structure for metadata. Custom metadata will put this structure
36 37
 * as the first member of their structure.
 */
Wim Taymans's avatar
Wim Taymans committed
38 39
struct _GstMeta {
  const GstMetaInfo *info;
40 41 42
};

/**
Wim Taymans's avatar
Wim Taymans committed
43
 * GST_META_TRACE_NAME:
44 45 46
 *
 * The name used for tracing memory allocations.
 */
Wim Taymans's avatar
Wim Taymans committed
47
#define GST_META_TRACE_NAME           "GstMeta"
48 49 50 51 52 53 54 55

/**
 * GstMetaInitFunction:
 * @meta: a #GstMeta
 * @buffer: a #GstBuffer
 *
 * Function called when @meta is initialized in @buffer.
 */
56
typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuffer *buffer);
57 58 59 60 61 62 63 64

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

/**
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
 * GstMetaTransformType:
 * @GST_META_TRANSFORM_NONE: invalid transform type
 * @GST_META_TRANSFORM_COPY: copy transform
 * @GST_META_TRANSFORM_MAKE_WRITABLE: make writable type
 * @GST_META_TRANSFORM_TRIM: trim buffer
 * @GST_META_TRANSFORM_CUSTOM: start of custom transform types
 *
 * Different default transform types.
 */
typedef enum {
  GST_META_TRANSFORM_NONE = 0,
  GST_META_TRANSFORM_COPY,
  GST_META_TRANSFORM_MAKE_WRITABLE,
  GST_META_TRANSFORM_TRIM,

  GST_META_TRANSFORM_CUSTOM = 256 
} GstMetaTransformType;

/**
 * GstMetaTransformData:
 * @type: a #GstMetaTransformType
89
 *
90 91 92
 * Common structure that should be put as the first field in the type specific
 * structure for the #GstMetaTransformFunction. It contains the type of the
 * transform that should be performed.
93
 */
94 95 96 97
typedef struct {
  GstMetaTransformType type;
} GstMetaTransformData;

98
/**
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
 * GstMetaTransformSubbuffer:
 * @data: parent #GstMetaTransformData
 * @offset: the offset of the subbuffer
 * @size: the new size of the subbuffer
 *
 * The subbuffer specific extra info.
 */
typedef struct {
  GstMetaTransformData data;
  gsize offset;
  gsize size;
} GstMetaTransformSubbuffer;

/**
 * GstMetaTransformFunction:
 * @transbuf: a #GstBuffer
115 116
 * @meta: a #GstMeta
 * @buffer: a #GstBuffer
117 118 119 120 121 122 123 124
 * @data: transform specific data.
 *
 * Function called for each @meta in @buffer as a result of performing a
 * transformation on @transbuf. Additional type specific transform data
 * is passed to the function.
 *
 * Implementations should check the type of the transform @data and parse
 * additional type specific field that should be used to perform the transform.
125
 *
126 127
 * If @data is NULL, the metadata should be shallow copied. This is done when
 * gst_buffer_make_metadata_writable() is called.
128
 */
129 130
typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf, GstMeta *meta,
                                          GstBuffer *buffer, GstMetaTransformData *data);
131 132 133 134 135

/**
 * GstMetaSerializeFunction:
 * @meta: a #GstMeta
 */
Wim Taymans's avatar
Wim Taymans committed
136
typedef gchar * (*GstMetaSerializeFunction) (GstMeta *meta);
137 138 139 140 141

/**
 * GstMetaDeserializeFunction:
 * @meta: a #GstMeta
 */
Wim Taymans's avatar
Wim Taymans committed
142
typedef gboolean (*GstMetaDeserializeFunction) (GstMeta *meta,
143 144 145
                                                const gchar *s);

/**
Wim Taymans's avatar
Wim Taymans committed
146 147 148
 * GstMetaInfo:
 * @api: tag indentifying the metadata structure and api
 * @impl: tag indentifying the implementor of the api
149 150 151 152 153 154 155 156
 * @size: size of the metadata
 * @init_func: function for initializing the metadata
 * @free_func: function for freeing the metadata
 * @copy_func: function for copying the metadata
 * @sub_func: function for when a subbuffer is taken
 * @serialize_func: function for serializing
 * @deserialize_func: function for deserializing
 *
Wim Taymans's avatar
Wim Taymans committed
157
 * The #GstMetaInfo provides information about a specific metadata
158 159
 * structure.
 */
Wim Taymans's avatar
Wim Taymans committed
160 161 162
struct _GstMetaInfo {
  GQuark                     api;
  GQuark                     impl;
163 164 165 166
  gsize                      size;

  GstMetaInitFunction        init_func;
  GstMetaFreeFunction        free_func;
167
  GstMetaTransformFunction   transform_func;
168 169 170 171
  GstMetaSerializeFunction   serialize_func;
  GstMetaDeserializeFunction deserialize_func;
};

Wim Taymans's avatar
Wim Taymans committed
172
void _gst_meta_init (void);
173

Wim Taymans's avatar
Wim Taymans committed
174 175 176 177
const GstMetaInfo *  gst_meta_register        (const gchar *api, const gchar *impl,
                                               gsize size,
                                               GstMetaInitFunction        init_func,
                                               GstMetaFreeFunction        free_func,
178
                                               GstMetaTransformFunction   transform_func,
Wim Taymans's avatar
Wim Taymans committed
179 180 181
                                               GstMetaSerializeFunction   serialize_func,
                                               GstMetaDeserializeFunction deserialize_func);
const GstMetaInfo *  gst_meta_get_info        (const gchar * impl);
182

183 184
/* default metadata */

Wim Taymans's avatar
Wim Taymans committed
185
/* memory metadata */
186 187
typedef struct _GstMetaMemory GstMetaMemory;

Wim Taymans's avatar
Wim Taymans committed
188 189 190
const GstMetaInfo *gst_meta_memory_get_info(void);
#define GST_META_MEMORY_INFO (gst_meta_memory_get_info())

191
typedef enum {
192 193 194
  GST_META_MAP_NONE  = 0,
  GST_META_MAP_READ  = (1 << 0),
  GST_META_MAP_WRITE = (1 << 1)
195 196 197 198
} GstMetaMapFlags;

struct _GstMetaMemory
{
Wim Taymans's avatar
Wim Taymans committed
199
  GstMeta      meta;
200

Wim Taymans's avatar
Wim Taymans committed
201 202 203
  gpointer   (*mmap_func)      (GstMetaMemory *meta, gsize offset, gsize *size,
                                GstMetaMapFlags flags);
  gboolean   (*munmap_func)    (GstMetaMemory *meta, gpointer data, gsize size);
204 205 206 207 208
};

#define gst_meta_memory_map(m,o,s,f)   ((m)->mmap_func(m, o, s, f))
#define gst_meta_memory_unmap(m,d,s)   ((m)->munmap_func(m, d, s))

Wim Taymans's avatar
Wim Taymans committed
209
#define gst_buffer_get_meta_memory(b)  ((GstMetaMemory*)gst_buffer_get_meta((b),GST_META_MEMORY_INFO))
210 211 212
GstMetaMemory * gst_buffer_add_meta_memory (GstBuffer *buffer, gpointer data,
                                            GFreeFunc free_func,
                                            gsize size, gsize offset);
Wim Taymans's avatar
Wim Taymans committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
/* timing metadata */
typedef struct _GstMetaTiming GstMetaTiming;

const GstMetaInfo *gst_meta_timing_get_info(void);
#define GST_META_TIMING_INFO (gst_meta_timing_get_info())

struct _GstMetaTiming {
  GstMeta        meta;        /* common meta header */

  GstClockTime   dts;         /* decoding timestamp */
  GstClockTime   pts;         /* presentation timestamp */
  GstClockTime   duration;    /* duration of the data */
  GstClockTime   clock_rate;  /* clock rate for the above values */
};

#define gst_buffer_get_meta_timing(b)  ((GstMetaTiming*)gst_buffer_get_meta((b),GST_META_TIMING_INFO))
#define gst_buffer_add_meta_timing(b)  ((GstMetaTiming*)gst_buffer_add_meta((b),GST_META_TIMING_INFO,NULL))
230

231 232
G_END_DECLS

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