From 5837ef8a8a354728f34146941e0a115aeb2b4fd1 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 17:04:34 +0000 Subject: [PATCH 1/2] MediaMtx: C++ replacement for the MediaMTX parts la_mojo uses New project Projects/MediaMtx, in MediaMTX's module layout (internal/core, conf, stream, staticsources/rtsp, servers/webrtc, recorder, api, ...): - RTSP pull of the cameras with live555 (H264, TCP/UDP), reconnect after errors or when no data arrives for --readTimeout - WebRTC WHEP on :8889 with libdatachannel, the MediaMTX URLs (POST /stream_N/whep, PATCH/DELETE /stream_N/whep/), so the dashboard works as is - recording as fragmented MP4 segments (no transcoding), playable in browsers, MediaMTX file names; a fragment is flushed every --recordPartDuration - no mediamtx.yml: command line options + a paths file (SIGHUP reload) + the v3 paths API (add / patch / replace / delete, written back to the file) - log lines in the MediaMTX format that kernelHelperMediaMTX parses Tested with a GStreamer RTSP camera and Chromium (WHEP, recordings), camera loss / reconnect, API, SIGHUP; ASan + UBSan clean. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16 --- Projects/MediaMtx/.gitignore | 3 + Projects/MediaMtx/LICENSE.mediamtx | 21 + Projects/MediaMtx/README.md | 112 ++++ Projects/MediaMtx/internal/api/api.cpp | 290 ++++++++++ Projects/MediaMtx/internal/api/api.h | 48 ++ .../MediaMtx/internal/codecs/h264/h264.cpp | 360 ++++++++++++ Projects/MediaMtx/internal/codecs/h264/h264.h | 53 ++ Projects/MediaMtx/internal/conf/conf.cpp | 515 +++++++++++++++++ Projects/MediaMtx/internal/conf/conf.h | 84 +++ Projects/MediaMtx/internal/core/core.cpp | 131 +++++ Projects/MediaMtx/internal/core/core.h | 39 ++ Projects/MediaMtx/internal/core/path.cpp | 119 ++++ Projects/MediaMtx/internal/core/path.h | 75 +++ .../MediaMtx/internal/core/pathManager.cpp | 110 ++++ Projects/MediaMtx/internal/core/pathManager.h | 37 ++ Projects/MediaMtx/internal/logger/logger.cpp | 121 ++++ Projects/MediaMtx/internal/logger/logger.h | 53 ++ .../internal/protocols/httpp/httpServer.cpp | 393 +++++++++++++ .../internal/protocols/httpp/httpServer.h | 74 +++ .../MediaMtx/internal/recorder/fmp4Writer.cpp | 415 +++++++++++++ .../MediaMtx/internal/recorder/fmp4Writer.h | 58 ++ .../MediaMtx/internal/recorder/recorder.cpp | 120 ++++ .../MediaMtx/internal/recorder/recorder.h | 42 ++ .../internal/servers/webrtc/session.cpp | 349 +++++++++++ .../internal/servers/webrtc/session.h | 74 +++ .../internal/servers/webrtc/webrtcServer.cpp | 285 +++++++++ .../internal/servers/webrtc/webrtcServer.h | 49 ++ .../staticsources/rtsp/rtspSource.cpp | 543 ++++++++++++++++++ .../internal/staticsources/rtsp/rtspSource.h | 63 ++ Projects/MediaMtx/internal/stream/stream.cpp | 160 ++++++ Projects/MediaMtx/internal/stream/stream.h | 98 ++++ Projects/MediaMtx/internal/unit/unit.h | 34 ++ Projects/MediaMtx/main.cpp | 14 + Projects/MediaMtx/makefile | 60 ++ Projects/MediaMtx/mediamtx.paths.example | 6 + Projects/MediaMtx/mediamtx.service.example | 15 + 36 files changed, 5023 insertions(+) create mode 100644 Projects/MediaMtx/.gitignore create mode 100644 Projects/MediaMtx/LICENSE.mediamtx create mode 100644 Projects/MediaMtx/README.md create mode 100644 Projects/MediaMtx/internal/api/api.cpp create mode 100644 Projects/MediaMtx/internal/api/api.h create mode 100644 Projects/MediaMtx/internal/codecs/h264/h264.cpp create mode 100644 Projects/MediaMtx/internal/codecs/h264/h264.h create mode 100644 Projects/MediaMtx/internal/conf/conf.cpp create mode 100644 Projects/MediaMtx/internal/conf/conf.h create mode 100644 Projects/MediaMtx/internal/core/core.cpp create mode 100644 Projects/MediaMtx/internal/core/core.h create mode 100644 Projects/MediaMtx/internal/core/path.cpp create mode 100644 Projects/MediaMtx/internal/core/path.h create mode 100644 Projects/MediaMtx/internal/core/pathManager.cpp create mode 100644 Projects/MediaMtx/internal/core/pathManager.h create mode 100644 Projects/MediaMtx/internal/logger/logger.cpp create mode 100644 Projects/MediaMtx/internal/logger/logger.h create mode 100644 Projects/MediaMtx/internal/protocols/httpp/httpServer.cpp create mode 100644 Projects/MediaMtx/internal/protocols/httpp/httpServer.h create mode 100644 Projects/MediaMtx/internal/recorder/fmp4Writer.cpp create mode 100644 Projects/MediaMtx/internal/recorder/fmp4Writer.h create mode 100644 Projects/MediaMtx/internal/recorder/recorder.cpp create mode 100644 Projects/MediaMtx/internal/recorder/recorder.h create mode 100644 Projects/MediaMtx/internal/servers/webrtc/session.cpp create mode 100644 Projects/MediaMtx/internal/servers/webrtc/session.h create mode 100644 Projects/MediaMtx/internal/servers/webrtc/webrtcServer.cpp create mode 100644 Projects/MediaMtx/internal/servers/webrtc/webrtcServer.h create mode 100644 Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.cpp create mode 100644 Projects/MediaMtx/internal/staticsources/rtsp/rtspSource.h create mode 100644 Projects/MediaMtx/internal/stream/stream.cpp create mode 100644 Projects/MediaMtx/internal/stream/stream.h create mode 100644 Projects/MediaMtx/internal/unit/unit.h create mode 100644 Projects/MediaMtx/main.cpp create mode 100644 Projects/MediaMtx/makefile create mode 100644 Projects/MediaMtx/mediamtx.paths.example create mode 100644 Projects/MediaMtx/mediamtx.service.example diff --git a/Projects/MediaMtx/.gitignore b/Projects/MediaMtx/.gitignore new file mode 100644 index 00000000..554c0a32 --- /dev/null +++ b/Projects/MediaMtx/.gitignore @@ -0,0 +1,3 @@ +Debug/ +Release/ +Asan/ diff --git a/Projects/MediaMtx/LICENSE.mediamtx b/Projects/MediaMtx/LICENSE.mediamtx new file mode 100644 index 00000000..50bbbd83 --- /dev/null +++ b/Projects/MediaMtx/LICENSE.mediamtx @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 aler9 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Projects/MediaMtx/README.md b/Projects/MediaMtx/README.md new file mode 100644 index 00000000..155766b8 --- /dev/null +++ b/Projects/MediaMtx/README.md @@ -0,0 +1,112 @@ +# MediaMtx (C++) + +A C++ replacement for the parts of [MediaMTX](https://github.com/bluenviron/mediamtx) that la_mojo uses: + +* **RTSP pull** of the camera streams (live555), H264 video, TCP or UDP, automatic reconnect +* **WebRTC / WHEP** playback in the browser on port 8889 (libdatachannel) - the same URLs as MediaMTX: + `POST http://:8889/stream_N/whep`, so `mojo_dashboard.js` works unchanged +* **Recording** as fragmented MP4 segments (the camera's H264 as it is, no transcoding) that a browser + plays with `