Skip to content

Commit

Permalink
Set timeout once, after grabber is open, fixes #431
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Feb 10, 2016
1 parent 7c565ab commit 2ccfaed
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class WebcamDefaultDevice implements WebcamDevice, BufferAccess, Runnable
private static final int DEVICE_BUFFER_SIZE = 5;

/**
* Artificial view sizes. I'm really not sure if will fit into other webcams
* but hope that OpenIMAJ can handle this.
* Artificial view sizes. I'm really not sure if will fit into other webcams but hope that
* OpenIMAJ can handle this.
*/
private final static Dimension[] DIMENSIONS = new Dimension[] {
WebcamResolution.QQVGA.getSize(),
Expand Down Expand Up @@ -77,7 +77,6 @@ protected void handle() {
return;
}

grabber.setTimeout(timeout);
result.set(grabber.nextFrame());
fresh.set(true);
}
Expand Down Expand Up @@ -335,6 +334,11 @@ public void open() {
throw new WebcamException("Cannot start native grabber!");
}

// set timeout, this MUST be done after grabber is open and before it's closed, otherwise it
// will result as crash

grabber.setTimeout(timeout);

LOG.debug("Webcam device session started");

Dimension size2 = new Dimension(grabber.getWidth(), grabber.getHeight());
Expand Down Expand Up @@ -377,8 +381,8 @@ public void open() {
}

/**
* this is to clean up all frames from device memory buffer which causes
* initial frames to be completely blank (black images)
* this is to clean up all frames from device memory buffer which causes initial frames to be
* completely blank (black images)
*/
private void clearMemoryBuffer() {
for (int i = 0; i < DEVICE_BUFFER_SIZE; i++) {
Expand Down Expand Up @@ -424,8 +428,8 @@ public void dispose() {
}

/**
* Determines if device should fail when requested image size is different
* than actually received.
* Determines if device should fail when requested image size is different than actually
* received.
*
* @param fail the fail on size mismatch flag, true or false
*/
Expand Down Expand Up @@ -453,6 +457,9 @@ public int getTimeout() {
* @param timeout the timeout value in milliseconds
*/
public void setTimeout(int timeout) {
if (isOpen()) {
throw new WebcamException("Timeout must be set before webcam is open");
}
this.timeout = timeout;
}

Expand Down

0 comments on commit 2ccfaed

Please sign in to comment.