<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;"><div>Hey folks,<br></div><div><br></div><div>I'm a bit confused about GstAdpater (<a target="_blank" href="https://gstreamer.freedesktop.org/documentation/base/gstadapter.html">https://gstreamer.freedesktop.org/documentation/base/gstadapter.html</a>) documentation and how it works.<br></div><div><br></div><div>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). <br></div><div><br></div><div>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.<br></div><div><br></div><div>The thing I'm not quite sure is how the <i>gst_adapter_copy_bytes(GstAdapter * adapter, gsize offset, gsize size)</i> works. According to the documentation: "size bytes of data starting at <b>offset</b> 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 <b>buffers </b>offset or is it the offset related to the <b>first position</b> of data in the adapter?<br></div><div><br></div><div>I thought it was related to <b>buffers </b>offset. But taking a look at Rust bindings:<br></div><div><br></div><div> #[doc(alias = "gst_adapter_copy_bytes")]<br></div><div> pub fn copy_bytes(&self, offset: usize, size: usize) -> Result<glib::Bytes, glib::BoolError> {<br></div><div> assert!(offset.checked_add(size).map(|end| end <= self.available()) == Some(true));<br></div><div><br></div><div> if size == 0 {<br></div><div> return Ok(glib::Bytes::from_static(&[]));<br></div><div> }<br></div><div><br></div><div> unsafe {<br></div><div> Ok(from_glib_full(ffi::gst_adapter_copy_bytes(<br></div><div> self.to_glib_none().0,<br></div><div> offset,<br></div><div> size,<br></div><div> )))<br></div><div> }<br></div><div> }<br></div><div><br></div><div>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 <b>offset</b> refers to buffers offset. It only makes sense if the <b>offset</b> is related to the first position of data in the adapter.<br></div><div><br></div><div>For instance, consider the following sequence of operations.<br></div><div><br></div><div>gst_adapter_push (adapter, buffer1); // buffer1: offset 0, size 512<br></div><div>gst_adapter_push (adapter, buffer2); // buffer2: offset 512, size 512<br></div><div>gst_adapter_push (adapter, buffer3); // buffer3: offset 1024, size 512<br></div><div><br></div><div>gst_adapter_available (adapter); // It should return 1536<br></div><div><br></div><div>gst_adapter_take_buffer (adapter, 1024); // It flushes the first 1024 bytes from the adapter<br></div><div><br></div><div>gst_adapter_available (adapter); // It should return 512<br></div><div><br></div><div>// now I want to copy the last 10 bytes of the adapter<br></div><div>gst_adapter_copy_bytes (adapter, offset, 10);<br></div><div><br></div><div>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.<br></div><div><br></div><div><br></div><div class="zmail_signature_below"><div id="" data-zbluepencil-ignore="true" data-sigid="8819909000000014001"><div>Rodrigo Santos<br></div></div></div><div><br></div></div><br></body></html>