Question about GstAdapter

Rodrigo Santos rsantos at
Wed Dec 14 15:32:18 UTC 2022

Hey folks,

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). 

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.

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?

I thought it was related to buffers offset. But taking a look at Rust bindings:

   #[doc(alias = "gst_adapter_copy_bytes")]

    pub fn copy_bytes(&self, offset: usize, size: usize) -> Result<glib::Bytes, glib::BoolError> {

        assert!(offset.checked_add(size).map(|end| end <= self.available()) == Some(true));

        if size == 0 {

            return Ok(glib::Bytes::from_static(&[]));


        unsafe {








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.

For instance, consider the following sequence of operations.

gst_adapter_push (adapter, buffer1); // buffer1: offset 0, size 512

gst_adapter_push (adapter, buffer2); // buffer2: offset 512, size 512

gst_adapter_push (adapter, buffer3); // buffer3: offset 1024, size 512

gst_adapter_available (adapter); // It should return 1536

gst_adapter_take_buffer (adapter, 1024); // It flushes the first 1024 bytes from the adapter

gst_adapter_available (adapter); // It should return 512

// now I want to copy the last 10 bytes of the adapter

gst_adapter_copy_bytes (adapter, offset, 10);

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.

Rodrigo Santos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gstreamer-devel mailing list