2 * Copyright (C) 2003 David A. Schleef <ds@schleef.org>
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.
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.
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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef __GST_STRUCTURE_H__
21 #define __GST_STRUCTURE_H__
23 #include <gst/gstconfig.h>
24 #include <glib-object.h>
25 #include <gst/gstclock.h>
26 #include <gst/gstdatetime.h>
27 #include <gst/glib-compat.h>
31 GST_API GType _gst_structure_type;
33 typedef struct _GstStructure GstStructure;
35 #define GST_TYPE_STRUCTURE (_gst_structure_type)
36 #define GST_IS_STRUCTURE(object) ((object) && (GST_STRUCTURE(object)->type == GST_TYPE_STRUCTURE))
37 #define GST_STRUCTURE_CAST(object) ((GstStructure *)(object))
38 #define GST_STRUCTURE(object) (GST_STRUCTURE_CAST(object))
42 * GstStructureForeachFunc:
43 * @field_id: the #GQuark of the field name
44 * @value: the #GValue of the field
45 * @user_data: user data
47 * A function that will be called in gst_structure_foreach(). The function may
50 * Returns: %TRUE if the foreach operation should continue, %FALSE if
51 * the foreach operation should stop with %FALSE.
53 typedef gboolean (*GstStructureForeachFunc) (GQuark field_id,
58 * GstStructureMapFunc:
59 * @field_id: the #GQuark of the field name
60 * @value: the #GValue of the field
61 * @user_data: user data
63 * A function that will be called in gst_structure_map_in_place(). The function
66 * Returns: %TRUE if the map operation should continue, %FALSE if
67 * the map operation should stop with %FALSE.
69 typedef gboolean (*GstStructureMapFunc) (GQuark field_id,
74 * GstStructureFilterMapFunc:
75 * @field_id: the #GQuark of the field name
76 * @value: the #GValue of the field
77 * @user_data: user data
79 * A function that will be called in gst_structure_filter_and_map_in_place().
80 * The function may modify @value, and the value will be removed from
81 * the structure if %FALSE is returned.
83 * Returns: %TRUE if the field should be preserved, %FALSE if it
86 typedef gboolean (*GstStructureFilterMapFunc) (GQuark field_id,
92 * @type: the GType of a structure
94 * The GstStructure object. Most fields are private.
96 struct _GstStructure {
104 GType gst_structure_get_type (void);
107 GstStructure * gst_structure_new_empty (const gchar * name) G_GNUC_MALLOC;
110 GstStructure * gst_structure_new_id_empty (GQuark quark) G_GNUC_MALLOC;
113 GstStructure * gst_structure_new (const gchar * name,
114 const gchar * firstfield,
115 ...) G_GNUC_NULL_TERMINATED G_GNUC_MALLOC;
117 GstStructure * gst_structure_new_valist (const gchar * name,
118 const gchar * firstfield,
119 va_list varargs) G_GNUC_MALLOC;
121 GstStructure * gst_structure_new_id (GQuark name_quark,
125 GstStructure * gst_structure_new_from_string (const gchar * string);
128 GstStructure * gst_structure_copy (const GstStructure * structure) G_GNUC_MALLOC;
131 gboolean gst_structure_set_parent_refcount (GstStructure * structure,
134 void gst_structure_free (GstStructure * structure);
137 const gchar * gst_structure_get_name (const GstStructure * structure);
140 GQuark gst_structure_get_name_id (const GstStructure * structure);
143 gboolean gst_structure_has_name (const GstStructure * structure,
146 void gst_structure_set_name (GstStructure * structure,
149 void gst_structure_id_set_value (GstStructure * structure,
151 const GValue * value);
153 void gst_structure_set_value (GstStructure * structure,
154 const gchar * fieldname,
155 const GValue * value);
157 void gst_structure_set_array (GstStructure * structure,
158 const gchar * fieldname,
159 const GValueArray * array);
161 void gst_structure_set_list (GstStructure * structure,
162 const gchar * fieldname,
163 const GValueArray * array);
165 void gst_structure_id_take_value (GstStructure * structure,
169 void gst_structure_take_value (GstStructure * structure,
170 const gchar * fieldname,
173 void gst_structure_set (GstStructure * structure,
174 const gchar * fieldname,
175 ...) G_GNUC_NULL_TERMINATED;
177 void gst_structure_set_valist (GstStructure * structure,
178 const gchar * fieldname,
181 void gst_structure_id_set (GstStructure * structure,
183 ...) G_GNUC_NULL_TERMINATED;
185 void gst_structure_id_set_valist (GstStructure * structure,
189 gboolean gst_structure_get_valist (const GstStructure * structure,
190 const char * first_fieldname,
193 gboolean gst_structure_get (const GstStructure * structure,
194 const char * first_fieldname,
195 ...) G_GNUC_NULL_TERMINATED;
197 gboolean gst_structure_id_get_valist (const GstStructure * structure,
198 GQuark first_field_id,
201 gboolean gst_structure_id_get (const GstStructure * structure,
202 GQuark first_field_id,
203 ...) G_GNUC_NULL_TERMINATED;
205 const GValue * gst_structure_id_get_value (const GstStructure * structure,
208 const GValue * gst_structure_get_value (const GstStructure * structure,
209 const gchar * fieldname);
211 void gst_structure_remove_field (GstStructure * structure,
212 const gchar * fieldname);
214 void gst_structure_remove_fields (GstStructure * structure,
215 const gchar * fieldname,
216 ...) G_GNUC_NULL_TERMINATED;
218 void gst_structure_remove_fields_valist (GstStructure * structure,
219 const gchar * fieldname,
222 void gst_structure_remove_all_fields (GstStructure * structure);
225 GType gst_structure_get_field_type (const GstStructure * structure,
226 const gchar * fieldname);
228 gboolean gst_structure_foreach (const GstStructure * structure,
229 GstStructureForeachFunc func,
232 gboolean gst_structure_map_in_place (GstStructure * structure,
233 GstStructureMapFunc func,
236 void gst_structure_filter_and_map_in_place (GstStructure * structure,
237 GstStructureFilterMapFunc func,
240 gint gst_structure_n_fields (const GstStructure * structure);
243 const gchar * gst_structure_nth_field_name (const GstStructure * structure,
246 gboolean gst_structure_id_has_field (const GstStructure * structure,
249 gboolean gst_structure_id_has_field_typed (const GstStructure * structure,
253 gboolean gst_structure_has_field (const GstStructure * structure,
254 const gchar * fieldname);
256 gboolean gst_structure_has_field_typed (const GstStructure * structure,
257 const gchar * fieldname,
260 /* utility functions */
263 gboolean gst_structure_get_boolean (const GstStructure * structure,
264 const gchar * fieldname,
267 gboolean gst_structure_get_int (const GstStructure * structure,
268 const gchar * fieldname,
271 gboolean gst_structure_get_uint (const GstStructure * structure,
272 const gchar * fieldname,
275 gboolean gst_structure_get_int64 (const GstStructure * structure,
276 const gchar * fieldname,
279 gboolean gst_structure_get_uint64 (const GstStructure * structure,
280 const gchar * fieldname,
283 gboolean gst_structure_get_double (const GstStructure * structure,
284 const gchar * fieldname,
287 gboolean gst_structure_get_date (const GstStructure * structure,
288 const gchar * fieldname,
291 gboolean gst_structure_get_date_time (const GstStructure * structure,
292 const gchar * fieldname,
293 GstDateTime ** value);
295 gboolean gst_structure_get_clock_time (const GstStructure * structure,
296 const gchar * fieldname,
297 GstClockTime * value);
299 const gchar * gst_structure_get_string (const GstStructure * structure,
300 const gchar * fieldname);
302 gboolean gst_structure_get_enum (const GstStructure * structure,
303 const gchar * fieldname,
307 gboolean gst_structure_get_fraction (const GstStructure * structure,
308 const gchar * fieldname,
309 gint * value_numerator,
310 gint * value_denominator);
312 gboolean gst_structure_get_flagset (const GstStructure * structure,
313 const gchar * fieldname,
317 gboolean gst_structure_get_array (GstStructure * structure,
318 const gchar * fieldname,
319 GValueArray ** array);
321 gboolean gst_structure_get_list (GstStructure * structure,
322 const gchar * fieldname,
323 GValueArray ** array);
325 gchar * gst_structure_to_string (const GstStructure * structure) G_GNUC_MALLOC;
328 GstStructure * gst_structure_from_string (const gchar * string,
329 gchar ** end) G_GNUC_MALLOC;
331 gboolean gst_structure_fixate_field_nearest_int (GstStructure * structure,
332 const char * field_name,
335 gboolean gst_structure_fixate_field_nearest_double (GstStructure * structure,
336 const char * field_name,
339 gboolean gst_structure_fixate_field_boolean (GstStructure * structure,
340 const char * field_name,
343 gboolean gst_structure_fixate_field_string (GstStructure * structure,
344 const char * field_name,
345 const gchar * target);
347 gboolean gst_structure_fixate_field_nearest_fraction (GstStructure * structure,
348 const char * field_name,
349 const gint target_numerator,
350 const gint target_denominator);
352 gboolean gst_structure_fixate_field (GstStructure * structure,
353 const char * field_name);
355 void gst_structure_fixate (GstStructure * structure);
358 gboolean gst_structure_is_equal (const GstStructure * structure1,
359 const GstStructure * structure2);
361 gboolean gst_structure_is_subset (const GstStructure * subset,
362 const GstStructure * superset);
364 gboolean gst_structure_can_intersect (const GstStructure * struct1,
365 const GstStructure * struct2);
367 GstStructure * gst_structure_intersect (const GstStructure * struct1,
368 const GstStructure * struct2) G_GNUC_MALLOC;
370 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
371 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstStructure, gst_structure_free)