Commit Graph
1549 Commits
Author SHA1 Message Date
IgorA100 0de8f784a8 - Add configurable Go2RTC RTSP backchannel handling on the C++ side
- Add a helper to add or update Go2RTC URL parameters without overwriting existing options or appending duplicate parameters.
- Allow enabling or disabling RTSP backchannel handling for cameras, including both primary and secondary stream paths.
2026-10-25 00:48:42 +03:00
IgorA100 dfbefef71d Processing the monitor's DeviceClass parameter 2026-10-21 13:42:19 +03:00
Isaac ConnorandClaude Opus 4.8 eff658e319 fix: release the ONVIF alarm latch only when a video frame records it refs #5301
The latch was released in Analyse() at the isAlarmed() sample, before the
packet was committed. Two paths then spent a momentary DetectedSound pulse
without recording it:

- A video packet not yet decoded makes Analyse() return at the decode gate
  before packet->score is set, and the same packet is retried. The sample --
  and the release -- ran on every retry, so the pulse was gone by the time the
  packet was decoded and scored, and the event recorded no alarm frame. This is
  why raising AlarmFrameCount or the earlier hold did not help: the retries of
  one undecoded packet consumed the latch.
- An audio packet (these cameras alarm on AudioAnalytics/DetectedSound, so audio
  packets are present) could sample and release the latch, but alarm_frames
  counts video frames, so the pulse was again recorded on no counted frame.

Defer the release to the point where a video packet is committed with its
score, so the latch is spent only on a frame the event actually writes.

Also keep the topic/value of the last activation and report it from
SetNoteSet() when the alarms map has already been cleared, so a momentary
pulse's event note still names the cause (e.g. AudioAnalytics/Audio/
DetectedSound/true) instead of a bare "ONVIF".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-20 08:49:01 -04:00
Isaac ConnorandClaude Opus 4.8 290b89ab6f fix: latch ONVIF alarms so a momentary pulse is not missed refs #5301
The ONVIF alarm was a plain atomic bool that the poll thread set and the
analysis thread sampled once per frame. A momentary alarm -- a DetectedSound
pulse the camera reports active then inactive between two analysis frames --
was raised and cleared on the raw level before any frame sampled it, so the
recorded event had no alarm frames. A motion alarm stays active for seconds
and so was always sampled, which is why MotionAlarm never showed the problem.

Replace the bool with an AlarmLatch: raise() marks the level active and that
an activation is waiting to be seen, clear() drops the level, and the analysis
thread calls observeAlarm() once it has sampled the alarm. isAlarmed() stays
true from a raise until the level is down and the activation has been observed,
so a pulse is reported on at least one frame however short it was. A
still-active alarm is unaffected. The latch is released only on a frame that
scored, so a pulse arriving just after the isAlarmed() check is kept for the
next frame rather than lost.

The activation guards in WaitForMessage() now test the raw level (alarm_.active())
instead of isAlarmed(), so a new topic still raises the level while an earlier
pulse's latch is still pending.

Add Catch2 coverage for AlarmLatch (tests/zm_onvif_alarm_latch.cpp), testable
without a gSOAP context like the other ONVIF free-function tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-18 18:09:32 -04:00
Isaac ConnorandClaude Opus 5.5 34084a229d fix: wake an on-demand monitor when a linked monitor alarms
A monitor with Capturing=Ondemand and LinkedMonitors never recorded a linked
alarm unless someone happened to be watching it. Links are evaluated in
Analyse(), per captured packet, and zmc pauses an on-demand camera, stopping
its analysis thread, 10 s after the last viewer. While paused nothing looked
at the links, so every alarm on the linked monitor was missed. This is the
low-bandwidth setup of a substream that analyses and a main stream that
records on demand.

zmc's on-demand decision moves into Monitor::CheckOndemand(), around a
DecideOndemand() table that can be tested:

- While paused, the links are checked on every pass. The analysis thread is
  stopped then, so the capture thread reads them without racing it. An alarm
  reopens the camera.
- An unwatched monitor keeps capturing while it is alarmed or in its
  post-event frames, instead of pausing in the middle of the event.
- A link only reports an alarm while it lasts, and reopening the camera can
  take longer than that (2.5 s against a local camera). So the wake is
  remembered for up to 30 s, and the first packet Analyse() scores counts it
  as a linked alarm, then clears it.

Tested live on 1.38 with a paused on-demand passthrough monitor linked to an
analysing one. Before: an 8 s forced alarm on the source recorded nothing.
After: the monitor woke within 0.1 s, alarmed 2.5 s later and recorded the
event. A 1 s alarm, over before the camera reopened, was also recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 08:33:11 -04:00
Isaac ConnorandClaude Opus 5.5 1fc6630d75 refactor: drop the linked-monitor re-parse from Monitor::Reload() refs #5275
#5276 re-parsed LinkedMonitors in Reload() because nothing else did until
the next reconnect. Since #5239, every reload is a reconnect: zmc Close()s
and disconnect()s the monitor, calls Reload(), then connect(), and
connect() already calls ReloadLinkedMonitors(). The call in Reload()
queried the database once per linked monitor for an expression connect()
then threw away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 20:45:39 -04:00
Isaac ConnorandClaude Opus 5.5 2d353fe43c fix: run the shared-memory reload action through zmc's SIGHUP reload fixes #5239
Monitor::CheckAction() handled the RELOAD action (zmu --reload, or a script
setting it through ZoneMinder::Memory) by calling Reload() in place. That
runs on zmc's capture thread, and Monitor::Load() rewrites settings such as
label_format, orientation and the image sizes while the decoder and analysis
threads read them unlocked.

SIGHUP already reloads safely: zmc leaves its capture loop, Close()s and
disconnect()s each monitor, which stops those threads, then Reload()s and
reconnects. Have the action set zm_reload, as the SIGHUP handler does, so
both take that path.

