Skip to content

Commit

Permalink
Add dedicated class for D-Link DSC-933L IP camera, refs #511
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Dec 6, 2016
1 parent 44e7b2e commit 64fdd35
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +35,7 @@

/**
* IP camera device.
*
*
* @author Bartosz Firyn (SarXos)
*/
public class IpCamDevice implements WebcamDevice {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand All @@ -434,7 +432,7 @@ public boolean isOnline() {
}

HttpHead head = new HttpHead(uri);

HttpResponse response = null;
try {
response = client.execute(head);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ public URL getURL() {
throw new WebcamException(String.format("Incorrect URL %s", url), e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down

0 comments on commit 64fdd35

Please sign in to comment.