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;
public class VideoMode implements Mode {
private Configuration config;
private Thread thread;
+ private Consumer<Frame> frameConsumer;
@Override
public void enter(Configuration config) {
}
private void startGrabberThread() {
+ assert frameConsumer != null;
thread = new Thread() {
public void run() {
try (FrameGrabber grabber = FrameGrabber.from(config)) {
while (!isInterrupted()) {
// Optional<Frame> 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
}
};
thread.start();
}
+
+ public void onFrame(Consumer<Frame> consumer) {
+ frameConsumer = consumer;
+ }
}