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 	protected override void setStruct(GObject* obj)
158 	{
159 		gstAdapter = cast(GstAdapter*)obj;
160 		super.setStruct(obj);
161 	}
162 
163 	/**
164 	 * Sets our main struct and passes it to the parent class.
165 	 */
166 	public this (GstAdapter* gstAdapter, bool ownedRef = false)
167 	{
168 		this.gstAdapter = gstAdapter;
169 		super(cast(GObject*)gstAdapter, ownedRef);
170 	}
171 
172 
173 	/** */
174 	public static GType getType()
175 	{
176 		return gst_adapter_get_type();
177 	}
178 
179 	/**
180 	 * Creates a new #GstAdapter. Free with g_object_unref().
181 	 *
182 	 * Returns: a new #GstAdapter
183 	 *
184 	 * Throws: ConstructionException GTK+ fails to create the object.
185 	 */
186 	public this()
187 	{
188 		auto p = gst_adapter_new();
189 
190 		if(p is null)
191 		{
192 			throw new ConstructionException("null returned by new");
193 		}
194 
195 		this(cast(GstAdapter*) p, true);
196 	}
197 
198 	/**
199 	 * Gets the maximum amount of bytes available, that is it returns the maximum
200 	 * value that can be supplied to gst_adapter_map() without that function
201 	 * returning %NULL.
202 	 *
203 	 * Returns: number of bytes available in @adapter
204 	 */
205 	public size_t available()
206 	{
207 		return gst_adapter_available(gstAdapter);
208 	}
209 
210 	/**
211 	 * Gets the maximum number of bytes that are immediately available without
212 	 * requiring any expensive operations (like copying the data into a
213 	 * temporary buffer).
214 	 *
215 	 * Returns: number of bytes that are available in @adapter without expensive
216 	 *     operations
217 	 */
218 	public size_t availableFast()
219 	{
220 		return gst_adapter_available_fast(gstAdapter);
221 	}
222 
223 	/**
224 	 * Removes all buffers from @adapter.
225 	 */
226 	public void clear()
227 	{
228 		gst_adapter_clear(gstAdapter);
229 	}
230 
231 	/**
232 	 * Copies @size bytes of data starting at @offset out of the buffers
233 	 * contained in #GstAdapter into an array @dest provided by the caller.
234 	 *
235 	 * The array @dest should be large enough to contain @size bytes.
236 	 * The user should check that the adapter has (@offset + @size) bytes
237 	 * available before calling this function.
238 	 *
239 	 * Params:
240 	 *     dest = the memory to copy into
241 	 *     offset = the bytes offset in the adapter to start from
242 	 */
243 	public void copy(ubyte[] dest, size_t offset)
244 	{
245 		gst_adapter_copy(gstAdapter, dest.ptr, offset, cast(size_t)dest.length);
246 	}
247 
248 	/**
249 	 * Similar to gst_adapter_copy, but more suitable for language bindings. @size
250 	 * bytes of data starting at @offset will be copied out of the buffers contained
251 	 * in @adapter and into a new #GBytes structure which is returned. Depending on
252 	 * the value of the @size argument an empty #GBytes structure may be returned.
253 	 *
254 	 * Params:
255 	 *     offset = the bytes offset in the adapter to start from
256 	 *     size = the number of bytes to copy
257 	 *
258 	 * Returns: A new #GBytes structure containing the copied data.
259 	 *
260 	 * Since: 1.4
261 	 */
262 	public Bytes copyBytes(size_t offset, size_t size)
263 	{
264 		auto p = gst_adapter_copy_bytes(gstAdapter, offset, size);
265 
266 		if(p is null)
267 		{
268 			return null;
269 		}
270 
271 		return new Bytes(cast(GBytes*) p, true);
272 	}
273 
274 	/** */
275 	public ulong distanceFromDiscont()
276 	{
277 		return gst_adapter_distance_from_discont(gstAdapter);
278 	}
279 
280 	/**
281 	 * Get the DTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
282 	 * flag, or GST_CLOCK_TIME_NONE.
283 	 *
284 	 * Returns: The DTS at the last discont or GST_CLOCK_TIME_NONE.
285 	 *
286 	 * Since: 1.10
287 	 */
288 	public GstClockTime dtsAtDiscont()
289 	{
290 		return gst_adapter_dts_at_discont(gstAdapter);
291 	}
292 
293 	/**
294 	 * Flushes the first @flush bytes in the @adapter. The caller must ensure that
295 	 * at least this many bytes are available.
296 	 *
297 	 * See also: gst_adapter_map(), gst_adapter_unmap()
298 	 *
299 	 * Params:
300 	 *     flush = the number of bytes to flush
301 	 */
302 	public void flush(size_t flush)
303 	{
304 		gst_adapter_flush(gstAdapter, flush);
305 	}
306 
307 	/**
308 	 * Returns a #GstBuffer containing the first @nbytes of the @adapter, but
309 	 * does not flush them from the adapter. See gst_adapter_take_buffer()
310 	 * for details.
311 	 *
312 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
313 	 * usage.
314 	 *
315 	 * Free-function: gst_buffer_unref
316 	 *
317 	 * Params:
318 	 *     nbytes = the number of bytes to get
319 	 *
320 	 * Returns: a #GstBuffer containing the first
321 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
322 	 *     gst_buffer_unref() when no longer needed.
323 	 *
324 	 * Since: 1.6
325 	 */
326 	public Buffer getBuffer(size_t nbytes)
327 	{
328 		auto p = gst_adapter_get_buffer(gstAdapter, nbytes);
329 
330 		if(p is null)
331 		{
332 			return null;
333 		}
334 
335 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
336 	}
337 
338 	/**
339 	 * Returns a #GstBuffer containing the first @nbytes of the @adapter, but
340 	 * does not flush them from the adapter. See gst_adapter_take_buffer_fast()
341 	 * for details.
342 	 *
343 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
344 	 * usage.
345 	 *
346 	 * Free-function: gst_buffer_unref
347 	 *
348 	 * Params:
349 	 *     nbytes = the number of bytes to get
350 	 *
351 	 * Returns: a #GstBuffer containing the first
352 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
353 	 *     gst_buffer_unref() when no longer needed.
354 	 *
355 	 * Since: 1.6
356 	 */
357 	public Buffer getBufferFast(size_t nbytes)
358 	{
359 		auto p = gst_adapter_get_buffer_fast(gstAdapter, nbytes);
360 
361 		if(p is null)
362 		{
363 			return null;
364 		}
365 
366 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
367 	}
368 
369 	/**
370 	 * Returns a #GstBufferList of buffers containing the first @nbytes bytes of
371 	 * the @adapter but does not flush them from the adapter. See
372 	 * gst_adapter_take_buffer_list() for details.
373 	 *
374 	 * Caller owns the returned list. Call gst_buffer_list_unref() to free
375 	 * the list after usage.
376 	 *
377 	 * Params:
378 	 *     nbytes = the number of bytes to get
379 	 *
380 	 * Returns: a #GstBufferList of buffers containing
381 	 *     the first @nbytes of the adapter, or %NULL if @nbytes bytes are not
382 	 *     available
383 	 *
384 	 * Since: 1.6
385 	 */
386 	public BufferList getBufferList(size_t nbytes)
387 	{
388 		auto p = gst_adapter_get_buffer_list(gstAdapter, nbytes);
389 
390 		if(p is null)
391 		{
392 			return null;
393 		}
394 
395 		return ObjectG.getDObject!(BufferList)(cast(GstBufferList*) p, true);
396 	}
397 
398 	/**
399 	 * Returns a #GList of buffers containing the first @nbytes bytes of the
400 	 * @adapter, but does not flush them from the adapter. See
401 	 * gst_adapter_take_list() for details.
402 	 *
403 	 * Caller owns returned list and contained buffers. gst_buffer_unref() each
404 	 * buffer in the list before freeing the list after usage.
405 	 *
406 	 * Params:
407 	 *     nbytes = the number of bytes to get
408 	 *
409 	 * Returns: a #GList of
410 	 *     buffers containing the first @nbytes of the adapter, or %NULL if @nbytes
411 	 *     bytes are not available
412 	 *
413 	 * Since: 1.6
414 	 */
415 	public ListG getList(size_t nbytes)
416 	{
417 		auto p = gst_adapter_get_list(gstAdapter, nbytes);
418 
419 		if(p is null)
420 		{
421 			return null;
422 		}
423 
424 		return new ListG(cast(GList*) p, true);
425 	}
426 
427 	/**
428 	 * Gets the first @size bytes stored in the @adapter. The returned pointer is
429 	 * valid until the next function is called on the adapter.
430 	 *
431 	 * Note that setting the returned pointer as the data of a #GstBuffer is
432 	 * incorrect for general-purpose plugins. The reason is that if a downstream
433 	 * element stores the buffer so that it has access to it outside of the bounds
434 	 * of its chain function, the buffer will have an invalid data pointer after
435 	 * your element flushes the bytes. In that case you should use
436 	 * gst_adapter_take(), which returns a freshly-allocated buffer that you can set
437 	 * as #GstBuffer memory or the potentially more performant
438 	 * gst_adapter_take_buffer().
439 	 *
440 	 * Returns %NULL if @size bytes are not available.
441 	 *
442 	 * Params:
443 	 *     size = the number of bytes to map/peek
444 	 *
445 	 * Returns: a pointer to the first @size bytes of data, or %NULL
446 	 */
447 	public ubyte[] map(size_t size)
448 	{
449 		auto p = gst_adapter_map(gstAdapter, size);
450 
451 		return cast(ubyte[])p[0 .. size];
452 	}
453 
454 	/**
455 	 * Scan for pattern @pattern with applied mask @mask in the adapter data,
456 	 * starting from offset @offset.
457 	 *
458 	 * The bytes in @pattern and @mask are interpreted left-to-right, regardless
459 	 * of endianness.  All four bytes of the pattern must be present in the
460 	 * adapter for it to match, even if the first or last bytes are masked out.
461 	 *
462 	 * It is an error to call this function without making sure that there is
463 	 * enough data (offset+size bytes) in the adapter.
464 	 *
465 	 * This function calls gst_adapter_masked_scan_uint32_peek() passing %NULL
466 	 * for value.
467 	 *
468 	 * Params:
469 	 *     mask = mask to apply to data before matching against @pattern
470 	 *     pattern = pattern to match (after mask is applied)
471 	 *     offset = offset into the adapter data from which to start scanning, returns
472 	 *         the last scanned position.
473 	 *     size = number of bytes to scan from offset
474 	 *
475 	 * Returns: offset of the first match, or -1 if no match was found.
476 	 *
477 	 *     Example:
478 	 *     |[
479 	 *     // Assume the adapter contains 0x00 0x01 0x02 ... 0xfe 0xff
480 	 *
481 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 0, 256);
482 	 *     // -> returns 0
483 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 1, 255);
484 	 *     // -> returns -1
485 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x01020304, 1, 255);
486 	 *     // -> returns 1
487 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0001, 0, 256);
488 	 *     // -> returns -1
489 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0203, 0, 256);
490 	 *     // -> returns 0
491 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 256);
492 	 *     // -> returns 2
493 	 *     gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 4);
494 	 *     // -> returns -1
495 	 *     ]|
496 	 */
497 	public ptrdiff_t maskedScanUint32(uint mask, uint pattern, size_t offset, size_t size)
498 	{
499 		return gst_adapter_masked_scan_uint32(gstAdapter, mask, pattern, offset, size);
500 	}
501 
502 	/**
503 	 * Scan for pattern @pattern with applied mask @mask in the adapter data,
504 	 * starting from offset @offset.  If a match is found, the value that matched
505 	 * is returned through @value, otherwise @value is left untouched.
506 	 *
507 	 * The bytes in @pattern and @mask are interpreted left-to-right, regardless
508 	 * of endianness.  All four bytes of the pattern must be present in the
509 	 * adapter for it to match, even if the first or last bytes are masked out.
510 	 *
511 	 * It is an error to call this function without making sure that there is
512 	 * enough data (offset+size bytes) in the adapter.
513 	 *
514 	 * Params:
515 	 *     mask = mask to apply to data before matching against @pattern
516 	 *     pattern = pattern to match (after mask is applied)
517 	 *     offset = offset into the adapter data from which to start scanning, returns
518 	 *         the last scanned position.
519 	 *     size = number of bytes to scan from offset
520 	 *     value = pointer to uint32 to return matching data
521 	 *
522 	 * Returns: offset of the first match, or -1 if no match was found.
523 	 */
524 	public ptrdiff_t maskedScanUint32Peek(uint mask, uint pattern, size_t offset, size_t size, out uint value)
525 	{
526 		return gst_adapter_masked_scan_uint32_peek(gstAdapter, mask, pattern, offset, size, &value);
527 	}
528 
529 	/**
530 	 * Get the offset that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
531 	 * flag, or GST_BUFFER_OFFSET_NONE.
532 	 *
533 	 * Returns: The offset at the last discont or GST_BUFFER_OFFSET_NONE.
534 	 *
535 	 * Since: 1.10
536 	 */
537 	public ulong offsetAtDiscont()
538 	{
539 		return gst_adapter_offset_at_discont(gstAdapter);
540 	}
541 
542 	/**
543 	 * Get the dts that was before the current byte in the adapter. When
544 	 * @distance is given, the amount of bytes between the dts and the current
545 	 * position is returned.
546 	 *
547 	 * The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
548 	 * the adapter is first created or when it is cleared. This also means that before
549 	 * the first byte with a dts is removed from the adapter, the dts
550 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
551 	 *
552 	 * Params:
553 	 *     distance = pointer to location for distance, or %NULL
554 	 *
555 	 * Returns: The previously seen dts.
556 	 */
557 	public GstClockTime prevDts(out ulong distance)
558 	{
559 		return gst_adapter_prev_dts(gstAdapter, &distance);
560 	}
561 
562 	/**
563 	 * Get the dts that was before the byte at offset @offset in the adapter. When
564 	 * @distance is given, the amount of bytes between the dts and the current
565 	 * position is returned.
566 	 *
567 	 * The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
568 	 * the adapter is first created or when it is cleared. This also means that before
569 	 * the first byte with a dts is removed from the adapter, the dts
570 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
571 	 *
572 	 * Params:
573 	 *     offset = the offset in the adapter at which to get timestamp
574 	 *     distance = pointer to location for distance, or %NULL
575 	 *
576 	 * Returns: The previously seen dts at given offset.
577 	 *
578 	 * Since: 1.2
579 	 */
580 	public GstClockTime prevDtsAtOffset(size_t offset, out ulong distance)
581 	{
582 		return gst_adapter_prev_dts_at_offset(gstAdapter, offset, &distance);
583 	}
584 
585 	/**
586 	 * Get the offset that was before the current byte in the adapter. When
587 	 * @distance is given, the amount of bytes between the offset and the current
588 	 * position is returned.
589 	 *
590 	 * The offset is reset to GST_BUFFER_OFFSET_NONE and the distance is set to 0
591 	 * when the adapter is first created or when it is cleared. This also means that
592 	 * before the first byte with an offset is removed from the adapter, the offset
593 	 * and distance returned are GST_BUFFER_OFFSET_NONE and 0 respectively.
594 	 *
595 	 * Params:
596 	 *     distance = pointer to a location for distance, or %NULL
597 	 *
598 	 * Returns: The previous seen offset.
599 	 *
600 	 * Since: 1.10
601 	 */
602 	public ulong prevOffset(out ulong distance)
603 	{
604 		return gst_adapter_prev_offset(gstAdapter, &distance);
605 	}
606 
607 	/**
608 	 * Get the pts that was before the current byte in the adapter. When
609 	 * @distance is given, the amount of bytes between the pts and the current
610 	 * position is returned.
611 	 *
612 	 * The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
613 	 * the adapter is first created or when it is cleared. This also means that before
614 	 * the first byte with a pts is removed from the adapter, the pts
615 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
616 	 *
617 	 * Params:
618 	 *     distance = pointer to location for distance, or %NULL
619 	 *
620 	 * Returns: The previously seen pts.
621 	 */
622 	public GstClockTime prevPts(out ulong distance)
623 	{
624 		return gst_adapter_prev_pts(gstAdapter, &distance);
625 	}
626 
627 	/**
628 	 * Get the pts that was before the byte at offset @offset in the adapter. When
629 	 * @distance is given, the amount of bytes between the pts and the current
630 	 * position is returned.
631 	 *
632 	 * The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
633 	 * the adapter is first created or when it is cleared. This also means that before
634 	 * the first byte with a pts is removed from the adapter, the pts
635 	 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
636 	 *
637 	 * Params:
638 	 *     offset = the offset in the adapter at which to get timestamp
639 	 *     distance = pointer to location for distance, or %NULL
640 	 *
641 	 * Returns: The previously seen pts at given offset.
642 	 *
643 	 * Since: 1.2
644 	 */
645 	public GstClockTime prevPtsAtOffset(size_t offset, out ulong distance)
646 	{
647 		return gst_adapter_prev_pts_at_offset(gstAdapter, offset, &distance);
648 	}
649 
650 	/**
651 	 * Get the PTS that was on the last buffer with the GST_BUFFER_FLAG_DISCONT
652 	 * flag, or GST_CLOCK_TIME_NONE.
653 	 *
654 	 * Returns: The PTS at the last discont or GST_CLOCK_TIME_NONE.
655 	 *
656 	 * Since: 1.10
657 	 */
658 	public GstClockTime ptsAtDiscont()
659 	{
660 		return gst_adapter_pts_at_discont(gstAdapter);
661 	}
662 
663 	/**
664 	 * Adds the data from @buf to the data stored inside @adapter and takes
665 	 * ownership of the buffer.
666 	 *
667 	 * Params:
668 	 *     buf = a #GstBuffer to add to queue in the adapter
669 	 */
670 	public void push(Buffer buf)
671 	{
672 		gst_adapter_push(gstAdapter, (buf is null) ? null : buf.getBufferStruct());
673 	}
674 
675 	/**
676 	 * Returns a freshly allocated buffer containing the first @nbytes bytes of the
677 	 * @adapter. The returned bytes will be flushed from the adapter.
678 	 *
679 	 * Caller owns returned value. g_free after usage.
680 	 *
681 	 * Free-function: g_free
682 	 *
683 	 * Params:
684 	 *     nbytes = the number of bytes to take
685 	 *
686 	 * Returns: oven-fresh hot data, or %NULL if @nbytes bytes are not available
687 	 */
688 	public ubyte[] take(size_t nbytes)
689 	{
690 		auto p = gst_adapter_take(gstAdapter, nbytes);
691 
692 		return cast(ubyte[])p[0 .. nbytes];
693 	}
694 
695 	/**
696 	 * Returns a #GstBuffer containing the first @nbytes bytes of the
697 	 * @adapter. The returned bytes will be flushed from the adapter.
698 	 * This function is potentially more performant than
699 	 * gst_adapter_take() since it can reuse the memory in pushed buffers
700 	 * by subbuffering or merging. This function will always return a
701 	 * buffer with a single memory region.
702 	 *
703 	 * Note that no assumptions should be made as to whether certain buffer
704 	 * flags such as the DISCONT flag are set on the returned buffer, or not.
705 	 * The caller needs to explicitly set or unset flags that should be set or
706 	 * unset.
707 	 *
708 	 * Since 1.6 this will also copy over all GstMeta of the input buffers except
709 	 * for meta with the %GST_META_FLAG_POOLED flag or with the "memory" tag.
710 	 *
711 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
712 	 * usage.
713 	 *
714 	 * Free-function: gst_buffer_unref
715 	 *
716 	 * Params:
717 	 *     nbytes = the number of bytes to take
718 	 *
719 	 * Returns: a #GstBuffer containing the first
720 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
721 	 *     gst_buffer_unref() when no longer needed.
722 	 */
723 	public Buffer takeBuffer(size_t nbytes)
724 	{
725 		auto p = gst_adapter_take_buffer(gstAdapter, nbytes);
726 
727 		if(p is null)
728 		{
729 			return null;
730 		}
731 
732 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
733 	}
734 
735 	/**
736 	 * Returns a #GstBuffer containing the first @nbytes of the @adapter.
737 	 * The returned bytes will be flushed from the adapter.  This function
738 	 * is potentially more performant than gst_adapter_take_buffer() since
739 	 * it can reuse the memory in pushed buffers by subbuffering or
740 	 * merging. Unlike gst_adapter_take_buffer(), the returned buffer may
741 	 * be composed of multiple non-contiguous #GstMemory objects, no
742 	 * copies are made.
743 	 *
744 	 * Note that no assumptions should be made as to whether certain buffer
745 	 * flags such as the DISCONT flag are set on the returned buffer, or not.
746 	 * The caller needs to explicitly set or unset flags that should be set or
747 	 * unset.
748 	 *
749 	 * This will also copy over all GstMeta of the input buffers except
750 	 * for meta with the %GST_META_FLAG_POOLED flag or with the "memory" tag.
751 	 *
752 	 * This function can return buffer up to the return value of
753 	 * gst_adapter_available() without making copies if possible.
754 	 *
755 	 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
756 	 * usage.
757 	 *
758 	 * Free-function: gst_buffer_unref
759 	 *
760 	 * Params:
761 	 *     nbytes = the number of bytes to take
762 	 *
763 	 * Returns: a #GstBuffer containing the first
764 	 *     @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
765 	 *     gst_buffer_unref() when no longer needed.
766 	 *
767 	 * Since: 1.2
768 	 */
769 	public Buffer takeBufferFast(size_t nbytes)
770 	{
771 		auto p = gst_adapter_take_buffer_fast(gstAdapter, nbytes);
772 
773 		if(p is null)
774 		{
775 			return null;
776 		}
777 
778 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true);
779 	}
780 
781 	/**
782 	 * Returns a #GstBufferList of buffers containing the first @nbytes bytes of
783 	 * the @adapter. The returned bytes will be flushed from the adapter.
784 	 * When the caller can deal with individual buffers, this function is more
785 	 * performant because no memory should be copied.
786 	 *
787 	 * Caller owns the returned list. Call gst_buffer_list_unref() to free
788 	 * the list after usage.
789 	 *
790 	 * Params:
791 	 *     nbytes = the number of bytes to take
792 	 *
793 	 * Returns: a #GstBufferList of buffers containing
794 	 *     the first @nbytes of the adapter, or %NULL if @nbytes bytes are not
795 	 *     available
796 	 *
797 	 * Since: 1.6
798 	 */
799 	public BufferList takeBufferList(size_t nbytes)
800 	{
801 		auto p = gst_adapter_take_buffer_list(gstAdapter, nbytes);
802 
803 		if(p is null)
804 		{
805 			return null;
806 		}
807 
808 		return ObjectG.getDObject!(BufferList)(cast(GstBufferList*) p, true);
809 	}
810 
811 	/**
812 	 * Returns a #GList of buffers containing the first @nbytes bytes of the
813 	 * @adapter. The returned bytes will be flushed from the adapter.
814 	 * When the caller can deal with individual buffers, this function is more
815 	 * performant because no memory should be copied.
816 	 *
817 	 * Caller owns returned list and contained buffers. gst_buffer_unref() each
818 	 * buffer in the list before freeing the list after usage.
819 	 *
820 	 * Params:
821 	 *     nbytes = the number of bytes to take
822 	 *
823 	 * Returns: a #GList of
824 	 *     buffers containing the first @nbytes of the adapter, or %NULL if @nbytes
825 	 *     bytes are not available
826 	 */
827 	public ListG takeList(size_t nbytes)
828 	{
829 		auto p = gst_adapter_take_list(gstAdapter, nbytes);
830 
831 		if(p is null)
832 		{
833 			return null;
834 		}
835 
836 		return new ListG(cast(GList*) p, true);
837 	}
838 
839 	/**
840 	 * Releases the memory obtained with the last gst_adapter_map().
841 	 */
842 	public void unmap()
843 	{
844 		gst_adapter_unmap(gstAdapter);
845 	}
846 }