diff --git a/README.md b/README.md index 4b9f4eb..de134b1 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,12 @@ Done so far (milestones M0–M4 and the first part of M5 of [the plan](docs/arch - `crates/tsc-gateway` (`tsgw`) + `tsc-gateway-proto`: companion gateway for server admins. Users log in with their TeamSpeak identity and get presence, channel chat and history without joining voice, limited by their server permissions ([admin guide](docs/gateway-admin.md)) -- `crates/tsc-core`: client engine; sessions merge voice, gateway and query sources, route chat, run audio +- `crates/tsc-core`: client engine; sessions merge voice, gateway and query sources, route chat, run audio; + the media pipeline for streams (capture → VP8 + Opus → stream, stream → decoder) - `crates/tsc-ui` (`tsc-desktop`): Slint desktop app: servers, channel tree with talking indicators, chat tabs (own channel via voice, other channels via relay), connect / observe invisibly, mute, push-to-talk + (in the window and as a global hotkey), audio settings with a level meter, per-client volume, and on + TeamSpeak 6 streams: watch in a viewer, share the screen with sound - `crates/tsc-stream`: TeamSpeak 6 streams: stream commands and notifications, JSON signalling, WebRTC peers (str0m) with host and STUN candidates. A live test streams VP8 + Opus between two clients through a TS6 server @@ -49,12 +52,14 @@ Done so far (milestones M0–M4 and the first part of M5 of [the plan](docs/arch relay chat and the gateway on both - `fuzz/`: cargo-fuzz targets for packets, commands and the license chain -Screen sharing has its protocol and transport layer (`tsc-stream`); capture, codecs and the UI -for it are in progress. No Android build yet. +Screen sharing works between our clients through a TeamSpeak 6 server (VP8 video, Opus audio); +interop with the official TeamSpeak 6 client is not verified yet. No Android build yet. | Connected with voice | Observing invisibly through the gateway | |---|---| | ![voice](docs/screenshots/desktop-voice.png) | ![observe](docs/screenshots/desktop-observe.png) | +| **Watching a stream** | **Sharing the screen** | +| ![viewer](docs/screenshots/desktop-stream-viewer.png) | ![share](docs/screenshots/desktop-share-dialog.png) | ## Try it @@ -71,6 +76,10 @@ cargo run -p tsctl -- connect 127.0.0.1:9988 --nick me repl # interactive chat cargo run -p tsctl -- connect 127.0.0.1:9988 --nick me voice send --tone 440 cargo run -p tsctl -- connect 127.0.0.1:9988 --nick ear voice record out.wav +# Streams (TeamSpeak 6): share the test pattern (or --source x11), watch and decode it +cargo run -p tsctl -- connect 127.0.0.1:9988 --nick eye stream watch --save-frame shot.png & +cargo run -p tsctl -- connect 127.0.0.1:9988 --nick me stream start --synthetic --auto-accept + # ServerQuery (dev password tsc-dev-admin): invisible presence and relay chat cargo run -p tsctl -- observe ssh 127.0.0.1:10022 --secret tsc-dev-admin --allowlisted cargo run -p tsctl -- relay ssh 127.0.0.1:10022 --secret tsc-dev-admin --allowlisted --channel 1 @@ -85,9 +94,14 @@ scripts/it-smoke.sh # all of the above, on both servers Other commands: `tsctl identity new`, `tsctl versions`, `tsctl connect listen|chat|raw`. `tsctl --help` lists all options. +Development switches of the desktop app (environment variables): `TSC_DATA_DIR` (database), +`TSC_AUTOCONNECT=voice|observe`, `TSC_SCREENSHOT=` (with `TSC_SCREENSHOT_DELAY`), +`TSC_DEMO_STREAM=1` (a local test stream in the viewer, no server needed), +`TSC_OPEN=share|settings[:]|about|client`, `TSC_AUTOWATCH=1`, `TSC_AUTOSHARE=test-pattern`. + Building on Linux needs the ALSA headers (`libasound2-dev`), fontconfig and xkbcommon headers for the UI (`libfontconfig1-dev libxkbcommon-dev`), plus CMake and a C compiler for -the bundled libopus. +the bundled libopus; for streams also libvpx and PipeWire (see [docs/media.md](docs/media.md#build-requirements)). ## License diff --git a/docs/architecture.md b/docs/architecture.md index 57ed344..137b72b 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -67,10 +67,10 @@ fuzz/ cargo-fuzz targets | `tsc-store` | Identities, bookmarks, settings, chat cache, secrets (keyring / Android Keystore) | done | | `tsc-audio` | Capture/playback, Opus, echo cancellation, resampling, jitter buffer, mixer, VAD/push-to-talk | v0 (no AEC yet) | | `tsc-stream` | TS6 stream commands, JSON signalling, str0m peer connections, host/STUN candidates, streamer/viewer sessions, frame-source seam | sessions + transport | -| `tsc-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, event bus, command API, streams on TS6 | done (streams with synthetic frames) | -| `tsc-ui` | Slint UI and the desktop binary | done (no streams yet) | -| `tsc-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs | planned | -| `tsc-platform` | Global hotkeys, notifications, paths | planned | +| `tsc-core` | Engine: runtime, per-server sessions, merge of voice/gateway/query sources, event bus, command API, audio settings and volumes, streams on TS6; `media` module (capture → encoder → stream, stream → decoder) | done | +| `tsc-ui` | Slint UI and the desktop binary: streams panel, viewer, share dialog, audio / hotkey / codec settings | done (desktop) | +| `tsc-media` | Screen and system-audio capture backends (PipeWire portal, X11, Windows Graphics Capture, Android MediaProjection), video codecs | done (Android and hardware encoders planned) | +| `tsc-platform` | Global hotkeys, notifications, paths, crash reports, notices | done | | `tsc-android` + `android/` | Android library + Gradle/Kotlin app (foreground services for voice and screen capture) | planned | ## Merging sources @@ -95,9 +95,20 @@ channel. Its tests drive two instances through a fake relay server. In `tsc-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 -to `Engine::subscribe_frames`, not the event bus. `tsc-stream::FrameSource` is -the seam for capture and encoders (`tsc-media`); `SyntheticSource` stands in -for tests and `tsctl stream start --synthetic`. +to `Engine::subscribe_frames`, not the event bus. The audio of watched streams +goes straight to the session's audio thread, which mixes it like a talker +with its own volume (`Command::SetStreamVolume`). + +`tsc-core::media` (feature `media`) connects this to `tsc-media`: +`Streamer` captures (screen, window, portal or the test pattern, plus system +audio), encodes with the codec of our offer (VP8 by default; the offer carries +only the codec we encode, since every viewer gets the same frames) and Opus, +and feeds the `StreamSink`, honouring keyframe requests. `Viewer` decodes a +watched stream on its own thread (skipping to the next keyframe after losses +and asking for one) and hands pictures to the UI, which keeps only the newest +(`Latest`). `EncodedSource` wraps a `Streamer` as a `tsc-stream::FrameSource` +for `tsctl stream start`; `SyntheticSource` (fake VP8 bytes) remains for +tsc-stream's own tests. ## Milestones diff --git a/docs/audio.md b/docs/audio.md index b66c796..af035c3 100644 --- a/docs/audio.md +++ b/docs/audio.md @@ -67,6 +67,30 @@ measure the end-to-end latency: | +200 ppm | 73 / 131 ms | 112 ms | 125 ms | | -200 ppm | 67 / 95 ms | 82 ms | 84 ms | +## Settings, levels and volumes + +The engine keeps one `AudioSettings` for all sessions (`Command::SetAudioSettings`; +each new audio thread starts with it) and applies changes live. The desktop app +stores them under the setting `audio` and shows them on its settings page: +devices, transmit mode (push-to-talk, voice activation, continuous), the voice +activation threshold, echo cancellation, noise suppression and its level, +automatic gain, microphone gain, output volume and the playback buffer. + +The audio thread reports the loudest 10 ms level since the last report about +ten times a second (`Event::InputLevel`, with whether voice is sent), which the +settings page shows as a meter with the threshold. Without a voice connection, +`Command::TestMicrophone` opens the microphone for the meter alone. + +Per-client volume and mute are local (`SetClientVolume`, `SetClientMuted`); the +app keeps them by unique id and sends them again when the client shows up. Client +ids are reused, so the session forgets the settings of clients that left. +Watched streams play through the same mixer under made-up client ids (counting +down from 65535) with their own volume (`SetStreamVolume`). + +Push-to-talk works with the button in the window and a global hotkey +(`tsc_platform::HotkeyManager`: the portal on Wayland, XInput2 on X11, a hook on +Windows), configurable as e.g. `Ctrl+Shift+T`. + ## Devices Devices are selected by cpal's stable id (`host:device`, e.g. `alsa:hw:1,0`); diff --git a/docs/media.md b/docs/media.md index 4469277..d8626ae 100644 --- a/docs/media.md +++ b/docs/media.md @@ -38,6 +38,40 @@ while let Some(frame) = frames.recv().await { } ``` +## The pipeline in `tsc-core` (`media` module) + +``` +streamer: ScreenCapture ─ VideoEncoder (codec of our offer) ─┐ + AudioCapture ─ 20 ms stereo Opus (128 kbit/s) ─────┴─ MediaSink: StreamSink / EncodedSource +viewer: Engine::subscribe_frames ─ VideoPipeline (thread) ─ VideoDecoder ─ picture callback ─ Latest + stream audio ─ session audio thread (mixer, own volume) ─ speakers +``` + +- `Streamer::start(&codecs, StreamerConfig)` starts capturing right away (the + portal asks the user then), so a cancelled dialog never starts a stream; + frames are encoded only after `attach(sink)`, i.e. once the stream is live. + The encoder runs at the setup's bitrate; a viewer's keyframe request (on + the sink) forces a keyframe, and is kept until the encoder produced one. + Audio follows the capture clock across gaps. With the test pattern + (`SourceId::Synthetic`) the audio is a quiet sine tone. The portal's restore + token is available afterwards (`restore_token()`) to store. +- `peer_config(&codecs, config)` makes a viewer accept only what we decode + and a streamer offer only the codec it encodes (VP8 unless changed): all + viewers get the same frames, and a viewer picks from the offer. +- `VideoPipeline` decodes on its own thread. It starts at a keyframe, and + after a lost frame (`contiguous == false`, a lagging frame bus, a queue + longer than 30 frames) or a decoder error it skips to the next keyframe, + asking for one at most every 500 ms. Keyframes are recognised from the + bitstream (VP8 frame tag, VP9 header, H.264 IDR/SPS NAL units, AV1 + sequence header OBU). +- `Viewer` feeds a `VideoPipeline` from the engine and sends + `RequestStreamKeyframe`; `LocalPreview` runs capture → encoder → decoder + without a server (the desktop app's `TSC_DEMO_STREAM`). +- The audio of watched streams does not go through this module: the session + hands the Opus frames to its audio thread, which plays them through the + jitter buffer and mixer under a made-up client id, with its own volume. + Playback is mono like the rest of the audio path. + ## Codecs Preference: a viewer accepts VP9 > VP8 > AV1 > H.264; a streamer encodes with @@ -171,3 +205,9 @@ run on Windows yet. | Portal capture, PipeWire video and audio streams | – | compiles only (no portal or PipeWire daemon here) | | Windows Graphics Capture, WASAPI | – | type-checked for `x86_64-pc-windows-gnu` only | | Hardware encoders | – | stubs | +| Test pattern → VP8 → decoder, rectangle position and colour | `tsc-core` `media::tests::local_preview_decodes_the_pattern` | tested | +| Test pattern → two engine stream tasks → str0m peers on loopback → decoder | `tsc-core` `stream::tests::test_pattern_through_stream_tasks` | tested | +| Stream audio (RTP time → jitter buffer ids, volume, end) | `tsc-core` `audio::tests::stream_audio_with_volume`, stream task test | tested | +| The same through the TeamSpeak 6 server | `tsc-core/tests/media_live.rs` (`TSC_LIVE=1`), `tsctl stream start --synthetic` / `watch --expect-frames` | tested against 6.0.0-beta13.1 | +| X11 monitor capture → VP8 → server → decoder | `tsctl stream start --source x11` under Xvfb | tested manually (debug build: about 8 fps at 1400×900) | +| Desktop app watching and sharing | Xvfb, `TSC_AUTOWATCH` / `TSC_AUTOSHARE` against tsctl, screenshots | tested manually | diff --git a/docs/protocol-notes/ts6-streaming.md b/docs/protocol-notes/ts6-streaming.md index 55c11c2..fe4b56a 100644 --- a/docs/protocol-notes/ts6-streaming.md +++ b/docs/protocol-notes/ts6-streaming.md @@ -173,14 +173,18 @@ cannot discover the ids of unknown streams), `updatestream` (`stream_id`, `stream_name`, `max_width`, `max_height`, `max_framerate`, `properties`), `notifystreamupdated`, `notifystreamattendees` (`return_code`, `client_id`). -### Streams that started before we joined (open) +### Streams that started before we joined (confirmed, 6.0.0-beta13.1, 2026-09-26) `initserver` and `notifycliententerview` carry `client_is_streaming`, but no -stream id. Whether the server sends `notifystreamstarted` for running streams -to a client that connects or enters the channel later is not confirmed yet. -`tsctl stream list` shows such streamers as "id not announced"; `tsctl stream -watch --id ` can still join when the streamer is known (`--streamer-nick`, -or the only other client streaming). The smoke test starts the viewer first. +stream id, and the server does not send `notifystreamstarted` for running +streams to a client that connects later: a `tsctl stream list` started while +the desktop app streamed printed only "id not announced", while one connected +before the stream started got the id. Entering the channel later was not +probed separately. `tsctl stream list` shows such streamers as "id not +announced"; `tsctl stream watch --id ` can still join when the streamer +is known (`--streamer-nick`, or the only other client streaming). The desktop +app lists them as streaming but not watchable. The smoke test starts the +viewer first. How the official client learns these ids is open. ### WebRTC interop with Chromium (confirmed, Chromium 141, 2026-09-26) @@ -213,7 +217,8 @@ libwebrtc, the stack the official client is built on: - [ ] Which permission gates `setupstream` (error 2568). - [x] Contents of `notifystreamstarted` (see probe results). - [ ] Contents of `notifystreaminfo` (`requeststreaminfo id=`). -- [ ] Whether a client that joins later is told about running streams (see above). +- [x] Whether a client that connects later is told about running streams: no (see above). +- [ ] How the official client finds running streams after connecting. - [ ] Interop with the official TS6 client (its offer/answer details, codecs it actually picks, whether it trickles candidates, mDNS host candidates). Chromium's WebRTC stack interoperates (see above).