zmc reloads every monitor it runs this way, not only the one the action was
sent to; zmc normally runs one.

Tested live on 1.38 with zmu --reload against a running zmc: the event closes,
the same process reloads and reconnects, capture resumes and a new event
opens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 19:07:40 -04:00
Isaac Connor c0251b3ac5 Merge pull request #5276 from nabbi/fix/b84-reload-linked-monitors
fix-medium: re-parse LinkedMonitors on a monitor reload
2026-10-14 18:52:23 -04:00
Isaac Connor 503a1c0c74 Merge pull request #5270 from nabbi/fix/b82-poll-thread-stop
fix-medium: let PollThread::Stop end the wait between polls
2026-10-14 18:25:18 -04:00
Isaac Connor 969069eacf Merge pull request #5241 from nabbi/fix/b68-signal-colour-luma
fix-medium: match SignalCheckColour by its luma on 1-byte-per-pixel captures
2026-10-13 18:14:42 -04:00
Nic BoetandClaude Opus 5.5 a5892c71e0 fix: re-parse LinkedMonitors on a monitor reload
Monitor::Reload() (the RELOAD action `zmu -m N -L` sends) re-reads the
monitor row, which replaces linked_monitors_string, but the
MonitorLinkExpression built from it is only rebuilt in connect(). The
old links stayed in use until zmc reconnected: after changing
LinkedMonitors from 3 to 4 and reloading, zmc kept scoring monitor 3
and ignored alarms on 4.

Rebuild the expression in Reload(), under event_mutex, which Analyse()
holds while it evaluates linked_monitors.

