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