Merge remote-tracking branch 'origin/master' into 0.11
[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/gstminiobject.h>
25 #include <gst/gststructure.h>
26 #include <gst/glib-compat.h>
27
28 G_BEGIN_DECLS
29
30 extern GType _gst_caps_type;
31
32 #define GST_TYPE_CAPS             (_gst_caps_type)
33 #define GST_IS_CAPS(obj)          (GST_IS_MINI_OBJECT_TYPE((obj), GST_TYPE_CAPS))
34 #define GST_CAPS_CAST(obj)        ((GstCaps*)(obj))
35 #define GST_CAPS(obj)             (GST_CAPS_CAST(obj))
36
37 #define GST_TYPE_STATIC_CAPS      (gst_static_caps_get_type())
38
39 /**
40  * GstCapsFlags:
41  * @GST_CAPS_FLAG_ANY: Caps has no specific content, but can contain
42  *    anything.
43  *
44  * Extra flags for a caps.
45  */
46 typedef enum {
47   GST_CAPS_FLAG_ANY     = (GST_MINI_OBJECT_FLAG_LAST << 0)
48 } GstCapsFlags;
49
50 /**
51  * GstCapsIntersectMode:
52  * @GST_CAPS_INTERSECT_ZIG_ZAG  : Zig-zags over both caps.
53  * @GST_CAPS_INTERSECT_FIRST    : Keeps the first caps order.
54  *
55  * Modes of caps intersection
56  *
57  * @GST_CAPS_INTERSECT_ZIG_ZAG tries to preserve overall order of both caps
58  * by iterating on the caps' structures as the following matrix shows:
59  * |[
60  *          caps1
61  *       +-------------
62  *       | 1  2  4  7
63  * caps2 | 3  5  8 10
64  *       | 6  9 11 12
65  * ]|
66  * Used when there is no explicit precedence of one caps over the other. e.g.
67  * tee's sink pad getcaps function, it will probe its src pad peers' for their
68  * caps and intersect them with this mode.
69  *
70  * @GST_CAPS_INTERSECT_FIRST is useful when an element wants to preserve
71  * another element's caps priority order when intersecting with its own caps.
72  * Example: If caps1 is [A, B, C] and caps2 is [E, B, D, A], the result
73  * would be [A, B], maintaining the first caps priority on the intersection.
74  *
75  * Since: 0.10.33
76  */
77 typedef enum {
78   GST_CAPS_INTERSECT_ZIG_ZAG            =  0,
79   GST_CAPS_INTERSECT_FIRST              =  1
80 } GstCapsIntersectMode;
81
82 /**
83  * GST_CAPS_ANY:
84  *
85  * Means that the element/pad can output 'anything'. Useful for elements
86  * that output unknown media, such as filesrc.
87  */
88 #define GST_CAPS_ANY              gst_caps_new_any()
89 /**
90  * GST_CAPS_NONE:
91  *
92  * The opposite of %GST_CAPS_ANY: it means that the pad/element outputs an
93  * undefined media type that can not be detected.
94  */
95 #define GST_CAPS_NONE             gst_caps_new_empty()
96
97 /**
98  * GST_STATIC_CAPS_ANY:
99  *
100  * Creates a new #GstCaps static caps that matches anything.
101  * This can be used in pad templates.
102  */
103 #define GST_STATIC_CAPS_ANY       GST_STATIC_CAPS("ANY")
104 /**
105  * GST_STATIC_CAPS_NONE:
106  *
107  * Creates a new #GstCaps static caps that matches nothing.
108  * This can be used in pad templates.
109  */
110 #define GST_STATIC_CAPS_NONE      GST_STATIC_CAPS("NONE")
111
112 /**
113  * GST_CAPS_IS_SIMPLE:
114  * @caps: the #GstCaps instance to check
115  *
116  * Convenience macro that checks if the number of structures in the given caps
117  * is exactly one.
118  */
119 #define GST_CAPS_IS_SIMPLE(caps) (gst_caps_get_size(caps) == 1)
120
121 /**
122  * GST_STATIC_CAPS:
123  * @string: the string describing the caps
124  *
125  * Creates a new #GstCaps static caps from an input string.
126  * This can be used in pad templates.
127  */
128 #define GST_STATIC_CAPS(string) \
129 { \
130   /* miniobject */ { { 0, 0, 0, 0, NULL, NULL, NULL, 0, NULL }, \
131   /* caps */ NULL }, \
132   /* string */ string, \
133   GST_PADDING_INIT \
134 }
135
136 typedef struct _GstCaps GstCaps;
137 typedef struct _GstStaticCaps GstStaticCaps;
138
139 /**
140  * GST_CAPS_FLAGS:
141  * @caps: a #GstCaps.
142  *
143  * A flags word containing #GstCapsFlags flags set on this caps.
144  */
145 #define GST_CAPS_FLAGS(caps)                    GST_MINI_OBJECT_FLAGS(caps)
146
147 /* refcount */
148 /**
149  * GST_CAPS_REFCOUNT:
150  * @caps: a #GstCaps
151  *
152  * Get access to the reference count field of the caps
153  */
154 #define GST_CAPS_REFCOUNT(caps)                 GST_MINI_OBJECT_REFCOUNT(caps)
155 /**
156  * GST_CAPS_REFCOUNT_VALUE:
157  * @caps: a #GstCaps
158  *
159  * Get the reference count value of the caps.
160  */
161 #define GST_CAPS_REFCOUNT_VALUE(caps)           GST_MINI_OBJECT_REFCOUNT_VALUE(caps)
162
163 /**
164  * GST_CAPS_FLAG_IS_SET:
165  * @caps: a #GstCaps.
166  * @flag: the #GstCapsFlags to check.
167  *
168  * Gives the status of a specific flag on a caps.
169  */
170 #define GST_CAPS_FLAG_IS_SET(caps,flag)        GST_MINI_OBJECT_FLAG_IS_SET (caps, flag)
171 /**
172  * GST_CAPS_FLAG_SET:
173  * @caps: a #GstCaps.
174  * @flag: the #GstCapsFlags to set.
175  *
176  * Sets a caps flag on a caps.
177  */
178 #define GST_CAPS_FLAG_SET(caps,flag)           GST_MINI_OBJECT_FLAG_SET (caps, flag)
179 /**
180  * GST_CAPS_FLAG_UNSET:
181  * @caps: a #GstCaps.
182  * @flag: the #GstCapsFlags to clear.
183  *
184  * Clears a caps flag.
185  */
186 #define GST_CAPS_FLAG_UNSET(caps,flag)         GST_MINI_OBJECT_FLAG_UNSET (caps, flag)
187
188 /* refcounting */
189 /**
190  * gst_caps_ref:
191  * @caps: the #GstCaps to reference
192  *
193  * Add a reference to a #GstCaps object.
194  *
195  * From this point on, until the caller calls gst_caps_unref() or
196  * gst_caps_make_writable(), it is guaranteed that the caps object will not
197  * change. This means its structures won't change, etc. To use a #GstCaps
198  * object, you must always have a refcount on it -- either the one made
199  * implicitly by e.g. gst_caps_new_simple(), or via taking one explicitly with
200  * this function.
201  *
202  * Returns: the same #GstCaps object.
203  */
204 #ifdef _FOOL_GTK_DOC_
205 G_INLINE_FUNC GstCaps * gst_caps_ref (GstCaps * caps);
206 #endif
207
208 static inline GstCaps *
209 gst_caps_ref (GstCaps * caps)
210 {
211   return (GstCaps *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (caps));
212 }
213
214 /**
215  * gst_caps_unref:
216  * @caps: a #GstCaps.
217  *
218  * Unref a #GstCaps and and free all its structures and the
219  * structures' values when the refcount reaches 0.
220  */
221 #ifdef _FOOL_GTK_DOC_
222 G_INLINE_FUNC void gst_caps_unref (GstCaps * caps);
223 #endif
224
225 static inline void
226 gst_caps_unref (GstCaps * caps)
227 {
228   gst_mini_object_unref (GST_MINI_OBJECT_CAST (caps));
229 }
230
231 /* copy caps */
232 /**
233  * gst_caps_copy:
234  * @caps: a #GstCaps.
235  *
236  * Creates a new #GstCaps as a copy of the old @caps. The new caps will have a
237  * refcount of 1, owned by the caller. The structures are copied as well.
238  *
239  * Note that this function is the semantic equivalent of a gst_caps_ref()
240  * followed by a gst_caps_make_writable(). If you only want to hold on to a
241  * reference to the data, you should use gst_caps_ref().
242  *
243  * When you are finished with the caps, call gst_caps_unref() on it.
244  *
245  * Returns: the new #GstCaps
246  */
247 #ifdef _FOOL_GTK_DOC_
248 G_INLINE_FUNC GstCaps * gst_caps_copy (const GstCaps * caps);
249 #endif
250
251 static inline GstCaps *
252 gst_caps_copy (const GstCaps * caps)
253 {
254   return GST_CAPS (gst_mini_object_copy (GST_MINI_OBJECT_CAST (caps)));
255 }
256
257 /**
258  * gst_caps_is_writable:
259  * @caps: a #GstCaps
260  *
261  * Tests if you can safely modify @caps. It is only safe to modify caps when
262  * there is only one owner of the caps - ie, the refcount is 1.
263  */
264 #define         gst_caps_is_writable(caps)     gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (caps))
265
266 /**
267  * gst_caps_make_writable:
268  * @caps: (transfer full): a #GstCaps
269  *
270  * Returns a writable copy of @caps.
271  *
272  * If there is only one reference count on @caps, the caller must be the owner,
273  * and so this function will return the caps object unchanged. If on the other
274  * hand there is more than one reference on the object, a new caps object will
275  * be returned. The caller's reference on @caps will be removed, and instead the
276  * caller will own a reference to the returned object.
277  *
278  * In short, this function unrefs the caps in the argument and refs the caps
279  * that it returns. Don't access the argument after calling this function. See
280  * also: gst_caps_ref().
281  *
282  * Returns: (transfer full): a writable caps which may or may not be the
283  *     same as @caps
284  */
285 #define         gst_caps_make_writable(caps)   GST_CAPS_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (caps)))
286
287 /**
288  * gst_caps_replace:
289  * @ocaps: (inout) (transfer full): pointer to a pointer to a #GstCaps to be
290  *     replaced.
291  * @ncaps: (transfer none) (allow-none): pointer to a #GstCaps that will
292  *     replace the caps pointed to by @ocaps.
293  *
294  * Modifies a pointer to a #GstCaps to point to a different #GstCaps. The
295  * modification is done atomically (so this is useful for ensuring thread safety
296  * in some cases), and the reference counts are updated appropriately (the old
297  * caps is unreffed, the new is reffed).
298  *
299  * Either @ncaps or the #GstCaps pointed to by @ocaps may be NULL.
300  */
301 #define         gst_caps_replace(ocaps,ncaps) \
302 G_STMT_START {                                                                \
303   GstCaps **___ocapsaddr = (GstCaps **)(ocaps);         \
304   gst_mini_object_replace ((GstMiniObject **)___ocapsaddr, \
305       GST_MINI_OBJECT_CAST (ncaps));                       \
306 } G_STMT_END
307
308 /**
309  * GstCaps:
310  * @mini_object: the parent type
311  *
312  * Object describing media types.
313  */
314 struct _GstCaps {
315   GstMiniObject mini_object;
316
317   /*< private >*/
318   gpointer     priv;
319 };
320
321 /**
322  * GstStaticCaps:
323  * @caps: the cached #GstCaps
324  * @string: a string describing a caps
325  *
326  * Datastructure to initialize #GstCaps from a string description usually
327  * used in conjunction with GST_STATIC_CAPS() and gst_static_caps_get() to
328  * instantiate a #GstCaps.
329  */
330 struct _GstStaticCaps {
331   /*< public >*/
332   GstCaps caps;
333   const char *string;
334
335   /*< private >*/
336   gpointer _gst_reserved[GST_PADDING];
337 };
338
339 GType             gst_caps_get_type                (void);
340
341 GstCaps *         gst_caps_new_empty               (void);
342 GstCaps *         gst_caps_new_any                 (void);
343 GstCaps *         gst_caps_new_empty_simple        (const char    *media_type) G_GNUC_WARN_UNUSED_RESULT;
344 GstCaps *         gst_caps_new_simple              (const char    *media_type,
345                                                     const char    *fieldname,
346                                                     ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
347 GstCaps *         gst_caps_new_full                (GstStructure  *struct1,
348                                                     ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
349 GstCaps *         gst_caps_new_full_valist         (GstStructure  *structure,
350                                                     va_list        var_args) G_GNUC_WARN_UNUSED_RESULT;
351
352 GType             gst_static_caps_get_type         (void);
353 GstCaps *         gst_static_caps_get              (GstStaticCaps *static_caps);
354 void              gst_static_caps_cleanup          (GstStaticCaps *static_caps);
355
356 /* manipulation */
357 void              gst_caps_append                  (GstCaps       *caps1,
358                                                     GstCaps       *caps2);
359 void              gst_caps_merge                   (GstCaps       *caps1,
360                                                     GstCaps       *caps2);
361 void              gst_caps_append_structure        (GstCaps       *caps,
362                                                     GstStructure  *structure);
363 void              gst_caps_remove_structure        (GstCaps       *caps, guint idx);
364 void              gst_caps_merge_structure         (GstCaps       *caps,
365                                                     GstStructure  *structure);
366 guint             gst_caps_get_size                (const GstCaps *caps);
367 GstStructure *    gst_caps_get_structure           (const GstCaps *caps,
368                                                     guint          index);
369 GstStructure *    gst_caps_steal_structure         (GstCaps *caps,
370                                                     guint          index) G_GNUC_WARN_UNUSED_RESULT;
371 GstCaps *         gst_caps_copy_nth                (const GstCaps *caps, guint nth) G_GNUC_WARN_UNUSED_RESULT;
372 void              gst_caps_truncate                (GstCaps       *caps);
373 void              gst_caps_set_value               (GstCaps       *caps,
374                                                     const char    *field,
375                                                     const GValue  *value);
376 void              gst_caps_set_simple              (GstCaps       *caps,
377                                                     const char    *field, ...) G_GNUC_NULL_TERMINATED;
378 void              gst_caps_set_simple_valist       (GstCaps       *caps,
379                                                     const char    *field,
380                                                     va_list        varargs);
381
382 /* tests */
383 gboolean          gst_caps_is_any                  (const GstCaps *caps);
384 gboolean          gst_caps_is_empty                (const GstCaps *caps);
385 gboolean          gst_caps_is_fixed                (const GstCaps *caps);
386 gboolean          gst_caps_is_always_compatible    (const GstCaps *caps1,
387                                                     const GstCaps *caps2);
388 gboolean          gst_caps_is_subset               (const GstCaps *subset,
389                                                     const GstCaps *superset);
390 gboolean          gst_caps_is_subset_structure     (const GstCaps *caps,
391                                                     const GstStructure *structure);
392 gboolean          gst_caps_is_equal                (const GstCaps *caps1,
393                                                     const GstCaps *caps2);
394 gboolean          gst_caps_is_equal_fixed          (const GstCaps *caps1,
395                                                     const GstCaps *caps2);
396 gboolean          gst_caps_can_intersect           (const GstCaps * caps1,
397                                                     const GstCaps * caps2);
398 gboolean          gst_caps_is_strictly_equal       (const GstCaps *caps1,
399                                                     const GstCaps *caps2);
400
401
402 /* operations */
403 GstCaps *         gst_caps_intersect               (const GstCaps *caps1,
404                                                     const GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
405 GstCaps *         gst_caps_intersect_full          (const GstCaps *caps1,
406                                                     const GstCaps *caps2,
407                                                     GstCapsIntersectMode mode) G_GNUC_WARN_UNUSED_RESULT;
408 GstCaps *         gst_caps_subtract                (const GstCaps *minuend,
409                                                     const GstCaps *subtrahend) G_GNUC_WARN_UNUSED_RESULT;
410 GstCaps *         gst_caps_union                   (const GstCaps *caps1,
411                                                     const GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
412 GstCaps *         gst_caps_normalize               (const GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
413 gboolean          gst_caps_do_simplify             (GstCaps       *caps);
414
415 void              gst_caps_fixate                  (GstCaps       *caps);
416
417 /* utility */
418 gchar *           gst_caps_to_string               (const GstCaps *caps) G_GNUC_MALLOC;
419 GstCaps *         gst_caps_from_string             (const gchar   *string) G_GNUC_WARN_UNUSED_RESULT;
420
421 G_END_DECLS
422
423 #endif /* __GST_CAPS_H__ */