gstbuffer.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /* GStreamer
  2. * Copyright (C) 1999,2000 Erik Walthinsen <[email protected]>
  3. * 2000 Wim Taymans <[email protected]>
  4. *
  5. * gstbuffer.h: Header for GstBuffer object
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef __GST_BUFFER_H__
  23. #define __GST_BUFFER_H__
  24. #include <gst/gstminiobject.h>
  25. #include <gst/gstclock.h>
  26. #include <gst/gstallocator.h>
  27. G_BEGIN_DECLS
  28. GST_EXPORT GType _gst_buffer_type;
  29. typedef struct _GstBuffer GstBuffer;
  30. typedef struct _GstBufferPool GstBufferPool;
  31. #define GST_TYPE_BUFFER (_gst_buffer_type)
  32. #define GST_IS_BUFFER(obj) (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_BUFFER))
  33. #define GST_BUFFER_CAST(obj) ((GstBuffer *)(obj))
  34. #define GST_BUFFER(obj) (GST_BUFFER_CAST(obj))
  35. /**
  36. * GST_BUFFER_FLAGS:
  37. * @buf: a #GstBuffer.
  38. *
  39. * A flags word containing #GstBufferFlags flags set on this buffer.
  40. */
  41. #define GST_BUFFER_FLAGS(buf) GST_MINI_OBJECT_FLAGS(buf)
  42. /**
  43. * GST_BUFFER_FLAG_IS_SET:
  44. * @buf: a #GstBuffer.
  45. * @flag: the #GstBufferFlags flag to check.
  46. *
  47. * Gives the status of a specific flag on a buffer.
  48. */
  49. #define GST_BUFFER_FLAG_IS_SET(buf,flag) GST_MINI_OBJECT_FLAG_IS_SET (buf, flag)
  50. /**
  51. * GST_BUFFER_FLAG_SET:
  52. * @buf: a #GstBuffer.
  53. * @flag: the #GstBufferFlags flag to set.
  54. *
  55. * Sets a buffer flag on a buffer.
  56. */
  57. #define GST_BUFFER_FLAG_SET(buf,flag) GST_MINI_OBJECT_FLAG_SET (buf, flag)
  58. /**
  59. * GST_BUFFER_FLAG_UNSET:
  60. * @buf: a #GstBuffer.
  61. * @flag: the #GstBufferFlags flag to clear.
  62. *
  63. * Clears a buffer flag.
  64. */
  65. #define GST_BUFFER_FLAG_UNSET(buf,flag) GST_MINI_OBJECT_FLAG_UNSET (buf, flag)
  66. /**
  67. * GST_BUFFER_PTS:
  68. * @buf: a #GstBuffer.:
  69. *
  70. * The presentation timestamp (pts) in nanoseconds (as a #GstClockTime)
  71. * of the data in the buffer. This is the timestamp when the media should be
  72. * presented to the user.
  73. * Value will be %GST_CLOCK_TIME_NONE if the pts is unknown.
  74. */
  75. #define GST_BUFFER_PTS(buf) (GST_BUFFER_CAST(buf)->pts)
  76. /**
  77. * GST_BUFFER_DTS:
  78. * @buf: a #GstBuffer.:
  79. *
  80. * The decoding timestamp (dts) in nanoseconds (as a #GstClockTime)
  81. * of the data in the buffer. This is the timestamp when the media should be
  82. * decoded or processed otherwise.
  83. * Value will be %GST_CLOCK_TIME_NONE if the dts is unknown.
  84. */
  85. #define GST_BUFFER_DTS(buf) (GST_BUFFER_CAST(buf)->dts)
  86. /**
  87. * GST_BUFFER_DURATION:
  88. * @buf: a #GstBuffer.
  89. *
  90. * The duration in nanoseconds (as a #GstClockTime) of the data in the buffer.
  91. * Value will be %GST_CLOCK_TIME_NONE if the duration is unknown.
  92. */
  93. #define GST_BUFFER_DURATION(buf) (GST_BUFFER_CAST(buf)->duration)
  94. /**
  95. * GST_BUFFER_OFFSET:
  96. * @buf: a #GstBuffer.
  97. *
  98. * The offset in the source file of the beginning of this buffer.
  99. */
  100. #define GST_BUFFER_OFFSET(buf) (GST_BUFFER_CAST(buf)->offset)
  101. /**
  102. * GST_BUFFER_OFFSET_END:
  103. * @buf: a #GstBuffer.
  104. *
  105. * The offset in the source file of the end of this buffer.
  106. */
  107. #define GST_BUFFER_OFFSET_END(buf) (GST_BUFFER_CAST(buf)->offset_end)
  108. /**
  109. * GST_BUFFER_OFFSET_NONE:
  110. *
  111. * Constant for no-offset return results.
  112. */
  113. #define GST_BUFFER_OFFSET_NONE ((guint64)-1)
  114. /**
  115. * GST_BUFFER_DURATION_IS_VALID:
  116. * @buffer: a #GstBuffer
  117. *
  118. * Tests if the duration is known.
  119. */
  120. #define GST_BUFFER_DURATION_IS_VALID(buffer) (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer)))
  121. /**
  122. * GST_BUFFER_PTS_IS_VALID:
  123. * @buffer: a #GstBuffer
  124. *
  125. * Tests if the pts is known.
  126. */
  127. #define GST_BUFFER_PTS_IS_VALID(buffer) (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buffer)))
  128. /**
  129. * GST_BUFFER_DTS_IS_VALID:
  130. * @buffer: a #GstBuffer
  131. *
  132. * Tests if the dts is known.
  133. */
  134. #define GST_BUFFER_DTS_IS_VALID(buffer) (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (buffer)))
  135. /**
  136. * GST_BUFFER_OFFSET_IS_VALID:
  137. * @buffer: a #GstBuffer
  138. *
  139. * Tests if the start offset is known.
  140. */
  141. #define GST_BUFFER_OFFSET_IS_VALID(buffer) (GST_BUFFER_OFFSET (buffer) != GST_BUFFER_OFFSET_NONE)
  142. /**
  143. * GST_BUFFER_OFFSET_END_IS_VALID:
  144. * @buffer: a #GstBuffer
  145. *
  146. * Tests if the end offset is known.
  147. */
  148. #define GST_BUFFER_OFFSET_END_IS_VALID(buffer) (GST_BUFFER_OFFSET_END (buffer) != GST_BUFFER_OFFSET_NONE)
  149. /**
  150. * GST_BUFFER_IS_DISCONT:
  151. * @buffer: a #GstBuffer
  152. *
  153. * Tests if the buffer marks a discontinuity in the stream.
  154. */
  155. #define GST_BUFFER_IS_DISCONT(buffer) (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT))
  156. /**
  157. * GstBufferFlags:
  158. * @GST_BUFFER_FLAG_LIVE: the buffer is live data and should be discarded in
  159. * the PAUSED state.
  160. * @GST_BUFFER_FLAG_DECODE_ONLY: the buffer contains data that should be dropped
  161. * because it will be clipped against the segment
  162. * boundaries or because it does not contain data
  163. * that should be shown to the user.
  164. * @GST_BUFFER_FLAG_DISCONT: the buffer marks a data discontinuity in the stream.
  165. * This typically occurs after a seek or a dropped buffer
  166. * from a live or network source.
  167. * @GST_BUFFER_FLAG_RESYNC: the buffer timestamps might have a discontinuity
  168. * and this buffer is a good point to resynchronize.
  169. * @GST_BUFFER_FLAG_CORRUPTED: the buffer data is corrupted.
  170. * @GST_BUFFER_FLAG_MARKER: the buffer contains a media specific marker. for
  171. * video this is typically the end of a frame boundary, for audio
  172. * this is usually the start of a talkspurt.
  173. * @GST_BUFFER_FLAG_HEADER: the buffer contains header information that is
  174. * needed to decode the following data.
  175. * @GST_BUFFER_FLAG_GAP: the buffer has been created to fill a gap in the
  176. * stream and contains media neutral data (elements can
  177. * switch to optimized code path that ignores the buffer
  178. * content).
  179. * @GST_BUFFER_FLAG_DROPPABLE: the buffer can be dropped without breaking the
  180. * stream, for example to reduce bandwidth.
  181. * @GST_BUFFER_FLAG_DELTA_UNIT: this unit cannot be decoded independently.
  182. * @GST_BUFFER_FLAG_TAG_MEMORY: this flag is set when memory of the buffer
  183. * is added/removed
  184. * @GST_BUFFER_FLAG_LAST: additional media specific flags can be added starting from
  185. * this flag.
  186. *
  187. * A set of buffer flags used to describe properties of a #GstBuffer.
  188. */
  189. typedef enum {
  190. GST_BUFFER_FLAG_LIVE = (GST_MINI_OBJECT_FLAG_LAST << 0),
  191. GST_BUFFER_FLAG_DECODE_ONLY = (GST_MINI_OBJECT_FLAG_LAST << 1),
  192. GST_BUFFER_FLAG_DISCONT = (GST_MINI_OBJECT_FLAG_LAST << 2),
  193. GST_BUFFER_FLAG_RESYNC = (GST_MINI_OBJECT_FLAG_LAST << 3),
  194. GST_BUFFER_FLAG_CORRUPTED = (GST_MINI_OBJECT_FLAG_LAST << 4),
  195. GST_BUFFER_FLAG_MARKER = (GST_MINI_OBJECT_FLAG_LAST << 5),
  196. GST_BUFFER_FLAG_HEADER = (GST_MINI_OBJECT_FLAG_LAST << 6),
  197. GST_BUFFER_FLAG_GAP = (GST_MINI_OBJECT_FLAG_LAST << 7),
  198. GST_BUFFER_FLAG_DROPPABLE = (GST_MINI_OBJECT_FLAG_LAST << 8),
  199. GST_BUFFER_FLAG_DELTA_UNIT = (GST_MINI_OBJECT_FLAG_LAST << 9),
  200. GST_BUFFER_FLAG_TAG_MEMORY = (GST_MINI_OBJECT_FLAG_LAST << 10),
  201. GST_BUFFER_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 16)
  202. } GstBufferFlags;
  203. /**
  204. * GstBuffer:
  205. * @mini_object: the parent structure
  206. * @pool: pointer to the pool owner of the buffer
  207. * @pts: presentation timestamp of the buffer, can be #GST_CLOCK_TIME_NONE when the
  208. * pts is not known or relevant. The pts contains the timestamp when the
  209. * media should be presented to the user.
  210. * @dts: decoding timestamp of the buffer, can be #GST_CLOCK_TIME_NONE when the
  211. * dts is not known or relevant. The dts contains the timestamp when the
  212. * media should be processed.
  213. * @duration: duration in time of the buffer data, can be #GST_CLOCK_TIME_NONE
  214. * when the duration is not known or relevant.
  215. * @offset: a media specific offset for the buffer data.
  216. * For video frames, this is the frame number of this buffer.
  217. * For audio samples, this is the offset of the first sample in this buffer.
  218. * For file data or compressed data this is the byte offset of the first
  219. * byte in this buffer.
  220. * @offset_end: the last offset contained in this buffer. It has the same
  221. * format as @offset.
  222. *
  223. * The structure of a #GstBuffer. Use the associated macros to access the public
  224. * variables.
  225. */
  226. struct _GstBuffer {
  227. GstMiniObject mini_object;
  228. /*< public >*/ /* with COW */
  229. GstBufferPool *pool;
  230. /* timestamp */
  231. GstClockTime pts;
  232. GstClockTime dts;
  233. GstClockTime duration;
  234. /* media specific offset */
  235. guint64 offset;
  236. guint64 offset_end;
  237. };
  238. GType gst_buffer_get_type (void);
  239. guint gst_buffer_get_max_memory (void);
  240. /* allocation */
  241. GstBuffer * gst_buffer_new (void);
  242. GstBuffer * gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
  243. GstAllocationParams * params);
  244. GstBuffer * gst_buffer_new_wrapped_full (GstMemoryFlags flags, gpointer data, gsize maxsize,
  245. gsize offset, gsize size, gpointer user_data,
  246. GDestroyNotify notify);
  247. GstBuffer * gst_buffer_new_wrapped (gpointer data, gsize size);
  248. /* memory blocks */
  249. guint gst_buffer_n_memory (GstBuffer *buffer);
  250. void gst_buffer_insert_memory (GstBuffer *buffer, gint idx, GstMemory *mem);
  251. void gst_buffer_replace_memory_range (GstBuffer *buffer, guint idx, gint length, GstMemory *mem);
  252. GstMemory * gst_buffer_peek_memory (GstBuffer *buffer, guint idx);
  253. GstMemory * gst_buffer_get_memory_range (GstBuffer *buffer, guint idx, gint length);
  254. void gst_buffer_remove_memory_range (GstBuffer *buffer, guint idx, gint length);
  255. void gst_buffer_prepend_memory (GstBuffer *buffer, GstMemory *mem);
  256. void gst_buffer_append_memory (GstBuffer *buffer, GstMemory *mem);
  257. void gst_buffer_replace_memory (GstBuffer *buffer, guint idx, GstMemory *mem);
  258. void gst_buffer_replace_all_memory (GstBuffer *buffer, GstMemory *mem);
  259. GstMemory * gst_buffer_get_memory (GstBuffer *buffer, guint idx);
  260. GstMemory * gst_buffer_get_all_memory (GstBuffer *buffer);
  261. void gst_buffer_remove_memory (GstBuffer *buffer, guint idx);
  262. void gst_buffer_remove_all_memory (GstBuffer *buffer);
  263. gboolean gst_buffer_find_memory (GstBuffer *buffer, gsize offset, gsize size,
  264. guint *idx, guint *length, gsize *skip);
  265. gboolean gst_buffer_is_memory_range_writable (GstBuffer *buffer, guint idx, gint length);
  266. gboolean gst_buffer_is_all_memory_writable (GstBuffer *buffer);
  267. gsize gst_buffer_fill (GstBuffer *buffer, gsize offset,
  268. gconstpointer src, gsize size);
  269. gsize gst_buffer_extract (GstBuffer *buffer, gsize offset,
  270. gpointer dest, gsize size);
  271. gint gst_buffer_memcmp (GstBuffer *buffer, gsize offset,
  272. gconstpointer mem, gsize size);
  273. gsize gst_buffer_memset (GstBuffer *buffer, gsize offset,
  274. guint8 val, gsize size);
  275. gsize gst_buffer_get_sizes_range (GstBuffer *buffer, guint idx, gint length,
  276. gsize *offset, gsize *maxsize);
  277. gboolean gst_buffer_resize_range (GstBuffer *buffer, guint idx, gint length,
  278. gssize offset, gssize size);
  279. gsize gst_buffer_get_sizes (GstBuffer *buffer, gsize *offset, gsize *maxsize);
  280. gsize gst_buffer_get_size (GstBuffer *buffer);
  281. void gst_buffer_resize (GstBuffer *buffer, gssize offset, gssize size);
  282. void gst_buffer_set_size (GstBuffer *buffer, gssize size);
  283. gboolean gst_buffer_map_range (GstBuffer *buffer, guint idx, gint length,
  284. GstMapInfo *info, GstMapFlags flags);
  285. gboolean gst_buffer_map (GstBuffer *buffer, GstMapInfo *info, GstMapFlags flags);
  286. void gst_buffer_unmap (GstBuffer *buffer, GstMapInfo *info);
  287. void gst_buffer_extract_dup (GstBuffer *buffer, gsize offset,
  288. gsize size, gpointer *dest,
  289. gsize *dest_size);
  290. /* refcounting */
  291. /**
  292. * gst_buffer_ref:
  293. * @buf: a #GstBuffer.
  294. *
  295. * Increases the refcount of the given buffer by one.
  296. *
  297. * Note that the refcount affects the writability
  298. * of @buf and its metadata, see gst_buffer_is_writable().
  299. * It is important to note that keeping additional references to
  300. * GstBuffer instances can potentially increase the number
  301. * of memcpy operations in a pipeline.
  302. *
  303. * Returns: (transfer full): @buf
  304. */
  305. #ifdef _FOOL_GTK_DOC_
  306. G_INLINE_FUNC GstBuffer * gst_buffer_ref (GstBuffer * buf);
  307. #endif
  308. static inline GstBuffer *
  309. gst_buffer_ref (GstBuffer * buf)
  310. {
  311. return (GstBuffer *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (buf));
  312. }
  313. /**
  314. * gst_buffer_unref:
  315. * @buf: (transfer full): a #GstBuffer.
  316. *
  317. * Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
  318. * with the associated metadata and memory will be freed.
  319. */
  320. #ifdef _FOOL_GTK_DOC_
  321. G_INLINE_FUNC void gst_buffer_unref (GstBuffer * buf);
  322. #endif
  323. static inline void
  324. gst_buffer_unref (GstBuffer * buf)
  325. {
  326. gst_mini_object_unref (GST_MINI_OBJECT_CAST (buf));
  327. }
  328. /* copy buffer */
  329. /**
  330. * gst_buffer_copy:
  331. * @buf: a #GstBuffer.
  332. *
  333. * Create a copy of the given buffer. This will also make a newly allocated
  334. * copy of the data the source buffer contains.
  335. *
  336. * Returns: (transfer full): a new copy of @buf.
  337. */
  338. #ifdef _FOOL_GTK_DOC_
  339. G_INLINE_FUNC GstBuffer * gst_buffer_copy (const GstBuffer * buf);
  340. #endif
  341. static inline GstBuffer *
  342. gst_buffer_copy (const GstBuffer * buf)
  343. {
  344. return GST_BUFFER (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (buf)));
  345. }
  346. /**
  347. * GstBufferCopyFlags:
  348. * @GST_BUFFER_COPY_NONE: copy nothing
  349. * @GST_BUFFER_COPY_FLAGS: flag indicating that buffer flags should be copied
  350. * @GST_BUFFER_COPY_TIMESTAMPS: flag indicating that buffer pts, dts,
  351. * duration, offset and offset_end should be copied
  352. * @GST_BUFFER_COPY_MEMORY: flag indicating that buffer memory should be reffed
  353. * and appended to already existing memory. Unless the memory is marked as
  354. * NO_SHARE, no actual copy of the memory is made but it is simply reffed.
  355. * Add @GST_BUFFER_COPY_DEEP to force a real copy.
  356. * @GST_BUFFER_COPY_MERGE: flag indicating that buffer memory should be
  357. * merged
  358. * @GST_BUFFER_COPY_META: flag indicating that buffer meta should be
  359. * copied
  360. * @GST_BUFFER_COPY_DEEP: flag indicating that memory should always be
  361. * copied instead of reffed (Since 1.2)
  362. *
  363. * A set of flags that can be provided to the gst_buffer_copy_into()
  364. * function to specify which items should be copied.
  365. */
  366. typedef enum {
  367. GST_BUFFER_COPY_NONE = 0,
  368. GST_BUFFER_COPY_FLAGS = (1 << 0),
  369. GST_BUFFER_COPY_TIMESTAMPS = (1 << 1),
  370. GST_BUFFER_COPY_META = (1 << 2),
  371. GST_BUFFER_COPY_MEMORY = (1 << 3),
  372. GST_BUFFER_COPY_MERGE = (1 << 4),
  373. GST_BUFFER_COPY_DEEP = (1 << 5)
  374. } GstBufferCopyFlags;
  375. /**
  376. * GST_BUFFER_COPY_METADATA:
  377. *
  378. * Combination of all possible metadata fields that can be copied with
  379. * gst_buffer_copy_into().
  380. */
  381. #define GST_BUFFER_COPY_METADATA (GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS |\
  382. GST_BUFFER_COPY_META)
  383. /**
  384. * GST_BUFFER_COPY_ALL:
  385. *
  386. * Combination of all possible fields that can be copied with
  387. * gst_buffer_copy_into().
  388. */
  389. #define GST_BUFFER_COPY_ALL ((GstBufferCopyFlags)(GST_BUFFER_COPY_METADATA | GST_BUFFER_COPY_MEMORY))
  390. /* copies memory or metadata into newly allocated buffer */
  391. gboolean gst_buffer_copy_into (GstBuffer *dest, GstBuffer *src,
  392. GstBufferCopyFlags flags,
  393. gsize offset, gsize size);
  394. /**
  395. * gst_buffer_is_writable:
  396. * @buf: a #GstBuffer
  397. *
  398. * Tests if you can safely write to a buffer's metadata or its memory array.
  399. * It is only safe to change buffer metadata when the current reference is
  400. * writable, i.e. nobody can see the modifications you will make.
  401. */
  402. #define gst_buffer_is_writable(buf) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (buf))
  403. /**
  404. * gst_buffer_make_writable:
  405. * @buf: (transfer full): a #GstBuffer
  406. *
  407. * Makes a writable buffer from the given buffer. If the source buffer is
  408. * already writable, this will simply return the same buffer. A copy will
  409. * otherwise be made using gst_buffer_copy().
  410. *
  411. * Returns: (transfer full): a writable buffer which may or may not be the
  412. * same as @buf
  413. */
  414. #define gst_buffer_make_writable(buf) GST_BUFFER_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (buf)))
  415. /**
  416. * gst_buffer_replace:
  417. * @obuf: (inout) (transfer full) (nullable): pointer to a pointer to
  418. * a #GstBuffer to be replaced.
  419. * @nbuf: (transfer none) (allow-none): pointer to a #GstBuffer that will
  420. * replace the buffer pointed to by @obuf.
  421. *
  422. * Modifies a pointer to a #GstBuffer to point to a different #GstBuffer. The
  423. * modification is done atomically (so this is useful for ensuring thread safety
  424. * in some cases), and the reference counts are updated appropriately (the old
  425. * buffer is unreffed, the new is reffed).
  426. *
  427. * Either @nbuf or the #GstBuffer pointed to by @obuf may be %NULL.
  428. *
  429. * Returns: %TRUE when @obuf was different from @nbuf.
  430. */
  431. #ifdef _FOOL_GTK_DOC_
  432. G_INLINE_FUNC gboolean gst_buffer_replace (GstBuffer **obuf, GstBuffer *nbuf);
  433. #endif
  434. static inline gboolean
  435. gst_buffer_replace (GstBuffer **obuf, GstBuffer *nbuf)
  436. {
  437. return gst_mini_object_replace ((GstMiniObject **) obuf, (GstMiniObject *) nbuf);
  438. }
  439. /* creating a region */
  440. GstBuffer* gst_buffer_copy_region (GstBuffer *parent, GstBufferCopyFlags flags,
  441. gsize offset, gsize size);
  442. /* append two buffers */
  443. GstBuffer* gst_buffer_append_region (GstBuffer *buf1, GstBuffer *buf2,
  444. gssize offset, gssize size);
  445. GstBuffer* gst_buffer_append (GstBuffer *buf1, GstBuffer *buf2);
  446. /* metadata */
  447. #include <gst/gstmeta.h>
  448. /**
  449. * GstBufferForeachMetaFunc:
  450. * @buffer: a #GstBuffer
  451. * @meta: (out) (nullable): a pointer to a #GstMeta
  452. * @user_data: user data passed to gst_buffer_foreach_meta()
  453. *
  454. * A function that will be called from gst_buffer_foreach_meta(). The @meta
  455. * field will point to a the reference of the meta.
  456. *
  457. * @buffer should not be modified from this callback.
  458. *
  459. * When this function returns %TRUE, the next meta will be
  460. * returned. When %FALSE is returned, gst_buffer_foreach_meta() will return.
  461. *
  462. * When @meta is set to %NULL, the item will be removed from the buffer.
  463. *
  464. * Returns: %FALSE when gst_buffer_foreach_meta() should stop
  465. */
  466. typedef gboolean (*GstBufferForeachMetaFunc) (GstBuffer *buffer, GstMeta **meta,
  467. gpointer user_data);
  468. GstMeta * gst_buffer_get_meta (GstBuffer *buffer, GType api);
  469. GstMeta * gst_buffer_add_meta (GstBuffer *buffer, const GstMetaInfo *info,
  470. gpointer params);
  471. gboolean gst_buffer_remove_meta (GstBuffer *buffer, GstMeta *meta);
  472. GstMeta * gst_buffer_iterate_meta (GstBuffer *buffer, gpointer *state);
  473. gboolean gst_buffer_foreach_meta (GstBuffer *buffer,
  474. GstBufferForeachMetaFunc func,
  475. gpointer user_data);
  476. /**
  477. * gst_value_set_buffer:
  478. * @v: a #GValue to receive the data
  479. * @b: (transfer none): a #GstBuffer to assign to the GstValue
  480. *
  481. * Sets @b as the value of @v. Caller retains reference to buffer.
  482. */
  483. #define gst_value_set_buffer(v,b) g_value_set_boxed((v),(b))
  484. /**
  485. * gst_value_take_buffer:
  486. * @v: a #GValue to receive the data
  487. * @b: (transfer full): a #GstBuffer to assign to the GstValue
  488. *
  489. * Sets @b as the value of @v. Caller gives away reference to buffer.
  490. */
  491. #define gst_value_take_buffer(v,b) g_value_take_boxed(v,(b))
  492. /**
  493. * gst_value_get_buffer:
  494. * @v: a #GValue to query
  495. *
  496. * Receives a #GstBuffer as the value of @v. Does not return a reference to
  497. * the buffer, so the pointer is only valid for as long as the caller owns
  498. * a reference to @v.
  499. *
  500. * Returns: (transfer none): buffer
  501. */
  502. #define gst_value_get_buffer(v) GST_BUFFER_CAST (g_value_get_boxed(v))
  503. G_END_DECLS
  504. #endif /* __GST_BUFFER_H__ */