diff --git a/webcam-capture-drivers/driver-ipcam/src/examples/java/DLinkDsc933LExample.java b/webcam-capture-drivers/driver-ipcam/src/examples/java/DLinkDsc933LExample.java new file mode 100644 index 00000000..4ecb6344 --- /dev/null +++ b/webcam-capture-drivers/driver-ipcam/src/examples/java/DLinkDsc933LExample.java @@ -0,0 +1,36 @@ +import java.net.MalformedURLException; + +import javax.swing.JFrame; + +import com.github.sarxos.webcam.Webcam; +import com.github.sarxos.webcam.WebcamPanel; +import com.github.sarxos.webcam.ds.ipcam.IpCamDeviceRegistry; +import com.github.sarxos.webcam.ds.ipcam.IpCamDriver; +import com.github.sarxos.webcam.ds.ipcam.device.dlink.DSC933L; + + +public class DLinkDsc933LExample { + + static { + Webcam.setDriver(new IpCamDriver()); + } + + public static void main(String[] args) throws MalformedURLException { + + final String name = "D-Link 993L Camera"; + final String user = "{username}"; // change to your own username + final String pass = "{password}"; // change to your own password + final String url = "http://{ip-address-or-domain-name}"; // camera's IP address or domain + + IpCamDeviceRegistry.register(new DSC933L(name, url, user, pass)); + + final Webcam webcam = Webcam.getDefault(); + final WebcamPanel panel = new WebcamPanel(webcam); + + JFrame f = new JFrame(name); + f.add(panel); + f.pack(); + f.setVisible(true); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } +} diff --git a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDevice.java b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDevice.java index 54ff3374..8d769a42 100644 --- a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDevice.java +++ b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDevice.java @@ -23,8 +23,6 @@ import org.apache.http.client.protocol.ClientContext; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.params.CoreProtocolPNames; -import org.apache.http.params.HttpConnectionParams; import org.apache.http.protocol.BasicHttpContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,7 +35,7 @@ /** * IP camera device. - * + * * @author Bartosz Firyn (SarXos) */ public class IpCamDevice implements WebcamDevice { @@ -207,7 +205,7 @@ public void stop() { private Dimension[] sizes = null; private Dimension size = null; - + public IpCamDevice(String name, String url, IpCamMode mode) throws MalformedURLException { this(name, new URL(url), mode, null); } @@ -416,10 +414,10 @@ private BufferedImage getImagePullMode() { } /** - * This method will send HTTP HEAD request to the camera URL to check - * whether it's online or offline. It's online when this request succeed and - * it's offline if any exception occurs or response code is 404 Not Found. - * + * This method will send HTTP HEAD request to the camera URL to check whether it's online or + * offline. It's online when this request succeed and it's offline if any exception occurs or + * response code is 404 Not Found. + * * @return True if camera is online, false otherwise */ public boolean isOnline() { @@ -434,7 +432,7 @@ public boolean isOnline() { } HttpHead head = new HttpHead(uri); - + HttpResponse response = null; try { response = client.execute(head); diff --git a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/device/dlink/DSC933L.java b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/device/dlink/DSC933L.java new file mode 100644 index 00000000..76f986ef --- /dev/null +++ b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/device/dlink/DSC933L.java @@ -0,0 +1,51 @@ +package com.github.sarxos.webcam.ds.ipcam.device.dlink; + +import java.net.MalformedURLException; +import java.net.URL; + +import com.github.sarxos.webcam.WebcamException; +import com.github.sarxos.webcam.ds.ipcam.IpCamAuth; +import com.github.sarxos.webcam.ds.ipcam.IpCamDevice; +import com.github.sarxos.webcam.ds.ipcam.IpCamMode; + + +/** + * This is webcam device abstraction to handle MJPEG video stream from D-Link DSC-933L IP camera. + * + * @author Bartosz Firyn (sarxos) + */ +public class DSC933L extends IpCamDevice { + + /** + * Path used by this camera model to expose MJPEG video feed. + */ + private static final String MJPEG_PATH = "video/mjpg.cgi"; + + /** + * @param name the camera name, e.g. 'Bedroom Camera' + * @param url the camera address, e.g. 'http://192.168.0.12' + * @param user the user name configured in camera + * @param password the password for the user + * @throws MalformedURLException if camera address is invalid + */ + public DSC933L(String name, String url, String user, String password) throws MalformedURLException { + this(name, url, IpCamMode.PUSH, new IpCamAuth(user, password)); + } + + private DSC933L(String name, String url, IpCamMode mode, IpCamAuth auth) throws MalformedURLException { + super(name, url, mode, auth); + } + + @Override + public URL getURL() { + + final String base = super.getURL().toString(); + final String address = base + (base.endsWith("/") ? MJPEG_PATH : ("/" + MJPEG_PATH)); + + try { + return new URL(address); + } catch (MalformedURLException e) { + throw new WebcamException("Invalid URL " + base); + } + } +} diff --git a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/device/marmitek/IPRobocam641.java b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/device/marmitek/IPRobocam641.java index 03853e95..1d3b1af3 100644 --- a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/device/marmitek/IPRobocam641.java +++ b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/device/marmitek/IPRobocam641.java @@ -30,5 +30,4 @@ public URL getURL() { throw new WebcamException(String.format("Incorrect URL %s", url), e); } } - } diff --git a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/impl/IpCamMJPEGStream.java b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/impl/IpCamMJPEGStream.java index 2d00672e..031a73bc 100644 --- a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/impl/IpCamMJPEGStream.java +++ b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/impl/IpCamMJPEGStream.java @@ -20,14 +20,12 @@ public class IpCamMJPEGStream extends DataInputStream { private static final Logger LOG = LoggerFactory.getLogger(IpCamMJPEGStream.class); /** - * The first two bytes of every JPEG stream are the Start Of Image (SOI) - * marker values FFh D8h. + * The first two bytes of every JPEG stream are the Start Of Image (SOI) marker values FFh D8h. */ private final byte[] SOI_MARKER = { (byte) 0xFF, (byte) 0xD8 }; /** - * All JPEG data streams end with the End Of Image (EOI) marker values FFh - * D9h. + * All JPEG data streams end with the End Of Image (EOI) marker values FFh D9h. */ private final byte[] EOI_MARKER = { (byte) 0xFF, (byte) 0xD9 };