Give the stream API core-owned types

Command and Event no longer carry voelin-stream's types. voelin-core owns
StreamInfo, ViewerInfo, StreamSetup, StreamKind, ViewerState, EndReason and
LeaveReason (stream_types.rs) with u16 client ids, a viewer's SRTP profile
as its name and its codec as voelin_media::Codec; stream.rs converts at the
boundary. Command::SetSrtpProfiles takes profile names, which the stream
task parses.

EncodedFrame, LayerSpec, LayerId and LayerSet move into voelin-media
(stream::EncodedFrame, layer); voelin-stream depends on it and re-exports
them, so the engine, the stream sessions and voelinctl share one type. The
crate is now a plain dependency of voelin-core (feature media keeps the
module and WHIP), and its str0m feature is gone with str0m always there.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-14 15:01:24 +03:00
1 parent b0f95a384f
commit da372dfe10
28 files changed
+798 -342

No files matched your search

+25 -5
View File
@@ -71,10 +71,10 @@ fuzz/ cargo-fuzz targets
| `voelin-gateway-proto`, `voelin-gateway` (`tsgw`) | Companion service for server admins: identity-challenge auth, permission-mirroring authorization, presence stream, chat relay, SQLite history, WebSocket + JSON (`tsgw.v1+json`) | done |
| `voelin-store` | Identities, bookmarks, settings, chat history (dedupe, paging, sync cursors, where each chat was read), contacts, secrets (keyring / Android Keystore); versioned schema | done |
| `voelin-audio` | Capture/playback, Opus, echo cancellation, resampling, jitter buffer, mixer, VAD/push-to-talk; the voice packet types (`TalkerId`, `VoicePacket`, `EncodedVoice`), so it depends on no voice transport | v0 (no AEC yet) |
| `voelin-stream` | TS6 stream commands, JSON signalling, str0m peer connections, host/STUN candidates, streamer/viewer sessions, frame-source seam | sessions + transport |
| `voelin-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, event bus, command API, chat history, the gateway's features, audio settings and volumes, streams on TS6, files, avatar and icon cache, pokes, offline messages, contacts; `media` module (capture → encoder → stream, stream → decoder) | done |
| `voelin-stream` | TS6 stream commands, JSON signalling, str0m peer connections, host/STUN candidates, streamer/viewer sessions, frame-source seam; its frame and simulcast layer types are `voelin-media`'s | sessions + transport |
| `voelin-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, event bus, command API, chat history, the gateway's features, audio settings and volumes, streams on TS6, files, avatar and icon cache, pokes, offline messages, contacts; `media` module (capture → encoder → stream, stream → decoder); the stream types of its API are its own (`stream_types`, see Streams) | done |
| `voelin-ui` | Slint UI and the desktop binary: streams panel, viewer, share dialog, audio / hotkey / codec settings | done (desktop) |
| `voelin-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs | done (desktop hardware encoders through FFmpeg loaded at runtime, not run on a GPU yet; MediaCodec not run on a device yet) |
| `voelin-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs; the frame and simulcast layer types of a stream (`stream::EncodedFrame`, `LayerSpec`, `LayerId`, `LayerSet`) | done (desktop hardware encoders through FFmpeg loaded at runtime, not run on a GPU yet; MediaCodec not run on a device yet) |
| `voelin-platform` | Global hotkeys, notifications, paths, crash reports, notices | done |
| `voelin-android` + `android/` | Android library + Gradle/Kotlin app (foreground services for voice and screen capture); see [android.md](android.md) | builds, not yet run on a device |
@@ -265,8 +265,9 @@ Transport details of our stream (`voelin-stream`):
browsers, so our order decides. `dtls::VoelinDtlsProvider` wraps str0m's
dimpl DTLS with that order; dimpl is vendored in `third_party/dimpl` with a
patch for it (`VOELIN-PATCH.md`). The order is a setting
(`Streams::set_srtp_profiles`, `Command::SetSrtpProfiles`) and applies to
new connections.
(`Streams::set_srtp_profiles`, `Command::SetSrtpProfiles`, which takes the
profiles' names; the stream task parses them) and applies to new
connections.
- **Media that does not get through**: a connection can come up and carry
nothing (an SRTP library that negotiates a profile it cannot use, a
streamer without an encoder for the codec the answer took). Each peer
@@ -326,6 +327,25 @@ Transport details of our stream (`voelin-stream`):
(`Streams::set_layers`, `Command::SetStreamLayers`). Without layers the
stream has one layer 0 at the setup's bitrate and every viewer gets it.
The stream types the UI sees are `voelin-core`'s own (`stream_types.rs`, also
under `voelin_core::stream`): `StreamInfo`, `ViewerInfo`, `StreamSetup`,
`StreamKind`, `ViewerState`, and why a stream ended (`EndReason`,
`LeaveReason`). They have plain fields: client ids are `u16`, a viewer's SRTP
profile is its name (`AEAD_AES_128_GCM`), its video codec is
`voelin_media::Codec`. The frame and layer types in the API
(`stream::EncodedFrame`, `LayerSpec`, `LayerId`, `LayerSet`) are
`voelin-media`'s, which `voelin-stream` uses as they are. The conversion to
and from `voelin-stream`'s own types happens in one place, `stream.rs`: the
stream task converts what `Streams` reports, and what the UI asks for
(`StreamSetup`, the profile names) on the way in, so the stream session's
own types (its `StreamInfo`, `ViewerInfo`, `StreamSetup`, `SrtpProfile`,
`EndReason`) no longer show in `Command` and `Event`. Still
`voelin-stream`'s in the engine's API are the peer and media vocabulary:
`PeerConfig` (in `VoiceOptions`), `MediaFrame` (the frames of watched
streams), `VideoFormat` and `VideoCodec` (on the `StreamSink`),
`FrameSource`, `SyntheticSource`; they move out of the core with the stream
task (the decoupling plan's next steps).
In `voelin-core` a stream task per voice connection runs `Streams`; the voice task
forwards `MessageEvent`s and sends the requests. Encoders push frames through
the `StreamSink` of `StreamState::Live`; received frames of watched streams go
+5 -3
View File
@@ -20,10 +20,12 @@ described in [studio.md](studio.md).
| `FrameRef { width, height, timestamp, pixels: PixelsRef }` | the same with borrowed planes (`PlaneRef { data: &[u8], stride }`), e.g. a mapped capture buffer; `VideoFrame::view()`, `FrameRef::to_frame()` |
| `AudioBuffer { samples, channels, timestamp }` | interleaved `f32`, 48 kHz |
| `convert::to_rgba(&frame, out, stride)`, `to_rgba_vec`, `to_i420`, `psnr` | BT.601 limited range (the WebRTC default). `to_rgba` writes straight into a Slint `SharedPixelBuffer<Rgba8Pixel>` (`make_mut_bytes()`, stride `width * 4`) |
| `Codec` | `Vp8`, `Vp9`, `H264`, `Av1`; `FromStr` for SDP/MIME names; `From`/`TryFrom` `str0m::format::Codec` with feature `str0m` |
| `Codec` | `Vp8`, `Vp9`, `H264`, `Av1`; `FromStr` for SDP/MIME names; `From`/`TryFrom` `str0m::format::Codec` |
| `VideoEncoder` | `encode(&frame, force_keyframe) -> Vec<EncodedFrame>`; `encode_with(&frame, force_keyframe, &mut |EncodedChunk| ..)` hands out the encoder's own buffer (no copy); `set_bitrate(bps)` (libvpx: in place, no keyframe), `set_fps`, `speed()`, `codec()`, `backend()`; `gpu_alignment()` / `encode_gpu(&GpuFrame, ..)` for encoders that take frames in GPU memory (VA-API; MediaCodec's surface path on Android) |
| `GpuFrame` | a picture in GPU memory (an NV12 VA-API surface), made by `ffmpeg::GpuConverter` from a captured DMA-BUF; `width`, `height`, `timestamp`, `at(timestamp)` (the same surface at another time). On Android `rendered(width, height, timestamp)`: a screen picture the virtual display renders straight into MediaCodec's input surface, only its size and time travel |
| `EncodedFrame { data, keyframe, pts_90khz }` | one frame for `Peer::write` |
| `EncodedFrame { data, keyframe, pts_90khz }` | one frame as an encoder makes it |
| `stream::EncodedFrame { kind, time, data, layer, keyframe }` | one frame of a stream, ready to send: the encoder's frame with its media kind, RTP time (90 kHz video, 48 kHz Opus) and simulcast layer. What `StreamSink::send` and `Command::SendStreamFrame` take; `voelin-stream` passes the same type on to its peers |
| `LayerSpec`, `LayerId`, `LayerSet` (`layer`) | the simulcast layers of a stream: size or scale, frame-rate cap, start, maximum and minimum bitrate, RID; `LayerSet` is a set of layer ids (e.g. those waiting for a keyframe). Owned here, used as they are by `voelin-stream` and the engine's API |
| `VideoDecoder` | `decode(&[u8]) -> Option<VideoFrame>` (timestamp zero; the caller knows the RTP time); `decode_into(&[u8], &mut VideoFrame) -> bool` reuses the frame's buffers (FFmpeg's decoders: no allocation per picture); `conceals_errors()` (FFmpeg's H.264 and HEVC: frames after a lost one still decode) |
| `EncoderConfig { fps, bitrate_bps, keyframe_interval, content, threads, speed }` | resolution follows the frames; a size change restarts with a keyframe; `threads` is a maximum (0: all CPUs but one), still capped at one per 320x240 pixels; `speed: None` adapts libvpx `cpu-used` to the encode time |
| `Codecs` | `new()` (probes FFmpeg / MediaCodec once per process), `builtin()` (compiled-in codecs only), `with_openh264(lib)`, `with_preference(EncoderPreference)` / `set_preference`, `decoders()` (viewer order: every codec one decoder here decodes), `decoders_for(codec)` (that codec's decoders, best first: the ladder), `with_decoder_preference(DecoderPreference)` / `set_decoder_preference`, `with_decoder(factory)` (an application's decoder, first), `encoders()` / `encoder_codecs()` (streamer order under the preference), `encoders_for(&pref)`, `new_decoder(codec)` (the first of the ladder that opens), `new_decoder_with(codec, DecoderBackend)`, `new_encoder(codec, config)`, `new_encoder_preferring(codec, config, &pref)`, `new_encoder_with(codec, backend, config)`, `pick_encoder(&accepted)`, `is_hardware(backend)`, `report()`; cheap to clone |
@@ -125,7 +127,7 @@ viewer: Engine::subscribe_frames ─ VideoPipeline (thread) ─ VideoDecoder
portal maps it, and a conversion that fails turns the GPU path off for
the capture (`StreamerStats::gpu_error`). Nothing is allocated per frame
on this path either (the surfaces' frames are recycled).
- Simulcast: `StreamerConfig::layers` (`voelin_stream::LayerSpec`; empty:
- Simulcast: `StreamerConfig::layers` (`voelin_media::LayerSpec`; empty:
one layer 0 at `bitrate_kbps`) are all encoded, each with its own encoder
at `output_size()` of the source, its own frame-rate cap (`max_fps`,
paced by timestamps) and its share of the CPUs. Frames carry `layer` and