001 package com.github.sarxos.webcam.ds.cgt;
002
003 import org.slf4j.Logger;
004 import org.slf4j.LoggerFactory;
005
006 import com.github.sarxos.webcam.WebcamDevice;
007 import com.github.sarxos.webcam.WebcamDriver;
008 import com.github.sarxos.webcam.WebcamTask;
009
010
011 public class WebcamOpenTask extends WebcamTask {
012
013 private static final Logger LOG = LoggerFactory.getLogger(WebcamOpenTask.class);
014
015 public WebcamOpenTask(WebcamDriver driver, WebcamDevice device) {
016 super(driver, device);
017 }
018
019 public void open() throws InterruptedException {
020 process();
021 }
022
023 @Override
024 protected void handle() {
025
026 WebcamDevice device = getDevice();
027
028 if (device.isOpen()) {
029 return;
030 }
031
032 if (device.getResolution() == null) {
033 device.setResolution(device.getResolutions()[0]);
034 }
035
036 LOG.info("Opening webcam {}", device.getName());
037
038 device.open();
039 }
040 }