Add video device to config
[kaka/cakelight.git] / src / kaka / cakelight / mode / VideoMode.java
index c7985e3..a8397dc 100644 (file)
@@ -25,7 +25,12 @@ public class VideoMode extends Mode {
     @Override
     public void enter(Configuration config) {
         this.config = config;
-        deviceListener.startListening();
+        if (config.video.deviceIsAutomatic) {
+            deviceListener.startListening();
+        } else {
+            File videoDevice = new File(config.video.device);
+            startGrabberThread(videoDevice);
+        }
     }
 
     @Override
@@ -36,13 +41,17 @@ public class VideoMode extends Mode {
     @Override
     public void resume() {
         isPaused = false;
-        grabberThread.notify();
+       synchronized (grabberThread) {
+           grabberThread.notify();
+       }
     }
 
     @Override
     public void exit() {
         grabberThread.interrupt();
-        deviceListener.stopListening();
+        if (config.video.deviceIsAutomatic) {
+            deviceListener.stopListening();
+        }
     }
 
     private void startGrabberThread(File videoDevice) {
@@ -53,7 +62,9 @@ public class VideoMode extends Mode {
                     while (!isInterrupted()) {
                         Optional<VideoFrame> frame = grabber.grabFrame();
                         if (isPaused) {
-                            wait();
+                           synchronized (grabberThread) {
+                               wait();
+                           }
                         }
                         if (frameConsumer != null) frame.ifPresent(frameConsumer);
                         frame.ifPresent(VideoMode.this::onVideoFrame);