baseparse: support reverse playback
[platform/upstream/gstreamer.git] / gst / gstcaps.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_CAPS_H__
21 #define __GST_CAPS_H__
22
23 #include <gst/gstconfig.h>
24 #include <gst/gststructure.h>
25 #include <gst/glib-compat.h>
26
27 G_BEGIN_DECLS
28
29 #define GST_TYPE_CAPS             (gst_caps_get_type())
30 #define GST_CAPS(object)          ((GstCaps*)object)
31 #define GST_IS_CAPS(object)       ((object) && (GST_CAPS(object)->type == GST_TYPE_CAPS))
32
33 #define GST_TYPE_STATIC_CAPS      (gst_static_caps_get_type())
34
35 /**
36  * GstCapsFlags:
37  * @GST_CAPS_FLAGS_ANY: Caps has no specific content, but can contain
38  *    anything.
39  *
40  * Extra flags for a caps.
41  */
42 typedef enum {
43   GST_CAPS_FLAGS_ANY    = (1 << 0)
44 } GstCapsFlags;
45
46 /**
47  * GstCapsIntersectMode:
48  * @GST_CAPS_INTERSECT_ZIG_ZAG  : Zig-zags over both caps.
49  * @GST_CAPS_INTERSECT_FIRST    : Keeps the first caps order.
50  *
51  * Modes of caps intersection
52  * 
53  * #GST_CAPS_INTERSECT_ZIG_ZAG tries to preserve overall order of both caps
54  * by iterating on the caps' structures as the following matrix shows:
55  *          caps1
56  *       +-------------
57  *       | 1  2  4  7
58  * caps2 | 3  5  8 10
59  *       | 6  9 11 12
60  *
61  * Used when there is no explicit precedence of one caps over the other. e.g.
62  * tee's sink pad getcaps function, it will probe its src pad peers' for their
63  * caps and intersect them with this mode.
64  *
65  * #GST_CAPS_INTERSECT_FIRST is useful when an element wants to preserve
66  * another element's caps priority order when intersecting with its own caps.
67  * Example: If caps1 is [A, B, C] and caps2 is [E, B, D, A], the result
68  * would be [A, B], maintaining the first caps priority on the intersection.
69  *
70  * Since: 0.10.33
71  */
72 typedef enum {
73   GST_CAPS_INTERSECT_ZIG_ZAG            =  0,
74   GST_CAPS_INTERSECT_FIRST              =  1
75 } GstCapsIntersectMode;
76
77 /**
78  * GST_CAPS_ANY:
79  *
80  * Means that the element/pad can output 'anything'. Useful for elements
81  * that output unknown media, such as filesrc.
82  */
83 #define GST_CAPS_ANY              gst_caps_new_any()
84 /**
85  * GST_CAPS_NONE:
86  *
87  * The opposite of %GST_CAPS_ANY: it means that the pad/element outputs an
88  * undefined media type that can not be detected.
89  */
90 #define GST_CAPS_NONE             gst_caps_new_empty()
91
92 /**
93  * GST_STATIC_CAPS_ANY:
94  *
95  * Creates a new #GstCaps static caps that matches anything.
96  * This can be used in pad templates.
97  */
98 #define GST_STATIC_CAPS_ANY       GST_STATIC_CAPS("ANY")
99 /**
100  * GST_STATIC_CAPS_NONE:
101  *
102  * Creates a new #GstCaps static caps that matches nothing.
103  * This can be used in pad templates.
104  */
105 #define GST_STATIC_CAPS_NONE      GST_STATIC_CAPS("NONE")
106
107 /**
108  * GST_CAPS_IS_SIMPLE:
109  * @caps: the #GstCaps instance to check
110  *
111  * Convenience macro that checks if the number of structures in the given caps
112  * is exactly one.
113  */
114 #define GST_CAPS_IS_SIMPLE(caps) (gst_caps_get_size(caps) == 1)
115
116 #ifndef GST_DISABLE_DEPRECATED
117 /**
118  * GST_DEBUG_CAPS:
119  * @string: a string that should be prepended to the caps data.
120  * @caps: the #GstCaps instance to print
121  *
122  * Convenience macro for printing out the contents of caps with GST_DEBUG().
123  *
124  * Deprecated: do not use anymore
125  */
126 #define GST_DEBUG_CAPS(string, caps) \
127   GST_DEBUG ( string "%s: " GST_PTR_FORMAT, caps)
128
129 #endif /* GST_DISABLE_DEPRECATED */
130
131 /**
132  * GST_STATIC_CAPS:
133  * @string: the string describing the caps
134  *
135  * Creates a new #GstCaps static caps from an input string.
136  * This can be used in pad templates.
137  */
138 #define GST_STATIC_CAPS(string) \
139 { \
140   /* caps */ { 0, 0, (GstCapsFlags) 0, NULL, GST_PADDING_INIT }, \
141   /* string */ string, \
142   GST_PADDING_INIT \
143 }
144
145 typedef struct _GstCaps GstCaps;
146 typedef struct _GstStaticCaps GstStaticCaps;
147
148 /* refcount */
149 /**
150  * GST_CAPS_REFCOUNT:
151  * @caps: a #GstCaps
152  *
153  * Get access to the reference count field of the caps
154  */
155 #define GST_CAPS_REFCOUNT(caps)                 ((GST_CAPS(caps))->refcount)
156 /**
157  * GST_CAPS_REFCOUNT_VALUE:
158  * @caps: a #GstCaps
159  *
160  * Get the reference count value of the caps.
161  */
162 #define GST_CAPS_REFCOUNT_VALUE(caps)           (g_atomic_int_get (&(GST_CAPS(caps))->refcount))
163
164 /**
165  * GstCaps:
166  * @type: GType of the caps
167  * @refcount: the atomic refcount value
168  * @flags: extra flags for the caps, read only.
169  *
170  * Object describing media types.
171  */
172 struct _GstCaps {
173   GType type;
174
175   /*< public >*/ /* with COW */
176   /* refcounting */
177   gint           refcount;
178
179   /*< public >*/ /* read only */
180   GstCapsFlags flags;
181
182   /*< private >*/
183   GPtrArray *structs;
184
185   /*< private >*/
186   gpointer _gst_reserved[GST_PADDING];
187 };
188
189 /**
190  * GstStaticCaps:
191  * @caps: the cached #GstCaps
192  * @string: a string describing a caps
193  *
194  * Datastructure to initialize #GstCaps from a string description usually
195  * used in conjunction with GST_STATIC_CAPS() and gst_static_caps_get() to
196  * instantiate a #GstCaps.
197  */
198 struct _GstStaticCaps {
199   /*< public >*/
200   GstCaps caps;
201   const char *string;
202
203   /*< private >*/
204   gpointer _gst_reserved[GST_PADDING];
205 };
206
207 GType             gst_caps_get_type                (void);
208 GstCaps *         gst_caps_new_empty               (void);
209 GstCaps *         gst_caps_new_any                 (void);
210 GstCaps *         gst_caps_new_simple              (const char    *media_type,
211                                                     const char    *fieldname,
212                                                     ...);
213 GstCaps *         gst_caps_new_full                (GstStructure  *struct1, ...);
214 GstCaps *         gst_caps_new_full_valist         (GstStructure  *structure,
215                                                     va_list        var_args);
216
217 /* reference counting */
218 GstCaps *         gst_caps_ref                     (GstCaps       *caps);
219 GstCaps *         gst_caps_copy                    (const GstCaps *caps);
220 GstCaps *         gst_caps_make_writable           (GstCaps       *caps) G_GNUC_WARN_UNUSED_RESULT;
221 void              gst_caps_unref                   (GstCaps       *caps);
222
223 GType             gst_static_caps_get_type         (void);
224 GstCaps *         gst_static_caps_get              (GstStaticCaps *static_caps);
225
226 /* manipulation */
227 void              gst_caps_append                  (GstCaps       *caps1,
228                                                     GstCaps       *caps2);
229 void              gst_caps_merge                   (GstCaps       *caps1,
230                                                     GstCaps       *caps2);
231 void              gst_caps_append_structure        (GstCaps       *caps,
232                                                     GstStructure  *structure);
233 void              gst_caps_remove_structure        (GstCaps       *caps, guint idx);
234 void              gst_caps_merge_structure         (GstCaps       *caps,
235                                                     GstStructure  *structure);
236 guint             gst_caps_get_size                (const GstCaps *caps);
237 GstStructure *    gst_caps_get_structure           (const GstCaps *caps,
238                                                     guint          index);
239 GstStructure *    gst_caps_steal_structure         (GstCaps *caps,
240                                                     guint          index);
241 GstCaps *         gst_caps_copy_nth                (const GstCaps *caps, guint nth);
242 void              gst_caps_truncate                (GstCaps       *caps);
243 void              gst_caps_set_value               (GstCaps       *caps,
244                                                     const char    *field,
245                                                     const GValue  *value);
246 void              gst_caps_set_simple              (GstCaps       *caps,
247                                                     const char    *field, ...) G_GNUC_NULL_TERMINATED;
248 void              gst_caps_set_simple_valist       (GstCaps       *caps,
249                                                     const char    *field,
250                                                     va_list        varargs);
251
252 /* tests */
253 gboolean          gst_caps_is_any                  (const GstCaps *caps);
254 gboolean          gst_caps_is_empty                (const GstCaps *caps);
255 gboolean          gst_caps_is_fixed                (const GstCaps *caps);
256 gboolean          gst_caps_is_always_compatible    (const GstCaps *caps1,
257                                                     const GstCaps *caps2);
258 gboolean          gst_caps_is_subset               (const GstCaps *subset,
259                                                     const GstCaps *superset);
260 gboolean          gst_caps_is_equal                (const GstCaps *caps1,
261                                                     const GstCaps *caps2);
262 gboolean          gst_caps_is_equal_fixed          (const GstCaps *caps1,
263                                                     const GstCaps *caps2);
264 gboolean          gst_caps_can_intersect           (const GstCaps * caps1,
265                                                     const GstCaps * caps2);
266
267
268 /* operations */
269 GstCaps *         gst_caps_intersect               (const GstCaps *caps1,
270                                                     const GstCaps *caps2);
271 GstCaps *         gst_caps_intersect_full          (const GstCaps *caps1,
272                                                     const GstCaps *caps2,
273                                                     GstCapsIntersectMode mode);
274 GstCaps *         gst_caps_subtract                (const GstCaps *minuend,
275                                                     const GstCaps *subtrahend);
276 GstCaps *         gst_caps_union                   (const GstCaps *caps1,
277                                                     const GstCaps *caps2);
278 GstCaps *         gst_caps_normalize               (const GstCaps *caps);
279 gboolean          gst_caps_do_simplify             (GstCaps       *caps);
280
281 #if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_DISABLE_DEPRECATED)
282 xmlNodePtr        gst_caps_save_thyself            (const GstCaps *caps,
283                                                     xmlNodePtr     parent);
284 GstCaps *         gst_caps_load_thyself            (xmlNodePtr     parent);
285 #endif
286
287 /* utility */
288 void              gst_caps_replace                 (GstCaps      **caps,
289                                                     GstCaps       *newcaps);
290 gchar *           gst_caps_to_string               (const GstCaps *caps);
291 GstCaps *         gst_caps_from_string             (const gchar   *string);
292
293 G_END_DECLS
294
295 #endif /* __GST_CAPS_H__ */