gstvalue.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /* GStreamer
  2. * Copyright (C) <2003> David A. Schleef <[email protected]>
  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_FOURCC_ARGS(fourcc) \
  77. ((gchar) ((fourcc) &0xff)), \
  78. ((gchar) (((fourcc)>>8 )&0xff)), \
  79. ((gchar) (((fourcc)>>16)&0xff)), \
  80. ((gchar) (((fourcc)>>24)&0xff))
  81. /**
  82. * GST_VALUE_HOLDS_INT_RANGE:
  83. * @x: the #GValue to check
  84. *
  85. * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
  86. */
  87. #define GST_VALUE_HOLDS_INT_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int_range_type)
  88. /**
  89. * GST_VALUE_HOLDS_INT64_RANGE:
  90. * @x: the #GValue to check
  91. *
  92. * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
  93. */
  94. #define GST_VALUE_HOLDS_INT64_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int64_range_type)
  95. /**
  96. * GST_VALUE_HOLDS_DOUBLE_RANGE:
  97. * @x: the #GValue to check
  98. *
  99. * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
  100. */
  101. #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_double_range_type)
  102. /**
  103. * GST_VALUE_HOLDS_FRACTION_RANGE:
  104. * @x: the #GValue to check
  105. *
  106. * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
  107. */
  108. #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_range_type)
  109. /**
  110. * GST_VALUE_HOLDS_LIST:
  111. * @x: the #GValue to check
  112. *
  113. * Checks if the given #GValue contains a #GST_TYPE_LIST value.
  114. */
  115. #define GST_VALUE_HOLDS_LIST(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_list_type)
  116. /**
  117. * GST_VALUE_HOLDS_ARRAY:
  118. * @x: the #GValue to check
  119. *
  120. * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
  121. */
  122. #define GST_VALUE_HOLDS_ARRAY(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_array_type)
  123. /**
  124. * GST_VALUE_HOLDS_CAPS:
  125. * @x: the #GValue to check
  126. *
  127. * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
  128. */
  129. #define GST_VALUE_HOLDS_CAPS(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_caps_type)
  130. /**
  131. * GST_VALUE_HOLDS_STRUCTURE:
  132. * @x: the #GValue to check
  133. *
  134. * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
  135. */
  136. #define GST_VALUE_HOLDS_STRUCTURE(x) (G_VALUE_HOLDS((x), _gst_structure_type))
  137. /**
  138. * GST_VALUE_HOLDS_CAPS_FEATURES:
  139. * @x: the #GValue to check
  140. *
  141. * Checks if the given #GValue contains a #GST_TYPE_CAPS_FEATURES value.
  142. */
  143. #define GST_VALUE_HOLDS_CAPS_FEATURES(x) (G_VALUE_HOLDS((x), _gst_caps_features_type))
  144. /**
  145. * GST_VALUE_HOLDS_BUFFER:
  146. * @x: the #GValue to check
  147. *
  148. * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
  149. */
  150. #define GST_VALUE_HOLDS_BUFFER(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_buffer_type)
  151. /**
  152. * GST_VALUE_HOLDS_SAMPLE:
  153. * @x: the #GValue to check
  154. *
  155. * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
  156. */
  157. #define GST_VALUE_HOLDS_SAMPLE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_sample_type)
  158. /**
  159. * GST_VALUE_HOLDS_FRACTION:
  160. * @x: the #GValue to check
  161. *
  162. * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
  163. */
  164. #define GST_VALUE_HOLDS_FRACTION(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_type)
  165. /**
  166. * GST_VALUE_HOLDS_DATE_TIME:
  167. * @x: the #GValue to check
  168. *
  169. * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
  170. */
  171. #define GST_VALUE_HOLDS_DATE_TIME(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_date_time_type)
  172. /**
  173. * GST_VALUE_HOLDS_BITMASK:
  174. * @x: the #GValue to check
  175. *
  176. * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
  177. */
  178. #define GST_VALUE_HOLDS_BITMASK(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_bitmask_type)
  179. GST_EXPORT GType _gst_int_range_type;
  180. /**
  181. * GST_TYPE_INT_RANGE:
  182. *
  183. * a #GValue type that represents an integer range
  184. *
  185. * Returns: the #GType of GstIntRange
  186. */
  187. #define GST_TYPE_INT_RANGE (_gst_int_range_type)
  188. GST_EXPORT GType _gst_int64_range_type;
  189. /**
  190. * GST_TYPE_INT64_RANGE:
  191. *
  192. * a #GValue type that represents an #gint64 range
  193. *
  194. * Returns: the #GType of GstInt64Range
  195. */
  196. #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
  197. GST_EXPORT GType _gst_double_range_type;
  198. /**
  199. * GST_TYPE_DOUBLE_RANGE:
  200. *
  201. * a #GValue type that represents a floating point range with double precision
  202. *
  203. * Returns: the #GType of GstIntRange
  204. */
  205. #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
  206. GST_EXPORT GType _gst_fraction_range_type;
  207. /**
  208. * GST_TYPE_FRACTION_RANGE:
  209. *
  210. * a #GValue type that represents a GstFraction range
  211. *
  212. * Returns: the #GType of GstFractionRange
  213. */
  214. #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
  215. GST_EXPORT GType _gst_value_list_type;
  216. /**
  217. * GST_TYPE_LIST:
  218. *
  219. * a #GValue type that represents an unordered list of #GValue values. This
  220. * is used for example to express a list of possible values for a field in
  221. * a caps structure, like a list of possible sample rates, of which only one
  222. * will be chosen in the end. This means that all values in the list are
  223. * meaningful on their own.
  224. *
  225. * Returns: the #GType of GstValueList (which is not explicitly typed)
  226. */
  227. #define GST_TYPE_LIST (_gst_value_list_type)
  228. GST_EXPORT GType _gst_value_array_type;
  229. /**
  230. * GST_TYPE_ARRAY:
  231. *
  232. * a #GValue type that represents an ordered list of #GValue values. This is
  233. * used to express a set of values that is meaningful only in their specific
  234. * combination and order of values. Each value on its own is not particularly
  235. * meaningful, only the ordered array in its entirety is meaningful. This is
  236. * used for example to express channel layouts for multichannel audio where
  237. * each channel needs to be mapped to a position in the room.
  238. *
  239. * Returns: the #GType of GstArrayList (which is not explicitly typed)
  240. */
  241. #define GST_TYPE_ARRAY (_gst_value_array_type)
  242. GST_EXPORT GType _gst_fraction_type;
  243. /**
  244. * GST_TYPE_FRACTION:
  245. *
  246. * a #GValue type that represents a fraction of an integer numerator over
  247. * an integer denominator
  248. *
  249. * Returns: the #GType of GstFraction (which is not explicitly typed)
  250. */
  251. #define GST_TYPE_FRACTION (_gst_fraction_type)
  252. GST_EXPORT GType _gst_bitmask_type;
  253. /**
  254. * GST_TYPE_BITMASK:
  255. *
  256. * a #GValue type that represents a 64-bit bitmask.
  257. *
  258. * Returns: the #GType of GstBitmask (which is not explicitly typed)
  259. */
  260. #define GST_TYPE_BITMASK (_gst_bitmask_type)
  261. /**
  262. * GST_TYPE_G_THREAD:
  263. *
  264. * a boxed #GValue type for #GThread that represents a thread.
  265. *
  266. * Returns: the #GType of GstGThread
  267. */
  268. #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
  269. /**
  270. * GST_VALUE_LESS_THAN:
  271. *
  272. * Indicates that the first value provided to a comparison function
  273. * (gst_value_compare()) is lesser than the second one.
  274. */
  275. #define GST_VALUE_LESS_THAN (-1)
  276. /**
  277. * GST_VALUE_EQUAL:
  278. *
  279. * Indicates that the first value provided to a comparison function
  280. * (gst_value_compare()) is equal to the second one.
  281. */
  282. #define GST_VALUE_EQUAL 0
  283. /**
  284. * GST_VALUE_GREATER_THAN:
  285. *
  286. * Indicates that the first value provided to a comparison function
  287. * (gst_value_compare()) is greater than the second one.
  288. */
  289. #define GST_VALUE_GREATER_THAN 1
  290. /**
  291. * GST_VALUE_UNORDERED:
  292. *
  293. * Indicates that the comparison function (gst_value_compare()) can not
  294. * determine a order for the two provided values.
  295. */
  296. #define GST_VALUE_UNORDERED 2
  297. /**
  298. * GstValueCompareFunc:
  299. * @value1: first value for comparison
  300. * @value2: second value for comparison
  301. *
  302. * Used together with gst_value_compare() to compare #GValue items.
  303. *
  304. * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
  305. * or GST_VALUE_UNORDERED
  306. */
  307. typedef gint (* GstValueCompareFunc) (const GValue *value1,
  308. const GValue *value2);
  309. /**
  310. * GstValueSerializeFunc:
  311. * @value1: a #GValue
  312. *
  313. * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
  314. *
  315. * Free-function: g_free
  316. *
  317. * Returns: (transfer full): the string representation of the value
  318. */
  319. typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
  320. /**
  321. * GstValueDeserializeFunc:
  322. * @dest: a #GValue
  323. * @s: a string
  324. *
  325. * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
  326. *
  327. * Returns: %TRUE for success
  328. */
  329. typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
  330. const gchar *s);
  331. typedef struct _GstValueTable GstValueTable;
  332. /**
  333. * GstValueTable:
  334. * @type: a #GType
  335. * @compare: a #GstValueCompareFunc
  336. * @serialize: a #GstValueSerializeFunc
  337. * @deserialize: a #GstValueDeserializeFunc
  338. *
  339. * VTable for the #GValue @type.
  340. */
  341. struct _GstValueTable {
  342. GType type;
  343. GstValueCompareFunc compare;
  344. GstValueSerializeFunc serialize;
  345. GstValueDeserializeFunc deserialize;
  346. /*< private >*/
  347. gpointer _gst_reserved [GST_PADDING];
  348. };
  349. GType gst_int_range_get_type (void);
  350. GType gst_int64_range_get_type (void);
  351. GType gst_double_range_get_type (void);
  352. GType gst_fraction_range_get_type (void);
  353. GType gst_fraction_get_type (void);
  354. GType gst_value_list_get_type (void);
  355. GType gst_value_array_get_type (void);
  356. GType gst_bitmask_get_type (void);
  357. /* Hide this compatibility type from introspection */
  358. #ifndef __GI_SCANNER__
  359. GType gst_g_thread_get_type (void);
  360. #endif
  361. void gst_value_register (const GstValueTable *table);
  362. void gst_value_init_and_copy (GValue *dest,
  363. const GValue *src);
  364. gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
  365. gboolean gst_value_deserialize (GValue *dest,
  366. const gchar *src);
  367. /* list */
  368. void gst_value_list_append_value (GValue *value,
  369. const GValue *append_value);
  370. void gst_value_list_append_and_take_value (GValue *value,
  371. GValue *append_value);
  372. void gst_value_list_prepend_value (GValue *value,
  373. const GValue *prepend_value);
  374. void gst_value_list_concat (GValue *dest,
  375. const GValue *value1,
  376. const GValue *value2);
  377. void gst_value_list_merge (GValue *dest,
  378. const GValue *value1,
  379. const GValue *value2);
  380. guint gst_value_list_get_size (const GValue *value);
  381. const GValue * gst_value_list_get_value (const GValue *value,
  382. guint index);
  383. /* array */
  384. void gst_value_array_append_value (GValue *value,
  385. const GValue *append_value);
  386. void gst_value_array_append_and_take_value (GValue *value,
  387. GValue *append_value);
  388. void gst_value_array_prepend_value (GValue *value,
  389. const GValue *prepend_value);
  390. guint gst_value_array_get_size (const GValue *value);
  391. const GValue * gst_value_array_get_value (const GValue *value,
  392. guint index);
  393. /* int range */
  394. void gst_value_set_int_range (GValue *value,
  395. gint start,
  396. gint end);
  397. void gst_value_set_int_range_step (GValue *value,
  398. gint start,
  399. gint end,
  400. gint step);
  401. gint gst_value_get_int_range_min (const GValue *value);
  402. gint gst_value_get_int_range_max (const GValue *value);
  403. gint gst_value_get_int_range_step (const GValue *value);
  404. /* int64 range */
  405. void gst_value_set_int64_range (GValue *value,
  406. gint64 start,
  407. gint64 end);
  408. void gst_value_set_int64_range_step (GValue *value,
  409. gint64 start,
  410. gint64 end,
  411. gint64 step);
  412. gint64 gst_value_get_int64_range_min (const GValue *value);
  413. gint64 gst_value_get_int64_range_max (const GValue *value);
  414. gint64 gst_value_get_int64_range_step (const GValue *value);
  415. /* double range */
  416. void gst_value_set_double_range (GValue *value,
  417. gdouble start,
  418. gdouble end);
  419. gdouble gst_value_get_double_range_min (const GValue *value);
  420. gdouble gst_value_get_double_range_max (const GValue *value);
  421. /* caps */
  422. const GstCaps * gst_value_get_caps (const GValue *value);
  423. void gst_value_set_caps (GValue *value,
  424. const GstCaps *caps);
  425. /* structure */
  426. const GstStructure *
  427. gst_value_get_structure (const GValue *value);
  428. void gst_value_set_structure (GValue *value,
  429. const GstStructure *structure);
  430. /* caps features */
  431. const GstCapsFeatures *
  432. gst_value_get_caps_features (const GValue *value);
  433. void gst_value_set_caps_features (GValue *value,
  434. const GstCapsFeatures *features);
  435. /* fraction */
  436. void gst_value_set_fraction (GValue *value,
  437. gint numerator,
  438. gint denominator);
  439. gint gst_value_get_fraction_numerator (const GValue *value);
  440. gint gst_value_get_fraction_denominator (const GValue *value);
  441. gboolean gst_value_fraction_multiply (GValue *product,
  442. const GValue *factor1,
  443. const GValue *factor2);
  444. gboolean gst_value_fraction_subtract (GValue * dest,
  445. const GValue * minuend,
  446. const GValue * subtrahend);
  447. /* fraction range */
  448. void gst_value_set_fraction_range (GValue *value,
  449. const GValue *start,
  450. const GValue *end);
  451. void gst_value_set_fraction_range_full (GValue *value,
  452. gint numerator_start,
  453. gint denominator_start,
  454. gint numerator_end,
  455. gint denominator_end);
  456. const GValue *gst_value_get_fraction_range_min (const GValue *value);
  457. const GValue *gst_value_get_fraction_range_max (const GValue *value);
  458. /* bitmask */
  459. guint64 gst_value_get_bitmask (const GValue *value);
  460. void gst_value_set_bitmask (GValue *value,
  461. guint64 bitmask);
  462. /* compare */
  463. gint gst_value_compare (const GValue *value1,
  464. const GValue *value2);
  465. gboolean gst_value_can_compare (const GValue *value1,
  466. const GValue *value2);
  467. gboolean gst_value_is_subset (const GValue *value1,
  468. const GValue *value2);
  469. /* union */
  470. gboolean gst_value_union (GValue *dest,
  471. const GValue *value1,
  472. const GValue *value2);
  473. gboolean gst_value_can_union (const GValue *value1,
  474. const GValue *value2);
  475. /* intersection */
  476. gboolean gst_value_intersect (GValue *dest,
  477. const GValue *value1,
  478. const GValue *value2);
  479. gboolean gst_value_can_intersect (const GValue *value1,
  480. const GValue *value2);
  481. /* subtraction */
  482. gboolean gst_value_subtract (GValue *dest,
  483. const GValue *minuend,
  484. const GValue *subtrahend);
  485. gboolean gst_value_can_subtract (const GValue *minuend,
  486. const GValue *subtrahend);
  487. /* fixation */
  488. gboolean gst_value_is_fixed (const GValue *value);
  489. gboolean gst_value_fixate (GValue *dest,
  490. const GValue *src);
  491. G_END_DECLS
  492. #endif