import org.freedesktop.gstreamer.Bus;
import org.freedesktop.gstreamer.Gst;
import org.freedesktop.gstreamer.Pipeline;
import static java.lang.Thread.sleep;
public class TestMain {
public static void main(String[] args) throws InterruptedException {
Gst.init();
for(int loop = 0; loop < 500; ++loop) {
String pipelinestring = "videotestsrc num-buffers=100 ! " + "x264enc speed-preset=0 ! h264parse ! fakesink";
Pipeline pipeline = (Pipeline) Gst.parseLaunch(pipelinestring);
pipeline.getBus().connect((Bus.ERROR) (gstObject, i, s) -> System.out.println("ERROR "+i+" "+s+" "+gstObject));
pipeline.getBus().connect((Bus.WARNING) (gstObject, i, s) -> System.out.println("WARN "+i+" "+s+" "+gstObject));
pipeline.getBus().connect((Bus.EOS) obj -> {
System.out.println("EOS " + obj);
((Pipeline) obj).stop();
((Pipeline)obj).getBus().dispose();
obj.dispose();
Gst.quit();
obj = null;
System.gc();
});
pipeline.play();
Gst.main();
// Disable this to have fixed GstBus Threads
Thread.sleep(1000);
}
// Block to see output
while(true){
sleep(10);
}
}
}This is working fine, except for these Thread proxies staying alive, which I think will become a problem in the long run.
They aren't cleaned up by forcing GC. Are the pipelines destroyed right in the example code?
Is this kind of pipeline creation strange behaviour? Seems to me you should be able to create and more than one pipeline..
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 19
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16
GstBus : 16GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 219
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 223
GstBus : 223
GstBus : 223
GstBus : 223
GstBus : 223
GstBus : 223
GstBus : 221
GstBus : 221
GstBus : 221
GstBus : 221
I'm using GStreamer for E2E tests and I also realized the `GstBus` leak.In my case, I'm not reusing the same pipeline, and I always call pipeline stop and dispose but the threads are still there
I was reading about CallbackThreadInitializer and I wonder if we could somehow call Native.detach() to detach the thread..
(gst1-java-core:37977): GLib-WARNING **: 16:33:22.568: poll(2) failed due to: Invalid argument.
Doing some profiling I saw a bunch of objects that weren't being clean and I mitigated the issue by calling `System.gc()` directly but my number of threads constantly increases during my executions and it's mostly GstBus.
Other things I tried was to call pipeline.close(), pipeline.dispose(), Gst.quit() and Gst.deinit() but without much success.
If you think that the Native.detach() makes sense I will gladly open an issue on Github, and also try to help any way I can
Regards