Question about GstAdapter

Sebastian Dröge sebastian at
Wed Dec 14 15:41:40 UTC 2022

On Wed, 2022-12-14 at 12:32 -0300, Rodrigo Santos via gstreamer-devel
> I'm a bit confused about GstAdpater
> (
> ) documentation and how it works.
> By reading the docs, my understanding is that it works "similarly" to
> a queue, where I can push buffers to it (docs say nothing about
> buffers offset/size restriction) and take buffers from the first
> position at arbitrary size (of course, assuming there's enough data
> in the adapter). 

That's correct

> The documentation also says the adapter keeps track of buffers'
> offset. So when I call gst_adapter_prev_offset(), I'll get back the
> offset "that was before the current byte in the adapter". I'm
> assuming "current byte" is the byte at first position (head) of the
> adapter, is that right? I've done some tests under this assumption
> and it seems to be true.

That's also correct. Note that "offset" here refers to the buffer
metadata: buffer.offset() in Rust / GST_BUFFER_OFFSET(buffer) in C. If
this is set and what it means depends on the element producing the
If you don't know what the upstream elements specifically do with the
offset, you can't really use its value for anything. Generally the
offset metadata is not very useful in GStreamer.

> The thing I'm not quite sure is how the
> gst_adapter_copy_bytes(GstAdapter * adapter,  gsize offset, gsize
> size) works. According to the documentation: "size bytes of data
> starting at offset will be copied out of the buffers contained in
> adapter and into a new GBytes structure which is returned". What
> offset is that, is it related to buffers offset or is it the offset
> related to the first position of data in the adapter?

This offset is the byte offset relative to the current head byte of the
adapter, not the buffer offset.

> The first line asserts if (offset + size <= data available in the
> adapter). It looks like it's assuming the first position in the
> adapter has offset 0, which is not necessarily true if the
> offset refers to buffers offset. It only makes sense if the offset is
> related to the first position of data in the adapter.


> [...]
> Which value should "offset" have to copy the last 10 bytes of the
> adapter? If that's related to adapter first position, then it should
> be 502. On the other hand, if it's related to buffer offset, then it
> should be 1526.

You would use offset=502 and size=10 in your example.

Sebastian Dröge, Centricular Ltd ·
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gstreamer-devel mailing list