Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ipcamera] Improve online/offline detection for ONVIF cameras #16332

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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