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_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/gstcapsfeatures.h>
27 #include <gst/glib-compat.h>
31 GST_API GType _gst_caps_type;
33 #define GST_TYPE_CAPS (_gst_caps_type)
34 #define GST_IS_CAPS(obj) (GST_IS_MINI_OBJECT_TYPE((obj), GST_TYPE_CAPS))
35 #define GST_CAPS_CAST(obj) ((GstCaps*)(obj))
36 #define GST_CAPS(obj) (GST_CAPS_CAST(obj))
38 #define GST_TYPE_STATIC_CAPS (gst_static_caps_get_type())
42 * @GST_CAPS_FLAG_ANY: Caps has no specific content, but can contain
45 * Extra flags for a caps.
48 GST_CAPS_FLAG_ANY = (GST_MINI_OBJECT_FLAG_LAST << 0)
52 * GstCapsIntersectMode:
53 * @GST_CAPS_INTERSECT_ZIG_ZAG : Zig-zags over both caps.
54 * @GST_CAPS_INTERSECT_FIRST : Keeps the first caps order.
56 * Modes of caps intersection
58 * @GST_CAPS_INTERSECT_ZIG_ZAG tries to preserve overall order of both caps
59 * by iterating on the caps' structures as the following matrix shows:
67 * Used when there is no explicit precedence of one caps over the other. e.g.
68 * tee's sink pad getcaps function, it will probe its src pad peers' for their
69 * caps and intersect them with this mode.
71 * @GST_CAPS_INTERSECT_FIRST is useful when an element wants to preserve
72 * another element's caps priority order when intersecting with its own caps.
73 * Example: If caps1 is [A, B, C] and caps2 is [E, B, D, A], the result
74 * would be [A, B], maintaining the first caps priority on the intersection.
77 GST_CAPS_INTERSECT_ZIG_ZAG = 0,
78 GST_CAPS_INTERSECT_FIRST = 1
79 } GstCapsIntersectMode;
84 * Means that the element/pad can output 'anything'. Useful for elements
85 * that output unknown media, such as filesrc. This macro returns a singleton and
86 * should not be unreffed.
88 #define GST_CAPS_ANY _gst_caps_any
92 * The opposite of %GST_CAPS_ANY: it means that the pad/element outputs an
93 * undefined media type that can not be detected. This macro returns a singleton
94 * and should not be unreffed.
96 #define GST_CAPS_NONE _gst_caps_none
99 * GST_STATIC_CAPS_ANY:
101 * Creates a new #GstCaps static caps that matches anything.
102 * This can be used in pad templates.
104 #define GST_STATIC_CAPS_ANY GST_STATIC_CAPS("ANY")
106 * GST_STATIC_CAPS_NONE:
108 * Creates a new #GstCaps static caps that matches nothing.
109 * This can be used in pad templates.
111 #define GST_STATIC_CAPS_NONE GST_STATIC_CAPS("NONE")
114 * GST_CAPS_IS_SIMPLE:
115 * @caps: the #GstCaps instance to check
117 * Convenience macro that checks if the number of structures in the given caps
120 #define GST_CAPS_IS_SIMPLE(caps) (gst_caps_get_size(caps) == 1)
124 * @string: the string describing the caps
126 * Creates a new #GstCaps static caps from an input string.
127 * This can be used in pad templates.
129 #define GST_STATIC_CAPS(string) \
132 /* string */ string, \
136 typedef struct _GstCaps GstCaps;
137 typedef struct _GstStaticCaps GstStaticCaps;
139 GST_API GstCaps * _gst_caps_any;
141 GST_API GstCaps * _gst_caps_none;
146 * A flags word containing #GstCapsFlags flags set on this caps.
148 #define GST_CAPS_FLAGS(caps) GST_MINI_OBJECT_FLAGS(caps)
155 * Get access to the reference count field of the caps
157 #define GST_CAPS_REFCOUNT(caps) GST_MINI_OBJECT_REFCOUNT(caps)
159 * GST_CAPS_REFCOUNT_VALUE:
162 * Get the reference count value of the caps.
164 #define GST_CAPS_REFCOUNT_VALUE(caps) GST_MINI_OBJECT_REFCOUNT_VALUE(caps)
167 * GST_CAPS_FLAG_IS_SET:
169 * @flag: the #GstCapsFlags to check.
171 * Gives the status of a specific flag on a caps.
173 #define GST_CAPS_FLAG_IS_SET(caps,flag) GST_MINI_OBJECT_FLAG_IS_SET (caps, flag)
177 * @flag: the #GstCapsFlags to set.
179 * Sets a caps flag on a caps.
181 #define GST_CAPS_FLAG_SET(caps,flag) GST_MINI_OBJECT_FLAG_SET (caps, flag)
183 * GST_CAPS_FLAG_UNSET:
185 * @flag: the #GstCapsFlags to clear.
187 * Clears a caps flag.
189 #define GST_CAPS_FLAG_UNSET(caps,flag) GST_MINI_OBJECT_FLAG_UNSET (caps, flag)
194 * @caps: the #GstCaps to reference
196 * Add a reference to a #GstCaps object.
198 * From this point on, until the caller calls gst_caps_unref() or
199 * gst_caps_make_writable(), it is guaranteed that the caps object will not
200 * change. This means its structures won't change, etc. To use a #GstCaps
201 * object, you must always have a refcount on it -- either the one made
202 * implicitly by e.g. gst_caps_new_simple(), or via taking one explicitly with
205 * Returns: the same #GstCaps object.
207 static inline GstCaps *
208 gst_caps_ref (GstCaps * caps)
210 return (GstCaps *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (caps));
217 * Unref a #GstCaps and and free all its structures and the
218 * structures' values when the refcount reaches 0.
221 gst_caps_unref (GstCaps * caps)
223 gst_mini_object_unref (GST_MINI_OBJECT_CAST (caps));
227 * gst_clear_caps: (skip)
228 * @caps_ptr: a pointer to a #GstCaps reference
230 * Clears a reference to a #GstCaps.
232 * @caps_ptr must not be %NULL.
234 * If the reference is %NULL then this function does nothing. Otherwise, the
235 * reference count of the caps is decreased and the pointer is set to %NULL.
240 gst_clear_caps (GstCaps ** caps_ptr)
242 gst_clear_mini_object ((GstMiniObject **) caps_ptr);
247 GstCaps * gst_caps_copy (const GstCaps * caps);
249 #define gst_caps_copy(caps) GST_CAPS (gst_mini_object_copy (GST_MINI_OBJECT_CAST (caps)))
252 * gst_caps_is_writable:
255 * Tests if you can safely modify @caps. It is only safe to modify caps when
256 * there is only one owner of the caps - ie, the object is writable.
258 #define gst_caps_is_writable(caps) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (caps))
261 * gst_caps_make_writable:
262 * @caps: (transfer full): a #GstCaps
264 * Returns a writable copy of @caps.
266 * If there is only one reference count on @caps, the caller must be the owner,
267 * and so this function will return the caps object unchanged. If on the other
268 * hand there is more than one reference on the object, a new caps object will
269 * be returned. The caller's reference on @caps will be removed, and instead the
270 * caller will own a reference to the returned object.
272 * In short, this function unrefs the caps in the argument and refs the caps
273 * that it returns. Don't access the argument after calling this function. See
274 * also: gst_caps_ref().
276 * Returns: (transfer full): a writable caps which may or may not be the
279 #define gst_caps_make_writable(caps) GST_CAPS_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (caps)))
283 * @old_caps: (inout) (transfer full) (nullable): pointer to a pointer
284 * to a #GstCaps to be replaced.
285 * @new_caps: (transfer none) (allow-none): pointer to a #GstCaps that will
286 * replace the caps pointed to by @old_caps.
288 * Modifies a pointer to a #GstCaps to point to a different #GstCaps. The
289 * modification is done atomically (so this is useful for ensuring thread safety
290 * in some cases), and the reference counts are updated appropriately (the old
291 * caps is unreffed, the new is reffed).
293 * Either @new_caps or the #GstCaps pointed to by @old_caps may be %NULL.
295 * Returns: %TRUE if @new_caps was different from @old_caps
297 static inline gboolean
298 gst_caps_replace (GstCaps **old_caps, GstCaps *new_caps)
300 return gst_mini_object_replace ((GstMiniObject **) old_caps, (GstMiniObject *) new_caps);
305 * @old_caps: (inout) (transfer full): pointer to a pointer to a #GstCaps to be
307 * @new_caps: (transfer full) (allow-none): pointer to a #GstCaps that will
308 * replace the caps pointed to by @old_caps.
310 * Modifies a pointer to a #GstCaps to point to a different #GstCaps. This
311 * function is similar to gst_caps_replace() except that it takes ownership
314 * Returns: %TRUE if @new_caps was different from @old_caps
316 static inline gboolean
317 gst_caps_take (GstCaps **old_caps, GstCaps *new_caps)
319 return gst_mini_object_take ((GstMiniObject **) old_caps, (GstMiniObject *) new_caps);
324 * @mini_object: the parent type
326 * Object describing media types.
329 GstMiniObject mini_object;
334 * @caps: the cached #GstCaps
335 * @string: a string describing a caps
337 * Datastructure to initialize #GstCaps from a string description usually
338 * used in conjunction with GST_STATIC_CAPS() and gst_static_caps_get() to
339 * instantiate a #GstCaps.
341 struct _GstStaticCaps {
347 gpointer _gst_reserved[GST_PADDING];
351 * GstCapsForeachFunc:
352 * @features: the #GstCapsFeatures
353 * @structure: the #GstStructure
354 * @user_data: user data
356 * A function that will be called in gst_caps_foreach(). The function may
357 * not modify @features or @structure.
359 * Returns: %TRUE if the foreach operation should continue, %FALSE if
360 * the foreach operation should stop with %FALSE.
364 typedef gboolean (*GstCapsForeachFunc) (GstCapsFeatures *features,
365 GstStructure *structure,
370 * @features: the #GstCapsFeatures
371 * @structure: the #GstStructure
372 * @user_data: user data
374 * A function that will be called in gst_caps_map_in_place(). The function
375 * may modify @features and @structure.
377 * Returns: %TRUE if the map operation should continue, %FALSE if
378 * the map operation should stop with %FALSE.
380 typedef gboolean (*GstCapsMapFunc) (GstCapsFeatures *features,
381 GstStructure *structure,
385 * GstCapsFilterMapFunc:
386 * @features: the #GstCapsFeatures
387 * @structure: the #GstStructure
388 * @user_data: user data
390 * A function that will be called in gst_caps_filter_and_map_in_place().
391 * The function may modify @features and @structure, and both will be
392 * removed from the caps if %FALSE is returned.
394 * Returns: %TRUE if the features and structure should be preserved,
395 * %FALSE if it should be removed.
397 typedef gboolean (*GstCapsFilterMapFunc) (GstCapsFeatures *features,
398 GstStructure *structure,
403 GType gst_caps_get_type (void);
406 GstCaps * gst_caps_new_empty (void);
409 GstCaps * gst_caps_new_any (void);
412 GstCaps * gst_caps_new_empty_simple (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
415 GstCaps * gst_caps_new_simple (const char *media_type,
416 const char *fieldname,
417 ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
419 GstCaps * gst_caps_new_full (GstStructure *struct1,
420 ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
422 GstCaps * gst_caps_new_full_valist (GstStructure *structure,
423 va_list var_args) G_GNUC_WARN_UNUSED_RESULT;
425 GType gst_static_caps_get_type (void);
428 GstCaps * gst_static_caps_get (GstStaticCaps *static_caps);
431 void gst_static_caps_cleanup (GstStaticCaps *static_caps);
436 void gst_caps_append (GstCaps *caps1,
439 void gst_caps_append_structure (GstCaps *caps,
440 GstStructure *structure);
442 void gst_caps_append_structure_full (GstCaps *caps,
443 GstStructure *structure,
444 GstCapsFeatures *features);
446 void gst_caps_remove_structure (GstCaps *caps, guint idx);
449 GstCaps * gst_caps_merge (GstCaps *caps1,
450 GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
452 GstCaps * gst_caps_merge_structure (GstCaps *caps,
453 GstStructure *structure) G_GNUC_WARN_UNUSED_RESULT;
455 GstCaps * gst_caps_merge_structure_full (GstCaps *caps,
456 GstStructure *structure,
457 GstCapsFeatures *features) G_GNUC_WARN_UNUSED_RESULT;
460 guint gst_caps_get_size (const GstCaps *caps);
463 GstStructure * gst_caps_get_structure (const GstCaps *caps,
466 GstStructure * gst_caps_steal_structure (GstCaps *caps,
467 guint index) G_GNUC_WARN_UNUSED_RESULT;
469 void gst_caps_set_features (GstCaps *caps,
471 GstCapsFeatures * features);
473 GstCapsFeatures * gst_caps_get_features (const GstCaps *caps,
476 GstCaps * gst_caps_copy_nth (const GstCaps *caps, guint nth) G_GNUC_WARN_UNUSED_RESULT;
479 GstCaps * gst_caps_truncate (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
482 void gst_caps_set_value (GstCaps *caps,
484 const GValue *value);
486 void gst_caps_set_simple (GstCaps *caps,
487 const char *field, ...) G_GNUC_NULL_TERMINATED;
489 void gst_caps_set_simple_valist (GstCaps *caps,
493 gboolean gst_caps_foreach (const GstCaps *caps,
494 GstCapsForeachFunc func,
497 gboolean gst_caps_map_in_place (GstCaps *caps,
501 void gst_caps_filter_and_map_in_place (GstCaps *caps,
502 GstCapsFilterMapFunc func,
508 gboolean gst_caps_is_any (const GstCaps *caps);
511 gboolean gst_caps_is_empty (const GstCaps *caps);
514 gboolean gst_caps_is_fixed (const GstCaps *caps);
517 gboolean gst_caps_is_always_compatible (const GstCaps *caps1,
518 const GstCaps *caps2);
520 gboolean gst_caps_is_subset (const GstCaps *subset,
521 const GstCaps *superset);
523 gboolean gst_caps_is_subset_structure (const GstCaps *caps,
524 const GstStructure *structure);
526 gboolean gst_caps_is_subset_structure_full (const GstCaps *caps,
527 const GstStructure *structure,
528 const GstCapsFeatures *features);
530 gboolean gst_caps_is_equal (const GstCaps *caps1,
531 const GstCaps *caps2);
533 gboolean gst_caps_is_equal_fixed (const GstCaps *caps1,
534 const GstCaps *caps2);
536 gboolean gst_caps_can_intersect (const GstCaps * caps1,
537 const GstCaps * caps2);
539 gboolean gst_caps_is_strictly_equal (const GstCaps *caps1,
540 const GstCaps *caps2);
546 GstCaps * gst_caps_intersect (GstCaps *caps1,
547 GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
549 GstCaps * gst_caps_intersect_full (GstCaps *caps1,
551 GstCapsIntersectMode mode) G_GNUC_WARN_UNUSED_RESULT;
553 GstCaps * gst_caps_subtract (GstCaps *minuend,
554 GstCaps *subtrahend) G_GNUC_WARN_UNUSED_RESULT;
556 GstCaps * gst_caps_normalize (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
559 GstCaps * gst_caps_simplify (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
562 GstCaps * gst_caps_fixate (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
567 gchar * gst_caps_to_string (const GstCaps *caps) G_GNUC_MALLOC;
570 GstCaps * gst_caps_from_string (const gchar *string) G_GNUC_WARN_UNUSED_RESULT;
572 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
573 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstCaps, gst_caps_unref)
578 #endif /* __GST_CAPS_H__ */