Skip to content

Commit

Permalink
Introduce get image timeout in OpenImage-based default driver, fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Mar 18, 2013
1 parent cf0b870 commit dcfb905
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class WebcamDefaultDevice implements WebcamDevice, BufferAccess {
*/
private static final ColorSpace COLOR_SPACE = ColorSpace.getInstance(ColorSpace.CS_sRGB);

private int timeout = 5000;

private OpenIMAJGrabber grabber = null;
private Device device = null;
private Dimension size = null;
Expand Down Expand Up @@ -136,7 +138,22 @@ public ByteBuffer getImageBytes() {

LOG.trace("Webcam device get image (next frame)");

grabber.nextFrame();
// set image acquisition timeout

grabber.setTimeout(timeout);

// grab next frame

int flag = grabber.nextFrame();
if (flag == -1) {
LOG.error("Timeout when requesting image!");
return null;
} else if (flag < -1) {
LOG.error("Error requesting new frame!");
return null;
}

// get image buffer

Pointer<Byte> image = grabber.getImage();
if (image == null) {
Expand Down Expand Up @@ -289,4 +306,22 @@ public void setFailOnSizeMismatch(boolean fail) {
public boolean isOpen() {
return open.get();
}

/**
* Get timeout for image acquisition.
*
* @return Value in milliseconds
*/
public int getTimeout() {
return timeout;
}

/**
* Set timeout for image acquisition.
*
* @param timeout the timeout value in milliseconds
*/
public void setTimeout(int timeout) {
this.timeout = timeout;
}
}

0 comments on commit dcfb905

Please sign in to comment.