-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ONVIF Cameras without stop/close event fail to trigger recording after first event closed #4195
Comments
Thanks for opening your first issue here! Just a reminder, this forum is for Bug Reports only. Be sure to follow the issue template! |
Is there anything else I could do to have this issue advance? |
I will take a look this week. I want to release 1.38 by end of month. So it would be nice to get this in by then. |
K, I see what you are saying, great job on a detail analysis... I'm just thinking instead of the suggested code change, should we not simply clear the alarms array when we set alarmed=false from zm_monitor? I don't actually like that zm_monitor adjusts the state of monitor_onvif... I feel like when the timeout in WaitForMessage happens, we should just automatically become unalarmed... |
Can you turn on debug please? Level 1 will do. It seems to me, we should get an OK, but empty SOAP response, in which case we should become unalarmed. |
What do you think of removing the code in zm_monitor, and using the following around line 227: Debug(1, "ONVIF polling : Got Good Response! %i", result); |
I will need to revisit the code and walk through its logic and impact from proposed changes. Should be able to do it in next day and a half. |
Level 1 debug logs attached as requested. |
Reviewed the code change proposed and tested it. Identified some potential issues:
It appears a new ONVIF event received could deactivate ONVIF alarm before the ONVIF triggered start event is raised in zm_monitor.cpp line 1957 causing a valid alarm to be missed. Line 1958 of zm_monitor.cpp references onvif->isAlarmed(). This is updated independently by the new code introduced starting at line 222 of zm_monitor_onvif.cpp introducing the race condition between Alarm event and ONVIF event reception.
Before: Alarm frames 6 - 20 and score 50 - 108. This is for 2 - 3 minute duration events. |
|
…on isAlarmed. Further to #4195
First up, thank you for ZM. The improvements in 1.37 branch is significant.
I looked into this problem and possibly identified the issue and logic fix. Not being familiar with ZM code base though, I am hesitant to produce a pull request until a review of the logic and impact assessment.
Environment
Expected
Whenever ZM receives a start ONVIF Motion Event it will trigger or continue recording. Recording will stop from ZM normal stop recording settings.
Observed
ZM starts the initial recording then stops the initial recording. Any additional start ONVIF Motion Events fail to trigger any further recordings.
Evidence
The logs below demonstrate this.
Start the camera. The first ONVIF motion alarm triggers a recording as noted by the Triggered Start Event on ONVIF log.
After this, logs are just the following repeated ad nauseam. There is no further triggering of recording.
Explaining why
There are two source files involved being zm_monitor.cpp and zm_monitor_onvif.cpp.
In zm_monitor_onvif.cpp void Monitor::ONVIF::WaitForMessage() a motionAlert event triggers the following code on line 202:
So we need to understand this code further. There are two types of cameras, one capable of generating Motion off / stop events, and one that only generates Motion on / start events. The code logic needs to handle both types.
Initially a camera is marked as only producing start events. This is done by Monitor::Monitor() : Event_Poller_Closes_Event(false) in zm_monitor.cpp line 319.
When an off event is received, Event_Poller_Closes_Event is set to true and off events are then expected for event termination. zm_monitor_onvif.cpp line 198.
So, we need to understand what receiving an off event does. zm_monitor.cpp lines 190 to 197 relevant code.
Whenever an off / close event happens, the alarm is erased and if it was the last alarm message type received, the ONVIF camera is removed from alarmed state.
What happens for ONVIF cameras that don't generate an off / close event. zm_monitor.cpp lines 1960 gives us the answer
If the camera does not generate ONVIF off / close events then the camera alarmed is set to false upon receipt.
What happens to the alarms array? Only the alarmed state variable gets updated. Alarms array remains untouched.
Going back to the Event Start code
On the first motion start event received, the alarms.count for the message will be 0. So the alarm message is recorded and the camera is alarmed.
On subsequent motion start events received, the alarms.count is not zero and alarms[last_topic] will contain the same value.
The if statement will not be true and the camera will never trigger a further start event recording because alarmed state will never be set again.
Let's test this logic out replacing the above code at line 202 in zm_monitor_onvif.cpp with the following code
By the way, that sleep_for line is deleted. Can't see any justification for it.
Testing the camera and ZM out gives us the below logs:
Three recording events successfully triggered. Much better outcome. The alarms not being erased seems a non issue and does not leak memory.
So the logic appears incorrect as demonstrated by the test code.
I am running the test code change for a few days now without observing any issue.
I hope the above code review assists in developing a proper fix.
The text was updated successfully, but these errors were encountered: