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