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.ConstructionException;
28 private import gobject.ObjectG;
29 private import gstreamer.AllocationParams;
30 private import gstreamer.Allocator;
31 private import gstreamer.Caps;
32 private import gstreamer.Memory;
33 private import gstreamer.ParentBufferMeta;
34 private import gstreamer.ProtectionMeta;
35 private import gstreamer.Structure;
36 private import gstreamer.c.functions;
37 public  import gstreamer.c.types;
38 public  import gstreamerc.gstreamertypes;
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 	 * Allocate a new buffer that wraps the given memory. @data must point to
249 	 * @maxsize of memory, the wrapped buffer will have the region from @offset and
250 	 * @size visible.
251 	 *
252 	 * When the buffer is destroyed, @notify will be called with @user_data.
253 	 *
254 	 * The prefix/padding must be filled with 0 if @flags contains
255 	 * #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively.
256 	 *
257 	 * Params:
258 	 *     flags = #GstMemoryFlags
259 	 *     data = data to wrap
260 	 *     maxsize = allocated size of @data
261 	 *     offset = offset in @data
262 	 *     userData = user_data
263 	 *     notify = called with @user_data when the memory is freed
264 	 *
265 	 * Returns: a new #GstBuffer
266 	 *
267 	 * Throws: ConstructionException GTK+ fails to create the object.
268 	 */
269 	public this(GstMemoryFlags flags, ubyte[] data, size_t maxsize, size_t offset, void* userData, GDestroyNotify notify)
270 	{
271 		auto p = gst_buffer_new_wrapped_full(flags, data.ptr, maxsize, offset, cast(size_t)data.length, userData, notify);
272 
273 		if(p is null)
274 		{
275 			throw new ConstructionException("null returned by new_wrapped_full");
276 		}
277 
278 		this(cast(GstBuffer*) p);
279 	}
280 
281 	/**
282 	 * Add metadata for @info to @buffer using the parameters in @params.
283 	 *
284 	 * Params:
285 	 *     info = a #GstMetaInfo
286 	 *     params = params for @info
287 	 *
288 	 * Returns: the metadata for the api in @info on @buffer.
289 	 */
290 	public GstMeta* addMeta(GstMetaInfo* info, void* params)
291 	{
292 		return gst_buffer_add_meta(gstBuffer, info, params);
293 	}
294 
295 	/**
296 	 * Add a #GstParentBufferMeta to @buffer that holds a reference on
297 	 * @ref until the buffer is freed.
298 	 *
299 	 * Params:
300 	 *     doref = a #GstBuffer to ref
301 	 *
302 	 * Returns: The #GstParentBufferMeta that was added to the buffer
303 	 *
304 	 * Since: 1.6
305 	 */
306 	public ParentBufferMeta addParentBufferMeta(Buffer doref)
307 	{
308 		auto p = gst_buffer_add_parent_buffer_meta(gstBuffer, (doref is null) ? null : doref.getBufferStruct());
309 
310 		if(p is null)
311 		{
312 			return null;
313 		}
314 
315 		return ObjectG.getDObject!(ParentBufferMeta)(cast(GstParentBufferMeta*) p);
316 	}
317 
318 	/**
319 	 * Attaches protection metadata to a #GstBuffer.
320 	 *
321 	 * Params:
322 	 *     info = a #GstStructure holding cryptographic
323 	 *         information relating to the sample contained in @buffer. This
324 	 *         function takes ownership of @info.
325 	 *
326 	 * Returns: a pointer to the added #GstProtectionMeta if successful; %NULL if
327 	 *     unsuccessful.
328 	 *
329 	 * Since: 1.6
330 	 */
331 	public ProtectionMeta addProtectionMeta(Structure info)
332 	{
333 		auto p = gst_buffer_add_protection_meta(gstBuffer, (info is null) ? null : info.getStructureStruct(true));
334 
335 		if(p is null)
336 		{
337 			return null;
338 		}
339 
340 		return ObjectG.getDObject!(ProtectionMeta)(cast(GstProtectionMeta*) p);
341 	}
342 
343 	/**
344 	 * Add a #GstReferenceTimestampMeta to @buffer that holds a @timestamp and
345 	 * optionally @duration based on a specific timestamp @reference. See the
346 	 * documentation of #GstReferenceTimestampMeta for details.
347 	 *
348 	 * Params:
349 	 *     reference = identifier for the timestamp reference.
350 	 *     timestamp = timestamp
351 	 *     duration = duration, or %GST_CLOCK_TIME_NONE
352 	 *
353 	 * Returns: The #GstReferenceTimestampMeta that was added to the buffer
354 	 *
355 	 * Since: 1.14
356 	 */
357 	public GstReferenceTimestampMeta* addReferenceTimestampMeta(Caps reference, GstClockTime timestamp, GstClockTime duration)
358 	{
359 		return gst_buffer_add_reference_timestamp_meta(gstBuffer, (reference is null) ? null : reference.getCapsStruct(), timestamp, duration);
360 	}
361 
362 	/**
363 	 * Append all the memory from @buf2 to @buf1. The result buffer will contain a
364 	 * concatenation of the memory of @buf1 and @buf2.
365 	 *
366 	 * Params:
367 	 *     buf2 = the second source #GstBuffer to append.
368 	 *
369 	 * Returns: the new #GstBuffer that contains the memory
370 	 *     of the two source buffers.
371 	 */
372 	public Buffer append(Buffer buf2)
373 	{
374 		auto p = gst_buffer_append(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct());
375 
376 		if(p is null)
377 		{
378 			return null;
379 		}
380 
381 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
382 	}
383 
384 	/**
385 	 * Append the memory block @mem to @buffer. This function takes
386 	 * ownership of @mem and thus doesn't increase its refcount.
387 	 *
388 	 * This function is identical to gst_buffer_insert_memory() with an index of -1.
389 	 * See gst_buffer_insert_memory() for more details.
390 	 *
391 	 * Params:
392 	 *     mem = a #GstMemory.
393 	 */
394 	public void appendMemory(Memory mem)
395 	{
396 		gst_buffer_append_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
397 	}
398 
399 	/**
400 	 * Append @size bytes at @offset from @buf2 to @buf1. The result buffer will
401 	 * contain a concatenation of the memory of @buf1 and the requested region of
402 	 * @buf2.
403 	 *
404 	 * Params:
405 	 *     buf2 = the second source #GstBuffer to append.
406 	 *     offset = the offset in @buf2
407 	 *     size = the size or -1 of @buf2
408 	 *
409 	 * Returns: the new #GstBuffer that contains the memory
410 	 *     of the two source buffers.
411 	 */
412 	public Buffer appendRegion(Buffer buf2, ptrdiff_t offset, ptrdiff_t size)
413 	{
414 		auto p = gst_buffer_append_region(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct(), offset, size);
415 
416 		if(p is null)
417 		{
418 			return null;
419 		}
420 
421 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
422 	}
423 
424 	/**
425 	 * Create a copy of the given buffer. This will make a newly allocated
426 	 * copy of the data the source buffer contains.
427 	 *
428 	 * Returns: a new copy of @buf.
429 	 *
430 	 * Since: 1.6
431 	 */
432 	public Buffer copyDeep()
433 	{
434 		auto p = gst_buffer_copy_deep(gstBuffer);
435 
436 		if(p is null)
437 		{
438 			return null;
439 		}
440 
441 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
442 	}
443 
444 	/**
445 	 * Copies the information from @src into @dest.
446 	 *
447 	 * If @dest already contains memory and @flags contains GST_BUFFER_COPY_MEMORY,
448 	 * the memory from @src will be appended to @dest.
449 	 *
450 	 * @flags indicate which fields will be copied.
451 	 *
452 	 * Params:
453 	 *     src = a source #GstBuffer
454 	 *     flags = flags indicating what metadata fields should be copied.
455 	 *     offset = offset to copy from
456 	 *     size = total size to copy. If -1, all data is copied.
457 	 *
458 	 * Returns: %TRUE if the copying succeeded, %FALSE otherwise.
459 	 */
460 	public bool copyInto(Buffer src, GstBufferCopyFlags flags, size_t offset, size_t size)
461 	{
462 		return gst_buffer_copy_into(gstBuffer, (src is null) ? null : src.getBufferStruct(), flags, offset, size) != 0;
463 	}
464 
465 	/**
466 	 * Creates a sub-buffer from @parent at @offset and @size.
467 	 * This sub-buffer uses the actual memory space of the parent buffer.
468 	 * This function will copy the offset and timestamp fields when the
469 	 * offset is 0. If not, they will be set to #GST_CLOCK_TIME_NONE and
470 	 * #GST_BUFFER_OFFSET_NONE.
471 	 * If @offset equals 0 and @size equals the total size of @buffer, the
472 	 * duration and offset end fields are also copied. If not they will be set
473 	 * to #GST_CLOCK_TIME_NONE and #GST_BUFFER_OFFSET_NONE.
474 	 *
475 	 * MT safe.
476 	 *
477 	 * Params:
478 	 *     flags = the #GstBufferCopyFlags
479 	 *     offset = the offset into parent #GstBuffer at which the new sub-buffer
480 	 *         begins.
481 	 *     size = the size of the new #GstBuffer sub-buffer, in bytes. If -1, all
482 	 *         data is copied.
483 	 *
484 	 * Returns: the new #GstBuffer or %NULL if the arguments were
485 	 *     invalid.
486 	 */
487 	public Buffer copyRegion(GstBufferCopyFlags flags, size_t offset, size_t size)
488 	{
489 		auto p = gst_buffer_copy_region(gstBuffer, flags, offset, size);
490 
491 		if(p is null)
492 		{
493 			return null;
494 		}
495 
496 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
497 	}
498 
499 	/**
500 	 * Copy @size bytes starting from @offset in @buffer to @dest.
501 	 *
502 	 * Params:
503 	 *     offset = the offset to extract
504 	 *     dest = the destination address
505 	 *     size = the size to extract
506 	 *
507 	 * Returns: The amount of bytes extracted. This value can be lower than @size
508 	 *     when @buffer did not contain enough data.
509 	 */
510 	public size_t extract(size_t offset, void* dest, size_t size)
511 	{
512 		return gst_buffer_extract(gstBuffer, offset, dest, size);
513 	}
514 
515 	/**
516 	 * Extracts a copy of at most @size bytes the data at @offset into
517 	 * newly-allocated memory. @dest must be freed using g_free() when done.
518 	 *
519 	 * Params:
520 	 *     offset = the offset to extract
521 	 *     size = the size to extract
522 	 *     dest = A pointer where
523 	 *         the destination array will be written. Might be %NULL if the size is 0.
524 	 *
525 	 * Since: 1.0.10
526 	 */
527 	public void extractDup(size_t offset, size_t size, out ubyte[] dest)
528 	{
529 		ubyte* outdest = null;
530 		size_t destSize;
531 
532 		gst_buffer_extract_dup(gstBuffer, offset, size, cast(void**)&outdest, &destSize);
533 
534 		dest = outdest[0 .. destSize];
535 	}
536 
537 	/**
538 	 * Copy @size bytes from @src to @buffer at @offset.
539 	 *
540 	 * Params:
541 	 *     offset = the offset to fill
542 	 *     src = the source address
543 	 *
544 	 * Returns: The amount of bytes copied. This value can be lower than @size
545 	 *     when @buffer did not contain enough data.
546 	 */
547 	public size_t fill(size_t offset, ubyte[] src)
548 	{
549 		return gst_buffer_fill(gstBuffer, offset, src.ptr, cast(size_t)src.length);
550 	}
551 
552 	/**
553 	 * Find the memory blocks that span @size bytes starting from @offset
554 	 * in @buffer.
555 	 *
556 	 * When this function returns %TRUE, @idx will contain the index of the first
557 	 * memory block where the byte for @offset can be found and @length contains the
558 	 * number of memory blocks containing the @size remaining bytes. @skip contains
559 	 * the number of bytes to skip in the memory block at @idx to get to the byte
560 	 * for @offset.
561 	 *
562 	 * @size can be -1 to get all the memory blocks after @idx.
563 	 *
564 	 * Params:
565 	 *     offset = an offset
566 	 *     size = a size
567 	 *     idx = pointer to index
568 	 *     length = pointer to length
569 	 *     skip = pointer to skip
570 	 *
571 	 * Returns: %TRUE when @size bytes starting from @offset could be found in
572 	 *     @buffer and @idx, @length and @skip will be filled.
573 	 */
574 	public bool findMemory(size_t offset, size_t size, out uint idx, out uint length, out size_t skip)
575 	{
576 		return gst_buffer_find_memory(gstBuffer, offset, size, &idx, &length, &skip) != 0;
577 	}
578 
579 	/**
580 	 * Call @func with @user_data for each meta in @buffer.
581 	 *
582 	 * @func can modify the passed meta pointer or its contents. The return value
583 	 * of @func define if this function returns or if the remaining metadata items
584 	 * in the buffer should be skipped.
585 	 *
586 	 * Params:
587 	 *     func = a #GstBufferForeachMetaFunc to call
588 	 *     userData = user data passed to @func
589 	 *
590 	 * Returns: %FALSE when @func returned %FALSE for one of the metadata.
591 	 */
592 	public bool foreachMeta(GstBufferForeachMetaFunc func, void* userData)
593 	{
594 		return gst_buffer_foreach_meta(gstBuffer, func, userData) != 0;
595 	}
596 
597 	/**
598 	 * Get all the memory block in @buffer. The memory blocks will be merged
599 	 * into one large #GstMemory.
600 	 *
601 	 * Returns: a #GstMemory that contains the merged memory.
602 	 *     Use gst_memory_unref () after usage.
603 	 */
604 	public Memory getAllMemory()
605 	{
606 		auto p = gst_buffer_get_all_memory(gstBuffer);
607 
608 		if(p is null)
609 		{
610 			return null;
611 		}
612 
613 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true);
614 	}
615 
616 	/**
617 	 * Get the #GstBufferFlags flags set on this buffer.
618 	 *
619 	 * Returns: the flags set on this buffer.
620 	 *
621 	 * Since: 1.10
622 	 */
623 	public GstBufferFlags getFlags()
624 	{
625 		return gst_buffer_get_flags(gstBuffer);
626 	}
627 
628 	/**
629 	 * Get the memory block at index @idx in @buffer.
630 	 *
631 	 * Params:
632 	 *     idx = an index
633 	 *
634 	 * Returns: a #GstMemory that contains the data of the
635 	 *     memory block at @idx. Use gst_memory_unref () after usage.
636 	 */
637 	public Memory getMemory(uint idx)
638 	{
639 		auto p = gst_buffer_get_memory(gstBuffer, idx);
640 
641 		if(p is null)
642 		{
643 			return null;
644 		}
645 
646 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true);
647 	}
648 
649 	/**
650 	 * Get @length memory blocks in @buffer starting at @idx. The memory blocks will
651 	 * be merged into one large #GstMemory.
652 	 *
653 	 * If @length is -1, all memory starting from @idx is merged.
654 	 *
655 	 * Params:
656 	 *     idx = an index
657 	 *     length = a length
658 	 *
659 	 * Returns: a #GstMemory that contains the merged data of @length
660 	 *     blocks starting at @idx. Use gst_memory_unref () after usage.
661 	 */
662 	public Memory getMemoryRange(uint idx, int length)
663 	{
664 		auto p = gst_buffer_get_memory_range(gstBuffer, idx, length);
665 
666 		if(p is null)
667 		{
668 			return null;
669 		}
670 
671 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true);
672 	}
673 
674 	/**
675 	 * Get the metadata for @api on buffer. When there is no such metadata, %NULL is
676 	 * returned. If multiple metadata with the given @api are attached to this
677 	 * buffer only the first one is returned.  To handle multiple metadata with a
678 	 * given API use gst_buffer_iterate_meta() or gst_buffer_foreach_meta() instead
679 	 * and check the meta->info.api member for the API type.
680 	 *
681 	 * Params:
682 	 *     api = the #GType of an API
683 	 *
684 	 * Returns: the metadata for @api on
685 	 *     @buffer.
686 	 */
687 	public GstMeta* getMeta(GType api)
688 	{
689 		return gst_buffer_get_meta(gstBuffer, api);
690 	}
691 
692 	/**
693 	 *
694 	 * Params:
695 	 *     apiType = the #GType of an API
696 	 * Returns: number of metas of type @api_type on @buffer.
697 	 *
698 	 * Since: 1.14
699 	 */
700 	public uint getNMeta(GType apiType)
701 	{
702 		return gst_buffer_get_n_meta(gstBuffer, apiType);
703 	}
704 
705 	/**
706 	 * Find the first #GstReferenceTimestampMeta on @buffer that conforms to
707 	 * @reference. Conformance is tested by checking if the meta's reference is a
708 	 * subset of @reference.
709 	 *
710 	 * Buffers can contain multiple #GstReferenceTimestampMeta metadata items.
711 	 *
712 	 * Params:
713 	 *     reference = a reference #GstCaps
714 	 *
715 	 * Returns: the #GstReferenceTimestampMeta or %NULL when there
716 	 *     is no such metadata on @buffer.
717 	 *
718 	 * Since: 1.14
719 	 */
720 	public GstReferenceTimestampMeta* getReferenceTimestampMeta(Caps reference)
721 	{
722 		return gst_buffer_get_reference_timestamp_meta(gstBuffer, (reference is null) ? null : reference.getCapsStruct());
723 	}
724 
725 	/**
726 	 * Get the total size of the memory blocks in @buffer.
727 	 *
728 	 * Returns: total size of the memory blocks in @buffer.
729 	 */
730 	public size_t getSize()
731 	{
732 		return gst_buffer_get_size(gstBuffer);
733 	}
734 
735 	/**
736 	 * Get the total size of the memory blocks in @b.
737 	 *
738 	 * When not %NULL, @offset will contain the offset of the data in the
739 	 * first memory block in @buffer and @maxsize will contain the sum of
740 	 * the size and @offset and the amount of extra padding on the last
741 	 * memory block.  @offset and @maxsize can be used to resize the
742 	 * buffer memory blocks with gst_buffer_resize().
743 	 *
744 	 * Params:
745 	 *     offset = a pointer to the offset
746 	 *     maxsize = a pointer to the maxsize
747 	 *
748 	 * Returns: total size of the memory blocks in @buffer.
749 	 */
750 	public size_t getSizes(out size_t offset, out size_t maxsize)
751 	{
752 		return gst_buffer_get_sizes(gstBuffer, &offset, &maxsize);
753 	}
754 
755 	/**
756 	 * Get the total size of @length memory blocks stating from @idx in @buffer.
757 	 *
758 	 * When not %NULL, @offset will contain the offset of the data in the
759 	 * memory block in @buffer at @idx and @maxsize will contain the sum of the size
760 	 * and @offset and the amount of extra padding on the memory block at @idx +
761 	 * @length -1.
762 	 * @offset and @maxsize can be used to resize the buffer memory blocks with
763 	 * gst_buffer_resize_range().
764 	 *
765 	 * Params:
766 	 *     idx = an index
767 	 *     length = a length
768 	 *     offset = a pointer to the offset
769 	 *     maxsize = a pointer to the maxsize
770 	 *
771 	 * Returns: total size of @length memory blocks starting at @idx in @buffer.
772 	 */
773 	public size_t getSizesRange(uint idx, int length, out size_t offset, out size_t maxsize)
774 	{
775 		return gst_buffer_get_sizes_range(gstBuffer, idx, length, &offset, &maxsize);
776 	}
777 
778 	/** */
779 	public bool hasFlags(GstBufferFlags flags)
780 	{
781 		return gst_buffer_has_flags(gstBuffer, flags) != 0;
782 	}
783 
784 	/**
785 	 * Insert the memory block @mem to @buffer at @idx. This function takes ownership
786 	 * of @mem and thus doesn't increase its refcount.
787 	 *
788 	 * Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is
789 	 * added, existing memory blocks will automatically be merged to make room for
790 	 * the new memory.
791 	 *
792 	 * Params:
793 	 *     idx = the index to add the memory at, or -1 to append it to the end
794 	 *     mem = a #GstMemory.
795 	 */
796 	public void insertMemory(int idx, Memory mem)
797 	{
798 		gst_buffer_insert_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct());
799 	}
800 
801 	/**
802 	 * Check if all memory blocks in @buffer are writable.
803 	 *
804 	 * Note that this function does not check if @buffer is writable, use
805 	 * gst_buffer_is_writable() to check that if needed.
806 	 *
807 	 * Returns: %TRUE if all memory blocks in @buffer are writable
808 	 *
809 	 * Since: 1.4
810 	 */
811 	public bool isAllMemoryWritable()
812 	{
813 		return gst_buffer_is_all_memory_writable(gstBuffer) != 0;
814 	}
815 
816 	/**
817 	 * Check if @length memory blocks in @buffer starting from @idx are writable.
818 	 *
819 	 * @length can be -1 to check all the memory blocks after @idx.
820 	 *
821 	 * Note that this function does not check if @buffer is writable, use
822 	 * gst_buffer_is_writable() to check that if needed.
823 	 *
824 	 * Params:
825 	 *     idx = an index
826 	 *     length = a length should not be 0
827 	 *
828 	 * Returns: %TRUE if the memory range is writable
829 	 *
830 	 * Since: 1.4
831 	 */
832 	public bool isMemoryRangeWritable(uint idx, int length)
833 	{
834 		return gst_buffer_is_memory_range_writable(gstBuffer, idx, length) != 0;
835 	}
836 
837 	/**
838 	 * Retrieve the next #GstMeta after @current. If @state points
839 	 * to %NULL, the first metadata is returned.
840 	 *
841 	 * @state will be updated with an opaque state pointer
842 	 *
843 	 * Params:
844 	 *     state = an opaque state pointer
845 	 *
846 	 * Returns: The next #GstMeta or %NULL
847 	 *     when there are no more items.
848 	 */
849 	public GstMeta* iterateMeta(out void* state)
850 	{
851 		return gst_buffer_iterate_meta(gstBuffer, &state);
852 	}
853 
854 	/**
855 	 * Retrieve the next #GstMeta of type @meta_api_type after the current one
856 	 * according to @state. If @state points to %NULL, the first metadata of
857 	 * type @meta_api_type is returned.
858 	 *
859 	 * @state will be updated with an opaque state pointer
860 	 *
861 	 * Params:
862 	 *     state = an opaque state pointer
863 	 *     metaApiType = only return #GstMeta of this type
864 	 *
865 	 * Returns: The next #GstMeta of type
866 	 *     @meta_api_type or %NULL when there are no more items.
867 	 *
868 	 * Since: 1.12
869 	 */
870 	public GstMeta* iterateMetaFiltered(out void* state, GType metaApiType)
871 	{
872 		return gst_buffer_iterate_meta_filtered(gstBuffer, &state, metaApiType);
873 	}
874 
875 	/**
876 	 * This function fills @info with the #GstMapInfo of all merged memory
877 	 * blocks in @buffer.
878 	 *
879 	 * @flags describe the desired access of the memory. When @flags is
880 	 * #GST_MAP_WRITE, @buffer should be writable (as returned from
881 	 * gst_buffer_is_writable()).
882 	 *
883 	 * When @buffer is writable but the memory isn't, a writable copy will
884 	 * automatically be created and returned. The readonly copy of the
885 	 * buffer memory will then also be replaced with this writable copy.
886 	 *
887 	 * The memory in @info should be unmapped with gst_buffer_unmap() after
888 	 * usage.
889 	 *
890 	 * Params:
891 	 *     info = info about the mapping
892 	 *     flags = flags for the mapping
893 	 *
894 	 * Returns: %TRUE if the map succeeded and @info contains valid data.
895 	 */
896 	public bool map(out GstMapInfo info, GstMapFlags flags)
897 	{
898 		return gst_buffer_map(gstBuffer, &info, flags) != 0;
899 	}
900 
901 	/**
902 	 * This function fills @info with the #GstMapInfo of @length merged memory blocks
903 	 * starting at @idx in @buffer. When @length is -1, all memory blocks starting
904 	 * from @idx are merged and mapped.
905 	 *
906 	 * @flags describe the desired access of the memory. When @flags is
907 	 * #GST_MAP_WRITE, @buffer should be writable (as returned from
908 	 * gst_buffer_is_writable()).
909 	 *
910 	 * When @buffer is writable but the memory isn't, a writable copy will
911 	 * automatically be created and returned. The readonly copy of the buffer memory
912 	 * will then also be replaced with this writable copy.
913 	 *
914 	 * The memory in @info should be unmapped with gst_buffer_unmap() after usage.
915 	 *
916 	 * Params:
917 	 *     idx = an index
918 	 *     length = a length
919 	 *     info = info about the mapping
920 	 *     flags = flags for the mapping
921 	 *
922 	 * Returns: %TRUE if the map succeeded and @info contains valid
923 	 *     data.
924 	 */
925 	public bool mapRange(uint idx, int length, out GstMapInfo info, GstMapFlags flags)
926 	{
927 		return gst_buffer_map_range(gstBuffer, idx, length, &info, flags) != 0;
928 	}
929 
930 	/**
931 	 * Compare @size bytes starting from @offset in @buffer with the memory in @mem.
932 	 *
933 	 * Params:
934 	 *     offset = the offset in @buffer
935 	 *     mem = the memory to compare
936 	 *
937 	 * Returns: 0 if the memory is equal.
938 	 */
939 	public int memcmp(size_t offset, ubyte[] mem)
940 	{
941 		return gst_buffer_memcmp(gstBuffer, offset, mem.ptr, cast(size_t)mem.length);
942 	}
943 
944 	/**
945 	 * Fill @buf with @size bytes with @val starting from @offset.
946 	 *
947 	 * Params:
948 	 *     offset = the offset in @buffer
949 	 *     val = the value to set
950 	 *     size = the size to set
951 	 *
952 	 * Returns: The amount of bytes filled. This value can be lower than @size
953 	 *     when @buffer did not contain enough data.
954 	 */
955 	public size_t memset(size_t offset, ubyte val, size_t size)
956 	{
957 		return gst_buffer_memset(gstBuffer, offset, val, size);
958 	}
959 
960 	/**
961 	 * Get the amount of memory blocks that this buffer has. This amount is never
962 	 * larger than what gst_buffer_get_max_memory() returns.
963 	 *
964 	 * Returns: the number of memory blocks this buffer is made of.
965 	 */
966 	public uint nMemory()
967 	{
968 		return gst_buffer_n_memory(gstBuffer);
969 	}
970 
971 	/**
972 	 * Get the memory block at @idx in @buffer. The memory block stays valid until
973 	 * the memory block in @buffer is removed, replaced or merged, typically with
974 	 * any call that modifies the memory in @buffer.
975 	 *
976 	 * Params:
977 	 *     idx = an index
978 	 *
979 	 * Returns: the #GstMemory at @idx.
980 	 */
981 	public Memory peekMemory(uint idx)
982 	{
983 		auto p = gst_buffer_peek_memory(gstBuffer, idx);
984 
985 		if(p is null)
986 		{
987 			return null;
988 		}
989 
990 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
991 	}
992 
993 	/**
994 	 * Prepend the memory block @mem to @buffer. This function takes
995 	 * ownership of @mem and thus doesn't increase its refcount.
996 	 *
997 	 * This function is identical to gst_buffer_insert_memory() with an index of 0.
998 	 * See gst_buffer_insert_memory() for more details.
999 	 *
1000 	 * Params:
1001 	 *     mem = a #GstMemory.
1002 	 */
1003 	public void prependMemory(Memory mem)
1004 	{
1005 		gst_buffer_prepend_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
1006 	}
1007 
1008 	/**
1009 	 * Remove all the memory blocks in @buffer.
1010 	 */
1011 	public void removeAllMemory()
1012 	{
1013 		gst_buffer_remove_all_memory(gstBuffer);
1014 	}
1015 
1016 	/**
1017 	 * Remove the memory block in @b at index @i.
1018 	 *
1019 	 * Params:
1020 	 *     idx = an index
1021 	 */
1022 	public void removeMemory(uint idx)
1023 	{
1024 		gst_buffer_remove_memory(gstBuffer, idx);
1025 	}
1026 
1027 	/**
1028 	 * Remove @length memory blocks in @buffer starting from @idx.
1029 	 *
1030 	 * @length can be -1, in which case all memory starting from @idx is removed.
1031 	 *
1032 	 * Params:
1033 	 *     idx = an index
1034 	 *     length = a length
1035 	 */
1036 	public void removeMemoryRange(uint idx, int length)
1037 	{
1038 		gst_buffer_remove_memory_range(gstBuffer, idx, length);
1039 	}
1040 
1041 	/**
1042 	 * Remove the metadata for @meta on @buffer.
1043 	 *
1044 	 * Params:
1045 	 *     meta = a #GstMeta
1046 	 *
1047 	 * Returns: %TRUE if the metadata existed and was removed, %FALSE if no such
1048 	 *     metadata was on @buffer.
1049 	 */
1050 	public bool removeMeta(GstMeta* meta)
1051 	{
1052 		return gst_buffer_remove_meta(gstBuffer, meta) != 0;
1053 	}
1054 
1055 	/**
1056 	 * Replaces all memory in @buffer with @mem.
1057 	 *
1058 	 * Params:
1059 	 *     mem = a #GstMemory
1060 	 */
1061 	public void replaceAllMemory(Memory mem)
1062 	{
1063 		gst_buffer_replace_all_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
1064 	}
1065 
1066 	/**
1067 	 * Replaces the memory block at index @idx in @buffer with @mem.
1068 	 *
1069 	 * Params:
1070 	 *     idx = an index
1071 	 *     mem = a #GstMemory
1072 	 */
1073 	public void replaceMemory(uint idx, Memory mem)
1074 	{
1075 		gst_buffer_replace_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct());
1076 	}
1077 
1078 	/**
1079 	 * Replaces @length memory blocks in @buffer starting at @idx with @mem.
1080 	 *
1081 	 * If @length is -1, all memory starting from @idx will be removed and
1082 	 * replaced with @mem.
1083 	 *
1084 	 * @buffer should be writable.
1085 	 *
1086 	 * Params:
1087 	 *     idx = an index
1088 	 *     length = a length should not be 0
1089 	 *     mem = a #GstMemory
1090 	 */
1091 	public void replaceMemoryRange(uint idx, int length, Memory mem)
1092 	{
1093 		gst_buffer_replace_memory_range(gstBuffer, idx, length, (mem is null) ? null : mem.getMemoryStruct());
1094 	}
1095 
1096 	/**
1097 	 * Set the offset and total size of the memory blocks in @buffer.
1098 	 *
1099 	 * Params:
1100 	 *     offset = the offset adjustment
1101 	 *     size = the new size or -1 to just adjust the offset
1102 	 */
1103 	public void resize(ptrdiff_t offset, ptrdiff_t size)
1104 	{
1105 		gst_buffer_resize(gstBuffer, offset, size);
1106 	}
1107 
1108 	/**
1109 	 * Set the total size of the @length memory blocks starting at @idx in
1110 	 * @buffer
1111 	 *
1112 	 * Params:
1113 	 *     idx = an index
1114 	 *     length = a length
1115 	 *     offset = the offset adjustment
1116 	 *     size = the new size or -1 to just adjust the offset
1117 	 *
1118 	 * Returns: %TRUE if resizing succeeded, %FALSE otherwise.
1119 	 */
1120 	public bool resizeRange(uint idx, int length, ptrdiff_t offset, ptrdiff_t size)
1121 	{
1122 		return gst_buffer_resize_range(gstBuffer, idx, length, offset, size) != 0;
1123 	}
1124 
1125 	/**
1126 	 * Sets one or more buffer flags on a buffer.
1127 	 *
1128 	 * Params:
1129 	 *     flags = the #GstBufferFlags to set.
1130 	 *
1131 	 * Returns: %TRUE if @flags were successfully set on buffer.
1132 	 *
1133 	 * Since: 1.10
1134 	 */
1135 	public bool setFlags(GstBufferFlags flags)
1136 	{
1137 		return gst_buffer_set_flags(gstBuffer, flags) != 0;
1138 	}
1139 
1140 	/**
1141 	 * Set the total size of the memory blocks in @buffer.
1142 	 *
1143 	 * Params:
1144 	 *     size = the new size
1145 	 */
1146 	public void setSize(ptrdiff_t size)
1147 	{
1148 		gst_buffer_set_size(gstBuffer, size);
1149 	}
1150 
1151 	/**
1152 	 * Release the memory previously mapped with gst_buffer_map().
1153 	 *
1154 	 * Params:
1155 	 *     info = a #GstMapInfo
1156 	 */
1157 	public void unmap(GstMapInfo* info)
1158 	{
1159 		gst_buffer_unmap(gstBuffer, info);
1160 	}
1161 
1162 	/**
1163 	 * Clears one or more buffer flags.
1164 	 *
1165 	 * Params:
1166 	 *     flags = the #GstBufferFlags to clear
1167 	 *
1168 	 * Returns: true if @flags is successfully cleared from buffer.
1169 	 *
1170 	 * Since: 1.10
1171 	 */
1172 	public bool unsetFlags(GstBufferFlags flags)
1173 	{
1174 		return gst_buffer_unset_flags(gstBuffer, flags) != 0;
1175 	}
1176 
1177 	/**
1178 	 * Get the maximum amount of memory blocks that a buffer can hold. This is a
1179 	 * compile time constant that can be queried with the function.
1180 	 *
1181 	 * When more memory blocks are added, existing memory blocks will be merged
1182 	 * together to make room for the new block.
1183 	 *
1184 	 * Returns: the maximum amount of memory blocks that a buffer can hold.
1185 	 *
1186 	 * Since: 1.2
1187 	 */
1188 	public static uint getMaxMemory()
1189 	{
1190 		return gst_buffer_get_max_memory();
1191 	}
1192 }