<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hey Tom<div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="">or should I completely skip the </div><div class=""><div class="" style="color: rgb(212, 212, 212); font-family: Menlo, Monaco, "Courier New", monospace; white-space: pre-wrap; background-color: rgb(30, 30, 30);"> <span class="" style="color: rgb(200, 200, 200);">ret</span> <span class="" style="color: rgb(180, 180, 180);">=</span> <span class="" style="color: rgb(189, 99, 197);">GST_BASE_TRANSFORM_CLASS</span>(<span class="" style="color: rgb(200, 200, 200);">gst_mtdata_meta_inject_parent_class</span>)-><span class="" style="color: rgb(218, 218, 218);">prepare_output_buffer</span>(<span class="" style="color: rgb(127, 127, 127);">trans</span>, <span class="" style="color: rgb(127, 127, 127);">input</span>, <span class="" style="color: rgb(127, 127, 127);">outbuf</span>);</div>part ?</div></div></blockquote><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">No, I believe chaining to the parent’s prepare_output_buffer is the smart thing to do. You actually need to create an output buffer in the prepare_output_buffer method, and you don’t actually want to deal with the buffer allocation yourself if possible, so it’s fine that you are relying on the default implementation. The default implementation does not simply allocate the memory for the buffer, it may also takes into account buffer pools and allocators proposed by downstream elements. </div></div></div><div><br class=""></div><div>Michael</div><div><br class=""></div><div><blockquote type="cite" class=""><div class="">On 8 Mar 2022, at 06:18, tom <<a href="mailto:tomschuring@gmail.com" class="">tomschuring@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">Hello Michael, (sorry for the re-send as I forgot to include the mail-list)<div class=""><br class=""></div><div class="">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 class=""><br class=""><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" class=""><div class=""><span style="color:rgb(86,156,214)" class="">static</span> <span style="color:rgb(78,201,176)" class="">GstFlowReturn</span></div><div class=""><span style="color:rgb(200,200,200)" class="">gst_mtdata_meta_inject_prepare_output_buffer</span>(<span style="color:rgb(78,201,176)" class="">GstBaseTransform</span> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">trans</span>, <span style="color:rgb(78,201,176)" class="">GstBuffer</span> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">input</span>, <span style="color:rgb(78,201,176)" class="">GstBuffer</span> <span style="color:rgb(180,180,180)" class="">**</span><span style="color:rgb(127,127,127)" class="">outbuf</span>)</div><div class="">{</div><div class=""> <span style="color:rgb(78,201,176)" class="">GstMtdataMetaInject</span> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(200,200,200)" class="">self</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">GST_MTDMETAINJECT</span>(<span style="color:rgb(127,127,127)" class="">trans</span>);</div><div class=""> <span style="color:rgb(78,201,176)" class="">GstFlowReturn</span> <span style="color:rgb(200,200,200)" class="">ret</span>;<br class=""></div><div style="line-height:18px" class=""><div class=""> <span style="color:rgb(200,200,200)" class="">ret</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">GST_BASE_TRANSFORM_CLASS</span>(<span style="color:rgb(200,200,200)" class="">gst_mtdata_meta_inject_parent_class</span>)-><span style="color:rgb(218,218,218)" class="">prepare_output_buffer</span>(<span style="color:rgb(127,127,127)" class="">trans</span>, <span style="color:rgb(127,127,127)" class="">input</span>, <span style="color:rgb(127,127,127)" class="">outbuf</span>);<br class=""></div><div class=""> <span style="color:rgb(86,156,214)" class="">if</span> (<span style="color:rgb(200,200,200)" class="">ret</span> <span style="color:rgb(180,180,180)" class="">!=</span> <span style="color:rgb(184,215,163)" class="">GST_FLOW_OK</span>)</div><div class=""> <span style="color:rgb(86,156,214)" class="">return</span> <span style="color:rgb(200,200,200)" class="">ret</span>;</div><br class=""><div class=""> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">gst_buffer_make_writable</span>(<span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span>);</div><div class=""><span style="color:rgb(87,166,74)" class=""> // Then you can add the meta to the output buffer.</span></div><br class=""><div class=""><span style="color:rgb(87,166,74)" class=""> // add extra meta data</span></div><div class=""> <span style="color:rgb(86,156,214)" class="">if</span> (<span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span> <span style="color:rgb(180,180,180)" class="">!=</span> <span style="color:rgb(189,99,197)" class="">NULL</span>)</div><div class=""></div></div><div class=""> <span style="color:rgb(86,156,214)" class="">if</span> (<span style="color:rgb(200,200,200)" class="">ret</span> <span style="color:rgb(180,180,180)" class="">!=</span> <span style="color:rgb(184,215,163)" class="">GST_FLOW_OK</span>)<br class=""></div><div class=""> <span style="color:rgb(86,156,214)" class="">return</span> <span style="color:rgb(200,200,200)" class="">ret</span>;</div><br class=""><div class=""> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">gst_buffer_make_writable</span>(<span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span>);</div><div class=""> <span style="color:rgb(86,156,214)" class="">if</span> (<span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span> <span style="color:rgb(180,180,180)" class="">!=</span> <span style="color:rgb(189,99,197)" class="">NULL</span>)
.....</div><div class=""></div></div></div></div><div class=""><br class=""></div><div class="">or should I completely skip the </div><div class=""><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)" class=""> <span style="color:rgb(200,200,200)" class="">ret</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">GST_BASE_TRANSFORM_CLASS</span>(<span style="color:rgb(200,200,200)" class="">gst_mtdata_meta_inject_parent_class</span>)-><span style="color:rgb(218,218,218)" class="">prepare_output_buffer</span>(<span style="color:rgb(127,127,127)" class="">trans</span>, <span style="color:rgb(127,127,127)" class="">input</span>, <span style="color:rgb(127,127,127)" class="">outbuf</span>);</div>part ?</div><div class=""><br class=""></div><div class="">Kind regards,</div><div class="">Tom</div></div><br class=""><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" class="">michael.gruner@ridgerun.com</a>> wrote:<br class=""></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;" class="">Hey Tom<div class=""><br class=""></div><div class="">Is this line ok?</div><div class=""><br class=""></div><div class=""> *outbuf = gst_buffer_make_writable(input);</div><div class=""><br class=""></div><div class="">Shouldn’t it be:</div><div class=""><br class=""></div><div class=""> *outbuf = gst_buffer_make_writable(*outbuf);</div><div class=""><br class=""></div><div class="">The way it is right now you are leaking the outbuf creating when calling:</div><div class=""><br class=""></div><div class=""> ret = GST_BASE_TRANSFORM_CLASS(gst_mtdata_meta_inject_parent_class)->prepare_output_buffer(trans, input, outbuf);<br class=""><div class=""><br class=""></div><div class="">Michael </div><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 6 Mar 2022, at 21:11, tom via gstreamer-devel <<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank" class="">gstreamer-devel@lists.freedesktop.org</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class="">Hello,</div><div class=""><br class=""></div><div class="">I'm trying to write a simple plugin that only inserts data as meta data to the stream.</div><div class="">My plugin is derived from GstBaseTransform</div><div class=""><br class=""></div><div class=""><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" class=""><div class=""><span style="color:rgb(86,156,214)" class="">typedef</span> <span style="color:rgb(86,156,214)" class="">struct</span> <span style="color:rgb(78,201,176)" class="">GstMtdataMetaInject</span></div><div class="">{</div><div class=""> GstBaseTransform base_mtdataplugins;</div></div></div><div class=""><br class=""></div><div class="">and i've created a simple meta data like: (see attached files)</div><div class=""><br class=""></div><div class=""><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" class=""><div class=""><span style="color:rgb(86,156,214)" class="">struct</span> <span style="color:rgb(78,201,176)" class="">_MtdataMeta</span></div><div class="">{</div><div class=""> GstMeta meta;</div><div class=""> gchar <span style="color:rgb(180,180,180)" class="">*</span>jsonstring;</div><div class="">};</div><br class=""></div></div><div class=""><br class=""></div><div class="">and to insert the meta data (on every frame for now)</div><div class=""><br class=""></div><div class=""><div class=""><div id="gmail-m_-1789423256863544210gmail-:13s" class=""><div id="gmail-m_-1789423256863544210gmail-:13o" aria-label="Message Body" role="textbox" aria-multiline="true" style="direction:ltr;min-height:700px" class=""><div dir="ltr" class=""><div dir="ltr" class=""><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" class=""><div class=""><span style="color:rgb(86,156,214)" class=""><br class=""></span></div><div class=""><span style="color:rgb(86,156,214)" class="">static</span> <span style="color:rgb(78,201,176)" class="">GstFlowReturn</span></div><div class=""><span style="color:rgb(200,200,200)" class="">gst_mtdata_meta_inject_prepare_output_buffer</span>(<span style="color:rgb(78,201,176)" class="">GstBaseTransform</span> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">trans</span>, <span style="color:rgb(78,201,176)" class="">GstBuffer</span> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">input</span>, <span style="color:rgb(78,201,176)" class="">GstBuffer</span> <span style="color:rgb(180,180,180)" class="">**</span><span style="color:rgb(127,127,127)" class="">outbuf</span>)</div><div class="">{</div><div class=""> <span style="color:rgb(78,201,176)" class="">GstMtdataMetaInject</span> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(200,200,200)" class="">self</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">GST_MTDMETAINJECT</span>(<span style="color:rgb(127,127,127)" class="">trans</span>);</div><div class=""> <span style="color:rgb(78,201,176)" class="">GstFlowReturn</span> <span style="color:rgb(200,200,200)" class="">ret</span>;<br class=""></div><div class=""> <span style="color:rgb(200,200,200)" class="">ret</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">GST_BASE_TRANSFORM_CLASS</span>(<span style="color:rgb(200,200,200)" class="">gst_mtdata_meta_inject_parent_class</span>)-><span style="color:rgb(218,218,218)" class="">prepare_output_buffer</span>(<span style="color:rgb(127,127,127)" class="">trans</span>, <span style="color:rgb(127,127,127)" class="">input</span>, <span style="color:rgb(127,127,127)" class="">outbuf</span>);</div><div class=""> <span style="color:rgb(86,156,214)" class="">if</span> (<span style="color:rgb(200,200,200)" class="">ret</span> <span style="color:rgb(180,180,180)" class="">!=</span> <span style="color:rgb(184,215,163)" class="">GST_FLOW_OK</span>)</div><div class=""> <span style="color:rgb(86,156,214)" class="">return</span> <span style="color:rgb(200,200,200)" class="">ret</span>;</div><div class=""> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(189,99,197)" class="">gst_buffer_make_writable</span>(<span style="color:rgb(127,127,127)" class="">input</span>);<br class=""></div><div class=""> <span style="color:rgb(86,156,214)" class="">if</span> (<span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span> <span style="color:rgb(180,180,180)" class="">!=</span> <span style="color:rgb(189,99,197)" class="">NULL</span>)<br class=""></div><div class=""> {</div><div class=""><span style="color:rgb(87,166,74)" class=""> // string hello = StringUtils::current_date_time_string();</span></div><div class=""><span style="color:rgb(87,166,74)" class=""> // string hello = "12345678901234";</span></div><div class=""> <span style="color:rgb(78,201,176)" class="">string</span> <span style="color:rgb(200,200,200)" class="">hello</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(78,201,176)" class="">StringUtils</span>::<span style="color:rgb(200,200,200)" class="">random_string</span>(<span style="color:rgb(181,206,168)" class="">14</span>);</div><br class=""><div class=""> <span style="color:rgb(78,201,176)" class="">MtdataMeta</span> <span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(200,200,200)" class="">in</span> <span style="color:rgb(180,180,180)" class="">=</span> <span style="color:rgb(200,200,200)" class="">gst_buffer_add_mtdata_meta</span>(<span style="color:rgb(180,180,180)" class="">*</span><span style="color:rgb(127,127,127)" class="">outbuf</span>, (<span style="color:rgb(78,201,176)" class="">gchar</span> <span style="color:rgb(180,180,180)" class="">*</span>)<span style="color:rgb(200,200,200)" class="">hello</span>.<span style="color:rgb(200,200,200)" class="">c_str</span>());</div><br class=""><div class=""> <span style="color:rgb(189,99,197)" class="">GST_WARNING</span>(<span style="color:rgb(214,157,133)" class="">"Added metdata: %s"</span>, <span style="color:rgb(200,200,200)" class="">in</span>-><span style="color:rgb(218,218,218)" class="">jsonstring</span>);</div><div class=""> }</div><div class=""> <span style="color:rgb(86,156,214)" class="">return</span> <span style="color:rgb(200,200,200)" class="">ret</span>;</div><div class="">}</div></div></div></div></div></div></div></div><div class="">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 class="">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 class=""><br class="">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 class="">Kind regards,</div><div class="">Tom</div><div class=""><br class=""></div></div>
<span id="gmail-m_-1789423256863544210cid:f_l0g4ce1u0" class=""><mtdata_meta.h></span><span id="gmail-m_-1789423256863544210cid:f_l0g4ce291" class=""><mtdata_meta.cpp></span><span id="gmail-m_-1789423256863544210cid:f_l0g4hp2m2" class=""><gstmtdmetainject.h></span><span id="gmail-m_-1789423256863544210cid:f_l0g4hp2v3" class=""><gstmtdmetainject.cpp></span></div></blockquote></div><br class=""></div></div></blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><span style="font-family: Verdana, sans-serif;" class="">☕</span><span style="font-family: Verdana, sans-serif; background-color: rgb(241, 241, 241);" class="">𝓉</span><span style="font-family: Verdana, sans-serif;" class="">𝓈</span><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>