<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.E-MailFormatvorlage19
        {mso-style-type:personal-reply;
        font-family:"Arial",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:fuchsia">Hi,<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:fuchsia">00 00 01 67 4D 40 29 96 54 03 C0</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4">  </span><span style="font-size:9.0pt;font-family:Consolas;color:#6A9955">  ><a href="mailto:..|....gM@).T.@">..|....gM@).T.@</a></span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6">00000040:</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> </span><span style="font-size:9.0pt;font-family:Consolas;color:fuchsia">11 3F 2A 00 00 00 01 68 EE 38 80 <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;mso-fareast-language:EN-US">Is an SPS NAL.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;mso-fareast-language:EN-US">Gruesse<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><b>Von:</b> gstreamer-devel <gstreamer-devel-bounces@lists.freedesktop.org>
<b>Im Auftrag von </b>Andreas Corneliussen<br>
<b>Gesendet:</b> Donnerstag, 21. November 2019 10:34<br>
<b>An:</b> gstreamer-devel@lists.freedesktop.org<br>
<b>Betreff:</b> gst_adapter_take_buffer and gst_buffer_copy_into problem<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Hi<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I have an embedded target where I am unable to upgrade the gstreamer installation higher than 12.3 due to a kernel with proprietary drivers not available in recent versions and a resulting problem with updating yocto to a recent version
 as well. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">On this target I need to rtp a h264 stream from a camera interfaced using the v4l2src. I therefore use the following pipeline to determine if the data sent on RTP is correct:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-h264, width=1920, height=1080, framerate=10/1 ! tee name=t t. ! queue ! filesink location=/home/dtc/testfilev4l2.dat t. ! queue ! rtph264pay name=pay0 ! filesink location=/home/dtc/testfilepay.dat<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">When I then look at the binary file testfilepay.dat I see the following:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6"> Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   </span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6">00000000:</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> </span><span style="font-size:9.0pt;font-family:Consolas;color:red">80 60 28 B5 40 5B 2F CD 7A 3E 18 90 67</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> 4D 40 29  </span><span style="font-size:9.0pt;font-family:Consolas;color:#6A9955">  .`(<a href="mailto:5@[/Mz%3e..gM@">5@[/Mz>..gM@</a>)</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6">00000010:</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> 96 54 03 C0 11 3F 2A </span><span style="font-size:9.0pt;font-family:Consolas;color:red">80 60 28 B6 40 5B 2F CD 7A</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4">  </span><span style="font-size:9.0pt;font-family:Consolas;color:#6A9955">  <a href="mailto:.T.@.?*.%60(6@[/Mz">.T.@.?*.`(6@[/Mz</a></span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6">00000020:</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> </span><span style="font-size:9.0pt;font-family:Consolas;color:red">3E 18 90 68</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> EE 38 80 </span><span style="font-size:9.0pt;font-family:Consolas;color:red">80 60 28 B7 40 5B 2F CD 7A</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4">  </span><span style="font-size:9.0pt;font-family:Consolas;color:#6A9955">  >..hn8..`(7@[/Mz</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6">00000030:</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> </span><span style="font-size:9.0pt;font-family:Consolas;color:red">3E 18 90 7C 85</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> </span><span style="font-size:9.0pt;font-family:Consolas;color:fuchsia">00 00 01 67 4D 40 29 96 54 03 C0</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4">  </span><span style="font-size:9.0pt;font-family:Consolas;color:#6A9955">  ><a href="mailto:..|....gM@).T.@">..|....gM@).T.@</a></span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6">00000040:</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> </span><span style="font-size:9.0pt;font-family:Consolas;color:fuchsia">11 3F 2A 00 00 00 01 68 EE 38 80 00 00 00 01 65</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4">  </span><span style="font-size:9.0pt;font-family:Consolas;color:#6A9955">  .?*....hn8.....e</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="line-height:12.0pt;background:#1E1E1E"><span style="font-size:9.0pt;font-family:Consolas;color:#569CD6">00000050:</span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"> 88 80 40 02 FF FE 04 18 70 29 1B 5D 15 CC 05 E9  </span><span style="font-size:9.0pt;font-family:Consolas;color:#6A9955">  <a href="mailto:..@..~..p).].L.i">..@..~..p).].L.i</a></span><span style="font-size:9.0pt;font-family:Consolas;color:#D4D4D4"><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">What I see from the about it that the two first NALs of the h264 stream is parsed correctly and the 00 00 00 01 h264 header is removed and replaced with an RTP header (marked in read above). However, for the third NAL (an 0x65 NAL) it seems
 that it starts copying from the input stream 27 bytes too early resulting in both the two first NALs to be duplicated into the stream where the second time they appear they are prepended with the h264 header 00 00 00 01 or 00 00 01 and the header of the third
 NAL to be copied incorrectly (all this is marked with pink above). In other words all the 27 bytes marked with pink above should be removed.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I have then investigated in the rtph264payload source code how this happens and what I have found is that the payload is doing the following to each input buffer:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">1. The input buffer to the element in pushed into an GstAdapter<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">2. Then the full GstAdapter is searched through in order to determine the start position of all the NALs<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">3. Then for each of the NALs a buffer is taken from from the adapter with gst_adapter_take_buffer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">4. These buffers are then parsed to determine which type of NAL is contained within and how big the buffer is<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">5. If the buffer size is below the mtu size of the system:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    5.1. Make a new GstBuffer with the correct header<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    5.2. Append the buffer taken from the adapter to the new GstBuffer with gst_buffer_append()<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    5.3. Send that new buffer out on the src pad<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">6. If the buffer size is above the mtu size of the system:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    6.1. Make a new GstBuffer with the correct header<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    6.2. Copy the correct part of the buffer taken from the adapter into the new buffer using gst_buffer_copy_into()<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    6.3. Send the new buffer out on the src pad<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">    6.4. Determine if all the buffer taken from the GstAdapter has been copied to output buffers and if not then go back to 6.1<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I have also determined that the problem seems to be that the gst_buffer_copy_into() seems to disregard that the buffer taken from the GstAdapter does not start at the start of the adapter. In other words, when we use gst_buffer_copy_info()
 to copy from the buffer taken from the GstAdapter with an offset of zero it starts at offset 0 relative to the start of the data pushed into the adapter even though 27 bytes have been taken or flushed from the adapter before this.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Does anyone know of a way to make the function gst_buffer_copy_into respect the offset of the input buffer instead of starting at the start of the adapter?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Kind regards<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Andreas Corneliussen<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>