Code Monkey home page Code Monkey logo

onvif-java's Introduction

ONVIF-Java


Download

ONVIF is an open industry forum that provides and promotes standardized interfaces for effective interoperability of IP-based physical security products. ONVIF was created to make a standard way of how IP products within CCTV and other security areas can communicate with each other.

Features

  • ONVIF & UPnP discovery
  • ONVIF device management (Services, device information, media profiles, raw media stream uri)
  • UPnP device information
  • Easily extendable with your own requests
  • Android supported!

Discovery


The OnvifDiscovery class uses the Web Services Dynamic Discovery (WS-Discovery). This is a technical specification that defines a multicast discovery protocol to locate services on a local network. It operates over TCP and UDP port 3702 and uses IP multicast address 239.255.255.250. As the name suggests, the actual communication between nodes is done using web services standards, notably SOAP-over-UDP.

With WS-Discovery, the discovery tool puts SSDP queries on the network from its unicast address to 239.255.255.250 multicast address, sending them to the well-known UDP port 3702. The device receives the query, and answers to the discovery tool's unicast IP address from its unicast IP address. The reply contains information about the Web Services (WS) available on the device.

UPnP works in a very similar way, but on a different UDP port (1900). Compared to the WS-Discovery, the UPnP is intended for a general use (data sharing, communication, entertainment).

DiscoveryManager manager = new DiscoveryManager();
manager.setDiscoveryTimeout(10000);
manager.discover(new DiscoveryListener() {
    @Override
    public void onDiscoveryStarted() {
        System.out.println("Discovery started");
    }

    @Override
    public void onDevicesFound(List<Device> devices) {
        for (Device device : devices)
            System.out.println("Devices found: " + device.getHostName());
    }
});

ONVIF


With the OnvifManager class it is possible to send requests to an ONVIF-supported device. All requests are sent asynchronously and you can use the OnvifResponseListener for errors and custom response handling. It is possible to create your own OnvifDevice or retrieve a list from the discover method in the DiscoveryManager

onvifManager = new OnvifManager();
onvifManager.setOnvifResponseListener(this);
OnvifDevice device = new OnvifDevice("192.168.0.131", "username", "password");

Services

Returns information about services on the device.

onvifManager.getServices(device, new OnvifServicesListener() {
    @Override
    public void onServicesReceived(@Nonnull OnvifDevice onvifDevice, OnvifServices services) {
        
    }
});

Device information

Returns basic device information from the device. This includes the manufacturer, serial number, hardwareId, ...

onvifManager.getDeviceInformation(device, new OnvifDeviceInformationListener() {
    @Override
    public void onDeviceInformationReceived(@Nonnull OnvifDevice device, 
                                            @Nonnull OnvifDeviceInformation deviceInformation) {
        
    }
});

Media Profiles

Returns pre-configured or dynamically configured profiles. This command lists all configured profiles in a device. The client does not need to know the media profile in order to use the command.

onvifManager.getMediaProfiles(device, new OnvifMediaProfilesListener() {
    @Override
    public void onMediaProfilesReceived(@Nonnull OnvifDevice device, 
                                        @Nonnull List<OnvifMediaProfile> mediaProfiles) {
        
    }
});

Media Stream URI

Returns a raw media stream URI that remains valid indefinitely even if the profile is changed.

onvifManager.getMediaStreamURI(device, mediaProfiles.get(0), new OnvifMediaStreamURIListener() {
    @Override
    public void onMediaStreamURIReceived(@Nonnull OnvifDevice device, 
                                        @Nonnull OnvifMediaProfile profile, @Nonnull String uri) {
        
    }
});

UPnP


With the UPnPManager it is possible to retrieve device information from a locally connected UPnP device. A UPnPDevice can be created manually or discovered from the DiscoveryManager using discovery.discover(DiscoveryMode.UPNP)

UPnPDevice device = new UPnPDevice("192.168.0.160");
device.setLocation("http://192.168.0.160:49152/rootdesc1.xml");
UPnPManager uPnPManager = new UPnPManager();
uPnPManager.getDeviceInformation(device, new UPnPDeviceInformationListener() {
    @Override
    public void onDeviceInformationReceived(@Nonnull UPnPDevice device, 
                                            @Nonnull UPnPDeviceInformation information) {
        Log.i(TAG, device.getHostName() + ": " + information.getFriendlyName());
    }
    @Override
    public void onError(@Nonnull UPnPDevice onvifDevice, int errorCode, String errorMessage) {
        Log.e(TAG, "Error: " + errorMessage);
    }
});

