Skip to content

Commit

Permalink
Merge 9fb344c into 5874815
Browse files Browse the repository at this point in the history
  • Loading branch information
tirz committed Jul 20, 2019
2 parents 5874815 + 9fb344c commit 1818498
Show file tree
Hide file tree
Showing 92 changed files with 332 additions and 416 deletions.
8 changes: 8 additions & 0 deletions webcam-capture-drivers/driver-ffmpeg-cli/pom.xml
Expand Up @@ -45,6 +45,14 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Expand Up @@ -8,6 +8,7 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -30,8 +31,8 @@ public class FFmpegCliDevice implements WebcamDevice, WebcamDevice.BufferAccess
private Dimension[] resolutions = null;
private Dimension resolution = null;

private AtomicBoolean open = new AtomicBoolean(false);
private AtomicBoolean disposed = new AtomicBoolean(false);
private final AtomicBoolean open = new AtomicBoolean(false);
private final AtomicBoolean disposed = new AtomicBoolean(false);

protected FFmpegCliDevice(String path, File vfile, String resolutions) {
this(path, vfile.getAbsolutePath(), resolutions);
Expand Down Expand Up @@ -108,7 +109,7 @@ private Dimension[] readResolutions(String res) {
resolutions.add(new Dimension(Integer.parseInt(xy[0]), Integer.parseInt(xy[1])));
}

return resolutions.toArray(new Dimension[resolutions.size()]);
return resolutions.toArray(new Dimension[0]);
}

