Commit Graph
120 Commits
Author SHA1 Message Date
Jash 5e0d6afaf4 fix: send pre-scaled frames as built when scale or zoom changes refs #3681 2026-08-26 18:22:39 +05:30
Jash e48ae03275 perf: scale during colour conversion in zms playback fixes #3681 2026-08-26 11:15:19 +05:30
Jash f5cfbcd54c fix: make MonitorStream playback state shared with the command thread atomic fixes #4939 2026-08-16 16:46:47 +05:30
Isaac ConnorandClaude Opus 5 e75a8b9654 fix: only unlink the command socket while holding the lock
openComms() logs an error but carries on to bind() when it cannot open or
flock() the .lock file, so a zms can be serving without holding the lock. In
that state the unlink in closeComms() could remove a socket belonging to the
zms that does hold the lock, leaving it unreachable.

Guard the unlink on lock_fd >= 0. Leaking the socket file when we never held
the lock is no worse than the behaviour before the unlink was added.

Expand the comment to spell out that this path is the command socket rather
than the .lock file, that our successor unlinks it itself on the way to bind(),
and why the unlink has to precede releasing the lock.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-03 08:32:01 -04:00
Isaac ConnorandClaude Opus 5 c93b8d7de5 fix: unlink the zms command socket on exit refs #5029
closeComms() left /var/lib/zoneminder/sock/zms-NNNNNNs.sock behind, and the
only thing that ever removed it was the unlink() before bind() in a later zms
that happened to draw the same connkey. Socket files accumulated indefinitely.

web/ajax/stream.php uses file_exists() on that path to decide whether zms is
listening, and waits up to a second for it to appear before giving up. A file
left by an exited zms defeats that wait: the check passes immediately, the
sendto() gets ECONNREFUSED, and the command is reported as failed even though
the new zms was about to bind. genConnKey() draws from six digits, so a page
cycling monitors every five seconds reuses a key well within an hour.

Unlink while we still hold the flock. A second zms with the same connkey blocks
on flock(LOCK_EX) in openComms() before it unlinks and binds, so it cannot have
created its own socket yet and we can't delete a file belonging to it. The lock
file itself is still left alone, since another zms may be waiting on it.

This is best effort: zms killed by a signal still leaves the socket behind. In
that case the process is usually still running, so the file being there is not
wrong.

Also reset lock_fd after closing it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-03 08:03:13 -04:00
copilot-swe-agent[bot]andconnortechnology 2dfb79975d fix: prevent segfault when MPEG stream codec fails to open
Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>
2026-03-05 02:15:08 +00:00
Isaac ConnorandClaude Opus 4.6 29541c9aa7 fix: prevent segfault in MonitorStream::processCommand from shared memory race
The command processor thread could crash dereferencing monitor->shared_data
or monitor->trigger_data while the main thread was in loadMonitor() calling
disconnect() which munmaps shared memory and nulls those pointers.

Three fixes:
- Guard against null monitor at the top of processCommand
- Add monitor_mutex to StreamBase, held during disconnect/connect in
  loadMonitor and during shared memory reads in processCommand, so the
  command thread cannot access shared memory while it is being remapped
- Initialize status_data.analysing and status_data.score in the
  !ShmValid branch where they were previously sent uninitialized

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:19:20 -05:00
Isaac ConnorandClaude Opus 4.5 2d01a38bdc fix: correct file descriptor error checks in StreamBase
- Change lock_fd error check from <= 0 to < 0 since open() returns -1
  on error and 0 is a valid file descriptor
- Use -1 consistently as invalid fd marker
- Fix close check from > 0 to >= 0 to handle fd 0 correctly

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:44:50 -05:00
Isaac Connor cd3e2b5d1e fix: address bugs in videostore and stream
zm_videostore.cpp:
- Fix incorrect size passed to av_stream_add_side_data (was sizeof(int32_t),
  should be sizeof(int32_t)*9 for display matrix)
- Fix null pointer dereference of chosen_codec_data in PASSTHROUGH mode
  (use video_in_ctx->pix_fmt instead)

