X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FVideoMode.java;h=1f6d68f2a7433aa5818171dd712565cb44f8b660;hp=960f9853a0bb9075dc7fb517b2e0b7640a15b8ea;hb=8418fbdaa82ab1152cd37154cb110762add943a6;hpb=d182b8ccdbbbdadc4441170f0135ec98c76f5d17 diff --git a/src/kaka/cakelight/VideoMode.java b/src/kaka/cakelight/VideoMode.java index 960f985..1f6d68f 100644 --- a/src/kaka/cakelight/VideoMode.java +++ b/src/kaka/cakelight/VideoMode.java @@ -7,7 +7,7 @@ import java.util.function.Consumer; public class VideoMode extends Mode { private Configuration config; - private Thread thread; + private Thread grabberThread; private Consumer frameConsumer; private VideoDeviceListener deviceListener; @@ -24,13 +24,13 @@ public class VideoMode extends Mode { @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 { 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 consumer) { @@ -54,14 +52,13 @@ public class VideoMode extends Mode { } private void onFrame(Frame frame) { - assert frameListener != null; - frameListener.accept(frame.getLedFrame()); + updateWithFrame(frame.getLedFrame()); } public void onVideoDeviceChange(Optional videoDevice) { // Should only happen when this mode is active! - if (thread != null) { - thread.interrupt(); + if (grabberThread != null) { + grabberThread.interrupt(); } videoDevice.ifPresent(this::startGrabberThread); }