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 gst.base.Adapter;
26 
27 private import glib.Bytes;
28 private import glib.ConstructionException;
29 private import glib.ListG;
30 private import gobject.ObjectG;
31 private import gst.base.c.functions;
32 public  import gst.base.c.types;
33 private import gstreamer.Buffer;
34 private import gstreamer.BufferList;
35 
36 
37 /**
38  * This class is for elements that receive buffers in an undesired size.
39  * While for example raw video contains one image per buffer, the same is not
40  * true for a lot of other formats, especially those that come directly from
41  * a file. So if you have undefined buffer sizes and require a specific size,
42  * this object is for you.
43  * 
44  * An adapter is created with gst_adapter_new(). It can be freed again with
45  * g_object_unref().
46  * 
47  * The theory of operation is like this: All buffers received are put
48  * into the adapter using gst_adapter_push() and the data is then read back
49  * in chunks of the desired size using gst_adapter_map()/gst_adapter_unmap()
50  * and/or gst_adapter_copy(). After the data has been processed, it is freed
51  * using gst_adapter_unmap().
52  * 
53  * Other methods such as gst_adapter_take() and gst_adapter_take_buffer()
54  * combine gst_adapter_map() and gst_adapter_unmap() in one method and are
55  * potentially more convenient for some use cases.
56  * 
57  * For example, a sink pad's chain function that needs to pass data to a library
58  * in 512-byte chunks could be implemented like this:
59  * |[<!-- language="C" -->
60  * static GstFlowReturn
61  * sink_pad_chain (GstPad *pad, GstObject *parent, GstBuffer *buffer)
62  * {
63  * MyElement *this;
64  * GstAdapter *adapter;
65  * GstFlowReturn ret = GST_FLOW_OK;
66  * 
67  * this = MY_ELEMENT (parent);
68  * 
69  * adapter = this->adapter;
70  * 
71  * // put buffer into adapter
72  * gst_adapter_push (adapter, buffer);
73  * 
74  * // while we can read out 512 bytes, process them
75  * while (gst_adapter_available (adapter) >= 512 && ret == GST_FLOW_OK) {
76  * const guint8 *data = gst_adapter_map (adapter, 512);
77  * // use flowreturn as an error value
78  * ret = my_library_foo (data);
79  * gst_adapter_unmap (adapter);
80  * gst_adapter_flush (adapter, 512);
81  * }
82  * return ret;
83  * }
84  * ]|
85  * 
86  * For another example, a simple element inside GStreamer that uses #GstAdapter
87  * is the libvisual element.
88  * 
89  * An element using #GstAdapter in its sink pad chain function should ensure that
90  * when the FLUSH_STOP event is received, that any queued data is cleared using
91  * gst_adapter_clear(). Data should also be cleared or processed on EOS and
92  * when changing state from %GST_STATE_PAUSED to %GST_STATE_READY.
93  * 
94  * Also check the GST_BUFFER_FLAG_DISCONT flag on the buffer. Some elements might
95  * need to clear the adapter after a discontinuity.
96  * 
97  * The adapter will keep track of the timestamps of the buffers
98  * that were pushed. The last seen timestamp before the current position
99  * can be queried with gst_adapter_prev_pts(). This function can
100  * optionally return the number of bytes between the start of the buffer that
101  * carried the timestamp and the current adapter position. The distance is
102  * useful when dealing with, for example, raw audio samples because it allows
103  * you to calculate the timestamp of the current adapter position by using the
104  * last seen timestamp and the amount of bytes since.  Additionally, the
105  * gst_adapter_prev_pts_at_offset() can be used to determine the last
106  * seen timestamp at a particular offset in the adapter.
107  * 
108  * The adapter will also keep track of the offset of the buffers
109  * (#GST_BUFFER_OFFSET) that were pushed. The last seen offset before the
110  * current position can be queried with gst_adapter_prev_offset(). This function
111  * can optionally return the number of bytes between the start of the buffer
112  * that carried the offset and the current adapter position.
113  * 
114  * Additionally the adapter also keeps track of the PTS, DTS and buffer offset
115  * at the last discontinuity, which can be retrieved with
116  * gst_adapter_pts_at_discont(), gst_adapter_dts_at_discont() and
117  * gst_adapter_offset_at_discont(). The number of bytes that were consumed
118  * since then can be queried with gst_adapter_distance_from_discont().
119  * 
120  * A last thing to note is that while #GstAdapter is pretty optimized,
121  * merging buffers still might be an operation that requires a `malloc()` and
122  * `memcpy()` operation, and these operations are not the fastest. Because of
123  * this, some functions like gst_adapter_available_fast() are provided to help
124  * speed up such cases should you want to. To avoid repeated memory allocations,
125  * gst_adapter_copy() can be used to copy data into a (statically allocated)
126  * user provided buffer.
127  * 
128  * #GstAdapter is not MT safe. All operations on an adapter must be serialized by
129  * the caller. This is not normally a problem, however, as the normal use case
130  * of #GstAdapter is inside one pad's chain function, in which case access is
131  * serialized via the pad's STREAM_LOCK.
132  * 
133  * Note that gst_adapter_push() takes ownership of the buffer passed. Use
134  * gst_buffer_ref() before pushing it into the adapter if you still want to
135  * access the buffer later. The adapter will never modify the data in the
136  * buffer pushed in it.
137  */
138 public class Adapter : ObjectG
139 {
140 	/** the main Gtk struct */
141 	protected GstAdapter* gstAdapter;
142 
143 	/** Get the main Gtk struct */
144 	public GstAdapter* getAdapterStruct(bool transferOwnership = false)
145 	{
146 		if (transferOwnership)
147 			ownedRef = false;
148 		return gstAdapter;
149 	}
150 
151 	/** the main Gtk struct as a void* */
152 	protected override void* getStruct()
153 	{
154 		return cast(void*)gstAdapter;
155 	}
156 
157 	/**
158 	 * Sets our main struct and passes it to the parent class.
159 	 */
160 	public this (GstAdapter* gstAdapter, bool ownedRef = false)
161 	{
162 		this.gstAdapter = gstAdapter;
163 		super(cast(GObject*)gstAdapter, ownedRef);
164 	}
165 
166 
167 	/** */
168 	public static GType getType()
169 	{
170 		return gst_adapter_get_type();
171 	}
172 
173 	/**
174 	 * Creates a new #GstAdapter. Free with g_object_unref().
175 	 *
176 	 * Returns: a new #GstAdapter
177 	 *
178 	 * Throws: ConstructionException GTK+ fails to create the object.
179 	 */
180 	public this()
181 	{
182 		auto __p = gst_adapter_new();
183 
184 		if(__p is null)
185 		{
186 			throw new ConstructionException("null returned by new");
187 		}
188 
189 		this(cast(GstAdapter*) __p, true);
190 	}
191 
192 	/**
193 	 * Gets the maximum amount of bytes available, that is it returns the maximum
194 	 * value that can be supplied to gst_adapter_map() without that function
195 	 * returning %NULL.
196 	 *
197 	 * Returns: number of bytes available in @adapter
198 	 */
199 	public size_t available()
200 	{
201 		return gst_adapter_available(gstAdapter);
202 	}
203 
204 	/**
205 	 * Gets the maximum number of bytes that are immediately available without
206 	 * requiring any expensive operations (like copying the data into a
207 	 * temporary buffer).
208 	 *
209 	 * Returns: number of bytes that are available in @adapter without expensive
210 	 *     operations
211 	 */
212 	public size_t availableFast()
213 	{
214 		return gst_adapter_available_fast(gstAdapter);
215 	}
216 
217 	/**
218 	 * Removes all buffers from @adapter.
219 	 */
220 	public void clear()
221 	{
222 		gst_adapter_clear(gstAdapter);
223 	}
224 
225 	/**
226 	 * Copies @size bytes of data starting at @offset out of the buffers
227 	 * contained in #GstAdapter into an array @dest provided by the caller.
228 	 *
229 	 * The array @dest should be large enough to contain @size bytes.
230 	 * The user should check that the adapter has (@offset + @size) bytes
231 	 * available before calling this function.
232 	 *
233 	 * Params:
234 	 *     dest = the memory to copy into
235 	 *     offset = the bytes offset in the adapter to start from
236 	 */
237 	public void copy(ubyte[] dest, size_t offset)
238 	{
239 		gst_adapter_copy(gstAdapter, dest.ptr, offset, cast(size_t)dest.length);
240 	}
241 
242 	/**
243 	 * Similar to gst_adapter_copy, but more suitable for language bindings. @size
244 	 * bytes of data starting at @offset will be copied out of the buffers contained
245 	 * in @adapter and into a new #GBytes structure which is returned. Depending on
246 	 * the value of the @size argument an empty #GBytes structure may be returned.
247 	 *
248 	 * Params:
249 	 *     offset = the bytes offset in the adapter to start from
250 	 *     size = the number of bytes to copy
251 	 *
252 	 * Returns: A new #GBytes structure containing the copied data.
253 	 *
254 	 * Since: 1.4
255 	 */
256 	public Bytes copyBytes(size_t offset, size_t size)
257 	{
258 		auto __p = gst_adapter_copy_bytes(gstAdapter, offset, size);
259 
260 		if(__p is null)
261 		{
262 			return null;
263 		}
264 
265 		return new Bytes(cast(GBytes*) __p, true);
266 	}
267 
268 	/**
269 	 * Get the distance in bytes since the last buffer with the
270 	 * %GST_BUFFER_FLAG_DISCONT flag.
271 	 *
272 	 * The distance will be reset to 0 for all buffers with
273 	 * %GST_BUFFER_FLAG_DISCONT on them, and then calculated for all other
274 	 * following buffers based on their size.
275 	 *
276 	 * Returns: The offset. Can be %GST_BUFFER_OFFSET_NONE.
277 	 *
278 	 * Since: 1.10
279 	 */
280 	public ulong distanceFromDiscont()
281 	{
282 		return gst_adapter_distance_from_discont(gstAdapter);
283 	}
284 
285 	/**
286 	 * Get the DTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
287 	 * flag, or GST_CLOCK_TIME_NONE.
288 	 *
289 	 * Returns: The DTS at the last discont or GST_CLOCK_TIME_NONE.
290 	 *
291 	 * Since: 1.10
292 	 */
293 	public GstClockTime dtsAtDiscont()
294 	{
295 		return gst_adapter_dts_at_discont(gstAdapter);
296 	}
297 
298 	/**
299 	 * Flushes the first @flush bytes in the @adapter. The caller must ensure that
300 	 * at least this many bytes are available.
301 	 *
302 	 * See also: gst_adapter_map(), gst_adapter_unmap()
303 	 *
304 	 * Params:
305 	 *     flush = the number of bytes to flush
306 	 */
307 	public void flush(size_t flush)
308 	{
309 		gst_adapter_flush(gstAdapter, flush);
310 	}
311 
312 	/**
313 	 * Returns a #GstBuffer containing the first @nbytes of the @adapter, but
314 	 * does not flush them from the adapter. See gst_adapter_take_buffer()
315 	 * for details.
316 	 *
317 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
318 	 * usage.
319 	 *
320 	 * Free-function: gst_buffer_unref
321 	 *
322 	 * Params:
323 	 *     nbytes = the number of bytes to get
324 	 *
325 	 * Returns: a #GstBuffer containing the first
326 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
327 	 *     gst_buffer_unref() when no longer needed.
328 	 *
329 	 * Since: 1.6
330 	 */
331 	public Buffer getBuffer(size_t nbytes)
332 	{
333 		auto __p = gst_adapter_get_buffer(gstAdapter, nbytes);
334 
335 		if(__p is null)
336 		{
337 			return null;
338 		}
339 
340 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
341 	}
342 
343 	/**
344 	 * Returns a #GstBuffer containing the first @nbytes of the @adapter, but
345 	 * does not flush them from the adapter. See gst_adapter_take_buffer_fast()
346 	 * for details.
347 	 *
348 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
349 	 * usage.
350 	 *
351 	 * Free-function: gst_buffer_unref
352 	 *
353 	 * Params:
354 	 *     nbytes = the number of bytes to get
355 	 *
356 	 * Returns: a #GstBuffer containing the first
357 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
358 	 *     gst_buffer_unref() when no longer needed.
359 	 *
360 	 * Since: 1.6
361 	 */
362 	public Buffer getBufferFast(size_t nbytes)
363 	{
364 		auto __p = gst_adapter_get_buffer_fast(gstAdapter, nbytes);
365 
366 		if(__p is null)
367 		{
368 			return null;
369 		}
370 
371 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
372 	}
373 
374 	/**
375 	 * Returns a #GstBufferList of buffers containing the first @nbytes bytes of
376 	 * the @adapter but does not flush them from the adapter. See
377 	 * gst_adapter_take_buffer_list() for details.
378 	 *
379 	 * Caller owns the returned list. Call gst_buffer_list_unref() to free
380 	 * the list after usage.
381 	 *
382 	 * Params:
383 	 *     nbytes = the number of bytes to get
384 	 *
385 	 * Returns: a #GstBufferList of buffers containing
386 	 *     the first @nbytes of the adapter, or %NULL if @nbytes bytes are not
387 	 *     available
388 	 *
389 	 * Since: 1.6
390 	 */
391 	public BufferList getBufferList(size_t nbytes)
392 	{
393 		auto __p = gst_adapter_get_buffer_list(gstAdapter, nbytes);
394 
395 		if(__p is null)
396 		{
397 			return null;
398 		}
399 
400 		return ObjectG.getDObject!(BufferList)(cast(GstBufferList*) __p, true);
401 	}
402 
403 	/**
404 	 * Returns a #GList of buffers containing the first @nbytes bytes of the
405 	 * @adapter, but does not flush them from the adapter. See
406 	 * gst_adapter_take_list() for details.
407 	 *
408 	 * Caller owns returned list and contained buffers. gst_buffer_unref() each
409 	 * buffer in the list before freeing the list after usage.
410 	 *
411 	 * Params:
412 	 *     nbytes = the number of bytes to get
413 	 *
414 	 * Returns: a #GList of
415 	 *     buffers containing the first @nbytes of the adapter, or %NULL if @nbytes
416 	 *     bytes are not available
417 	 *
418 	 * Since: 1.6
419 	 */
420 	public ListG getList(size_t nbytes)
421 	{
422 		auto __p = gst_adapter_get_list(gstAdapter, nbytes);
423 
424 		if(__p is null)
425 		{
426 			return null;
427 		}
428 
429 		return new ListG(cast(GList*) __p, true);
430 	}
431 
432 	/**
433 	 * Gets the first @size bytes stored in the @adapter. The returned pointer is
434 	 * valid until the next function is called on the adapter.
435 	 *
436 	 * Note that setting the returned pointer as the data of a #GstBuffer is
437 	 * incorrect for general-purpose plugins. The reason is that if a downstream
438 	 * element stores the buffer so that it has access to it outside of the bounds
439 	 * of its chain function, the buffer will have an invalid data pointer after
440 	 * your element flushes the bytes. In that case you should use
441 	 * gst_adapter_take(), which returns a freshly-allocated buffer that you can set
442 	 * as #GstBuffer memory or the potentially more performant
443 	 * gst_adapter_take_buffer().
444 	 *
445 	 * Returns %NULL if @size bytes are not available.
446 	 *
447 	 * Params:
448 	 *     size = the number of bytes to map/peek
449 	 *
450 	 * Returns: a pointer to the first @size bytes of data, or %NULL
451 	 */
452 	public ubyte[] map(size_t size)
453 	{
454 		auto __p = gst_adapter_map(gstAdapter, size);
455 
456 		return cast(ubyte[])__p[0 .. size];
457 	}
458 
459 	/**
460 	 * Scan for pattern @pattern with applied mask @mask in the adapter data,
461 	 * starting from offset @offset.
462 	 *
463 	 * The bytes in @pattern and @mask are interpreted left-to-right, regardless
464 	 * of endianness.  All four bytes of the pattern must be present in the
465 	 * adapter for it to match, even if the first or last bytes are masked out.
466 	 *
467 	 * It is an error to call this function without making sure that there is
468 	 * enough data (offset+size bytes) in the adapter.
469 	 *
470 	 * This function calls gst_adapter_masked_scan_uint32_peek() passing %NULL
471 	 * for value.
472 	 *
473 	 * Params:
474 	 *     mask = mask to apply to data before matching against @pattern
475 	 *     pattern = pattern to match (after mask is applied)
476 	 *     offset = offset into the adapter data from which to start scanning, returns
477 	 *         the last scanned position.
478 	 *     size = number of bytes to scan from offset
479 	 *
480 	 * Returns: offset of the first match, or -1 if no match was found.
481 	 *
482 	 *     Example:
483 	 *     |[
484 	 *     // Assume the adapter contains 0x00 0x01 0x02 ... 0xfe 0xff
485 	 *
486 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 0, 256);
487 	 *     // -> returns 0
488 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 1, 255);
489 	 *     // -> returns -1
490 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x01020304, 1, 255);
491 	 *     // -> returns 1
492 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0001, 0, 256);
493 	 *     // -> returns -1
494 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0203, 0, 256);
495 	 *     // -> returns 0
496 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 256);
497 	 *     // -> returns 2
498 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 4);
499 	 *     // -> returns -1
500 	 *     ]|
501 	 */
502 	public ptrdiff_t maskedScanUint32(uint mask, uint pattern, size_t offset, size_t size)
503 	{
504 		return gst_adapter_masked_scan_uint32(gstAdapter, mask, pattern, offset, size);
505 	}
506 
507 	/**
508 	 * Scan for pattern @pattern with applied mask @mask in the adapter data,
509 	 * starting from offset @offset.  If a match is found, the value that matched
510 	 * is returned through @value, otherwise @value is left untouched.
511 	 *
512 	 * The bytes in @pattern and @mask are interpreted left-to-right, regardless
513 	 * of endianness.  All four bytes of the pattern must be present in the
514 	 * adapter for it to match, even if the first or last bytes are masked out.
515 	 *
516 	 * It is an error to call this function without making sure that there is
517 	 * enough data (offset+size bytes) in the adapter.
518 	 *
519 	 * Params:
520 	 *     mask = mask to apply to data before matching against @pattern
521 	 *     pattern = pattern to match (after mask is applied)
522 	 *     offset = offset into the adapter data from which to start scanning, returns
523 	 *         the last scanned position.
524 	 *     size = number of bytes to scan from offset
525 	 *     value = pointer to uint32 to return matching data
526 	 *
527 	 * Returns: offset of the first match, or -1 if no match was found.
528 	 */
529 	public ptrdiff_t maskedScanUint32Peek(uint mask, uint pattern, size_t offset, size_t size, out uint value)
530 	{
531 		return gst_adapter_masked_scan_uint32_peek(gstAdapter, mask, pattern, offset, size, &value);
532 	}
533 
534 	/**
535 	 * Get the offset that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
536 	 * flag, or GST_BUFFER_OFFSET_NONE.
537 	 *
538 	 * Returns: The offset at the last discont or GST_BUFFER_OFFSET_NONE.
539 	 *
540 	 * Since: 1.10
541 	 */
542 	public ulong offsetAtDiscont()
543 	{
544 		return gst_adapter_offset_at_discont(gstAdapter);
545 	}
546 
547 	/**
548 	 * Get the dts that was before the current byte in the adapter. When
549 	 * @distance is given, the amount of bytes between the dts and the current
550 	 * position is returned.
551 	 *
552 	 * The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
553 	 * the adapter is first created or when it is cleared. This also means that before
554 	 * the first byte with a dts is removed from the adapter, the dts
555 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
556 	 *
557 	 * Params:
558 	 *     distance = pointer to location for distance, or %NULL
559 	 *
560 	 * Returns: The previously seen dts.
561 	 */
562 	public GstClockTime prevDts(out ulong distance)
563 	{
564 		return gst_adapter_prev_dts(gstAdapter, &distance);
565 	}
566 
567 	/**
568 	 * Get the dts that was before the byte at offset @offset in the adapter. When
569 	 * @distance is given, the amount of bytes between the dts and the current
570 	 * position is returned.
571 	 *
572 	 * The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
573 	 * the adapter is first created or when it is cleared. This also means that before
574 	 * the first byte with a dts is removed from the adapter, the dts
575 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
576 	 *
577 	 * Params:
578 	 *     offset = the offset in the adapter at which to get timestamp
579 	 *     distance = pointer to location for distance, or %NULL
580 	 *
581 	 * Returns: The previously seen dts at given offset.
582 	 *
583 	 * Since: 1.2
584 	 */
585 	public GstClockTime prevDtsAtOffset(size_t offset, out ulong distance)
586 	{
587 		return gst_adapter_prev_dts_at_offset(gstAdapter, offset, &distance);
588 	}
589 
590 	/**
591 	 * Get the offset that was before the current byte in the adapter. When
592 	 * @distance is given, the amount of bytes between the offset and the current
593 	 * position is returned.
594 	 *
595 	 * The offset is reset to GST_BUFFER_OFFSET_NONE and the distance is set to 0
596 	 * when the adapter is first created or when it is cleared. This also means that
597 	 * before the first byte with an offset is removed from the adapter, the offset
598 	 * and distance returned are GST_BUFFER_OFFSET_NONE and 0 respectively.
599 	 *
600 	 * Params:
601 	 *     distance = pointer to a location for distance, or %NULL
602 	 *
603 	 * Returns: The previous seen offset.
604 	 *
605 	 * Since: 1.10
606 	 */
607 	public ulong prevOffset(out ulong distance)
608 	{
609 		return gst_adapter_prev_offset(gstAdapter, &distance);
610 	}
611 
612 	/**
613 	 * Get the pts that was before the current byte in the adapter. When
614 	 * @distance is given, the amount of bytes between the pts and the current
615 	 * position is returned.
616 	 *
617 	 * The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
618 	 * the adapter is first created or when it is cleared. This also means that before
619 	 * the first byte with a pts is removed from the adapter, the pts
620 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
621 	 *
622 	 * Params:
623 	 *     distance = pointer to location for distance, or %NULL
624 	 *
625 	 * Returns: The previously seen pts.
626 	 */
627 	public GstClockTime prevPts(out ulong distance)
628 	{
629 		return gst_adapter_prev_pts(gstAdapter, &distance);
630 	}
631 
632 	/**
633 	 * Get the pts that was before the byte at offset @offset in the adapter. When
634 	 * @distance is given, the amount of bytes between the pts and the current
635 	 * position is returned.
636 	 *
637 	 * The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
638 	 * the adapter is first created or when it is cleared. This also means that before
639 	 * the first byte with a pts is removed from the adapter, the pts
640 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
641 	 *
642 	 * Params:
643 	 *     offset = the offset in the adapter at which to get timestamp
644 	 *     distance = pointer to location for distance, or %NULL
645 	 *
646 	 * Returns: The previously seen pts at given offset.
647 	 *
648 	 * Since: 1.2
649 	 */
650 	public GstClockTime prevPtsAtOffset(size_t offset, out ulong distance)
651 	{
652 		return gst_adapter_prev_pts_at_offset(gstAdapter, offset, &distance);
653 	}
654 
655 	/**
656 	 * Get the PTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
657 	 * flag, or GST_CLOCK_TIME_NONE.
658 	 *
659 	 * Returns: The PTS at the last discont or GST_CLOCK_TIME_NONE.
660 	 *
661 	 * Since: 1.10
662 	 */
663 	public GstClockTime ptsAtDiscont()
664 	{
665 		return gst_adapter_pts_at_discont(gstAdapter);
666 	}
667 
668 	/**
669 	 * Adds the data from @buf to the data stored inside @adapter and takes
670 	 * ownership of the buffer.
671 	 *
672 	 * Params:
673 	 *     buf = a #GstBuffer to add to queue in the adapter
674 	 */
675 	public void push(Buffer buf)
676 	{
677 		gst_adapter_push(gstAdapter, (buf is null) ? null : buf.getBufferStruct());
678 	}
679 
680 	/**
681 	 * Returns a freshly allocated buffer containing the first @nbytes bytes of the
682 	 * @adapter. The returned bytes will be flushed from the adapter.
683 	 *
684 	 * Caller owns returned value. g_free after usage.
685 	 *
686 	 * Free-function: g_free
687 	 *
688 	 * Params:
689 	 *     nbytes = the number of bytes to take
690 	 *
691 	 * Returns: oven-fresh hot data, or %NULL if @nbytes bytes are not available
692 	 */
693 	public ubyte[] take(size_t nbytes)
694 	{
695 		auto __p = gst_adapter_take(gstAdapter, nbytes);
696 
697 		return cast(ubyte[])__p[0 .. nbytes];
698 	}
699 
700 	/**
701 	 * Returns a #GstBuffer containing the first @nbytes bytes of the
702 	 * @adapter. The returned bytes will be flushed from the adapter.
703 	 * This function is potentially more performant than
704 	 * gst_adapter_take() since it can reuse the memory in pushed buffers
705 	 * by subbuffering or merging. This function will always return a
706 	 * buffer with a single memory region.
707 	 *
708 	 * Note that no assumptions should be made as to whether certain buffer
709 	 * flags such as the DISCONT flag are set on the returned buffer, or not.
710 	 * The caller needs to explicitly set or unset flags that should be set or
711 	 * unset.
712 	 *
713 	 * Since 1.6 this will also copy over all GstMeta of the input buffers except
714 	 * for meta with the %GST_META_FLAG_POOLED flag or with the "memory" tag.
715 	 *
716 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
717 	 * usage.
718 	 *
719 	 * Free-function: gst_buffer_unref
720 	 *
721 	 * Params:
722 	 *     nbytes = the number of bytes to take
723 	 *
724 	 * Returns: a #GstBuffer containing the first
725 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
726 	 *     gst_buffer_unref() when no longer needed.
727 	 */
728 	public Buffer takeBuffer(size_t nbytes)
729 	{
730 		auto __p = gst_adapter_take_buffer(gstAdapter, nbytes);
731 
732 		if(__p is null)
733 		{
734 			return null;
735 		}
736 
737 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
738 	}
739 
740 	/**
741 	 * Returns a #GstBuffer containing the first @nbytes of the @adapter.
742 	 * The returned bytes will be flushed from the adapter.  This function
743 	 * is potentially more performant than gst_adapter_take_buffer() since
744 	 * it can reuse the memory in pushed buffers by subbuffering or
745 	 * merging. Unlike gst_adapter_take_buffer(), the returned buffer may
746 	 * be composed of multiple non-contiguous #GstMemory objects, no
747 	 * copies are made.
748 	 *
749 	 * Note that no assumptions should be made as to whether certain buffer
750 	 * flags such as the DISCONT flag are set on the returned buffer, or not.
751 	 * The caller needs to explicitly set or unset flags that should be set or
752 	 * unset.
753 	 *
754 	 * This will also copy over all GstMeta of the input buffers except
755 	 * for meta with the %GST_META_FLAG_POOLED flag or with the "memory" tag.
756 	 *
757 	 * This function can return buffer up to the return value of
758 	 * gst_adapter_available() without making copies if possible.
759 	 *
760 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
761 	 * usage.
762 	 *
763 	 * Free-function: gst_buffer_unref
764 	 *
765 	 * Params:
766 	 *     nbytes = the number of bytes to take
767 	 *
768 	 * Returns: a #GstBuffer containing the first
769 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
770 	 *     gst_buffer_unref() when no longer needed.
771 	 *
772 	 * Since: 1.2
773 	 */
774 	public Buffer takeBufferFast(size_t nbytes)
775 	{
776 		auto __p = gst_adapter_take_buffer_fast(gstAdapter, nbytes);
777 
778 		if(__p is null)
779 		{
780 			return null;
781 		}
782 
783 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
784 	}
785 
786 	/**
787 	 * Returns a #GstBufferList of buffers containing the first @nbytes bytes of
788 	 * the @adapter. The returned bytes will be flushed from the adapter.
789 	 * When the caller can deal with individual buffers, this function is more
790 	 * performant because no memory should be copied.
791 	 *
792 	 * Caller owns the returned list. Call gst_buffer_list_unref() to free
793 	 * the list after usage.
794 	 *
795 	 * Params:
796 	 *     nbytes = the number of bytes to take
797 	 *
798 	 * Returns: a #GstBufferList of buffers containing
799 	 *     the first @nbytes of the adapter, or %NULL if @nbytes bytes are not
800 	 *     available
801 	 *
802 	 * Since: 1.6
803 	 */
804 	public BufferList takeBufferList(size_t nbytes)
805 	{
806 		auto __p = gst_adapter_take_buffer_list(gstAdapter, nbytes);
807 
808 		if(__p is null)
809 		{
810 			return null;
811 		}
812 
813 		return ObjectG.getDObject!(BufferList)(cast(GstBufferList*) __p, true);
814 	}
815 
816 	/**
817 	 * Returns a #GList of buffers containing the first @nbytes bytes of the
818 	 * @adapter. The returned bytes will be flushed from the adapter.
819 	 * When the caller can deal with individual buffers, this function is more
820 	 * performant because no memory should be copied.
821 	 *
822 	 * Caller owns returned list and contained buffers. gst_buffer_unref() each
823 	 * buffer in the list before freeing the list after usage.
824 	 *
825 	 * Params:
826 	 *     nbytes = the number of bytes to take
827 	 *
828 	 * Returns: a #GList of
829 	 *     buffers containing the first @nbytes of the adapter, or %NULL if @nbytes
830 	 *     bytes are not available
831 	 */
832 	public ListG takeList(size_t nbytes)
833 	{
834 		auto __p = gst_adapter_take_list(gstAdapter, nbytes);
835 
836 		if(__p is null)
837 		{
838 			return null;
839 		}
840 
841 		return new ListG(cast(GList*) __p, true);
842 	}
843 
844 	/**
845 	 * Releases the memory obtained with the last gst_adapter_map().
846 	 */
847 	public void unmap()
848 	{
849 		gst_adapter_unmap(gstAdapter);
850 	}
851 }