Made a GUI tester for video capture
[kaka/cakelight.git] / src / kaka / cakelight / VideoMode.java
CommitLineData
4a2d6056
TW
1package kaka.cakelight;
2
3import java.io.IOException;
4import java.util.Optional;
100b82fe 5import java.util.function.Consumer;
4a2d6056
TW
6
7import static kaka.cakelight.Main.log;
8import static kaka.cakelight.Main.timeIt;
9
10public class VideoMode implements Mode {
11 private Configuration config;
12 private Thread thread;
100b82fe 13 private Consumer<Frame> frameConsumer;
4a2d6056
TW
14
15 @Override
16 public void enter(Configuration config) {
17 this.config = config;
18 startGrabberThread();
19 }
20
21 @Override
22 public void exit() {
23 thread.interrupt();
24 }
25
26 private void startGrabberThread() {
100b82fe 27 assert frameConsumer != null;
4a2d6056
TW
28 thread = new Thread() {
29 public void run() {
30 try (FrameGrabber grabber = FrameGrabber.from(config)) {
31 while (!isInterrupted()) {
32// Optional<Frame> frame = grabber.grabFrame();
100b82fe
TW
33 grabber.grabFrame().ifPresent(frameConsumer);
34// timeIt("frame", grabber::grabFrame);
4a2d6056
TW
35 // TODO: process frame
36 // TODO: save where the LedController can access it
37 }
38 } catch (IOException e) {
39 e.printStackTrace();
40 }
41 }
42 };
43 thread.start();
44 }
100b82fe
TW
45
46 public void onFrame(Consumer<Frame> consumer) {
47 frameConsumer = consumer;
48 }
4a2d6056 49}