001package com.github.sarxos.webcam.ds.v4l4j;
002
003import java.io.File;
004import java.util.ArrayList;
005import java.util.List;
006
007import org.slf4j.Logger;
008import org.slf4j.LoggerFactory;
009
010import au.edu.jcu.v4l4j.V4L4J;
011
012import com.github.sarxos.webcam.WebcamDevice;
013import com.github.sarxos.webcam.WebcamDriver;
014import com.github.sarxos.webcam.util.NixVideoDevUtils;
015
016
017/**
018 * Capture driver for V4L4J framework. For more details on V4L4J please check <a
019 * href="http://code.google.com/p/v4l4j">http://code.google.com/p/v4l4j</a>
020 * 
021 * @author Bartosz Firyn (sarxos)
022 */
023public class V4l4jDriver implements WebcamDriver {
024
025        /**
026         * Logger.
027         */
028        private static final Logger LOG = LoggerFactory.getLogger(V4l4jDriver.class);
029
030        /**
031         * Initialize customized V4L4J libraries.
032         */
033        static {
034                try {
035                        Class.forName("au.edu.jcu.v4l4j.V4L4J");
036                        V4L4J.init();
037                } catch (ClassNotFoundException e) {
038                        LOG.warn("Modified V4L4J has not been found in classpath");
039                }
040        }
041
042        @Override
043        public List<WebcamDevice> getDevices() {
044
045                List<WebcamDevice> devices = new ArrayList<WebcamDevice>();
046                File[] vfiles = NixVideoDevUtils.getVideoFiles();
047
048                if (LOG.isDebugEnabled()) {
049                        for (File vfile : vfiles) {
050                                LOG.debug("Video file detected {}", vfile);
051                        }
052                }
053
054                for (File vfile : vfiles) {
055                        devices.add(new V4l4jDevice(vfile));
056                }
057
058                return devices;
059        }
060
061        @Override
062        public boolean isThreadSafe() {
063                return false;
064        }
065
066        @Override
067        public String toString() {
068                return getClass().getSimpleName();
069        }
070}