fbba358aaf2b83b99abc2130389f13e2e285196e
[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
27 G_BEGIN_DECLS
28
29 #define GST_TYPE_STRUCTURE             (gst_structure_get_type ())
30 #define GST_STRUCTURE(object)          ((GstStructure *)(object))
31 #define GST_IS_STRUCTURE(object)       ((object) && (GST_STRUCTURE(object)->type == GST_TYPE_STRUCTURE))
32
33 typedef struct _GstStructure GstStructure;
34
35 /**
36  * GstStructureForeachFunc:
37  * @field_id: the #GQuark of the field name
38  * @value: the #GValue of the field
39  * @user_data: user data
40  *
41  * A function that will be called in gst_structure_foreach(). The function may
42  * not modify @value.
43  *
44  * Returns: TRUE if the foreach operation should continue, FALSE if
45  * the foreach operation should stop with FALSE.
46  */
47 typedef gboolean (*GstStructureForeachFunc) (GQuark   field_id,
48                                              const GValue * value,
49                                              gpointer user_data);
50
51 /**
52  * GstStructureMapFunc:
53  * @field_id: the #GQuark of the field name
54  * @value: the #GValue of the field
55  * @user_data: user data
56  *
57  * A function that will be called in gst_structure_map_in_place(). The function
58  * may modify @value.
59  *
60  * Returns: TRUE if the map operation should continue, FALSE if
61  * the map operation should stop with FALSE.
62  */
63 typedef gboolean (*GstStructureMapFunc)     (GQuark   field_id,
64                                              GValue * value,
65                                              gpointer user_data);
66
67 /**
68  * GstStructure:
69  * @type: the GType of a structure
70  *
71  * The GstStructure object. Most fields are private.
72  */
73 struct _GstStructure {
74   GType type;
75
76   /*< private >*/
77   GQuark name;
78
79   /* owned by parent structure, NULL if no parent */
80   gint *parent_refcount;
81
82   GArray *fields;
83
84   gpointer _gst_reserved[GST_PADDING];
85 };
86
87 GType                   gst_structure_get_type             (void);
88
89 GstStructure *          gst_structure_empty_new            (const gchar *            name);
90 GstStructure *          gst_structure_id_empty_new         (GQuark                   quark);
91 GstStructure *          gst_structure_new                  (const gchar *            name,
92                                                             const gchar *            firstfield,
93                                                             ...);
94 GstStructure *          gst_structure_new_valist           (const gchar *            name,
95                                                             const gchar *            firstfield,
96                                                             va_list                  varargs);
97 GstStructure *          gst_structure_copy                 (const GstStructure      *structure);
98 void                    gst_structure_set_parent_refcount  (GstStructure            *structure,
99                                                             gint            *refcount);
100 void                    gst_structure_free                 (GstStructure            *structure);
101
102 G_CONST_RETURN gchar *  gst_structure_get_name             (const GstStructure      *structure);
103 GQuark                  gst_structure_get_name_id          (const GstStructure      *structure);
104 gboolean                gst_structure_has_name             (const GstStructure      *structure,
105                                                             const gchar             *name);
106 void                    gst_structure_set_name             (GstStructure            *structure,
107                                                             const gchar             *name);
108
109 void                    gst_structure_id_set_value         (GstStructure            *structure,
110                                                             GQuark                   field,
111                                                             const GValue            *value);
112 void                    gst_structure_set_value            (GstStructure            *structure,
113                                                             const gchar             *fieldname,
114                                                             const GValue            *value);
115 void                    gst_structure_set                  (GstStructure            *structure,
116                                                             const gchar             *fieldname,
117                                                             ...);
118 void                    gst_structure_set_valist           (GstStructure            *structure,
119                                                             const gchar             *fieldname,
120                                                             va_list varargs);
121 G_CONST_RETURN GValue * gst_structure_id_get_value         (const GstStructure      *structure,
122                                                             GQuark                   field);
123 G_CONST_RETURN GValue * gst_structure_get_value            (const GstStructure      *structure,
124                                                             const gchar             *fieldname);
125 void                    gst_structure_remove_field         (GstStructure            *structure,
126                                                             const gchar             *fieldname);
127 void                    gst_structure_remove_fields        (GstStructure            *structure,
128                                                              const gchar            *fieldname,
129                                                             ...);
130 void                    gst_structure_remove_fields_valist (GstStructure             *structure,
131                                                             const gchar             *fieldname,
132                                                             va_list                  varargs);
133 void                    gst_structure_remove_all_fields    (GstStructure            *structure);
134
135 GType                   gst_structure_get_field_type       (const GstStructure      *structure,
136                                                             const gchar             *fieldname);
137 gboolean                gst_structure_foreach              (const GstStructure      *structure,
138                                                             GstStructureForeachFunc  func,
139                                                             gpointer                 user_data);
140 gboolean                gst_structure_map_in_place         (GstStructure            *structure,
141                                                             GstStructureMapFunc      func,
142                                                             gpointer                 user_data);
143 gint                    gst_structure_n_fields             (const GstStructure      *structure);
144 const gchar *           gst_structure_nth_field_name       (const GstStructure      *structure, guint index);
145 gboolean                gst_structure_has_field            (const GstStructure      *structure,
146                                                             const gchar             *fieldname);
147 gboolean                gst_structure_has_field_typed      (const GstStructure      *structure,
148                                                             const gchar             *fieldname,
149                                                             GType                    type);
150
151 /* utility functions */
152 gboolean                gst_structure_get_boolean          (const GstStructure      *structure,
153                                                             const gchar             *fieldname,
154                                                             gboolean                *value);
155 gboolean                gst_structure_get_int              (const GstStructure      *structure,
156                                                             const gchar             *fieldname,
157                                                             gint                    *value);
158 gboolean                gst_structure_get_fourcc           (const GstStructure      *structure,
159                                                             const gchar             *fieldname,
160                                                             guint32                 *value);
161 gboolean                gst_structure_get_double           (const GstStructure      *structure,
162                                                             const gchar             *fieldname,
163                                                             gdouble                 *value);
164 gboolean                gst_structure_get_date             (const GstStructure      *structure,
165                                                             const gchar             *fieldname,
166                                                             GDate                  **value);
167 gboolean                gst_structure_get_clock_time       (const GstStructure      *structure,
168                                                             const gchar             *fieldname,
169                                                             GstClockTime            *value);
170 G_CONST_RETURN gchar *  gst_structure_get_string           (const GstStructure      *structure,
171                                                             const gchar             *fieldname);
172 gboolean                gst_structure_get_enum             (const GstStructure      *structure,
173                                                             const gchar             *fieldname,
174                                                             GType                    enumtype,
175                                                             gint                    *value);
176
177 gchar *                 gst_structure_to_string            (const GstStructure      *structure);
178 GstStructure *          gst_structure_from_string          (const gchar             *string,
179                                                             gchar                  **end);
180
181 gboolean                 gst_structure_fixate_field_nearest_int    (GstStructure *structure,
182                                                                          const char   *field_name,
183                                                                          int           target);
184 gboolean                 gst_structure_fixate_field_nearest_double (GstStructure *structure,
185                                                                          const char   *field_name,
186                                                                          double        target);
187
188 gboolean                 gst_structure_fixate_field_boolean (GstStructure *structure,
189                                                                          const char   *field_name,
190                                                                          gboolean        target);
191
192
193 G_END_DECLS
194
195 #endif
196