gstvalue.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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_VALUE_H__
  20. #define __GST_VALUE_H__
  21. #include <gst/gstconfig.h>
  22. #include <gst/gstcaps.h>
  23. #include <gst/gststructure.h>
  24. #include <gst/gstcapsfeatures.h>
  25. G_BEGIN_DECLS
  26. /**
  27. * GST_MAKE_FOURCC:
  28. * @a: the first character
  29. * @b: the second character
  30. * @c: the third character
  31. * @d: the fourth character
  32. *
  33. * Transform four characters into a #guint32 fourcc value with host
  34. * endianness.
  35. * <informalexample>
  36. * <programlisting>
  37. * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
  38. * </programlisting>
  39. * </informalexample>
  40. */
  41. #define GST_MAKE_FOURCC(a,b,c,d) ((guint32)((a)|(b)<<8|(c)<<16|(d)<<24))
  42. /**
  43. * GST_STR_FOURCC:
  44. * @f: a string with at least four characters
  45. *
  46. * Transform an input string into a #guint32 fourcc value with host
  47. * endianness.
  48. * Caller is responsible for ensuring the input string consists of at least
  49. * four characters.
  50. * <informalexample>
  51. * <programlisting>
  52. * guint32 fourcc = GST_STR_FOURCC ("MJPG");
  53. * </programlisting>
  54. * </informalexample>
  55. */
  56. #define GST_STR_FOURCC(f) ((guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)))
  57. /**
  58. * GST_FOURCC_FORMAT:
  59. *
  60. * Can be used together with #GST_FOURCC_ARGS to properly output a
  61. * #guint32 fourcc value in a printf()-style text message.
  62. * <informalexample>
  63. * <programlisting>
  64. * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
  65. * </programlisting>
  66. * </informalexample>
  67. */
  68. #define GST_FOURCC_FORMAT "c%c%c%c"
  69. /**
  70. * GST_FOURCC_ARGS:
  71. * @fourcc: a #guint32 fourcc value to output
  72. *
  73. * Can be used together with #GST_FOURCC_FORMAT to properly output a
  74. * #guint32 fourcc value in a printf()-style text message.
  75. */
  76. #define __GST_PRINT_CHAR(c) \
  77. g_ascii_isprint(c) ? (c) : '.'
  78. #define GST_FOURCC_ARGS(fourcc) \
  79. __GST_PRINT_CHAR((fourcc) & 0xff), \
  80. __GST_PRINT_CHAR(((fourcc) >> 8) & 0xff), \
  81. __GST_PRINT_CHAR(((fourcc) >> 16) & 0xff), \
  82. __GST_PRINT_CHAR(((fourcc) >> 24) & 0xff)
  83. /**
  84. * GST_VALUE_HOLDS_INT_RANGE:
  85. * @x: the #GValue to check
  86. *
  87. * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
  88. */
  89. #define GST_VALUE_HOLDS_INT_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int_range_type)
  90. /**
  91. * GST_VALUE_HOLDS_INT64_RANGE:
  92. * @x: the #GValue to check
  93. *
  94. * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
  95. */
  96. #define GST_VALUE_HOLDS_INT64_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int64_range_type)
  97. /**
  98. * GST_VALUE_HOLDS_DOUBLE_RANGE:
  99. * @x: the #GValue to check
  100. *
  101. * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
  102. */
  103. #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_double_range_type)
  104. /**
  105. * GST_VALUE_HOLDS_FRACTION_RANGE:
  106. * @x: the #GValue to check
  107. *
  108. * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
  109. */
  110. #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_range_type)
  111. /**
  112. * GST_VALUE_HOLDS_LIST:
  113. * @x: the #GValue to check
  114. *
  115. * Checks if the given #GValue contains a #GST_TYPE_LIST value.
  116. */
  117. #define GST_VALUE_HOLDS_LIST(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_list_type)
  118. /**
  119. * GST_VALUE_HOLDS_ARRAY:
  120. * @x: the #GValue to check
  121. *
  122. * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
  123. */
  124. #define GST_VALUE_HOLDS_ARRAY(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_array_type)
  125. /**
  126. * GST_VALUE_HOLDS_CAPS:
  127. * @x: the #GValue to check
  128. *
  129. * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
  130. */
  131. #define GST_VALUE_HOLDS_CAPS(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_caps_type)
  132. /**
  133. * GST_VALUE_HOLDS_STRUCTURE:
  134. * @x: the #GValue to check
  135. *
  136. * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
  137. */
  138. #define GST_VALUE_HOLDS_STRUCTURE(x) (G_VALUE_HOLDS((x), _gst_structure_type))
  139. /**
  140. * GST_VALUE_HOLDS_CAPS_FEATURES:
  141. * @x: the #GValue to check
  142. *
  143. * Checks if the given #GValue contains a #GST_TYPE_CAPS_FEATURES value.
  144. */
  145. #define GST_VALUE_HOLDS_CAPS_FEATURES(x) (G_VALUE_HOLDS((x), _gst_caps_features_type))
  146. /**
  147. * GST_VALUE_HOLDS_BUFFER:
  148. * @x: the #GValue to check
  149. *
  150. * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
  151. */
  152. #define GST_VALUE_HOLDS_BUFFER(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_buffer_type)
  153. /**
  154. * GST_VALUE_HOLDS_SAMPLE:
  155. * @x: the #GValue to check
  156. *
  157. * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
  158. */
  159. #define GST_VALUE_HOLDS_SAMPLE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_sample_type)
  160. /**
  161. * GST_VALUE_HOLDS_FRACTION:
  162. * @x: the #GValue to check
  163. *
  164. * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
  165. */
  166. #define GST_VALUE_HOLDS_FRACTION(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_type)
  167. /**
  168. * GST_VALUE_HOLDS_DATE_TIME:
  169. * @x: the #GValue to check
  170. *
  171. * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
  172. */
  173. #define GST_VALUE_HOLDS_DATE_TIME(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_date_time_type)
  174. /**
  175. * GST_VALUE_HOLDS_BITMASK:
  176. * @x: the #GValue to check
  177. *
  178. * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
  179. */
  180. #define GST_VALUE_HOLDS_BITMASK(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_bitmask_type)
  181. /**
  182. * GST_VALUE_HOLDS_FLAG_SET:
  183. * @x: the #GValue to check
  184. *
  185. * Checks if the given #GValue contains a #GST_TYPE_FLAG_SET value.
  186. *
  187. * Since: 1.6
  188. */
  189. #define GST_VALUE_HOLDS_FLAG_SET(x) (G_TYPE_CHECK_VALUE_TYPE ((x), GST_TYPE_FLAG_SET))
  190. /*
  191. * GST_FLAG_SET_MASK_EXACT:
  192. * A mask value with all bits set, for use as a
  193. * #GstFlagSet mask where all flag bits must match
  194. * exactly
  195. *
  196. * Since: 1.6
  197. */
  198. #define GST_FLAG_SET_MASK_EXACT ((guint)(-1))
  199. GST_EXPORT GType _gst_int_range_type;
  200. /**
  201. * GST_TYPE_INT_RANGE:
  202. *
  203. * a #GValue type that represents an integer range
  204. *
  205. * Returns: the #GType of GstIntRange
  206. */
  207. #define GST_TYPE_INT_RANGE (_gst_int_range_type)
  208. GST_EXPORT GType _gst_int64_range_type;
  209. /**
  210. * GST_TYPE_INT64_RANGE:
  211. *
  212. * a #GValue type that represents an #gint64 range
  213. *
  214. * Returns: the #GType of GstInt64Range
  215. */
  216. #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
  217. GST_EXPORT GType _gst_double_range_type;
  218. /**
  219. * GST_TYPE_DOUBLE_RANGE:
  220. *
  221. * a #GValue type that represents a floating point range with double precision
  222. *
  223. * Returns: the #GType of GstIntRange
  224. */
  225. #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
  226. GST_EXPORT GType _gst_fraction_range_type;
  227. /**
  228. * GST_TYPE_FRACTION_RANGE:
  229. *
  230. * a #GValue type that represents a GstFraction range
  231. *
  232. * Returns: the #GType of GstFractionRange
  233. */
  234. #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
  235. GST_EXPORT GType _gst_value_list_type;
  236. /**
  237. * GST_TYPE_LIST:
  238. *
  239. * a #GValue type that represents an unordered list of #GValue values. This
  240. * is used for example to express a list of possible values for a field in
  241. * a caps structure, like a list of possible sample rates, of which only one
  242. * will be chosen in the end. This means that all values in the list are
  243. * meaningful on their own.
  244. *
  245. * Returns: the #GType of GstValueList (which is not explicitly typed)
  246. */
  247. #define GST_TYPE_LIST (_gst_value_list_type)
  248. GST_EXPORT GType _gst_value_array_type;
  249. /**
  250. * GST_TYPE_ARRAY:
  251. *
  252. * a #GValue type that represents an ordered list of #GValue values. This is
  253. * used to express a set of values that is meaningful only in their specific
  254. * combination and order of values. Each value on its own is not particularly
  255. * meaningful, only the ordered array in its entirety is meaningful. This is
  256. * used for example to express channel layouts for multichannel audio where
  257. * each channel needs to be mapped to a position in the room.
  258. *
  259. * Returns: the #GType of GstArrayList (which is not explicitly typed)
  260. */
  261. #define GST_TYPE_ARRAY (_gst_value_array_type)
  262. GST_EXPORT GType _gst_fraction_type;
  263. /**
  264. * GST_TYPE_FRACTION:
  265. *
  266. * a #GValue type that represents a fraction of an integer numerator over
  267. * an integer denominator
  268. *
  269. * Returns: the #GType of GstFraction (which is not explicitly typed)
  270. */
  271. #define GST_TYPE_FRACTION (_gst_fraction_type)
  272. GST_EXPORT GType _gst_bitmask_type;
  273. /**
  274. * GST_TYPE_BITMASK:
  275. *
  276. * a #GValue type that represents a 64-bit bitmask.
  277. *
  278. * Returns: the #GType of GstBitmask (which is not explicitly typed)
  279. */
  280. #define GST_TYPE_BITMASK (_gst_bitmask_type)
  281. GST_EXPORT GType _gst_flagset_type;
  282. /**
  283. * GST_TYPE_FLAG_SET:
  284. *
  285. * a #GValue type that represents a 32-bit flag bitfield, with 32-bit
  286. * mask indicating which of the bits in the field are explicitly set.
  287. * Useful for negotiation.
  288. *
  289. * Returns: the #GType of GstFlags (which is not explicitly typed)
  290. *
  291. * Since: 1.6
  292. */
  293. #define GST_TYPE_FLAG_SET (_gst_flagset_type)
  294. /**
  295. * GST_TYPE_G_THREAD:
  296. *
  297. * a boxed #GValue type for #GThread that represents a thread.
  298. *
  299. * Returns: the #GType of GstGThread
  300. */
  301. #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
  302. /**
  303. * GST_VALUE_LESS_THAN:
  304. *
  305. * Indicates that the first value provided to a comparison function
  306. * (gst_value_compare()) is lesser than the second one.
  307. */
  308. #define GST_VALUE_LESS_THAN (-1)
  309. /**
  310. * GST_VALUE_EQUAL:
  311. *
  312. * Indicates that the first value provided to a comparison function
  313. * (gst_value_compare()) is equal to the second one.
  314. */
  315. #define GST_VALUE_EQUAL 0
  316. /**
  317. * GST_VALUE_GREATER_THAN:
  318. *
  319. * Indicates that the first value provided to a comparison function
  320. * (gst_value_compare()) is greater than the second one.
  321. */
  322. #define GST_VALUE_GREATER_THAN 1
  323. /**
  324. * GST_VALUE_UNORDERED:
  325. *
  326. * Indicates that the comparison function (gst_value_compare()) can not
  327. * determine a order for the two provided values.
  328. */
  329. #define GST_VALUE_UNORDERED 2
  330. /**
  331. * GstValueCompareFunc:
  332. * @value1: first value for comparison
  333. * @value2: second value for comparison
  334. *
  335. * Used together with gst_value_compare() to compare #GValue items.
  336. *
  337. * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
  338. * or GST_VALUE_UNORDERED
  339. */
  340. typedef gint (* GstValueCompareFunc) (const GValue *value1,
  341. const GValue *value2);
  342. /**
  343. * GstValueSerializeFunc:
  344. * @value1: a #GValue
  345. *
  346. * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
  347. *
  348. * Free-function: g_free
  349. *
  350. * Returns: (transfer full): the string representation of the value
  351. */
  352. typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
  353. /**
  354. * GstValueDeserializeFunc:
  355. * @dest: a #GValue
  356. * @s: a string
  357. *
  358. * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
  359. *
  360. * Returns: %TRUE for success
  361. */
  362. typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
  363. const gchar *s);
  364. typedef struct _GstValueTable GstValueTable;
  365. /**
  366. * GstValueTable:
  367. * @type: a #GType
  368. * @compare: a #GstValueCompareFunc
  369. * @serialize: a #GstValueSerializeFunc
  370. * @deserialize: a #GstValueDeserializeFunc
  371. *
  372. * VTable for the #GValue @type.
  373. */
  374. struct _GstValueTable {
  375. GType type;
  376. GstValueCompareFunc compare;
  377. GstValueSerializeFunc serialize;
  378. GstValueDeserializeFunc deserialize;
  379. /*< private >*/
  380. gpointer _gst_reserved [GST_PADDING];
  381. };
  382. GType gst_int_range_get_type (void);
  383. GType gst_int64_range_get_type (void);
  384. GType gst_double_range_get_type (void);
  385. GType gst_fraction_range_get_type (void);
  386. GType gst_fraction_get_type (void);
  387. GType gst_value_list_get_type (void);
  388. GType gst_value_array_get_type (void);
  389. GType gst_bitmask_get_type (void);
  390. GType gst_flagset_get_type (void);
  391. /* Hide this compatibility type from introspection */
  392. #ifndef __GI_SCANNER__
  393. GType gst_g_thread_get_type (void);
  394. #endif
  395. void gst_value_register (const GstValueTable *table);
  396. void gst_value_init_and_copy (GValue *dest,
  397. const GValue *src);
  398. gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
  399. gboolean gst_value_deserialize (GValue *dest,
  400. const gchar *src);
  401. /* list */
  402. void gst_value_list_append_value (GValue *value,
  403. const GValue *append_value);
  404. void gst_value_list_append_and_take_value (GValue *value,
  405. GValue *append_value);
  406. void gst_value_list_prepend_value (GValue *value,
  407. const GValue *prepend_value);
  408. void gst_value_list_concat (GValue *dest,
  409. const GValue *value1,
  410. const GValue *value2);
  411. void gst_value_list_merge (GValue *dest,
  412. const GValue *value1,
  413. const GValue *value2);
  414. guint gst_value_list_get_size (const GValue *value);
  415. const GValue * gst_value_list_get_value (const GValue *value,
  416. guint index);
  417. /* array */
  418. void gst_value_array_append_value (GValue *value,
  419. const GValue *append_value);
  420. void gst_value_array_append_and_take_value (GValue *value,
  421. GValue *append_value);
  422. void gst_value_array_prepend_value (GValue *value,
  423. const GValue *prepend_value);
  424. guint gst_value_array_get_size (const GValue *value);
  425. const GValue * gst_value_array_get_value (const GValue *value,
  426. guint index);
  427. /* int range */
  428. void gst_value_set_int_range (GValue *value,
  429. gint start,
  430. gint end);
  431. void gst_value_set_int_range_step (GValue *value,
  432. gint start,
  433. gint end,
  434. gint step);
  435. gint gst_value_get_int_range_min (const GValue *value);
  436. gint gst_value_get_int_range_max (const GValue *value);
  437. gint gst_value_get_int_range_step (const GValue *value);
  438. /* int64 range */
  439. void gst_value_set_int64_range (GValue *value,
  440. gint64 start,
  441. gint64 end);
  442. void gst_value_set_int64_range_step (GValue *value,
  443. gint64 start,
  444. gint64 end,
  445. gint64 step);
  446. gint64 gst_value_get_int64_range_min (const GValue *value);
  447. gint64 gst_value_get_int64_range_max (const GValue *value);
  448. gint64 gst_value_get_int64_range_step (const GValue *value);
  449. /* double range */
  450. void gst_value_set_double_range (GValue *value,
  451. gdouble start,
  452. gdouble end);
  453. gdouble gst_value_get_double_range_min (const GValue *value);
  454. gdouble gst_value_get_double_range_max (const GValue *value);
  455. /* caps */
  456. const GstCaps * gst_value_get_caps (const GValue *value);
  457. void gst_value_set_caps (GValue *value,
  458. const GstCaps *caps);
  459. /* structure */
  460. const GstStructure *
  461. gst_value_get_structure (const GValue *value);
  462. void gst_value_set_structure (GValue *value,
  463. const GstStructure *structure);
  464. /* caps features */
  465. const GstCapsFeatures *
  466. gst_value_get_caps_features (const GValue *value);
  467. void gst_value_set_caps_features (GValue *value,
  468. const GstCapsFeatures *features);
  469. /* fraction */
  470. void gst_value_set_fraction (GValue *value,
  471. gint numerator,
  472. gint denominator);
  473. gint gst_value_get_fraction_numerator (const GValue *value);
  474. gint gst_value_get_fraction_denominator (const GValue *value);
  475. gboolean gst_value_fraction_multiply (GValue *product,
  476. const GValue *factor1,
  477. const GValue *factor2);
  478. gboolean gst_value_fraction_subtract (GValue * dest,
  479. const GValue * minuend,
  480. const GValue * subtrahend);
  481. /* fraction range */
  482. void gst_value_set_fraction_range (GValue *value,
  483. const GValue *start,
  484. const GValue *end);
  485. void gst_value_set_fraction_range_full (GValue *value,
  486. gint numerator_start,
  487. gint denominator_start,
  488. gint numerator_end,
  489. gint denominator_end);
  490. const GValue *gst_value_get_fraction_range_min (const GValue *value);
  491. const GValue *gst_value_get_fraction_range_max (const GValue *value);
  492. /* bitmask */
  493. guint64 gst_value_get_bitmask (const GValue *value);
  494. void gst_value_set_bitmask (GValue *value,
  495. guint64 bitmask);
  496. /* flagset */
  497. void gst_value_set_flagset (GValue * value, guint flags, guint mask);
  498. guint gst_value_get_flagset_flags (const GValue * value);
  499. guint gst_value_get_flagset_mask (const GValue * value);
  500. /* compare */
  501. gint gst_value_compare (const GValue *value1,
  502. const GValue *value2);
  503. gboolean gst_value_can_compare (const GValue *value1,
  504. const GValue *value2);
  505. gboolean gst_value_is_subset (const GValue *value1,
  506. const GValue *value2);
  507. /* union */
  508. gboolean gst_value_union (GValue *dest,
  509. const GValue *value1,
  510. const GValue *value2);
  511. gboolean gst_value_can_union (const GValue *value1,
  512. const GValue *value2);
  513. /* intersection */
  514. gboolean gst_value_intersect (GValue *dest,
  515. const GValue *value1,
  516. const GValue *value2);
  517. gboolean gst_value_can_intersect (const GValue *value1,
  518. const GValue *value2);
  519. /* subtraction */
  520. gboolean gst_value_subtract (GValue *dest,
  521. const GValue *minuend,
  522. const GValue *subtrahend);
  523. gboolean gst_value_can_subtract (const GValue *minuend,
  524. const GValue *subtrahend);
  525. /* fixation */
  526. gboolean gst_value_is_fixed (const GValue *value);
  527. gboolean gst_value_fixate (GValue *dest,
  528. const GValue *src);
  529. /* Flagset registration wrapper */
  530. GType gst_flagset_register (GType flags_type);
  531. G_END_DECLS
  532. #endif