Skip to content

Commit

Permalink
Allow ONVIF to come online if they dont support events. (openhab#16332)
Browse files Browse the repository at this point in the history
Remove commented out code.

Signed-off-by: Matthew Skinner <matt@pcmus.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
Skinah authored and austvik committed Mar 27, 2024
1 parent 0f15c0a commit debbeaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,16 @@ public String getTinyUrl(String httpRequestURL) {
private void checkCameraConnection() {
if (snapshotPolling) { // Currently polling a real URL for snapshots, so camera must be online.
return;
} else if (ffmpegSnapshotGeneration) { // Use RTSP stream creating snapshots to know camera is online.
} else if (ffmpegSnapshotGeneration) {
Ffmpeg localSnapshot = ffmpegSnapshot;
if (localSnapshot != null && !localSnapshot.isAlive()) {
cameraCommunicationError("FFmpeg Snapshots Stopped: Check that your camera can be reached.");
}
return; // ffmpeg snapshot stream is still alive
return; // RTSP stream is creating snapshots, so camera is online.
}

// ONVIF cameras get regular event messages from the camera
if (supportsOnvifEvents() && onvifCamera.isConnected()) {
return;
if (supportsOnvifEvents() && onvifCamera.isConnected() && onvifCamera.getEventsSupported()) {
return;// ONVIF cameras that are getting event messages must be online
}

// Open a HTTP connection without sending any requests as we do not need a snapshot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ public enum RequestType {
private String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service";
private boolean isConnected = false;
private int mediaProfileIndex = 0;
// private String snapshotUri = "";
private String rtspUri = "";
private IpCameraHandler ipCameraHandler;
private boolean supportsEvents = false; // camera has replied that it can do events
// Use/skip events even if camera support them. API cameras skip, as their own methods give better results.
private boolean usingEvents = false;

// These hold the cameras PTZ position in the range that the camera uses, ie
Expand Down Expand Up @@ -312,7 +313,7 @@ public void processReply(String message) {
} else if (message.contains("RenewResponse")) {
sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr);
} else if (message.contains("GetSystemDateAndTimeResponse")) {// 1st to be sent.
setIsConnected(true);
setIsConnected(true);// Instar profile T only cameras need this
parseDateAndTime(message);
logger.debug("openHAB UTC dateTime is: {}", getUTCdateTime());
} else if (message.contains("GetCapabilitiesResponse")) {// 2nd to be sent.
Expand All @@ -337,6 +338,7 @@ public void processReply(String message) {
} else if (message.contains("GetEventPropertiesResponse")) {
sendOnvifRequest(RequestType.CreatePullPointSubscription, eventXAddr);
} else if (message.contains("CreatePullPointSubscriptionResponse")) {
supportsEvents = true;
subscriptionXAddr = Helper.fetchXML(message, "SubscriptionReference>", "Address>");
logger.debug("subscriptionXAddr={}", subscriptionXAddr);
sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr);
Expand Down Expand Up @@ -958,6 +960,10 @@ public boolean isConnected() {
}
}

public boolean getEventsSupported() {
return supportsEvents;
}

public void setIsConnected(boolean isConnected) {
connecting.lock();
try {
Expand Down

0 comments on commit debbeaf

Please sign in to comment.