Debian Codegraph @

gstreamer/gstreamermm/buffer.h

raw symbols SCIP
1 // Generated by gmmproc 2.50.1 -- DO NOT MODIFY!
2 #ifndef _GSTREAMERMM_BUFFER_H
3 #define _GSTREAMERMM_BUFFER_H
4
5
6 #include <glibmm/ustring.h>
7 #include <sigc++/sigc++.h>
8
9 /* gstreamermm - a C++ wrapper for gstreamer
10 *
11 * Copyright 2008-2015 The gstreamermm Development Team
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28 #include <gstreamermm/miniobject.h>
29 #include <gstreamermm/clock.h>
30 #include <gstreamermm/memory.h>
31
32
33 namespace Gst
34 {
35
36 /** @addtogroup gstreamermmEnums gstreamermm Enums and Flags */
37
38 /**
39 * @var BufferFlags BUFFER_FLAG_LIVE
40 * The buffer is live data and should be discarded in
41 * the PAUSED state.
42 *
43 * @var BufferFlags BUFFER_FLAG_DECODE_ONLY
44 * The buffer contains data that should be dropped
45 * because it will be clipped against the segment
46 * boundaries or because it does not contain data
47 * that should be shown to the user.
48 *
49 * @var BufferFlags BUFFER_FLAG_DISCONT
50 * The buffer marks a data discontinuity in the stream.
51 * This typically occurs after a seek or a dropped buffer
52 * from a live or network source.
53 *
54 * @var BufferFlags BUFFER_FLAG_RESYNC
55 * The buffer timestamps might have a discontinuity
56 * and this buffer is a good point to resynchronize.
57 *
58 * @var BufferFlags BUFFER_FLAG_CORRUPTED
59 * The buffer data is corrupted.
60 *
61 * @var BufferFlags BUFFER_FLAG_MARKER
62 * The buffer contains a media specific marker. for
63 * video this is typically the end of a frame boundary, for audio
64 * this is usually the start of a talkspurt.
65 *
66 * @var BufferFlags BUFFER_FLAG_HEADER
67 * The buffer contains header information that is
68 * needed to decode the following data.
69 *
70 * @var BufferFlags BUFFER_FLAG_GAP
71 * The buffer has been created to fill a gap in the
72 * stream and contains media neutral data (elements can
73 * switch to optimized code path that ignores the buffer
74 * content).
75 *
76 * @var BufferFlags BUFFER_FLAG_DROPPABLE
77 * The buffer can be dropped without breaking the
78 * stream, for example to reduce bandwidth.
79 *
80 * @var BufferFlags BUFFER_FLAG_DELTA_UNIT
81 * This unit cannot be decoded independently.
82 *
83 * @var BufferFlags BUFFER_FLAG_TAG_MEMORY
84 * This flag is set when memory of the buffer
85 * is added/removed.
86 *
87 * @var BufferFlags BUFFER_FLAG_SYNC_AFTER
88 * Elements which write to disk or permanent
89 * storage should ensure the data is synced after
90 * writing the contents of this buffer. (Since 1.6).
91 *
92 * @var BufferFlags BUFFER_FLAG_LAST
93 * Additional media specific flags can be added starting from
94 * this flag.
95 *
96 * @enum BufferFlags
97 *
98 * A set of buffer flags used to describe properties of a Gst::Buffer.
99 *
100 * @ingroup gstreamermmEnums
101 * @par Bitwise operators:
102 * <tt>%BufferFlags operator|(BufferFlags, BufferFlags)</tt><br>
103 * <tt>%BufferFlags operator&(BufferFlags, BufferFlags)</tt><br>
104 * <tt>%BufferFlags operator^(BufferFlags, BufferFlags)</tt><br>
105 * <tt>%BufferFlags operator~(BufferFlags)</tt><br>
106 * <tt>%BufferFlags& operator|=(BufferFlags&, BufferFlags)</tt><br>
107 * <tt>%BufferFlags& operator&=(BufferFlags&, BufferFlags)</tt><br>
108 * <tt>%BufferFlags& operator^=(BufferFlags&, BufferFlags)</tt><br>
109 */
110 enum BufferFlags
111 {
112 BUFFER_FLAG_LIVE = (GST_MINI_OBJECT_FLAG_LAST << 0),
113 BUFFER_FLAG_DECODE_ONLY = (GST_MINI_OBJECT_FLAG_LAST << 1),
114 BUFFER_FLAG_DISCONT = (GST_MINI_OBJECT_FLAG_LAST << 2),
115 BUFFER_FLAG_RESYNC = (GST_MINI_OBJECT_FLAG_LAST << 3),
116 BUFFER_FLAG_CORRUPTED = (GST_MINI_OBJECT_FLAG_LAST << 4),
117 BUFFER_FLAG_MARKER = (GST_MINI_OBJECT_FLAG_LAST << 5),
118 BUFFER_FLAG_HEADER = (GST_MINI_OBJECT_FLAG_LAST << 6),
119 BUFFER_FLAG_GAP = (GST_MINI_OBJECT_FLAG_LAST << 7),
120 BUFFER_FLAG_DROPPABLE = (GST_MINI_OBJECT_FLAG_LAST << 8),
121 BUFFER_FLAG_DELTA_UNIT = (GST_MINI_OBJECT_FLAG_LAST << 9),
122 BUFFER_FLAG_TAG_MEMORY = (GST_MINI_OBJECT_FLAG_LAST << 10),
123 BUFFER_FLAG_SYNC_AFTER = (GST_MINI_OBJECT_FLAG_LAST << 11),
124 BUFFER_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 16)
125 };
126
127 /** @ingroup gstreamermmEnums */
128 inline BufferFlags operator|(BufferFlags lhs, BufferFlags rhs)
129 { return static_cast<BufferFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
130
131 /** @ingroup gstreamermmEnums */
132 inline BufferFlags operator&(BufferFlags lhs, BufferFlags rhs)
133 { return static_cast<BufferFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
134
135 /** @ingroup gstreamermmEnums */
136 inline BufferFlags operator^(BufferFlags lhs, BufferFlags rhs)
137 { return static_cast<BufferFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
138
139 /** @ingroup gstreamermmEnums */
140 inline BufferFlags operator~(BufferFlags flags)
141 { return static_cast<BufferFlags>(~static_cast<unsigned>(flags)); }
142
143 /** @ingroup gstreamermmEnums */
144 inline BufferFlags& operator|=(BufferFlags& lhs, BufferFlags rhs)
145 { return (lhs = static_cast<BufferFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
146
147 /** @ingroup gstreamermmEnums */
148 inline BufferFlags& operator&=(BufferFlags& lhs, BufferFlags rhs)
149 { return (lhs = static_cast<BufferFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
150
151 /** @ingroup gstreamermmEnums */
152 inline BufferFlags& operator^=(BufferFlags& lhs, BufferFlags rhs)
153 { return (lhs = static_cast<BufferFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
154
155 } // namespace Gst
156
157 #ifndef DOXYGEN_SHOULD_SKIP_THIS
158 namespace Glib
159 {
160
161 template <>
162 class Value<Gst::BufferFlags> : public Glib::Value_Flags<Gst::BufferFlags>
163 {
164 public:
165 static GType value_type() G_GNUC_CONST;
166 };
167
168 } // namespace Glib
169 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
170
171 namespace Gst
172 {
173
174 /**
175 * @var BufferCopyFlags BUFFER_COPY_NONE
176 * Copy nothing.
177 *
178 * @var BufferCopyFlags BUFFER_COPY_FLAGS
179 * Flag indicating that buffer flags should be copied.
180 *
181 * @var BufferCopyFlags BUFFER_COPY_TIMESTAMPS
182 * Flag indicating that buffer pts, dts,
183 * duration, offset and offset_end should be copied.
184 *
185 * @var BufferCopyFlags BUFFER_COPY_MEMORY
186 * Flag indicating that buffer memory should be reffed
187 * and appended to already existing memory. Unless the memory is marked as
188 * NO_SHARE, no actual copy of the memory is made but it is simply reffed.
189 * Add @a GST_BUFFER_COPY_DEEP to force a real copy.
190 *
191 * @var BufferCopyFlags BUFFER_COPY_MERGE
192 * Flag indicating that buffer memory should be
193 * merged.
194 *
195 * @var BufferCopyFlags BUFFER_COPY_META
196 * Flag indicating that buffer meta should be
197 * copied.
198 *
199 * @var BufferCopyFlags BUFFER_COPY_DEEP
200 * Flag indicating that memory should always be
201 * copied instead of reffed (Since 1.2).
202 *
203 * @enum BufferCopyFlags
204 *
205 * A set of flags that can be provided to the Gst::Buffer::copy_into()
206 * function to specify which items should be copied.
207 *
208 * @ingroup gstreamermmEnums
209 * @par Bitwise operators:
210 * <tt>%BufferCopyFlags operator|(BufferCopyFlags, BufferCopyFlags)</tt><br>
211 * <tt>%BufferCopyFlags operator&(BufferCopyFlags, BufferCopyFlags)</tt><br>
212 * <tt>%BufferCopyFlags operator^(BufferCopyFlags, BufferCopyFlags)</tt><br>
213 * <tt>%BufferCopyFlags operator~(BufferCopyFlags)</tt><br>
214 * <tt>%BufferCopyFlags& operator|=(BufferCopyFlags&, BufferCopyFlags)</tt><br>
215 * <tt>%BufferCopyFlags& operator&=(BufferCopyFlags&, BufferCopyFlags)</tt><br>
216 * <tt>%BufferCopyFlags& operator^=(BufferCopyFlags&, BufferCopyFlags)</tt><br>
217 */
218 enum BufferCopyFlags
219 {
220 BUFFER_COPY_NONE = 0x0,
221 BUFFER_COPY_FLAGS = (1 << 0),
222 BUFFER_COPY_TIMESTAMPS = (1 << 1),
223 BUFFER_COPY_META = (1 << 2),
224 BUFFER_COPY_MEMORY = (1 << 3),
225 BUFFER_COPY_MERGE = (1 << 4),
226 BUFFER_COPY_DEEP = (1 << 5)
227 };
228
229 /** @ingroup gstreamermmEnums */
230 inline BufferCopyFlags operator|(BufferCopyFlags lhs, BufferCopyFlags rhs)
231 { return static_cast<BufferCopyFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
232
233 /** @ingroup gstreamermmEnums */
234 inline BufferCopyFlags operator&(BufferCopyFlags lhs, BufferCopyFlags rhs)
235 { return static_cast<BufferCopyFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
236
237 /** @ingroup gstreamermmEnums */
238 inline BufferCopyFlags operator^(BufferCopyFlags lhs, BufferCopyFlags rhs)
239 { return static_cast<BufferCopyFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
240
241 /** @ingroup gstreamermmEnums */
242 inline BufferCopyFlags operator~(BufferCopyFlags flags)
243 { return static_cast<BufferCopyFlags>(~static_cast<unsigned>(flags)); }
244
245 /** @ingroup gstreamermmEnums */
246 inline BufferCopyFlags& operator|=(BufferCopyFlags& lhs, BufferCopyFlags rhs)
247 { return (lhs = static_cast<BufferCopyFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
248
249 /** @ingroup gstreamermmEnums */
250 inline BufferCopyFlags& operator&=(BufferCopyFlags& lhs, BufferCopyFlags rhs)
251 { return (lhs = static_cast<BufferCopyFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
252
253 /** @ingroup gstreamermmEnums */
254 inline BufferCopyFlags& operator^=(BufferCopyFlags& lhs, BufferCopyFlags rhs)
255 { return (lhs = static_cast<BufferCopyFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
256
257 } // namespace Gst
258
259 #ifndef DOXYGEN_SHOULD_SKIP_THIS
260 namespace Glib
261 {
262
263 template <>
264 class Value<Gst::BufferCopyFlags> : public Glib::Value_Flags<Gst::BufferCopyFlags>
265 {
266 public:
267 static GType value_type() G_GNUC_CONST;
268 };
269
270 } // namespace Glib
271 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
272
273 namespace Gst
274 {
275
276
277 class Memory;
278
279 /**
280 * Data-passing buffer type.
281 * See also: Pad, MiniObject, Memory, Meta, BufferPool
282 *
283 * Buffers are the basic unit of data transfer in GStreamer. They contain the
284 * timing and offset along with other arbitrary metadata that is associated
285 * with the #GstMemory blocks that the buffer contains.
286 *
287 * Buffers are usually created with Gst::Buffer::create. After a buffer has been
288 * created one will typically allocate memory for it and add it to the buffer.
289 * The following example creates a buffer that can hold a given video frame
290 * with a given width, height and bits per plane.
291 *
292 * Buffers can contain a list of Gst::Memory objects. You can retrieve how many
293 * memory objects with n_memory() and you can get a pointer
294 * to memory with peek_memory()
295 *
296 * A buffer will usually have timestamps, and a duration, but neither of these
297 * are guaranteed (they may be set to #GST_CLOCK_TIME_NONE). Whenever a
298 * meaningful value can be given for these, they should be set. The timestamps
299 * and duration are measured in nanoseconds (they are Gst::ClockTime values).
300 *
301 * The buffer DTS refers to the timestamp when the buffer should be decoded and
302 * is usually monotonically increasing. The buffer PTS refers to the timestamp when
303 * the buffer content should be presented to the user and is not always
304 * monotonically increasing.
305 *
306 * A buffer can also have one or both of a start and an end offset. These are
307 * media-type specific. For video buffers, the start offset will generally be
308 * the frame number. For audio buffers, it will be the number of samples
309 * produced so far. For compressed data, it could be the byte offset in a
310 * source or destination file. Likewise, the end offset will be the offset of
311 * the end of the buffer. These can only be meaningfully interpreted if you
312 * know the media type of the buffer (the preceeding CAPS event). Either or both
313 * can be set to Gst::BUFFER_OFFSET_NONE.
314 *
315 * To efficiently create a smaller buffer out of an existing one, you can
316 * use copy_region(). This method tries to share the memory objects
317 * between the two buffers.
318 *
319 * If a plug-in wants to modify the buffer data or metadata in-place, it should
320 * first obtain a buffer that is safe to modify by using
321 * create_writable(). This function is optimized so that a copy will
322 * only be made when it is necessary.
323 *
324 * Several flags of the buffer can be set and unset with the
325 * GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use
326 * GST_BUFFER_FLAG_IS_SET() to test if a certain Gst::BufferFlag is set.
327 *
328 * Buffers can be efficiently merged into a larger buffer with
329 * append(). Copying of memory will only be done when absolutely
330 * needed.
331 *
332 * Arbitrary extra metadata can be set on a buffer with add_meta().
333 * Metadata can be retrieved with get_meta(). See also Gst::Meta
334 *
335 * An element should either unref the buffer or push it out on a src pad
336 * using Gst::Pad::push() (see Gst::Pad).
337 */
338 class Buffer : public MiniObject
339 {
340 public:
341 #ifndef DOXYGEN_SHOULD_SKIP_THIS
342 using CppObjectType = Buffer;
343 using BaseObjectType = GstBuffer;
344 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
345
346 static Glib::RefPtr<Buffer> create();
347
348 /** Increment the reference count for this object.
349 * You should never need to do this manually - use the object via a RefPtr instead.
350 */
351 void reference() const;
352
353 /** Decrement the reference count for this object.
354 * You should never need to do this manually - use the object via a RefPtr instead.
355 */
356 void unreference() const;
357
358 ///Provides access to the underlying C instance.
359 GstBuffer* gobj();
360
361 ///Provides access to the underlying C instance.
362 const GstBuffer* gobj() const;
363
364 ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
365 GstBuffer* gobj_copy() const;
366
367 Buffer() = delete;
368
369 // noncopyable
370 Buffer(const Buffer&) = delete;
371 Buffer& operator=(const Buffer&) = delete;
372
373 protected:
374 // Do not derive this. Gst::Buffer can neither be constructed nor deleted.
375
376 void operator delete(void*, std::size_t);
377
378 private:
379
380
381 public:
382
383 /** Create a copy of the given buffer. This will only copy the buffer's
384 * data to a newly allocated memory if needed (if the type of memory
385 * requires it), otherwise the underlying data is just referenced.
386 * Check copy_deep() if you want to force the data
387 * to be copied to newly allocated memory.
388 *
389 * @return A new copy of @a buf.
390 */
391 Glib::RefPtr<Gst::Buffer> copy() const;
392
393
394 /** Create a copy of the given buffer. This will make a newly allocated
395 * copy of the data the source buffer contains.
396 *
397 * @return A new copy of @a buf.
398 */
399 Glib::RefPtr<Gst::Buffer> copy_deep() const;
400
401
402 /** Copies the information from @a source_buffer into @a dest.
403 *
404 * If @a dest already contains memory and @a flags contains GST_BUFFER_COPY_MEMORY,
405 * the memory from @a source_buffer will be appended to @a dest.
406 *
407 * @a flags indicate which fields will be copied.
408 *
409 * @param dest A destination Gst::Buffer.
410 * @param source_buffer A source Gst::Buffer.
411 * @param flags Flags indicating what metadata fields should be copied.
412 * @param offset Offset to copy from.
413 * @param size Total size to copy. If -1, all data is copied.
414 * @return <tt>true</tt> if the copying succeeded, <tt>false</tt> otherwise.
415 */
416 static void copy_into(const Glib::RefPtr<Gst::Buffer>& destination_buffer, const Glib::RefPtr<Gst::Buffer>& source_buffer, BufferCopyFlags flags, gsize offset, gsize size);
417
418
419 /** Creates a sub-buffer from @a parent at @a offset and @a size.
420 * This sub-buffer uses the actual memory space of the parent buffer.
421 * This function will copy the offset and timestamp fields when the
422 * offset is 0. If not, they will be set to Gst::CLOCK_TIME_NONE and
423 * Gst::BUFFER_OFFSET_NONE.
424 * If @a offset equals 0 and @a size equals the total size of @a buffer, the
425 * duration and offset end fields are also copied. If not they will be set
426 * to Gst::CLOCK_TIME_NONE and Gst::BUFFER_OFFSET_NONE.
427 *
428 * MT safe.
429 *
430 * @param flags The Gst::BufferCopyFlags.
431 * @param offset The offset into parent Gst::Buffer at which the new sub-buffer
432 * begins.
433 * @param size The size of the new Gst::Buffer sub-buffer, in bytes. If -1, all
434 * data is copied.
435 * @return The new Gst::Buffer or <tt>nullptr</tt> if the arguments were
436 * invalid.
437 */
438 Glib::RefPtr<Gst::Buffer> copy_region(Gst::BufferCopyFlags flags, gsize offset, gsize size);
439
440 static Glib::RefPtr<Gst::Buffer> create(guint size);
441
442 /** Makes a writable buffer from the given buffer. If the source buffer is
443 * already writable, this will simply return the same buffer. A copy will
444 * otherwise be made.
445 * @return A buffer (possibly the same pointer) that is writable.
446 */
447 Glib::RefPtr<Gst::Buffer> create_writable();
448
449
450 /** Get the memory block at index @a idx in @a buffer.
451 *
452 * @param idx An index.
453 * @return A Gst::Memory that contains the data of the
454 * memory block at @a idx. Use Gst::Memory::unref() after usage.
455 */
456 Glib::RefPtr<Gst::Memory> get_memory(guint idx) const;
457
458
459 /** Get the total size of the memory blocks in @a buffer.
460 *
461 * @return Total size of the memory blocks in @a buffer.
462 */
463 gsize get_size() const;
464
465
466 /** Get the total size of the memory blocks in @a b.
467 *
468 * When not <tt>nullptr</tt>, @a offset will contain the offset of the data in the
469 * first memory block in @a buffer and @a max_size will contain the sum of
470 * the size and @a offset and the amount of extra padding on the last
471 * memory block. @a offset and @a max_size can be used to resize the
472 * buffer memory blocks with resize().
473 *
474 * @param offset A pointer to the offset.
475 * @param max_size A pointer to the maxsize.
476 * @return Total size of the memory blocks in @a buffer.
477 */
478 gsize get_sizes(gsize& offset, gsize& max_size) const;
479
480
481 /** Get the total size of @a length memory blocks stating from @a idx in @a buffer.
482 *
483 * When not <tt>nullptr</tt>, @a offset will contain the offset of the data in the
484 * memory block in @a buffer at @a idx and @a max_size will contain the sum of the size
485 * and @a offset and the amount of extra padding on the memory block at @a idx +
486 * @a length -1.
487 * @a offset and @a max_size can be used to resize the buffer memory blocks with
488 * resize_range().
489 *
490 * @param idx An index.
491 * @param length A length.
492 * @param offset A pointer to the offset.
493 * @param max_size A pointer to the maxsize.
494 * @return Total size of @a length memory blocks starting at @a idx in @a buffer.
495 */
496 gsize get_sizes_range(guint idx, gint length, gsize& offset, gsize& max_size) const;
497
498
499 /** Set the total size of the @a length memory blocks starting at @a idx in
500 * @a buffer
501 *
502 * @param idx An index.
503 * @param length A length.
504 * @param offset The offset adjustment.
505 * @param size The new size or -1 to just adjust the offset.
506 * @return <tt>true</tt> if resizing succeeded, <tt>false</tt> otherwise.
507 */
508 bool resize_range(guint idx, gint length, gssize offset, gssize size);
509
510
511 /** Set the offset and total size of the memory blocks in @a buffer.
512 *
513 * @param offset The offset adjustment.
514 * @param size The new size or -1 to just adjust the offset.
515 */
516 void resize(gssize offset, gssize size);
517
518
519 /** Set the total size of the memory blocks in @a buffer.
520 *
521 * @param size The new size.
522 */
523 void set_size(gssize size);
524
525
526 /** Get the memory block at @a idx in @a buffer. The memory block stays valid until
527 * the memory block in @a buffer is removed, replaced or merged, typically with
528 * any call that modifies the memory in @a buffer.
529 *
530 * @param idx An index.
531 * @return The Gst::Memory at @a idx.
532 */
533 Glib::RefPtr<Gst::Memory> peek_memory(guint idx);
534
535
536 /** Get the amount of memory blocks that this buffer has. This amount is never
537 * larger than what get_max_memory() returns.
538 *
539 * @return The amount of memory block in this buffer.
540 */
541 guint n_memory() const;
542
543
544 /** Insert the memory block @a mem to @a buffer at @a idx. This function takes ownership
545 * of @a mem and thus doesn't increase its refcount.
546 *
547 * Only get_max_memory() can be added to a buffer. If more memory is
548 * added, existing memory blocks will automatically be merged to make room for
549 * the new memory.
550 *
551 * @param idx The index to add the memory at, or -1 to append it to the end.
552 * @param mem A Gst::Memory.
553 */
554 void insert_memory(gint idx, Glib::RefPtr<Gst::Memory>&& mem);
555
556
557 /** Get all the memory block in @a buffer. The memory blocks will be merged
558 * into one large Gst::Memory.
559 *
560 * @return A Gst::Memory that contains the merged memory.
561 * Use Gst::Memory::unref() after usage.
562 */
563 Glib::RefPtr<Gst::Memory> get_all_memory() const;
564
565
566 /** Copy @a size bytes from @a src to @a buffer at @a offset.
567 *
568 * @param offset The offset to fill.
569 * @param src The source address.
570 * @param size The size to fill.
571 * @return The amount of bytes copied. This value can be lower than @a size
572 * when @a buffer did not contain enough data.
573 */
574 gsize fill(gsize offset, gconstpointer src, gsize size);
575
576
577 /** Replaces @a length memory blocks in @a buffer starting at @a idx with @a mem.
578 *
579 * If @a length is -1, all memory starting from @a idx will be removed and
580 * replaced with @a mem.
581 *
582 * @a buffer should be writable.
583 *
584 * @param idx An index.
585 * @param length A length should not be 0.
586 * @param mem A Gst::Memory.
587 */
588 void replace_memory_range(guint idx, gint length, Glib::RefPtr<Gst::Memory>&& mem);
589
590
591 /** Get @a length memory blocks in @a buffer starting at @a idx. The memory blocks will
592 * be merged into one large Gst::Memory.
593 *
594 * If @a length is -1, all memory starting from @a idx is merged.
595 *
596 * @param idx An index.
597 * @param length A length.
598 * @return A Gst::Memory that contains the merged data of @a length
599 * blocks starting at @a idx. Use Gst::Memory::unref() after usage.
600 */
601 Glib::RefPtr<Gst::Memory> get_memory_range(guint idx, gint length);
602
603
604 /** Remove @a length memory blocks in @a buffer starting from @a idx.
605 *
606 * @a length can be -1, in which case all memory starting from @a idx is removed.
607 *
608 * @param idx An index.
609 * @param length A length.
610 */
611 void remove_memory_range(guint idx, gint length);
612
613
614 /** Find the memory blocks that span @a size bytes starting from @a offset
615 * in @a buffer.
616 *
617 * When this function returns <tt>true</tt>, @a idx will contain the index of the first
618 * memory block where the byte for @a offset can be found and @a length contains the
619 * number of memory blocks containing the @a size remaining bytes. @a skip contains
620 * the number of bytes to skip in the memory block at @a idx to get to the byte
621 * for @a offset.
622 *
623 * @a size can be -1 to get all the memory blocks after @a idx.
624 *
625 * @param offset An offset.
626 * @param size A size.
627 * @param idx Pointer to index.
628 * @param length Pointer to length.
629 * @param skip Pointer to skip.
630 * @return <tt>true</tt> when @a size bytes starting from @a offset could be found in
631 * @a buffer and @a idx, @a length and @a skip will be filled.
632 */
633 bool find_memory(gsize offset, gsize size, guint& idx, guint& length, gsize& skip);
634
635
636 /** Prepend the memory block @a mem to @a buffer. This function takes
637 * ownership of @a mem and thus doesn't increase its refcount.
638 *
639 * This function is identical to insert_memory() with an index of 0.
640 * See insert_memory() for more details.
641 *
642 * @param mem A Gst::Memory.
643 */
644 void prepend_memory(Glib::RefPtr<Gst::Memory>&& mem);
645
646
647 /** Append the memory block @a mem to @a buffer. This function takes
648 * ownership of @a mem and thus doesn't increase its refcount.
649 *
650 * This function is identical to insert_memory() with an index of -1.
651 * See insert_memory() for more details.
652 *
653 * @param mem A Gst::Memory.
654 */
655 void append_memory(Glib::RefPtr<Gst::Memory>&& mem);
656
657
658 /** Remove the memory block in @a b at index @a i.
659 *
660 * @param idx An index.
661 */
662 void remove_memory(guint idx);
663
664
665 /** Remove all the memory blocks in @a buffer.
666 */
667 void remove_all_memory();
668
669
670 /** Fill @a buf with @a size bytes with @a val starting from @a offset.
671 *
672 * @param offset The offset in @a buffer.
673 * @param val The value to set.
674 * @param size The size to set.
675 * @return The amount of bytes filled. This value can be lower than @a size
676 * when @a buffer did not contain enough data.
677 */
678 gsize memset(gsize offset, guint8 val, gsize size);
679
680
681 /** Replaces the memory block at index @a idx in @a buffer with @a mem.
682 *
683 * @param idx An index.
684 * @param mem A Gst::Memory.
685 */
686 void replace_memory(guint idx, Glib::RefPtr<Gst::Memory>&& mem);
687
688
689 /** Replaces all memory in @a buffer with @a mem.
690 *
691 * @param mem A Gst::Memory.
692 */
693 void replace_all_memory(Glib::RefPtr<Gst::Memory>&& mem);
694
695
696 /** Copy @a size bytes starting from @a offset in @a buffer to @a dest.
697 *
698 * @param offset The offset to extract.
699 * @param dest The destination address.
700 * @param size The size to extract.
701 * @return The amount of bytes extracted. This value can be lower than @a size
702 * when @a buffer did not contain enough data.
703 */
704 gsize extract(gsize offset, gpointer dest, gsize size);
705
706
707 /** Extracts a copy of at most @a size bytes the data at @a offset into
708 * newly-allocated memory.
709 *
710 * @param offset The offset to extract.
711 * @param size The size to extract.
712 * @param dest A pointer where
713 * the destination array will be written.
714 * @param dest_size A location where the size of @a dest can be written.
715 */
716 void extract_dup(gsize offset, gsize size, gpointer& dest, gsize& dest_size);
717
718
719 /** Compare @a size bytes starting from @a offset in @a buffer with the memory in @a mem.
720 *
721 * @param offset The offset in @a buffer.
722 * @param mem The memory to compare.
723 * @param size The size to compare.
724 * @return 0 if the memory is equal.
725 */
726 int memcmp(gsize offset, gconstpointer mem, gsize size);
727
728
729 /** Check if all memory blocks in @a buffer are writable.
730 *
731 * Note that this function does not check if @a buffer is writable, use
732 * gst_buffer_is_writable() to check that if needed.
733 *
734 * @return <tt>true</tt> if all memory blocks in @a buffer are writable.
735 */
736 bool is_all_memory_writable() const;
737
738
739 /** Check if @a length memory blocks in @a buffer starting from @a idx are writable.
740 *
741 * @a length can be -1 to check all the memory blocks after @a idx.
742 *
743 * Note that this function does not check if @a buffer is writable, use
744 * gst_buffer_is_writable() to check that if needed.
745 *
746 * @param idx An index.
747 * @param length A length should not be 0.
748 * @return <tt>true</tt> if the memory range is writable.
749 */
750 bool is_memory_range_writable(guint idx, gint length) const;
751
752
753 /** This function fills @a info with the Gst::MapInfo of all merged memory
754 * blocks in @a buffer.
755 *
756 * @a flags describe the desired access of the memory. When @a flags is
757 * Gst::MAP_WRITE, @a buffer should be writable (as returned from
758 * gst_buffer_is_writable()).
759 *
760 * When @a buffer is writable but the memory isn't, a writable copy will
761 * automatically be created and returned. The readonly copy of the
762 * buffer memory will then also be replaced with this writable copy.
763 *
764 * The memory in @a info should be unmapped with unmap() after
765 * usage.
766 *
767 * @param info Info about the mapping.
768 * @param flags Flags for the mapping.
769 * @return <tt>true</tt> if the map succeeded and @a info contains valid data.
770 */
771 bool map(Gst::MapInfo& info, Gst::MapFlags flags);
772
773
774 /** This function fills @a info with the Gst::MapInfo of @a length merged memory blocks
775 * starting at @a idx in @a buffer. When @a length is -1, all memory blocks starting
776 * from @a idx are merged and mapped.
777 *
778 * @a flags describe the desired access of the memory. When @a flags is
779 * Gst::MAP_WRITE, @a buffer should be writable (as returned from
780 * gst_buffer_is_writable()).
781 *
782 * When @a buffer is writable but the memory isn't, a writable copy will
783 * automatically be created and returned. The readonly copy of the buffer memory
784 * will then also be replaced with this writable copy.
785 *
786 * The memory in @a info should be unmapped with unmap() after usage.
787 *
788 * @param idx An index.
789 * @param length A length.
790 * @param info Info about the mapping.
791 * @param flags Flags for the mapping.
792 * @return <tt>true</tt> if the map succeeded and @a info contains valid
793 * data.
794 */
795 bool map_range(guint idx, gint length, Gst::MapInfo& info, MapFlags flags);
796
797
798 /** Release the memory previously mapped with map().
799 *
800 * @param info A Gst::MapInfo.
801 */
802 void unmap(Gst::MapInfo& info);
803
804 Glib::RefPtr<Gst::Buffer> append_region(Glib::RefPtr<Gst::Buffer>&& buf, gssize offset, gssize size);
805
806
807 Glib::RefPtr<Gst::Buffer> append(Glib::RefPtr<Gst::Buffer>&& buf);
808
809
810 ClockTime get_pts() const;
811 void set_pts(const ClockTime& value);
812
813 ClockTime get_dts() const;
814 void set_dts(const ClockTime& value);
815
816 /** Get duration of this buffer.
817 * @return he duration in nanoseconds (as a Gst::ClockTime) of the data in
818 * the buffer. Value will be Gst::CLOCK_TIME_NONE if the duration is unknown.
819 */
820 ClockTime get_duration() const;
821 void set_duration(const ClockTime& value);
822 /** Get the offset of this buffer.
823 * @return The offset in the source file of the beginning of this buffer.
824 */
825 guint64 get_offset() const;
826
827 /** Get the offset end of this buffer.
828 * @return The offset in the source file of the end of this buffer.
829 */
830 guint64 get_offset_end() const;
831
832 /** Constant for no-offset return results.
833 */
834 static guint64 offset_none();
835
836
837 };
838
839 }//namespace Gst
840
841
842 namespace Glib
843 {
844
845 /** A Glib::wrap() method for this object.
846 *
847 * @param object The C instance.
848 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
849 * @result A C++ instance that wraps this C instance.
850 *
851 * @relates Gst::Buffer
852 */
853 Glib::RefPtr<Gst::Buffer> wrap(GstBuffer* object, bool take_copy = false);
854
855 } // namespace Glib
856
857
858 #endif /* _GSTREAMERMM_BUFFER_H */
859