zm_stream.cpp:
- Fix logic error in last_crop initialization check (OR should be AND)
2026-02-02 23:26:20 -05:00
Isaac Connor 4757d711ef Change various cases of int img_buffer_size to size_t 2025-07-19 14:18:32 -04:00
Aaron Kling c4683d90a9 Format code using astyle google format
Commands used:
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.cpp
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.h
2024-03-26 13:43:58 -05:00
Isaac Connor 3bca776214 Handle change of res/colours in zms by reloading the monitor object. 2023-12-08 10:14:38 -05:00
Isaac Connor 599d21050d Only log error when not sigpipe 2023-12-07 09:15:41 -05:00
Isaac Connor 6dc0e88988 Turn common Errors into Info beacuse they happen all the time when reloading a monitor 2023-12-06 14:40:29 -05:00
Isaac Connor 89f90dc5fa Don't output the boundary if we aren't streaming. Single jpegs don't need it and I think something was complaining about it. 2023-12-03 09:24:27 -05:00
Alejandro Criado-Pérez 543683aa4c Corrections on cpp and h files 2023-08-13 01:27:19 +02:00
Isaac Connor 2773385262 Remove redundanct frame_mod=1 2023-04-06 19:02:24 -04:00
Isaac Connor 4d716f26ee Make shm is not connected a debug... otherwise we really spam the logs. Useful error messages can go at a higher level 2022-11-16 09:07:36 -05:00
Isaac Connor 2d9bc06170 Set a 1 second timeout one the communications socket, so that our blocking commandQueue check will check zm_terminate every now an then 2022-10-26 13:09:43 -04:00
Isaac Connor 8558ade8f1 Merge branch 'master' into misc_fixes 2022-08-25 18:33:06 -04:00
Isaac Connor aa030afcb6 Make checkCommandQueue it's own thread, meaning we use blocking I/O and will still respond when it takes forever to send a jpeg. Make warning about broken stream into a Debug. The signal doesn't set zm_terminate fast enough. 2022-08-15 17:58:56 -04:00
Doug Nazar 9385127b50 Consolidate temp_img_buffer resizing and use correct delete[] operator 2022-07-30 22:27:41 -04:00
Isaac Connor 356678f164 Use ints when comparing maxfps and effectivefps so that small decimal differences in fps don't matter. 2022-07-13 18:47:27 -04:00
Isaac Connor 2cb85492e9 Clean out cruft from prepareImage. Fixes not sending scaled image. 2022-05-11 10:05:48 -04:00
Isaac Connor 3804f6c66c Finally fix centering of zoomed image 2022-05-07 11:37:58 -04:00
Isaac Connor a8583086ce Rework zooming. We now crop first, then scale to retain image fidelity as much as possible. More work to be done but is working better than the old code and I think is more readable. This also makes Box a class member instead of a static 2022-05-06 11:45:12 -04:00
Isaac Connor 5aca811d5d Don't delete the socket file because another zms might have opened it and be waiting on the lock. This should remove a ton of zms error messages 2022-04-28 19:16:22 -04:00
Isaac Connor 063f27e5f7 Debug log when failed sending 2022-04-28 16:42:16 -04:00
Isaac Connor 39d45e527c Switch from DecodingEnabled to DecodingOption. Implement the logic in ::Decode. 2022-03-28 17:44:44 -04:00
Isaac Connor bf4d2a82d6 handle when maxfps is not specified 2022-03-27 12:17:00 -04:00
Isaac Connor cd2c977ed8 Merge branch 'master' into replace_function_concept 2022-02-16 14:25:38 -05:00
Isaac Connor 67563737c3 Rework to remove static temp_img_buffer. Is now a class member. Must be allocated as needed. 2022-02-16 14:16:46 -05:00
Isaac Connor fd3a70172d Merge branch 'master' into multistream 2022-01-10 17:51:50 -05:00
Isaac Connor b406bf8fd1 remove last_send_image_width/height. Not really useful or relevant 2022-01-10 17:36:49 -05:00
Isaac Connor 657fc5cad5 convert function to relevant capturing/analysing 2022-01-07 11:52:19 -05:00
Isaac Connor 60d2186ff4 Move from SystemTimePoint to SteadyTimePoint where possible. Implement MAXFPS command. Change the logic of calculating sleep time to make more sense. Get rid of frame_mod use in favour of calculating when then next frame should get sent and just waiting till then. 2021-12-16 16:35:20 -05:00
Isaac Connor 854d11ce9d List the connkey that isn't open, differentiate logs a bit to help debug. 2021-12-15 09:11:55 -05:00
Isaac Connor 848a537a0f Fix zms giving 500 code instead of displaying error image due to not having sent the headers yet. 2021-08-23 18:10:31 -04:00
Isaac Connor 1766bbdfcd Handle the case when the monitor doesn't exist more gracefully and not crash. Fixes #3316 2021-07-08 10:07:01 -04:00
Peter Keresztes Schmidt e1fe53338c BaseStream: Convert internals to std::chrono 2021-06-13 11:29:59 +02:00
Peter Keresztes Schmidt a9ad5c5eee Build: Promote libavcodec to a required dependency
FFmpeg is an integral component of ZM. Promote the appropriate libraries to required dependencies.
This reduces the possible build configurations greatly and thus maintenance burden.
2021-06-05 14:25:54 +02:00
Peter Keresztes Schmidt 8f685b3d66 Box+Poly: Remove direct accessors to {Hi,Lo}{X,Y} 2021-05-16 16:42:58 +02:00
Peter Keresztes Schmidt f85e3765db Box: Remove unnecessary constructors 2021-05-16 16:42:58 +02:00
Peter Keresztes Schmidt 68bedfe48f Fix logging format string mismatches
* Remove SZFMTD format macro and use %zu instead for size_t. %zu is understood by every compiler nowadays.
2021-04-30 00:26:24 +02:00
Isaac Connor cfe51d7349 Disconnect if we call loadMonitor a second time. 2021-04-12 15:59:31 -04:00
Isaac Connor 1bfc61a5b7 change log level to debug when monitor is not decoding 2021-03-23 10:32:59 -04:00
Isaac Connor 14ef8336b9 If ffmpeg and decoding Disabled don't stream 2021-03-16 20:10:00 -04:00
Isaac Connor c0242e7369 Fix memleak when connect fails 2021-03-16 13:28:00 -04:00
Peter Keresztes Schmidt d9568a98c0 Drop zm_thread which has been replaced by STL implementations 2021-03-04 10:55:46 +01:00
Peter Keresztes Schmidt f43507dce0 Use the power of smart pointers to manage Monitor instances 2021-02-07 21:20:45 +01:00