structure: Use a const GstStructure * as parameter for some more gst_structure_get...
[platform/upstream/gstreamer.git] / gst / gststructure.h
1 /* GStreamer
2  * Copyright (C) 2003 David A. Schleef <ds@schleef.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GST_STRUCTURE_H__
21 #define __GST_STRUCTURE_H__
22
23 #include <gst/gstconfig.h>
24 #include <glib-object.h>
25 #include <gst/gstclock.h>
26 #include <gst/glib-compat.h>
27
28 G_BEGIN_DECLS
29
30 #define GST_TYPE_STRUCTURE             (gst_structure_get_type ())
31 #define GST_STRUCTURE(object)          ((GstStructure *)(object))
32 #define GST_IS_STRUCTURE(object)       ((object) && (GST_STRUCTURE(object)->type == GST_TYPE_STRUCTURE))
33
34 typedef struct _GstStructure GstStructure;
35
36 /**
37  * GstStructureForeachFunc:
38  * @field_id: the #GQuark of the field name
39  * @value: the #GValue of the field
40  * @user_data: user data
41  *
42  * A function that will be called in gst_structure_foreach(). The function may
43  * not modify @value.
44  *
45  * Returns: TRUE if the foreach operation should continue, FALSE if
46  * the foreach operation should stop with FALSE.
47  */
48 typedef gboolean (*GstStructureForeachFunc) (GQuark   field_id,
49                                              const GValue * value,
50                                              gpointer user_data);
51
52 /**
53  * GstStructureMapFunc:
54  * @field_id: the #GQuark of the field name
55  * @value: the #GValue of the field
56  * @user_data: user data
57  *
58  * A function that will be called in gst_structure_map_in_place(). The function
59  * may modify @value.
60  *
61  * Returns: TRUE if the map operation should continue, FALSE if
62  * the map operation should stop with FALSE.
63  */
64 typedef gboolean (*GstStructureMapFunc)     (GQuark   field_id,
65                                              GValue * value,
66                                              gpointer user_data);
67
68 /**
69  * GstStructure:
70  * @type: the GType of a structure
71  *
72  * The GstStructure object. Most fields are private.
73  */
74 struct _GstStructure {
75   GType type;
76
77   /*< private >*/
78   GQuark name;
79
80   /* owned by parent structure, NULL if no parent */
81   gint *parent_refcount;
82
83   GArray *fields;
84
85   gpointer _gst_reserved;
86 };
87
88 GType                   gst_structure_get_type             (void);
89
90 GstStructure *          gst_structure_empty_new            (const gchar *            name);
91 GstStructure *          gst_structure_id_empty_new         (GQuark                   quark);
92 GstStructure *          gst_structure_new                  (const gchar *            name,
93                                                             const gchar *            firstfield,
94                                                             ...);
95 GstStructure *          gst_structure_new_valist           (const gchar *            name,
96                                                             const gchar *            firstfield,
97                                                             va_list                  varargs);
98 GstStructure *          gst_structure_id_new               (GQuark                   name_quark,
99                                                             GQuark                   field_quark,
100                                                             ...);
101 GstStructure *          gst_structure_copy                 (const GstStructure      *structure);
102 void                    gst_structure_set_parent_refcount  (GstStructure            *structure,
103                                                             gint            *refcount);
104 void                    gst_structure_free                 (GstStructure            *structure);
105
106 G_CONST_RETURN gchar *  gst_structure_get_name             (const GstStructure      *structure);
107 GQuark                  gst_structure_get_name_id          (const GstStructure      *structure);
108 gboolean                gst_structure_has_name             (const GstStructure      *structure,
109                                                             const gchar             *name);
110 void                    gst_structure_set_name             (GstStructure            *structure,
111                                                             const gchar             *name);
112
113 void                    gst_structure_id_set_value         (GstStructure            *structure,
114                                                             GQuark                   field,
115                                                             const GValue            *value);
116 void                    gst_structure_set_value            (GstStructure            *structure,
117                                                             const gchar             *fieldname,
118                                                             const GValue            *value);
119 void                    gst_structure_set                  (GstStructure            *structure,
120                                                             const gchar             *fieldname,
121                                                             ...) G_GNUC_NULL_TERMINATED;
122
123 void                    gst_structure_set_valist           (GstStructure            *structure,
124                                                             const gchar             *fieldname,
125                                                             va_list varargs);
126
127 void                    gst_structure_id_set                (GstStructure            *structure,
128                                                             GQuark                   fieldname,
129                                                             ...) G_GNUC_NULL_TERMINATED;
130
131 void                    gst_structure_id_set_valist         (GstStructure            *structure,
132                                                             GQuark                   fieldname,
133                                                             va_list varargs);
134
135 gboolean                gst_structure_get_valist           (const GstStructure      *structure,
136                                                             const char              *first_fieldname,
137                                                             va_list                  args);
138
139 gboolean                gst_structure_get                  (const GstStructure      *structure,
140                                                             const char              *first_fieldname,
141                                                             ...) G_GNUC_NULL_TERMINATED;
142
143 gboolean                gst_structure_id_get_valist        (const GstStructure      *structure,
144                                                             GQuark                   first_field_id,
145                                                             va_list                  args);
146
147 gboolean                gst_structure_id_get               (const GstStructure      *structure,
148                                                             GQuark                   first_field_id,
149                                                             ...) G_GNUC_NULL_TERMINATED;
150
151 G_CONST_RETURN GValue * gst_structure_id_get_value         (const GstStructure      *structure,
152                                                             GQuark                   field);
153 G_CONST_RETURN GValue * gst_structure_get_value            (const GstStructure      *structure,
154                                                             const gchar             *fieldname);
155 void                    gst_structure_remove_field         (GstStructure            *structure,
156                                                             const gchar             *fieldname);
157 void                    gst_structure_remove_fields        (GstStructure            *structure,
158                                                              const gchar            *fieldname,
159                                                             ...) G_GNUC_NULL_TERMINATED;
160 void                    gst_structure_remove_fields_valist (GstStructure             *structure,
161                                                             const gchar             *fieldname,
162                                                             va_list                  varargs);
163 void                    gst_structure_remove_all_fields    (GstStructure            *structure);
164
165 GType                   gst_structure_get_field_type       (const GstStructure      *structure,
166                                                             const gchar             *fieldname);
167 gboolean                gst_structure_foreach              (const GstStructure      *structure,
168                                                             GstStructureForeachFunc  func,
169                                                             gpointer                 user_data);
170 gboolean                gst_structure_map_in_place         (GstStructure            *structure,
171                                                             GstStructureMapFunc      func,
172                                                             gpointer                 user_data);
173 gint                    gst_structure_n_fields             (const GstStructure      *structure);
174 const gchar *           gst_structure_nth_field_name       (const GstStructure      *structure, guint index);
175 gboolean                gst_structure_id_has_field         (const GstStructure      *structure,
176                                                             GQuark                   field);
177 gboolean                gst_structure_id_has_field_typed   (const GstStructure      *structure,
178                                                             GQuark                   field,
179                                                             GType                    type);
180 gboolean                gst_structure_has_field            (const GstStructure      *structure,
181                                                             const gchar             *fieldname);
182 gboolean                gst_structure_has_field_typed      (const GstStructure      *structure,
183                                                             const gchar             *fieldname,
184                                                             GType                    type);
185
186 /* utility functions */
187 gboolean                gst_structure_get_boolean          (const GstStructure      *structure,
188                                                             const gchar             *fieldname,
189                                                             gboolean                *value);
190 gboolean                gst_structure_get_int              (const GstStructure      *structure,
191                                                             const gchar             *fieldname,
192                                                             gint                    *value);
193 gboolean                gst_structure_get_uint             (const GstStructure      *structure,
194                                                             const gchar             *fieldname,
195                                                             guint                   *value);
196 gboolean                gst_structure_get_fourcc           (const GstStructure      *structure,
197                                                             const gchar             *fieldname,
198                                                             guint32                 *value);
199 gboolean                gst_structure_get_double           (const GstStructure      *structure,
200                                                             const gchar             *fieldname,
201                                                             gdouble                 *value);
202 gboolean                gst_structure_get_date             (const GstStructure      *structure,
203                                                             const gchar             *fieldname,
204                                                             GDate                  **value);
205 gboolean                gst_structure_get_clock_time       (const GstStructure      *structure,
206                                                             const gchar             *fieldname,
207                                                             GstClockTime            *value);
208 G_CONST_RETURN gchar *  gst_structure_get_string           (const GstStructure      *structure,
209                                                             const gchar             *fieldname);
210 gboolean                gst_structure_get_enum             (const GstStructure      *structure,
211                                                             const gchar             *fieldname,
212                                                             GType                    enumtype,
213                                                             gint                    *value);
214 gboolean                gst_structure_get_fraction         (const GstStructure      *structure,
215                                                             const gchar             *fieldname,
216                                                             gint *value_numerator,
217                                                             gint *value_denominator);
218
219 gchar *                 gst_structure_to_string            (const GstStructure      *structure);
220 GstStructure *          gst_structure_from_string          (const gchar             *string,
221                                                             gchar                  **end);
222
223 gboolean                 gst_structure_fixate_field_nearest_int    (GstStructure *structure,
224                                                                          const char   *field_name,
225                                                                          int           target);
226 gboolean                 gst_structure_fixate_field_nearest_double (GstStructure *structure,
227                                                                          const char   *field_name,
228                                                                          double        target);
229
230 gboolean                 gst_structure_fixate_field_boolean (GstStructure *structure,
231                                                                          const char   *field_name,
232                                                                          gboolean        target);
233 gboolean                 gst_structure_fixate_field_string (GstStructure *structure,
234                                                                          const char   *field_name,
235                                                                          const gchar  *target);
236 gboolean                 gst_structure_fixate_field_nearest_fraction (GstStructure *structure,
237                                                                          const char   *field_name,
238                                                                          const gint target_numerator,
239                                                                          const gint target_denominator);
240
241 G_END_DECLS
242
243 #endif
244