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
3702239.255.255.250
239.255.255.250
1900
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
OnvifManagerOnvifResponseListenerOnvifDevicediscoverDiscoveryManager
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
UPnPManagerUPnPDeviceDiscoveryManagerdiscovery.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
OnvifRequestgetXml()getType()
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; } }
OnvifDevice
onvifManager.sendOnvifRequest(device, new PTZRequest());
OnvifResponseListener
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.
LicenseCopyright 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.