[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gstreamer-devel
Subject:    Re: How to transfer GstBuffer from one pipeline to other pipeline
From:       Andy Devar <andy.devar () gmail ! com>
Date:       2020-11-29 22:06:31
Message-ID: CAGW3BCtrSSYUbNkV=nFKwJNxYf8wg_X4DK3n7p=DjeCawCMUmw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

how to do this correctly? I'm referring to Anton's suggestion to use
gst_sample_copy/gst_buffer_copy_deep.

As soon as I copy the buffer (see example below), I get a memory leak
(megabytes per second, so I think the buffer won't be disposed).

If I don't copy the buffer, I get warnings - probably because the copied
sample references the buffer of the sample received from appsink:
"free_priv_data: object finalizing but still has 1 parents
(object:000001E0052CED80)"

gstreamer version: 1.18.1 x64 msvc


g_signal_connect(videosink, "new-sample",
G_CALLBACK(on_new_sample_from_appsink), data);

on_new_sample_from_appsink(GstElement * elt, ProgramData * data)
{
/* get the sample from appsink */
GstSample *sample_in;
sample_in = gst_app_sink_pull_sample(GST_APP_SINK(elt));

// Copy the sample.
GstSample* sample_out = gst_sample_copy(sample_in);
// Now, the buffer of sample_out is a reference to the buffer of sample_in.

// Copy the buffer of sample_in and set it as buffer of sample_out
GstBuffer *buffer_in = gst_sample_get_buffer(sample_in);
GstBuffer *buffer_out = gst_buffer_copy_deep(buffer_in);
gst_sample_set_buffer(sample_out, buffer_out);
gst_buffer_unref(buffer_out);

// Push sample_out to appsource
GstElement* appsource = gst_bin_get_by_name(GST_BIN(data->targetpipeline),
"appsource");
gst_app_src_push_sample(GST_APP_SRC(appsource), sample_out);

gst_sample_unref(sample_in);
gst_object_unref(appsource);

return GST_FLOW_OK;
}


Thanks,

Andy

Am Mo., 21. Sept. 2020 um 14:23 Uhr schrieb shiva.mudugal <
shiva.mudugal@gmail.com>:

> Hello Anton,
>
> Thanks for your response. In understand you point, but is there a way to do
> this without creating the deep copy  from pipeline1 to pipeline2 ?
>
> My intention is to avoid deep copy from pipeline1 to pipeline2. Can we just
> increase the reference count of the buffer in the appsink callback of
> pipeline1 to then apsrc_push to pipeline2 ?
>
> -Regards,
> Shiva
>
>
>
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>

[Attachment #5 (text/html)]

<div dir="ltr"><div>Hi,</div><div><br></div><div>how to do this correctly? I&#39;m \
referring to Anton&#39;s suggestion to use  \
gst_sample_copy/gst_buffer_copy_deep.</div><div><br></div><div>As soon as I copy the \
buffer (see example below), I get a memory leak (megabytes per second, so I think the \
buffer won&#39;t be disposed).</div><div><br></div><div>If I don&#39;t copy the \
buffer, I get warnings - probably because the copied sample references the buffer of \
the sample received from appsink:<br>&quot;free_priv_data: object finalizing but \
still has 1 parents (object:000001E0052CED80)&quot;</div><div><br></div><div>gstreamer \
version: 1.18.1 x64 msvc<br></div><div><br></div><div><br>g_signal_connect(videosink, \
&quot;new-sample&quot;, G_CALLBACK(on_new_sample_from_appsink), \
data);<br><br>on_new_sample_from_appsink(GstElement * elt, ProgramData * \
data)<br>{<br>	/* get the sample from appsink */<br>	GstSample \
*sample_in;<br>	sample_in = gst_app_sink_pull_sample(GST_APP_SINK(elt));<br><br>	// \
Copy the sample.<br>	GstSample* sample_out = gst_sample_copy(sample_in);		<br>	// \
Now, the buffer of sample_out is a reference to the buffer of sample_in.<br><br>	// \
Copy the buffer of sample_in and set it as buffer of sample_out<br>	GstBuffer \
*buffer_in = gst_sample_get_buffer(sample_in);<br>	GstBuffer *buffer_out = \
gst_buffer_copy_deep(buffer_in);<br>	gst_sample_set_buffer(sample_out, \
buffer_out);<br>	gst_buffer_unref(buffer_out);<br>	<br>	// Push sample_out to \
appsource<br>	GstElement* appsource = \
gst_bin_get_by_name(GST_BIN(data-&gt;targetpipeline), \
&quot;appsource&quot;);<br>	gst_app_src_push_sample(GST_APP_SRC(appsource), \
sample_out);<br>	<br>	gst_sample_unref(sample_in);<br>	gst_object_unref(appsource);	<br>	<br>	return \
GST_FLOW_OK;<br>}</div><div><br></div><div><br></div><div>Thanks,</div><div><br></div><div>Andy<br></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mo., 21. Sept. 2020 um 14:23 \
Uhr schrieb shiva.mudugal &lt;<a \
href="mailto:shiva.mudugal@gmail.com">shiva.mudugal@gmail.com</a>&gt;:<br></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">Hello Anton,<br> <br>
Thanks for your response. In understand you point, but is there a way to do<br>
this without creating the deep copy   from pipeline1 to pipeline2 ?<br>
<br>
My intention is to avoid deep copy from pipeline1 to pipeline2. Can we just<br>
increase the reference count of the buffer in the appsink callback of<br>
pipeline1 to then apsrc_push to pipeline2 ? <br>
<br>
-Regards,<br>
Shiva <br>
<br>
<br>
<br>
--<br>
Sent from: <a href="http://gstreamer-devel.966125.n4.nabble.com/" rel="noreferrer" \
target="_blank">http://gstreamer-devel.966125.n4.nabble.com/</a><br> \
_______________________________________________<br> gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" \
target="_blank">gstreamer-devel@lists.freedesktop.org</a><br> <a \
href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" \
rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
 </blockquote></div>



_______________________________________________
gstreamer-devel mailing list
gstreamer-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic