X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FVideoMode.java;h=53cf09b5f8076562a2a1f78fcf4525ffbd08b17f;hp=be2ee4121526939ed4054e3941403b8db0b271d9;hb=100b82fe1c5ada6ef2ce768bf7b9f6f469650e11;hpb=4a2d60564647052562fad28644904298ba83667b diff --git a/src/kaka/cakelight/VideoMode.java b/src/kaka/cakelight/VideoMode.java index be2ee41..53cf09b 100644 --- a/src/kaka/cakelight/VideoMode.java +++ b/src/kaka/cakelight/VideoMode.java @@ -2,6 +2,7 @@ package kaka.cakelight; import java.io.IOException; import java.util.Optional; +import java.util.function.Consumer; import static kaka.cakelight.Main.log; import static kaka.cakelight.Main.timeIt; @@ -9,6 +10,7 @@ import static kaka.cakelight.Main.timeIt; public class VideoMode implements Mode { private Configuration config; private Thread thread; + private Consumer frameConsumer; @Override public void enter(Configuration config) { @@ -22,12 +24,14 @@ public class VideoMode implements Mode { } private void startGrabberThread() { + assert frameConsumer != null; thread = new Thread() { public void run() { try (FrameGrabber grabber = FrameGrabber.from(config)) { while (!isInterrupted()) { // Optional frame = grabber.grabFrame(); - timeIt("frame", grabber::grabFrame); + grabber.grabFrame().ifPresent(frameConsumer); +// timeIt("frame", grabber::grabFrame); // TODO: process frame // TODO: save where the LedController can access it } @@ -38,4 +42,8 @@ public class VideoMode implements Mode { }; thread.start(); } + + public void onFrame(Consumer consumer) { + frameConsumer = consumer; + } }