Skip to content

Commit

Permalink
issue sarxos#307 - passing parameters to WebcamDevice instances
Browse files Browse the repository at this point in the history
  • Loading branch information
krok32 committed Feb 16, 2015
1 parent fd1c944 commit b8aaa95
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java
Expand Up @@ -8,6 +8,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -20,6 +21,7 @@
import org.slf4j.LoggerFactory;

import com.github.sarxos.webcam.WebcamDevice.BufferAccess;
import com.github.sarxos.webcam.WebcamDevice.Configurable;
import com.github.sarxos.webcam.WebcamUpdater.DefaultDelayCalculator;
import com.github.sarxos.webcam.WebcamUpdater.DelayCalculator;
import com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice;
Expand Down Expand Up @@ -764,6 +766,23 @@ public void getImageBytes(ByteBuffer target) {
}
}

/**
* If the underlying device implements Configurable interface, specified
* parameters are passed to it. May be called before the open method or
* later in dependence of the device implementation.
*
* @param parameters - Map of parameters changing device defaults
* @see Configurable
*/
public void setParameters(Map<String, ?> parameters) {
WebcamDevice device = getDevice();
if (device instanceof Configurable) {
((Configurable) device).setParameters(parameters);
} else {
LOG.debug("Webcam device {} is not configurable", device);
}
}

/**
* Is webcam ready to be read.
*
Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.util.Map;


/**
Expand Down Expand Up @@ -56,6 +57,27 @@ public static interface FPSSource {

}

/**
* This interface may be implemented by devices which expect any specific
* parameters.
*
* @author Martin Krok (krok32)
*/
public static interface Configurable {

/**
* Sets device parameters. Each device implementation may accept its own
* set of parameters. All accepted keys, value types, possible values
* and defaults should be reasonably documented by the implementor. May
* be called before the open method or later in dependence of the device
* implementation.
*
* @param parameters - Map of parameters changing device defaults
* @see Webcam#setParameters(Map)
*/
void setParameters(Map<String, ?> parameters);
}

/**
* Get device name.
*
Expand Down

0 comments on commit b8aaa95

Please sign in to comment.