Skip to content

Commit

Permalink
Initial IP camera driver impl
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jul 30, 2012
1 parent fd83116 commit ee7357f
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 0 deletions.
7 changes: 7 additions & 0 deletions webcam-capture-driver-ipcam/.classpath
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions webcam-capture-driver-ipcam/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webcam-capture-driver-ipcam</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
6 changes: 6 additions & 0 deletions webcam-capture-driver-ipcam/bin/.classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="src/main/java/|src/main/resources/|src/test/java/|src/test/resources/|src/main/|src/|src/main/java/|target/classes/|target/" kind="src" path=""/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="bin"/>
</classpath>
23 changes: 23 additions & 0 deletions webcam-capture-driver-ipcam/bin/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>webcam-capture-driver-ipcam</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
15 changes: 15 additions & 0 deletions webcam-capture-driver-ipcam/bin/pom.xml
@@ -0,0 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.4</version>
</parent>

<artifactId>webcam-capture-driver-ipcam</artifactId>
<name>Webcam Capture - IP Camera Driver</name>
<description>Webcam Capture driver to be used for IP cameras </description>

</project>
33 changes: 33 additions & 0 deletions webcam-capture-driver-ipcam/pom.xml
@@ -0,0 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.4</version>
</parent>

<artifactId>webcam-capture-driver-ipcam</artifactId>
<name>Webcam Capture - IP Camera Driver</name>
<description>Webcam Capture driver to be used for IP cameras </description>

<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>0.3.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,117 @@
package com.github.sarxos.webcam.ds.ipcam;

import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.net.URL;

import javax.imageio.ImageIO;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;

import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamException;
import com.github.sarxos.webcam.ds.ipcam.http.IpCamAuth;
import com.github.sarxos.webcam.ds.ipcam.http.IpCamHttpClient;
import com.github.sarxos.webcam.ds.ipcam.http.IpCamMode;


/**
* IP camera device.
*
* @author Bartosz Firyn (SarXos)
*/
public class IpCamDevice implements WebcamDevice {

private String name = null;
private URL url = null;
private IpCamMode mode = null;
private IpCamAuth auth = null;
private IpCamHttpClient client = IpCamHttpClient.getIstance();

public IpCamDevice(String name, URL url) {
this(name, url, IpCamMode.PULL);
}

public IpCamDevice(String name, URL url, IpCamMode mode) {
this(name, url, mode, IpCamAuth.NONE);
}

public IpCamDevice(String name, URL url, IpCamMode mode, IpCamAuth auth) {
if (name == null) {
throw new IllegalArgumentException("Name cannot be null");
}
if (url == null) {
throw new IllegalArgumentException("URL cannot be null");
}
this.name = name;
this.url = url;
this.mode = mode;
this.auth = auth;
}

@Override
public String getName() {
return name;
}

@Override
public Dimension[] getSizes() {
// TODO Auto-generated method stub
return null;
}

@Override
public Dimension getSize() {
// TODO Auto-generated method stub
return null;
}

@Override
public void setSize(Dimension size) {
// TODO Auto-generated method stub

}

@Override
public BufferedImage getImage() {
HttpGet get = null;
try {
get = new HttpGet(url.toURI());
HttpResponse respone = client.execute(get);
HttpEntity entity = respone.getEntity();
return ImageIO.read(entity.getContent());
} catch (Exception e) {
throw new WebcamException("Cannot download image", e);
} finally {
if (get != null) {
get.releaseConnection();
}
}
}

@Override
public void open() {
// TODO Auto-generated method stub

}

@Override
public void close() {
// TODO Auto-generated method stub

}

public URL getUrl() {
return url;
}

public IpCamMode getMode() {
return mode;
}

public IpCamAuth getAuth() {
return auth;
}
}
@@ -0,0 +1,57 @@
package com.github.sarxos.webcam.ds.ipcam;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.imageio.ImageIO;

import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamDriver;
import com.github.sarxos.webcam.WebcamException;


/**
* IP camera driver.
*
* @author Bartosz Firyn (SarXos)
*/
public class IpCamDriver implements WebcamDriver {

private static final List<WebcamDevice> DEVICES = new ArrayList<WebcamDevice>();

@Override
public List<WebcamDevice> getDevices() {
return Collections.unmodifiableList(DEVICES);
}

public void registerDevice(IpCamDevice device) {
DEVICES.add(device);
}

public void registerURL(String name, URL url) {
DEVICES.add(new IpCamDevice(name, url));
}

public void registerURL(String name, String url) {
try {
DEVICES.add(new IpCamDevice(name, new URL(url)));
} catch (MalformedURLException e) {
throw new WebcamException("Incorrect URL", e);
}
}

public static void main(String[] args) throws IOException {
IpCamDriver driver = new IpCamDriver();
driver.registerURL("Test", "http://www.dasding.de/ext/webcam/webcam770.php?cam=1");
WebcamDevice device = driver.getDevices().get(0);
BufferedImage image = device.getImage();
ImageIO.write(image, "jpg", new File("ninonap.jpg"));
}

}
@@ -0,0 +1,25 @@
package com.github.sarxos.webcam.ds.ipcam.http;

/**
* HTTP authentication type.
*
* @author Bartosz Firyn (SarXos)
*/
public enum IpCamAuth {

/**
* No authentication.
*/
NONE,

/**
* Basic auth.
*/
BASIC,

/**
* WSSE auth.
*/
WSSE,

}
@@ -0,0 +1,26 @@
package com.github.sarxos.webcam.ds.ipcam.http;

import java.awt.image.BufferedImage;
import java.net.URL;

import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;


public class IpCamHttpClient extends DefaultHttpClient {

private static IpCamHttpClient istance = new IpCamHttpClient();

public IpCamHttpClient() {
super(new PoolingClientConnectionManager());
}

public static IpCamHttpClient getIstance() {
return istance;
}

public BufferedImage getImage(URL url) {

return null;
}
}
@@ -0,0 +1,20 @@
package com.github.sarxos.webcam.ds.ipcam.http;

/**
* How to obtain new images from IP cameras.
*
* @author Bartosz Firyn (SarXos)
*/
public enum IpCamMode {

/**
* Device will pull image from IP camera.
*/
PULL,

/**
* IP camera HTTP server will push new image to the device.
*/
PUSH,

}

0 comments on commit ee7357f

Please sign in to comment.