Skip to content

Commit

Permalink
Get ONVIF entry points programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-beauc committed Dec 22, 2023
1 parent 0cb4703 commit 246bcd4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/us/mn/state/dot/tms/server/comm/onvifptz/DOMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static String getString(Node n) {
public static Document getDocument(String s) {
Document doc = null;
try {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
DocumentBuilder db = DocumentBuilderFactory.newNSInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(s));
doc = db.parse(is);
Expand Down
34 changes: 34 additions & 0 deletions src/us/mn/state/dot/tms/server/comm/onvifptz/DeviceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package us.mn.state.dot.tms.server.comm.onvifptz;

import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.NodeList;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

Expand Down Expand Up @@ -56,6 +57,39 @@ public String getServices() {
return sendRequestDocument(doc);
}

/** Gets a service address by its namespace */
public String getServiceAddr(String namespace) {
String servicesRes = getServices();
Document servicesDoc = DOMUtils.getDocument(servicesRes);

NodeList services = servicesDoc.getElementsByTagNameNS("*", "Service");
for (int i = 0; i < services.getLength(); i++) {
Element service = (Element) services.item(i);
Element ns = (Element) service.getElementsByTagNameNS("*", "Namespace").item(0);

if (ns.getTextContent().equalsIgnoreCase(namespace)) {
Element addr = (Element) service.getElementsByTagNameNS("*", "XAddr").item(0);
return addr.getTextContent();
}
}
return null;
}

/** Get the PTZ binding address */
public String getPTZBinding() {
return getServiceAddr("http://www.onvif.org/ver20/ptz/wsdl");
}

/** Get the media binding address */
public String getMediaBinding() {
return getServiceAddr("http://www.onvif.org/ver10/media/wsdl");
}

/** Get the imaging binding address */
public String getImagingBinding() {
return getServiceAddr("http://www.onvif.org/ver20/imaging/wsdl");
}

/** Document builder function for GetScopes */
public Document getScopesDocument() {
Document doc = getBaseDocument();
Expand Down
9 changes: 4 additions & 5 deletions src/us/mn/state/dot/tms/server/comm/onvifptz/OnvifProp.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ public String sendSoap() {
return "No cmd specified";
}

// create each service
// TODO: generalize service paths? (device service specified by ONVIF standard)
// create each service (device service binding specified by ONVIF standard)
DeviceService dev = DeviceService.getDeviceService(url + "/onvif/device_service", user, pass);
PTZService ptz = PTZService.getPTZService(url + ":80/onvif/ptz", user, pass);
MediaService media = MediaService.getMediaService(url + ":80/onvif/media", user, pass);
ImagingService img = ImagingService.getImagingService(url + ":80/onvif/imaging", user, pass);
PTZService ptz = PTZService.getPTZService(dev.getPTZBinding(), user, pass);
MediaService media = MediaService.getMediaService(dev.getMediaBinding(), user, pass);
ImagingService img = ImagingService.getImagingService(dev.getImagingBinding(), user, pass);

String mediaProfile = null, videoSource = null;
int mediaWidth = 0, videoWidth = 0; // to find maximum values
Expand Down

0 comments on commit 246bcd4

Please sign in to comment.