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