Commit Graph
1 Commits
Author SHA1 Message Date
SteveGilvarryandClaude Fable 5 b46be59622 feat: add StreamSocket unix-socket media server class
Per-monitor media stream server for the wire protocol added previously:
a poll()-driven listener thread serving multiple consumers at once over
PATH_SOCKS/stream_{monitor_id}.sock.

Memory and blocking behaviour:
- each message is serialized once and shared across all client queues;
  media payloads are reference-counted via av_packet_clone, no copies
- header and payload are written with writev, never concatenated
- the producer (capture thread) never blocks: per-client queues are
  bounded by bytes and message count; on overflow the oldest non-control
  messages are dropped for that client only, observable as sequence gaps
  and in STATS; clients making no progress are disconnected
- the latest keyframe access unit is cached (refcount only) and replayed
  to late joiners after HELLO for immediate first-frame rendering

Parameter changes (SetVideoParams/SetAudioParams) bump the generation,
reset sequences and rebroadcast HELLO. Peers are checked via SO_PEERCRED
against ZM_STREAM_SOCKET_ALLOWED_UIDS; sockets are chmod 0660 with group
ZM_STREAM_SOCKET_GROUP. Stop() sends BYE so consumers can distinguish
shutdown from failure.

Tests: 8 new Catch2 test cases (lifecycle/permissions, HELLO-first
ordering, late-joiner keyframe replay, queue overflow with sequence-gap
and STATS accounting, stalled-vs-live client isolation, generation bump,
BYE on stop, allowed-uids parsing). Full suite: 98/98 pass via ctest.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-16 05:00:44 +10:00