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