Permalink
Browse files

V4L2 implementation using v4l4j.

  • Loading branch information...
1 parent a867e7a commit 8cc5ba625ee3f854e99bceece46f06f38588a5f4 @tonyg committed Sep 7, 2012
@@ -0,0 +1 @@
+v4l4j-0.9.0/
@@ -0,0 +1,4 @@
+#!/bin/sh
+LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`
+export LD_LIBRARY_PATH
+exec java -server -cp $(for d in *.jar; do echo -n "$d":; done) net.lshift.camcapture.v4l2.Main "$@"
@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+<project default="build">
+ <property name="build.out" location="build"/>
+ <property name="javah.out" location="${build.out}/javah"/>
+ <property name="lib.out" location="${build.out}/lib"/>
+ <property name="dist.out" location="${build.out}/dist"/>
+ <property name="javac.debug" value="true"/>
+ <property name="javac.source" value="1.5"/>
+ <property name="javac.target" value="1.5"/>
+ <property name="javac.out" location="${build.out}/classes"/>
+ <property name="v4l4j.tarball" location="v4l4j-0.9.0.tar.gz"/>
+ <property name="v4l4j.sourcedir" location="v4l4j-0.9.0"/>
+
+ <property name="rabbitmq.dist" value="../camcapturecommon/lib"/>
+
+ <property name="jdk_home" location="${java.home}/.."/>
+
+ <path id="javac.classpath">
+ <fileset dir="${rabbitmq.dist}">
+ <include name="rabbitmq-client-2.7.1.jar"/>
+ <include name="commons-io-1.2.jar"/>
+ </fileset>
+ <pathelement path="${javah.out}"/>
+ <fileset dir="${v4l4j.sourcedir}">
+ <include name="v4l4j.jar"/>
+ </fileset>
+ </path>
+
+ <path id="test.classpath">
+ <path refid="javac.classpath"/>
+ <pathelement path="${javac.out}"/>
+ </path>
+
+ <target name="v4l4j">
+ <untar src="${v4l4j.tarball}" dest="." compression="gzip"/>
+ <ant dir="${v4l4j.sourcedir}" target="all"/>
+ </target>
+
+ <target name="build" depends="v4l4j">
+ <mkdir dir="${javac.out}"/>
+ <javac destdir="${javac.out}"
+ classpathref="javac.classpath"
+ source="${javac.source}"
+ target="${javac.target}"
+ debug="${javac.debug}">
+ <src path="src"/>
+ <src path="../camcapturecommon/src"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="build">
+ <mkdir dir="${lib.out}"/>
+ <jar destfile="${lib.out}/camcapturelinux.jar" basedir="${javac.out}"/>
+ </target>
+
+ <target name="dist" depends="jar">
+ <mkdir dir="${dist.out}"/>
+ <copy todir="${dist.out}">
+ <fileset dir="${rabbitmq.dist}">
+ <include name="rabbitmq-client-2.7.1.jar"/>
+ <include name="commons-io-1.2.jar"/>
+ </fileset>
+ <fileset dir="${v4l4j.sourcedir}">
+ <include name="v4l4j.jar"/>
+ <include name="libv4l4j.so"/>
+ </fileset>
+ <fileset dir="${v4l4j.sourcedir}/libvideo">
+ <include name="libvideo.so.0"/>
+ </fileset>
+ <fileset dir="${lib.out}">
+ <include name="**/*.jar"/>
+ </fileset>
+ <fileset dir="bin"/>
+ <fileset dir="../licenses" includes="*"/>
+ </copy>
+ <exec dir="${dist.out}" executable="chmod">
+ <arg line="a+x"/>
+ <arg line="camcaptureLinux"/>
+ <arg line="libv4l4j.so"/>
+ <arg line="libvideo.so.0"/>
+ </exec>
+ </target>
+
+ <target name="sign-dist" depends="dist"/>
+
+ <target name="clean">
+ <delete dir="build"/>
+ <delete dir="${v4l4j.sourcedir}"/>
+ </target>
+</project>
@@ -0,0 +1,87 @@
+package net.lshift.camcapture.v4l2;
+
+import java.io.Console;
+import java.io.IOException;
+
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.Raster;
+import java.awt.image.WritableRaster;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+import au.edu.jcu.v4l4j.CaptureCallback;
+import au.edu.jcu.v4l4j.RGBFrameGrabber;
+import au.edu.jcu.v4l4j.VideoDevice;
+
+import au.edu.jcu.v4l4j.VideoFrame;
+import au.edu.jcu.v4l4j.exceptions.V4L4JException;
+import net.lshift.camcapture.CaptureBase;
+import net.lshift.camcapture.SwingUtil;
+
+public class Main extends CaptureBase {
+ public static void main(String[] args) {
+ try {
+ new Main(args);
+ } catch (Exception e) {
+ SwingUtil.complainFatal("Error", null, e);
+ }
+ }
+
+ public Main(String[] args)
+ throws Exception
+ {
+ super("camcapturev4l", args);
+ }
+
+ public java.util.Iterator buildFrameIterator(int desiredWidth,
+ int desiredHeight,
+ int targetFrameRate)
+ throws Exception
+ {
+ final BlockingQueue<VideoFrame> frames = new ArrayBlockingQueue<VideoFrame>(1);
+
+ VideoDevice d = new VideoDevice("/dev/video0");
+ System.out.println(d);
+
+ RGBFrameGrabber grabber = d.getRGBFrameGrabber(desiredWidth, desiredHeight, 0, 0);
+ grabber.setFrameInterval(1, targetFrameRate);
+ System.out.println("Number of buffered frames: " + grabber.getNumberOfVideoFrames());
+
+ grabber.setCaptureCallback(new CaptureCallback() {
+ @Override
+ public void nextFrame(VideoFrame frame) {
+ if (!frames.offer(frame)) {
+ frame.recycle();
+ }
+ }
+
+ @Override
+ public void exceptionReceived(V4L4JException e) {
+ e.printStackTrace();
+ System.exit(0);
+ }
+ });
+ grabber.startCapture();
+
+ return new java.util.Iterator() {
+ public VideoFrame previous = null;
+ public boolean hasNext() { return true; }
+ public Object next() {
+ try {
+ if (previous != null) previous.recycle();
+ previous = frames.take();
+ return previous.getBufferedImage();
+ } catch (InterruptedException ie) {
+ throw new RuntimeException(ie);
+ }
+ }
+ public void remove() {}
+ };
+ }
+}
Binary file not shown.

0 comments on commit 8cc5ba6

Please sign in to comment.