fixes #5275

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 17:12:24 -05:00
Nic BoetandClaude Opus 5.5 87a9db816e Merge master into fix/b59-signal-single-writer
Resolves the conflict with dad9da272 (refs #4242) in Monitor::Capture():
keep the timestamp continuity block from master, followed by this
branch's signal handling. Same tree as the branch rebased onto
233a15828, which passed the holodeck checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:23:06 -05:00
Nic BoetandClaude Opus 5.5 dcca007124 fix: let PollThread::Stop end the wait between polls
Monitor::Poll() ended by sleeping until 10 s after it started, and
PollThread::Stop() joins the thread, so Monitor::Close() waited for the
rest of that sleep: up to 10 s on every stop, reconnect and reload of a
zmc whose monitor has an ONVIF event listener, Janus, RTSP2Web, Go2RTC
or the Amcrest API enabled.

Wait for the next poll in PollThread::Run() on a condition variable
that Stop() notifies. Polls still start every 10 s.

fixes #5269

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:53:51 -05:00
Isaac ConnorandClaude Opus 5.5 dad9da272a fix: take a jump back in a camera's clock out of the timestamps at capture refs #4242
When a camera's clock steps back by under 10 s (an NTP sync, a clock reset),
the packets after the step carry dts values behind the ones before it. The
video store patched each one to last_dts + last_duration and logged "non
increasing dts, fixing." for every packet until the event ended, thousands
per event. Splitting the event at the step doesn't help on its own: in
passthrough an event has to start on a keyframe, and the walk back for one
crosses the step again.

Handle it the way ffmpeg's demuxer does, where packets enter the pipeline:
the Monitor keeps each stream's last dts and one offset shared by all the
camera's streams. When a stream steps back by more than 1 s, the offset moves
so the stream continues one frame after where it was, and every packet gets
the offset from then on. Monitor::Capture applies it before the stream
socket, the packet queue or anything else sees the packet, and Pause() resets
it when the capture session ends. The packet queue, the event's choice of
first keyframe and the video store then see one continuous timeline: nothing
is split, flagged or patched downstream, and no video is dropped. Steps under
1 s are reordering jitter, left to the video store's reorder queue; steps of
10 s or more keep FfmpegCamera's existing handling.

tests/zm_monitor_dts.cpp covers a continuous stream, jitter, the 8.9 s and
1.048 s steps, audio following the offset video set, a missing duration and
packets without a dts.

Alternative to #5212 and #5068.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 14:45:19 -04:00
Nic BoetandClaude Opus 5.5 72d45bcdcf fix: make the per-monitor frame counters atomic
decoding_image_count is incremented by the decoder thread and read by
Ready() on the analysis thread; motion_frame_count is incremented by
the analysis thread and read by UpdateFPS() on the capture thread. Both
were plain ints. ThreadSanitizer reports zm_monitor.cpp:3687 and :2366.

Make both std::atomic<int>, and reset decoding_image_count in Pause()
after the analysis thread is joined instead of between the decoder and
analysis joins, while Ready() could still read it.

fixes #5250

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 11:47:40 -05:00
Nic BoetandClaude Opus 5.5 0c6e18c427 fix: match SignalCheckColour by its luma on 1-byte-per-pixel captures
On GRAY8 and planar YUV images CheckSignal compared the Y byte with the
low byte of the RGB setting, which is its blue component. A camera
showing the default #0000BE decodes to Y=35 and never counted as lost;
only a colour whose blue byte happened to equal the luma matched.

Compare with the BT.601 luma of the colour in limited range (YUV420P,
YUV422P) and in full range (J formats, GRAY8). The low byte still
matches, so setups that stored the luma there (#000023, as the V4L2
probe does for GREY) keep working.

fixes #5240

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 11:20:58 -05:00
Nic BoetandClaude Opus 5.5 68aa214ff7 fix: leave the signal flag to the decoder when it checks SignalCheckPoints
Capture set shared_data->signal to true for every packet while the
decoder set it to CheckSignal() for every decoded frame. With
SignalCheckPoints on and a camera showing its lost-signal picture,
Analyse sometimes read Capture's true between two decoded frames, so the
signal flipped back for one frame: the event was closed for signal loss
and a zero-frame "Signal: Reacquired" event opened, about once a minute.

Capture now writes true only when no decoder measures the signal: no
SignalCheckPoints, Decoding=None, or on-demand decoding with no viewer.
It still writes true for the first packet after connect(), as before, so
Analyse doesn't see a signal loss before the first decoded frame and the
first event keeps its cause. The capture-failure path still writes false.

fixes #5235

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 11:15:52 -05:00
Isaac ConnorandClaude Opus 5 b0645ae512 feat: remove the Libvlc capture method from the daemons and build
Ffmpeg reaches the same network cameras libvlc did, so carrying a second
streaming library -- with its own threading, its own bugs and its own
build dependency -- buys nothing. The preceding migration moves existing
monitors to Ffmpeg first, so Monitor::Load cannot meet a type it no
longer recognises, which is Fatal and would stop zmc rather than skip
the monitor.

Drops LibvlcCamera, the LIBVLC camera type and its parse and
construction arms, LIBVLC_SRC and Camera::IsLibvlc, the ZM_NO_LIBVLC
option and the libvlc probe, and the HAVE_LIBVLC and HAVE_VLC_VLC_H
defines. Since the camera resolved libvlc through dlopen rather than
linking it, this removes a headers-only build dependency and a runtime
one, and nothing else needed relinking.

kOptionSeparators stays -- the Ffmpeg path still parses the Options
field with it -- but it is no longer a contract shared between two
readers, so its comment and the test that pins its behaviour are
reworded rather than removed.

Built clean from a fresh cmake configure, which no longer lists libVLC
among optional libraries; unit suite passes (147 cases, 12531
assertions); no libvlc strings remain in zmc.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 fd0450c160 feat: remove the NVSocket capture method
NVSocket spoke a bespoke socket protocol to one vendor's nvr. It has a
single known user, no way for anyone else to test it, and nothing it
reaches that ffmpeg cannot reach over rtsp or http, so it is removed
rather than carried further.

Drops RemoteCameraNVSocket, the NVSOCKET camera type and its parse and
construction arms, the source-type option and settings panel in the web
ui, and the stray ja_jp translation key. The preceding migration moves
any existing rows off the type first, so Monitor::Load cannot meet a
type it no longer recognises -- that path is Fatal and would stop zmc
rather than skip the monitor.

Built clean; unit suite passes (147 cases, 12531 assertions, run from
tests/ where the font fixtures' relative paths resolve). eslint clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 7991628191 fix: give CameraType_Strings its missing LibCURL entry
The table is indexed by Monitor::CameraType but had no entry for
LIBCURL, so every name from that point on belonged to the wrong type --
LIBCURL printed "NVSOCKET" and NVSOCKET printed "VNC" -- and VNC, the
last value, indexed one past the end of the array. The only reader is a
Debug(1) in Monitor::Load, so a VNC monitor read out of bounds whenever
debug logging was on.

Add a static_assert tying the table's length to the last enum value, so
adding or removing a camera type fails the build instead of silently
shifting the names again. Verified by removing an entry and confirming
the build fails on the assertion.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 ce16d3eb08 feat: deprecate the Libvlc and NVSocket capture methods
Both reach cameras that ffmpeg reaches. Libvlc does it through a second
streaming library with its own build dependency, threading and bugs; NVSocket
speaks a bespoke socket protocol for one vendor's nvr that we have no way to
test. Neither earns the maintenance, and the same monitors work as Type Ffmpeg
with the camera's rtsp or http url.

Deprecated, not removed. A monitor using either still captures; it logs a
warning at startup naming what to change it to, and the form marks the type and
explains. That follows what Remote/RTSP did before it was removed, which is the
shape that gives people a release to move in.

The warnings were verified firing rather than assumed: switching a monitor to
each type in turn produces the expected message naming that monitor.

php -l and eslint clean; the three pre-existing duplicate lang keys are
unchanged. Suite 147 cases / 12531 assertions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 8d44c2173d refactor: stop reading RTSPDescribe, which only the removed client used
rtsp_describe was passed to RemoteCameraRtsp and nowhere else, so with that
camera gone it was loaded from the database on every monitor read and then
ignored.

The SELECT column and its positional read come out together. They have to: the
row is walked by index, so removing one without the other silently shifts every
field after it rather than failing to build.

The Monitors.RTSPDescribe column stays. Dropping it is a migration and a web
change, which is a separate piece of work from no longer reading it.

Verified against the live database rather than by inspection, since a
misalignment here compiles perfectly: the monitor loads its name, 2560x1440
geometry, hevc codec and vaapi setting correctly, and captured 668 frames with
no errors.

Suite 147 cases / 12531 assertions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 6c5904482b refactor: no camera holds a video decoder any more
RemoteCameraRtsp was the last camera that opened one, so Camera's
mVideoCodecContext and getVideoCodecContext() are now written by nobody and
read only by the fallback that existed for it.

Drop both. Monitor::GetVideoCodecContext() returns the monitor's context and
nothing else, OpenDecoder() no longer has to ask whether the camera brought its
own, and FfmpegCamera::Close() stops freeing a pointer it cannot have set. The
audio decoder stays with the camera; only video moved.

This is what the previous commits were working towards: one owner for the
decoder, with the hw device reference and the hw pix fmt storage beside it, and
no path where a camera can free a context the decoder thread is using.

Verified on hardware after the removal: vaapi negotiated, 646 frames into a
recorded event, no errors. Suite 147 cases / 12531 assertions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 d14dfd8efb feat: remove the hand-written rtsp client
ZoneMinder carried two rtsp implementations: ffmpeg, which every Type=Ffmpeg
monitor uses, and a hand-written one behind Type=Remote with Protocol=rtsp --
its own rtsp state machine, rtp transport, rtcp control and sdp parser, some
3200 lines. ffmpeg handles rtsp well enough now that a second implementation
earns nothing, and it was already marked deprecated in the interface.

A monitor still configured that way now logs an error naming the exact Source
Path to move to, built by RtspUrlFromRemote with the credentials stripped, so
the message is actionable rather than only a refusal. That helper and its tests
stay; they describe the migration, which still needs describing.

Type=Remote keeps its http protocol. mjpeg streams and snapshot-jpeg cameras
are what that capture method is for and they are unaffected.

Removed: zm_remote_camera_rtsp, zm_rtsp, zm_rtp, zm_rtp_ctrl, zm_rtp_data,
zm_rtp_source and zm_sdp. zm_rtsp_auth stays -- it is included by
zm_remote_camera.h and so is shared with the http camera. Everything named
zm_rtsp_server_* is the restreaming server and is unrelated.

Verified nothing outside the cluster referenced any of it: RtspThread,
RtpSource, RtpCtrlThread, RtpDataThread and SessionDescriptor had no callers
elsewhere in the tree, and RemoteCameraRtsp was named only by zm_monitor.

Build clean; suite 147 cases / 12531 assertions. An rtsp-over-ffmpeg monitor
still captures on hardware: vaapi negotiated, 646 frames into a recorded event,
no errors.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 f22d6d9e4d fix: reopen the decoder when an on-demand monitor resumes
Pause() releases the decoder, so Play() has to open another. It did not, and
an on-demand monitor would have resumed with a null context: Play() re-primes
the camera and restarts the decoder thread without going back through
PrimeCapture(), which is where the only OpenDecoder() call was.

This was introduced by moving ownership to the monitor. Before that the camera
rebuilt its own context inside camera->PrimeCapture(), which Play() does call,
so the gap did not exist.

Neither monitor on the machine this was developed against is on-demand, so the
earlier hardware runs exercised the startup path only and could not have shown
it. Found by following who calls what rather than by testing.

Verified by running an on-demand monitor through a full cycle: hardware
decoding is negotiated twice, once at prime and again at resume after the
pause, with the decoder and analysis threads restarting in between and no
errors. Without the fix the second open is absent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 44f2e70081 refactor: correct the PrimeCapture comment and drop unused rtsp accessors
The comment above PrimeCapture() still described the decoder thread holding a
context it got from camera->getVideoCodecContext(), which the camera would free
and rebuild. The monitor owns that context now, so the first half no longer
described what happens. The second half still does: the decoder thread has to
be joined so it releases the in-flight packet locks in decoder_queue, or stale
entries survive the reconnect and the packetqueue fills and stays full. Kept
that and corrected the rest.

RemoteCameraRtsp declared get_VideoStream, get_AudioStream,
get_VideoCodecContext and get_AudioCodecContext -- four accessors duplicating
the base class's under a different naming convention, none of them called from
anywhere in the tree. Removed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 a69321aeac refactor: drop the decoder state FfmpegCamera no longer has a use for
With the monitor opening the decoder, the camera's hwaccel_name,
hwaccel_device, hw_device_ctx and hw_pix_fmt are written and never read, and
the two hwaccel arguments to its constructor are passed only to be stored.
Remove them rather than leave fields that look like they still configure
something -- the monitor reads the same settings straight from its own members.

The re-arm comment in Close() described setting use_hwaccel back to true so a
transient hardware failure would not pin the monitor to software for the life
of the process. That flag is gone, but the behaviour is not: OpenDecoder()
builds a fresh decoder on every PrimeCapture(), so a reconnect retries hardware
decoding by construction. The reasoning moved there with it.

Close() keeps freeing mVideoCodecContext. It is a base-class member that an
Ffmpeg camera no longer sets, but RemoteCameraRtsp does, and the base is where
that belongs.

Verified on hardware again after the removal: vaapi still negotiates and 652
frames decoded into a recorded event with no errors. Suite 147 cases / 12531
assertions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 69462139ae feat: let the monitor own the decoder instead of the camera
The camera's job is to produce packets; decoding belongs with the thread that
does it. FfmpegCamera opened the video decoder and handed the context out, so
Monitor::Decode() ran against a pointer whose lifetime the camera controlled.
PrimeCapture() already carried a comment about the consequence: the decoder
thread had to be stopped and joined before re-priming, because
camera->PrimeCapture() frees that context and builds another, and a decoder
running against the dying one is unsafe.

Monitor::OpenDecoder() now opens it, after camera->PrimeCapture() has produced
the stream to decode from, and Monitor::CloseDecoder() releases it where the
decoder thread has already been joined -- at the top of PrimeCapture and in
Pause(). The monitor holds the hw device reference and the hw pix fmt storage
alongside it, which is what the context's opaque pointer refers to, so the
lifetime is now one object's business rather than split across two.

Two cases deliberately do nothing:

  Cameras that hand over images rather than packets -- local, vlc, vnc -- have
  no video stream, so there is nothing to open.

  RemoteCameraRtsp opens its own decoder and decodes through it.
  GetVideoCodecContext() falls back to the camera's for that one rather than
  running a second decoder over the same stream. That capture method is
  deprecated and goes in 1.41, and this branch cannot be tested here, so it is
  left as it is rather than changed blind.

Verified on hardware: an rtsp hevc monitor with DecoderHWAccelName=vaapi still
negotiates through the monitor-owned path ("Trying hwdevice vaapi", "Using
vaapi hardware decoding for hevc") and decoded 752 frames into a recorded
event with no errors.

Suite 147 cases / 12531 assertions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5.5 ddc4d67dd4 fix: escape event Cause and Notes in the Events insert refs GHSA-hc5x-7jfw-r692
Event::Event() wrote the event's Cause and Notes into single-quoted
literals of the Events INSERT without escaping them. Both come from
outside the daemon: Cause includes the names of the alarmed zones, which
any Monitors=Edit user can set, and the external trigger's cause and
text, which zmtrigger.pl takes unauthenticated from TCP port 6802. A
zone name could close the literal and fill the rest of the row with a
subquery, copying any value the ZoneMinder database user can read, such
as password hashes, into an event shown in the web UI.

An ordinary apostrophe was enough to break it: the INSERT failed, and
the constructor retries until it succeeds, so it logged the failure
several times a second and the monitor recorded no further events until
zmc was restarted. A zone named "Bob's drive" stopped motion recording.

Escape both, as updateNotes() already does for the same column. While
here, escape the other SQL values built from strings in src/: the
Event_Data detections JSON, the DefaultVideo update, both Tags queries,
the Servers lookup by ZM_SERVER_NAME and the device, path, protocol,
host and port that the zmc monitor-loading queries match on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 20:30:19 -04:00
nicandClaude Opus 5.5 ba0844915e fix: free decoded frames and images once no consumer can read them (#5185)
* fix: free decoded frames and images once no consumer can read them

Packets stay in the packet queue for passthrough's keyframe alignment and
for pre-event frames, but each also kept its decoded AVFrame until it left
the queue, and with SaveJPEGs set (the default) its Image too: ~15 MB per
packet at 5MP. The frames also pinned libavcodec's buffer pool at the
queue's depth. With on-demand decoding and viewers, or a keyframe interval
longer than MaxImageBufferCount, zmc grew to several GB.

- Analyse() releases in_frame, and the y_image view into it, once the
  packet has been analysed; later readers use packet->image. It is kept
  when an encoder has no image to work from.
- PacketQueue::releaseDecoded() frees every decoded copy of packets that
  all iterators have passed and that lie before where an event could still
  start (openEvent's pre-event walk back, to a keyframe for passthrough).
  The compressed packets stay queued.

Event output (capture/analysis JPEGs, snapshot, alarm, video) is unchanged.

refs #4860

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say which reload can widen the window under releaseDecoded refs #4860

The comment said the release boundary can't move back because events only
open on the analysis thread. That holds for events, but a RELOAD action
(zmu --reload) runs Monitor::Reload() on zmc's main loop and can widen
pre_event_video_packet_count or set keep_keyframes without clearing the
queue. Say so, and what an event right after it loses: capture JPEGs for
released passthrough frames; on encode those packets are already gone.
Raised in review of #5185.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: never start an event on packets whose decoded data was released refs #4860

releaseDecoded() frees the images and decoder frames of packets before the
earliest point an event could start, computed with the current pre-event
window. A RELOAD action (zmu --reload) can widen that window, or turn on
keep_keyframes, without clearing the queue. On passthrough the queue still
holds the previous GOP until the next keyframe trims it, so the next event
could walk back into packets already released: its video was complete, but
those frames had no capture JPEGs. On a 15 fps camera with a 30-frame GOP,
widening PreEventCount 5 -> 100 left frames 1-30 without JPEGs in about a
third of the events right after the reload.

get_event_start_packet_it() now treats the first packet at or after
released_before_ as the front of the queue and warns when it stops there.
For passthrough that packet is the keyframe releaseDecoded() stopped on;
after a reload from encode to passthrough it may not be, so the start
moves forward to the next keyframe. With an unchanged window the walk
never reaches the boundary. After a widening reload the next event gets up
to one GOP fewer pre-event frames than before #4860's change, instead of
frames without images.

Raised in review of #5185.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 17:33:20 -04:00
Isaac Connor 8f5a0af862 Merge pull request #5143 from SteveGilvarry/feature/stream-socket-events
Replace the per-monitor media FIFOs with a unix stream socket
2026-09-23 18:17:50 -04:00
Steve GilvarryandClaude Fable 5.1 2f1112cd14 fix: build the stream snapshot from one synchronized view of state and health
RefreshStreamSnapshot read the analysis thread's state member from the
capture thread (through SendStreamHealthEvent) while SetState could be
writing it, and only the health fields were under the mutex. Two threads
could also each build a snapshot and publish them in the wrong order.
SetState now mirrors the state into a field guarded by
stream_event_mutex, and the snapshot is built and published under that
one lock from the mirror and the health fields, so every snapshot is a
consistent view and the last one published is the newest.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-23 15:07:15 +10:00
Steve GilvarryandClaude Fable 5.1 7d9d97f387 fix: apply both stream parameter sets to the stream socket in one generation
Two problems with announcing streams one at a time. SetAudioParams only
bumped the generation when audio had been announced before, so audio
joining a video-only stream was appended to the current generation after
its video HELLO, which the protocol says is the last HELLO of a
generation. And a re-prime that changed both streams bumped twice:
consumers saw, and a connecting consumer was handed, an intermediate
generation pairing the new audio with the old video, which
zm_rtsp_server built a session for and tore down again.

Add StreamSocket::SetStreams(video, audio), which applies the whole set
under one lock: unchanged is a no-op, the first announcement stays in
generation 0, and any change once a video HELLO has gone out - new
parameters, a stream appearing, a stream disappearing - is exactly one
bump with every remaining stream re-announced, audio first. The single
stream setters and the new ClearVideoParams are wrappers over the same
logic, and a null or codec-less parameter set means "no such stream".
PrimeCapture passes both streams in one call.

Tests: audio joining an announced video stream bumps the generation;
SetStreams keeps the initial announcement in generation 0, changes both
streams in one generation with consistent pairing, and drops a video
stream the source no longer has.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-23 15:07:14 +10:00
Isaac ConnorandClaude Opus 5 428c048bac feat: measure the audio level on demand, with a meter in the editor
Reverts the previous commit's always-on measurement. Decoding audio for every
monitor that has it spends CPU on a number almost nothing reads, which is the
wrong trade even though it did solve the chicken and egg of picking a
threshold without ever seeing a level.

Measure when something is actually going to use the reading instead:

 - AudioDetection is on, as before, so nothing changes for a monitor that
   scores on audio; or
 - somebody asked. SharedData gains audio_level_until, a wall clock second
   the capture thread keeps measuring up to. The monitor editor's new level
   meter pushes it forward while it is on screen and the measurement lapses a
   few seconds after the page is left, so nothing has to send a stop and a
   crashed browser cannot leave a monitor decoding forever.

When the reading stops being wanted the decoder is released and the published
level and peak are cleared, so a stale number is not left looking current and
an old peak does not land on the next frame row written.

audio_level_until is carved out of analysis_pad rather than appended, so
SharedData stays 888 bytes and no existing offset moves; the static_asserts,
Memory.pm and Monitor.php are updated together and all three now agree the
field is at +880.

The meter itself is on the audio settings, shown whether or not
AudioDetection is checked, because the level is what you need in order to
choose a threshold. It draws the threshold currently in the input as a mark on
the bar so a reading can be judged against it before saving, and a monitor
whose zmc is not running reads "no reading" rather than a confident 0, which
would be indistinguishable from silence.

Frames.AudioLevel is therefore 0 again on monitors that do not score on audio.
That is what the graph already treats as "no audio data", so it draws no line
rather than a flat one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JpiSWBmtQkR5bcgpHWY4ME
2026-09-20 18:17:44 -05:00
Isaac ConnorandClaude Opus 5 4619258293 feat: measure the audio level whatever AudioDetection is set to
Gating the measurement on AudioDetection made the graph useless for the job
it is most wanted for. AudioThreshold is a per-device number -- the floor on
one camera's mic is nothing like another's -- so it has to be measured before
it can be set, but nothing was measured until it was already set. Enabling
detection with a guessed threshold to find out what the real one should be is
backwards.

The level is now read for every monitor with decodable audio.  AudioDetection
governs only whether crossing the threshold contributes a score, which is
what the setting is named for. shared_data->audio_alarm stays 0 when it is
off, so nothing downstream changes for a monitor that does not want audio
alarms.

Nothing here depends on Analysing either. The measurement is in
Monitor::Capture, which runs on whatever Analysing is set to, and frame rows
come from Event::AddFrame, which a continuously recording monitor reaches
through the RECORDING_ALWAYS path with motion detection off. So a monitor
that only records continuously still gets levels on its rows.

Since Monitor::Capture retries Open on every audio packet until it succeeds,
and that now happens for every monitor with audio rather than the handful with
detection on, AudioDetector remembers a codec it has already failed to find a
decoder for. Without it a stream ZoneMinder cannot decode logs a warning at
the audio packet rate for as long as the monitor runs. A reconnect bringing a
different codec is still tried.

The cost is one audio decode per monitor with audio, where before it was one
per monitor with detection enabled. That is small next to the video path, but
it is not nothing on a box with many cameras.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JpiSWBmtQkR5bcgpHWY4ME
2026-09-20 18:17:44 -05:00
Claude 7502019ecb fix: copy the stream socket path into shm without a truncating strncpy
GCC at -O2 rejects strncpy with a bound equal to the destination size
(-Werror=stringop-truncation), which failed the Release CI build. The
preceding length check already guarantees the path and its terminator
fit, so copy size()+1 bytes with memcpy instead.

refs #5143

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T4UcdJLt1bxwdpcigGxZRD
2026-09-20 01:48:19 +00:00
Claude 21042ba2f7 fix: send audio HELLO first and keep rtsp sessions across a zmc restart
Correct three problems in the stream socket generation tracking added by
the previous review fix-up:

- ClearAudioParams bumped the generation without restarting the video
  sequence or dropping the cached keyframe, so a late joiner received a
  HELLO at generation N+1 followed by a KEYFRAME still stamped N, and
  sequences did not restart as documented. It now does the same full bump
  as SetVideoParams/SetAudioParams.
- zm_rtsp_server rebuilt the xop session whenever the generation changed,
  even with identical codec parameters. Generations restart at 0 when zmc
  restarts, so every zmc restart dropped the RTSP clients; the original
  code kept the session in that case. Unchanged parameters now just adopt
  the new generation without a teardown.
- Deciding whether audio belongs to the current generation by comparing
  per-stream generation numbers raced the two HELLOs of a generation
  (double rebuild when Update() ran between them) and cannot tell a
  producer restart apart. The producer now sends the audio HELLO before
  the video HELLO within a generation (on connect and on every bump, and
  PrimeCapture announces audio before video), so the video HELLO always
  completes a generation's parameter set. The consumer forgets the
  previous generation's HELLOs when a new generation starts and on
  disconnect, and builds only once the video HELLO of the latest
  generation is in. It also records whether audio was announced at build
  time rather than whether a packer was created, so an unsupported audio
  codec no longer triggers a rebuild on every pass.

The ordering guarantee is documented in the protocol header and the
stream socket docs. Tests pin the audio-first order on connect and on a
video reconfigure, and the keyframe drop and sequence restart on audio
removal.

refs #5143

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T4UcdJLt1bxwdpcigGxZRD
2026-09-20 00:36:35 +00:00
Claude 89837a6b40 fix: start the monitor stream socket before capture connects
Address monitor-side stream socket review findings:

- zmc starts the stream socket before the first connect attempt, and
  SendStreamHealthEvent records the health state even when the socket is
  not up yet, so connection/prime faults during startup are observable to
  a consumer instead of being lost until the first successful prime.
- PrimeCapture announces audio whenever the camera has a decodable audio
  stream (Capture forwards audio packets unconditionally), and clears a
  previously announced stream when a re-prime no longer sees it.
- Publish the media stream socket path in the monitor shared-memory
  block (reusing the retired video_fifo_path field as stream_socket_path,
  same offset and size) so consumers discover it without hard-coding the
  convention or reading the producer's zm.conf; the PHP Monitor object
  and the ZoneMinder::Memory Perl module expose the renamed field.
- Move the wall-clock microseconds helper out of zm_monitor.cpp into
  zm_time.h as SystemClockMicros(), where time helpers belong.

refs #5143

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T4UcdJLt1bxwdpcigGxZRD
2026-09-19 23:00:14 +00:00
Steve GilvarryandClaude Fable 5.1 84b1c06430 fix: drop the cached stream socket keyframe when the capture source closes
The keyframe cached for late joiners survived Monitor::Close(). A
consumer connecting while the camera reconnected was primed with a
keyframe from the previous capture session, whose pts can be ahead of
what the new session produces, and with identical stream parameters
there is no generation bump to warn it. Add StreamSocket::InvalidateKeyframe()
and call it from Close(); the next keyframe from the new session fills
the cache again.

Tests: after InvalidateKeyframe() a new consumer gets HELLO and then the
next live packet, with no KEYFRAME replay in between.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 05:12:42 +10:00
Steve GilvarryandClaude Fable 5.1 9570e24265 fix: skip the stream socket HELLO for cameras without an encoded stream
Camera::getVideoStream() creates a stream with codec id NONE for sources
that hand zmc decoded images (V4L2, MJPEG over HTTP, VNC). PrimeCapture
announced that stream anyway, and ParseHello rejects a HELLO without a
codec, so every consumer logged a malformed HELLO warning on each
connect to such a monitor although no media could ever follow. Only
announce a stream that has a codec; the socket still carries lifecycle
events for these monitors.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 05:12:42 +10:00
SteveGilvarryandClaude Fable 5.1 0a392802f8 feat: emit capture-fault and state-change events on the monitor stream socket
Wire the monitor lifecycle events into zmc. Monitor::SetState() replaces
the scattered shared_data->state assignments in Analyse() and connect(),
publishing a state_changed event (with previous and new state id and name)
whenever the analysis state actually changes. Monitor::SendStreamHealthEvent()
emits the capture-fault edges and tracks the active fault for the snapshot;
the snapshot is refreshed on every state or health change and after a
successful prime, so a consumer connecting mid-fault learns current status.

zmc's capture loop emits the six health transitions once per edge:
connection failed/restored around connect(), prime_capture failed/restored
around PrimeCapture(), capture_failed on pre/capture/post failure, and a
single capture_resumed once the pipeline recovers. Because the stream
socket survives camera reconnects, these are observable exactly when media
has stopped. A small mutex guards the health fields shared between the
capture thread (health events) and analysis thread (state events).

Documents the EVENT frame in docs/stream_socket.rst and decodes it in
tools/zm_stream_socket_dump.py. Full build and ctest pass (121 tests).

refs #2875

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 05:02:24 +10:00
SteveGilvarryandClaude Fable 5 94eeec6c2a refactor!: retire fifo path fields from SharedData
Rename video_fifo_path/audio_fifo_path to reserved_path1/2, keeping the
struct layout and 864-byte size unchanged so existing shared memory
mappers (and out-of-tree shm readers) keep working through the
transition. The fields are zeroed at startup as before, scrubbing any
stale path strings left by a pre-upgrade zmc.

The stream socket deliberately publishes nothing via shared memory: its
path is the documented convention PATH_SOCKS/stream_{monitor_id}.sock,
derivable from static config, and codec parameters travel in the HELLO
handshake instead of shm fields.

Perl (Memory.pm) and PHP shared memory maps updated to match by name;
offsets are unchanged.

Tests: full suite passes via ctest; php -l clean on Monitor.php.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-16 05:02:24 +10:00
SteveGilvarryandClaude Fable 5 50aa94cd1c refactor!: remove media FIFO output from zmc
The per-monitor media FIFOs (video_fifo_{id}.{codec} /
audio_fifo_{id}.{codec}) are fully replaced by the monitor stream
socket; their only in-tree consumer, zm_rtsp_server, was ported in the
previous commits. Removes:

- the Fifo writer instance API (open/close/write/writePacket, the
  O_NONBLOCK silent-drop path and the 1MB F_SETPIPE_SZ kernel buffer
  per pipe); the class keeps only the static fifo-creation helpers
  still used by the diagnostic image pipes
- fifo creation in PrimeCapture (including the codec-name-as-file-
  extension discovery hack), the write call sites in Capture (including
  the extradata-before-every-keyframe rewrite - extradata travels in
  the stream socket HELLO), and the Close()/destructor teardown
- the GetVideoFifoPath/GetAudioFifoPath accessors

The shared memory fifo path fields are retired separately in the next
commit. zm_fifo_debug and zm_fifo_stream (diagnostic pipes) are
unrelated features and unchanged.

BREAKING CHANGE: external consumers of the media FIFOs must move to
the stream socket (PATH_SOCKS/stream_{monitor_id}.sock, see
zm_stream_socket_protocol.h).

Tests: full suite passes via ctest; all binaries build clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-16 05:02:24 +10:00
SteveGilvarryandClaude Fable 5 8b0679651e feat: serve monitor media on the per-monitor stream socket
zmc now serves every monitor's compressed media on
PATH_SOCKS/stream_{monitor_id}.sock, alongside the media FIFOs (which a
later change removes). Always on, like zms streaming and zmdc.sock: the
path is a documented convention derived from static config, consumers
connect on demand, and an idle socket costs nothing. No new monitor
option, no shared memory change.

- PrimeCapture() creates and starts the socket once, then (re)applies
  video/audio codec parameters on every prime; a camera reconnect that
  changes parameters bumps the protocol generation and rebroadcasts
  HELLO to connected consumers
- Monitor::Capture() queues each video access unit (with keyframe flag)
  and audio packet by reference; payloads are never copied
- the listener survives Close() so consumers keep their connection
  across camera reconnects; it is freed in the destructor
- the FIFO's write-extradata-before-keyframe hack is not carried over:
  extradata travels in the HELLO handshake

Tests: full suite 98/98 pass via ctest; zmc/zms/zmu/zm_rtsp_server all
build with no new warnings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-16 05:00:44 +10:00
Steve Gilvarry 1316ca3a33 Merge branch 'master' into 5127-packetqueue-iterator-leak 2026-09-12 15:03:28 +10:00
Steve GilvarryandClaude Opus 5 f04302d6fc fix: initialize alarm_actions_fired in declaration order
ad70d5e80 added alarm_actions_fired to the Monitor constructor's
init list between audio_alarm_score and wallclock_timestamps, but
declared the member far later in the class, after linked_monitors.
Members are initialized in declaration order regardless of the order
written here, so gcc rejects it under -Werror=reorder:

  src/zm_monitor.h:767:8: error: 'Monitor::alarm_actions_fired' will
  be initialized after
  src/zm_monitor.h:621:19: error:   'bool Monitor::wallclock_timestamps'

This is a plain bool with a constant initializer, so nothing observable
changes - only the order the entry is written in. Moved it to sit after
linked_monitors, matching where the member is declared.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B5KL9Xbi7K5aGsauLtd8tG
2026-09-12 14:41:08 +10:00
Isaac ConnorandClaude Opus 5 99ae7b8e98 fix: free the event start iterator when openEvent cannot lock its packet fixes #5127
PacketQueue::get_event_start_packet_it() allocates a packetqueue_iterator and
registers it in PacketQueue::iterators. Every path out of Monitor::openEvent()
hands that pointer to the Event, which releases it in ~Event via free_it, except
the one that fails to lock the starting packet. That path returned nullptr and
left the iterator registered for the life of the process.

clearPackets() takes min_iterator_queue_index across all registered iterators and
stops removing at the first packet whose queue_index reaches it. An abandoned
iterator pins that to the front packet, so the trimmer removes nothing on every
invocation, and deletePacket() advances registered iterators onto the packet
after the one it removed, which drags the orphan onto each new front packet so it
can never age out. clear_packets_pending_ then latches true, downgrading the gate
so the futile scan re-runs on every video packet rather than only on keyframes.

The only removal path left is the emergency one-GOP eviction in queuePacket, so
the queue settles into refill a GOP, exceed max_video_packet_count, warn, evict a
GOP, repeat. It is pinned at its cap by construction, which is why the monitor
warns once per GOP at a constant rate for as long as zmc runs and no amount of
idle time or extra headroom recovers it.

Our trigger was an RTSP stream EOF mid-event during a reconnect on an ONVIF
camera. It is a race, so it leaks only when openEvent loses it, and each
occurrence leaks one more iterator.

Add tests covering both halves: that free_it takes an event start iterator back
out of the queue, and what an abandoned one does to trimming until it does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 21:49:34 -04:00
Isaac ConnorandClaude Opus 5 2d6565da1f fix: stop the audio note growing the event's Notes on every frame
Event::updateNotes only inserts into the note set and rewrites the Notes
column each time it gains a string. The audio note carried the live level, so
every distinct reading added another entry and another database write, and the
event ended up recording the whole climb:

  Audio: level 10, level 11, level 12, ... level 78, ...

Measured on this install before the fix: monitor 1 reached 946 bytes of notes
and averaged 117, against 8 to 12 bytes on monitors without audio detection.

The note is now the constant AUDIO_CAUSE, matching the ONVIF and Amcrest notes
a few lines above. The level is still in the Debug line, which is where a
per-frame reading belongs.

Existing events keep their bloated notes. Rewriting recorded history to tidy
up would be worse than leaving it to age out with normal event deletion.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UvTCzCbvGt8xKQRNCSA7o8
2026-09-11 20:13:03 -05:00
Isaac ConnorandClaude Opus 5 ad70d5e80a feat: add an AlarmEnd trigger to monitor actions
Alarm turns a light on when motion starts; nothing turned it back off. The
existing EventEnd is not the answer: the alarm ends when the monitor leaves the
alert state, while the event carries on recording for the rest of its section,
which on a continuous-recording monitor is up to ten minutes later.

Analyse() leaves the alarm condition by three paths and all three fire it: the
normal ALERT to IDLE, a signal change, and the trigger being turned off. The
abnormal two matter most - a light switched on by an alarm must not stay on
because the camera lost signal.

That needs the firing to be paired, so alarm_actions_fired is set when Alarm
fires and cleared by EndAlarmActions. It guards both directions:

  - the three call sites can run back to back, so without it one alarm could
    fire AlarmEnd several times
  - signal loss and trigger off also run on monitors that never alarmed, and an
    unpaired AlarmEnd would switch a light off for an alarm that never happened
  - the ALERT to ALARM re-trigger inside one incident deliberately does not
    re-fire Alarm, so a single AlarmEnd still has to balance it

The migration MODIFYs the enum and appends the value, so stored rows keep their
meaning; appending to an enum does not renumber what is already there.

Tested: 8 assertions over the pairing rule, run standalone because the real
class needs a database and a camera - the ordinary pair, repeated calls firing
once, an unpaired call firing nothing, two alarms pairing independently, and
the re-trigger case. The action test now also requires every trigger name to
round trip through the TriggerOn enum, so an action saved by the editor cannot
load with a trigger the C++ does not recognise and fire at the wrong moment.
Build clean at 1.39.33, Perl 15 files / 249 assertions, ESLint 0 problems,
tests/js 154 assertions, php -l clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UvTCzCbvGt8xKQRNCSA7o8
2026-09-11 20:13:03 -05:00
Isaac ConnorandClaude Opus 5 c20b6a9488 docs: name the release that removes Remote/RTSP support
A deprecation warning without a version attached is one people learn to
scroll past. Both notices now say deprecated as of 1.40, removed in 1.41.

Removal is 1.41 rather than 1.40 because 1.39.x is the development series.
Anyone running stable is on 1.38 and will never see a 1.39.x warning, so
removing in 1.40 would take the feature away in the same release that first
mentions it - no notice at all for the people it affects. Warning in 1.40 and
removing in 1.41 gives stable users one release to migrate.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UvTCzCbvGt8xKQRNCSA7o8
2026-09-11 20:13:03 -05:00