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 #GstBufferFlags flags set on this buffer.
591 	 *
592 	 * Return: the flags set on this buffer.
593 	 *
594 	 * Since: 1.10
595 	 */
596 	public GstBufferFlags getFlags()
597 	{
598 		return gst_buffer_get_flags(gstBuffer);
599 	}
600 
601 	/**
602 	 * Get the memory block at index @idx in @buffer.
603 	 *
604 	 * Params:
605 	 *     idx = an index
606 	 *
607 	 * Return: a #GstMemory that contains the data of the
608 	 *     memory block at @idx. Use gst_memory_unref () after usage.
609 	 */
610 	public Memory getMemory(uint idx)
611 	{
612 		auto p = gst_buffer_get_memory(gstBuffer, idx);
613 		
614 		if(p is null)
615 		{
616 			return null;
617 		}
618 		
619 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true);
620 	}
621 
622 	/**
623 	 * Get @length memory blocks in @buffer starting at @idx. The memory blocks will
624 	 * be merged into one large #GstMemory.
625 	 *
626 	 * If @length is -1, all memory starting from @idx is merged.
627 	 *
628 	 * Params:
629 	 *     idx = an index
630 	 *     length = a length
631 	 *
632 	 * Return: a #GstMemory that contains the merged data of @length
633 	 *     blocks starting at @idx. Use gst_memory_unref () after usage.
634 	 */
635 	public Memory getMemoryRange(uint idx, int length)
636 	{
637 		auto p = gst_buffer_get_memory_range(gstBuffer, idx, length);
638 		
639 		if(p is null)
640 		{
641 			return null;
642 		}
643 		
644 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true);
645 	}
646 
647 	/**
648 	 * Get the metadata for @api on buffer. When there is no such metadata, %NULL is
649 	 * returned. If multiple metadata with the given @api are attached to this
650 	 * buffer only the first one is returned.  To handle multiple metadata with a
651 	 * given API use gst_buffer_iterate_meta() or gst_buffer_foreach_meta() instead
652 	 * and check the meta->info.api member for the API type.
653 	 *
654 	 * Params:
655 	 *     api = the #GType of an API
656 	 *
657 	 * Return: the metadata for @api on
658 	 *     @buffer.
659 	 */
660 	public GstMeta* getMeta(GType api)
661 	{
662 		return gst_buffer_get_meta(gstBuffer, api);
663 	}
664 
665 	/**
666 	 * Get the total size of the memory blocks in @buffer.
667 	 *
668 	 * Return: total size of the memory blocks in @buffer.
669 	 */
670 	public size_t getSize()
671 	{
672 		return gst_buffer_get_size(gstBuffer);
673 	}
674 
675 	/**
676 	 * Get the total size of the memory blocks in @b.
677 	 *
678 	 * When not %NULL, @offset will contain the offset of the data in the
679 	 * first memory block in @buffer and @maxsize will contain the sum of
680 	 * the size and @offset and the amount of extra padding on the last
681 	 * memory block.  @offset and @maxsize can be used to resize the
682 	 * buffer memory blocks with gst_buffer_resize().
683 	 *
684 	 * Params:
685 	 *     offset = a pointer to the offset
686 	 *     maxsize = a pointer to the maxsize
687 	 *
688 	 * Return: total size of the memory blocks in @buffer.
689 	 */
690 	public size_t getSizes(out size_t offset, out size_t maxsize)
691 	{
692 		return gst_buffer_get_sizes(gstBuffer, &offset, &maxsize);
693 	}
694 
695 	/**
696 	 * Get the total size of @length memory blocks stating from @idx in @buffer.
697 	 *
698 	 * When not %NULL, @offset will contain the offset of the data in the
699 	 * memory block in @buffer at @idx and @maxsize will contain the sum of the size
700 	 * and @offset and the amount of extra padding on the memory block at @idx +
701 	 * @length -1.
702 	 * @offset and @maxsize can be used to resize the buffer memory blocks with
703 	 * gst_buffer_resize_range().
704 	 *
705 	 * Params:
706 	 *     idx = an index
707 	 *     length = a length
708 	 *     offset = a pointer to the offset
709 	 *     maxsize = a pointer to the maxsize
710 	 *
711 	 * Return: total size of @length memory blocks starting at @idx in @buffer.
712 	 */
713 	public size_t getSizesRange(uint idx, int length, out size_t offset, out size_t maxsize)
714 	{
715 		return gst_buffer_get_sizes_range(gstBuffer, idx, length, &offset, &maxsize);
716 	}
717 
718 	/** */
719 	public bool hasFlags(GstBufferFlags flags)
720 	{
721 		return gst_buffer_has_flags(gstBuffer, flags) != 0;
722 	}
723 
724 	/**
725 	 * Insert the memory block @mem to @buffer at @idx. This function takes ownership
726 	 * of @mem and thus doesn't increase its refcount.
727 	 *
728 	 * Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is
729 	 * added, existing memory blocks will automatically be merged to make room for
730 	 * the new memory.
731 	 *
732 	 * Params:
733 	 *     idx = the index to add the memory at, or -1 to append it to the end
734 	 *     mem = a #GstMemory.
735 	 */
736 	public void insertMemory(int idx, Memory mem)
737 	{
738 		gst_buffer_insert_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct());
739 	}
740 
741 	/**
742 	 * Check if all memory blocks in @buffer are writable.
743 	 *
744 	 * Note that this function does not check if @buffer is writable, use
745 	 * gst_buffer_is_writable() to check that if needed.
746 	 *
747 	 * Return: %TRUE if all memory blocks in @buffer are writable
748 	 *
749 	 * Since: 1.4
750 	 */
751 	public bool isAllMemoryWritable()
752 	{
753 		return gst_buffer_is_all_memory_writable(gstBuffer) != 0;
754 	}
755 
756 	/**
757 	 * Check if @length memory blocks in @buffer starting from @idx are writable.
758 	 *
759 	 * @length can be -1 to check all the memory blocks after @idx.
760 	 *
761 	 * Note that this function does not check if @buffer is writable, use
762 	 * gst_buffer_is_writable() to check that if needed.
763 	 *
764 	 * Params:
765 	 *     idx = an index
766 	 *     length = a length should not be 0
767 	 *
768 	 * Return: %TRUE if the memory range is writable
769 	 *
770 	 * Since: 1.4
771 	 */
772 	public bool isMemoryRangeWritable(uint idx, int length)
773 	{
774 		return gst_buffer_is_memory_range_writable(gstBuffer, idx, length) != 0;
775 	}
776 
777 	/**
778 	 * Retrieve the next #GstMeta after @current. If @state points
779 	 * to %NULL, the first metadata is returned.
780 	 *
781 	 * @state will be updated with an opaque state pointer
782 	 *
783 	 * Params:
784 	 *     state = an opaque state pointer
785 	 *
786 	 * Return: The next #GstMeta or %NULL
787 	 *     when there are no more items.
788 	 */
789 	public GstMeta* iterateMeta(void** state)
790 	{
791 		return gst_buffer_iterate_meta(gstBuffer, state);
792 	}
793 
794 	/**
795 	 * This function fills @info with the #GstMapInfo of all merged memory
796 	 * blocks in @buffer.
797 	 *
798 	 * @flags describe the desired access of the memory. When @flags is
799 	 * #GST_MAP_WRITE, @buffer should be writable (as returned from
800 	 * gst_buffer_is_writable()).
801 	 *
802 	 * When @buffer is writable but the memory isn't, a writable copy will
803 	 * automatically be created and returned. The readonly copy of the
804 	 * buffer memory will then also be replaced with this writable copy.
805 	 *
806 	 * The memory in @info should be unmapped with gst_buffer_unmap() after
807 	 * usage.
808 	 *
809 	 * Params:
810 	 *     info = info about the mapping
811 	 *     flags = flags for the mapping
812 	 *
813 	 * Return: %TRUE if the map succeeded and @info contains valid data.
814 	 */
815 	public bool map(out GstMapInfo info, GstMapFlags flags)
816 	{
817 		return gst_buffer_map(gstBuffer, &info, flags) != 0;
818 	}
819 
820 	/**
821 	 * This function fills @info with the #GstMapInfo of @length merged memory blocks
822 	 * starting at @idx in @buffer. When @length is -1, all memory blocks starting
823 	 * from @idx are merged and mapped.
824 	 *
825 	 * @flags describe the desired access of the memory. When @flags is
826 	 * #GST_MAP_WRITE, @buffer should be writable (as returned from
827 	 * gst_buffer_is_writable()).
828 	 *
829 	 * When @buffer is writable but the memory isn't, a writable copy will
830 	 * automatically be created and returned. The readonly copy of the buffer memory
831 	 * will then also be replaced with this writable copy.
832 	 *
833 	 * The memory in @info should be unmapped with gst_buffer_unmap() after usage.
834 	 *
835 	 * Params:
836 	 *     idx = an index
837 	 *     length = a length
838 	 *     info = info about the mapping
839 	 *     flags = flags for the mapping
840 	 *
841 	 * Return: %TRUE if the map succeeded and @info contains valid
842 	 *     data.
843 	 */
844 	public bool mapRange(uint idx, int length, out GstMapInfo info, GstMapFlags flags)
845 	{
846 		return gst_buffer_map_range(gstBuffer, idx, length, &info, flags) != 0;
847 	}
848 
849 	/**
850 	 * Compare @size bytes starting from @offset in @buffer with the memory in @mem.
851 	 *
852 	 * Params:
853 	 *     offset = the offset in @buffer
854 	 *     mem = the memory to compare
855 	 *     size = the size to compare
856 	 *
857 	 * Return: 0 if the memory is equal.
858 	 */
859 	public int memcmp(size_t offset, ubyte[] mem)
860 	{
861 		return gst_buffer_memcmp(gstBuffer, offset, mem.ptr, cast(size_t)mem.length);
862 	}
863 
864 	/**
865 	 * Fill @buf with @size bytes with @val starting from @offset.
866 	 *
867 	 * Params:
868 	 *     offset = the offset in @buffer
869 	 *     val = the value to set
870 	 *     size = the size to set
871 	 *
872 	 * Return: The amount of bytes filled. This value can be lower than @size
873 	 *     when @buffer did not contain enough data.
874 	 */
875 	public size_t memset(size_t offset, ubyte val, size_t size)
876 	{
877 		return gst_buffer_memset(gstBuffer, offset, val, size);
878 	}
879 
880 	/**
881 	 * Get the amount of memory blocks that this buffer has. This amount is never
882 	 * larger than what gst_buffer_get_max_memory() returns.
883 	 *
884 	 * Return: the number of memory blocks this buffer is made of.
885 	 */
886 	public uint nMemory()
887 	{
888 		return gst_buffer_n_memory(gstBuffer);
889 	}
890 
891 	/**
892 	 * Get the memory block at @idx in @buffer. The memory block stays valid until
893 	 * the memory block in @buffer is removed, replaced or merged, typically with
894 	 * any call that modifies the memory in @buffer.
895 	 *
896 	 * Params:
897 	 *     idx = an index
898 	 *
899 	 * Return: the #GstMemory at @idx.
900 	 */
901 	public Memory peekMemory(uint idx)
902 	{
903 		auto p = gst_buffer_peek_memory(gstBuffer, idx);
904 		
905 		if(p is null)
906 		{
907 			return null;
908 		}
909 		
910 		return ObjectG.getDObject!(Memory)(cast(GstMemory*) p);
911 	}
912 
913 	/**
914 	 * Prepend the memory block @mem to @buffer. This function takes
915 	 * ownership of @mem and thus doesn't increase its refcount.
916 	 *
917 	 * This function is identical to gst_buffer_insert_memory() with an index of 0.
918 	 * See gst_buffer_insert_memory() for more details.
919 	 *
920 	 * Params:
921 	 *     mem = a #GstMemory.
922 	 */
923 	public void prependMemory(Memory mem)
924 	{
925 		gst_buffer_prepend_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
926 	}
927 
928 	/**
929 	 * Remove all the memory blocks in @buffer.
930 	 */
931 	public void removeAllMemory()
932 	{
933 		gst_buffer_remove_all_memory(gstBuffer);
934 	}
935 
936 	/**
937 	 * Remove the memory block in @b at index @i.
938 	 *
939 	 * Params:
940 	 *     idx = an index
941 	 */
942 	public void removeMemory(uint idx)
943 	{
944 		gst_buffer_remove_memory(gstBuffer, idx);
945 	}
946 
947 	/**
948 	 * Remove @length memory blocks in @buffer starting from @idx.
949 	 *
950 	 * @length can be -1, in which case all memory starting from @idx is removed.
951 	 *
952 	 * Params:
953 	 *     idx = an index
954 	 *     length = a length
955 	 */
956 	public void removeMemoryRange(uint idx, int length)
957 	{
958 		gst_buffer_remove_memory_range(gstBuffer, idx, length);
959 	}
960 
961 	/**
962 	 * Remove the metadata for @meta on @buffer.
963 	 *
964 	 * Params:
965 	 *     meta = a #GstMeta
966 	 *
967 	 * Return: %TRUE if the metadata existed and was removed, %FALSE if no such
968 	 *     metadata was on @buffer.
969 	 */
970 	public bool removeMeta(GstMeta* meta)
971 	{
972 		return gst_buffer_remove_meta(gstBuffer, meta) != 0;
973 	}
974 
975 	/**
976 	 * Replaces all memory in @buffer with @mem.
977 	 *
978 	 * Params:
979 	 *     mem = a #GstMemory
980 	 */
981 	public void replaceAllMemory(Memory mem)
982 	{
983 		gst_buffer_replace_all_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct());
984 	}
985 
986 	/**
987 	 * Replaces the memory block at index @idx in @buffer with @mem.
988 	 *
989 	 * Params:
990 	 *     idx = an index
991 	 *     mem = a #GstMemory
992 	 */
993 	public void replaceMemory(uint idx, Memory mem)
994 	{
995 		gst_buffer_replace_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct());
996 	}
997 
998 	/**
999 	 * Replaces @length memory blocks in @buffer starting at @idx with @mem.
1000 	 *
1001 	 * If @length is -1, all memory starting from @idx will be removed and
1002 	 * replaced with @mem.
1003 	 *
1004 	 * @buffer should be writable.
1005 	 *
1006 	 * Params:
1007 	 *     idx = an index
1008 	 *     length = a length should not be 0
1009 	 *     mem = a #GstMemory
1010 	 */
1011 	public void replaceMemoryRange(uint idx, int length, Memory mem)
1012 	{
1013 		gst_buffer_replace_memory_range(gstBuffer, idx, length, (mem is null) ? null : mem.getMemoryStruct());
1014 	}
1015 
1016 	/**
1017 	 * Set the offset and total size of the memory blocks in @buffer.
1018 	 *
1019 	 * Params:
1020 	 *     offset = the offset adjustment
1021 	 *     size = the new size or -1 to just adjust the offset
1022 	 */
1023 	public void resize(ptrdiff_t offset, ptrdiff_t size)
1024 	{
1025 		gst_buffer_resize(gstBuffer, offset, size);
1026 	}
1027 
1028 	/**
1029 	 * Set the total size of the @length memory blocks starting at @idx in
1030 	 * @buffer
1031 	 *
1032 	 * Params:
1033 	 *     idx = an index
1034 	 *     length = a length
1035 	 *     offset = the offset adjustment
1036 	 *     size = the new size or -1 to just adjust the offset
1037 	 *
1038 	 * Return: %TRUE if resizing succeeded, %FALSE otherwise.
1039 	 */
1040 	public bool resizeRange(uint idx, int length, ptrdiff_t offset, ptrdiff_t size)
1041 	{
1042 		return gst_buffer_resize_range(gstBuffer, idx, length, offset, size) != 0;
1043 	}
1044 
1045 	/**
1046 	 * Sets one or more buffer flags on a buffer.
1047 	 *
1048 	 * Params:
1049 	 *     flags = the #GstBufferFlags to set.
1050 	 *
1051 	 * Return: %TRUE if @flags were successfully set on buffer.
1052 	 *
1053 	 * Since: 1.10
1054 	 */
1055 	public bool setFlags(GstBufferFlags flags)
1056 	{
1057 		return gst_buffer_set_flags(gstBuffer, flags) != 0;
1058 	}
1059 
1060 	/**
1061 	 * Set the total size of the memory blocks in @buffer.
1062 	 *
1063 	 * Params:
1064 	 *     size = the new size
1065 	 */
1066 	public void setSize(ptrdiff_t size)
1067 	{
1068 		gst_buffer_set_size(gstBuffer, size);
1069 	}
1070 
1071 	/**
1072 	 * Release the memory previously mapped with gst_buffer_map().
1073 	 *
1074 	 * Params:
1075 	 *     info = a #GstMapInfo
1076 	 */
1077 	public void unmap(GstMapInfo* info)
1078 	{
1079 		gst_buffer_unmap(gstBuffer, info);
1080 	}
1081 
1082 	/**
1083 	 * Clears one or more buffer flags.
1084 	 *
1085 	 * Params:
1086 	 *     flags = the #GstBufferFlags to clear
1087 	 *
1088 	 * Return: true if @flags is successfully cleared from buffer.
1089 	 *
1090 	 * Since: 1.10
1091 	 */
1092 	public bool unsetFlags(GstBufferFlags flags)
1093 	{
1094 		return gst_buffer_unset_flags(gstBuffer, flags) != 0;
1095 	}
1096 
1097 	/**
1098 	 * Get the maximum amount of memory blocks that a buffer can hold. This is a
1099 	 * compile time constant that can be queried with the function.
1100 	 *
1101 	 * When more memory blocks are added, existing memory blocks will be merged
1102 	 * together to make room for the new block.
1103 	 *
1104 	 * Return: the maximum amount of memory blocks that a buffer can hold.
1105 	 *
1106 	 * Since: 1.2
1107 	 */
1108 	public static uint getMaxMemory()
1109 	{
1110 		return gst_buffer_get_max_memory();
1111 	}
1112 }