Merge branch 'master' into 0.11
[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 /**
32  * GstMeta:
33  * @info: pointer to the #GstMetaInfo
34  *
35  * Base structure for metadata. Custom metadata will put this structure
36  * as the first member of their structure.
37  */
38 struct _GstMeta {
39   const GstMetaInfo *info;
40 };
41
42 /**
43  * GST_META_TRACE_NAME:
44  *
45  * The name used for tracing memory allocations.
46  */
47 #define GST_META_TRACE_NAME           "GstMeta"
48
49 /**
50  * GstMetaInitFunction:
51  * @meta: a #GstMeta
52  * @buffer: a #GstBuffer
53  *
54  * Function called when @meta is initialized in @buffer.
55  */
56 typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuffer *buffer);
57
58 /**
59  * GstMetaFreeFunction:
60  * @meta: a #GstMeta
61  * @buffer: a #GstBuffer
62  *
63  * Function called when @meta is freed in @buffer.
64  */
65 typedef void (*GstMetaFreeFunction)     (GstMeta *meta, GstBuffer *buffer);
66
67 typedef void (*GstMetaCopyFunction)     (GstBuffer *dest, GstMeta *meta,
68                                          GstBuffer *buffer, gsize offset, gsize size);
69 /**
70  * GstMetaTransformFunction:
71  * @transbuf: a #GstBuffer
72  * @meta: a #GstMeta
73  * @buffer: a #GstBuffer
74  * @data: transform specific data.
75  *
76  * Function called for each @meta in @buffer as a result of performing a
77  * transformation on @transbuf. Additional type specific transform data
78  * is passed to the function.
79  *
80  * Implementations should check the type of the transform @data and parse
81  * additional type specific field that should be used to perform the transform.
82  */
83 typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf, GstMeta *meta,
84                                           GstBuffer *buffer, gpointer data);
85
86 /**
87  * GstMetaInfo:
88  * @api: tag indentifying the metadata structure and api
89  * @type: type indentifying the implementor of the api
90  * @size: size of the metadata
91  * @init_func: function for initializing the metadata
92  * @free_func: function for freeing the metadata
93  * @copy_func: function for copying the metadata
94  * @transform_func: function for transforming the metadata
95  *
96  * The #GstMetaInfo provides information about a specific metadata
97  * structure.
98  */
99 struct _GstMetaInfo {
100   GQuark                     api;
101   GType                      type;
102   gsize                      size;
103
104   GstMetaInitFunction        init_func;
105   GstMetaFreeFunction        free_func;
106   GstMetaCopyFunction        copy_func;
107   GstMetaTransformFunction   transform_func;
108 };
109
110 const GstMetaInfo *  gst_meta_register        (const gchar *api, const gchar *impl,
111                                                gsize size,
112                                                GstMetaInitFunction        init_func,
113                                                GstMetaFreeFunction        free_func,
114                                                GstMetaCopyFunction        copy_func,
115                                                GstMetaTransformFunction   transform_func);
116 const GstMetaInfo *  gst_meta_get_info        (const gchar * impl);
117
118 /* default metadata */
119
120 /* timing metadata */
121 typedef struct _GstMetaTiming GstMetaTiming;
122
123 const GstMetaInfo *gst_meta_timing_get_info(void);
124 #define GST_META_TIMING_INFO (gst_meta_timing_get_info())
125
126 struct _GstMetaTiming {
127   GstMeta        meta;        /* common meta header */
128
129   GstClockTime   dts;         /* decoding timestamp */
130   GstClockTime   pts;         /* presentation timestamp */
131   GstClockTime   duration;    /* duration of the data */
132   GstClockTime   clock_rate;  /* clock rate for the above values */
133 };
134
135 #define gst_buffer_get_meta_timing(b)  ((GstMetaTiming*)gst_buffer_get_meta((b),GST_META_TIMING_INFO))
136 #define gst_buffer_add_meta_timing(b)  ((GstMetaTiming*)gst_buffer_add_meta((b),GST_META_TIMING_INFO,NULL))
137
138 G_END_DECLS
139
140 #endif /* __GST_META_H__ */