@Override
Expand Down
Expand Up @@ -71,7 +71,7 @@ private List<WebcamDevice> getUnixDevices() {

try {
while ((line = br.readLine()) != null) {
if (line.startsWith(STARTER) && line.indexOf(MARKER) != -1) {
if (line.startsWith(STARTER) && line.contains(MARKER)) {
LOG.debug("Command stdout line: {}", line);
String resolutions = line.split(" : ")[3].trim();
devices.add(new FFmpegCliDevice(path, vfile, resolutions));
Expand Down Expand Up @@ -131,7 +131,7 @@ private WebcamDevice buildWindowsDevice(String deviceName) {
br = new BufferedReader(new InputStreamReader(is));

while ((line = br.readLine()) != null) {
if (line.startsWith(STARTER) && line.indexOf(MARKER) != -1) {
if (line.startsWith(STARTER) && line.contains(MARKER)) {
int begin = line.indexOf(MARKER) + MARKER.length();
String resolution = line.substring(begin, line.indexOf(" ", begin));
resolutions.add(resolution);
Expand Down Expand Up @@ -177,19 +177,19 @@ private List<String> getWindowsDevicesNames() {
br = new BufferedReader(new InputStreamReader(is));

while ((line = br.readLine()) != null) {
if (line.startsWith(STARTER) && line.indexOf(VIDEO_MARKER) != -1) {
if (line.startsWith(STARTER) && line.contains(VIDEO_MARKER)) {
startDevices = true;
continue;
}
if (startDevices) {
if (line.startsWith(STARTER) && line.indexOf(NAME_MARKER) != -1) {
if (line.startsWith(STARTER) && line.contains(NAME_MARKER)) {
String deviceName = line.substring(line.indexOf(NAME_MARKER) + NAME_MARKER.length());
// Remove final double quotes
deviceName = deviceName.substring(0, deviceName.length() - 1);
devicesNames.add(deviceName);
continue;
}
if (line.startsWith(STARTER) && line.indexOf(AUDIO_MARKER) != -1) {
if (line.startsWith(STARTER) && line.contains(AUDIO_MARKER)) {
break;
}
}
Expand Down
Expand Up @@ -105,11 +105,11 @@ public void run() {
private Dimension resolution = null;
private Process process = null;
private File pipe = null;
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
private DataInputStream dis = null;

private AtomicBoolean open = new AtomicBoolean(false);
private AtomicBoolean disposed = new AtomicBoolean(false);
private final AtomicBoolean open = new AtomicBoolean(false);
private final AtomicBoolean disposed = new AtomicBoolean(false);

private String logFilePathString;
private int frames = 1;
Expand Down Expand Up @@ -288,7 +288,7 @@ private void executeFsWebcamProcess() throws IOException {
c.add(pipe.getAbsolutePath()); // output file (pipe)
//@formatter:on

String[] cmd = c.toArray(new String[c.size()]);
String[] cmd = c.toArray(new String[0]);

if (LOG.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
Expand Down
Expand Up @@ -111,11 +111,10 @@ public void open() {

final String name = getName();
final Dimension resolution = getResolution();
final String str = new StringBuilder(MIME_VIDEO_X_RAW)
.append(",")
.append("width=").append(resolution.width).append(",")
.append("height").append(resolution.height)
.toString();
final String str = MIME_VIDEO_X_RAW +
"," +
"width=" + resolution.width + "," +
"height" + resolution.height;
final Caps caps = Caps.fromString(str);

LOG.debug("Opening device {} with caps {}", name, caps);
Expand Down
Expand Up @@ -56,7 +56,7 @@ public Gst1Driver() {
}
}

private static final void init() {
private static void init() {
String[] args = new String[] {};
Gst.init(Gst1Driver.class.getSimpleName(), args);
Runtime.getRuntime().addShutdownHook(new GStreamerShutdownHook());
Expand Down
Expand Up @@ -12,6 +12,7 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import org.bridj.Platform;
import org.gstreamer.Caps;
Expand Down Expand Up @@ -75,10 +76,10 @@ public class GStreamerDevice implements WebcamDevice, RGBDataSink.Listener, Webc

/* logic */

private AtomicBoolean open = new AtomicBoolean(false);
private AtomicBoolean disposed = new AtomicBoolean(false);
private AtomicBoolean starting = new AtomicBoolean(false);
private AtomicBoolean initialized = new AtomicBoolean(false);
private final AtomicBoolean open = new AtomicBoolean(false);
private final AtomicBoolean disposed = new AtomicBoolean(false);
private final AtomicBoolean starting = new AtomicBoolean(false);
private final AtomicBoolean initialized = new AtomicBoolean(false);
private Dimension resolution = WebcamResolution.VGA.getSize();
private BufferedImage image = null;

Expand All @@ -87,7 +88,7 @@ public class GStreamerDevice implements WebcamDevice, RGBDataSink.Listener, Webc
private long t1 = -1;
private long t2 = -1;

private volatile double fps = 0;
private final AtomicReference<Double> fps = new AtomicReference<Double>(0.0);

/**
* Create GStreamer webcam device.
Expand Down Expand Up @@ -409,12 +410,12 @@ public void rgbFrame(boolean preroll, int width, int height, IntBuffer rgb) {
t1 = t2;
t2 = System.currentTimeMillis();

fps = (4 * fps + 1000 / (t2 - t1 + 1)) / 5;
fps.set((4 * fps.get() + 1000 / (t2 - t1 + 1)) / 5);
}

@Override
public double getFPS() {
return fps;
return fps.get();
}

public Pipeline getPipe() {
Expand Down
Expand Up @@ -55,7 +55,7 @@ public GStreamerDriver(final List<String> preferredFormats) {
setPreferredFormats(preferredFormats);
}

private static final void init() {
private static void init() {

if (!INITIALIZED.compareAndSet(false, true)) {
return;
Expand All @@ -75,7 +75,7 @@ private static final void init() {

for (String p : path.split(";")) {
LOG.trace("Search %PATH% for gstreamer bin {}", p);
if (p.indexOf("GStreamer\\v0.10.") != -1) {
if (p.contains("GStreamer\\v0.10.")) {
gpath = p;
break;
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicReference;

import javax.imageio.ImageIO;

Expand Down Expand Up @@ -69,7 +70,7 @@ private final class PushImageReader extends Thread implements ImageReader {
private volatile boolean running = true;
private volatile BufferedImage image = null;
private BufferedImage tmp;
private volatile double fps = 0;
private final AtomicReference<Double> fps = new AtomicReference<Double>(0.0);

public PushImageReader(final URI uri) {
this.uri = uri;
Expand Down Expand Up @@ -98,7 +99,7 @@ public void run() {
image = tmp;
}
t2 = System.currentTimeMillis();
fps = (double) 1000 / (t2 - t1 + 1);
fps.set((double) 1000 / (t2 - t1 + 1));
} while (running && !stream.isClosed());
} catch (IOException e) {
if (e instanceof EOFException) { // EOF, ignore error and recreate stream
Expand All @@ -124,7 +125,7 @@ public void halt() {

@Override
public double getFPS() {
return fps;
return fps.get();
}
}

Expand All @@ -138,7 +139,7 @@ public PullImageReader(final URI uri) {
}

@Override
public BufferedImage readImage() throws InterruptedException {
public BufferedImage readImage() {

long t1;
long t2;
Expand Down Expand Up @@ -219,7 +220,7 @@ public IpCamDevice(String name, URL url, IpCamMode mode, IpCamAuth auth) {

}

protected static final URL toURL(String url) {
protected static URL toURL(String url) {
if (!url.startsWith("http://")) {
url = "http://" + url;
}
Expand All @@ -230,7 +231,7 @@ protected static final URL toURL(String url) {
}
}

private static final URI toURI(URL url) {
private static URI toURI(URL url) {
try {
return url.toURI();
} catch (URISyntaxException e) {
Expand Down
Expand Up @@ -86,13 +86,11 @@ public static boolean isRegistered(IpCamDevice ipcam) {
throw new IllegalArgumentException("IP camera device cannot be null");
}

Iterator<IpCamDevice> di = DEVICES.iterator();
while (di.hasNext()) {
if (di.next().getName().equals(ipcam.getName())) {
for (final IpCamDevice device : DEVICES) {
if (device.getName().equals(ipcam.getName())) {
return true;
}
}

return false;
}

Expand All @@ -108,13 +106,11 @@ public static boolean isRegistered(String name) {
throw new IllegalArgumentException("Device name cannot be null");
}

Iterator<IpCamDevice> di = DEVICES.iterator();
while (di.hasNext()) {
if (di.next().getName().equals(name)) {
for (final IpCamDevice device : DEVICES) {
if (device.getName().equals(name)) {
return true;
}
}

return false;
}

Expand Down
Expand Up @@ -40,7 +40,7 @@ private static class DeviceCheckThreadFactory implements ThreadFactory {
/**
* Next number for created thread.
*/
private AtomicInteger number = new AtomicInteger();
private final AtomicInteger number = new AtomicInteger();

@Override
public Thread newThread(Runnable r) {
Expand Down Expand Up @@ -88,7 +88,7 @@ public DeviceOnlineCheck(IpCamDevice device, CountDownLatch latch) {
}

@Override
public IpCamDevice call() throws Exception {
public IpCamDevice call() {
try {
return device.isOnline() ? device : null;
} finally {
Expand Down
Expand Up @@ -113,17 +113,17 @@ public void test_isRegisteredURI() throws MalformedURLException, URISyntaxExcept
}

@Test(expected = IllegalArgumentException.class)
public void test_isRegisteredURIIllegal() throws MalformedURLException, URISyntaxException {
public void test_isRegisteredURIIllegal() {
Assert.assertTrue(IpCamDeviceRegistry.isRegistered((URI) null));
}

@Test(expected = IllegalArgumentException.class)
public void test_isRegisteredURLIllegal() throws MalformedURLException, URISyntaxException {
public void test_isRegisteredURLIllegal() {
Assert.assertTrue(IpCamDeviceRegistry.isRegistered((URL) null));
}

@Test(expected = IllegalArgumentException.class)
public void test_isRegisteredDeviceIllegal() throws MalformedURLException, URISyntaxException {
public void test_isRegisteredDeviceIllegal() {
Assert.assertTrue(IpCamDeviceRegistry.isRegistered((IpCamDevice) null));
}
}
Expand Up @@ -125,7 +125,7 @@ public void controllerUpdate(ControllerEvent ce) {
private volatile boolean disposed = false;

private PlayerStarter starter = null;
private Semaphore semaphore = new Semaphore(0, true);
private final Semaphore semaphore = new Semaphore(0, true);

private CaptureDeviceInfo cdi = null;
private List<Dimension> dimensions = null;
Expand Down Expand Up @@ -252,18 +252,12 @@ public Dimension[] getResolutions() {
public int compare(Dimension a, Dimension b) {
int apx = a.width * a.height;
int bpx = b.width * b.height;
if (apx > bpx) {
return 1;
} else if (apx < bpx) {
return -1;
} else {
return 0;
}
return Integer.compare(apx, bpx);
}
});
}

return dimensions.toArray(new Dimension[dimensions.size()]);
return dimensions.toArray(new Dimension[0]);
}

@Override
Expand Down
@@ -1,7 +1,6 @@
package com.github.sarxos.webcam.ds.jmf;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

Expand All @@ -25,11 +24,9 @@ public List<WebcamDevice> getDevices() {
devices = new ArrayList<WebcamDevice>();

@SuppressWarnings("unchecked")
Vector<Object> cdis = CaptureDeviceManager.getDeviceList(new Format("RGB"));
Iterator<Object> di = cdis.iterator();
Vector<CaptureDeviceInfo> cdis = CaptureDeviceManager.getDeviceList(new Format("RGB"));

while (di.hasNext()) {
CaptureDeviceInfo cdi = (CaptureDeviceInfo) di.next();
for (final CaptureDeviceInfo cdi : cdis) {
devices.add(new JmfDevice(cdi));
}
}
Expand Down

0 comments on commit 1818498

Please sign in to comment.