public class GstStreamerPipeline {
public GstStreamerPipeline(String pipelineDescription) {
this.pipeline = (Pipeline) Gst.parseLaunch(pipelineDescription);
this.terminationSignal = new CountDownLatch(1);
this.pipeline.getBus().connect((Bus.EOS) (e) -> termination());
}
public synchronized void play() {
this.pipeline.ready();
this.pipeline.getState();
this.pipeline.play();
this.pipeline.getState();
logger.debug("[{}] - Pipeline has started", uuid);
}
public synchronized void stop() {
if (stopped)
return;
this.pipeline.sendEvent(new EOSEvent());
this.pipeline.postMessage(new EOSMessage(pipeline));
this.pipeline.postMessage(new EOSMessage(pipeline.getBus()));
try {
// Wait for the termination signal.
terminationSignal.await();
if (!stopped) {
// TODO : Workaround : I have to add a hardcode "waiting 2 seconds", otherwise Some threads (GstBus) stucks forever and lock the camera device).
// When this happens, I have to kill the application to release the resources.
// BusError => Could not open audio device for recording. Device is being used by another application.
// Work around ==> Thread.sleep(2000);
pipeline.stop();
// pipeline.dispose() # also does not work
Gst.invokeLater(pipeline::dispose);
stopped = true;
}
logger.debug("[{}] - Pipeline has stopped", uuid);
} catch (InterruptedException e) {
logger.warn("[{}] - Pipeline stop was interrupted", uuid);
}
}
public void termination() {
// Release termination signal.
terminationSignal.countDown();
}
}
1 - All GstBus Daemon Threads were created on the first click.
2 - I couldn't find any way to "release" these threads.
3 - It looks like java disposes the pipeline without waiting for "confirmation" from the native gstreamer.
--
You received this message because you are subscribed to the Google Groups "gstreamer-java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gstreamer-jav...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gstreamer-java/CAPxOS5Eb0oboDPrV_gw_%2Bxt9LHcHHhxkkVV8V2TsiV%2BRa6L8eg%40mail.gmail.com.