-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to read image to pre-created buffer, fixes #240
- Loading branch information
Showing
9 changed files
with
209 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
webcam-capture/src/main/java/com/github/sarxos/webcam/ds/cgt/WebcamGetBufferTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.sarxos.webcam.ds.cgt; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.github.sarxos.webcam.WebcamDevice; | ||
import com.github.sarxos.webcam.WebcamDevice.BufferAccess; | ||
import com.github.sarxos.webcam.WebcamDriver; | ||
import com.github.sarxos.webcam.WebcamTask; | ||
|
||
|
||
public class WebcamGetBufferTask extends WebcamTask { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(WebcamGetBufferTask.class); | ||
|
||
private volatile ByteBuffer buffer = null; | ||
|
||
public WebcamGetBufferTask(WebcamDriver driver, WebcamDevice device) { | ||
super(driver, device); | ||
} | ||
|
||
public ByteBuffer getBuffer() { | ||
try { | ||
process(); | ||
} catch (InterruptedException e) { | ||
LOG.debug("Image buffer request interrupted", e); | ||
return null; | ||
} | ||
return buffer; | ||
} | ||
|
||
@Override | ||
protected void handle() { | ||
|
||
WebcamDevice device = getDevice(); | ||
if (!device.isOpen()) { | ||
return; | ||
} | ||
|
||
if (!(device instanceof BufferAccess)) { | ||
return; | ||
} | ||
|
||
buffer = ((BufferAccess) device).getImageBytes(); | ||
} | ||
} |
Oops, something went wrong.