Added a LED controller that consumes LED frames from the modes
[kaka/cakelight.git] / src / kaka / cakelight / VideoMode.java
index e0dc386..e4b9400 100644 (file)
@@ -5,7 +5,7 @@ import java.io.IOException;
 import java.util.Optional;
 import java.util.function.Consumer;
 
-public class VideoMode implements Mode, Consumer<Optional<File>> {
+public class VideoMode extends Mode implements Consumer<Optional<File>> {
     private Configuration config;
     private Thread thread;
     private Consumer<Frame> frameConsumer;
@@ -34,8 +34,9 @@ public class VideoMode implements Mode, Consumer<Optional<File>> {
             public void run() {
                 try (FrameGrabber grabber = FrameGrabber.from(videoDevice, config)) {
                     while (!isInterrupted()) {
-//                        Optional<Frame> frame = grabber.grabFrame();
-                        grabber.grabFrame().ifPresent(frameConsumer);
+                        Optional<Frame> frame = grabber.grabFrame();
+                        if (frameConsumer != null) frame.ifPresent(frameConsumer);
+                        frame.ifPresent(VideoMode.this::onFrame);
 //                        timeIt("frame", grabber::grabFrame);
                         // TODO: process frame
                         // TODO: save where the LedController can access it
@@ -48,10 +49,15 @@ public class VideoMode implements Mode, Consumer<Optional<File>> {
         thread.start();
     }
 
-    public void onFrame(Consumer<Frame> consumer) {
+    public void onVideoFrame(Consumer<Frame> consumer) {
         frameConsumer = consumer;
     }
 
+    private void onFrame(Frame frame) {
+        assert frameListener != null;
+        frameListener.accept(frame.getLedFrame());
+    }
+
     @Override
     public void accept(Optional<File> videoDevice) {
         // Should only happen when this mode is active!