-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
WebcamDefaultDriver.java
74 lines (57 loc) · 1.78 KB
/
WebcamDefaultDriver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.github.sarxos.webcam.ds.buildin;
import java.util.ArrayList;
import java.util.List;
import org.bridj.Pointer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamDiscoverySupport;
import com.github.sarxos.webcam.WebcamDriver;
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;
/**
* Default build-in webcam driver based on natives from OpenIMAJ framework. It
* can be widely used on various systems - Mac OS, Linux (x86, x64, ARM),
* Windows (win32, win64).
*
* @author Bartosz Firyn (SarXos)
*/
public class WebcamDefaultDriver implements WebcamDriver, WebcamDiscoverySupport {
/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(WebcamDefaultDriver.class);
private static OpenIMAJGrabber grabber = null;
@Override
public List<WebcamDevice> getDevices() {
LOG.debug("Searching devices");
if (grabber == null) {
grabber = new OpenIMAJGrabber();
}
List<WebcamDevice> devices = new ArrayList<WebcamDevice>();
Pointer<DeviceList> pointer = grabber.getVideoDevices();
DeviceList list = pointer.get();
for (Device device : list.asArrayList()) {
devices.add(new WebcamDefaultDevice(device));
}
if (LOG.isDebugEnabled()) {
for (WebcamDevice device : devices) {
LOG.debug("Found device {}", device.getName());
}
}
return devices;
}
@Override
public long getScanInterval() {
return 3000;
}
@Override
public boolean isScanPossible() {
return true;
}
@Override
public boolean isThreadSafe() {
return false;
}
}