Datarhei - Dragon Fork: fork of datarhei/core with native WebRTC (WHEP) egress for low-latency streaming. Built with Pion.
Find a file
Zac Gaetano 4d2f11d836 feat(app/webrtc): M3 robustness — error matrix, per-stream index, PATCH, CORS
Major Handler rewrite implementing the design's M3 acceptance
criteria ('5 concurrent viewers, all error paths correct, clean
teardown'):

Multi-viewer correctness:
- streamID -> resourceID -> Peer two-level index (was flat)
- per-stream peer cap alongside total cap, defaults match the
  design's '5–8 viewer' target (8/stream, total from corewebrtc)
- per-peer awaitPeerClose goroutine watches Peer.Done() so ICE
  failures yank the index entry + decrement the counter (no leaks)
- tearDownStreamPeers callback (registered with Subsystem in
  NewHandler) drives all peer closes when the source process stops

Error matrix from design §6:
- 406 on codec mismatch (offer missing H264 or Opus rtpmap)
- 504 on ICE gathering timeout (passthrough from CreatePeerFromSources)
- 204 on DELETE unknown resource (idempotent per WHEP spec; was 404)
- 503 on per-stream cap reached (separate body from total-cap 503)
- 400 on missing/empty body (unchanged)
- 404 on unknown stream (unchanged)

WHEP spec compatibility:
- PATCH /whep/:id/:resource for trickle-ICE
- OPTIONS preflight on every WHEP path
- CORS Allow-Origin/Methods/Headers + Expose-Headers (Location, ETag)
- ETag header on Subscribe response

Defensive nil-peer guards in tearDown / Close paths so a partial
state doesn't panic.

Refactor: 134 -> 341 lines on handler.go but the surface is the
same (NewHandler/Register/Subscribe/Unsubscribe/Close); existing
callers continue to work. Pre-M3 test 'Unsubscribe_404WhenUnknown'
renamed and updated to the new 204 expectation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 11:23:55 +00:00
.github Add linux/arm/v8 build 2026-03-16 09:28:04 +01:00
app feat(app/webrtc): M3 robustness — error matrix, per-stream index, PATCH, CORS 2026-05-03 11:23:55 +00:00
cmd/webrtc-poc feat(webrtc): add -rtp-host flag + TrueNAS Docker deploy 2026-04-17 09:05:37 -04:00
config fix(config): preserve WebRTC section in Config.Clone() 2026-04-17 15:26:11 -04:00
core/webrtc feat(core/webrtc): expose Peer.Done() channel + AddICECandidate 2026-05-03 11:23:55 +00:00
deploy deploy(truenas): Core image + compose for M2 WebRTC rollout 2026-04-17 14:59:49 -04:00
docs docs(m2): implementation plan 2026-04-17 09:49:20 -04:00
encoding/json Add v16.7.2 2022-05-13 19:26:45 +02:00
ffmpeg Add looping_runtime to avstream status 2023-05-05 12:03:48 +02:00
glob Fix memfs concurrent read and write performance 2024-03-15 15:25:25 +01:00
http fix(http/api): carry process WebRTC config through the API DTO 2026-05-03 04:53:25 +00:00
internal Update dependencies 2024-01-12 12:35:07 +01:00
io Fix memfs concurrent read and write performance 2024-03-15 15:25:25 +01:00
log Add WithLevel() to Logger interface 2024-05-29 15:51:51 +02:00
math/rand Fix concurrent accesses 2024-03-15 11:45:50 +01:00
monitor Fix typo in test name 2024-03-14 12:03:38 +01:00
net Fix tests 2023-04-26 09:50:09 +02:00
playout Add v16.7.2 2022-05-13 19:26:45 +02:00
process Fix race condition 2024-01-15 10:42:08 +01:00
prometheus Add GoSRT & improvements (repo-merge) 2022-06-23 22:13:58 +02:00
psutil Fix #10 2023-04-11 15:04:31 +02:00
restream feat(restream): add ProcessHooks for WebRTC subsystem integration 2026-04-17 09:57:14 -04:00
rtmp Don't report EOF as error in RTMP server, update dependency 2024-05-29 16:33:32 +02:00
service Add logging for service 2022-12-27 09:47:59 +01:00
session Fix require positive persist interval 2024-01-12 15:37:51 +01:00
srt Add support for SRTv4 clients 2024-01-12 15:38:32 +01:00
test test(whep-client): add -token flag for JWT-gated /api/v3/whep endpoints 2026-05-03 04:59:08 +00:00
update Don't use deprecated functions from io/ioutil 2022-08-18 10:27:33 +03:00
vendor feat(webrtc): add ICE config helper (Configuration + SettingEngine) 2026-04-17 08:46:27 -04:00
.dockerignore Add v16.8.0 2022-06-03 17:21:52 +02:00
.editorconfig Add v16.7.2 2022-05-13 19:26:45 +02:00
.gitignore feat(webrtc): add package skeleton and typed errors 2026-04-17 08:43:57 -04:00
build.sh Add v16.7.2 2022-05-13 19:26:45 +02:00
CHANGELOG.md Update changelog, bump version to 16.16.0 2024-06-07 11:37:25 +02:00
Dockerfile Add ubuntu build for vod branch 2024-09-24 11:47:25 +02:00
Dockerfile.bundle Mod exposes ports 2022-09-29 10:10:05 +02:00
Dockerfile.test Mod updates build-files 2023-02-23 10:17:39 +01:00
go.mod feat(webrtc): add ICE config helper (Configuration + SettingEngine) 2026-04-17 08:46:27 -04:00
go.sum feat(webrtc): add ICE config helper (Configuration + SettingEngine) 2026-04-17 08:46:27 -04:00
LICENSE Add v16.8.0 2022-06-03 17:21:52 +02:00
main.go Use config locations for import and ffmigrage 2023-01-03 11:45:10 +01:00
Makefile Bump version to 16.15.0, update changelog 2024-04-03 14:27:58 +02:00
mime.types Add v16.7.2 2022-05-13 19:26:45 +02:00
NOTES.md docs: add Dragon Fork WebRTC egress design spec and M1 plan 2026-04-17 08:40:05 -04:00
README.md Update README 2023-02-23 10:23:32 +01:00
run.sh Add test if import and migrate script exist 2024-04-04 11:10:10 +02:00
SECURITY.md Create SECURITY.md 2022-06-01 22:48:21 +02:00

Core

dsdsds

License: Apache2 CodeQL tests codecov Go Report Card PkgGoDev Gitbook

The datarhei Core is a process management solution for FFmpeg that offers a range of interfaces for media content, including HTTP, RTMP, SRT, and storage options. It is optimized for use in virtual environments such as Docker. It has been implemented in various contexts, from small-scale applications like Restreamer to large-scale, multi-instance frameworks spanning multiple locations, such as dedicated servers, cloud instances, and single-board computers. The datarhei Core stands out from traditional media servers by emphasizing FFmpeg and its capabilities rather than focusing on media conversion.

Objectives of development

The objectives of development are:

  • Unhindered use of FFmpeg processes
  • Portability of FFmpeg, including management across development and production environments
  • Scalability of FFmpeg-based applications through the ability to offload processes to additional instances
  • Streamlining of media product development by focusing on features and design.

What issues have been resolved thus far?

Process management

  • Run multiple processes via API
  • Unrestricted FFmpeg commands in process configuration.
  • Error detection and recovery (e.g., FFmpeg stalls, dumps)
  • Referencing for process chaining (pipelines)
  • Placeholders for storage, RTMP, and SRT usage (automatic credentials management and URL resolution)
  • Logs (access to current stdout/stderr)
  • Log history (configurable log history, e.g., for error analysis)
  • Resource limitation (max. CPU and MEMORY usage per process)
  • Statistics (like FFmpeg progress per input and output, CPU and MEMORY, state, uptime)
  • Input verification (like FFprobe)
  • Metadata (option to store additional information like a title)

Media delivery

  • Configurable file systems (in-memory, disk-mount, S3)
  • HTTP/S, RTMP/S, and SRT services, including Let's Encrypt
  • Bandwidth and session limiting for HLS/MPEG DASH sessions (protects restreams from congestion)
  • Viewer session API and logging

Misc

  • HTTP REST and GraphQL API
  • Swagger documentation
  • Metrics incl. Prometheus support (also detects POSIX and cgroups resources)
  • Docker images for fast setup of development environments up to the integration of cloud resources

Docker images

  • datarhei/core:latest (AMD64, ARM64, ARMv7)
  • datarhei/core:cuda-latest (Nvidia CUDA 11.7.1, AMD64)
  • datarhei/core:rpi-latest (Raspberry Pi / OMX/V4L2-M2M, AMD64/ARMv7)
  • datarhei/core:vaapi-latest (Intel VAAPI, AMD64)

Quick start

  1. Run the Docker image
docker run --name core -d \
    -e CORE_API_AUTH_USERNAME=admin \
    -e CORE_API_AUTH_PASSWORD=secret \
    -p 8080:8080 \
    -v ${HOME}/core/config:/core/config \
    -v ${HOME}/core/data:/core/data \
    datarhei/core:latest
  1. Open Swagger http://host-ip:8080/api/swagger/index.html

  2. Log in with Swagger Authorize > Basic authorization > Username: admin, Password: secret

Documentation

Documentation is available on docs.datarhei.com/core.

License

datarhei/core is licensed under the Apache License 2.0