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