Skip to content

Commit

Permalink
Move some common files to main project
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jun 18, 2014
1 parent e8278d2 commit 4e5cd76
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -113,8 +113,7 @@ public List<WebcamDevice> 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 {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -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.
*/
Expand All @@ -48,7 +43,7 @@ public class V4l4jDriver implements WebcamDriver {
public List<WebcamDevice> getDevices() {

List<WebcamDevice> devices = new ArrayList<WebcamDevice>();
File[] vfiles = VIDEO_FILE_FILTER.getVideoFiles();
File[] vfiles = NixVideoDevUtils.getVideoFiles();

if (LOG.isDebugEnabled()) {
for (File vfile : vfiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand Down Expand Up @@ -105,15 +105,15 @@ protected VlcjDevice(MediaListItem item) {
}

public String getCaptureDevice() {
switch (OS.getOS()) {
switch (OsUtils.getOS()) {
case WIN:
return "dshow://";
case OSX:
return "qtcapture://";
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());
}
}

Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.sarxos.webcam.ds.vlcj.impl;
package com.github.sarxos.webcam.util;

/**
* Just a simple enumeration with supported (not yet confirmed) operating
* systems.
*
* @author Bartosz Firyn (sarxos)
*/
public enum OS {
public enum OsUtils {

/**
* Microsoft Windows
Expand All @@ -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) {
Expand Down

0 comments on commit 4e5cd76

Please sign in to comment.