Skip to content

Instantly share code, notes, and snippets.

@MaZderMind
Created Mar 22, 2020
Embed
What would you like to do?
pad-block-deadlock.
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.freedesktop.gstreamer.Element;
import org.freedesktop.gstreamer.Gst;
import org.freedesktop.gstreamer.Pad;
import org.freedesktop.gstreamer.Pipeline;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {
Gst.init();
Pipeline pipeline = (Pipeline) Gst
.parseLaunch("audiotestsrc name=src ! fakesink sync=false");
pipeline.play();
Element src = pipeline.getElementByName("src");
Pad srcPad = src.getStaticPad("src");
//noinspection InfiniteLoopStatement
while (true) {
log.info("> blocking");
CompletableFuture<Void> future = new CompletableFuture<>();
srcPad.block(() -> {
log.info("= blocked");
future.complete(null);
log.info("= completed");
});
log.info("< getting");
future.get(10, TimeUnit.SECONDS);
log.info("< got");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment