ReviewOS

also looking at this

home-lang/home

feat(media): add bounded PCM capture, owned snapshots and A/V streaming

#917
Merged chris wants to merge feat/pcm-av-streaming into main
11 files +683 -0
8 days ago

Capture consumers need bounded audio ownership, repeatable asynchronous pre-roll snapshots and streaming A/V output. Add an opt-in, header-checked ALSA S16LE capture adapter, a fixed PCM timeline queue, streaming MJPEG/AVC/HEVC + PCM Matroska and soft recording rotation policy. Export the modules without changing the older recorder abstraction.

The PCM timeline supports consuming sample-clipped output, non-consuming window cursors, and cloneWindow for independent minimal owned copies that can outlive the live source. Rolling input validates before evicting whole oldest blocks to satisfy sample and descriptor limits; its retention floor lets an encoded video ring select a covered keyframe. Original-clock chunk endpoints preserve fractional sample phase across wrap and replay. Cloning handles a wrapped block with all 4096 source descriptors occupied and frees partial allocations. Invalid/oversized/overlapping input leaves history untouched. Only cloning/initialization allocates; rolling/consuming/window operations do not.

The ALSA adapter uses monotonic status plus BOOTTIME conversion and anchored sample counting, surfaces measured error, and fails explicitly on XRUN/disconnect or >100ms skew. No implicit microphone access, subprocesses, FFmpeg, file-sized buffers or resampling is introduced. Input bounds and hardware acceptance gaps are documented in packages/video/STREAMING_AV.md.

Validation: seven PCM allocation/wrap/clipping/owned-copy/eviction tests, Matroska track/interleave/I/O-poison tests and rotation threshold tests pass on Zig 0.15.2 and Home's 0.17 development toolchain locally; targeted pickier passes. Dedicated Linux x86_64/aarch64 workflow compiles ALSA with strict warnings and opens only the explicit null test device. zig-camera integration validates circular and delayed A/V, frozen snapshots surviving source close, splits/rotation, independent FAAD2/AVFoundation AAC sample-count/waveform checks and video decoding. Physical microphone latency, drift and camera synchronization remain unmeasured.

11 changed files on the files tab, with 0 review threads.

Sign in to comment on this pull request.