Renamed a thread
[kaka/cakelight.git] / src / kaka / cakelight / VideoMode.java
index e4b9400..1f6d68f 100644 (file)
@@ -5,15 +5,15 @@ import java.io.IOException;
 import java.util.Optional;
 import java.util.function.Consumer;
 
-public class VideoMode extends Mode implements Consumer<Optional<File>> {
+public class VideoMode extends Mode {
     private Configuration config;
-    private Thread thread;
+    private Thread grabberThread;
     private Consumer<Frame> frameConsumer;
     private VideoDeviceListener deviceListener;
 
     public VideoMode() {
         deviceListener = new VideoDeviceListener();
-        deviceListener.onVideoDeviceChange(this);
+        deviceListener.onVideoDeviceChange(this::onVideoDeviceChange);
     }
 
     @Override
@@ -24,13 +24,13 @@ public class VideoMode extends Mode implements Consumer<Optional<File>> {
 
     @Override
     public void exit() {
-        thread.interrupt();
+        grabberThread.interrupt();
         deviceListener.stopListening();
     }
 
     private void startGrabberThread(File videoDevice) {
         assert frameConsumer != null;
-        thread = new Thread() {
+        grabberThread = new Thread() {
             public void run() {
                 try (FrameGrabber grabber = FrameGrabber.from(videoDevice, config)) {
                     while (!isInterrupted()) {
@@ -38,15 +38,13 @@ public class VideoMode extends Mode implements Consumer<Optional<File>> {
                         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
                     }
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
         };
-        thread.start();
+        grabberThread.start();
     }
 
     public void onVideoFrame(Consumer<Frame> consumer) {
@@ -54,15 +52,13 @@ public class VideoMode extends Mode implements Consumer<Optional<File>> {
     }
 
     private void onFrame(Frame frame) {
-        assert frameListener != null;
-        frameListener.accept(frame.getLedFrame());
+        updateWithFrame(frame.getLedFrame());
     }
 
-    @Override
-    public void accept(Optional<File> videoDevice) {
+    public void onVideoDeviceChange(Optional<File> videoDevice) {
         // Should only happen when this mode is active!
-        if (thread != null) {
-            thread.interrupt();
+        if (grabberThread != null) {
+            grabberThread.interrupt();
         }
         videoDevice.ifPresent(this::startGrabberThread);
     }