Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #307 - passing parameters to WebcamDevice instances #313

Merged
merged 1 commit into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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