Skip to main content

Module recording_sink

Module recording_sink 

Source
Expand description

Unix-socket H.264 recording fan-out for external capture tools. Unix-socket video fan-out for external recording.

Frames are intercepted at the delivery layer (not inside each encoder), so the tap works uniformly for every full-frame encoder. The pixelflux wire header is skipped so consumers receive a plain elementary stream that is directly muxable: Annex-B for H.264 and H.265, a temporal-unit OBU stream for AV1 (each unit opened by a temporal delimiter), and IVF for VP8 and VP9, whose raw frames carry no framing of their own.

The tap must never perturb the live viewer transport, and it never copies frame bytes: stripe payloads are Arc-shared, so the encode thread only clones a handle into a bounded per-client channel drained by a dedicated writer thread. A slow or stalled recorder blocks nothing but itself and is dropped once its queue overflows. A newly connected client arms [RecordingSink::should_force_idr] so the next encode emits an IDR it can decode from.

Structs§

ClientHandle 🔒
The sink’s handle to one connected recorder: the feed end of its bounded queue, a kill switch for its writer thread, and how many frames it has been sent (the IVF frame index). The socket itself is owned solely by that writer thread.
QueuedFrame 🔒
A queued frame: the container bytes the stream needs ahead of it (an IVF file or frame header, an AV1 temporal delimiter; usually nothing), the Arc-shared payload, and the byte offset where the recordable stream starts (past the wire header, or 0 when the payload is bare).
RecordingSink
Unix-socket fan-out that broadcasts every encoded video frame to connected consumers.

Constants§

ACCEPT_POLL_INTERVAL 🔒
How often the non-blocking accept loop retries when no client is waiting.
CLIENT_QUEUE_CAP 🔒
Per-client backlog bound. A recorder that falls this far behind is dropped rather than allowed to grow memory or push back on the shared encode thread.
WRITE_TIMEOUT 🔒
Per-write timeout on a client stream; a stalled write surfaces as a soft error that write_all_frame retries, keeping the writer thread responsive to teardown.

Functions§

stream_prefix 🔒
The container bytes a client’s stream needs ahead of its indexth frame: an IVF file header (on the first frame) and frame header for VP8 and VP9, a temporal delimiter for an AV1 unit that does not open with one, nothing for the Annex-B codecs. The IVF header’s time base is one frame at fps, which the frame index counts in.
write_all_frame 🔒
Write one whole frame to a recorder’s socket, resuming across the soft timeouts a slow reader induces so a partial NAL or OBU is never left behind. Aborts if stop is set (the client was dropped by RecordingSink::write_frame) or a hard error occurs.