gstutils.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. /* GStreamer
  2. * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
  3. * 2000 Wim Taymans <wtay@chello.be>
  4. * 2002 Thomas Vander Stichele <thomas@apestaart.org>
  5. *
  6. * gstutils.h: Header for various utility functions
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. */
  23. #ifndef __GST_UTILS_H__
  24. #define __GST_UTILS_H__
  25. #include <glib.h>
  26. #include <gst/gstconfig.h>
  27. #include <gst/gstbin.h>
  28. #include <gst/gstparse.h>
  29. G_BEGIN_DECLS
  30. void gst_util_set_value_from_string (GValue *value, const gchar *value_str);
  31. void gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value);
  32. void gst_util_dump_mem (const guchar *mem, guint size);
  33. guint64 gst_util_gdouble_to_guint64 (gdouble value) G_GNUC_CONST;
  34. gdouble gst_util_guint64_to_gdouble (guint64 value) G_GNUC_CONST;
  35. /**
  36. * gst_guint64_to_gdouble:
  37. * @value: the #guint64 value to convert
  38. *
  39. * Convert @value to a gdouble.
  40. *
  41. * Returns: @value converted to a #gdouble.
  42. */
  43. /**
  44. * gst_gdouble_to_guint64:
  45. * @value: the #gdouble value to convert
  46. *
  47. * Convert @value to a guint64.
  48. *
  49. * Returns: @value converted to a #guint64.
  50. */
  51. #ifdef WIN32
  52. #define gst_gdouble_to_guint64(value) gst_util_gdouble_to_guint64(value)
  53. #define gst_guint64_to_gdouble(value) gst_util_guint64_to_gdouble(value)
  54. #else
  55. #define gst_gdouble_to_guint64(value) ((guint64) (value))
  56. #define gst_guint64_to_gdouble(value) ((gdouble) (value))
  57. #endif
  58. guint64 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom);
  59. guint64 gst_util_uint64_scale_round (guint64 val, guint64 num, guint64 denom);
  60. guint64 gst_util_uint64_scale_ceil (guint64 val, guint64 num, guint64 denom);
  61. guint64 gst_util_uint64_scale_int (guint64 val, gint num, gint denom);
  62. guint64 gst_util_uint64_scale_int_round (guint64 val, gint num, gint denom);
  63. guint64 gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint denom);
  64. guint32 gst_util_seqnum_next (void);
  65. gint32 gst_util_seqnum_compare (guint32 s1, guint32 s2);
  66. guint gst_util_group_id_next (void);
  67. /**
  68. * GST_CALL_PARENT:
  69. * @parent_class_cast: the name of the class cast macro for the parent type
  70. * @name: name of the function to call
  71. * @args: arguments enclosed in '( )'
  72. *
  73. * Just call the parent handler. This assumes that there is a variable
  74. * named parent_class that points to the (duh!) parent class. Note that
  75. * this macro is not to be used with things that return something, use
  76. * the _WITH_DEFAULT version for that
  77. */
  78. #define GST_CALL_PARENT(parent_class_cast, name, args) \
  79. ((parent_class_cast(parent_class)->name != NULL) ? \
  80. parent_class_cast(parent_class)->name args : (void) 0)
  81. /**
  82. * GST_CALL_PARENT_WITH_DEFAULT:
  83. * @parent_class_cast: the name of the class cast macro for the parent type
  84. * @name: name of the function to call
  85. * @args: arguments enclosed in '( )'
  86. * @def_return: default result
  87. *
  88. * Same as GST_CALL_PARENT(), but in case there is no implementation, it
  89. * evaluates to @def_return.
  90. */
  91. #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
  92. ((parent_class_cast(parent_class)->name != NULL) ? \
  93. parent_class_cast(parent_class)->name args : def_return)
  94. /* Define PUT and GET functions for unaligned memory */
  95. #define _GST_GET(__data, __idx, __size, __shift) \
  96. (((guint##__size) (((const guint8 *) (__data))[__idx])) << (__shift))
  97. #define _GST_PUT(__data, __idx, __size, __shift, __num) \
  98. (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
  99. #ifndef __GTK_DOC_IGNORE__
  100. #if GST_HAVE_UNALIGNED_ACCESS
  101. static inline guint16 __gst_fast_read16(const guint8 *v) {
  102. return *(const guint16*)(const void*)(v);
  103. }
  104. static inline guint32 __gst_fast_read32(const guint8 *v) {
  105. return *(const guint32*)(const void*)(v);
  106. }
  107. static inline guint64 __gst_fast_read64(const guint8 *v) {
  108. return *(const guint64*)(const void*)(v);
  109. }
  110. static inline guint16 __gst_fast_read_swap16(const guint8 *v) {
  111. return GUINT16_SWAP_LE_BE(*(const guint16*)(const void*)(v));
  112. }
  113. static inline guint32 __gst_fast_read_swap32(const guint8 *v) {
  114. return GUINT32_SWAP_LE_BE(*(const guint32*)(const void*)(v));
  115. }
  116. static inline guint64 __gst_fast_read_swap64(const guint8 *v) {
  117. return GUINT64_SWAP_LE_BE(*(const guint64*)(const void*)(v));
  118. }
  119. # define _GST_FAST_READ(s, d) __gst_fast_read##s((const guint8 *)(d))
  120. # define _GST_FAST_READ_SWAP(s, d) __gst_fast_read_swap##s((const guint8 *)(d))
  121. #endif
  122. #endif
  123. /**
  124. * GST_READ_UINT64_BE:
  125. * @data: memory location
  126. *
  127. * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
  128. */
  129. /**
  130. * GST_READ_UINT64_LE:
  131. * @data: memory location
  132. *
  133. * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
  134. */
  135. #if GST_HAVE_UNALIGNED_ACCESS
  136. # if (G_BYTE_ORDER == G_BIG_ENDIAN)
  137. # define GST_READ_UINT64_BE(data) _GST_FAST_READ (64, data)
  138. # define GST_READ_UINT64_LE(data) _GST_FAST_READ_SWAP (64, data)
  139. # else
  140. # define GST_READ_UINT64_BE(data) _GST_FAST_READ_SWAP (64, data)
  141. # define GST_READ_UINT64_LE(data) _GST_FAST_READ (64, data)
  142. # endif
  143. #else
  144. #define _GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \
  145. _GST_GET (data, 1, 64, 48) | \
  146. _GST_GET (data, 2, 64, 40) | \
  147. _GST_GET (data, 3, 64, 32) | \
  148. _GST_GET (data, 4, 64, 24) | \
  149. _GST_GET (data, 5, 64, 16) | \
  150. _GST_GET (data, 6, 64, 8) | \
  151. _GST_GET (data, 7, 64, 0))
  152. #define _GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \
  153. _GST_GET (data, 6, 64, 48) | \
  154. _GST_GET (data, 5, 64, 40) | \
  155. _GST_GET (data, 4, 64, 32) | \
  156. _GST_GET (data, 3, 64, 24) | \
  157. _GST_GET (data, 2, 64, 16) | \
  158. _GST_GET (data, 1, 64, 8) | \
  159. _GST_GET (data, 0, 64, 0))
  160. #define GST_READ_UINT64_BE(data) __gst_slow_read64_be((const guint8 *)(data))
  161. static inline guint64 __gst_slow_read64_be (const guint8 * data) {
  162. return _GST_READ_UINT64_BE (data);
  163. }
  164. #define GST_READ_UINT64_LE(data) __gst_slow_read64_le((const guint8 *)(data))
  165. static inline guint64 __gst_slow_read64_le (const guint8 * data) {
  166. return _GST_READ_UINT64_LE (data);
  167. }
  168. #endif
  169. /**
  170. * GST_READ_UINT32_BE:
  171. * @data: memory location
  172. *
  173. * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
  174. */
  175. /**
  176. * GST_READ_UINT32_LE:
  177. * @data: memory location
  178. *
  179. * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
  180. */
  181. #if GST_HAVE_UNALIGNED_ACCESS
  182. # if (G_BYTE_ORDER == G_BIG_ENDIAN)
  183. # define GST_READ_UINT32_BE(data) _GST_FAST_READ (32, data)
  184. # define GST_READ_UINT32_LE(data) _GST_FAST_READ_SWAP (32, data)
  185. # else
  186. # define GST_READ_UINT32_BE(data) _GST_FAST_READ_SWAP (32, data)
  187. # define GST_READ_UINT32_LE(data) _GST_FAST_READ (32, data)
  188. # endif
  189. #else
  190. #define _GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \
  191. _GST_GET (data, 1, 32, 16) | \
  192. _GST_GET (data, 2, 32, 8) | \
  193. _GST_GET (data, 3, 32, 0))
  194. #define _GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \
  195. _GST_GET (data, 2, 32, 16) | \
  196. _GST_GET (data, 1, 32, 8) | \
  197. _GST_GET (data, 0, 32, 0))
  198. #define GST_READ_UINT32_BE(data) __gst_slow_read32_be((const guint8 *)(data))
  199. static inline guint32 __gst_slow_read32_be (const guint8 * data) {
  200. return _GST_READ_UINT32_BE (data);
  201. }
  202. #define GST_READ_UINT32_LE(data) __gst_slow_read32_le((const guint8 *)(data))
  203. static inline guint32 __gst_slow_read32_le (const guint8 * data) {
  204. return _GST_READ_UINT32_LE (data);
  205. }
  206. #endif
  207. /**
  208. * GST_READ_UINT24_BE:
  209. * @data: memory location
  210. *
  211. * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
  212. */
  213. #define _GST_READ_UINT24_BE(data) (_GST_GET (data, 0, 32, 16) | \
  214. _GST_GET (data, 1, 32, 8) | \
  215. _GST_GET (data, 2, 32, 0))
  216. #define GST_READ_UINT24_BE(data) __gst_slow_read24_be((const guint8 *)(data))
  217. static inline guint32 __gst_slow_read24_be (const guint8 * data) {
  218. return _GST_READ_UINT24_BE (data);
  219. }
  220. /**
  221. * GST_READ_UINT24_LE:
  222. * @data: memory location
  223. *
  224. * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
  225. */
  226. #define _GST_READ_UINT24_LE(data) (_GST_GET (data, 2, 32, 16) | \
  227. _GST_GET (data, 1, 32, 8) | \
  228. _GST_GET (data, 0, 32, 0))
  229. #define GST_READ_UINT24_LE(data) __gst_slow_read24_le((const guint8 *)(data))
  230. static inline guint32 __gst_slow_read24_le (const guint8 * data) {
  231. return _GST_READ_UINT24_LE (data);
  232. }
  233. /**
  234. * GST_READ_UINT16_BE:
  235. * @data: memory location
  236. *
  237. * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
  238. */
  239. /**
  240. * GST_READ_UINT16_LE:
  241. * @data: memory location
  242. *
  243. * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
  244. */
  245. #if GST_HAVE_UNALIGNED_ACCESS
  246. # if (G_BYTE_ORDER == G_BIG_ENDIAN)
  247. # define GST_READ_UINT16_BE(data) _GST_FAST_READ (16, data)
  248. # define GST_READ_UINT16_LE(data) _GST_FAST_READ_SWAP (16, data)
  249. # else
  250. # define GST_READ_UINT16_BE(data) _GST_FAST_READ_SWAP (16, data)
  251. # define GST_READ_UINT16_LE(data) _GST_FAST_READ (16, data)
  252. # endif
  253. #else
  254. #define _GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
  255. _GST_GET (data, 1, 16, 0))
  256. #define _GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
  257. _GST_GET (data, 0, 16, 0))
  258. #define GST_READ_UINT16_BE(data) __gst_slow_read16_be((const guint8 *)(data))
  259. static inline guint16 __gst_slow_read16_be (const guint8 * data) {
  260. return _GST_READ_UINT16_BE (data);
  261. }
  262. #define GST_READ_UINT16_LE(data) __gst_slow_read16_le((const guint8 *)(data))
  263. static inline guint16 __gst_slow_read16_le (const guint8 * data) {
  264. return _GST_READ_UINT16_LE (data);
  265. }
  266. #endif
  267. /**
  268. * GST_READ_UINT8:
  269. * @data: memory location
  270. *
  271. * Read an 8 bit unsigned integer value from the memory buffer.
  272. */
  273. #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
  274. /**
  275. * GST_WRITE_UINT64_BE:
  276. * @data: memory location
  277. * @num: value to store
  278. *
  279. * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
  280. */
  281. #define GST_WRITE_UINT64_BE(data, num) do { \
  282. gpointer __put_data = data; \
  283. _GST_PUT (__put_data, 0, 64, 56, num); \
  284. _GST_PUT (__put_data, 1, 64, 48, num); \
  285. _GST_PUT (__put_data, 2, 64, 40, num); \
  286. _GST_PUT (__put_data, 3, 64, 32, num); \
  287. _GST_PUT (__put_data, 4, 64, 24, num); \
  288. _GST_PUT (__put_data, 5, 64, 16, num); \
  289. _GST_PUT (__put_data, 6, 64, 8, num); \
  290. _GST_PUT (__put_data, 7, 64, 0, num); \
  291. } while (0)
  292. /**
  293. * GST_WRITE_UINT64_LE:
  294. * @data: memory location
  295. * @num: value to store
  296. *
  297. * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
  298. */
  299. #define GST_WRITE_UINT64_LE(data, num) do { \
  300. gpointer __put_data = data; \
  301. _GST_PUT (__put_data, 0, 64, 0, num); \
  302. _GST_PUT (__put_data, 1, 64, 8, num); \
  303. _GST_PUT (__put_data, 2, 64, 16, num); \
  304. _GST_PUT (__put_data, 3, 64, 24, num); \
  305. _GST_PUT (__put_data, 4, 64, 32, num); \
  306. _GST_PUT (__put_data, 5, 64, 40, num); \
  307. _GST_PUT (__put_data, 6, 64, 48, num); \
  308. _GST_PUT (__put_data, 7, 64, 56, num); \
  309. } while (0)
  310. /**
  311. * GST_WRITE_UINT32_BE:
  312. * @data: memory location
  313. * @num: value to store
  314. *
  315. * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
  316. */
  317. #define GST_WRITE_UINT32_BE(data, num) do { \
  318. gpointer __put_data = data; \
  319. _GST_PUT (__put_data, 0, 32, 24, num); \
  320. _GST_PUT (__put_data, 1, 32, 16, num); \
  321. _GST_PUT (__put_data, 2, 32, 8, num); \
  322. _GST_PUT (__put_data, 3, 32, 0, num); \
  323. } while (0)
  324. /**
  325. * GST_WRITE_UINT32_LE:
  326. * @data: memory location
  327. * @num: value to store
  328. *
  329. * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
  330. */
  331. #define GST_WRITE_UINT32_LE(data, num) do { \
  332. gpointer __put_data = data; \
  333. _GST_PUT (__put_data, 0, 32, 0, num); \
  334. _GST_PUT (__put_data, 1, 32, 8, num); \
  335. _GST_PUT (__put_data, 2, 32, 16, num); \
  336. _GST_PUT (__put_data, 3, 32, 24, num); \
  337. } while (0)
  338. /**
  339. * GST_WRITE_UINT24_BE:
  340. * @data: memory location
  341. * @num: value to store
  342. *
  343. * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
  344. */
  345. #define GST_WRITE_UINT24_BE(data, num) do { \
  346. gpointer __put_data = data; \
  347. _GST_PUT (__put_data, 0, 32, 16, num); \
  348. _GST_PUT (__put_data, 1, 32, 8, num); \
  349. _GST_PUT (__put_data, 2, 32, 0, num); \
  350. } while (0)
  351. /**
  352. * GST_WRITE_UINT24_LE:
  353. * @data: memory location
  354. * @num: value to store
  355. *
  356. * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
  357. */
  358. #define GST_WRITE_UINT24_LE(data, num) do { \
  359. gpointer __put_data = data; \
  360. _GST_PUT (__put_data, 0, 32, 0, num); \
  361. _GST_PUT (__put_data, 1, 32, 8, num); \
  362. _GST_PUT (__put_data, 2, 32, 16, num); \
  363. } while (0)
  364. /**
  365. * GST_WRITE_UINT16_BE:
  366. * @data: memory location
  367. * @num: value to store
  368. *
  369. * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
  370. */
  371. #define GST_WRITE_UINT16_BE(data, num) do { \
  372. gpointer __put_data = data; \
  373. _GST_PUT (__put_data, 0, 16, 8, num); \
  374. _GST_PUT (__put_data, 1, 16, 0, num); \
  375. } while (0)
  376. /**
  377. * GST_WRITE_UINT16_LE:
  378. * @data: memory location
  379. * @num: value to store
  380. *
  381. * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
  382. */
  383. #define GST_WRITE_UINT16_LE(data, num) do { \
  384. gpointer __put_data = data; \
  385. _GST_PUT (__put_data, 0, 16, 0, num); \
  386. _GST_PUT (__put_data, 1, 16, 8, num); \
  387. } while (0)
  388. /**
  389. * GST_WRITE_UINT8:
  390. * @data: memory location
  391. * @num: value to store
  392. *
  393. * Store an 8 bit unsigned integer value into the memory buffer.
  394. */
  395. #define GST_WRITE_UINT8(data, num) do { \
  396. _GST_PUT (data, 0, 8, 0, num); \
  397. } while (0)
  398. /* Float endianness conversion macros */
  399. /* FIXME: Remove this once we depend on a GLib version with this */
  400. #ifndef GFLOAT_FROM_LE
  401. /**
  402. * GFLOAT_SWAP_LE_BE:
  403. * @in: input value
  404. *
  405. * Swap byte order of a 32-bit floating point value (float).
  406. *
  407. * Returns: @in byte-swapped.
  408. */
  409. static inline gfloat
  410. GFLOAT_SWAP_LE_BE(gfloat in)
  411. {
  412. union
  413. {
  414. guint32 i;
  415. gfloat f;
  416. } u;
  417. u.f = in;
  418. u.i = GUINT32_SWAP_LE_BE (u.i);
  419. return u.f;
  420. }
  421. /**
  422. * GDOUBLE_SWAP_LE_BE:
  423. * @in: input value
  424. *
  425. * Swap byte order of a 64-bit floating point value (double).
  426. *
  427. * Returns: @in byte-swapped.
  428. */
  429. static inline gdouble
  430. GDOUBLE_SWAP_LE_BE(gdouble in)
  431. {
  432. union
  433. {
  434. guint64 i;
  435. gdouble d;
  436. } u;
  437. u.d = in;
  438. u.i = GUINT64_SWAP_LE_BE (u.i);
  439. return u.d;
  440. }
  441. /**
  442. * GDOUBLE_TO_LE:
  443. * @val: value
  444. *
  445. * Convert 64-bit floating point value (double) from native byte order into
  446. * little endian byte order.
  447. */
  448. /**
  449. * GDOUBLE_TO_BE:
  450. * @val: value
  451. *
  452. * Convert 64-bit floating point value (double) from native byte order into
  453. * big endian byte order.
  454. */
  455. /**
  456. * GDOUBLE_FROM_LE:
  457. * @val: value
  458. *
  459. * Convert 64-bit floating point value (double) from little endian byte order
  460. * into native byte order.
  461. */
  462. /**
  463. * GDOUBLE_FROM_BE:
  464. * @val: value
  465. *
  466. * Convert 64-bit floating point value (double) from big endian byte order
  467. * into native byte order.
  468. */
  469. /**
  470. * GFLOAT_TO_LE:
  471. * @val: value
  472. *
  473. * Convert 32-bit floating point value (float) from native byte order into
  474. * little endian byte order.
  475. */
  476. /**
  477. * GFLOAT_TO_BE:
  478. * @val: value
  479. *
  480. * Convert 32-bit floating point value (float) from native byte order into
  481. * big endian byte order.
  482. */
  483. /**
  484. * GFLOAT_FROM_LE:
  485. * @val: value
  486. *
  487. * Convert 32-bit floating point value (float) from little endian byte order
  488. * into native byte order.
  489. */
  490. /**
  491. * GFLOAT_FROM_BE:
  492. * @val: value
  493. *
  494. * Convert 32-bit floating point value (float) from big endian byte order
  495. * into native byte order.
  496. */
  497. #if G_BYTE_ORDER == G_LITTLE_ENDIAN
  498. #define GFLOAT_TO_LE(val) ((gfloat) (val))
  499. #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
  500. #define GDOUBLE_TO_LE(val) ((gdouble) (val))
  501. #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
  502. #elif G_BYTE_ORDER == G_BIG_ENDIAN
  503. #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
  504. #define GFLOAT_TO_BE(val) ((gfloat) (val))
  505. #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
  506. #define GDOUBLE_TO_BE(val) ((gdouble) (val))
  507. #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
  508. #error unknown ENDIAN type
  509. #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
  510. #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
  511. #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
  512. #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
  513. #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
  514. #endif /* !defined(GFLOAT_FROM_LE) */
  515. /**
  516. * GST_READ_FLOAT_LE:
  517. * @data: memory location
  518. *
  519. * Read a 32 bit float value in little endian format from the memory buffer.
  520. *
  521. * Returns: The floating point value read from @data
  522. */
  523. static inline gfloat
  524. GST_READ_FLOAT_LE(const guint8 *data)
  525. {
  526. union
  527. {
  528. guint32 i;
  529. gfloat f;
  530. } u;
  531. u.i = GST_READ_UINT32_LE (data);
  532. return u.f;
  533. }
  534. /**
  535. * GST_READ_FLOAT_BE:
  536. * @data: memory location
  537. *
  538. * Read a 32 bit float value in big endian format from the memory buffer.
  539. *
  540. * Returns: The floating point value read from @data
  541. */
  542. static inline gfloat
  543. GST_READ_FLOAT_BE(const guint8 *data)
  544. {
  545. union
  546. {
  547. guint32 i;
  548. gfloat f;
  549. } u;
  550. u.i = GST_READ_UINT32_BE (data);
  551. return u.f;
  552. }
  553. /**
  554. * GST_READ_DOUBLE_LE:
  555. * @data: memory location
  556. *
  557. * Read a 64 bit double value in little endian format from the memory buffer.
  558. *
  559. * Returns: The double-precision floating point value read from @data
  560. */
  561. static inline gdouble
  562. GST_READ_DOUBLE_LE(const guint8 *data)
  563. {
  564. union
  565. {
  566. guint64 i;
  567. gdouble d;
  568. } u;
  569. u.i = GST_READ_UINT64_LE (data);
  570. return u.d;
  571. }
  572. /**
  573. * GST_READ_DOUBLE_BE:
  574. * @data: memory location
  575. *
  576. * Read a 64 bit double value in big endian format from the memory buffer.
  577. *
  578. * Returns: The double-precision floating point value read from @data
  579. */
  580. static inline gdouble
  581. GST_READ_DOUBLE_BE(const guint8 *data)
  582. {
  583. union
  584. {
  585. guint64 i;
  586. gdouble d;
  587. } u;
  588. u.i = GST_READ_UINT64_BE (data);
  589. return u.d;
  590. }
  591. /**
  592. * GST_WRITE_FLOAT_LE:
  593. * @data: memory location
  594. * @num: value to store
  595. *
  596. * Store a 32 bit float value in little endian format into the memory buffer.
  597. */
  598. static inline void
  599. GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
  600. {
  601. union
  602. {
  603. guint32 i;
  604. gfloat f;
  605. } u;
  606. u.f = num;
  607. GST_WRITE_UINT32_LE (data, u.i);
  608. }
  609. /**
  610. * GST_WRITE_FLOAT_BE:
  611. * @data: memory location
  612. * @num: value to store
  613. *
  614. * Store a 32 bit float value in big endian format into the memory buffer.
  615. */
  616. static inline void
  617. GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
  618. {
  619. union
  620. {
  621. guint32 i;
  622. gfloat f;
  623. } u;
  624. u.f = num;
  625. GST_WRITE_UINT32_BE (data, u.i);
  626. }
  627. /**
  628. * GST_WRITE_DOUBLE_LE:
  629. * @data: memory location
  630. * @num: value to store
  631. *
  632. * Store a 64 bit double value in little endian format into the memory buffer.
  633. */
  634. static inline void
  635. GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
  636. {
  637. union
  638. {
  639. guint64 i;
  640. gdouble d;
  641. } u;
  642. u.d = num;
  643. GST_WRITE_UINT64_LE (data, u.i);
  644. }
  645. /**
  646. * GST_WRITE_DOUBLE_BE:
  647. * @data: memory location
  648. * @num: value to store
  649. *
  650. * Store a 64 bit double value in big endian format into the memory buffer.
  651. */
  652. static inline void
  653. GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
  654. {
  655. union
  656. {
  657. guint64 i;
  658. gdouble d;
  659. } u;
  660. u.d = num;
  661. GST_WRITE_UINT64_BE (data, u.i);
  662. }
  663. /* Miscellaneous utility macros */
  664. /**
  665. * GST_ROUND_UP_2:
  666. * @num: integer value to round up
  667. *
  668. * Rounds an integer value up to the next multiple of 2.
  669. */
  670. #define GST_ROUND_UP_2(num) (((num)+1)&~1)
  671. /**
  672. * GST_ROUND_UP_4:
  673. * @num: integer value to round up
  674. *
  675. * Rounds an integer value up to the next multiple of 4.
  676. */
  677. #define GST_ROUND_UP_4(num) (((num)+3)&~3)
  678. /**
  679. * GST_ROUND_UP_8:
  680. * @num: integer value to round up
  681. *
  682. * Rounds an integer value up to the next multiple of 8.
  683. */
  684. #define GST_ROUND_UP_8(num) (((num)+7)&~7)
  685. /**
  686. * GST_ROUND_UP_16:
  687. * @num: integer value to round up
  688. *
  689. * Rounds an integer value up to the next multiple of 16.
  690. */
  691. #define GST_ROUND_UP_16(num) (((num)+15)&~15)
  692. /**
  693. * GST_ROUND_UP_32:
  694. * @num: integer value to round up
  695. *
  696. * Rounds an integer value up to the next multiple of 32.
  697. */
  698. #define GST_ROUND_UP_32(num) (((num)+31)&~31)
  699. /**
  700. * GST_ROUND_UP_64:
  701. * @num: integer value to round up
  702. *
  703. * Rounds an integer value up to the next multiple of 64.
  704. */
  705. #define GST_ROUND_UP_64(num) (((num)+63)&~63)
  706. /**
  707. * GST_ROUND_UP_128:
  708. * @num: integer value to round up
  709. *
  710. * Rounds an integer value up to the next multiple of 128.
  711. * Since: 1.4
  712. */
  713. #define GST_ROUND_UP_128(num) (((num)+127)&~127)
  714. /**
  715. * GST_ROUND_UP_N:
  716. * @num: integrer value to round up
  717. * @align: a power of two to round up to
  718. *
  719. * Rounds an integer value up to the next multiple of @align. @align MUST be a
  720. * power of two.
  721. */
  722. #define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
  723. /**
  724. * GST_ROUND_DOWN_2:
  725. * @num: integer value to round down
  726. *
  727. * Rounds an integer value down to the next multiple of 2.
  728. */
  729. #define GST_ROUND_DOWN_2(num) ((num)&(~1))
  730. /**
  731. * GST_ROUND_DOWN_4:
  732. * @num: integer value to round down
  733. *
  734. * Rounds an integer value down to the next multiple of 4.
  735. */
  736. #define GST_ROUND_DOWN_4(num) ((num)&(~3))
  737. /**
  738. * GST_ROUND_DOWN_8:
  739. * @num: integer value to round down
  740. *
  741. * Rounds an integer value down to the next multiple of 8.
  742. */
  743. #define GST_ROUND_DOWN_8(num) ((num)&(~7))
  744. /**
  745. * GST_ROUND_DOWN_16:
  746. * @num: integer value to round down
  747. *
  748. * Rounds an integer value down to the next multiple of 16.
  749. */
  750. #define GST_ROUND_DOWN_16(num) ((num)&(~15))
  751. /**
  752. * GST_ROUND_DOWN_32:
  753. * @num: integer value to round down
  754. *
  755. * Rounds an integer value down to the next multiple of 32.
  756. */
  757. #define GST_ROUND_DOWN_32(num) ((num)&(~31))
  758. /**
  759. * GST_ROUND_DOWN_64:
  760. * @num: integer value to round down
  761. *
  762. * Rounds an integer value down to the next multiple of 64.
  763. */
  764. #define GST_ROUND_DOWN_64(num) ((num)&(~63))
  765. /**
  766. * GST_ROUND_DOWN_128:
  767. * @num: integer value to round down
  768. *
  769. * Rounds an integer value down to the next multiple of 128.
  770. * Since: 1.4
  771. */
  772. #define GST_ROUND_DOWN_128(num) ((num)&(~127))
  773. /**
  774. * GST_ROUND_DOWN_N:
  775. * @num: integrer value to round down
  776. * @align: a power of two to round down to
  777. *
  778. * Rounds an integer value down to the next multiple of @align. @align MUST be a
  779. * power of two.
  780. */
  781. #define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1)))
  782. void gst_object_default_error (GstObject * source,
  783. const GError * error,
  784. const gchar * debug);
  785. /* element functions */
  786. void gst_element_create_all_pads (GstElement *element);
  787. GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
  788. GstCaps *caps);
  789. GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
  790. const gchar* gst_element_state_get_name (GstState state);
  791. const gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
  792. gboolean gst_element_link (GstElement *src, GstElement *dest);
  793. gboolean gst_element_link_many (GstElement *element_1,
  794. GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
  795. gboolean gst_element_link_filtered (GstElement * src,
  796. GstElement * dest,
  797. GstCaps *filter);
  798. void gst_element_unlink (GstElement *src, GstElement *dest);
  799. void gst_element_unlink_many (GstElement *element_1,
  800. GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
  801. gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
  802. GstElement *dest, const gchar *destpadname);
  803. gboolean gst_element_link_pads_full (GstElement *src, const gchar *srcpadname,
  804. GstElement *dest, const gchar *destpadname,
  805. GstPadLinkCheck flags);
  806. void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
  807. GstElement *dest, const gchar *destpadname);
  808. gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
  809. GstElement * dest, const gchar * destpadname,
  810. GstCaps *filter);
  811. gboolean gst_element_seek_simple (GstElement *element,
  812. GstFormat format,
  813. GstSeekFlags seek_flags,
  814. gint64 seek_pos);
  815. /* util elementfactory functions */
  816. gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
  817. gboolean gst_element_factory_can_src_all_caps (GstElementFactory *factory, const GstCaps *caps);
  818. gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
  819. gboolean gst_element_factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps);
  820. /* util query functions */
  821. gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur);
  822. gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration);
  823. gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
  824. GstFormat dest_format, gint64 *dest_val);
  825. /* pad functions */
  826. void gst_pad_use_fixed_caps (GstPad *pad);
  827. GstElement* gst_pad_get_parent_element (GstPad *pad);
  828. /* util query functions */
  829. gboolean gst_pad_proxy_query_accept_caps (GstPad *pad, GstQuery *query);
  830. gboolean gst_pad_proxy_query_caps (GstPad *pad, GstQuery *query);
  831. gboolean gst_pad_query_position (GstPad *pad, GstFormat format, gint64 *cur);
  832. gboolean gst_pad_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
  833. gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
  834. GstFormat dest_format, gint64 *dest_val);
  835. GstCaps * gst_pad_query_caps (GstPad *pad, GstCaps *filter);
  836. gboolean gst_pad_query_accept_caps (GstPad *pad, GstCaps *caps);
  837. gboolean gst_pad_peer_query_position (GstPad *pad, GstFormat format, gint64 *cur);
  838. gboolean gst_pad_peer_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
  839. gboolean gst_pad_peer_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
  840. GstFormat dest_format, gint64 *dest_val);
  841. GstCaps * gst_pad_peer_query_caps (GstPad * pad, GstCaps *filter);
  842. gboolean gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps *caps);
  843. gchar * gst_pad_create_stream_id (GstPad * pad, GstElement * parent, const gchar *stream_id) G_GNUC_MALLOC;
  844. gchar * gst_pad_create_stream_id_printf (GstPad * pad, GstElement * parent, const gchar *stream_id, ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
  845. gchar * gst_pad_create_stream_id_printf_valist (GstPad * pad, GstElement * parent, const gchar *stream_id, va_list var_args) G_GNUC_PRINTF (3, 0) G_GNUC_MALLOC;
  846. gchar * gst_pad_get_stream_id (GstPad * pad);
  847. /* bin functions */
  848. void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
  849. void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
  850. GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
  851. gboolean gst_bin_sync_children_states (GstBin *bin);
  852. /* parse utility functions */
  853. GstElement * gst_parse_bin_from_description (const gchar * bin_description,
  854. gboolean ghost_unlinked_pads,
  855. GError ** err);
  856. GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
  857. gboolean ghost_unlinked_pads,
  858. GstParseContext * context,
  859. GstParseFlags flags,
  860. GError ** err);
  861. GstClockTime gst_util_get_timestamp (void);
  862. /**
  863. * GstSearchMode:
  864. * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
  865. * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
  866. * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
  867. *
  868. * The different search modes.
  869. */
  870. typedef enum {
  871. GST_SEARCH_MODE_EXACT = 0,
  872. GST_SEARCH_MODE_BEFORE,
  873. GST_SEARCH_MODE_AFTER
  874. } GstSearchMode;
  875. gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
  876. gsize element_size, GCompareDataFunc search_func,
  877. GstSearchMode mode, gconstpointer search_data,
  878. gpointer user_data);
  879. /* fraction operations */
  880. gint gst_util_greatest_common_divisor (gint a, gint b);
  881. gint64 gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
  882. void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
  883. void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
  884. gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
  885. gint *res_n, gint *res_d);
  886. gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d,
  887. gint *res_n, gint *res_d);
  888. gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
  889. G_END_DECLS
  890. #endif /* __GST_UTILS_H__ */