From 4e5cd763b58d29929c0b46c17f9c0948d0741fee Mon Sep 17 00:00:00 2001 From: Bartosz Firyn Date: Wed, 18 Jun 2014 22:28:30 +0000 Subject: [PATCH] Move some common files to main project --- .../webcam/ds/gstreamer/GStreamerDriver.java | 5 ++- .../impl/VideoDeviceFilenameFilter.java | 28 --------------- .../impl/VideoDeviceFilenameFilterTest.java | 36 ------------------- .../sarxos/webcam/ds/v4l4j/V4l4jDriver.java | 9 ++--- .../sarxos/webcam/ds/vlcj/VlcjDevice.java | 8 ++--- .../sarxos/webcam/ds/vlcj/VlcjDriver.java | 4 +-- .../sarxos/webcam/util/NixVideoDevUtils.java | 10 +++--- .../github/sarxos/webcam/util/OsUtils.java | 8 ++--- 8 files changed, 19 insertions(+), 89 deletions(-) delete mode 100644 webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilter.java delete mode 100644 webcam-capture-drivers/driver-gstreamer/src/test/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilterTest.java rename webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/impl/VideoDeviceFilenameFilter.java => webcam-capture/src/main/java/com/github/sarxos/webcam/util/NixVideoDevUtils.java (60%) rename webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/impl/OS.java => webcam-capture/src/main/java/com/github/sarxos/webcam/util/OsUtils.java (82%) diff --git a/webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/GStreamerDriver.java b/webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/GStreamerDriver.java index 5aef7af5..37559174 100644 --- a/webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/GStreamerDriver.java +++ b/webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/GStreamerDriver.java @@ -15,7 +15,7 @@ import com.github.sarxos.webcam.WebcamDevice; import com.github.sarxos.webcam.WebcamDriver; import com.github.sarxos.webcam.WebcamException; -import com.github.sarxos.webcam.ds.gstreamer.impl.VideoDeviceFilenameFilter; +import com.github.sarxos.webcam.util.NixVideoDevUtils; import com.sun.jna.NativeLibrary; import com.sun.jna.Platform; @@ -113,8 +113,7 @@ public List getDevices() { devices.add(new GStreamerDevice(name.toString())); } } else if (Platform.isLinux()) { - VideoDeviceFilenameFilter vfilter = new VideoDeviceFilenameFilter(); - for (File vfile : vfilter.getVideoFiles()) { + for (File vfile : NixVideoDevUtils.getVideoFiles()) { devices.add(new GStreamerDevice(vfile)); } } else { diff --git a/webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilter.java b/webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilter.java deleted file mode 100644 index 1889cc91..00000000 --- a/webcam-capture-drivers/driver-gstreamer/src/main/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilter.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.sarxos.webcam.ds.gstreamer.impl; - -import java.io.File; -import java.io.FilenameFilter; - - -public class VideoDeviceFilenameFilter implements FilenameFilter { - - private static final File DEV = new File("/dev"); - - @Override - public boolean accept(File dir, String name) { - return dir.getName().equals("dev") && name.startsWith("video") - && (name.length() > 5 && Character.isDigit(name.charAt(5))); - } - - public File[] getVideoFiles() { - - String[] names = DEV.list(this); - File[] files = new File[names.length]; - - for (int i = 0; i < names.length; i++) { - files[i] = new File(DEV, names[i]); - } - - return files; - } -} diff --git a/webcam-capture-drivers/driver-gstreamer/src/test/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilterTest.java b/webcam-capture-drivers/driver-gstreamer/src/test/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilterTest.java deleted file mode 100644 index 6e5ae4cf..00000000 --- a/webcam-capture-drivers/driver-gstreamer/src/test/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilterTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.sarxos.webcam.ds.gstreamer.impl; - -import org.junit.Test; - -import java.io.File; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * @author Dan Rollo - * Date: 3/8/14 - * Time: 10:44 PM - */ -public class VideoDeviceFilenameFilterTest { - - /** - * Accept method was failing with exception: String index out of range: 5 - * This occurs on opensuse 11 where video device files do not all have a suffix. The files are created like so: - * $ ls -l /dev/video* - * /dev/video -> video0 - * /dev/video0 - * - * In this case, the link name 'video' is less that 6 characters long, so the filter statement: - * Character.isDigit(name.charAt(5)) - * causes the exception. - * - * Fix is to also check for length before checking for isDigit(). - */ - @Test - public void testAcceptHandlesShortVideoDeviceFilename() { - final VideoDeviceFilenameFilter videoDeviceFilenameFilter = new VideoDeviceFilenameFilter(); - assertFalse(videoDeviceFilenameFilter.accept(new File("/dev"), "video")); - assertTrue(videoDeviceFilenameFilter.accept(new File("/dev"), "video0")); - } -} diff --git a/webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/V4l4jDriver.java b/webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/V4l4jDriver.java index 89597127..c249550e 100644 --- a/webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/V4l4jDriver.java +++ b/webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/V4l4jDriver.java @@ -11,7 +11,7 @@ import com.github.sarxos.webcam.WebcamDevice; import com.github.sarxos.webcam.WebcamDriver; -import com.github.sarxos.webcam.ds.v4l4j.impl.VideoDeviceFilenameFilter; +import com.github.sarxos.webcam.util.NixVideoDevUtils; /** @@ -27,11 +27,6 @@ public class V4l4jDriver implements WebcamDriver { */ private static final Logger LOG = LoggerFactory.getLogger(V4l4jDriver.class); - /** - * File filter used to find /dev/videoN files. - */ - private static final VideoDeviceFilenameFilter VIDEO_FILE_FILTER = new VideoDeviceFilenameFilter(); - /** * Initialize customized V4L4J libraries. */ @@ -48,7 +43,7 @@ public class V4l4jDriver implements WebcamDriver { public List getDevices() { List devices = new ArrayList(); - File[] vfiles = VIDEO_FILE_FILTER.getVideoFiles(); + File[] vfiles = NixVideoDevUtils.getVideoFiles(); if (LOG.isDebugEnabled()) { for (File vfile : vfiles) { diff --git a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDevice.java b/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDevice.java index a3d2ae44..e4264604 100644 --- a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDevice.java +++ b/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDevice.java @@ -14,7 +14,7 @@ import com.github.sarxos.webcam.WebcamDevice; import com.github.sarxos.webcam.WebcamException; import com.github.sarxos.webcam.WebcamResolution; -import com.github.sarxos.webcam.ds.vlcj.impl.OS; +import com.github.sarxos.webcam.util.OsUtils; /** @@ -105,7 +105,7 @@ protected VlcjDevice(MediaListItem item) { } public String getCaptureDevice() { - switch (OS.getOS()) { + switch (OsUtils.getOS()) { case WIN: return "dshow://"; case OSX: @@ -113,7 +113,7 @@ public String getCaptureDevice() { case NIX: return "v4l2://"; default: - throw new RuntimeException("Capture device not supported on " + OS.getOS()); + throw new RuntimeException("Capture device not supported on " + OsUtils.getOS()); } } @@ -189,7 +189,7 @@ public synchronized void open() { String[] options = null; - switch (OS.getOS()) { + switch (OsUtils.getOS()) { case WIN: options = new String[] { ":dshow-vdev=" + getName(), diff --git a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java b/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java index 0f930032..fc737087 100644 --- a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java +++ b/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java @@ -14,7 +14,7 @@ import com.github.sarxos.webcam.WebcamDevice; import com.github.sarxos.webcam.WebcamDiscoverySupport; import com.github.sarxos.webcam.WebcamDriver; -import com.github.sarxos.webcam.ds.vlcj.impl.OS; +import com.github.sarxos.webcam.util.OsUtils; import com.sun.jna.Native; @@ -43,7 +43,7 @@ public class VlcjDriver implements WebcamDriver, WebcamDiscoverySupport { private long scanInterval = -1; public VlcjDriver() { - if (OS.getOS() == OS.WIN) { + if (OsUtils.getOS() == OsUtils.WIN) { System.err.println(String.format("WARNING: %s does not support Windows platform", getClass().getSimpleName())); } initialize(); diff --git a/webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/impl/VideoDeviceFilenameFilter.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/util/NixVideoDevUtils.java similarity index 60% rename from webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/impl/VideoDeviceFilenameFilter.java rename to webcam-capture/src/main/java/com/github/sarxos/webcam/util/NixVideoDevUtils.java index 98711329..0bb65611 100644 --- a/webcam-capture-drivers/driver-v4l4j/src/main/java/com/github/sarxos/webcam/ds/v4l4j/impl/VideoDeviceFilenameFilter.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/util/NixVideoDevUtils.java @@ -1,21 +1,21 @@ -package com.github.sarxos.webcam.ds.v4l4j.impl; +package com.github.sarxos.webcam.util; import java.io.File; import java.io.FilenameFilter; -public class VideoDeviceFilenameFilter implements FilenameFilter { +public class NixVideoDevUtils implements FilenameFilter { private static final File DEV = new File("/dev"); @Override public boolean accept(File dir, String name) { - return dir.getName().equals("dev") && name.startsWith("video") && Character.isDigit(name.charAt(5)); + return dir.getName().equals("dev") && name.startsWith("video") && (name.length() > 5 && Character.isDigit(name.charAt(5))); } - public File[] getVideoFiles() { + public static File[] getVideoFiles() { - String[] names = DEV.list(this); + String[] names = DEV.list(new NixVideoDevUtils()); File[] files = new File[names.length]; for (int i = 0; i < names.length; i++) { diff --git a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/impl/OS.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/util/OsUtils.java similarity index 82% rename from webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/impl/OS.java rename to webcam-capture/src/main/java/com/github/sarxos/webcam/util/OsUtils.java index 769ebf9b..a215d634 100644 --- a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/impl/OS.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/util/OsUtils.java @@ -1,4 +1,4 @@ -package com.github.sarxos.webcam.ds.vlcj.impl; +package com.github.sarxos.webcam.util; /** * Just a simple enumeration with supported (not yet confirmed) operating @@ -6,7 +6,7 @@ * * @author Bartosz Firyn (sarxos) */ -public enum OS { +public enum OsUtils { /** * Microsoft Windows @@ -23,14 +23,14 @@ public enum OS { */ OSX; - private static OS os = null; + private static OsUtils os = null; /** * Get operating system. * * @return OS */ - public static final OS getOS() { + public static final OsUtils getOS() { if (os == null) { String osp = System.getProperty("os.name").toLowerCase(); if (osp.indexOf("win") >= 0) {