2 * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
3 * 2005 Wim Taymans <wim@fluendo.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
23 * @short_description: adapts incoming data on a sink pad into chunks of N bytes
25 * This class is for elements that receive buffers in an undesired size.
26 * While for example raw video contains one image per buffer, the same is not
27 * true for a lot of other formats, especially those that come directly from
28 * a file. So if you have undefined buffer sizes and require a specific size,
29 * this object is for you.
31 * An adapter is created with gst_adapter_new(). It can be freed again with
34 * The theory of operation is like this: All buffers received are put
35 * into the adapter using gst_adapter_push() and the data is then read back
36 * in chunks of the desired size using gst_adapter_map()/gst_adapter_unmap()
37 * and/or gst_adapter_copy(). After the data has been processed, it is freed
38 * using gst_adapter_unmap().
40 * Other methods such as gst_adapter_take() and gst_adapter_take_buffer()
41 * combine gst_adapter_map() and gst_adapter_unmap() in one method and are
42 * potentially more convenient for some use cases.
44 * For example, a sink pad's chain function that needs to pass data to a library
45 * in 512-byte chunks could be implemented like this:
47 * static GstFlowReturn
48 * sink_pad_chain (GstPad *pad, GstObject *parent, GstBuffer *buffer)
51 * GstAdapter *adapter;
52 * GstFlowReturn ret = GST_FLOW_OK;
54 * this = MY_ELEMENT (parent);
56 * adapter = this->adapter;
58 * // put buffer into adapter
59 * gst_adapter_push (adapter, buffer);
61 * // while we can read out 512 bytes, process them
62 * while (gst_adapter_available (adapter) >= 512 && ret == GST_FLOW_OK) {
63 * const guint8 *data = gst_adapter_map (adapter, 512);
64 * // use flowreturn as an error value
65 * ret = my_library_foo (data);
66 * gst_adapter_unmap (adapter);
67 * gst_adapter_flush (adapter, 512);
73 * For another example, a simple element inside GStreamer that uses #GstAdapter
74 * is the libvisual element.
76 * An element using #GstAdapter in its sink pad chain function should ensure that
77 * when the FLUSH_STOP event is received, that any queued data is cleared using
78 * gst_adapter_clear(). Data should also be cleared or processed on EOS and
79 * when changing state from %GST_STATE_PAUSED to %GST_STATE_READY.
81 * Also check the GST_BUFFER_FLAG_DISCONT flag on the buffer. Some elements might
82 * need to clear the adapter after a discontinuity.
84 * The adapter will keep track of the timestamps of the buffers
85 * that were pushed. The last seen timestamp before the current position
86 * can be queried with gst_adapter_prev_pts(). This function can
87 * optionally return the number of bytes between the start of the buffer that
88 * carried the timestamp and the current adapter position. The distance is
89 * useful when dealing with, for example, raw audio samples because it allows
90 * you to calculate the timestamp of the current adapter position by using the
91 * last seen timestamp and the amount of bytes since. Additionally, the
92 * gst_adapter_prev_pts_at_offset() can be used to determine the last
93 * seen timestamp at a particular offset in the adapter.
95 * A last thing to note is that while #GstAdapter is pretty optimized,
96 * merging buffers still might be an operation that requires a malloc() and
97 * memcpy() operation, and these operations are not the fastest. Because of
98 * this, some functions like gst_adapter_available_fast() are provided to help
99 * speed up such cases should you want to. To avoid repeated memory allocations,
100 * gst_adapter_copy() can be used to copy data into a (statically allocated)
101 * user provided buffer.
103 * #GstAdapter is not MT safe. All operations on an adapter must be serialized by
104 * the caller. This is not normally a problem, however, as the normal use case
105 * of #GstAdapter is inside one pad's chain function, in which case access is
106 * serialized via the pad's STREAM_LOCK.
108 * Note that gst_adapter_push() takes ownership of the buffer passed. Use
109 * gst_buffer_ref() before pushing it into the adapter if you still want to
110 * access the buffer later. The adapter will never modify the data in the
111 * buffer pushed in it.
114 #include <gst/gst_private.h>
115 #include "gstadapter.h"
118 /* default size for the assembled data buffer */
119 #define DEFAULT_SIZE 4096
121 static void gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush);
123 GST_DEBUG_CATEGORY_STATIC (gst_adapter_debug);
124 #define GST_CAT_DEFAULT gst_adapter_debug
137 /* we keep state of assembled pieces */
138 gpointer assembled_data;
139 gsize assembled_size;
143 guint64 pts_distance;
145 guint64 dts_distance;
153 struct _GstAdapterClass
155 GObjectClass parent_class;
159 GST_DEBUG_CATEGORY_INIT (gst_adapter_debug, "adapter", 0, "object to splice and merge buffers to desired size")
160 #define gst_adapter_parent_class parent_class
161 G_DEFINE_TYPE_WITH_CODE (GstAdapter, gst_adapter, G_TYPE_OBJECT, _do_init);
163 static void gst_adapter_dispose (GObject * object);
164 static void gst_adapter_finalize (GObject * object);
167 gst_adapter_class_init (GstAdapterClass * klass)
169 GObjectClass *object = G_OBJECT_CLASS (klass);
171 object->dispose = gst_adapter_dispose;
172 object->finalize = gst_adapter_finalize;
176 gst_adapter_init (GstAdapter * adapter)
178 adapter->assembled_data = g_malloc (DEFAULT_SIZE);
179 adapter->assembled_size = DEFAULT_SIZE;
180 adapter->pts = GST_CLOCK_TIME_NONE;
181 adapter->pts_distance = 0;
182 adapter->dts = GST_CLOCK_TIME_NONE;
183 adapter->dts_distance = 0;
187 gst_adapter_dispose (GObject * object)
189 GstAdapter *adapter = GST_ADAPTER (object);
191 gst_adapter_clear (adapter);
193 GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
197 gst_adapter_finalize (GObject * object)
199 GstAdapter *adapter = GST_ADAPTER (object);
201 g_free (adapter->assembled_data);
203 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
209 * Creates a new #GstAdapter. Free with g_object_unref().
211 * Returns: (transfer full): a new #GstAdapter
214 gst_adapter_new (void)
216 return g_object_newv (GST_TYPE_ADAPTER, 0, NULL);
221 * @adapter: a #GstAdapter
223 * Removes all buffers from @adapter.
226 gst_adapter_clear (GstAdapter * adapter)
228 g_return_if_fail (GST_IS_ADAPTER (adapter));
230 if (adapter->info.memory)
231 gst_adapter_unmap (adapter);
233 g_slist_foreach (adapter->buflist, (GFunc) gst_mini_object_unref, NULL);
234 g_slist_free (adapter->buflist);
235 adapter->buflist = NULL;
236 adapter->buflist_end = NULL;
240 adapter->assembled_len = 0;
241 adapter->pts = GST_CLOCK_TIME_NONE;
242 adapter->pts_distance = 0;
243 adapter->dts = GST_CLOCK_TIME_NONE;
244 adapter->dts_distance = 0;
245 adapter->scan_offset = 0;
246 adapter->scan_entry = NULL;
250 update_timestamps (GstAdapter * adapter, GstBuffer * buf)
252 GstClockTime pts, dts;
254 pts = GST_BUFFER_PTS (buf);
255 if (GST_CLOCK_TIME_IS_VALID (pts)) {
256 GST_LOG_OBJECT (adapter, "new pts %" GST_TIME_FORMAT, GST_TIME_ARGS (pts));
258 adapter->pts_distance = 0;
260 dts = GST_BUFFER_DTS (buf);
261 if (GST_CLOCK_TIME_IS_VALID (dts)) {
262 GST_LOG_OBJECT (adapter, "new dts %" GST_TIME_FORMAT, GST_TIME_ARGS (dts));
264 adapter->dts_distance = 0;
268 /* copy data into @dest, skipping @skip bytes from the head buffers */
270 copy_into_unchecked (GstAdapter * adapter, guint8 * dest, gsize skip,
277 /* first step, do skipping */
278 /* we might well be copying where we were scanning */
279 if (adapter->scan_entry && (adapter->scan_offset <= skip)) {
280 g = adapter->scan_entry;
281 skip -= adapter->scan_offset;
283 g = adapter->buflist;
286 bsize = gst_buffer_get_size (buf);
287 while (G_UNLIKELY (skip >= bsize)) {
289 g = g_slist_next (g);
291 bsize = gst_buffer_get_size (buf);
293 /* copy partial buffer */
294 csize = MIN (bsize - skip, size);
295 GST_DEBUG ("bsize %" G_GSIZE_FORMAT ", skip %" G_GSIZE_FORMAT ", csize %"
296 G_GSIZE_FORMAT, bsize, skip, csize);
297 GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, adapter, "extract %" G_GSIZE_FORMAT
299 gst_buffer_extract (buf, skip, dest, csize);
303 /* second step, copy remainder */
305 g = g_slist_next (g);
307 bsize = gst_buffer_get_size (buf);
308 if (G_LIKELY (bsize > 0)) {
309 csize = MIN (bsize, size);
310 GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, adapter,
311 "extract %" G_GSIZE_FORMAT " bytes", csize);
312 gst_buffer_extract (buf, 0, dest, csize);
321 * @adapter: a #GstAdapter
322 * @buf: (transfer full): a #GstBuffer to add to queue in the adapter
324 * Adds the data from @buf to the data stored inside @adapter and takes
325 * ownership of the buffer.
328 gst_adapter_push (GstAdapter * adapter, GstBuffer * buf)
332 g_return_if_fail (GST_IS_ADAPTER (adapter));
333 g_return_if_fail (GST_IS_BUFFER (buf));
335 size = gst_buffer_get_size (buf);
336 adapter->size += size;
338 /* Note: merging buffers at this point is premature. */
339 if (G_UNLIKELY (adapter->buflist == NULL)) {
340 GST_LOG_OBJECT (adapter, "pushing %p first %" G_GSIZE_FORMAT " bytes",
342 adapter->buflist = adapter->buflist_end = g_slist_append (NULL, buf);
343 update_timestamps (adapter, buf);
345 /* Otherwise append to the end, and advance our end pointer */
346 GST_LOG_OBJECT (adapter, "pushing %p %" G_GSIZE_FORMAT " bytes at end, "
347 "size now %" G_GSIZE_FORMAT, buf, size, adapter->size);
348 adapter->buflist_end = g_slist_append (adapter->buflist_end, buf);
349 adapter->buflist_end = g_slist_next (adapter->buflist_end);
355 /* Internal method only. Tries to merge buffers at the head of the queue
356 * to form a single larger buffer of size 'size'.
358 * Returns %TRUE if it managed to merge anything.
361 gst_adapter_try_to_merge_up (GstAdapter * adapter, gsize size)
363 GstBuffer *cur, *head;
365 gboolean ret = FALSE;
368 g = adapter->buflist;
374 hsize = gst_buffer_get_size (head);
376 /* Remove skipped part from the buffer (otherwise the buffer might grow indefinitely) */
377 head = gst_buffer_make_writable (head);
378 gst_buffer_resize (head, adapter->skip, hsize - adapter->skip);
379 hsize -= adapter->skip;
383 g = g_slist_next (g);
385 while (g != NULL && hsize < size) {
387 /* Merge the head buffer and the next in line */
388 GST_LOG_OBJECT (adapter, "Merging buffers of size %" G_GSIZE_FORMAT " & %"
389 G_GSIZE_FORMAT " in search of target %" G_GSIZE_FORMAT,
390 hsize, gst_buffer_get_size (cur), size);
392 head = gst_buffer_append (head, cur);
393 hsize = gst_buffer_get_size (head);
396 /* Delete the front list item, and store our new buffer in the 2nd list
398 adapter->buflist = g_slist_delete_link (adapter->buflist, adapter->buflist);
401 /* invalidate scan position */
402 adapter->scan_offset = 0;
403 adapter->scan_entry = NULL;
405 g = g_slist_next (g);
414 * @adapter: a #GstAdapter
415 * @size: the number of bytes to map/peek
417 * Gets the first @size bytes stored in the @adapter. The returned pointer is
418 * valid until the next function is called on the adapter.
420 * Note that setting the returned pointer as the data of a #GstBuffer is
421 * incorrect for general-purpose plugins. The reason is that if a downstream
422 * element stores the buffer so that it has access to it outside of the bounds
423 * of its chain function, the buffer will have an invalid data pointer after
424 * your element flushes the bytes. In that case you should use
425 * gst_adapter_take(), which returns a freshly-allocated buffer that you can set
426 * as #GstBuffer memory or the potentially more performant
427 * gst_adapter_take_buffer().
429 * Returns %NULL if @size bytes are not available.
431 * Returns: (transfer none) (array length=size) (element-type guint8) (nullable):
432 * a pointer to the first @size bytes of data, or %NULL
435 gst_adapter_map (GstAdapter * adapter, gsize size)
439 gsize toreuse, tocopy;
442 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
443 g_return_val_if_fail (size > 0, NULL);
445 if (adapter->info.memory)
446 gst_adapter_unmap (adapter);
448 /* we don't have enough data, return NULL. This is unlikely
449 * as one usually does an _available() first instead of peeking a
451 if (G_UNLIKELY (size > adapter->size))
454 /* we have enough assembled data, return it */
455 if (adapter->assembled_len >= size)
456 return adapter->assembled_data;
461 cur = adapter->buflist->data;
462 skip = adapter->skip;
464 csize = gst_buffer_get_size (cur);
465 if (csize >= size + skip) {
466 if (!gst_buffer_map (cur, &adapter->info, GST_MAP_READ))
469 return (guint8 *) adapter->info.data + skip;
471 /* We may be able to efficiently merge buffers in our pool to
472 * gather a big enough chunk to return it from the head buffer directly */
474 } while (gst_adapter_try_to_merge_up (adapter, size));
477 /* see how much data we can reuse from the assembled memory and how much
479 toreuse = adapter->assembled_len;
480 tocopy = size - toreuse;
482 /* Gonna need to copy stuff out */
483 if (G_UNLIKELY (adapter->assembled_size < size)) {
484 adapter->assembled_size = (size / DEFAULT_SIZE + 1) * DEFAULT_SIZE;
485 GST_DEBUG_OBJECT (adapter, "resizing internal buffer to %" G_GSIZE_FORMAT,
486 adapter->assembled_size);
488 GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "alloc new buffer");
489 /* no g_realloc to avoid a memcpy that is not desired here since we are
490 * not going to reuse any data here */
491 g_free (adapter->assembled_data);
492 adapter->assembled_data = g_malloc (adapter->assembled_size);
494 /* we are going to reuse all data, realloc then */
495 GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "reusing %" G_GSIZE_FORMAT " bytes",
497 adapter->assembled_data =
498 g_realloc (adapter->assembled_data, adapter->assembled_size);
501 GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "copy remaining %" G_GSIZE_FORMAT
502 " bytes from adapter", tocopy);
503 data = adapter->assembled_data;
504 copy_into_unchecked (adapter, data + toreuse, skip + toreuse, tocopy);
505 adapter->assembled_len = size;
507 return adapter->assembled_data;
512 * @adapter: a #GstAdapter
514 * Releases the memory obtained with the last gst_adapter_map().
517 gst_adapter_unmap (GstAdapter * adapter)
519 g_return_if_fail (GST_IS_ADAPTER (adapter));
521 if (adapter->info.memory) {
522 GstBuffer *cur = adapter->buflist->data;
523 GST_LOG_OBJECT (adapter, "unmap memory buffer %p", cur);
524 gst_buffer_unmap (cur, &adapter->info);
525 adapter->info.memory = NULL;
530 * gst_adapter_copy: (skip)
531 * @adapter: a #GstAdapter
532 * @dest: (out caller-allocates) (array length=size) (element-type guint8):
533 * the memory to copy into
534 * @offset: the bytes offset in the adapter to start from
535 * @size: the number of bytes to copy
537 * Copies @size bytes of data starting at @offset out of the buffers
538 * contained in #GstAdapter into an array @dest provided by the caller.
540 * The array @dest should be large enough to contain @size bytes.
541 * The user should check that the adapter has (@offset + @size) bytes
542 * available before calling this function.
545 gst_adapter_copy (GstAdapter * adapter, gpointer dest, gsize offset, gsize size)
547 g_return_if_fail (GST_IS_ADAPTER (adapter));
548 g_return_if_fail (size > 0);
549 g_return_if_fail (offset + size <= adapter->size);
551 copy_into_unchecked (adapter, dest, offset + adapter->skip, size);
555 * gst_adapter_copy_bytes: (rename-to gst_adapter_copy)
556 * @adapter: a #GstAdapter
557 * @offset: the bytes offset in the adapter to start from
558 * @size: the number of bytes to copy
560 * Similar to gst_adapter_copy, but more suitable for language bindings. @size
561 * bytes of data starting at @offset will be copied out of the buffers contained
562 * in @adapter and into a new #GBytes structure which is returned. Depending on
563 * the value of the @size argument an empty #GBytes structure may be returned.
565 * Returns: (transfer full): A new #GBytes structure containing the copied data.
570 gst_adapter_copy_bytes (GstAdapter * adapter, gsize offset, gsize size)
573 data = g_malloc (size);
574 gst_adapter_copy (adapter, data, offset, size);
575 return g_bytes_new_take (data, size);
578 /*Flushes the first @flush bytes in the @adapter*/
580 gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
586 GST_LOG_OBJECT (adapter, "flushing %" G_GSIZE_FORMAT " bytes", flush);
588 if (adapter->info.memory)
589 gst_adapter_unmap (adapter);
592 adapter->size -= flush;
593 adapter->assembled_len = 0;
595 /* take skip into account */
596 flush += adapter->skip;
597 /* distance is always at least the amount of skipped bytes */
598 adapter->pts_distance -= adapter->skip;
599 adapter->dts_distance -= adapter->skip;
601 g = adapter->buflist;
603 size = gst_buffer_get_size (cur);
604 while (flush >= size) {
605 /* can skip whole buffer */
606 GST_LOG_OBJECT (adapter, "flushing out head buffer");
607 adapter->pts_distance += size;
608 adapter->dts_distance += size;
611 gst_buffer_unref (cur);
612 g = g_slist_delete_link (g, g);
615 if (G_UNLIKELY (g == NULL)) {
616 GST_LOG_OBJECT (adapter, "adapter empty now");
617 adapter->buflist_end = NULL;
620 /* there is a new head buffer, update the timestamps */
622 update_timestamps (adapter, cur);
623 size = gst_buffer_get_size (cur);
625 adapter->buflist = g;
626 /* account for the remaining bytes */
627 adapter->skip = flush;
628 adapter->pts_distance += flush;
629 adapter->dts_distance += flush;
630 /* invalidate scan position */
631 adapter->scan_offset = 0;
632 adapter->scan_entry = NULL;
637 * @adapter: a #GstAdapter
638 * @flush: the number of bytes to flush
640 * Flushes the first @flush bytes in the @adapter. The caller must ensure that
641 * at least this many bytes are available.
643 * See also: gst_adapter_map(), gst_adapter_unmap()
646 gst_adapter_flush (GstAdapter * adapter, gsize flush)
648 g_return_if_fail (GST_IS_ADAPTER (adapter));
649 g_return_if_fail (flush <= adapter->size);
651 /* flushing out 0 bytes will do nothing */
652 if (G_UNLIKELY (flush == 0))
655 gst_adapter_flush_unchecked (adapter, flush);
658 /* internal function, nbytes should be flushed if needed after calling this function */
660 gst_adapter_get_internal (GstAdapter * adapter, gsize nbytes)
663 gsize toreuse, tocopy;
665 /* see how much data we can reuse from the assembled memory and how much
667 toreuse = MIN (nbytes, adapter->assembled_len);
668 tocopy = nbytes - toreuse;
670 /* find memory to return */
671 if (adapter->assembled_size >= nbytes && toreuse > 0) {
672 /* we reuse already allocated memory but only when we're going to reuse
673 * something from it because else we are worse than the malloc and copy
675 GST_LOG_OBJECT (adapter, "reusing %" G_GSIZE_FORMAT " bytes of assembled"
677 /* we have enough free space in the assembled array */
678 data = adapter->assembled_data;
679 /* flush after this function should set the assembled_size to 0 */
680 adapter->assembled_data = g_malloc (adapter->assembled_size);
682 GST_LOG_OBJECT (adapter, "allocating %" G_GSIZE_FORMAT " bytes", nbytes);
683 /* not enough bytes in the assembled array, just allocate new space */
684 data = g_malloc (nbytes);
685 /* reuse what we can from the already assembled data */
687 GST_LOG_OBJECT (adapter, "reusing %" G_GSIZE_FORMAT " bytes", toreuse);
688 GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, adapter,
689 "memcpy %" G_GSIZE_FORMAT " bytes", toreuse);
690 memcpy (data, adapter->assembled_data, toreuse);
694 /* copy the remaining data */
695 copy_into_unchecked (adapter, toreuse + data, toreuse + adapter->skip,
703 * @adapter: a #GstAdapter
704 * @nbytes: the number of bytes to take
706 * Returns a freshly allocated buffer containing the first @nbytes bytes of the
707 * @adapter. The returned bytes will be flushed from the adapter.
709 * Caller owns returned value. g_free after usage.
711 * Free-function: g_free
713 * Returns: (transfer full) (array length=nbytes) (element-type guint8) (nullable):
714 * oven-fresh hot data, or %NULL if @nbytes bytes are not available
717 gst_adapter_take (GstAdapter * adapter, gsize nbytes)
721 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
722 g_return_val_if_fail (nbytes > 0, NULL);
724 /* we don't have enough data, return NULL. This is unlikely
725 * as one usually does an _available() first instead of peeking a
727 if (G_UNLIKELY (nbytes > adapter->size))
730 data = gst_adapter_get_internal (adapter, nbytes);
732 gst_adapter_flush_unchecked (adapter, nbytes);
738 * gst_adapter_get_buffer_fast:
739 * @adapter: a #GstAdapter
740 * @nbytes: the number of bytes to get
742 * Returns a #GstBuffer containing the first @nbytes of the @adapter, but
743 * does not flush them from the adapter. See gst_adapter_take_buffer_fast()
746 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
749 * Free-function: gst_buffer_unref
751 * Returns: (transfer full) (nullable): a #GstBuffer containing the first
752 * @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
753 * gst_buffer_unref() when no longer needed.
758 gst_adapter_get_buffer_fast (GstAdapter * adapter, gsize nbytes)
760 GstBuffer *buffer = NULL;
766 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
767 g_return_val_if_fail (nbytes > 0, NULL);
769 GST_LOG_OBJECT (adapter, "getting buffer of %" G_GSIZE_FORMAT " bytes",
772 /* we don't have enough data, return NULL. This is unlikely
773 * as one usually does an _available() first instead of grabbing a
775 if (G_UNLIKELY (nbytes > adapter->size))
778 skip = adapter->skip;
779 cur = adapter->buflist->data;
781 if (skip == 0 && gst_buffer_get_size (cur) == nbytes) {
782 GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
783 " as head buffer", nbytes);
784 buffer = gst_buffer_ref (cur);
788 for (item = adapter->buflist; item && left > 0; item = item->next) {
789 gsize size, cur_size;
792 cur_size = gst_buffer_get_size (cur);
793 size = MIN (cur_size - skip, left);
795 GST_LOG_OBJECT (adapter, "appending %" G_GSIZE_FORMAT " bytes"
796 " via region copy", size);
798 gst_buffer_copy_into (buffer, cur,
799 GST_BUFFER_COPY_MEMORY | GST_BUFFER_COPY_META, skip, size);
801 buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, size);
812 * gst_adapter_take_buffer_fast:
813 * @adapter: a #GstAdapter
814 * @nbytes: the number of bytes to take
816 * Returns a #GstBuffer containing the first @nbytes of the @adapter.
817 * The returned bytes will be flushed from the adapter. This function
818 * is potentially more performant than gst_adapter_take_buffer() since
819 * it can reuse the memory in pushed buffers by subbuffering or
820 * merging. Unlike gst_adapter_take_buffer(), the returned buffer may
821 * be composed of multiple non-contiguous #GstMemory objects, no
824 * Note that no assumptions should be made as to whether certain buffer
825 * flags such as the DISCONT flag are set on the returned buffer, or not.
826 * The caller needs to explicitly set or unset flags that should be set or
829 * This will also copy over all GstMeta of the input buffers except
830 * for meta with the %GST_META_FLAG_POOLED flag or with the "memory" tag.
832 * This function can return buffer up to the return value of
833 * gst_adapter_available() without making copies if possible.
835 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
838 * Free-function: gst_buffer_unref
840 * Returns: (transfer full) (nullable): a #GstBuffer containing the first
841 * @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
842 * gst_buffer_unref() when no longer needed.
847 gst_adapter_take_buffer_fast (GstAdapter * adapter, gsize nbytes)
851 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
852 g_return_val_if_fail (nbytes > 0, NULL);
854 buffer = gst_adapter_get_buffer_fast (adapter, nbytes);
856 gst_adapter_flush_unchecked (adapter, nbytes);
862 foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
864 GstBuffer *outbuf = user_data;
865 const GstMetaInfo *info = (*meta)->info;
866 gboolean do_copy = FALSE;
868 if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
869 /* never call the transform_meta with memory specific metadata */
870 GST_DEBUG ("not copying memory specific metadata %s",
871 g_type_name (info->api));
875 GST_DEBUG ("copying metadata %s", g_type_name (info->api));
879 GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
880 GST_DEBUG ("copy metadata %s", g_type_name (info->api));
881 /* simply copy then */
882 info->transform_func (outbuf, *meta, inbuf,
883 _gst_meta_transform_copy, ©_data);
889 * gst_adapter_get_buffer:
890 * @adapter: a #GstAdapter
891 * @nbytes: the number of bytes to get
893 * Returns a #GstBuffer containing the first @nbytes of the @adapter, but
894 * does not flush them from the adapter. See gst_adapter_take_buffer()
897 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
900 * Free-function: gst_buffer_unref
902 * Returns: (transfer full) (nullable): a #GstBuffer containing the first
903 * @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
904 * gst_buffer_unref() when no longer needed.
909 gst_adapter_get_buffer (GstAdapter * adapter, gsize nbytes)
916 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
917 g_return_val_if_fail (nbytes > 0, NULL);
919 GST_LOG_OBJECT (adapter, "getting buffer of %" G_GSIZE_FORMAT " bytes",
922 /* we don't have enough data, return NULL. This is unlikely
923 * as one usually does an _available() first instead of grabbing a
925 if (G_UNLIKELY (nbytes > adapter->size))
928 cur = adapter->buflist->data;
929 skip = adapter->skip;
930 hsize = gst_buffer_get_size (cur);
932 /* our head buffer has enough data left, return it */
933 if (skip == 0 && hsize == nbytes) {
934 GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
935 " as head buffer", nbytes);
936 buffer = gst_buffer_ref (cur);
938 } else if (hsize >= nbytes + skip) {
939 GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
940 " via region copy", nbytes);
941 buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, nbytes);
945 if (gst_adapter_try_to_merge_up (adapter, nbytes)) {
946 /* Merged something, let's try again for sub-buffering */
947 cur = adapter->buflist->data;
948 skip = adapter->skip;
949 if (gst_buffer_get_size (cur) >= nbytes + skip) {
950 GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
951 " via sub-buffer", nbytes);
952 buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, nbytes);
958 data = gst_adapter_get_internal (adapter, nbytes);
960 buffer = gst_buffer_new_wrapped (data, nbytes);
965 gsize read_offset = 0;
967 g = adapter->buflist;
968 while (g && read_offset < nbytes + adapter->skip) {
971 gst_buffer_foreach_meta (cur, foreach_metadata, buffer);
972 read_offset += gst_buffer_get_size (cur);
974 g = g_slist_next (g);
984 * gst_adapter_take_buffer:
985 * @adapter: a #GstAdapter
986 * @nbytes: the number of bytes to take
988 * Returns a #GstBuffer containing the first @nbytes bytes of the
989 * @adapter. The returned bytes will be flushed from the adapter.
990 * This function is potentially more performant than
991 * gst_adapter_take() since it can reuse the memory in pushed buffers
992 * by subbuffering or merging. This function will always return a
993 * buffer with a single memory region.
995 * Note that no assumptions should be made as to whether certain buffer
996 * flags such as the DISCONT flag are set on the returned buffer, or not.
997 * The caller needs to explicitly set or unset flags that should be set or
1000 * Since 1.6 this will also copy over all GstMeta of the input buffers except
1001 * for meta with the %GST_META_FLAG_POOLED flag or with the "memory" tag.
1003 * Caller owns a reference to the returned buffer. gst_buffer_unref() after
1006 * Free-function: gst_buffer_unref
1008 * Returns: (transfer full) (nullable): a #GstBuffer containing the first
1009 * @nbytes of the adapter, or %NULL if @nbytes bytes are not available.
1010 * gst_buffer_unref() when no longer needed.
1013 gst_adapter_take_buffer (GstAdapter * adapter, gsize nbytes)
1017 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1018 g_return_val_if_fail (nbytes > 0, NULL);
1020 buffer = gst_adapter_get_buffer (adapter, nbytes);
1022 gst_adapter_flush_unchecked (adapter, nbytes);
1028 * gst_adapter_take_list:
1029 * @adapter: a #GstAdapter
1030 * @nbytes: the number of bytes to take
1032 * Returns a #GList of buffers containing the first @nbytes bytes of the
1033 * @adapter. The returned bytes will be flushed from the adapter.
1034 * When the caller can deal with individual buffers, this function is more
1035 * performant because no memory should be copied.
1037 * Caller owns returned list and contained buffers. gst_buffer_unref() each
1038 * buffer in the list before freeing the list after usage.
1040 * Returns: (element-type Gst.Buffer) (transfer full) (nullable): a #GList of
1041 * buffers containing the first @nbytes of the adapter, or %NULL if @nbytes
1042 * bytes are not available
1045 gst_adapter_take_list (GstAdapter * adapter, gsize nbytes)
1047 GQueue queue = G_QUEUE_INIT;
1049 gsize hsize, skip, cur_size;
1051 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1052 g_return_val_if_fail (nbytes <= adapter->size, NULL);
1054 GST_LOG_OBJECT (adapter, "taking %" G_GSIZE_FORMAT " bytes", nbytes);
1056 while (nbytes > 0) {
1057 cur = adapter->buflist->data;
1058 skip = adapter->skip;
1059 cur_size = gst_buffer_get_size (cur);
1060 hsize = MIN (nbytes, cur_size - skip);
1062 cur = gst_adapter_take_buffer (adapter, hsize);
1064 g_queue_push_tail (&queue, cur);
1072 * gst_adapter_get_list:
1073 * @adapter: a #GstAdapter
1074 * @nbytes: the number of bytes to get
1076 * Returns a #GList of buffers containing the first @nbytes bytes of the
1077 * @adapter, but does not flush them from the adapter. See
1078 * gst_adapter_take_list() for details.
1080 * Caller owns returned list and contained buffers. gst_buffer_unref() each
1081 * buffer in the list before freeing the list after usage.
1083 * Returns: (element-type Gst.Buffer) (transfer full) (nullable): a #GList of
1084 * buffers containing the first @nbytes of the adapter, or %NULL if @nbytes
1085 * bytes are not available
1090 gst_adapter_get_list (GstAdapter * adapter, gsize nbytes)
1092 GQueue queue = G_QUEUE_INIT;
1093 GstBuffer *cur, *buffer;
1094 gsize hsize, skip, cur_size;
1097 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1098 g_return_val_if_fail (nbytes <= adapter->size, NULL);
1100 GST_LOG_OBJECT (adapter, "getting %" G_GSIZE_FORMAT " bytes", nbytes);
1102 g = adapter->buflist;
1103 skip = adapter->skip;
1105 while (nbytes > 0) {
1107 cur_size = gst_buffer_get_size (cur);
1108 hsize = MIN (nbytes, cur_size - skip);
1110 if (skip == 0 && cur_size == hsize) {
1111 GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
1112 " as head buffer", hsize);
1113 buffer = gst_buffer_ref (cur);
1115 GST_LOG_OBJECT (adapter, "appending %" G_GSIZE_FORMAT " bytes"
1116 " via region copy", hsize);
1117 buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, hsize);
1120 g_queue_push_tail (&queue, buffer);
1124 g = g_slist_next (g);
1131 * gst_adapter_take_buffer_list:
1132 * @adapter: a #GstAdapter
1133 * @nbytes: the number of bytes to take
1135 * Returns a #GstBufferList of buffers containing the first @nbytes bytes of
1136 * the @adapter. The returned bytes will be flushed from the adapter.
1137 * When the caller can deal with individual buffers, this function is more
1138 * performant because no memory should be copied.
1140 * Caller owns the returned list. Call gst_buffer_list_unref() to free
1141 * the list after usage.
1143 * Returns: (transfer full) (nullable): a #GstBufferList of buffers containing
1144 * the first @nbytes of the adapter, or %NULL if @nbytes bytes are not
1150 gst_adapter_take_buffer_list (GstAdapter * adapter, gsize nbytes)
1152 GstBufferList *buffer_list;
1154 gsize hsize, skip, cur_size;
1157 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1159 if (nbytes > adapter->size)
1162 GST_LOG_OBJECT (adapter, "taking %" G_GSIZE_FORMAT " bytes", nbytes);
1164 /* try to create buffer list with sufficient size, so no resize is done later */
1165 if (adapter->count < 64)
1166 n_bufs = adapter->count;
1168 n_bufs = (adapter->count * nbytes * 1.2 / adapter->size) + 1;
1170 buffer_list = gst_buffer_list_new_sized (n_bufs);
1172 while (nbytes > 0) {
1173 cur = adapter->buflist->data;
1174 skip = adapter->skip;
1175 cur_size = gst_buffer_get_size (cur);
1176 hsize = MIN (nbytes, cur_size - skip);
1178 gst_buffer_list_add (buffer_list, gst_adapter_take_buffer (adapter, hsize));
1185 * gst_adapter_get_buffer_list:
1186 * @adapter: a #GstAdapter
1187 * @nbytes: the number of bytes to get
1189 * Returns a #GstBufferList of buffers containing the first @nbytes bytes of
1190 * the @adapter but does not flush them from the adapter. See
1191 * gst_adapter_take_buffer_list() for details.
1193 * Caller owns the returned list. Call gst_buffer_list_unref() to free
1194 * the list after usage.
1196 * Returns: (transfer full) (nullable): a #GstBufferList of buffers containing
1197 * the first @nbytes of the adapter, or %NULL if @nbytes bytes are not
1203 gst_adapter_get_buffer_list (GstAdapter * adapter, gsize nbytes)
1205 GstBufferList *buffer_list;
1206 GstBuffer *cur, *buffer;
1207 gsize hsize, skip, cur_size;
1211 g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
1213 if (nbytes > adapter->size)
1216 GST_LOG_OBJECT (adapter, "getting %" G_GSIZE_FORMAT " bytes", nbytes);
1218 /* try to create buffer list with sufficient size, so no resize is done later */
1219 if (adapter->count < 64)
1220 n_bufs = adapter->count;
1222 n_bufs = (adapter->count * nbytes * 1.2 / adapter->size) + 1;
1224 buffer_list = gst_buffer_list_new_sized (n_bufs);
1226 g = adapter->buflist;
1227 skip = adapter->skip;
1229 while (nbytes > 0) {
1231 cur_size = gst_buffer_get_size (cur);
1232 hsize = MIN (nbytes, cur_size - skip);
1234 if (skip == 0 && cur_size == hsize) {
1235 GST_LOG_OBJECT (adapter, "providing buffer of %" G_GSIZE_FORMAT " bytes"
1236 " as head buffer", hsize);
1237 buffer = gst_buffer_ref (cur);
1239 GST_LOG_OBJECT (adapter, "appending %" G_GSIZE_FORMAT " bytes"
1240 " via region copy", hsize);
1241 buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, hsize);
1244 gst_buffer_list_add (buffer_list, buffer);
1248 g = g_slist_next (g);
1255 * gst_adapter_available:
1256 * @adapter: a #GstAdapter
1258 * Gets the maximum amount of bytes available, that is it returns the maximum
1259 * value that can be supplied to gst_adapter_map() without that function
1262 * Returns: number of bytes available in @adapter
1265 gst_adapter_available (GstAdapter * adapter)
1267 g_return_val_if_fail (GST_IS_ADAPTER (adapter), 0);
1269 return adapter->size;
1273 * gst_adapter_available_fast:
1274 * @adapter: a #GstAdapter
1276 * Gets the maximum number of bytes that are immediately available without
1277 * requiring any expensive operations (like copying the data into a
1278 * temporary buffer).
1280 * Returns: number of bytes that are available in @adapter without expensive
1284 gst_adapter_available_fast (GstAdapter * adapter)
1290 g_return_val_if_fail (GST_IS_ADAPTER (adapter), 0);
1293 if (adapter->size == 0)
1296 /* some stuff we already assembled */
1297 if (adapter->assembled_len)
1298 return adapter->assembled_len;
1300 /* take the first non-zero buffer */
1301 g = adapter->buflist;
1304 size = gst_buffer_get_size (cur);
1307 g = g_slist_next (g);
1310 /* we can quickly get the (remaining) data of the first buffer */
1311 return size - adapter->skip;
1315 * gst_adapter_prev_pts:
1316 * @adapter: a #GstAdapter
1317 * @distance: (out) (allow-none): pointer to location for distance, or %NULL
1319 * Get the pts that was before the current byte in the adapter. When
1320 * @distance is given, the amount of bytes between the pts and the current
1321 * position is returned.
1323 * The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
1324 * the adapter is first created or when it is cleared. This also means that before
1325 * the first byte with a pts is removed from the adapter, the pts
1326 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
1328 * Returns: The previously seen pts.
1331 gst_adapter_prev_pts (GstAdapter * adapter, guint64 * distance)
1333 g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE);
1336 *distance = adapter->pts_distance;
1338 return adapter->pts;
1342 * gst_adapter_prev_dts:
1343 * @adapter: a #GstAdapter
1344 * @distance: (out) (allow-none): pointer to location for distance, or %NULL
1346 * Get the dts that was before the current byte in the adapter. When
1347 * @distance is given, the amount of bytes between the dts and the current
1348 * position is returned.
1350 * The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
1351 * the adapter is first created or when it is cleared. This also means that before
1352 * the first byte with a dts is removed from the adapter, the dts
1353 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
1355 * Returns: The previously seen dts.
1358 gst_adapter_prev_dts (GstAdapter * adapter, guint64 * distance)
1360 g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE);
1363 *distance = adapter->dts_distance;
1365 return adapter->dts;
1369 * gst_adapter_prev_pts_at_offset:
1370 * @adapter: a #GstAdapter
1371 * @offset: the offset in the adapter at which to get timestamp
1372 * @distance: (out) (allow-none): pointer to location for distance, or %NULL
1374 * Get the pts that was before the byte at offset @offset in the adapter. When
1375 * @distance is given, the amount of bytes between the pts and the current
1376 * position is returned.
1378 * The pts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
1379 * the adapter is first created or when it is cleared. This also means that before
1380 * the first byte with a pts is removed from the adapter, the pts
1381 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
1384 * Returns: The previously seen pts at given offset.
1387 gst_adapter_prev_pts_at_offset (GstAdapter * adapter, gsize offset,
1392 gsize read_offset = 0;
1393 GstClockTime pts = adapter->pts;
1395 g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE);
1397 g = adapter->buflist;
1399 while (g && read_offset < offset + adapter->skip) {
1402 read_offset += gst_buffer_get_size (cur);
1403 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (cur))) {
1404 pts = GST_BUFFER_PTS (cur);
1407 g = g_slist_next (g);
1411 *distance = adapter->dts_distance + offset;
1417 * gst_adapter_prev_dts_at_offset:
1418 * @adapter: a #GstAdapter
1419 * @offset: the offset in the adapter at which to get timestamp
1420 * @distance: (out) (allow-none): pointer to location for distance, or %NULL
1422 * Get the dts that was before the byte at offset @offset in the adapter. When
1423 * @distance is given, the amount of bytes between the dts and the current
1424 * position is returned.
1426 * The dts is reset to GST_CLOCK_TIME_NONE and the distance is set to 0 when
1427 * the adapter is first created or when it is cleared. This also means that before
1428 * the first byte with a dts is removed from the adapter, the dts
1429 * and distance returned are GST_CLOCK_TIME_NONE and 0 respectively.
1432 * Returns: The previously seen dts at given offset.
1435 gst_adapter_prev_dts_at_offset (GstAdapter * adapter, gsize offset,
1440 gsize read_offset = 0;
1441 GstClockTime dts = adapter->dts;
1443 g_return_val_if_fail (GST_IS_ADAPTER (adapter), GST_CLOCK_TIME_NONE);
1445 g = adapter->buflist;
1447 while (g && read_offset < offset + adapter->skip) {
1450 read_offset += gst_buffer_get_size (cur);
1451 if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (cur))) {
1452 dts = GST_BUFFER_DTS (cur);
1455 g = g_slist_next (g);
1459 *distance = adapter->dts_distance + offset;
1465 * gst_adapter_masked_scan_uint32_peek:
1466 * @adapter: a #GstAdapter
1467 * @mask: mask to apply to data before matching against @pattern
1468 * @pattern: pattern to match (after mask is applied)
1469 * @offset: offset into the adapter data from which to start scanning, returns
1470 * the last scanned position.
1471 * @size: number of bytes to scan from offset
1472 * @value: (out) (allow-none): pointer to uint32 to return matching data
1474 * Scan for pattern @pattern with applied mask @mask in the adapter data,
1475 * starting from offset @offset. If a match is found, the value that matched
1476 * is returned through @value, otherwise @value is left untouched.
1478 * The bytes in @pattern and @mask are interpreted left-to-right, regardless
1479 * of endianness. All four bytes of the pattern must be present in the
1480 * adapter for it to match, even if the first or last bytes are masked out.
1482 * It is an error to call this function without making sure that there is
1483 * enough data (offset+size bytes) in the adapter.
1485 * Returns: offset of the first match, or -1 if no match was found.
1488 gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask,
1489 guint32 pattern, gsize offset, gsize size, guint32 * value)
1492 gsize skip, bsize, i;
1498 g_return_val_if_fail (size > 0, -1);
1499 g_return_val_if_fail (offset + size <= adapter->size, -1);
1500 g_return_val_if_fail (((~mask) & pattern) == 0, -1);
1502 /* we can't find the pattern with less than 4 bytes */
1503 if (G_UNLIKELY (size < 4))
1506 skip = offset + adapter->skip;
1508 /* first step, do skipping and position on the first buffer */
1509 /* optimistically assume scanning continues sequentially */
1510 if (adapter->scan_entry && (adapter->scan_offset <= skip)) {
1511 g = adapter->scan_entry;
1512 skip -= adapter->scan_offset;
1514 g = adapter->buflist;
1515 adapter->scan_offset = 0;
1516 adapter->scan_entry = NULL;
1519 bsize = gst_buffer_get_size (buf);
1520 while (G_UNLIKELY (skip >= bsize)) {
1522 g = g_slist_next (g);
1523 adapter->scan_offset += bsize;
1524 adapter->scan_entry = g;
1526 bsize = gst_buffer_get_size (buf);
1528 /* get the data now */
1529 if (!gst_buffer_map (buf, &info, GST_MAP_READ))
1532 bdata = (guint8 *) info.data + skip;
1533 bsize = info.size - skip;
1536 /* set the state to something that does not match */
1541 bsize = MIN (bsize, size);
1542 for (i = 0; i < bsize; i++) {
1543 state = ((state << 8) | bdata[i]);
1544 if (G_UNLIKELY ((state & mask) == pattern)) {
1545 /* we have a match but we need to have skipped at
1546 * least 4 bytes to fill the state. */
1547 if (G_LIKELY (skip + i >= 3)) {
1548 if (G_LIKELY (value))
1550 gst_buffer_unmap (buf, &info);
1551 return offset + skip + i - 3;
1559 /* nothing found yet, go to next buffer */
1561 g = g_slist_next (g);
1562 adapter->scan_offset += info.size;
1563 adapter->scan_entry = g;
1564 gst_buffer_unmap (buf, &info);
1567 if (!gst_buffer_map (buf, &info, GST_MAP_READ))
1574 gst_buffer_unmap (buf, &info);
1581 * gst_adapter_masked_scan_uint32:
1582 * @adapter: a #GstAdapter
1583 * @mask: mask to apply to data before matching against @pattern
1584 * @pattern: pattern to match (after mask is applied)
1585 * @offset: offset into the adapter data from which to start scanning, returns
1586 * the last scanned position.
1587 * @size: number of bytes to scan from offset
1589 * Scan for pattern @pattern with applied mask @mask in the adapter data,
1590 * starting from offset @offset.
1592 * The bytes in @pattern and @mask are interpreted left-to-right, regardless
1593 * of endianness. All four bytes of the pattern must be present in the
1594 * adapter for it to match, even if the first or last bytes are masked out.
1596 * It is an error to call this function without making sure that there is
1597 * enough data (offset+size bytes) in the adapter.
1599 * This function calls gst_adapter_masked_scan_uint32_peek() passing %NULL
1602 * Returns: offset of the first match, or -1 if no match was found.
1606 * // Assume the adapter contains 0x00 0x01 0x02 ... 0xfe 0xff
1608 * gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 0, 256);
1610 * gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x00010203, 1, 255);
1612 * gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x01020304, 1, 255);
1614 * gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0001, 0, 256);
1616 * gst_adapter_masked_scan_uint32 (adapter, 0xffff, 0x0203, 0, 256);
1618 * gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 256);
1620 * gst_adapter_masked_scan_uint32 (adapter, 0xffff0000, 0x02030000, 0, 4);
1625 gst_adapter_masked_scan_uint32 (GstAdapter * adapter, guint32 mask,
1626 guint32 pattern, gsize offset, gsize size)
1628 return gst_adapter_masked_scan_uint32_peek (adapter, mask, pattern, offset,