<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I was reporting this as an issue here <a href="https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1010" class="">https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1010</a>, but was redirected to this list. Not sure if it is the right place, but I will try.</div><div class=""><br class=""></div><div class=""><div class="md"><p data-sourcepos="1:1-1:114" dir="auto" class="">I'm referring to the Java sample app: <a href="https://github.com/centricular/gstwebrtc-demos/tree/master/sendrecv/gst-java" rel="nofollow noreferrer noopener" target="_blank" class="">https://github.com/centricular/gstwebrtc-demos/tree/master/sendrecv/gst-java</a></p><p data-sourcepos="3:1-3:157" dir="auto" class="">With respect to increasing memory consumption everything is fine and balanced if we are using this approach to display the received video in a pop-up window:</p>
<pre class="code highlight white js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code class=""><span id="LC1" class="line" lang="plaintext">if (name.startsWith("video")) {</span>
<span id="LC2" class="line" lang="plaintext">            Element queue = ElementFactory.make("queue", "my-videoqueue");</span>
<span id="LC3" class="line" lang="plaintext">            Element videoconvert = ElementFactory.make("videoconvert", "my-videoconvert");</span>
<span id="LC4" class="line" lang="plaintext">            Element autovideosink = ElementFactory.make("osxvideosink", "my-autovideosink");</span>
<span id="LC5" class="line" lang="plaintext">//            Element autovideosink = ElementFactory.make("autovideosink", "my-autovideosink");</span>
<span id="LC6" class="line" lang="plaintext">            pipe.addMany(queue, videoconvert, autovideosink);</span>
<span id="LC7" class="line" lang="plaintext">            queue.syncStateWithParent();</span>
<span id="LC8" class="line" lang="plaintext">            videoconvert.syncStateWithParent();</span>
<span id="LC9" class="line" lang="plaintext">            autovideosink.syncStateWithParent();</span>
<span id="LC10" class="line" lang="plaintext">            <a href="http://pad.link" class="">pad.link</a>(queue.getStaticPad("sink"));</span>
<span id="LC11" class="line" lang="plaintext">            <a href="http://queue.link" class="">queue.link</a>(videoconvert);</span>
<span id="LC12" class="line" lang="plaintext">            <a href="http://videoconvert.link" class="">videoconvert.link</a>(autovideosink);</span>
<span id="LC13" class="line" lang="plaintext">}</span></code></pre><p data-sourcepos="21:1-21:53" dir="auto" class="">(autovideosink is replaced by osxvideosink for macOS)</p><p data-sourcepos="23:1-23:196" dir="auto" class="">If this sequence above is replaced by the following, the memory consumption of the Java app grows by 200 MB/s, which after a while leads to a complete crash of the app if not of the entire system:</p>
<pre class="code highlight white js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code class=""><span id="LC1" class="line" lang="plaintext">if (name.startsWith("video")) {</span>
<span id="LC2" class="line" lang="plaintext">            Element queue = ElementFactory.make("queue", "my-videoqueue");</span>
<span id="LC3" class="line" lang="plaintext">            Element videoconvert = ElementFactory.make("videoconvert", "my-videoconvert");</span>
<span id="LC4" class="line" lang="plaintext">            AppSink sink = (AppSink) ElementFactory.make("appsink", "my-appsink");</span>
<span id="LC5" class="line" lang="plaintext">            sink.set("emit-signals", true);</span>
<span id="LC6" class="line" lang="plaintext">            sink.connect(new AppSink.NEW_SAMPLE() {</span>
<span id="LC7" class="line" lang="plaintext">                @Override</span>
<span id="LC8" class="line" lang="plaintext">                public FlowReturn newSample(AppSink elem) {</span>
<span id="LC9" class="line" lang="plaintext">                    Sample sample = elem.pullSample();</span>
<span id="LC10" class="line" lang="plaintext">                    Structure capsStruct = sample.getCaps().getStructure(0);</span>
<span id="LC11" class="line" lang="plaintext">                    String format = capsStruct.getString("format");</span>
<span id="LC12" class="line" lang="plaintext">                    int width = capsStruct.getInteger("width");</span>
<span id="LC13" class="line" lang="plaintext">                    int height = capsStruct.getInteger("height");</span>
<span id="LC14" class="line" lang="plaintext"></span>
<span id="LC15" class="line" lang="plaintext">                    ByteBuffer bytes = sample.getBuffer().map(false);</span>
<span id="LC16" class="line" lang="plaintext">                    byte[] buffer = new byte[bytes.remaining()];</span>
<span id="LC17" class="line" lang="plaintext">                    bytes.get(buffer);</span>
<span id="LC18" class="line" lang="plaintext">                    dragonfly.onNextFrame(format, buffer, width, height);</span>
<span id="LC19" class="line" lang="plaintext"></span>
<span id="LC20" class="line" lang="plaintext">                    sample.dispose();</span>
<span id="LC21" class="line" lang="plaintext">                    return FlowReturn.OK;</span>
<span id="LC22" class="line" lang="plaintext">                }</span>
<span id="LC23" class="line" lang="plaintext">            });</span>
<span id="LC24" class="line" lang="plaintext"></span>
<span id="LC25" class="line" lang="plaintext">            sink.connect(new AppSink.NEW_PREROLL() {</span>
<span id="LC26" class="line" lang="plaintext">                @Override</span>
<span id="LC27" class="line" lang="plaintext">                public FlowReturn newPreroll(AppSink elem) {</span>
<span id="LC28" class="line" lang="plaintext">                    Sample sample = elem.pullPreroll();</span>
<span id="LC29" class="line" lang="plaintext">                    Structure capsStruct = sample.getCaps().getStructure(0);</span>
<span id="LC30" class="line" lang="plaintext">                    String format = capsStruct.getString("format");</span>
<span id="LC31" class="line" lang="plaintext"></span>
<span id="LC32" class="line" lang="plaintext">                    int width = capsStruct.getInteger("width");</span>
<span id="LC33" class="line" lang="plaintext">                    int height = capsStruct.getInteger("height");</span>
<span id="LC34" class="line" lang="plaintext"></span>
<span id="LC35" class="line" lang="plaintext">                    ByteBuffer bytes = sample.getBuffer().map(false);</span>
<span id="LC36" class="line" lang="plaintext">                    byte[] buffer = new byte[bytes.remaining()];</span>
<span id="LC37" class="line" lang="plaintext">                    bytes.get(buffer);</span>
<span id="LC38" class="line" lang="plaintext">                    dragonfly.onNextFrame(format, buffer, width, height);</span>
<span id="LC39" class="line" lang="plaintext"></span>
<span id="LC40" class="line" lang="plaintext">                    sample.dispose();</span>
<span id="LC41" class="line" lang="plaintext">                    return FlowReturn.OK;</span>
<span id="LC42" class="line" lang="plaintext">                }</span>
<span id="LC43" class="line" lang="plaintext">            });</span>
<span id="LC44" class="line" lang="plaintext"></span>
<span id="LC45" class="line" lang="plaintext">            pipe.addMany(queue, videoconvert, sink);</span>
<span id="LC46" class="line" lang="plaintext">            queue.syncStateWithParent();</span>
<span id="LC47" class="line" lang="plaintext"></span>
<span id="LC48" class="line" lang="plaintext">            videoconvert.syncStateWithParent();</span>
<span id="LC49" class="line" lang="plaintext">            sink.syncStateWithParent();</span>
<span id="LC50" class="line" lang="plaintext">            <a href="http://pad.link" class="">pad.link</a>(queue.getStaticPad("sink"));</span>
<span id="LC51" class="line" lang="plaintext">            <a href="http://queue.link" class="">queue.link</a>(videoconvert);</span>
<span id="LC52" class="line" lang="plaintext">            <a href="http://videoconvert.link" class="">videoconvert.link</a>(sink);</span>
<span id="LC53" class="line" lang="plaintext">}</span></code></pre><p data-sourcepos="81:1-81:76" dir="auto" class="">Is there anything wrong with the sequence above, which could cause the leak? The copy of the buffers (instead of forwarding) is necessary, since the final handling is done in native code, not under my control. And even if we don't do anything in the callbacks - the simple replace of autovideosink vs appsink causes the leak.</p><div class=""><br class=""></div><div class=""><br class=""></div><div class="">TIA</div><div class=""><br class=""></div></div></div></body></html>