Skip to content

Commit

Permalink
Update LTI-CIVIL binaries by the ones from George Rhoten patch, refs #…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jun 18, 2014
1 parent 3446098 commit e8278d2
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 61 deletions.
2 changes: 2 additions & 0 deletions webcam-capture-drivers/driver-lti-civil/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/etc/licenses"/>
<classpathentry kind="src" path="src/example/java"/>
<classpathentry kind="src" path="src/example/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
3 changes: 3 additions & 0 deletions webcam-capture-drivers/driver-lti-civil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Although, the LTI-CIVIL works with Mac OS as well as with Linux or Windows, this
has been designed for Linux and Windows only (32- and 64-bit). This is because I
do not have Mac OS machine to perform tests.

## NOTES

* LTI-CIVIL does not work on Ubuntu 12.04 on x86_64!

## Download

Expand Down
5 changes: 5 additions & 0 deletions webcam-capture-drivers/driver-lti-civil/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<artifactId>lti-civil-no-swt</artifactId>
<version>20070920-1721</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.ds.civil.LtiCivilDriver;


public class LtiCivilDriverExample {

static {
Webcam.setDriver(new LtiCivilDriver());
}

public static void main(String[] args) {
JFrame frame = new JFrame("LTI-CIVIL Webcam Capture Driver Example");
frame.add(new WebcamPanel(Webcam.getDefault()));
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamDriver;
import com.github.sarxos.webcam.WebcamException;
import com.lti.civil.CaptureDeviceInfo;
import com.lti.civil.CaptureException;
import com.lti.civil.CaptureSystem;
Expand All @@ -19,55 +21,74 @@ public class LtiCivilDriver implements WebcamDriver {

// load civil DLL
static {
LtiCivilLoader.load("civil");

}

private static final Logger LOG = LoggerFactory.getLogger(LtiCivilDriver.class);

private static List<WebcamDevice> devices = null;
private static CaptureSystemFactory factory = null;
private static CaptureSystem system = null;
private static boolean initialized = false;

private static volatile boolean ready = false;
private static final AtomicBoolean INIT = new AtomicBoolean(false);

private static void initialize() {

if (!INIT.compareAndSet(false, true)) {
return;
}

LtiCivilLoader.load("civil");

factory = DefaultCaptureSystemFactorySingleton.instance();

try {
system = factory.createCaptureSystem();
system.init();

ready = true;

} catch (UnsatisfiedLinkError e) {
// ignore - it is already loaded
LOG.debug("Library already loaded");
} catch (CaptureException e) {
LOG.error("Capture exception", e);
throw new WebcamException(e);
}
}

protected static CaptureSystem getCaptureSystem() {
if (!initialized) {
initialize();
}
initialize();
return system;
}

@Override
public List<WebcamDevice> getDevices() {

if (!initialized) {
initialize();
}
initialize();

int i = 0;
while (!ready) {

if (devices == null) {
devices = new ArrayList<WebcamDevice>();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
return null;
}

@SuppressWarnings("unchecked")
List<CaptureDeviceInfo> infos = system.getCaptureDeviceInfoList();
// wait max 10 seconds for driver to be ready
if (i++ > 100) {
throw new RuntimeException("Cannot get devices because capture driver has not become ready for 10 seconds");
}
}

List<WebcamDevice> devices = new ArrayList<WebcamDevice>();

for (CaptureDeviceInfo cdi : infos) {
devices.add(new LtiCivilDevice(cdi));
}
} catch (CaptureException e) {
e.printStackTrace();
try {
for (Object cdi : system.getCaptureDeviceInfoList()) {
devices.add(new LtiCivilDevice((CaptureDeviceInfo) cdi));
}
} catch (CaptureException e) {
throw new WebcamException(e);
}

return devices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public void run() {
}
}

private LtiCivilLoader() {
// singleton
}

/**
* Copy bytes from a large (over 2GB) InputStream to an OutputStream.
*
Expand All @@ -49,7 +53,7 @@ public void run() {
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
*/
public static long copy(InputStream input, OutputStream output) throws IOException {
private static long copy(InputStream input, OutputStream output) throws IOException {
byte[] buffer = new byte[1024 * 4];
long count = 0;
int n = 0;
Expand All @@ -60,22 +64,22 @@ public static long copy(InputStream input, OutputStream output) throws IOExcepti
return count;
}

public static void load(String lib) {
protected static void load(String lib) {
LOG.info("Loading native library: " + lib);
try {
System.loadLibrary(lib);
LOG.info("DLL has been loaded from memory: " + lib);
} catch (UnsatisfiedLinkError e) {
try {
load("webcam-capture-lib-" + System.currentTimeMillis(), lib);
load("civil-" + System.currentTimeMillis(), lib);
} catch (Exception e2) {
LOG.error("Exception when loading DLL library", e2);
throw new RuntimeException(e2);
}
}
}

public static void load(String path, String name) {
protected static void load(String path, String name) {

String libroot = "/META-INF/lib";
String libpath = null;
Expand All @@ -85,15 +89,10 @@ public static void load(String path, String name) {
boolean linux = System.getProperty("os.name").toLowerCase().indexOf("linux") != -1;

if (linux) {
if (arch64) {
libpath = libroot + "/linux64/";
libfile = "lib" + name + ".so";
} else {
libpath = libroot + "/linux32/";
libfile = "lib" + name + ".so";
}
libpath = libroot + (arch64 ? "/linux64/" : "/linux32/");
libfile = "lib" + name + ".so";
} else {
libpath = libroot + "/win32/";
libpath = libroot + (arch64 ? "/win64/" : "/win32/");
libfile = name + ".dll";
}

Expand Down Expand Up @@ -122,6 +121,8 @@ public static void load(String path, String name) {

String resource = libpath + libfile;

LOG.debug("Library resource in JAR is {}", resource);

InputStream in = LtiCivilDriver.class.getResourceAsStream(resource);
if (in == null) {
throw new RuntimeException("Resource not found: " + resource);
Expand Down Expand Up @@ -153,6 +154,8 @@ public static void load(String path, String name) {
}
}

LOG.debug("Loading library from file {}", file);

try {
System.load(file.getAbsolutePath());
} catch (UnsatisfiedLinkError e) {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e8278d2

Please sign in to comment.