<div dir="ltr"><div dir="ltr">Hello Michael, (sorry for the re-send as I forgot to include the mail-list)<div><br></div><div>Thank you for picking up on that !  In my mind I was taking the input buffer and turning it into an output buffer, but that obviously is the wrong way to do it. I've changed it to:</div><div><br><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(78,201,176)">GstFlowReturn</span></div><div><span style="color:rgb(200,200,200)">gst_mtdata_meta_inject_prepare_output_buffer</span>(<span style="color:rgb(78,201,176)">GstBaseTransform</span> <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">trans</span>, <span style="color:rgb(78,201,176)">GstBuffer</span> <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">input</span>, <span style="color:rgb(78,201,176)">GstBuffer</span> <span style="color:rgb(180,180,180)">**</span><span style="color:rgb(127,127,127)">outbuf</span>)</div><div>{</div><div>  <span style="color:rgb(78,201,176)">GstMtdataMetaInject</span> <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(200,200,200)">self</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">GST_MTDMETAINJECT</span>(<span style="color:rgb(127,127,127)">trans</span>);</div><div>  <span style="color:rgb(78,201,176)">GstFlowReturn</span> <span style="color:rgb(200,200,200)">ret</span>;<br></div><div style="line-height:18px"><div>  <span style="color:rgb(200,200,200)">ret</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">GST_BASE_TRANSFORM_CLASS</span>(<span style="color:rgb(200,200,200)">gst_mtdata_meta_inject_parent_class</span>)-><span style="color:rgb(218,218,218)">prepare_output_buffer</span>(<span style="color:rgb(127,127,127)">trans</span>, <span style="color:rgb(127,127,127)">input</span>, <span style="color:rgb(127,127,127)">outbuf</span>);<br></div><div>  <span style="color:rgb(86,156,214)">if</span> (<span style="color:rgb(200,200,200)">ret</span> <span style="color:rgb(180,180,180)">!=</span> <span style="color:rgb(184,215,163)">GST_FLOW_OK</span>)</div><div>    <span style="color:rgb(86,156,214)">return</span> <span style="color:rgb(200,200,200)">ret</span>;</div><br><div>  <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">gst_buffer_make_writable</span>(<span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span>);</div><div><span style="color:rgb(87,166,74)">  //  Then you can add the meta to the output buffer.</span></div><br><div><span style="color:rgb(87,166,74)">  // add extra meta data</span></div><div>  <span style="color:rgb(86,156,214)">if</span> (<span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span> <span style="color:rgb(180,180,180)">!=</span> <span style="color:rgb(189,99,197)">NULL</span>)</div><div></div></div><div>  <span style="color:rgb(86,156,214)">if</span> (<span style="color:rgb(200,200,200)">ret</span> <span style="color:rgb(180,180,180)">!=</span> <span style="color:rgb(184,215,163)">GST_FLOW_OK</span>)<br></div><div>    <span style="color:rgb(86,156,214)">return</span> <span style="color:rgb(200,200,200)">ret</span>;</div><br><div>  <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">gst_buffer_make_writable</span>(<span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span>);</div><div>  <span style="color:rgb(86,156,214)">if</span> (<span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span> <span style="color:rgb(180,180,180)">!=</span> <span style="color:rgb(189,99,197)">NULL</span>)
.....</div><div></div></div></div></div><div><br></div><div>or should I completely skip the </div><div><div style="color:rgb(212,212,212);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre-wrap;background-color:rgb(30,30,30)">  <span style="color:rgb(200,200,200)">ret</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">GST_BASE_TRANSFORM_CLASS</span>(<span style="color:rgb(200,200,200)">gst_mtdata_meta_inject_parent_class</span>)-><span style="color:rgb(218,218,218)">prepare_output_buffer</span>(<span style="color:rgb(127,127,127)">trans</span>, <span style="color:rgb(127,127,127)">input</span>, <span style="color:rgb(127,127,127)">outbuf</span>);</div>part ?</div><div><br></div><div>Kind regards,</div><div>Tom</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 8 Mar 2022 at 04:04, Michael Gruner <<a href="mailto:michael.gruner@ridgerun.com">michael.gruner@ridgerun.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">Hey Tom<div><br></div><div>Is this line ok?</div><div><br></div><div>  *outbuf = gst_buffer_make_writable(input);</div><div><br></div><div>Shouldn’t it be:</div><div><br></div><div>  *outbuf = gst_buffer_make_writable(*outbuf);</div><div><br></div><div>The way it is right now you are leaking the outbuf creating when calling:</div><div><br></div><div> ret = GST_BASE_TRANSFORM_CLASS(gst_mtdata_meta_inject_parent_class)->prepare_output_buffer(trans, input, outbuf);<br><div><br></div><div>Michael </div><div><br><blockquote type="cite"><div>On 6 Mar 2022, at 21:11, tom via gstreamer-devel <<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a>> wrote:</div><br><div><div dir="ltr"><div>Hello,</div><div><br></div><div>I'm trying to write a simple plugin that only inserts data as meta data to the stream.</div><div>My plugin is derived from GstBaseTransform</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(86,156,214)">typedef</span> <span style="color:rgb(86,156,214)">struct</span> <span style="color:rgb(78,201,176)">GstMtdataMetaInject</span></div><div>{</div><div>  GstBaseTransform base_mtdataplugins;</div></div></div><div><br></div><div>and i've created a simple meta data like: (see attached files)</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(86,156,214)">struct</span> <span style="color:rgb(78,201,176)">_MtdataMeta</span></div><div>{</div><div>    GstMeta meta;</div><div>    gchar <span style="color:rgb(180,180,180)">*</span>jsonstring;</div><div>};</div><br></div></div><div><br></div><div>and to insert the meta data (on every frame for now)</div><div><br></div><div><div><div id="gmail-m_-1789423256863544210gmail-:13s"><div id="gmail-m_-1789423256863544210gmail-:13o" aria-label="Message Body" role="textbox" aria-multiline="true" style="direction:ltr;min-height:700px"><div dir="ltr"><div dir="ltr"><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(86,156,214)"><br></span></div><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(78,201,176)">GstFlowReturn</span></div><div><span style="color:rgb(200,200,200)">gst_mtdata_meta_inject_prepare_output_buffer</span>(<span style="color:rgb(78,201,176)">GstBaseTransform</span> <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">trans</span>, <span style="color:rgb(78,201,176)">GstBuffer</span> <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">input</span>, <span style="color:rgb(78,201,176)">GstBuffer</span> <span style="color:rgb(180,180,180)">**</span><span style="color:rgb(127,127,127)">outbuf</span>)</div><div>{</div><div>  <span style="color:rgb(78,201,176)">GstMtdataMetaInject</span> <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(200,200,200)">self</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">GST_MTDMETAINJECT</span>(<span style="color:rgb(127,127,127)">trans</span>);</div><div>  <span style="color:rgb(78,201,176)">GstFlowReturn</span> <span style="color:rgb(200,200,200)">ret</span>;<br></div><div>  <span style="color:rgb(200,200,200)">ret</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">GST_BASE_TRANSFORM_CLASS</span>(<span style="color:rgb(200,200,200)">gst_mtdata_meta_inject_parent_class</span>)-><span style="color:rgb(218,218,218)">prepare_output_buffer</span>(<span style="color:rgb(127,127,127)">trans</span>, <span style="color:rgb(127,127,127)">input</span>, <span style="color:rgb(127,127,127)">outbuf</span>);</div><div>  <span style="color:rgb(86,156,214)">if</span> (<span style="color:rgb(200,200,200)">ret</span> <span style="color:rgb(180,180,180)">!=</span> <span style="color:rgb(184,215,163)">GST_FLOW_OK</span>)</div><div>    <span style="color:rgb(86,156,214)">return</span> <span style="color:rgb(200,200,200)">ret</span>;</div><div>  <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(189,99,197)">gst_buffer_make_writable</span>(<span style="color:rgb(127,127,127)">input</span>);<br></div><div>  <span style="color:rgb(86,156,214)">if</span> (<span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span> <span style="color:rgb(180,180,180)">!=</span> <span style="color:rgb(189,99,197)">NULL</span>)<br></div><div>  {</div><div><span style="color:rgb(87,166,74)">    // string hello = StringUtils::current_date_time_string();</span></div><div><span style="color:rgb(87,166,74)">    // string hello = "12345678901234";</span></div><div>    <span style="color:rgb(78,201,176)">string</span> <span style="color:rgb(200,200,200)">hello</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(78,201,176)">StringUtils</span>::<span style="color:rgb(200,200,200)">random_string</span>(<span style="color:rgb(181,206,168)">14</span>);</div><br><div>    <span style="color:rgb(78,201,176)">MtdataMeta</span> <span style="color:rgb(180,180,180)">*</span><span style="color:rgb(200,200,200)">in</span> <span style="color:rgb(180,180,180)">=</span> <span style="color:rgb(200,200,200)">gst_buffer_add_mtdata_meta</span>(<span style="color:rgb(180,180,180)">*</span><span style="color:rgb(127,127,127)">outbuf</span>, (<span style="color:rgb(78,201,176)">gchar</span> <span style="color:rgb(180,180,180)">*</span>)<span style="color:rgb(200,200,200)">hello</span>.<span style="color:rgb(200,200,200)">c_str</span>());</div><br><div>    <span style="color:rgb(189,99,197)">GST_WARNING</span>(<span style="color:rgb(214,157,133)">"Added metdata: %s"</span>, <span style="color:rgb(200,200,200)">in</span>-><span style="color:rgb(218,218,218)">jsonstring</span>);</div><div>  }</div><div>  <span style="color:rgb(86,156,214)">return</span> <span style="color:rgb(200,200,200)">ret</span>;</div><div>}</div></div></div></div></div></div></div></div><div>however i'm getting a quite fast memory leak that i can see in gst-launch-1.0 where it goes from 30% memory up to 60% in a matter of a minute.<br>the funny think is that if i change the meta data string to be something constant like "12345678901234" with the same length, there is no memory leak and it stays on 28% forever.</div><div><br>Do I need to go to the last element in the stream and 'free' the meta data so it doesn't add up ?</div><div>Kind regards,</div><div>Tom</div><div><br></div></div>
<span id="gmail-m_-1789423256863544210cid:f_l0g4ce1u0"><mtdata_meta.h></span><span id="gmail-m_-1789423256863544210cid:f_l0g4ce291"><mtdata_meta.cpp></span><span id="gmail-m_-1789423256863544210cid:f_l0g4hp2m2"><gstmtdmetainject.h></span><span id="gmail-m_-1789423256863544210cid:f_l0g4hp2v3"><gstmtdmetainject.cpp></span></div></blockquote></div><br></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif">☕</span><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;background-color:rgb(241,241,241)">𝓉</span><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif">𝓈</span><br></div></div>