gstcaps.h 19 KB

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