AppSink consumes lot's of memory. How to control memory consumption?
Michael Gruner
michael.gruner at ridgerun.com
Thu Sep 14 23:39:44 UTC 2023
Appsink has an internal queue. If your app does not consume samples fast enough, buffers will start accumulating in the queue.
You can limit the amount of buffers that the internal queue can hold using the "max-buffers" and "drop" properties. For example: "appsink max-buffers=10 drop=true".
> On 14 Sep 2023, at 17:32, Антон Шаров via gstreamer-devel <gstreamer-devel at lists.freedesktop.org> wrote:
>
> Hi.
>
> Consider following pipeline:
> rtspsrc ! rtph264depay ! h264parse ! tee name=vi vi. ! queue ! splitmuxsink vi. ! queue ! avdec_h264 ! jpegenc ! apsink
>
> Appsink config and NewSample handler is below. My problem is that it consumes lot’s of (unmanaged) memory.
> There is no leak, it works ok, after .net GC run memory lower to normal values and then grows again. It looks like
> saw-tooth. I’ve tried to limit max-buffers (set it to 100 or 1), drop = true but it seems that nothing works. Memory profiler shows smth like 30K instances of Gst.Memory holds 1.5Gb of unmanaged (in terms of .net) memory. Aftre GC collect, it seems to collect some of these instances and release some unmanaged memory (say it lowers 10 times). Again, there is no leeks, I just want to lower memory consumption of appsink element.
>
> Any ideas how to achieve that?
>
> Thanks in advance.
>
>
> Appsink code:
>
> var appSink = new AppSink("appsink_{CaptureConfig.CameraId}");
> appSink.NewSample += AppSinkNewSample;
> appSink.EmitSignals = true;
>
> private void AppSinkNewSample(object o, NewSampleArgs args)
> {
> if (o is AppSink aps)
> {
> using (var sample = aps.PullSample())
> {
> using (var buf = sample.Buffer)
> {
> SomeStuff(buf);
> }
> }
> }
> }
>
>
>
More information about the gstreamer-devel
mailing list