diff --git a/webcam-capture-driver-openimaj/pom.xml b/webcam-capture-driver-openimaj/pom.xml index 5953bf20..eedeaa26 100644 --- a/webcam-capture-driver-openimaj/pom.xml +++ b/webcam-capture-driver-openimaj/pom.xml @@ -40,7 +40,7 @@ org.openimaj core-video-capture - 1.0.5 + 1.0.6-x diff --git a/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDevice.java b/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDevice.java index 8e43c42a..69c8ccd2 100644 --- a/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDevice.java +++ b/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDevice.java @@ -4,12 +4,11 @@ import java.awt.image.BufferedImage; import org.openimaj.image.ImageUtilities; -import org.openimaj.video.capture.Device; -import org.openimaj.video.capture.VideoCapture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.sarxos.webcam.WebcamDevice; +import com.github.sarxos.webcam.ds.buildin.natives.Device; public class OpenImajDevice implements WebcamDevice { @@ -20,7 +19,7 @@ public class OpenImajDevice implements WebcamDevice { * Artificial view sizes. I'm really not sure if will fit into other webcams * but hope that OpenIMAJ can handle this. */ - private final static Dimension[] dimensions = new Dimension[] { + private final static Dimension[] DIMENSIONS = new Dimension[] { new Dimension(176, 144), new Dimension(320, 240), new Dimension(352, 288), @@ -45,7 +44,7 @@ public String getName() { @Override public Dimension[] getSizes() { - return dimensions; + return DIMENSIONS; } @Override diff --git a/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDriver.java b/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDriver.java index e2c2cacd..6efbdb3c 100644 --- a/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDriver.java +++ b/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/OpenImajDriver.java @@ -1,22 +1,24 @@ package com.github.sarxos.webcam.ds.openimaj; -import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.imageio.ImageIO; - -import org.openimaj.video.capture.Device; -import org.openimaj.video.capture.VideoCapture; - -import com.github.sarxos.webcam.WebcamDriver; import com.github.sarxos.webcam.WebcamDevice; +import com.github.sarxos.webcam.WebcamDriver; +import com.github.sarxos.webcam.ds.buildin.natives.Device; +/** + * This is webcam driver for OpenIMAJ library. + * + * @author Bartosz Firyn (SarXos) + */ public class OpenImajDriver implements WebcamDriver { - List webcamDevices = null; + /** + * Cached webcams list. + */ + private static List webcamDevices = null; @Override public List getDevices() { @@ -32,15 +34,4 @@ public List getDevices() { return webcamDevices; } - public static void main(String[] args) throws IOException, InterruptedException { - WebcamDevice d = new OpenImajDriver().getDevices().get(0); - d.setSize(d.getSizes()[0]); - d.open(); - for (int i = 0; i < 5; i++) { - ImageIO.write(d.getImage(), "JPG", new File(System.currentTimeMillis() + ".jpg")); - Thread.sleep(1000); - } - - d.close(); - } } diff --git a/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/VideoCapture.java b/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/VideoCapture.java new file mode 100644 index 00000000..44019709 --- /dev/null +++ b/webcam-capture-driver-openimaj/src/main/java/com/github/sarxos/webcam/ds/openimaj/VideoCapture.java @@ -0,0 +1,372 @@ +/** + * Copyright (c) 2011, The University of Southampton and the individual contributors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the University of Southampton nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.github.sarxos.webcam.ds.openimaj; + +import java.io.IOException; +import java.util.List; + +import javax.swing.SwingUtilities; + +import org.bridj.Pointer; +import org.openimaj.image.ImageUtilities; +import org.openimaj.image.MBFImage; +import org.openimaj.image.colour.ColourSpace; +import org.openimaj.video.Video; +import org.openimaj.video.VideoDisplay; + +import com.github.sarxos.webcam.ds.buildin.natives.Device; +import com.github.sarxos.webcam.ds.buildin.natives.DeviceList; +import com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber; + + +/** + * VideoCapture is a type of {@link Video} that can capture live video streams + * from a webcam or other video device. + * + * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) + */ +public class VideoCapture extends Video { + + /** + * The property key for overriding the default device number. + */ + public static final String DEFAULT_DEVICE_NUMBER_PROPERTY = "openimaj.grabber.camera"; + + private OpenIMAJGrabber grabber; + private MBFImage frame; + private int width; + private int height; + private boolean isStopped = true; + private double fps = 25; + + /** + * Construct a VideoCapture instance with the requested width and height. + * The default video device will be used. The actual height and width of the + * captured frames may not equal the requested size if the underlying + * platform-specific grabber is not able to honor the request. The actual + * size can be inspected through the {@link #getWidth()} and + * {@link #getHeight()} methods. + *

+ * The default device is usually the first device listed by + * {@link #getVideoDevices()}, however this is down to the underlying native + * libraries and operating system. The + * {@link #DEFAULT_DEVICE_NUMBER_PROPERTY} system property allows the + * selection of the default device to be overridden. The property value can + * be an integer representing the index of the default device in the list + * produced by {@link #DEFAULT_DEVICE_NUMBER_PROPERTY} or a {@link String} + * that includes part of the device identifier. In the case of a String + * value, the device with the identifier that first contains the value is + * selected. + * + * @param width the requested video width + * @param height the requested video height + * @throws IOException if no webcam is found + */ + public VideoCapture(int width, int height) throws IOException { + // on 32 bit osx a deadlock seems to occur between the + // initialisation of the native library and AWT. This + // seems to fix it... + List devices = VideoCapture.getVideoDevices(); + + Device defaultDevice = null; + String defaultDeviceStr = System.getProperty(DEFAULT_DEVICE_NUMBER_PROPERTY); + if (defaultDeviceStr != null) { + try { + int i = Integer.parseInt(defaultDeviceStr); + + if (i >= 0 && i < devices.size()) { + defaultDevice = devices.get(i); + } else { + System.err.println("Warning: The " + DEFAULT_DEVICE_NUMBER_PROPERTY + " property setting is out of range (0..<" + devices.size() + ") and will be ignored."); + System.err.println("Valid devices are:"); + for (int x = 0; x < devices.size(); x++) + System.err.println(x + " : " + devices.get(x).getIdentifierStr()); + } + } catch (NumberFormatException e) { + for (Device d : devices) { + if (d.getIdentifierStr().contains(defaultDeviceStr)) { + defaultDevice = d; + break; + } + + if (defaultDevice == null) { + System.err.println("Warning: The device name given by the " + DEFAULT_DEVICE_NUMBER_PROPERTY + " property (" + defaultDeviceStr + ") setting was not found and has been ignored."); + System.err.println("Valid devices are:"); + for (int x = 0; x < devices.size(); x++) + System.err.println(x + " : " + devices.get(x).getIdentifierStr()); + } + } + } + } + + grabber = new OpenIMAJGrabber(); + + if (defaultDevice == null) { + if (!startSession(width, height, fps)) + throw new IOException("No webcams found!"); + } else { + startSession(width, height, 0, defaultDevice); + } + } + + /** + * Construct a VideoCapture instance with the requested width and height + * using the specified video device. The actual height and width of the + * captured frames may not equal the requested size if the underlying + * platform-specific grabber is not able to honor the request. The actual + * size can be inspected through the {@link #getWidth()} and + * {@link #getHeight()} methods. + * + * @param width the requested video width. + * @param height the requested video height. + * @param device the requested video device. + */ + public VideoCapture(int width, int height, Device device) { + grabber = new OpenIMAJGrabber(); + startSession(width, height, 0, device); + } + + /** + * Construct a VideoCapture instance with the requested width and height + * using the specified video device. The actual height and width of the + * captured frames may not equal the requested size if the underlying + * platform-specific grabber is not able to honor the request. The actual + * size can be inspected through the {@link #getWidth()} and + * {@link #getHeight()} methods. + * + * @param width the requested video width. + * @param height the requested video height. + * @param fps the requested frame rate + * @param device the requested video device. + */ + public VideoCapture(int width, int height, double fps, Device device) { + this.fps = fps; + grabber = new OpenIMAJGrabber(); + startSession(width, height, fps, device); + } + + /** + * Get a list of all compatible video devices attached to the machine. + * + * @return a list of devices. + */ + public static List getVideoDevices() { + OpenIMAJGrabber grabber = new OpenIMAJGrabber(); + DeviceList list = grabber.getVideoDevices().get(); + + return list.asArrayList(); + } + + protected synchronized boolean startSession(final int requestedWidth, final int requestedHeight, double requestedFPS, Device device) { + if (grabber.startSession(requestedWidth, requestedHeight, requestedFPS, Pointer.pointerTo(device))) { + width = grabber.getWidth(); + height = grabber.getHeight(); + frame = new MBFImage(width, height, ColourSpace.RGB); + + isStopped = false; + + return true; + } + return false; + } + + protected synchronized boolean startSession(int requestedWidth, int requestedHeight, double requestedFPS) { + if (grabber.startSession(requestedWidth, requestedHeight, requestedFPS)) { + width = grabber.getWidth(); + height = grabber.getHeight(); + frame = new MBFImage(width, height, ColourSpace.RGB); + + isStopped = false; + + return true; + } + return false; + } + + /** + * Stop the video capture system. Once stopped, it can only be started again + * by constructing a new instance of VideoCapture. + */ + public synchronized void stopCapture() { + isStopped = true; + grabber.stopSession(); + } + + @Override + public MBFImage getCurrentFrame() { + return frame; + } + + @Override + public synchronized MBFImage getNextFrame() { + if (isStopped) + return frame; + + System.out.println("------------------- GETTING FRAME"); + + grabber.nextFrame(); + + Pointer data = grabber.getImage(); + if (data == null) { + System.out.println("---------------NULL BUFFER--------------"); + return frame; + } + + final byte[] d = data.getBytes(width * height * 3); + final float[][] r = frame.bands.get(0).pixels; + final float[][] g = frame.bands.get(1).pixels; + final float[][] b = frame.bands.get(2).pixels; + + for (int i = 0, y = 0; y < height; y++) { + for (int x = 0; x < width; x++, i += 3) { + int red = d[i + 0] & 0xFF; + int green = d[i + 1] & 0xFF; + int blue = d[i + 2] & 0xFF; + r[y][x] = ImageUtilities.BYTE_TO_FLOAT_LUT[red]; + g[y][x] = ImageUtilities.BYTE_TO_FLOAT_LUT[green]; + b[y][x] = ImageUtilities.BYTE_TO_FLOAT_LUT[blue]; + } + } + + super.currentFrame++; + + return frame; + } + + @Override + public boolean hasNextFrame() { + return true; + } + + @Override + public long countFrames() { + return -1; + } + + /** + * Test main method. Lists the available devices, and then opens the first + * and second capture devices if they are available and displays their + * video. + * + * @param args ignored. + */ + public static void main(String[] args) { + List devices = VideoCapture.getVideoDevices(); + for (Device d : devices) + System.out.println(d); + + if (devices.size() == 1) { + VideoCapture grabber1 = new VideoCapture(640, 480, devices.get(0)); + VideoDisplay.createVideoDisplay(grabber1); + } else { + int w = 320; + int h = 240; + double rate = 10.0; + + for (int y = 0, i = 0; y < 3; y++) { + for (int x = 0; x < 3 && i < devices.size(); x++, i++) { + VideoCapture grabber2 = new VideoCapture(w, h, rate, devices.get(i)); + VideoDisplay disp = VideoDisplay.createVideoDisplay(grabber2); + SwingUtilities.getRoot(disp.getScreen()).setLocation(320 * x, 240 * y); + } + } + } + } + + /** + * {@inheritDoc} + * + * @see org.openimaj.video.Video#getWidth() + */ + @Override + public int getWidth() + { + return width; + } + + /** + * {@inheritDoc} + * + * @see org.openimaj.video.Video#getHeight() + */ + @Override + public int getHeight() + { + return height; + } + + @Override + public void reset() + { + stopCapture(); + startSession(width, height, fps); + } + + /** + * {@inheritDoc} + * + * @see org.openimaj.video.Video#getTimeStamp() + */ + @Override + public long getTimeStamp() + { + return (long) (super.currentFrame * 1000 / this.fps); + } + + /* + * (non-Javadoc) + * @see org.openimaj.video.Video#setCurrentFrameIndex(long) + */ + @Override + public void setCurrentFrameIndex(long newFrame) { + // do nothing + } + + /** + * {@inheritDoc} + * + * @see org.openimaj.video.Video#getFPS() + */ + @Override + public double getFPS() + { + return fps; + } + + /** + * Set the number of frames per second. + * + * @param fps The number of frames per second. + */ + public void setFPS(double fps) + { + this.fps = fps; + } +} diff --git a/webcam-capture/.classpath b/webcam-capture/.classpath index 575249a6..1a04f3e1 100644 --- a/webcam-capture/.classpath +++ b/webcam-capture/.classpath @@ -3,6 +3,7 @@ + diff --git a/webcam-capture/pom.xml b/webcam-capture/pom.xml index f5ac0aaf..251b1a75 100644 --- a/webcam-capture/pom.xml +++ b/webcam-capture/pom.xml @@ -18,6 +18,11 @@ filters 2.0.235 + + com.nativelibs4java + bridj + 0.6.1 + diff --git a/webcam-capture/src/example/java/com/github/sarxos/webcam/TakePictureExample.java b/webcam-capture/src/example/java/com/github/sarxos/webcam/TakePictureExample.java index 609aa3de..068ec4c0 100644 --- a/webcam-capture/src/example/java/com/github/sarxos/webcam/TakePictureExample.java +++ b/webcam-capture/src/example/java/com/github/sarxos/webcam/TakePictureExample.java @@ -8,13 +8,14 @@ /** + * Example of how to take single picture. + * * @author Bartosz Firyn (SarXos) */ public class TakePictureExample { public static void main(String[] args) throws IOException { - Webcam webcam = Webcam.getDefault(); - BufferedImage image = webcam.getImage(); + BufferedImage image = Webcam.getDefault().getImage(); ImageIO.write(image, "PNG", new File("test.png")); } } diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java index 89f94816..93818711 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java @@ -35,9 +35,10 @@ public void run() { } private static final String[] DRIVERS = new String[] { + "buildin.DefaultDriver", + "openimaj.OpenImajDriver", "civil.LtiCivilDriver", "jmf.JmfDriver", - "openimaj.OpenImajDriver", }; private static WebcamDriver driver = null; diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDriver.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDriver.java index bd702077..eba42778 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDriver.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamDriver.java @@ -3,8 +3,18 @@ import java.util.List; +/** + * This is interface for all webcam drivers. + * + * @author Bartosz Firyn (SarXos) + */ public interface WebcamDriver { + /** + * Return all registered webcam devices. + * + * @return List of webcam devices + */ public List getDevices(); } diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDevice.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDevice.java new file mode 100644 index 00000000..a68e82d9 --- /dev/null +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDevice.java @@ -0,0 +1,150 @@ +package com.github.sarxos.webcam.ds.buildin; + +import java.awt.Dimension; +import java.awt.Transparency; +import java.awt.color.ColorSpace; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.ComponentColorModel; +import java.awt.image.ComponentSampleModel; +import java.awt.image.DataBuffer; +import java.awt.image.DataBufferByte; +import java.awt.image.Raster; +import java.awt.image.WritableRaster; + +import org.bridj.Pointer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.github.sarxos.webcam.WebcamDevice; +import com.github.sarxos.webcam.WebcamException; +import com.github.sarxos.webcam.ds.buildin.natives.Device; +import com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber; + + +public class DefaultDevice implements WebcamDevice { + + private static final Logger LOG = LoggerFactory.getLogger(DefaultDevice.class); + + /** + * Artificial view sizes. I'm really not sure if will fit into other webcams + * but hope that OpenIMAJ can handle this. + */ + private final static Dimension[] DIMENSIONS = new Dimension[] { + new Dimension(176, 144), + new Dimension(320, 240), + new Dimension(352, 288), + new Dimension(640, 400), + new Dimension(640, 480), + }; + + private static final int[] BAND_OFFSETS = new int[] { 0, 1, 2 }; + private static final int[] BITS = { 8, 8, 8 }; + private static final int[] OFFSET = new int[] { 0 }; + private static final int DATA_TYPE = DataBuffer.TYPE_BYTE; + + private static final ColorSpace COLOR_SPACE = ColorSpace.getInstance(ColorSpace.CS_sRGB); + + private OpenIMAJGrabber grabber = null; + private Device device = null; + private Dimension size = null; + private ComponentSampleModel sampleModel = null; + private ColorModel colorModel = null; + private boolean open = false; + + protected DefaultDevice(Device device) { + this.device = device; + } + + @Override + public String getName() { + return device.getNameStr() + " " + device.getIdentifierStr(); + } + + @Override + public Dimension[] getSizes() { + return DIMENSIONS; + } + + @Override + public Dimension getSize() { + return size; + } + + @Override + public void setSize(Dimension size) { + this.size = size; + } + + @Override + public BufferedImage getImage() { + + if (!open) { + throw new WebcamException("Cannot get image when webcam device is not open"); + } + + Pointer image = grabber.getImage(); + if (image == null) { + return null; + } + + byte[] bytes = image.getBytes(size.width * size.height * 3); + byte[][] data = new byte[][] { bytes }; + + DataBufferByte buffer = new DataBufferByte(data, bytes.length, OFFSET); + WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null); + + return new BufferedImage(colorModel, raster, false, null); + } + + @Override + public void open() { + + if (open) { + return; + } + + grabber = new OpenIMAJGrabber(); + + boolean started = grabber.startSession(size.width, size.height, 0, Pointer.pointerTo(device)); + if (!started) { + throw new WebcamException("Cannot start video data grabber!"); + } + + int w1 = size.width; + int w2 = grabber.getWidth(); + int h1 = size.height; + int h2 = grabber.getHeight(); + + if (w1 != w2 || h1 != h2) { + LOG.warn("Different size obtained vs requested - [" + w1 + "x" + h1 + "] vs [" + w2 + "x" + h2 + "]. Setting correct one. New size is [" + w2 + "x" + h2 + "]"); + size = new Dimension(w2, h2); + } + + sampleModel = new ComponentSampleModel(DATA_TYPE, size.width, size.height, 3, size.width * 3, BAND_OFFSETS); + colorModel = new ComponentColorModel(COLOR_SPACE, BITS, false, false, Transparency.OPAQUE, DATA_TYPE); + + int i = 0; + do { + grabber.nextFrame(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } while (i++ < 3); + + open = true; + } + + @Override + public void close() { + + if (!open) { + return; + } + + grabber.stopSession(); + open = false; + } + +} diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDriver.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDriver.java new file mode 100644 index 00000000..a5963d9c --- /dev/null +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/DefaultDriver.java @@ -0,0 +1,52 @@ +package com.github.sarxos.webcam.ds.buildin; + +import java.util.ArrayList; +import java.util.List; + +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.ds.buildin.natives.Device; +import com.github.sarxos.webcam.ds.buildin.natives.DeviceList; +import com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber; + + +public class DefaultDriver implements WebcamDriver { + + private static final Logger LOG = LoggerFactory.getLogger(DefaultDriver.class); + + private static OpenIMAJGrabber grabber = null; + private static List devices = null; + + @Override + public List getDevices() { + + if (grabber == null) { + LOG.debug("Creating grabber"); + grabber = new OpenIMAJGrabber(); + } + + if (devices == null) { + + LOG.debug("Searching devices"); + + devices = new ArrayList(); + + DeviceList list = grabber.getVideoDevices().get(); + for (Device device : list.asArrayList()) { + devices.add(new DefaultDevice(device)); + } + + if (LOG.isDebugEnabled()) { + for (WebcamDevice device : devices) { + LOG.debug("Found device " + device); + } + } + } + + return devices; + } + +} diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/Device.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/Device.java new file mode 100644 index 00000000..074dbd4c --- /dev/null +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/Device.java @@ -0,0 +1,125 @@ +/** + * Copyright (c) 2011, The University of Southampton and the individual contributors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the University of Southampton nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.github.sarxos.webcam.ds.buildin.natives; + +import org.bridj.Pointer; +import org.bridj.ann.Field; +import org.bridj.ann.Library; +import org.bridj.ann.Runtime; +import org.bridj.cpp.CPPObject; +import org.bridj.cpp.CPPRuntime; + + +/** + * native declaration : line 1
+ * This file was autogenerated by JNAerator,
+ * a tool written by Olivier Chafik that + * uses a + * few opensource projects..
+ * For help, please visit NativeLibs4Java or BridJ . + */ +@Library("OpenIMAJGrabber") +@Runtime(CPPRuntime.class) +@SuppressWarnings("all") +public final class Device extends CPPObject { + + public Device() { + super(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public Device(Pointer pointer) { + super(pointer); + } + + // / C type : const char* + @Field(0) + protected Pointer name() { + return this.io.getPointerField(this, 0); + } + + // / C type : const char* + @Field(0) + protected Device name(Pointer name) { + this.io.setPointerField(this, 0, name); + return this; + } + + // / C type : const char* + @Field(1) + protected Pointer identifier() { + return this.io.getPointerField(this, 1); + } + + // / C type : const char* + @Field(1) + protected Device identifier(Pointer identifier) { + this.io.setPointerField(this, 1, identifier); + return this; + } + + protected native Pointer getName(); + + public String getNameStr() { + return getName().getCString(); + } + + protected native Pointer getIdentifier(); + + public String getIdentifierStr() { + return getIdentifier().getCString(); + } + + /* + * (non-Javadoc) + * @see org.bridj.NativeObject#equals(java.lang.Object) + */ + @Override + public boolean equals(Object o) { + return o.toString().equals(this.toString()); + } + + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.toString().hashCode(); + } + + @Override + public String toString() { + return String.format("Device[%s]=\"%s\"", getIdentifierStr(), getNameStr()); + } +} diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/DeviceList.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/DeviceList.java new file mode 100644 index 00000000..091eed02 --- /dev/null +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/DeviceList.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2011, The University of Southampton and the individual contributors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the University of Southampton nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.github.sarxos.webcam.ds.buildin.natives; + +import java.util.ArrayList; +import java.util.List; + +import org.bridj.Pointer; +import org.bridj.ann.Field; +import org.bridj.ann.Library; +import org.bridj.cpp.CPPObject; + + +/** + * native declaration : line 1
+ * This file was autogenerated by JNAerator,
+ * a tool written by Olivier Chafik that + * uses a + * few opensource projects..
+ * For help, please visit NativeLibs4Java or BridJ . + */ +@Library("OpenIMAJGrabber") +@SuppressWarnings("all") +public class DeviceList extends CPPObject { + + public DeviceList() { + super(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public DeviceList(Pointer pointer) { + super(pointer); + } + + @Field(0) + protected int nDevices() { + return this.io.getIntField(this, 0); + } + + @Field(0) + protected DeviceList nDevices(int nDevices) { + this.io.setIntField(this, 0, nDevices); + return this; + } + + // / C type : Device** + @Field(1) + protected Pointer> devices() { + return this.io.getPointerField(this, 1); + } + + // / C type : Device** + @Field(1) + protected DeviceList devices(Pointer> devices) { + this.io.setPointerField(this, 1, devices); + return this; + } + + public native int getNumDevices(); + + public native Pointer getDevice(int i); + + public List asArrayList() { + List devices = new ArrayList(); + + for (int i = 0; i < getNumDevices(); i++) { + devices.add(getDevice(i).get()); + } + + return devices; + } +} diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/OpenIMAJGrabber.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/OpenIMAJGrabber.java new file mode 100644 index 00000000..9b876846 --- /dev/null +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/ds/buildin/natives/OpenIMAJGrabber.java @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2011, The University of Southampton and the individual contributors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the University of Southampton nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.github.sarxos.webcam.ds.buildin.natives; + +import org.bridj.BridJ; +import org.bridj.Platform; +import org.bridj.Pointer; +import org.bridj.ann.Field; +import org.bridj.ann.Library; +import org.bridj.ann.Runtime; +import org.bridj.cpp.CPPObject; +import org.bridj.cpp.CPPRuntime; + + +/** + * native declaration : line 1
+ * This file was autogenerated by JNAerator,
+ * a tool written by Olivier Chafik that + * uses a + * few opensource projects..
+ * For help, please visit NativeLibs4Java or BridJ . + */ +@Library("OpenIMAJGrabber") +@Runtime(CPPRuntime.class) +@SuppressWarnings("all") +public class OpenIMAJGrabber extends CPPObject { + + static { + Platform.addEmbeddedLibraryResourceRoot("com/github/sarxos/webcam/ds/buildin/lib/"); + BridJ.register(); + } + + public OpenIMAJGrabber() { + super(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public OpenIMAJGrabber(Pointer pointer) { + super(pointer); + } + + public native Pointer getVideoDevices(); + + public native Pointer getImage(); + + public native void nextFrame(); + + public native boolean startSession(int width, int height, double reqFPS); + + public native boolean startSession(int width, int height, double reqFPS, Pointer devptr); + + public native void stopSession(); + + public native int getWidth(); + + public native int getHeight(); + + // / C type : void* + @Field(0) + protected Pointer data() { + return this.io.getPointerField(this, 0); + } + + // / C type : void* + @Field(0) + protected OpenIMAJGrabber data(Pointer data) { + this.io.setPointerField(this, 0, data); + return this; + } +} diff --git a/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/darwin_universal/libOpenIMAJGrabber.dylib b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/darwin_universal/libOpenIMAJGrabber.dylib new file mode 100644 index 00000000..784b7b98 Binary files /dev/null and b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/darwin_universal/libOpenIMAJGrabber.dylib differ diff --git a/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_arm32_arm/OpenIMAJGrabber.so b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_arm32_arm/OpenIMAJGrabber.so new file mode 100644 index 00000000..26d00da5 Binary files /dev/null and b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_arm32_arm/OpenIMAJGrabber.so differ diff --git a/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_x64/OpenIMAJGrabber.so b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_x64/OpenIMAJGrabber.so new file mode 100644 index 00000000..febaa188 Binary files /dev/null and b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_x64/OpenIMAJGrabber.so differ diff --git a/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_x86/OpenIMAJGrabber.so b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_x86/OpenIMAJGrabber.so new file mode 100644 index 00000000..92c12afb Binary files /dev/null and b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/linux_x86/OpenIMAJGrabber.so differ diff --git a/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/win32/OpenIMAJGrabber.dll b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/win32/OpenIMAJGrabber.dll new file mode 100644 index 00000000..376245be Binary files /dev/null and b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/win32/OpenIMAJGrabber.dll differ diff --git a/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/win64/OpenIMAJGrabber.dll b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/win64/OpenIMAJGrabber.dll new file mode 100644 index 00000000..d506c608 Binary files /dev/null and b/webcam-capture/src/main/resources/com/github/sarxos/webcam/ds/buildin/lib/win64/OpenIMAJGrabber.dll differ