1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gstreamer.Buffer;
26 
27 private import glib.Bytes;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import gstreamer.AllocationParams;
31 private import gstreamer.Allocator;
32 private import gstreamer.Caps;
33 private import gstreamer.Memory;
34 private import gstreamer.Meta;
35 private import gstreamer.ProtectionMeta;
36 private import gstreamer.Structure;
37 private import gstreamer.c.functions;
38 public  import gstreamer.c.types;
39 
40 
41 /**
42  * Buffers are the basic unit of data transfer in GStreamer. They contain the
43  * timing and offset along with other arbitrary metadata that is associated
44  * with the #GstMemory blocks that the buffer contains.
45  * 
46  * Buffers are usually created with gst_buffer_new(). After a buffer has been
47  * created one will typically allocate memory for it and add it to the buffer.
48  * The following example creates a buffer that can hold a given video frame
49  * with a given width, height and bits per plane.
50  * |[<!-- language="C" -->
51  * GstBuffer *buffer;
52  * GstMemory *memory;
53  * gint size, width, height, bpp;
54  * ...
55  * size = width * height * bpp;
56  * buffer = gst_buffer_new ();
57  * memory = gst_allocator_alloc (NULL, size, NULL);
58  * gst_buffer_insert_memory (buffer, -1, memory);
59  * ...
60  * ]|
61  * 
62  * Alternatively, use gst_buffer_new_allocate() to create a buffer with
63  * preallocated data of a given size.
64  * 
65  * Buffers can contain a list of #GstMemory objects. You can retrieve how many
66  * memory objects with gst_buffer_n_memory() and you can get a pointer
67  * to memory with gst_buffer_peek_memory()
68  * 
69  * A buffer will usually have timestamps, and a duration, but neither of these
70  * are guaranteed (they may be set to #GST_CLOCK_TIME_NONE). Whenever a
71  * meaningful value can be given for these, they should be set. The timestamps
72  * and duration are measured in nanoseconds (they are #GstClockTime values).
73  * 
74  * The buffer DTS refers to the timestamp when the buffer should be decoded and
75  * is usually monotonically increasing. The buffer PTS refers to the timestamp when
76  * the buffer content should be presented to the user and is not always
77  * monotonically increasing.
78  * 
79  * A buffer can also have one or both of a start and an end offset. These are
80  * media-type specific. For video buffers, the start offset will generally be
81  * the frame number. For audio buffers, it will be the number of samples
82  * produced so far. For compressed data, it could be the byte offset in a
83  * source or destination file. Likewise, the end offset will be the offset of
84  * the end of the buffer. These can only be meaningfully interpreted if you
85  * know the media type of the buffer (the preceding CAPS event). Either or both
86  * can be set to #GST_BUFFER_OFFSET_NONE.
87  * 
88  * gst_buffer_ref() is used to increase the refcount of a buffer. This must be
89  * done when you want to keep a handle to the buffer after pushing it to the
90  * next element. The buffer refcount determines the writability of the buffer, a
91  * buffer is only writable when the refcount is exactly 1, i.e. when the caller
92  * has the only reference to the buffer.
93  * 
94  * To efficiently create a smaller buffer out of an existing one, you can
95  * use gst_buffer_copy_region(). This method tries to share the memory objects
96  * between the two buffers.
97  * 
98  * If a plug-in wants to modify the buffer data or metadata in-place, it should
99  * first obtain a buffer that is safe to modify by using
100  * gst_buffer_make_writable().  This function is optimized so that a copy will
101  * only be made when it is necessary.
102  * 
103  * Several flags of the buffer can be set and unset with the
104  * GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use
105  * GST_BUFFER_FLAG_IS_SET() to test if a certain #GstBufferFlags flag is set.
106  * 
107  * Buffers can be efficiently merged into a larger buffer with
108  * gst_buffer_append(). Copying of memory will only be done when absolutely
109  * needed.
110  * 
111  * Arbitrary extra metadata can be set on a buffer with gst_buffer_add_meta().
112  * Metadata can be retrieved with gst_buffer_get_meta(). See also #GstMeta
113  * 
114  * An element should either unref the buffer or push it out on a src pad
115  * using gst_pad_push() (see #GstPad).
116  * 
117  * Buffers are usually freed by unreffing them with gst_buffer_unref(). When
118  * the refcount drops to 0, any memory and metadata pointed to by the buffer is
119  * unreffed as well. Buffers allocated from a #GstBufferPool will be returned to
120  * the pool when the refcount drops to 0.
121  * 
122  * The #GstParentBufferMeta is a meta which can be attached to a #GstBuffer
123  * to hold a reference to another buffer that is only released when the child
124  * #GstBuffer is released.
125  * 
126  * Typically, #GstParentBufferMeta is used when the child buffer is directly
127  * using the #GstMemory of the parent buffer, and wants to prevent the parent
128  * buffer from being returned to a buffer pool until the #GstMemory is available
129  * for re-use. (Since: 1.6)
130  */
131 public class Buffer
132 {
133 	/** the main Gtk struct */
134 	protected GstBuffer* gstBuffer;
135 	protected bool ownedRef;
136 
137 	/** Get the main Gtk struct */
138 	public GstBuffer* getBufferStruct(bool transferOwnership = false)
139 	{
140 		if (transferOwnership)
141 			ownedRef = false;
142 		return gstBuffer;
143 	}
144 
145 	/** the main Gtk struct as a void* */
146 	protected void* getStruct()
147 	{
148 		return cast(void*)gstBuffer;
149 	}
150 
151 	/**
152 	 * Sets our main struct and passes it to the parent class.
153 	 */
154 	public this (GstBuffer* gstBuffer, bool ownedRef = false)
155 	{
156 		this.gstBuffer = gstBuffer;
157 		this.ownedRef = ownedRef;
158 	}
159 
160 
161 	/** */
162 	public static GType getType()
163 	{
164 		return gst_buffer_get_type();
165 	}
166 
167 	/**
168 	 * Creates a newly allocated buffer without any data.
169 	 *
170 	 * MT safe.
171 	 *
172 	 * Returns: the new #GstBuffer.
173 	 *
174 	 * Throws: ConstructionException GTK+ fails to create the object.
175 	 */
176 	public this()
177 	{
178 		auto __p = gst_buffer_new();
179 
180 		if(__p is null)
181 		{
182 			throw new ConstructionException("null returned by new");
183 		}
184 
185 		this(cast(GstBuffer*) __p);
186 	}
187 
188 	/**
189 	 * Tries to create a newly allocated buffer with data of the given size and
190 	 * extra parameters from @allocator. If the requested amount of memory can't be
191 	 * allocated, %NULL will be returned. The allocated buffer memory is not cleared.
192 	 *
193 	 * When @allocator is %NULL, the default memory allocator will be used.
194 	 *
195 	 * Note that when @size == 0, the buffer will not have memory associated with it.
196 	 *
197 	 * MT safe.
198 	 *
199 	 * Params:
200 	 *     allocator = the #GstAllocator to use, or %NULL to use the
201 	 *         default allocator
202 	 *     size = the size in bytes of the new buffer's data.
203 	 *     params = optional parameters
204 	 *
205 	 * Returns: a new #GstBuffer, or %NULL if
206 	 *     the memory couldn't be allocated.
207 	 *
208 	 * Throws: ConstructionException GTK+ fails to create the object.
209 	 */
210 	public this(Allocator allocator, size_t size, AllocationParams params)
211 	{
212 		auto __p = gst_buffer_new_allocate((allocator is null) ? null : allocator.getAllocatorStruct(), size, (params is null) ? null : params.getAllocationParamsStruct());
213 
214 		if(__p is null)
215 		{
216 			throw new ConstructionException("null returned by new_allocate");
217 		}
218 
219 		this(cast(GstBuffer*) __p);
220 	}
221 
222 	/**
223 	 * Creates a new buffer that wraps the given @data. The memory will be freed
224 	 * with g_free and will be marked writable.
225 	 *
226 	 * MT safe.
227 	 *
228 	 * Params:
229 	 *     data = data to wrap
230 	 *
231 	 * Returns: a new #GstBuffer
232 	 *
233 	 * Throws: ConstructionException GTK+ fails to create the object.
234 	 */
235 	public this(ubyte[] data)
236 	{
237 		auto __p = gst_buffer_new_wrapped(data.ptr, cast(size_t)data.length);
238 
239 		if(__p is null)
240 		{
241 			throw new ConstructionException("null returned by new_wrapped");
242 		}
243 
244 		this(cast(GstBuffer*) __p);
245 	}
246 
247 	/**
248 	 * Creates a new #GstBuffer that wraps the given @bytes. The data inside
249 	 * @bytes cannot be %NULL and the resulting buffer will be marked as read only.
250 	 *
251 	 * MT safe.
252 	 *
253 	 * Params:
254 	 *     bytes = a #GBytes to wrap
255 	 *
256 	 * Returns: a new #GstBuffer wrapping @bytes
257 	 *
258 	 * Since: 1.16
259 	 *
260 	 * Throws: ConstructionException GTK+ fails to create the object.
261 	 */
262 	public this(Bytes bytes)
263 	{
264 		auto __p = gst_buffer_new_wrapped_bytes((bytes is null) ? null : bytes.getBytesStruct());
265 
266 		if(__p is null)
267 		{
268 			throw new ConstructionException("null returned by new_wrapped_bytes");
269 		}
270 
271 		this(cast(GstBuffer*) __p);
272 	}
273 
274 	/**
275 	 * Allocate a new buffer that wraps the given memory. @data must point to
276 	 * @maxsize of memory, the wrapped buffer will have the region from @offset and
277 	 * @size visible.
278 	 *
279 	 * When the buffer is destroyed, @notify will be called with @user_data.
280 	 *
281 	 * The prefix/padding must be filled with 0 if @flags contains
282 	 * #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively.
283 	 *
284 	 * Params:
285 	 *     flags = #GstMemoryFlags
286 	 *     data = data to wrap
287 	 *     maxsize = allocated size of @data
288 	 *     offset = offset in @data
289 	 *     userData = user_data
290 	 *     notify = called with @user_data when the memory is freed
291 	 *
292 	 * Returns: a new #GstBuffer
293 	 *
294 	 * Throws: ConstructionException GTK+ fails to create the object.
295 	 */
296 	public this(GstMemoryFlags flags, ubyte[] data, size_t maxsize, size_t offset, void* userData, GDestroyNotify notify)
297 	{
298 		auto __p = gst_buffer_new_wrapped_full(flags, data.ptr, maxsize, offset, cast(size_t)data.length, userData, notify);
299 
300 		if(__p is null)
301 		{
302 			throw new ConstructionException("null returned by new_wrapped_full");
303 		}
304 
305 		this(cast(GstBuffer*) __p);
306 	}
307 
308 	/**
309 	 * Add metadata for @info to @buffer using the parameters in @params.
310 	 *
311 	 * Params:
312 	 *     info = a #GstMetaInfo
313 	 *     params = params for @info
314 	 *
315 	 * Returns: the metadata for the api in @info on @buffer.
316 	 */
317 	public Meta addMeta(GstMetaInfo* info, void* params)
318 	{
319 		auto __p = gst_buffer_add_meta(gstBuffer, info, params);
320 
321 		if(__p is null)
322 		{
323 			return null;
324 		}
325 
326 		return ObjectG.getDObject!(Meta)(cast(GstMeta*) __p);
327 	}
328 
329 	/**
330 	 * Add a #GstParentBufferMeta to @buffer that holds a reference on
331 	 * @ref until the buffer is freed.
332 	 *
333 	 * Params:
334 	 *     ref_ = a #GstBuffer to ref
335 	 *
336 	 * Returns: The #GstParentBufferMeta that was added to the buffer
337 	 *
338 	 * Since: 1.6
339 	 */
340 	public GstParentBufferMeta* addParentBufferMeta(Buffer ref_)
341 	{
342 		return gst_buffer_add_parent_buffer_meta(gstBuffer, (ref_ is null) ? null : ref_.getBufferStruct());
343 	}
344 
345 	/**
346 	 * Attaches protection metadata to a #GstBuffer.
347 	 *
348 	 * Params:
349 	 *     info = a #GstStructure holding cryptographic
350 	 *         information relating to the sample contained in @buffer. This
351 	 *         function takes ownership of @info.
352 	 *
353 	 * Returns: a pointer to the added #GstProtectionMeta if successful; %NULL if
354 	 *     unsuccessful.
355 	 *
356 	 * Since: 1.6
357 	 */
358 	public ProtectionMeta addProtectionMeta(Structure info)
359 	{
360 		auto __p = gst_buffer_add_protection_meta(gstBuffer, (info is null) ? null : info.getStructureStruct(true));
361 
362 		if(__p is null)
363 		{
364 			return null;
365 		}
366 
367 		return ObjectG.getDObject!(ProtectionMeta)(cast(GstProtectionMeta*) __p);
368 	}
369 
370 	/**
371 	 * Add a #GstReferenceTimestampMeta to @buffer that holds a @timestamp and
372 	 * optionally @duration based on a specific timestamp @reference. See the
373 	 * documentation of #GstReferenceTimestampMeta for details.
374 	 *
375 	 * Params:
376 	 *     reference = identifier for the timestamp reference.
377 	 *     timestamp = timestamp
378 	 *     duration = duration, or %GST_CLOCK_TIME_NONE
379 	 *
380 	 * Returns: The #GstReferenceTimestampMeta that was added to the buffer
381 	 *
382 	 * Since: 1.14
383 	 */
384 	public GstReferenceTimestampMeta* addReferenceTimestampMeta(Caps reference, GstClockTime timestamp, GstClockTime duration)
385 	{
386 		return gst_buffer_add_reference_timestamp_meta(gstBuffer, (reference is null) ? null : reference.getCapsStruct(), timestamp, duration);
387 	}
388 
389 	/**
390 	 * Append all the memory from @buf2 to @buf1. The result buffer will contain a
391 	 * concatenation of the memory of @buf1 and @buf2.
392 	 *
393 	 * Params:
394 	 *     buf2 = the second source #GstBuffer to append.
395 	 *
396 	 * Returns: the new #GstBuffer that contains the memory
397 	 *     of the two source buffers.
398 	 */
399 	public Buffer append(Buffer buf2)
400 	{
401 		auto __p = gst_buffer_append(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct());
402 
403 		if(__p is null)
404 		{
405 			return null;
406 		}
407 
408 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
409 	}
410 
411 	/**
412 	 * Append the memory block @mem to @buffer. This function takes
413 	 * ownership of @mem and thus doesn't increase its refcount.
414 	 *
415 	 * This function is identical to gst_buffer_insert_memory() with an index of -1.
416 	 * See gst_buffer_insert_memory() for more details.
417 	 *
418 	 * Params:
419 	 *     mem = a #GstMemory.
420 	 */
421 	public void appendMemory(Memory mem)
422 	{
423 		gst_buffer_append_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
424 	}
425 
426 	/**
427 	 * Append @size bytes at @offset from @buf2 to @buf1. The result buffer will
428 	 * contain a concatenation of the memory of @buf1 and the requested region of
429 	 * @buf2.
430 	 *
431 	 * Params:
432 	 *     buf2 = the second source #GstBuffer to append.
433 	 *     offset = the offset in @buf2
434 	 *     size = the size or -1 of @buf2
435 	 *
436 	 * Returns: the new #GstBuffer that contains the memory
437 	 *     of the two source buffers.
438 	 */
439 	public Buffer appendRegion(Buffer buf2, ptrdiff_t offset, ptrdiff_t size)
440 	{
441 		auto __p = gst_buffer_append_region(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct(), offset, size);
442 
443 		if(__p is null)
444 		{
445 			return null;
446 		}
447 
448 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
449 	}
450 
451 	/**
452 	 * Create a copy of the given buffer. This will make a newly allocated
453 	 * copy of the data the source buffer contains.
454 	 *
455 	 * Returns: a new copy of @buf.
456 	 *
457 	 * Since: 1.6
458 	 */
459 	public Buffer copyDeep()
460 	{
461 		auto __p = gst_buffer_copy_deep(gstBuffer);
462 
463 		if(__p is null)
464 		{
465 			return null;
466 		}
467 
468 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
469 	}
470 
471 	/**
472 	 * Copies the information from @src into @dest.
473 	 *
474 	 * If @dest already contains memory and @flags contains GST_BUFFER_COPY_MEMORY,
475 	 * the memory from @src will be appended to @dest.
476 	 *
477 	 * @flags indicate which fields will be copied.
478 	 *
479 	 * Params:
480 	 *     src = a source #GstBuffer
481 	 *     flags = flags indicating what metadata fields should be copied.
482 	 *     offset = offset to copy from
483 	 *     size = total size to copy. If -1, all data is copied.
484 	 *
485 	 * Returns: %TRUE if the copying succeeded, %FALSE otherwise.
486 	 */
487 	public bool copyInto(Buffer src, GstBufferCopyFlags flags, size_t offset, size_t size)
488 	{
489 		return gst_buffer_copy_into(gstBuffer, (src is null) ? null : src.getBufferStruct(), flags, offset, size) != 0;
490 	}
491 
492 	/**
493 	 * Creates a sub-buffer from @parent at @offset and @size.
494 	 * This sub-buffer uses the actual memory space of the parent buffer.
495 	 * This function will copy the offset and timestamp fields when the
496 	 * offset is 0. If not, they will be set to #GST_CLOCK_TIME_NONE and
497 	 * #GST_BUFFER_OFFSET_NONE.
498 	 * If @offset equals 0 and @size equals the total size of @buffer, the
499 	 * duration and offset end fields are also copied. If not they will be set
500 	 * to #GST_CLOCK_TIME_NONE and #GST_BUFFER_OFFSET_NONE.
501 	 *
502 	 * MT safe.
503 	 *
504 	 * Params:
505 	 *     flags = the #GstBufferCopyFlags
506 	 *     offset = the offset into parent #GstBuffer at which the new sub-buffer
507 	 *         begins.
508 	 *     size = the size of the new #GstBuffer sub-buffer, in bytes. If -1, all
509 	 *         data is copied.
510 	 *
511 	 * Returns: the new #GstBuffer or %NULL if the arguments were
512 	 *     invalid.
513 	 */
514 	public Buffer copyRegion(GstBufferCopyFlags flags, size_t offset, size_t size)
515 	{
516 		auto __p = gst_buffer_copy_region(gstBuffer, flags, offset, size);
517 
518 		if(__p is null)
519 		{
520 			return null;
521 		}
522 
523 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
524 	}
525 
526 	/**
527 	 * Copy @size bytes starting from @offset in @buffer to @dest.
528 	 *
529 	 * Params:
530 	 *     offset = the offset to extract
531 	 *     dest = the destination address
532 	 *
533 	 * Returns: The amount of bytes extracted. This value can be lower than @size
534 	 *     when @buffer did not contain enough data.
535 	 */
536 	public size_t extract(size_t offset, ubyte[] dest)
537 	{
538 		return gst_buffer_extract(gstBuffer, offset, dest.ptr, cast(size_t)dest.length);
539 	}
540 
541 	/**
542 	 * Extracts a copy of at most @size bytes the data at @offset into
543 	 * newly-allocated memory. @dest must be freed using g_free() when done.
544 	 *
545 	 * Params:
546 	 *     offset = the offset to extract
547 	 *     size = the size to extract
548 	 *     dest = A pointer where
549 	 *         the destination array will be written. Might be %NULL if the size is 0.
550 	 *
551 	 * Since: 1.0.10
552 	 */
553 	public void extractDup(size_t offset, size_t size, out ubyte[] dest)
554 	{
555 		ubyte* outdest;
556 		size_t destSize;
557 
558 		gst_buffer_extract_dup(gstBuffer, offset, size, cast(void**)&outdest, &destSize);
559 
560 		dest = outdest[0 .. destSize];
561 	}
562 
563 	/**
564 	 * Copy @size bytes from @src to @buffer at @offset.
565 	 *
566 	 * Params:
567 	 *     offset = the offset to fill
568 	 *     src = the source address
569 	 *
570 	 * Returns: The amount of bytes copied. This value can be lower than @size
571 	 *     when @buffer did not contain enough data.
572 	 */
573 	public size_t fill(size_t offset, ubyte[] src)
574 	{
575 		return gst_buffer_fill(gstBuffer, offset, src.ptr, cast(size_t)src.length);
576 	}
577 
578 	/**
579 	 * Find the memory blocks that span @size bytes starting from @offset
580 	 * in @buffer.
581 	 *
582 	 * When this function returns %TRUE, @idx will contain the index of the first
583 	 * memory block where the byte for @offset can be found and @length contains the
584 	 * number of memory blocks containing the @size remaining bytes. @skip contains
585 	 * the number of bytes to skip in the memory block at @idx to get to the byte
586 	 * for @offset.
587 	 *
588 	 * @size can be -1 to get all the memory blocks after @idx.
589 	 *
590 	 * Params:
591 	 *     offset = an offset
592 	 *     size = a size
593 	 *     idx = pointer to index
594 	 *     length = pointer to length
595 	 *     skip = pointer to skip
596 	 *
597 	 * Returns: %TRUE when @size bytes starting from @offset could be found in
598 	 *     @buffer and @idx, @length and @skip will be filled.
599 	 */
600 	public bool findMemory(size_t offset, size_t size, out uint idx, out uint length, out size_t skip)
601 	{
602 		return gst_buffer_find_memory(gstBuffer, offset, size, &idx, &length, &skip) != 0;
603 	}
604 
605 	/**
606 	 * Call @func with @user_data for each meta in @buffer.
607 	 *
608 	 * @func can modify the passed meta pointer or its contents. The return value
609 	 * of @func define if this function returns or if the remaining metadata items
610 	 * in the buffer should be skipped.
611 	 *
612 	 * Params:
613 	 *     func = a #GstBufferForeachMetaFunc to call
614 	 *     userData = user data passed to @func
615 	 *
616 	 * Returns: %FALSE when @func returned %FALSE for one of the metadata.
617 	 */
618 	public bool foreachMeta(GstBufferForeachMetaFunc func, void* userData)
619 	{
620 		return gst_buffer_foreach_meta(gstBuffer, func, userData) != 0;
621 	}
622 
623 	/**
624 	 * Get all the memory block in @buffer. The memory blocks will be merged
625 	 * into one large #GstMemory.
626 	 *
627 	 * Returns: a #GstMemory that contains the merged memory.
628 	 *     Use gst_memory_unref () after usage.
629 	 */
630 	public Memory getAllMemory()
631 	{
632 		auto __p = gst_buffer_get_all_memory(gstBuffer);
633 
634 		if(__p is null)
635 		{
636 			return null;
637 		}
638 
639 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) __p, true);
640 	}
641 
642 	/**
643 	 * Get the #GstBufferFlags flags set on this buffer.
644 	 *
645 	 * Returns: the flags set on this buffer.
646 	 *
647 	 * Since: 1.10
648 	 */
649 	public GstBufferFlags getFlags()
650 	{
651 		return gst_buffer_get_flags(gstBuffer);
652 	}
653 
654 	/**
655 	 * Get the memory block at index @idx in @buffer.
656 	 *
657 	 * Params:
658 	 *     idx = an index
659 	 *
660 	 * Returns: a #GstMemory that contains the data of the
661 	 *     memory block at @idx. Use gst_memory_unref () after usage.
662 	 */
663 	public Memory getMemory(uint idx)
664 	{
665 		auto __p = gst_buffer_get_memory(gstBuffer, idx);
666 
667 		if(__p is null)
668 		{
669 			return null;
670 		}
671 
672 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) __p, true);
673 	}
674 
675 	/**
676 	 * Get @length memory blocks in @buffer starting at @idx. The memory blocks will
677 	 * be merged into one large #GstMemory.
678 	 *
679 	 * If @length is -1, all memory starting from @idx is merged.
680 	 *
681 	 * Params:
682 	 *     idx = an index
683 	 *     length = a length
684 	 *
685 	 * Returns: a #GstMemory that contains the merged data of @length
686 	 *     blocks starting at @idx. Use gst_memory_unref () after usage.
687 	 */
688 	public Memory getMemoryRange(uint idx, int length)
689 	{
690 		auto __p = gst_buffer_get_memory_range(gstBuffer, idx, length);
691 
692 		if(__p is null)
693 		{
694 			return null;
695 		}
696 
697 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) __p, true);
698 	}
699 
700 	/**
701 	 * Get the metadata for @api on buffer. When there is no such metadata, %NULL is
702 	 * returned. If multiple metadata with the given @api are attached to this
703 	 * buffer only the first one is returned.  To handle multiple metadata with a
704 	 * given API use gst_buffer_iterate_meta() or gst_buffer_foreach_meta() instead
705 	 * and check the meta->info.api member for the API type.
706 	 *
707 	 * Params:
708 	 *     api = the #GType of an API
709 	 *
710 	 * Returns: the metadata for @api on
711 	 *     @buffer.
712 	 */
713 	public Meta getMeta(GType api)
714 	{
715 		auto __p = gst_buffer_get_meta(gstBuffer, api);
716 
717 		if(__p is null)
718 		{
719 			return null;
720 		}
721 
722 		return ObjectG.getDObject!(Meta)(cast(GstMeta*) __p);
723 	}
724 
725 	/**
726 	 *
727 	 * Params:
728 	 *     apiType = the #GType of an API
729 	 * Returns: number of metas of type @api_type on @buffer.
730 	 *
731 	 * Since: 1.14
732 	 */
733 	public uint getNMeta(GType apiType)
734 	{
735 		return gst_buffer_get_n_meta(gstBuffer, apiType);
736 	}
737 
738 	/**
739 	 * Find the first #GstReferenceTimestampMeta on @buffer that conforms to
740 	 * @reference. Conformance is tested by checking if the meta's reference is a
741 	 * subset of @reference.
742 	 *
743 	 * Buffers can contain multiple #GstReferenceTimestampMeta metadata items.
744 	 *
745 	 * Params:
746 	 *     reference = a reference #GstCaps
747 	 *
748 	 * Returns: the #GstReferenceTimestampMeta or %NULL when there
749 	 *     is no such metadata on @buffer.
750 	 *
751 	 * Since: 1.14
752 	 */
753 	public GstReferenceTimestampMeta* getReferenceTimestampMeta(Caps reference)
754 	{
755 		return gst_buffer_get_reference_timestamp_meta(gstBuffer, (reference is null) ? null : reference.getCapsStruct());
756 	}
757 
758 	/**
759 	 * Get the total size of the memory blocks in @buffer.
760 	 *
761 	 * Returns: total size of the memory blocks in @buffer.
762 	 */
763 	public size_t getSize()
764 	{
765 		return gst_buffer_get_size(gstBuffer);
766 	}
767 
768 	/**
769 	 * Get the total size of the memory blocks in @b.
770 	 *
771 	 * When not %NULL, @offset will contain the offset of the data in the
772 	 * first memory block in @buffer and @maxsize will contain the sum of
773 	 * the size and @offset and the amount of extra padding on the last
774 	 * memory block.  @offset and @maxsize can be used to resize the
775 	 * buffer memory blocks with gst_buffer_resize().
776 	 *
777 	 * Params:
778 	 *     offset = a pointer to the offset
779 	 *     maxsize = a pointer to the maxsize
780 	 *
781 	 * Returns: total size of the memory blocks in @buffer.
782 	 */
783 	public size_t getSizes(out size_t offset, out size_t maxsize)
784 	{
785 		return gst_buffer_get_sizes(gstBuffer, &offset, &maxsize);
786 	}
787 
788 	/**
789 	 * Get the total size of @length memory blocks stating from @idx in @buffer.
790 	 *
791 	 * When not %NULL, @offset will contain the offset of the data in the
792 	 * memory block in @buffer at @idx and @maxsize will contain the sum of the size
793 	 * and @offset and the amount of extra padding on the memory block at @idx +
794 	 * @length -1.
795 	 * @offset and @maxsize can be used to resize the buffer memory blocks with
796 	 * gst_buffer_resize_range().
797 	 *
798 	 * Params:
799 	 *     idx = an index
800 	 *     length = a length
801 	 *     offset = a pointer to the offset
802 	 *     maxsize = a pointer to the maxsize
803 	 *
804 	 * Returns: total size of @length memory blocks starting at @idx in @buffer.
805 	 */
806 	public size_t getSizesRange(uint idx, int length, out size_t offset, out size_t maxsize)
807 	{
808 		return gst_buffer_get_sizes_range(gstBuffer, idx, length, &offset, &maxsize);
809 	}
810 
811 	/**
812 	 * Gives the status of a specific flag on a buffer.
813 	 *
814 	 * Params:
815 	 *     flags = the #GstBufferFlags flag to check.
816 	 *
817 	 * Returns: %TRUE if all flags in @flags are found on @buffer.
818 	 *
819 	 * Since: 1.10
820 	 */
821 	public bool hasFlags(GstBufferFlags flags)
822 	{
823 		return gst_buffer_has_flags(gstBuffer, flags) != 0;
824 	}
825 
826 	/**
827 	 * Insert the memory block @mem to @buffer at @idx. This function takes ownership
828 	 * of @mem and thus doesn't increase its refcount.
829 	 *
830 	 * Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is
831 	 * added, existing memory blocks will automatically be merged to make room for
832 	 * the new memory.
833 	 *
834 	 * Params:
835 	 *     idx = the index to add the memory at, or -1 to append it to the end
836 	 *     mem = a #GstMemory.
837 	 */
838 	public void insertMemory(int idx, Memory mem)
839 	{
840 		gst_buffer_insert_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct());
841 	}
842 
843 	/**
844 	 * Check if all memory blocks in @buffer are writable.
845 	 *
846 	 * Note that this function does not check if @buffer is writable, use
847 	 * gst_buffer_is_writable() to check that if needed.
848 	 *
849 	 * Returns: %TRUE if all memory blocks in @buffer are writable
850 	 *
851 	 * Since: 1.4
852 	 */
853 	public bool isAllMemoryWritable()
854 	{
855 		return gst_buffer_is_all_memory_writable(gstBuffer) != 0;
856 	}
857 
858 	/**
859 	 * Check if @length memory blocks in @buffer starting from @idx are writable.
860 	 *
861 	 * @length can be -1 to check all the memory blocks after @idx.
862 	 *
863 	 * Note that this function does not check if @buffer is writable, use
864 	 * gst_buffer_is_writable() to check that if needed.
865 	 *
866 	 * Params:
867 	 *     idx = an index
868 	 *     length = a length should not be 0
869 	 *
870 	 * Returns: %TRUE if the memory range is writable
871 	 *
872 	 * Since: 1.4
873 	 */
874 	public bool isMemoryRangeWritable(uint idx, int length)
875 	{
876 		return gst_buffer_is_memory_range_writable(gstBuffer, idx, length) != 0;
877 	}
878 
879 	/**
880 	 * Retrieve the next #GstMeta after @current. If @state points
881 	 * to %NULL, the first metadata is returned.
882 	 *
883 	 * @state will be updated with an opaque state pointer
884 	 *
885 	 * Params:
886 	 *     state = an opaque state pointer
887 	 *
888 	 * Returns: The next #GstMeta or %NULL
889 	 *     when there are no more items.
890 	 */
891 	public Meta iterateMeta(out void* state)
892 	{
893 		auto __p = gst_buffer_iterate_meta(gstBuffer, &state);
894 
895 		if(__p is null)
896 		{
897 			return null;
898 		}
899 
900 		return ObjectG.getDObject!(Meta)(cast(GstMeta*) __p);
901 	}
902 
903 	/**
904 	 * Retrieve the next #GstMeta of type @meta_api_type after the current one
905 	 * according to @state. If @state points to %NULL, the first metadata of
906 	 * type @meta_api_type is returned.
907 	 *
908 	 * @state will be updated with an opaque state pointer
909 	 *
910 	 * Params:
911 	 *     state = an opaque state pointer
912 	 *     metaApiType = only return #GstMeta of this type
913 	 *
914 	 * Returns: The next #GstMeta of type
915 	 *     @meta_api_type or %NULL when there are no more items.
916 	 *
917 	 * Since: 1.12
918 	 */
919 	public Meta iterateMetaFiltered(out void* state, GType metaApiType)
920 	{
921 		auto __p = gst_buffer_iterate_meta_filtered(gstBuffer, &state, metaApiType);
922 
923 		if(__p is null)
924 		{
925 			return null;
926 		}
927 
928 		return ObjectG.getDObject!(Meta)(cast(GstMeta*) __p);
929 	}
930 
931 	/**
932 	 * This function fills @info with the #GstMapInfo of all merged memory
933 	 * blocks in @buffer.
934 	 *
935 	 * @flags describe the desired access of the memory. When @flags is
936 	 * #GST_MAP_WRITE, @buffer should be writable (as returned from
937 	 * gst_buffer_is_writable()).
938 	 *
939 	 * When @buffer is writable but the memory isn't, a writable copy will
940 	 * automatically be created and returned. The readonly copy of the
941 	 * buffer memory will then also be replaced with this writable copy.
942 	 *
943 	 * The memory in @info should be unmapped with gst_buffer_unmap() after
944 	 * usage.
945 	 *
946 	 * Params:
947 	 *     info = info about the mapping
948 	 *     flags = flags for the mapping
949 	 *
950 	 * Returns: %TRUE if the map succeeded and @info contains valid data.
951 	 */
952 	public bool map(out GstMapInfo info, GstMapFlags flags)
953 	{
954 		return gst_buffer_map(gstBuffer, &info, flags) != 0;
955 	}
956 
957 	/**
958 	 * This function fills @info with the #GstMapInfo of @length merged memory blocks
959 	 * starting at @idx in @buffer. When @length is -1, all memory blocks starting
960 	 * from @idx are merged and mapped.
961 	 *
962 	 * @flags describe the desired access of the memory. When @flags is
963 	 * #GST_MAP_WRITE, @buffer should be writable (as returned from
964 	 * gst_buffer_is_writable()).
965 	 *
966 	 * When @buffer is writable but the memory isn't, a writable copy will
967 	 * automatically be created and returned. The readonly copy of the buffer memory
968 	 * will then also be replaced with this writable copy.
969 	 *
970 	 * The memory in @info should be unmapped with gst_buffer_unmap() after usage.
971 	 *
972 	 * Params:
973 	 *     idx = an index
974 	 *     length = a length
975 	 *     info = info about the mapping
976 	 *     flags = flags for the mapping
977 	 *
978 	 * Returns: %TRUE if the map succeeded and @info contains valid
979 	 *     data.
980 	 */
981 	public bool mapRange(uint idx, int length, out GstMapInfo info, GstMapFlags flags)
982 	{
983 		return gst_buffer_map_range(gstBuffer, idx, length, &info, flags) != 0;
984 	}
985 
986 	/**
987 	 * Compare @size bytes starting from @offset in @buffer with the memory in @mem.
988 	 *
989 	 * Params:
990 	 *     offset = the offset in @buffer
991 	 *     mem = the memory to compare
992 	 *
993 	 * Returns: 0 if the memory is equal.
994 	 */
995 	public int memcmp(size_t offset, ubyte[] mem)
996 	{
997 		return gst_buffer_memcmp(gstBuffer, offset, mem.ptr, cast(size_t)mem.length);
998 	}
999 
1000 	/**
1001 	 * Fill @buf with @size bytes with @val starting from @offset.
1002 	 *
1003 	 * Params:
1004 	 *     offset = the offset in @buffer
1005 	 *     val = the value to set
1006 	 *     size = the size to set
1007 	 *
1008 	 * Returns: The amount of bytes filled. This value can be lower than @size
1009 	 *     when @buffer did not contain enough data.
1010 	 */
1011 	public size_t memset(size_t offset, ubyte val, size_t size)
1012 	{
1013 		return gst_buffer_memset(gstBuffer, offset, val, size);
1014 	}
1015 
1016 	/**
1017 	 * Get the amount of memory blocks that this buffer has. This amount is never
1018 	 * larger than what gst_buffer_get_max_memory() returns.
1019 	 *
1020 	 * Returns: the number of memory blocks this buffer is made of.
1021 	 */
1022 	public uint nMemory()
1023 	{
1024 		return gst_buffer_n_memory(gstBuffer);
1025 	}
1026 
1027 	/**
1028 	 * Get the memory block at @idx in @buffer. The memory block stays valid until
1029 	 * the memory block in @buffer is removed, replaced or merged, typically with
1030 	 * any call that modifies the memory in @buffer.
1031 	 *
1032 	 * Params:
1033 	 *     idx = an index
1034 	 *
1035 	 * Returns: the #GstMemory at @idx.
1036 	 */
1037 	public Memory peekMemory(uint idx)
1038 	{
1039 		auto __p = gst_buffer_peek_memory(gstBuffer, idx);
1040 
1041 		if(__p is null)
1042 		{
1043 			return null;
1044 		}
1045 
1046 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) __p);
1047 	}
1048 
1049 	/**
1050 	 * Prepend the memory block @mem to @buffer. This function takes
1051 	 * ownership of @mem and thus doesn't increase its refcount.
1052 	 *
1053 	 * This function is identical to gst_buffer_insert_memory() with an index of 0.
1054 	 * See gst_buffer_insert_memory() for more details.
1055 	 *
1056 	 * Params:
1057 	 *     mem = a #GstMemory.
1058 	 */
1059 	public void prependMemory(Memory mem)
1060 	{
1061 		gst_buffer_prepend_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
1062 	}
1063 
1064 	/**
1065 	 * Remove all the memory blocks in @buffer.
1066 	 */
1067 	public void removeAllMemory()
1068 	{
1069 		gst_buffer_remove_all_memory(gstBuffer);
1070 	}
1071 
1072 	/**
1073 	 * Remove the memory block in @b at index @i.
1074 	 *
1075 	 * Params:
1076 	 *     idx = an index
1077 	 */
1078 	public void removeMemory(uint idx)
1079 	{
1080 		gst_buffer_remove_memory(gstBuffer, idx);
1081 	}
1082 
1083 	/**
1084 	 * Remove @length memory blocks in @buffer starting from @idx.
1085 	 *
1086 	 * @length can be -1, in which case all memory starting from @idx is removed.
1087 	 *
1088 	 * Params:
1089 	 *     idx = an index
1090 	 *     length = a length
1091 	 */
1092 	public void removeMemoryRange(uint idx, int length)
1093 	{
1094 		gst_buffer_remove_memory_range(gstBuffer, idx, length);
1095 	}
1096 
1097 	/**
1098 	 * Remove the metadata for @meta on @buffer.
1099 	 *
1100 	 * Params:
1101 	 *     meta = a #GstMeta
1102 	 *
1103 	 * Returns: %TRUE if the metadata existed and was removed, %FALSE if no such
1104 	 *     metadata was on @buffer.
1105 	 */
1106 	public bool removeMeta(Meta meta)
1107 	{
1108 		return gst_buffer_remove_meta(gstBuffer, (meta is null) ? null : meta.getMetaStruct()) != 0;
1109 	}
1110 
1111 	/**
1112 	 * Replaces all memory in @buffer with @mem.
1113 	 *
1114 	 * Params:
1115 	 *     mem = a #GstMemory
1116 	 */
1117 	public void replaceAllMemory(Memory mem)
1118 	{
1119 		gst_buffer_replace_all_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
1120 	}
1121 
1122 	/**
1123 	 * Replaces the memory block at index @idx in @buffer with @mem.
1124 	 *
1125 	 * Params:
1126 	 *     idx = an index
1127 	 *     mem = a #GstMemory
1128 	 */
1129 	public void replaceMemory(uint idx, Memory mem)
1130 	{
1131 		gst_buffer_replace_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct());
1132 	}
1133 
1134 	/**
1135 	 * Replaces @length memory blocks in @buffer starting at @idx with @mem.
1136 	 *
1137 	 * If @length is -1, all memory starting from @idx will be removed and
1138 	 * replaced with @mem.
1139 	 *
1140 	 * @buffer should be writable.
1141 	 *
1142 	 * Params:
1143 	 *     idx = an index
1144 	 *     length = a length should not be 0
1145 	 *     mem = a #GstMemory
1146 	 */
1147 	public void replaceMemoryRange(uint idx, int length, Memory mem)
1148 	{
1149 		gst_buffer_replace_memory_range(gstBuffer, idx, length, (mem is null) ? null : mem.getMemoryStruct());
1150 	}
1151 
1152 	/**
1153 	 * Set the offset and total size of the memory blocks in @buffer.
1154 	 *
1155 	 * Params:
1156 	 *     offset = the offset adjustment
1157 	 *     size = the new size or -1 to just adjust the offset
1158 	 */
1159 	public void resize(ptrdiff_t offset, ptrdiff_t size)
1160 	{
1161 		gst_buffer_resize(gstBuffer, offset, size);
1162 	}
1163 
1164 	/**
1165 	 * Set the total size of the @length memory blocks starting at @idx in
1166 	 * @buffer
1167 	 *
1168 	 * Params:
1169 	 *     idx = an index
1170 	 *     length = a length
1171 	 *     offset = the offset adjustment
1172 	 *     size = the new size or -1 to just adjust the offset
1173 	 *
1174 	 * Returns: %TRUE if resizing succeeded, %FALSE otherwise.
1175 	 */
1176 	public bool resizeRange(uint idx, int length, ptrdiff_t offset, ptrdiff_t size)
1177 	{
1178 		return gst_buffer_resize_range(gstBuffer, idx, length, offset, size) != 0;
1179 	}
1180 
1181 	/**
1182 	 * Sets one or more buffer flags on a buffer.
1183 	 *
1184 	 * Params:
1185 	 *     flags = the #GstBufferFlags to set.
1186 	 *
1187 	 * Returns: %TRUE if @flags were successfully set on buffer.
1188 	 *
1189 	 * Since: 1.10
1190 	 */
1191 	public bool setFlags(GstBufferFlags flags)
1192 	{
1193 		return gst_buffer_set_flags(gstBuffer, flags) != 0;
1194 	}
1195 
1196 	/**
1197 	 * Set the total size of the memory blocks in @buffer.
1198 	 *
1199 	 * Params:
1200 	 *     size = the new size
1201 	 */
1202 	public void setSize(ptrdiff_t size)
1203 	{
1204 		gst_buffer_set_size(gstBuffer, size);
1205 	}
1206 
1207 	/**
1208 	 * Release the memory previously mapped with gst_buffer_map().
1209 	 *
1210 	 * Params:
1211 	 *     info = a #GstMapInfo
1212 	 */
1213 	public void unmap(GstMapInfo* info)
1214 	{
1215 		gst_buffer_unmap(gstBuffer, info);
1216 	}
1217 
1218 	/**
1219 	 * Clears one or more buffer flags.
1220 	 *
1221 	 * Params:
1222 	 *     flags = the #GstBufferFlags to clear
1223 	 *
1224 	 * Returns: true if @flags is successfully cleared from buffer.
1225 	 *
1226 	 * Since: 1.10
1227 	 */
1228 	public bool unsetFlags(GstBufferFlags flags)
1229 	{
1230 		return gst_buffer_unset_flags(gstBuffer, flags) != 0;
1231 	}
1232 
1233 	/**
1234 	 * Get the maximum amount of memory blocks that a buffer can hold. This is a
1235 	 * compile time constant that can be queried with the function.
1236 	 *
1237 	 * When more memory blocks are added, existing memory blocks will be merged
1238 	 * together to make room for the new block.
1239 	 *
1240 	 * Returns: the maximum amount of memory blocks that a buffer can hold.
1241 	 *
1242 	 * Since: 1.2
1243 	 */
1244 	public static uint getMaxMemory()
1245 	{
1246 		return gst_buffer_get_max_memory();
1247 	}
1248 }