<!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>Thanks for the quick response Sebastian. I'll adapt my code accordingly. I was considering the <b>offset </b>in gst_adapter_copy_bytes() to be related to buffer offset instead of "adapter" offset.<br></div><div><br></div><div id="Zm-_Id_-Sgn" data-zbluepencil-ignore="true" data-sigid="8819909000000014001"><div>Rodrigo Santos<br></div></div><div><br></div><div class="zmail_extra_hr" style="border-top: 1px solid rgb(204, 204, 204); height: 0px; margin-top: 10px; margin-bottom: 10px; line-height: 0px;"><br></div><div class="zmail_extra" data-zbluepencil-ignore="true"><div><br></div><div id="Zm-_Id_-Sgn1">---- On Wed, 14 Dec 2022 12:41:40 -0300 <b>Sebastian Dröge via gstreamer-devel <gstreamer-devel@lists.freedesktop.org></b> wrote ---<br></div><div><br></div><blockquote id="blockquote_zmail" style="margin: 0px;"><div><div>On Wed, 2022-12-14 at 12:32 -0300, Rodrigo Santos via gstreamer-devel wrote:<br></div><blockquote style="margin :  0 0 0; border-left :  2px #729fcf solid; padding-left :  1ex;"><div style="font-family :  Verdana,  Arial,  Helvetica,  sans-serif; font-size :  10pt;"><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></blockquote><div><br></div><div>That's correct<br></div><div><br></div><blockquote style="margin :  0 0 0; border-left :  2px #729fcf solid; padding-left :  1ex;"><div style="font-family :  Verdana,  Arial,  Helvetica,  sans-serif; font-size :  10pt;"><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></blockquote><div><br></div><div>That's also correct. Note that "offset" here refers to the buffer metadata:<span class="font" style="font-family:Courier New, Courier, monospace"> buffer.offset()</span> in Rust / <span class="font" style="font-family:Courier New, Courier, monospace">GST_BUFFER_OFFSET(buffer)</span> in C. If this is set and what it means depends on the element producing the buffer.<br></div><div>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.<br></div><div><br></div><blockquote style="margin :  0 0 0; border-left :  2px #729fcf solid; padding-left :  1ex;"><div style="font-family :  Verdana,  Arial,  Helvetica,  sans-serif; font-size :  10pt;"><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></blockquote><div><br></div><div>This offset is the byte offset relative to the current head byte of the adapter, not the buffer offset.<br></div><div><br></div><blockquote style="margin :  0 0 0; border-left :  2px #729fcf solid; padding-left :  1ex;"><div style="font-family :  Verdana,  Arial,  Helvetica,  sans-serif; font-size :  10pt;"><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></blockquote><div><br></div><div>Correct<br></div><div><br></div><blockquote style="margin :  0 0 0; border-left :  2px #729fcf solid; padding-left :  1ex;"><div style="font-family :  Verdana,  Arial,  Helvetica,  sans-serif; font-size :  10pt;"><div>[...]<br></div></div></blockquote><blockquote style="margin :  0 0 0; border-left :  2px #729fcf solid; padding-left :  1ex;"><div style="font-family :  Verdana,  Arial,  Helvetica,  sans-serif; font-size :  10pt;"><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></blockquote><div><br></div><div>You would use offset=502 and size=10 in your example.<br></div><div><br></div><div><span><pre>-- <br></pre><div><div><span class="font" style="font-family:Calibri, sans-serif"><span class="size" style="font-size:14.6667px">Sebastian Dröge, Centricular Ltd · </span></span><a href="https://www.centricular.com/" title="Click to open https://www.centricular.com/" style="color :  rgb(0, 0, 238); font-family :  Calibri,  sans-serif; font-size :  14.666667px;" target="_blank">https://www.centricular.com</a><br></div></div></span></div></div></blockquote></div><div><br></div></div><br></body></html>