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