Re: How to push data in appsrc without freeing memory?

Aleksandr Slobodeniuk via gstreamer-devel <[email protected]> Sat, 30 Nov 2024 02:36:11 +0100
Newsgroups gmane.comp.video.gstreamer.devel
Message-ID <CAHuwaLC1HMj=d8HGx-oCJ-Uhx9f0E70V0f=BHPrtuER7EBBNQQ@mail.gmail.com>
--000000000000c67b6406281757bf
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi, I'm sure that the gst_buffer_new_wrapped_full() function can't free the
wrapped memory.
If you see it have been freed maybe it's freed by another thread, probably
another code in another thread unmaps it.
Since you don't want your data to be freed while it's used, but also are
passing NULL to the gst_buffer_new_wrapped_full(),
we can make a conclusion, that the management is not complete - in other
words there's no logic that would free the data.
And if it's still freed, then there's another code that does that and does
that at the wrong moment.

IMHO the mapping should be attached to the buffer through the "user_data"
parameter of the gst_buffer_new_wrapped_full(),
and the "notify" callback should destroy this mapping, so when the refcount
of the buffer
reaches 0 and the buffer (and it's GstMemory) is freed it will unmap the
DMA.

Kind Regards,

Aleksandr Slobodeniuk

Senior Software Engineer

+34 936 03 42 35

Carrer de Jordi Girona, 29

08034, Barcelona, Spain.

<http://fluendo.com>

<https://es.linkedin.com/company/fluendo>   <https://twitter.com/fluendo>
<https://github.com/fluendo>


On Sat, Nov 30, 2024 at 12:00=E2=80=AFAM Gregoire Gentil via gstreamer-deve=
l <
[email protected]> wrote:

> I push data in an appsrc element with gst_app_src_push_buffer.
>
> Data is mmaped from a fixed DMA memory allocation.
>
> I'm currently using GstBuffer *buffer =3D gst_buffer_new_wrapped_full to
> wrap data in the gstreamer buffer that is passed.
>
> Even if the notify function is null, the framework is still trying to
> free my data.
>
> It's actually "working" but freeing mapped memory and continuing to use
> it is certainly not a good idea.
>
> I obviously don't want to memcpy data. What is the proper way to wrap
> data in a GstBuffer structure so that gstreamer never tries to free the
> memory?
>
> Thank you in advance,
>
> Gr=C3=A9goire
>
>

--000000000000c67b6406281757bf
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi, I&#39;m sure that the gst_buffer_new_wrapped_full=
() function can&#39;t free the wrapped memory.<br></div><div>If you see it =
have been freed maybe it&#39;s freed by another thread, probably another co=
de in another thread unmaps it.<br></div><div>Since you don&#39;t want your=
 data to be freed while it&#39;s used, but also are passing NULL to the gst=
_buffer_new_wrapped_full(),</div><div>we can make a conclusion, that the ma=
nagement is not complete - in other words there&#39;s no logic that would f=
ree the data.<br></div><div>And if it&#39;s still freed, then there&#39;s a=
nother code that does that and does that at the wrong moment.<br></div><div=
><br>IMHO the mapping should be attached to the buffer through the &quot;us=
er_data&quot; parameter of the=C2=A0gst_buffer_new_wrapped_full(),<br> and =
the &quot;notify&quot; callback should destroy this mapping, so when the re=
fcount of the buffer</div><div>reaches 0 and the buffer (and it&#39;s GstMe=
mory) is freed it will unmap the DMA.<br></div><div><br></div><div>Kind Reg=
ards,<br clear=3D"all"></div><div><div dir=3D"ltr" class=3D"gmail_signature=
" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><span><div dir=3D"ltr=
" style=3D"margin-left:0pt" align=3D"left"><table style=3D"border:none;bord=
er-collapse:collapse"><colgroup><col width=3D"220"><col width=3D"175"></col=
group><tbody><tr style=3D"height:50.25pt"><td style=3D"border-left:solid #f=
fffff 1pt;border-right:solid #ffffff 1pt;border-bottom:solid #f915ab 1pt;bo=
rder-top:solid #ffffff 1pt;vertical-align:top;padding:5pt 5pt 5pt 5pt;overf=
low:hidden"><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-=
bottom:0pt"><span style=3D"font-size:10pt;font-family:&quot;DM Sans&quot;,s=
ans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:700;ver=
tical-align:baseline">Aleksandr Slobodeniuk</span></p><p dir=3D"ltr" style=
=3D"line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-s=
ize:8pt;font-family:&quot;DM Sans&quot;,sans-serif;color:rgb(0,0,0);backgro=
und-color:transparent;vertical-align:baseline">Senior Software Engineer</sp=
an></p></td><td style=3D"border-left:solid #ffffff 1pt;border-right:solid #=
ffffff 1pt;border-bottom:solid #f915ab 1pt;border-top:solid #ffffff 1pt;ver=
tical-align:top;padding:5pt 5pt 5pt 5pt;overflow:hidden"><p dir=3D"ltr" sty=
le=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"fon=
t-size:8pt;font-family:&quot;DM Sans&quot;,sans-serif;color:rgb(249,21,171)=
;background-color:transparent;font-weight:700;vertical-align:baseline">+34 =
936 03 42 35</span></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:=
0pt;margin-bottom:0pt"><span style=3D"font-size:8pt;font-family:&quot;DM Sa=
ns&quot;,sans-serif;color:rgb(0,0,0);background-color:transparent;vertical-=
align:baseline">Carrer de Jordi Girona, 29</span></p><p dir=3D"ltr" style=
=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-=
size:8pt;font-family:&quot;DM Sans&quot;,sans-serif;color:rgb(0,0,0);backgr=
ound-color:transparent;vertical-align:baseline">08034, Barcelona, Spain.</s=
pan></p></td></tr><tr style=3D"height:0pt"><td style=3D"border-left:solid #=
ffffff 1pt;border-right:solid #ffffff 1pt;border-bottom:solid #ffffff 1pt;b=
order-top:solid #f915ab 1pt;vertical-align:top;padding:5pt 5pt 5pt 5pt;over=
flow:hidden"><br><p dir=3D"ltr" style=3D"line-height:1.2;margin-top:0pt;mar=
gin-bottom:0pt"><a href=3D"http://fluendo.com" target=3D"_blank"><span styl=
e=3D"font-size:11pt;font-family:Arial,sans-serif;color:rgb(17,85,204);backg=
round-color:transparent;vertical-align:baseline"><span style=3D"border:none=
;display:inline-block;overflow:hidden;width:135px;height:23px"><img src=3D"=
https://lh7-us.googleusercontent.com/7f4gLdr2vrB3tXPMwJmLsq1xFFFqPKnq7My8Tn=
umcBKpIMI0HfrvUTStJeCYVUP7FynvoYZw1jq-6fQtHdK7u3qLC7NEmPMet6iQkYpoPcyp3EUYQ=
BrOnhgFYa7XDzgeDkJjVBknQdmb76YE2o3c63s" width=3D"135" height=3D"23" style=
=3D"margin-left:0px;margin-top:0px"></span></span></a></p></td><td style=3D=
"border-left:solid #ffffff 1pt;border-right:solid #ffffff 1pt;border-bottom=
:solid #ffffff 1pt;border-top:solid #f915ab 1pt;vertical-align:top;padding:=
5pt 5pt 5pt 5pt;overflow:hidden"><br><p dir=3D"ltr" style=3D"line-height:1.=
2;margin-top:0pt;margin-bottom:0pt"><a href=3D"https://es.linkedin.com/comp=
any/fluendo" target=3D"_blank"><span style=3D"font-size:10pt;font-family:&q=
uot;DM Sans&quot;,sans-serif;color:rgb(17,85,204);background-color:transpar=
ent;font-weight:700;vertical-align:baseline"><span style=3D"border:none;dis=
play:inline-block;overflow:hidden;width:23px;height:22px"><img src=3D"https=
://lh7-us.googleusercontent.com/OzDx4NDORH8FwQh0Ux7Eqszty4oDNvLyo5ad22JS7q5=
6cErOlNi67GdfCqrm0usd5BLylF7NHaveLM3xgRy99wMKYbhF-BxnrlHeUpOzDHYrG0E70Yb78W=
FAZuuTG4XQAgSVBxhPIXz3WvcK2_PrW9I" width=3D"23" height=3D"22" style=3D"marg=
in-left:0px;margin-top:0px"></span></span></a><span style=3D"font-size:10pt=
;font-family:&quot;DM Sans&quot;,sans-serif;color:rgb(51,113,242);backgroun=
d-color:transparent;font-weight:700;vertical-align:baseline"> =C2=A0 </span=
><a href=3D"https://twitter.com/fluendo" target=3D"_blank"><span style=3D"f=
ont-size:11pt;font-family:Arial,sans-serif;color:rgb(17,85,204);background-=
color:transparent;vertical-align:baseline"><span style=3D"border:none;displ=
ay:inline-block;overflow:hidden;width:22px;height:22px"><img src=3D"https:/=
/lh7-us.googleusercontent.com/dP_zElA4XMeIAQtvlavqqCuEG9zesjnBeqAMRtw-5HKza=
LT5nyX49DGsOuwokHCOLVQZTvc1Ng7NPJ8ozUhweGF6BWx-33UYp5XEQSCAcefq4NfZOUGRQgRV=
Wvv5Jyb725Rlc-zuXkM-T-MXCmqfVqo" width=3D"22" height=3D"22" style=3D"margin=
-left:0px;margin-top:0px"></span></span></a><span style=3D"font-size:10pt;f=
ont-family:&quot;DM Sans&quot;,sans-serif;color:rgb(51,113,242);background-=
color:transparent;font-weight:700;vertical-align:baseline"> =C2=A0 </span><=
a href=3D"https://github.com/fluendo" target=3D"_blank"><span style=3D"font=
-size:10pt;font-family:&quot;DM Sans&quot;,sans-serif;color:rgb(17,85,204);=
background-color:transparent;font-weight:700;vertical-align:baseline"><span=
 style=3D"border:none;display:inline-block;overflow:hidden;width:24px;heigh=
t:23px"><img src=3D"https://lh7-us.googleusercontent.com/xe27dLIuIPtsQqcHCI=
4EhUQzqxQmQTe3h0rsuabYwOv8-BoHKM50vhxMKUsssJ91DmCTt_MsYCwxQmZq-8bIQY-9e3TFd=
br3ckIfX3eSx1YKF5JB7LgH7v6qbjsn0ntflPyrb694cH-t9BYspEeZK-Q" width=3D"24" he=
ight=3D"23" style=3D"margin-left:0px;margin-top:0px"></span></span></a><spa=
n style=3D"font-size:10pt;font-family:&quot;DM Sans&quot;,sans-serif;color:=
rgb(51,113,242);background-color:transparent;font-weight:700;vertical-align=
:baseline">=C2=A0=C2=A0=C2=A0=C2=A0</span></p></td></tr></tbody></table></d=
iv></span></div></div></div><br></div><br><div class=3D"gmail_quote gmail_q=
uote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Nov 30, 2024 =
at 12:00=E2=80=AFAM Gregoire Gentil via gstreamer-devel &lt;<a href=3D"mail=
to:[email protected]">[email protected]=
.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1=
ex">I push data in an appsrc element with gst_app_src_push_buffer.<br>
<br>
Data is mmaped from a fixed DMA memory allocation.<br>
<br>
I&#39;m currently using GstBuffer *buffer =3D gst_buffer_new_wrapped_full t=
o <br>
wrap data in the gstreamer buffer that is passed.<br>
<br>
Even if the notify function is null, the framework is still trying to <br>
free my data.<br>
<br>
It&#39;s actually &quot;working&quot; but freeing mapped memory and continu=
ing to use <br>
it is certainly not a good idea.<br>
<br>
I obviously don&#39;t want to memcpy data. What is the proper way to wrap <=
br>
data in a GstBuffer structure so that gstreamer never tries to free the <br=
>
memory?<br>
<br>
Thank you in advance,<br>
<br>
Gr=C3=A9goire<br>
<br>
</blockquote></div>

--000000000000c67b6406281757bf--