 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/<id>), 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago  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/<id>), 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago |
|
/*
MediaMtx (C++) - H264 helpers (MediaMTX uses mediacommon/pkg/codecs/h264)*/#pragma once
#include <string>
#include <vector>
#include "../../unit/unit.h"
namespace mtx {namespace h264 {
enum NaluType{ NALU_NON_IDR = 1, NALU_IDR = 5, NALU_SEI = 6, NALU_SPS = 7, NALU_PPS = 8, NALU_AUD = 9, NALU_STAP_A = 24, NALU_FU_A = 28};
inline int naluType(const Bytes & n){ return n.empty() ? 0 : (n[0] & 0x1f);}
struct SpsInfo{ int width = 0; int height = 0; int profileIdc = 0; int constraints = 0; int levelIdc = 0;};
bool parseSps(const Bytes & sps, SpsInfo & info);// 4d401f style string for SDP profile-level-id and "avc1.4d401f" codec strings
std::string profileLevelId(const Bytes & sps);// Base64 sprop-parameter-sets ("Z00AH...,aO4...") -> NAL units
std::vector<Bytes> decodeSpropParameterSets(const char * sprop);// Annex-B byte stream (00 00 00 01 start codes)
Bytes toAnnexB(const std::vector<Bytes> & nalus);// Annex-B byte stream -> NAL units (3 or 4 byte start codes; AUD and empty units are dropped)
std::vector<Bytes> splitAnnexB(const uint8_t * data, size_t size);// Length prefixed NAL units (lengthSize 1..4, MP4 / avcC style) -> NAL units
std::vector<Bytes> splitAvcc(const uint8_t * data, size_t size, int lengthSize = 4);// SPS / PPS of an avcC record (libav extradata of MP4 sources) or of Annex-B extradata
std::vector<Bytes> parameterSetsFromExtradata(const uint8_t * data, size_t size, int * avccLengthSize = nullptr);// AVCC: 4 byte big-endian lengths (MP4 samples)
Bytes toAvcc(const std::vector<Bytes> & nalus);// AVCDecoderConfigurationRecord (avcC box payload)
Bytes buildAvcC(const Bytes & sps, const Bytes & pps);
} // namespace h264
} // namespace mtx
|