Embed MediaMTX (WebRTC live view + recording) in kernelModuleEmbedVideo #28

Closed
ClaudeAI wants to merge 0 commits from feature/embed-video-webrtc into master
ClaudeAI commented 3 hours ago
Collaborator

Summary

Brings the MediaMTX functionality into la_mojo itself: kernelModuleEmbedVideo now serves the WebRTC live view and records video, so the external mediamtx service is no longer needed. Includes the standalone C++ MediaMtx project from feature/mediamtx-cpp.

Live view and recording

  • kernelModuleEmbedVideo hosts a WHEP server (:8889/stream_<node>/whep, same URLs as MediaMTX, so the dashboard works unchanged) and one media path per camera stream, with fMP4 segment recording.
  • module_eve.live_mode selects what is streamed:
    • off
    • camera H264 passthrough
    • re-encoded processed frames with time stamp / label / logo overlays (streamLiveEncoder)
  • Other settings: port, recording, segment length, bitrate, fps and ICE servers (live_* columns, optional, with defaults).
  • Shared code lives in lib/data/media/mtx (codecs, stream, HTTP, recorder, WebRTC server). Projects/MediaMtx builds against it as a standalone replacement.
  • kernelHelperMediaMTX stops the external mediamtx.service and keeps indexing recorded segments.

Embed video fixes

  • Settings changes from the web UI are now applied: the module reloads when its module_eve row changes. Before, this check was unreachable, and a reload stopped the streams without restarting them.
  • Logo: images without an alpha channel no longer crash, and the logo is drawn only when it fits in the frame. Runtime state no longer overwrites the DB copy, which caused endless reloads.
  • Time stamp: negative X/Y are measured from the right/bottom edge, and the background box fits the text.
  • Font face and line type are sanitised before cv::putText.

Alarm clips: video recorded only once

  • With recording on (live_mode on and live_record = 1), alarm clips come from the recorder's fMP4 segments, and the old encoder is not started.
  • The scratch is in shared memory (/dev/shm), so it is kept as small as possible. An alarm moves the segments within 5 s before and 5 s after it to the kernel, the same way the old encoder's clips were handed over; the kernel copies them into the report folder and deletes them from the scratch. A closed segment no alarm wants is deleted as soon as a later alarm cannot want it (5 s pre-alarm + 2 s), so only the segment being recorded and, for a few seconds, the last closed one are in <scratch>/stream_<node>. Left-overs from a crash are deleted at start-up, and stopping the recording deletes everything. Reports/History gets H264 .mp4 clips, which Mojo_Web already plays. The event is bound to its segment with the frame offset.
  • With live_record = 0, the old encoder makes the clips as before.
  • Decode-only stream handlers no longer start the encoder thread. That thread left an empty segment file per stream in the scratch folder.
  • VIDEO_SEGMENT_INFO in EVT_CAPTURE_DONE is now a heap copy that the receiver (mojoKernel) deletes. Before, it was a memcpy of a struct with std::vector members, and the copy leaked.
  • Fixed m_mEncodedProtector: it was unlocked every frame without being locked.

Build and DB

  • makefile and la_mojo.vpj get the new sources and -ldatachannel (all configs except LRF_Proxy_ONLY).
  • Distro/database/db_tools.php creates the live_* columns on fresh installs. Existing databases are upgraded by Mojo_Web lib/upgrade_database.php (companion PR in Mojo_Web, branch feature/eve-live-columns).

Testing

  • Built CFG=Debug86 against libdatachannel and live555.
  • Fake RTSP camera into la_mojo, then the WHEP live view in Chromium in both passthrough and re-encode modes, with overlays visible in re-encode.
  • Recorded fMP4 segments play in the browser.
  • Changing settings from the web UI triggers exactly one reload, with no reload loop, and the live view reconnects.
  • Logo upload from a JPEG (no alpha) works.
  • Alarm clips (10 s segments): an alarm at 5.1 s into a segment gives that segment as a clip with the event at frame 77, plus the next segment (post-alarm). Both are copied into the report with videos / events_2_videos rows. Segments without an alarm are deleted about 7 s after they close; after a graceful stop (SIGTERM) /dev/shm/argus/video_scratch is empty, and left-overs of a killed run are deleted at the next start. With live_record = 0 the old encoder path still delivers its clip. la_mojo stops cleanly.
  • MediaMtx standalone: camera loss and reconnect, API, SIGHUP reload; ASan + UBSan clean.

Notes

  • kernelModuleEmbedVideo.h and serverConf.h changed layout, and the makefile does not track header dependencies: do a clean rebuild (make -B).
  • Requires libdatachannel on the target.

Generated with Claude Code

https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16

