g_type_init() is no longer required and deprecated in glib >= 2.35.0
[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 GST_EXPORT 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 typedef enum {
76   GST_CAPS_INTERSECT_ZIG_ZAG            =  0,
77   GST_CAPS_INTERSECT_FIRST              =  1
78 } GstCapsIntersectMode;
79
80 /**
81  * GST_CAPS_ANY:
82  *
83  * Means that the element/pad can output 'anything'. Useful for elements
84  * that output unknown media, such as filesrc. This macro returns a singleton and
85  * should not be unreffed.
86  */
87 #define GST_CAPS_ANY              _gst_caps_any
88 /**
89  * GST_CAPS_NONE:
90  *
91  * The opposite of %GST_CAPS_ANY: it means that the pad/element outputs an
92  * undefined media type that can not be detected. This macro returns a singleton
93  * and should not be unreffed.
94  */
95 #define GST_CAPS_NONE             _gst_caps_none
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   /* caps */ NULL, \
131   /* string */ string, \
132   GST_PADDING_INIT \
133 }
134
135 typedef struct _GstCaps GstCaps;
136 typedef struct _GstStaticCaps GstStaticCaps;
137
138 GST_EXPORT GstCaps * _gst_caps_any;
139 GST_EXPORT GstCaps * _gst_caps_none;
140 /**
141  * GST_CAPS_FLAGS:
142  * @caps: a #GstCaps.
143  *
144  * A flags word containing #GstCapsFlags flags set on this caps.
145  */
146 #define GST_CAPS_FLAGS(caps)                    GST_MINI_OBJECT_FLAGS(caps)
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_MINI_OBJECT_REFCOUNT(caps)
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)           GST_MINI_OBJECT_REFCOUNT_VALUE(caps)
163
164 /**
165  * GST_CAPS_FLAG_IS_SET:
166  * @caps: a #GstCaps.
167  * @flag: the #GstCapsFlags to check.
168  *
169  * Gives the status of a specific flag on a caps.
170  */
171 #define GST_CAPS_FLAG_IS_SET(caps,flag)        GST_MINI_OBJECT_FLAG_IS_SET (caps, flag)
172 /**
173  * GST_CAPS_FLAG_SET:
174  * @caps: a #GstCaps.
175  * @flag: the #GstCapsFlags to set.
176  *
177  * Sets a caps flag on a caps.
178  */
179 #define GST_CAPS_FLAG_SET(caps,flag)           GST_MINI_OBJECT_FLAG_SET (caps, flag)
180 /**
181  * GST_CAPS_FLAG_UNSET:
182  * @caps: a #GstCaps.
183  * @flag: the #GstCapsFlags to clear.
184  *
185  * Clears a caps flag.
186  */
187 #define GST_CAPS_FLAG_UNSET(caps,flag)         GST_MINI_OBJECT_FLAG_UNSET (caps, flag)
188
189 /* refcounting */
190 /**
191  * gst_caps_ref:
192  * @caps: the #GstCaps to reference
193  *
194  * Add a reference to a #GstCaps object.
195  *
196  * From this point on, until the caller calls gst_caps_unref() or
197  * gst_caps_make_writable(), it is guaranteed that the caps object will not
198  * change. This means its structures won't change, etc. To use a #GstCaps
199  * object, you must always have a refcount on it -- either the one made
200  * implicitly by e.g. gst_caps_new_simple(), or via taking one explicitly with
201  * this function.
202  *
203  * Returns: the same #GstCaps object.
204  */
205 #ifdef _FOOL_GTK_DOC_
206 G_INLINE_FUNC GstCaps * gst_caps_ref (GstCaps * caps);
207 #endif
208
209 static inline GstCaps *
210 gst_caps_ref (GstCaps * caps)
211 {
212   return (GstCaps *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (caps));
213 }
214
215 /**
216  * gst_caps_unref:
217  * @caps: a #GstCaps.
218  *
219  * Unref a #GstCaps and and free all its structures and the
220  * structures' values when the refcount reaches 0.
221  */
222 #ifdef _FOOL_GTK_DOC_
223 G_INLINE_FUNC void gst_caps_unref (GstCaps * caps);
224 #endif
225
226 static inline void
227 gst_caps_unref (GstCaps * caps)
228 {
229   gst_mini_object_unref (GST_MINI_OBJECT_CAST (caps));
230 }
231
232 /* copy caps */
233 /**
234  * gst_caps_copy:
235  * @caps: a #GstCaps.
236  *
237  * Creates a new #GstCaps as a copy of the old @caps. The new caps will have a
238  * refcount of 1, owned by the caller. The structures are copied as well.
239  *
240  * Note that this function is the semantic equivalent of a gst_caps_ref()
241  * followed by a gst_caps_make_writable(). If you only want to hold on to a
242  * reference to the data, you should use gst_caps_ref().
243  *
244  * When you are finished with the caps, call gst_caps_unref() on it.
245  *
246  * Returns: the new #GstCaps
247  */
248 #ifdef _FOOL_GTK_DOC_
249 G_INLINE_FUNC GstCaps * gst_caps_copy (const GstCaps * caps);
250 #endif
251
252 static inline GstCaps *
253 gst_caps_copy (const GstCaps * caps)
254 {
255   return GST_CAPS (gst_mini_object_copy (GST_MINI_OBJECT_CAST (caps)));
256 }
257
258 /**
259  * gst_caps_is_writable:
260  * @caps: a #GstCaps
261  *
262  * Tests if you can safely modify @caps. It is only safe to modify caps when
263  * there is only one owner of the caps - ie, the object is writable.
264  */
265 #define         gst_caps_is_writable(caps)     gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (caps))
266
267 /**
268  * gst_caps_make_writable:
269  * @caps: (transfer full): a #GstCaps
270  *
271  * Returns a writable copy of @caps.
272  *
273  * If there is only one reference count on @caps, the caller must be the owner,
274  * and so this function will return the caps object unchanged. If on the other
275  * hand there is more than one reference on the object, a new caps object will
276  * be returned. The caller's reference on @caps will be removed, and instead the
277  * caller will own a reference to the returned object.
278  *
279  * In short, this function unrefs the caps in the argument and refs the caps
280  * that it returns. Don't access the argument after calling this function. See
281  * also: gst_caps_ref().
282  *
283  * Returns: (transfer full): a writable caps which may or may not be the
284  *     same as @caps
285  */
286 #define         gst_caps_make_writable(caps)   GST_CAPS_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (caps)))
287
288 /**
289  * gst_caps_replace:
290  * @old_caps: (inout) (transfer full): pointer to a pointer to a #GstCaps to be
291  *     replaced.
292  * @new_caps: (transfer none) (allow-none): pointer to a #GstCaps that will
293  *     replace the caps pointed to by @ocaps.
294  *
295  * Modifies a pointer to a #GstCaps to point to a different #GstCaps. The
296  * modification is done atomically (so this is useful for ensuring thread safety
297  * in some cases), and the reference counts are updated appropriately (the old
298  * caps is unreffed, the new is reffed).
299  *
300  * Either @ncaps or the #GstCaps pointed to by @ocaps may be NULL.
301  *
302  * Returns: TRUE if @new_caps was different from @old_caps
303  */
304 #ifdef _FOOL_GTK_DOC_
305 G_INLINE_FUNC gboolean gst_caps_replace (GstCaps **old_caps, GstCaps *new_caps);
306 #endif
307
308 static inline gboolean
309 gst_caps_replace (GstCaps **old_caps, GstCaps *new_caps)
310 {
311     return gst_mini_object_replace ((GstMiniObject **) old_caps, (GstMiniObject *) new_caps);
312 }
313
314 /**
315  * gst_caps_take:
316  * @old_caps: (inout) (transfer full): pointer to a pointer to a #GstCaps to be
317  *     replaced.
318  * @new_caps: (transfer full) (allow-none): pointer to a #GstCaps that will
319  *     replace the caps pointed to by @ocaps.
320  *
321  * Modifies a pointer to a #GstCaps to point to a different #GstCaps. This
322  * function is similar to gst_caps_replace() except that it takes ownership
323  * of @new_caps.
324  *
325  * Returns: TRUE if @new_caps was different from @old_caps
326  */
327 #ifdef _FOOL_GTK_DOC_
328 G_INLINE_FUNC gboolean gst_caps_take (GstCaps **old_caps, GstCaps *new_caps);
329 #endif
330
331 static inline gboolean
332 gst_caps_take (GstCaps **old_caps, GstCaps *new_caps)
333 {
334     return gst_mini_object_take ((GstMiniObject **) old_caps, (GstMiniObject *) new_caps);
335 }
336
337 /**
338  * GstCaps:
339  * @mini_object: the parent type
340  *
341  * Object describing media types.
342  */
343 struct _GstCaps {
344   GstMiniObject mini_object;
345 };
346
347 /**
348  * GstStaticCaps:
349  * @caps: the cached #GstCaps
350  * @string: a string describing a caps
351  *
352  * Datastructure to initialize #GstCaps from a string description usually
353  * used in conjunction with GST_STATIC_CAPS() and gst_static_caps_get() to
354  * instantiate a #GstCaps.
355  */
356 struct _GstStaticCaps {
357   /*< public >*/
358   GstCaps *caps;
359   const char *string;
360
361   /*< private >*/
362   gpointer _gst_reserved[GST_PADDING];
363 };
364
365 GType             gst_caps_get_type                (void);
366
367 GstCaps *         gst_caps_new_empty               (void);
368 GstCaps *         gst_caps_new_any                 (void);
369 GstCaps *         gst_caps_new_empty_simple        (const char    *media_type) G_GNUC_WARN_UNUSED_RESULT;
370 GstCaps *         gst_caps_new_simple              (const char    *media_type,
371                                                     const char    *fieldname,
372                                                     ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
373 GstCaps *         gst_caps_new_full                (GstStructure  *struct1,
374                                                     ...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
375 GstCaps *         gst_caps_new_full_valist         (GstStructure  *structure,
376                                                     va_list        var_args) G_GNUC_WARN_UNUSED_RESULT;
377
378 GType             gst_static_caps_get_type         (void);
379 GstCaps *         gst_static_caps_get              (GstStaticCaps *static_caps);
380 void              gst_static_caps_cleanup          (GstStaticCaps *static_caps);
381
382 /* manipulation */
383 void              gst_caps_append                  (GstCaps       *caps1,
384                                                     GstCaps       *caps2);
385 void              gst_caps_append_structure        (GstCaps       *caps,
386                                                     GstStructure  *structure);
387 void              gst_caps_remove_structure        (GstCaps       *caps, guint idx);
388 GstCaps *         gst_caps_merge                   (GstCaps       *caps1,
389                                                     GstCaps       *caps2) G_GNUC_WARN_UNUSED_RESULT;
390 GstCaps *         gst_caps_merge_structure         (GstCaps       *caps,
391                                                     GstStructure  *structure) G_GNUC_WARN_UNUSED_RESULT;
392 guint             gst_caps_get_size                (const GstCaps *caps);
393 GstStructure *    gst_caps_get_structure           (const GstCaps *caps,
394                                                     guint          index);
395 GstStructure *    gst_caps_steal_structure         (GstCaps       *caps,
396                                                     guint          index) G_GNUC_WARN_UNUSED_RESULT;
397 GstCaps *         gst_caps_copy_nth                (const GstCaps *caps, guint nth) G_GNUC_WARN_UNUSED_RESULT;
398 GstCaps *         gst_caps_truncate                (GstCaps       *caps) G_GNUC_WARN_UNUSED_RESULT;
399 void              gst_caps_set_value               (GstCaps       *caps,
400                                                     const char    *field,
401                                                     const GValue  *value);
402 void              gst_caps_set_simple              (GstCaps       *caps,
403                                                     const char    *field, ...) G_GNUC_NULL_TERMINATED;
404 void              gst_caps_set_simple_valist       (GstCaps       *caps,
405                                                     const char    *field,
406                                                     va_list        varargs);
407
408 /* tests */
409 gboolean          gst_caps_is_any                  (const GstCaps *caps);
410 gboolean          gst_caps_is_empty                (const GstCaps *caps);
411 gboolean          gst_caps_is_fixed                (const GstCaps *caps);
412 gboolean          gst_caps_is_always_compatible    (const GstCaps *caps1,
413                                                     const GstCaps *caps2);
414 gboolean          gst_caps_is_subset               (const GstCaps *subset,
415                                                     const GstCaps *superset);
416 gboolean          gst_caps_is_subset_structure     (const GstCaps *caps,
417                                                     const GstStructure *structure);
418 gboolean          gst_caps_is_equal                (const GstCaps *caps1,
419                                                     const GstCaps *caps2);
420 gboolean          gst_caps_is_equal_fixed          (const GstCaps *caps1,
421                                                     const GstCaps *caps2);
422 gboolean          gst_caps_can_intersect           (const GstCaps * caps1,
423                                                     const GstCaps * caps2);
424 gboolean          gst_caps_is_strictly_equal       (const GstCaps *caps1,
425                                                     const GstCaps *caps2);
426
427
428 /* operations */
429 GstCaps *         gst_caps_intersect               (GstCaps *caps1,
430                                                     GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
431 GstCaps *         gst_caps_intersect_full          (GstCaps *caps1,
432                                                     GstCaps *caps2,
433                                                     GstCapsIntersectMode mode) G_GNUC_WARN_UNUSED_RESULT;
434 GstCaps *         gst_caps_subtract                (GstCaps *minuend,
435                                                     GstCaps *subtrahend) G_GNUC_WARN_UNUSED_RESULT;
436 GstCaps *         gst_caps_normalize               (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
437 GstCaps *         gst_caps_simplify                (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
438
439 GstCaps *         gst_caps_fixate                  (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
440
441 /* utility */
442 gchar *           gst_caps_to_string               (const GstCaps *caps) G_GNUC_MALLOC;
443 GstCaps *         gst_caps_from_string             (const gchar   *string) G_GNUC_WARN_UNUSED_RESULT;
444
445 G_END_DECLS
446
447 #endif /* __GST_CAPS_H__ */