Watch
1
Fork
You've already forked afogados-video
0
0

Latest commit

maotovisk
f3b4ce2 2026-11-20 04:23:56 -03:00 4 commits

afogados-video

The WHIP/WHEP forwarder behind afogados.com's streams: the part of Broadcast Box that afogados uses, rewritten small. One publisher per stream key, any number of viewers, packets forwarded as they are (no transcoding, no mixing). Built on Pion.

The afogados API is its only client: it proxies every signaling request and keeps stream keys secret, so this service has no accounts, web UI, chat, webhooks, stream profiles or simulcast layer selection. Why, and what it costs compared with Broadcast Box: docs/study.md.

API

Drop-in for the Broadcast Box endpoints the afogados API calls (BROADCAST_BOX_BASE_URL).

Request Answer
POST /api/whip + Authorization: Bearer <key>, SDP offer 201, SDP answer, Location: /api/whip/{id}. 409 while the key already has a live publisher
POST /api/whep + Authorization: Bearer <key>, SDP offer 201, SDP answer, Location: /api/whep/{id}. Viewers may connect before the publisher and stay across publisher changes
PATCH /api/{whip,whep}/{id}, application/trickle-ice-sdpfrag 204. Candidates only: ICE restarts are refused
DELETE /api/{whip,whep}/{id} 200
GET /api/status?key=<key> {"streamKey","motd","viewers","isOnline","streamStart"}, or 404 when nothing uses the key. Without key: 400 (there is no list of streams, it would hand out their keys)
GET /healthz 200

With viewers the server takes the DTLS server role and picks AES-GCM for SRTP where the viewer has it; a viewer's NACKs are answered from one history per stream.

The media codec lines follow Broadcast Box (H.264, H.265, VP9, AV1, Opus). The Afogados API rewrites viewers' H.265 offers to match. WHIP also negotiates RTX when a publisher offers it. The relay checks for missing publisher packets every 20 ms so a repair can reach desktop viewers within their 100 ms reorder window on a low-latency connection.

Configuration

Variable Default
HTTP_ADDRESS :8080 Signaling. Put it behind a TLS reverse proxy
UDP_MUX_PORT 3000 All UDP media, every session, one port
UDP_GSO on One segmented send per frame per viewer (Linux UDP GSO). Turns itself off where the kernel or the route refuses it; off sends packet by packet
TCP_MUX_ADDRESS off ICE-TCP fallback for networks that block UDP, e.g. :3000
NAT_1_TO_1_IP none Public IP(s) to advertise when the host only has private addresses
NETWORK_TYPES udp4,tcp4 Add udp6,tcp6 for IPv6
INTERFACES all but loopback and container bridges Comma-separated interface names to gather on
MAX_SDP_BYTES 262144 Offer and trickle body limit
PPROF_ADDRESS off e.g. 127.0.0.1:6060 for go tool pprof
LOG_LEVEL info debug logs every connection state change

Logs name streams by a hash of their key, never the key.

Running

docker compose up -d --build   # see compose.yaml: host networking, open UDP_MUX_PORT in the firewall

Development

go test -race ./...            # codec checks + end to end with Pion publishers and viewers over loopback
scripts/bench.sh 0 50 100 200  # CPU per viewer count, ffmpeg publisher, needs ffmpeg with the WHIP muxer

cmd/whepload opens N WHEP viewers, discards the media and reports frame arrival gaps and sequence holes (-cm: viewers without AES-GCM). cmd/whipload publishes a synthetic H.264-shaped stream at a chosen bitrate, cut into packets like libwebrtc or like OBS (-shape), with padding-only probes (-pad).