## Summary Brings the MediaMTX functionality into la_mojo itself: `kernelModuleEmbedVideo` now serves the WebRTC live view and records video, so the external `mediamtx` service is no longer needed. Includes the standalone C++ MediaMtx project from `feature/mediamtx-cpp`. **Live view and recording** - `kernelModuleEmbedVideo` hosts a WHEP server (`:8889/stream_<node>/whep`, same URLs as MediaMTX, so the dashboard works unchanged) and one media path per camera stream, with fMP4 segment recording. - `module_eve.live_mode` selects what is streamed: - off - camera H264 passthrough - re-encoded processed frames with time stamp / label / logo overlays (`streamLiveEncoder`) - Other settings: port, recording, segment length, bitrate, fps and ICE servers (`live_*` columns, optional, with defaults). - Shared code lives in `lib/data/media/mtx` (codecs, stream, HTTP, recorder, WebRTC server). `Projects/MediaMtx` builds against it as a standalone replacement. - `kernelHelperMediaMTX` stops the external `mediamtx.service` and keeps indexing recorded segments. **Embed video fixes** - Settings changes from the web UI are now applied: the module reloads when its `module_eve` row changes. Before, this check was unreachable, and a reload stopped the streams without restarting them. - Logo: images without an alpha channel no longer crash, and the logo is drawn only when it fits in the frame. Runtime state no longer overwrites the DB copy, which caused endless reloads. - Time stamp: negative X/Y are measured from the right/bottom edge, and the background box fits the text. - Font face and line type are sanitised before `cv::putText`. **Alarm clips: video recorded only once** - With recording on (`live_mode` on and `live_record = 1`), alarm clips come from the recorder's fMP4 segments, and the old encoder is not started. - The scratch is in shared memory (/dev/shm), so it is kept as small as possible. An alarm moves the segments within 5 s before and 5 s after it to the kernel, the same way the old encoder's clips were handed over; the kernel copies them into the report folder and deletes them from the scratch. A closed segment no alarm wants is deleted as soon as a later alarm cannot want it (5 s pre-alarm + 2 s), so only the segment being recorded and, for a few seconds, the last closed one are in `<scratch>/stream_<node>`. Left-overs from a crash are deleted at start-up, and stopping the recording deletes everything. Reports/History gets H264 `.mp4` clips, which Mojo_Web already plays. The event is bound to its segment with the frame offset. - With `live_record = 0`, the old encoder makes the clips as before. - Decode-only stream handlers no longer start the encoder thread. That thread left an empty segment file per stream in the scratch folder. - `VIDEO_SEGMENT_INFO` in `EVT_CAPTURE_DONE` is now a heap copy that the receiver (mojoKernel) deletes. Before, it was a `memcpy` of a struct with `std::vector` members, and the copy leaked. - Fixed `m_mEncodedProtector`: it was unlocked every frame without being locked. **Build and DB** - `makefile` and `la_mojo.vpj` get the new sources and `-ldatachannel` (all configs except LRF_Proxy_ONLY). - `Distro/database/db_tools.php` creates the `live_*` columns on fresh installs. Existing databases are upgraded by Mojo_Web `lib/upgrade_database.php` (companion PR in Mojo_Web, branch `feature/eve-live-columns`). ## Testing - Built `CFG=Debug86` against libdatachannel and live555. - Fake RTSP camera into la_mojo, then the WHEP live view in Chromium in both passthrough and re-encode modes, with overlays visible in re-encode. - Recorded fMP4 segments play in the browser. - Changing settings from the web UI triggers exactly one reload, with no reload loop, and the live view reconnects. - Logo upload from a JPEG (no alpha) works. - Alarm clips (10 s segments): an alarm at 5.1 s into a segment gives that segment as a clip with the event at frame 77, plus the next segment (post-alarm). Both are copied into the report with `videos` / `events_2_videos` rows. Segments without an alarm are deleted about 7 s after they close; after a graceful stop (SIGTERM) /dev/shm/argus/video_scratch is empty, and left-overs of a killed run are deleted at the next start. With `live_record = 0` the old encoder path still delivers its clip. la_mojo stops cleanly. - MediaMtx standalone: camera loss and reconnect, API, SIGHUP reload; ASan + UBSan clean. ## Notes - `kernelModuleEmbedVideo.h` and `serverConf.h` changed layout, and the makefile does not track header dependencies: do a clean rebuild (`make -B`). - Requires libdatachannel on the target. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
ClaudeAI added 8 commits 3 hours ago
5837ef8a8a
MediaMtx: C++ replacement for the MediaMTX parts la_mojo uses
39700129ec
MediaMtx: use dr_frucht's JsonCpp instead of nlohmann/json
13387b3f0d
Embed MediaMTX functionality (WebRTC live view + recording) in kernelModuleEmbedVideo
aa4afffe1c
la_mojo.vpj: add embedded MediaMTX sources and libdatachannel
19ef839b19
db_tools.php: module_eve live_* columns for embedded MediaMTX
0e8279e22a
Embed video: apply DB setting changes, robust logo and time stamp
da5b4754db
Restore CRLF line endings on files that use them in master
ClaudeAI added 1 commit 3 hours ago
7b343a9988
Alarm clips from the recorder segments; record video only once
ClaudeAI added 1 commit 1 hour ago
2183c3a4d6
Alarm clips: keep /dev/shm clean, move only the clips bound to an alarm
ClaudeAI added 1 commit 53 minutes ago
ba7c152861
Distro: do not install MediaMTX; disable a mediamtx service left by an older package
ClaudeAI closed this pull request 39 minutes ago
This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.