Made a GUI tester for video capture
[kaka/cakelight.git] / src / kaka / cakelight / VideoMode.java
index be2ee41..53cf09b 100644 (file)
@@ -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<Frame> 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> 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<Frame> consumer) {
+        frameConsumer = consumer;
+    }
 }