mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
Per-topic alarm expiry takes each alarm's deadline from the PullMessagesResponse TerminationTime. Beward cameras send their CurrentTime as the TerminationTime in every response, so an alarm was stored with a deadline that had already passed and the sweep at the end of the same WaitForMessage() pass removed it about 25us later. The analysis thread checks onvif->isAlarmed() once per frame, never saw the monitor alarmed, and no event was recorded even though the log showed "ONVIF Triggered Start Event". Move the TerminationTime handling into a free function, ONVIFAlarmTermination(), which applies the camera clock offset as before and returns false when the adjusted time is not after now. The alarm then gets no expiry and is cleared by the camera's explicit State=false message, as it was before per-topic expiry was added. The Debug line now also prints CurrentTime so this camera behaviour is visible in logs. Tests cover TerminationTime equal to and before CurrentTime, a future TerminationTime, a skewed camera clock, a missing CurrentTime keeping the previous offset, and a missing TerminationTime. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3.0 KiB
C++
75 lines
3.0 KiB
C++
/*
|
|
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "zm_catch2.h"
|
|
#include "zm_monitor_onvif.h"
|
|
|
|
#ifdef WITH_GSOAP
|
|
|
|
TEST_CASE("ONVIFAlarmTermination", "[onvif]") {
|
|
// 2026-10-01 18:52:32.917 UTC, the moment of the first alarm in the #5165 log
|
|
const time_t now_t = 1790880752;
|
|
const SystemTimePoint now = std::chrono::system_clock::from_time_t(now_t) + std::chrono::milliseconds(917);
|
|
time_t clock_offset = 0;
|
|
SystemTimePoint termination;
|
|
|
|
SECTION("TerminationTime equal to CurrentTime is not usable") {
|
|
// Beward cameras put their CurrentTime in TerminationTime on every
|
|
// PullMessagesResponse. Using it expired each alarm in the same pass that
|
|
// raised it, so the analysis thread never saw the monitor alarmed.
|
|
REQUIRE_FALSE(ONVIFAlarmTermination(now_t, now_t, now, clock_offset, termination));
|
|
REQUIRE(clock_offset == 0);
|
|
}
|
|
|
|
SECTION("TerminationTime before CurrentTime is not usable") {
|
|
REQUIRE_FALSE(ONVIFAlarmTermination(now_t - 5, now_t, now, clock_offset, termination));
|
|
}
|
|
|
|
SECTION("TerminationTime in the future is used") {
|
|
REQUIRE(ONVIFAlarmTermination(now_t + 60, now_t, now, clock_offset, termination));
|
|
REQUIRE(clock_offset == 0);
|
|
REQUIRE(termination == std::chrono::system_clock::from_time_t(now_t + 60));
|
|
}
|
|
|
|
SECTION("Camera clock offset is applied") {
|
|
// Camera clock is an hour behind ours
|
|
REQUIRE(ONVIFAlarmTermination(now_t - 3600 + 60, now_t - 3600, now, clock_offset, termination));
|
|
REQUIRE(clock_offset == 3600);
|
|
REQUIRE(termination == std::chrono::system_clock::from_time_t(now_t + 60));
|
|
}
|
|
|
|
SECTION("TerminationTime equal to a skewed CurrentTime is not usable") {
|
|
REQUIRE_FALSE(ONVIFAlarmTermination(now_t - 3600, now_t - 3600, now, clock_offset, termination));
|
|
REQUIRE(clock_offset == 3600);
|
|
}
|
|
|
|
SECTION("Without CurrentTime the previous offset is kept") {
|
|
clock_offset = 3600;
|
|
REQUIRE(ONVIFAlarmTermination(now_t - 3600 + 60, 0, now, clock_offset, termination));
|
|
REQUIRE(clock_offset == 3600);
|
|
REQUIRE(termination == std::chrono::system_clock::from_time_t(now_t + 60));
|
|
|
|
REQUIRE_FALSE(ONVIFAlarmTermination(now_t - 3600, 0, now, clock_offset, termination));
|
|
}
|
|
|
|
SECTION("No TerminationTime is not usable") {
|
|
REQUIRE_FALSE(ONVIFAlarmTermination(0, now_t, now, clock_offset, termination));
|
|
}
|
|
}
|
|
|
|
#endif // WITH_GSOAP
|