feat: cross-stream motion trigger for dual-lens cameras (fixes #334)#336
Merged
feat: cross-stream motion trigger for dual-lens cameras (fixes #334)#336
Conversation
Add a motion_trigger_source field to stream_config_t that allows a stream's ONVIF motion-based recording to be triggered by motion events detected on a different stream. This is specifically designed for dual-lens cameras such as the TP-Link/Tapo C545D, where the fixed wide-angle lens exposes ONVIF motion events but the PTZ tracking lens does not. By setting motion_trigger_source on the PTZ stream to the name of the fixed-lens stream, both recordings start and stop together. Changes: - include/core/config.h: add char motion_trigger_source[MAX_STREAM_NAME] to stream_config_t - db/migrations/0039_add_motion_trigger_source.sql: new migration adding motion_trigger_source TEXT DEFAULT '' column to streams table - include/database/db_embedded_migrations.h: embed migration 0039, bump EMBEDDED_MIGRATIONS_COUNT to 39 - src/database/db_streams.c: include motion_trigger_source in all INSERT, UPDATE and SELECT queries with correct column index enums - src/video/onvif_motion_recording.c: after queuing a motion event for the primary stream, propagate the same event (start or end) to every stream whose motion_trigger_source matches the current stream name - src/web/api_handlers_streams_get.c: expose motion_trigger_source in all three GET endpoints (list, single, full) - src/web/api_handlers_streams_modify.c: parse motion_trigger_source in both POST (create) and PUT (update) stream handlers Closes #334
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Addresses Codecov patch coverage gap (was 20.37%, 43 uncovered lines) across four changed files. test_db_streams.c — 4 new tests (covers db_streams.c missing lines): - test_motion_trigger_source_defaults_empty - test_motion_trigger_source_round_trip - test_motion_trigger_source_update - test_motion_trigger_source_in_get_all test_cross_stream_motion_trigger.c — new Layer 3 test binary (covers onvif_motion_recording.c cross-stream propagation block): - test_process_motion_event_null_stream_returns_error - test_process_motion_event_no_linked_streams - test_process_motion_event_propagates_to_linked_stream - test_process_motion_event_end_propagates_to_linked_stream - test_process_motion_event_unregistered_source_no_crash test_api_handlers_system.c — 2 new tests (covers api_handlers_streams_get.c and api_handlers_streams_modify.c new lines): - test_handle_get_streams_includes_motion_trigger_source - test_handle_put_stream_parses_motion_trigger_source CMakeLists.txt — register test_cross_stream_motion_trigger as Layer 3 target
|
I have to admit I don't know where and how to put this configuration:
Edit Stream->Recording Settings-Recording Mode:
lightnvr.ini under [api_detection] also requires a URL Please advise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements cross-stream motion triggering to address the dual-lens camera use-case raised in #334 (TP-Link/Tapo C545D and similar cameras where one lens provides ONVIF events and the other PTZ lens does not).
A new
motion_trigger_sourcefield on each stream allows it to be slaved to another stream's ONVIF motion events. When the source stream detects motion (start or end), the same event is automatically propagated to every stream that lists it as its trigger source.How it works
motion_trigger_sourceon the PTZ stream to the exact name of the Fixed Wide stream.process_motion_event("C545D-Fixed", true/false, ...).process_motion_eventnow scans all configured streams and re-queues the event for any stream whosemotion_trigger_source == "C545D-Fixed"-- in this case the PTZ stream.Files changed
include/core/config.hmotion_trigger_source[MAX_STREAM_NAME]tostream_config_tdb/migrations/0039_add_motion_trigger_source.sqlinclude/database/db_embedded_migrations.hsrc/database/db_streams.csrc/video/onvif_motion_recording.cprocess_motion_event()src/web/api_handlers_streams_get.cmotion_trigger_sourcein all three GET endpointssrc/web/api_handlers_streams_modify.cmotion_trigger_sourcein POST (create) and PUT (update) handlersUsage (C545D example)
After adding both streams, slave the PTZ stream to the Fixed Wide stream via the API:
Both streams must have ONVIF motion recording enabled. The PTZ stream's
pre_buffer_secondsandpost_buffer_secondssettings apply as normal to its triggered recordings.Known limitation
As noted in the original issue: if the moving object leaves the Fixed Wide's field of view while the PTZ is still tracking it, the Fixed Wide sends a motion-end event which begins the PTZ stream's post-buffer countdown. The post-buffer provides a configurable grace period before the recording actually stops.
Testing
Pull Request opened by Augment Code with guidance from the PR author