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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef __GST_CAPS_H__
21 #define __GST_CAPS_H__
23 #include <gst/gstconfig.h>
24 #include <gst/gstminiobject.h>
25 #include <gst/gststructure.h>
26 #include <gst/glib-compat.h>
30 GST_EXPORT GType _gst_caps_type;
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))
37 #define GST_TYPE_STATIC_CAPS (gst_static_caps_get_type())
41 * @GST_CAPS_FLAG_ANY: Caps has no specific content, but can contain
44 * Extra flags for a caps.
47 GST_CAPS_FLAG_ANY = (GST_MINI_OBJECT_FLAG_LAST << 0)
51 * GstCapsIntersectMode:
52 * @GST_CAPS_INTERSECT_ZIG_ZAG : Zig-zags over both caps.
53 * @GST_CAPS_INTERSECT_FIRST : Keeps the first caps order.
55 * Modes of caps intersection
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:
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.
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.
78 GST_CAPS_INTERSECT_ZIG_ZAG = 0,
79 GST_CAPS_INTERSECT_FIRST = 1
80 } GstCapsIntersectMode;
85 * Means that the element/pad can output 'anything'. Useful for elements
86 * that output unknown media, such as filesrc. This macro returns a singleton and
87 * should not be unreffed.
89 #define GST_CAPS_ANY _gst_caps_any
93 * The opposite of %GST_CAPS_ANY: it means that the pad/element outputs an
94 * undefined media type that can not be detected. This macro returns a singleton
95 * and should not be unreffed.
97 #define GST_CAPS_NONE _gst_caps_none
100 * GST_STATIC_CAPS_ANY:
102 * Creates a new #GstCaps static caps that matches anything.
103 * This can be used in pad templates.
105 #define GST_STATIC_CAPS_ANY GST_STATIC_CAPS("ANY")
107 * GST_STATIC_CAPS_NONE:
109 * Creates a new #GstCaps static caps that matches nothing.
110 * This can be used in pad templates.
112 #define GST_STATIC_CAPS_NONE GST_STATIC_CAPS("NONE")
115 * GST_CAPS_IS_SIMPLE:
116 * @caps: the #GstCaps instance to check
118 * Convenience macro that checks if the number of structures in the given caps
121 #define GST_CAPS_IS_SIMPLE(caps) (gst_caps_get_size(caps) == 1)
125 * @string: the string describing the caps
127 * Creates a new #GstCaps static caps from an input string.
128 * This can be used in pad templates.
130 #define GST_STATIC_CAPS(string) \
132 /* miniobject */ { { 0, 0, 0, 0, NULL, NULL, NULL, 0, NULL }, \
134 /* string */ string, \
138 typedef struct _GstCaps GstCaps;
139 typedef struct _GstStaticCaps GstStaticCaps;
141 GST_EXPORT GstCaps * _gst_caps_any;
142 GST_EXPORT GstCaps * _gst_caps_none;
147 * A flags word containing #GstCapsFlags flags set on this caps.
149 #define GST_CAPS_FLAGS(caps) GST_MINI_OBJECT_FLAGS(caps)
156 * Get access to the reference count field of the caps
158 #define GST_CAPS_REFCOUNT(caps) GST_MINI_OBJECT_REFCOUNT(caps)
160 * GST_CAPS_REFCOUNT_VALUE:
163 * Get the reference count value of the caps.
165 #define GST_CAPS_REFCOUNT_VALUE(caps) GST_MINI_OBJECT_REFCOUNT_VALUE(caps)
168 * GST_CAPS_FLAG_IS_SET:
170 * @flag: the #GstCapsFlags to check.
172 * Gives the status of a specific flag on a caps.
174 #define GST_CAPS_FLAG_IS_SET(caps,flag) GST_MINI_OBJECT_FLAG_IS_SET (caps, flag)
178 * @flag: the #GstCapsFlags to set.
180 * Sets a caps flag on a caps.
182 #define GST_CAPS_FLAG_SET(caps,flag) GST_MINI_OBJECT_FLAG_SET (caps, flag)
184 * GST_CAPS_FLAG_UNSET:
186 * @flag: the #GstCapsFlags to clear.
188 * Clears a caps flag.
190 #define GST_CAPS_FLAG_UNSET(caps,flag) GST_MINI_OBJECT_FLAG_UNSET (caps, flag)
195 * @caps: the #GstCaps to reference
197 * Add a reference to a #GstCaps object.
199 * From this point on, until the caller calls gst_caps_unref() or
200 * gst_caps_make_writable(), it is guaranteed that the caps object will not
201 * change. This means its structures won't change, etc. To use a #GstCaps
202 * object, you must always have a refcount on it -- either the one made
203 * implicitly by e.g. gst_caps_new_simple(), or via taking one explicitly with
206 * Returns: the same #GstCaps object.
208 #ifdef _FOOL_GTK_DOC_
209 G_INLINE_FUNC GstCaps * gst_caps_ref (GstCaps * caps);
212 static inline GstCaps *
213 gst_caps_ref (GstCaps * caps)
215 return (GstCaps *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (caps));
222 * Unref a #GstCaps and and free all its structures and the
223 * structures' values when the refcount reaches 0.
225 #ifdef _FOOL_GTK_DOC_
226 G_INLINE_FUNC void gst_caps_unref (GstCaps * caps);
230 gst_caps_unref (GstCaps * caps)
232 gst_mini_object_unref (GST_MINI_OBJECT_CAST (caps));
240 * Creates a new #GstCaps as a copy of the old @caps. The new caps will have a
241 * refcount of 1, owned by the caller. The structures are copied as well.
243 * Note that this function is the semantic equivalent of a gst_caps_ref()
244 * followed by a gst_caps_make_writable(). If you only want to hold on to a
245 * reference to the data, you should use gst_caps_ref().
247 * When you are finished with the caps, call gst_caps_unref() on it.
249 * Returns: the new #GstCaps
251 #ifdef _FOOL_GTK_DOC_
252 G_INLINE_FUNC GstCaps * gst_caps_copy (const GstCaps * caps);
255 static inline GstCaps *
256 gst_caps_copy (const GstCaps * caps)
258 return GST_CAPS (gst_mini_object_copy (GST_MINI_OBJECT_CAST (caps)));
262 * gst_caps_is_writable:
265 * Tests if you can safely modify @caps. It is only safe to modify caps when
266 * there is only one owner of the caps - ie, the refcount is 1.
268 #define gst_caps_is_writable(caps) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (caps))
271 * gst_caps_make_writable:
272 * @caps: (transfer full): a #GstCaps
274 * Returns a writable copy of @caps.
276 * If there is only one reference count on @caps, the caller must be the owner,
277 * and so this function will return the caps object unchanged. If on the other
278 * hand there is more than one reference on the object, a new caps object will
279 * be returned. The caller's reference on @caps will be removed, and instead the
280 * caller will own a reference to the returned object.
282 * In short, this function unrefs the caps in the argument and refs the caps
283 * that it returns. Don't access the argument after calling this function. See
284 * also: gst_caps_ref().
286 * Returns: (transfer full): a writable caps which may or may not be the
289 #define gst_caps_make_writable(caps) GST_CAPS_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (caps)))
293 * @old_caps: (inout) (transfer full): pointer to a pointer to a #GstCaps to be
295 * @new_caps: (transfer none) (allow-none): pointer to a #GstCaps that will
296 * replace the caps pointed to by @ocaps.
298 * Modifies a pointer to a #GstCaps to point to a different #GstCaps. The
299 * modification is done atomically (so this is useful for ensuring thread safety
300 * in some cases), and the reference counts are updated appropriately (the old
301 * caps is unreffed, the new is reffed).
303 * Either @ncaps or the #GstCaps pointed to by @ocaps may be NULL.
305 * Returns: TRUE if @new_caps was different from @old_caps
307 #ifdef _FOOL_GTK_DOC_
308 G_INLINE_FUNC gboolean gst_caps_replace (GstCaps **old_caps, GstCaps *new_caps);
311 static inline gboolean
312 gst_caps_replace (GstCaps **old_caps, GstCaps *new_caps)
314 return gst_mini_object_replace ((GstMiniObject **) old_caps, (GstMiniObject *) new_caps);
319 * @old_caps: (inout) (transfer full): pointer to a pointer to a #GstCaps to be
321 * @new_caps: (transfer full) (allow-none): pointer to a #GstCaps that will
322 * replace the caps pointed to by @ocaps.
324 * Modifies a pointer to a #GstCaps to point to a different #GstCaps. This
325 * function is similar to gst_caps_replace() except that it takes ownership
328 * Returns: TRUE if @new_caps was different from @old_caps
330 #ifdef _FOOL_GTK_DOC_
331 G_INLINE_FUNC gboolean gst_caps_take (GstCaps **old_caps, GstCaps *new_caps);
334 static inline gboolean
335 gst_caps_take (GstCaps **old_caps, GstCaps *new_caps)
337 return gst_mini_object_take ((GstMiniObject **) old_caps, (GstMiniObject *) new_caps);
342 * @mini_object: the parent type
344 * Object describing media types.
347 GstMiniObject mini_object;
355 * @caps: the cached #GstCaps
356 * @string: a string describing a caps
358 * Datastructure to initialize #GstCaps from a string description usually
359 * used in conjunction with GST_STATIC_CAPS() and gst_static_caps_get() to
360 * instantiate a #GstCaps.
362 struct _GstStaticCaps {
368 gpointer _gst_reserved[GST_PADDING];
371 GType gst_caps_get_type (void);
373 GstCaps * gst_caps_new_empty (void);
374 GstCaps * gst_caps_new_any (void);
375 GstCaps * gst_caps_new_empty_simple (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
376 GstCaps * gst_caps_new_simple (const char *media_type,
377 const char *fieldname,
378 ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
379 GstCaps * gst_caps_new_full (GstStructure *struct1,
380 ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
381 GstCaps * gst_caps_new_full_valist (GstStructure *structure,
382 va_list var_args) G_GNUC_WARN_UNUSED_RESULT;
384 GType gst_static_caps_get_type (void);
385 GstCaps * gst_static_caps_get (GstStaticCaps *static_caps);
386 void gst_static_caps_cleanup (GstStaticCaps *static_caps);
389 void gst_caps_append (GstCaps *caps1,
391 void gst_caps_merge (GstCaps *caps1,
393 void gst_caps_append_structure (GstCaps *caps,
394 GstStructure *structure);
395 void gst_caps_remove_structure (GstCaps *caps, guint idx);
396 void gst_caps_merge_structure (GstCaps *caps,
397 GstStructure *structure);
398 guint gst_caps_get_size (const GstCaps *caps);
399 GstStructure * gst_caps_get_structure (const GstCaps *caps,
401 GstStructure * gst_caps_steal_structure (GstCaps *caps,
402 guint index) G_GNUC_WARN_UNUSED_RESULT;
403 GstCaps * gst_caps_copy_nth (const GstCaps *caps, guint nth) G_GNUC_WARN_UNUSED_RESULT;
404 void gst_caps_truncate (GstCaps *caps);
405 void gst_caps_set_value (GstCaps *caps,
407 const GValue *value);
408 void gst_caps_set_simple (GstCaps *caps,
409 const char *field, ...) G_GNUC_NULL_TERMINATED;
410 void gst_caps_set_simple_valist (GstCaps *caps,
415 gboolean gst_caps_is_any (const GstCaps *caps);
416 gboolean gst_caps_is_empty (const GstCaps *caps);
417 gboolean gst_caps_is_fixed (const GstCaps *caps);
418 gboolean gst_caps_is_always_compatible (const GstCaps *caps1,
419 const GstCaps *caps2);
420 gboolean gst_caps_is_subset (const GstCaps *subset,
421 const GstCaps *superset);
422 gboolean gst_caps_is_subset_structure (const GstCaps *caps,
423 const GstStructure *structure);
424 gboolean gst_caps_is_equal (const GstCaps *caps1,
425 const GstCaps *caps2);
426 gboolean gst_caps_is_equal_fixed (const GstCaps *caps1,
427 const GstCaps *caps2);
428 gboolean gst_caps_can_intersect (const GstCaps * caps1,
429 const GstCaps * caps2);
430 gboolean gst_caps_is_strictly_equal (const GstCaps *caps1,
431 const GstCaps *caps2);
435 GstCaps * gst_caps_intersect (const GstCaps *caps1,
436 const GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
437 GstCaps * gst_caps_intersect_full (const GstCaps *caps1,
438 const GstCaps *caps2,
439 GstCapsIntersectMode mode) G_GNUC_WARN_UNUSED_RESULT;
440 GstCaps * gst_caps_subtract (const GstCaps *minuend,
441 const GstCaps *subtrahend) G_GNUC_WARN_UNUSED_RESULT;
442 GstCaps * gst_caps_union (const GstCaps *caps1,
443 const GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
444 GstCaps * gst_caps_normalize (const GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
445 gboolean gst_caps_do_simplify (GstCaps *caps);
447 void gst_caps_fixate (GstCaps *caps);
450 gchar * gst_caps_to_string (const GstCaps *caps) G_GNUC_MALLOC;
451 GstCaps * gst_caps_from_string (const gchar *string) G_GNUC_WARN_UNUSED_RESULT;
455 #endif /* __GST_CAPS_H__ */