Skip to content

Commit 2ad6b81

Browse files
committed
Merge pull request #313 from krok32/master
Passing parameters to WebcamDevice instances, issue #307
2 parents 2697860 + b8aaa95 commit 2ad6b81

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Collections;
99
import java.util.Iterator;
1010
import java.util.List;
11+
import java.util.Map;
1112
import java.util.concurrent.CopyOnWriteArrayList;
1213
import java.util.concurrent.ExecutorService;
1314
import java.util.concurrent.Executors;
@@ -20,6 +21,7 @@
2021
import org.slf4j.LoggerFactory;
2122

2223
import com.github.sarxos.webcam.WebcamDevice.BufferAccess;
24+
import com.github.sarxos.webcam.WebcamDevice.Configurable;
2325
import com.github.sarxos.webcam.WebcamUpdater.DefaultDelayCalculator;
2426
import com.github.sarxos.webcam.WebcamUpdater.DelayCalculator;
2527
import com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice;
@@ -764,6 +766,23 @@ public void getImageBytes(ByteBuffer target) {
764766
}
765767
}
766768

769+
/**
770+
* If the underlying device implements Configurable interface, specified
771+
* parameters are passed to it. May be called before the open method or
772+
* later in dependence of the device implementation.
773+
*
774+
* @param parameters - Map of parameters changing device defaults
775+
* @see Configurable
776+
*/
777+
public void setParameters(Map<String, ?> parameters) {
778+
WebcamDevice device = getDevice();
779+
if (device instanceof Configurable) {
780+
((Configurable) device).setParameters(parameters);
781+
} else {
782+
LOG.debug("Webcam device {} is not configurable", device);
783+
}
784+
}
785+
767786
/**
768787
* Is webcam ready to be read.
769788
*

webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDevice.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.Dimension;
44
import java.awt.image.BufferedImage;
55
import java.nio.ByteBuffer;
6+
import java.util.Map;
67

78

89
/**
@@ -56,6 +57,27 @@ public static interface FPSSource {
5657

5758
}
5859

60+
/**
61+
* This interface may be implemented by devices which expect any specific
62+
* parameters.
63+
*
64+
* @author Martin Krok (krok32)
65+
*/
66+
public static interface Configurable {
67+
68+
/**
69+
* Sets device parameters. Each device implementation may accept its own
70+
* set of parameters. All accepted keys, value types, possible values
71+
* and defaults should be reasonably documented by the implementor. May
72+
* be called before the open method or later in dependence of the device
73+
* implementation.
74+
*
75+
* @param parameters - Map of parameters changing device defaults
76+
* @see Webcam#setParameters(Map)
77+
*/
78+
void setParameters(Map<String, ?> parameters);
79+
}
80+
5981
/**
6082
* Get device name.
6183
*

0 commit comments

Comments
 (0)