Custom requests


It is possible to implement your custom ONVIF request by creating a new class and implementing the OnvifRequest interface and overriding the getXml() and getType() methods.

public class PTZRequest implements OnvifRequest {
    @Override
    public String getXml() {
        return "<GetServices xmlns=\"http://www.onvif.org/ver10/device/wsdl\">" +
                "<IncludeCapability>false</IncludeCapability>" +
                "</GetServices>";
    }
    @Override
    public OnvifType getType() {
        return OnvifType.CUSTOM;
    }
}

and send it to the appropriate OnvifDevice:

onvifManager.sendOnvifRequest(device, new PTZRequest());

Use the OnvifResponseListener to receive responses from your custom requests.

Android


In order to receive multicasts packets on your Android device, you'll have to acquire a lock on your WifiManager before making a discovery. Make sure to release the lock once the discovery is completed. More information can be found here: https://developer.android.com/reference/android/net/wifi/WifiManager.MulticastLock

private void lockMulticast() {
    WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (wifi == null)
        return;

    WifiManager.MulticastLock lock = wifi.createMulticastLock("ONVIF");
    lock.acquire();
}

Download

Download the latest JAR or grab via Maven:

<dependency>
  <groupId>be.teletask.onvif</groupId>
  <artifactId>onvif</artifactId>
  <version>1.0.0</version>
</dependency>

or Gradle:

compile 'be.teletask.onvif:onvif:1.0.0'

Todos

  • Implementation ONVIF version management
  • Implementation PTZ

Pull Requests


Feel free to send pull requests.

License

Copyright 2018 TELETASK BVBA.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

onvif-java's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

onvif-java's Issues

How to specify a port that is non 80?

One of my cameras (Instar brand) uses port 8080 for onvif and it will not connect, whilst my other brands connect fine as they use port 80. Is there a way to specify a port? if so how? Foscam is another brand that uses a different port of 888 for onvif.

onvifDevice = new OnvifDevice("/192.168.1.6:8080", username, password);
onvifDevice = new OnvifDevice("192.168.1.6:8080", username, password);

Both of the above do not work. First gives no errors or any feedback, the second one gives a failed to connect error message.

Is there a way to get the snapshot URI?

I can only see rstp URIs which works fine. My need is to get snapshots every n seconds, decoding the stream and capturing is not feasible.

I guess a custom request should do the trick but i have not idea how to build one or where to look for to learn how to build one.

Can't download jar with Maven

I'm adding the suggested dependency but when i build the project i get the following error:
Failed to collect dependencies at be.teletask.onvif:onvif:jar:1.0.0: Failed to read artifact descriptor for be.teletask.onvif:onvif:jar:1.0.0: Could not transfer artifact be.teletask.onvif:onvif:pom:1.0.0 from/to Eclipse repo (https://repo.eclipse.org/content/groups/releases/): Server chose TLSv1, but that protocol version is not enabled or not supported by the client

is there any resolution for such a problem?

TPLink camera response error calling getServices

This is my code (I've tested with different url's like 172.16.8.193 alone an so, and the result is the same):

OnvifManager onvifManager = new OnvifManager();

onvifManager.setOnvifResponseListener(this);

OnvifDevice device = new OnvifDevice("http://172.16.8.193:2020/onvif/device_service", "admin", "xxxxx");

//my own listener
TecOnvifserviceListener tecOnvifServiceListener = new TecOnvifserviceListener();

onvifManager.getServices(device, tecOnvifServiceListener);

Response:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:trp="http://www.onvif.org/ver10/replay/wsdl"><SOAP-ENV:Body><SOAP-ENV:Fault><SOAP-ENV:Code><SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value><SOAP-ENV:Subcode></SOAP-ENV:Subcode></SOAP-ENV:Code><SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en">Method 'GetServices' not implemented: method name or namespace not recognized</SOAP-ENV:Text></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

PTZ abilities added?

Hi,

I have PTZ working by extending this lib using external classes so thanks for creating this lib and also making it opensource with a license. Do you plan to update this at all and would you accept any PR that I make to extend its feature set? Any guidance on how I should go about it?

I also need the ability to know the manufacturer and model of auto discovered devices without knowing the user/pass which is possible to do, just not with the lib in its current state.

Wondering what the future plans of this library are as I wish to use the library to give Openhab (a fully opensource home automation platform) better camera support.

Once again thanks and hope to get a reply back as it is sad that Java does not have a fully featured ONVIF library that is actively being added to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.