-
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.
Redesign some synchronization features
refs #26
- Loading branch information
Showing
8 changed files
with
225 additions
and
77 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
43 changes: 43 additions & 0 deletions
43
webcam-capture/src/example/java/com/github/sarxos/webcam/ConcurrentThreadsExample.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,43 @@ | ||
package com.github.sarxos.webcam; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
|
||
public class ConcurrentThreadsExample { | ||
|
||
private static AtomicInteger counter = new AtomicInteger(0); | ||
|
||
private static final class Capture extends Thread { | ||
|
||
private static final AtomicInteger number = new AtomicInteger(0); | ||
|
||
public Capture() { | ||
super("capture-" + number.incrementAndGet()); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (true) { | ||
Webcam.getDefault().getImage(); | ||
int value = counter.incrementAndGet(); | ||
if (value != 0 && value % 10 == 0) { | ||
System.out.println(Thread.currentThread().getName() + ": Frames captured: " + value); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
/** | ||
* This example will start several concurrent threads which use single | ||
* webcam instance. | ||
*/ | ||
|
||
int n = Runtime.getRuntime().availableProcessors() * 4; | ||
for (int i = 0; i < n; i++) { | ||
System.out.println("Thread: " + i); | ||
new Capture().start(); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
webcam-capture/src/example/java/com/github/sarxos/webcam/PureDefaultDeviceExample.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,45 @@ | ||
package com.github.sarxos.webcam; | ||
|
||
import org.bridj.Pointer; | ||
|
||
import com.github.sarxos.webcam.ds.buildin.natives.Device; | ||
import com.github.sarxos.webcam.ds.buildin.natives.DeviceList; | ||
import com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber; | ||
|
||
|
||
public class PureDefaultDeviceExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
/** | ||
* This example show how to use native OpenIMAJ API to capture raw bytes | ||
* data as byte[] array. It also calculates current FPS. | ||
*/ | ||
|
||
OpenIMAJGrabber grabber = new OpenIMAJGrabber(); | ||
|
||
Device device = null; | ||
Pointer<DeviceList> devices = grabber.getVideoDevices(); | ||
for (Device d : devices.get().asArrayList()) { | ||
device = d; | ||
break; | ||
} | ||
|
||
grabber.startSession(320, 240, 30, Pointer.pointerTo(device)); | ||
|
||
long t1 = System.currentTimeMillis() / 1000; | ||
|
||
int n = 100; | ||
int i = 0; | ||
do { | ||
grabber.nextFrame(); | ||
grabber.getImage().getBytes(320 * 240 * 3); // byte[] | ||
} while (++i < n); | ||
|
||
long t2 = System.currentTimeMillis() / 1000; | ||
|
||
System.out.println("FPS: " + ((double) n / (t2 - t1))); | ||
|
||
grabber.stopSession(); | ||
} | ||
} |
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
Oops, something went wrong.