Files
piik/prototype/channel-native/README.md
T

19 KiB
Raw Blame History

Native channel participant

This isolated Rust participant operates rooms through the same shared RoomHost core as the Browser adapter. SQLite stores each room's policy and confirmed history; the domain supplies admission, directory views and transport leases. Its str0m endpoint carries room DataChannels, encoded media and requested file ranges without retaining file contents in SQLite. Opus and compatible original video are forwarded without decoding. Capture-enabled desktop Apps derive constrained H264 outputs through one demand-driven decoder; Windows also supports VP8. The original encoded feed remains available. Server forwarding builds without capture.

The network design owns the model. This executable is an explicitly started development host. Chat, history, room voice and files use the base paths, and screen startup reuses those paths through the same participant. The default Server embeds one participant for its three rooms and owns its service lifetime. The App composition owns its Native hosting endpoint, separately from the Browser's personal activities. The App reuses the product's site approval and saved-site interface, and starts its own domain through the shared Local/public-invitation launcher. Windows WGC captures each source once in the parent; each encoding owns a separate same-executable child for D3D11 conversion, hardware H264 or software VP8, bitrate, keyframe requests and ordered output. Demand-driven GPU handoff preserves the source's presentation clock and copies the texture into the child's private resource before encoding. An unread encoding rests on its bounded output queue without continuing GPU transfers. The Encoding owner stops and joins its child; a Windows Job also releases it when the App exits. Encoding failure affects only outputs using that encoder. Stopping capture ends all its encodings and input authority while App-hosted rooms continue. Each picture producer retires its own source-sound input. The selecting page's share lease retains the mixer across replacement and stops it when the share ends. Frame-rate selection retains the original timestamps and accumulates its sampling interval across frames. The network design owns the process and output boundaries. On supported Windows versions, the source picker can request capture without the system border. Windows grants that access; denial keeps ordinary bordered capture. Cancelling selection also cancels the pending permission request under the existing capture lease. Windows encoders feed their actual output size into the existing WebRTC FrameDropper algorithm; raw-frame admission adjusts when hardware rate control overshoots, without discarding encoded reference frames or changing the source clock. Windows hardware H264 uses CBR so live bitrate updates also restore encoding quality after low-rate startup. The encoder assessment records the rejected low-delay VBR control. Live updates keep the same owner. The macOS 13+ adapter uses ScreenCaptureKit and VideoToolbox through the published MIT-licensed cidre bindings. It plugs into the same producer, source picker, encoding demand and page lease; it does not use the Windows worker process. Its source, source sound and encoding owners are defined in the network design. Platform verification owns SDK builds and native acceptance.

Linux uses the system Portal picker through ashpd and one PipeWire capture. Each H264 encoding has its own GStreamer pipeline; system-output audio uses the PulseAudio monitor, including PipeWire's PulseAudio compatibility service. The App enables the Native capture Cargo feature; Server disables it so forwarding does not require desktop media libraries. Linux App builds need GStreamer 1.20+ development libraries and pkg-config. Current Linux App packages require glibc 2.39+ and GStreamer 1.20+ core, app and video libraries, plus GLib/GObject/GIO, before the launcher can start. Native capture additionally needs the PipeWire, conversion, H264 parser and an available H264 encoder plugin, plus a working desktop Portal backend. The optional global stop shortcut also needs normal desktop integration: install the package's piik-app.desktop entry with piik-app on the desktop's PATH. Without that identity or a GlobalShortcuts backend, ordinary control and its manual stop remain available. Hardware selection uses the VA/VA-API, NVENC, MSDK and QSV plugins only when the installed encoder exposes live bitrate control. Selection opens the actual device and skips unavailable encoders. An installed x264enc is tried after the hardware candidates, with low-latency software settings and the same live bitrate control. Its GPL-licensed plugin remains a system dependency; Piik does not bundle or install it. The network design owns source, clock and encoder lifetimes; verification status owns platform acceptance. ashpd and the reis input bindings use MIT licensing; the GStreamer Rust bindings use MIT/Apache-2.0. GStreamer and system-installed plugins retain their own licenses.

Android uses MediaProjection and independent H264/VP8 NDK MediaCodec encodings through the Rust JNI, NDK and EGL bindings. The Android runtime owns the system-browser shell and build inputs; source permission and capture retain the same selecting-page lease.

The App's source picker starts that producer on its existing Native endpoint. Local and received sources share the same encoded outputs and room routes. Each local output packetizes complete access units on its own stable RTP clock; selecting another encoding of the same capture keeps its sender and SSRC and switches at a replacement keyframe. A slow output recovers independently of its siblings. The selecting page holds the capture lease: closing it stops its captures while App-hosted rooms continue. Startup completes after the first encoded access unit; errors before that point return to the page. The producer's completion ends its App capture lease and reports an active capture failure to the selecting page. Room snapshots describe publication availability; they do not retire that lease ahead of its completion. A failed output leaves healthy siblings running. Normal source closure, explicit stop, cancelled candidates and retired producers keep quiet cleanup. Optional WASAPI source audio uses process loopback for a selected window and render-device loopback for a screen. The Rust Opus encoder shares the picture's capture clock and routes. Silence does not delay picture startup; an audio failure warns the page while picture sharing continues. Each physical connection's target now allocates its confirmed local video outputs. Constrained outputs control their own encoding; zero demand pauses only that output, and restoration waits for a newer baseline keyframe before retiring its encoder. The network design owns measured behavior and the source-sized encoding boundary; TODO owns remaining adaptation, input and platform work.

Windows keyboard, mouse and text input share one App-owned desktop executor. The Browser reuses the existing remote-control and source-consent components; input returns over the selected screen route on the same peer connections. Capture leases own consent and held-key cleanup, independently of room hosting. Global stop uses a process-only Windows hotkey selected by the Browser preference. The activity model owns authorization and retirement. Optional Windows gamepads use an already installed ViGEmBus through vigem-rust; Piik bundles or installs neither a driver nor a client DLL. Up to four approved controllers have independent device workers. Focus/reset keeps the neutral device, while grant retirement stops it; gamepad failures leave keyboard and mouse permission intact. The macOS input backend uses public Quartz/Accessibility bindings in the same executor, including physical keys, Unicode text, pointer/drag/scroll and the Browser-selected stop chord observed by the existing App tick. Only the source page enabling control can request Accessibility permission. Window identity, focused-window geometry and permission are checked separately; macOS does not advertise gamepad support. Linux control requests the system RemoteDesktop permission when the source page enables it. The selected monitor and its EIS input connection belong to that one Portal session. Approval preserves the existing producer, encoders and media clock; cancelling keeps the current sharing session. The same source consent owner cancels pending permission on replacement, local stop or capture closure. The backend must provide RemoteDesktop and ConnectToEIS; text entry is advertised only when the granted device provides it. Linux global stop uses one process-owned GlobalShortcuts Portal session. The Browser's key is a preference; the source UI shows the actual system binding, including remapping or an unbound state. Linux prefers Super + Alt + Fn to avoid the Ctrl + Alt + Fn virtual-terminal chord. Enabling control requests missing shortcut consent; opening its panel does not. Source retirement cancels pending registration while the committed binding stays process-owned. Global stop revokes input without stopping capture. Platform verification records real binding/activation with capture continuity and the remaining GNOME shortcut-dialog cleanup limitation. Linux gamepads remain platform work.

The App entry point keeps the Windows MTA alive outside its async runtime. Cached WinRT factories span successive captures and source-list refreshes; their runtime must therefore span the process, while capture workers still stop and join with their individual page lease.

The source picker requests one independent still image at a time. Windows uses WGC and the system bitmap encoder; macOS 13 uses the existing ScreenCaptureKit frames and ImageIO. Each JPEG fits within 320×180 and 64 KiB. A two-second first-frame deadline, picker cancellation and connection closure stop and join this capture before completing its request. These previews neither publish nor retain images; Linux and Android keep their system picker.

Each incoming audio/video track keeps its RTP clock and source Sender Report mapping. Outputs in one flow share a stream while owning separate SSRCs and bounded writers; WebRTC handles each hop's retransmission and congestion control. Readers, outputs and their completion reports belong to the exact directed flow lease. Removing that lease retires its work even if the same publication is subscribed again on the shared connection; the replacement has a new flow ID. Each outgoing lease references its admitted incoming flow. Incumbent and shadow inputs can forward concurrently; selecting the shadow preserves its already warm output, stream, SSRC, source clock and feedback owner.

RTC Dependency

Native, Server and Android patch rtc-rtp to commit 3b6d3c0a03a641a92aff7518418c6eeb67cf1444 in the temporary bug-fix fork. It contains only PR #308 on the published 0.21.1 baseline: a new FU-A start clears unfinished fragments, and an incomplete STAP-A length returns an error. The unchanged rtc-shared crate uses the same revision so its public error and marshal types have one identity. The other RTC helpers use published 0.21.1 crates for STUN, TURN and crypto. The existing url crate parses configured UDP STUN/TURN server addresses. Piik does not depend on the umbrella RTC engine; str0m owns negotiation and transport.

The incoming-source adapter owns complete-AU ordering and first-packet metadata. Its narrow H264 admission rule accepts equivalent Constrained Baseline formats and validates actual SPS separately from advertised decoder levels, as defined by the network design.

Cargo's patches belong to each workspace root. All three consuming manifests and lockfiles carry the same Git revision for the two patched packages. The fork retains upstream MIT/Apache-2.0 licensing; no build-time source patch or registry-cache edit is used. When an upstream release provides the parser repair, update the three roots and locks, run the existing media interoperability and platform checks, and remove the patch entries.

Use the shared upstream refresh procedure to prepare and review updates without changing the current pin.

Optional port mapping selects its socket in the pair-owned worker, independently of host-candidate signaling. Native pins portmapper 0.20.0 to 0a61bb64facc469d015f5ba537dda57c94cdcb17, a one-file scheduling repair on the official 0.20.0 baseline. It moves synchronous gateway discovery onto Tokio's blocking pool and awaits it through existing private callers, preserving the public API and mapping protocols. The Git workspace also supplies sibling netwatch 0.20.0, so Native's direct netwatch entry uses that same revision. Its source is unchanged from the published release; this keeps one netwatch source in each consuming graph. Both crates retain upstream MIT/Apache-2.0 licensing.

Upstream PR #268 carries the repair after the maintainer requested a submission in issue #266. When an upstream release includes the repair, return both direct entries to that release and regenerate Native, Server and Android locks, then run the existing mapping timer/lifecycle checks and package notice collection.

Native uses str0m's public RTP/Sans-I/O interface, pinned to the official Git snapshot 3b5b7ed1. Published 0.25.0 contains the earlier pacing and TWCC repairs below, but predates the merged RTX jitter-statistics repair. This pin includes that repair: recovered packets still deliver once, without their retransmission delay changing the primary stream's jitter estimate. Released 0.24.1 omits authentic early simulcast RTX padding from TWCC feedback before the main SSRC is known. This pin includes the upstream receipt-accounting repair and TWCC timestamp precision repair, plus persistent-queue pacing, allocation probing and idle output readiness, without a private RTC fork. Selected Original supply provides the SDK's minimum transmit demand; the SDK owns padding and probing within its estimate. Return to a release containing these repairs and regenerate the Native, Server and Android locks when one is available. The SDK owns ICE, DTLS/SRTP, SCTP, pacing, retransmission and congestion control. Piik owns source clocks, shared encodings, output demand and pair-scoped socket handoff; Server owns its fixed UDP listeners. The rust-crypto provider requires AWS-LC through its published dependency graph.

build/native-current-assembly/receipt.json indexes separately frozen source and runtime evidence, including earlier dependency candidates. Each receipt records its tested revision. TODO owns remaining platform and packaging acceptance.

Run

Start the domain and shared Web interface, then run this participant with the project's Rust 1.91 toolchain.

$env:CHANNEL_WS_URL = "ws://127.0.0.1:8791/prototype/channel"
$env:CHANNEL_UI_ORIGIN = "http://127.0.0.1:8790"
$env:PIIK_CHANNEL_NATIVE_KEY = "<the configured domain owner key>"
New-Item -ItemType Directory -Force build/channel-native-data | Out-Null
cargo +1.91.0 run --manifest-path prototype/channel-native/Cargo.toml -- --room build/channel-native-data/lounge.sqlite "Lounge"

Use your configured key, never the placeholder. An existing user credential can instead be supplied through PIIK_CHANNEL_NATIVE_CREDENTIAL; the optional PIIK_CHANNEL_NATIVE_NAME selects the user's display name. Credentials are not printed or saved by this launcher. Reopening saved room data requires the same authenticated user. Reuse the domain owner's stable key for the example above.

Repeat --room <database> <name> to operate several rooms. The domain assigns each new room's ID; an existing database restores its saved identity. Each room has a separate database and an OS file lock held by its runtime. A second process cannot open that room while the first holds it. Existing files restore their saved policy; command-line names do not overwrite it. Live calls, captures and routes are never restored from disk.

Open the normal Web interface in separate Browser profiles, enter the room and join voice. The Native endpoint is the base root; it does not borrow the domain administrator page's peer connection. Ctrl+C ends hosting and confirms departure through the existing domain protocol. An abrupt process loss uses the normal 20-second recovery window.

Checks

cargo +1.91.0 test --manifest-path prototype/channel-native/Cargo.toml
cargo +1.91.0 build --manifest-path prototype/channel-native/Cargo.toml
node prototype/channel-server/run-browser-check.mjs --native

The Browser check also needs a built domain executable and the existing agent-browser environment. CHANNEL_NATIVE_EXECUTABLE and CHANNEL_EXECUTABLE can select separate Native and domain builds. The runner owns its processes, temporary databases and Browser sessions, and stops them on completion.

The manual CI workflow's channel_native entry builds the macOS targets and runs a synthetic H264 roundtrip through the production encoder/decoder, source clock and stop owner.

The peer check uses real WebRTC endpoints for source replacement, signaling recovery, encoded audio/video forwarding and feedback under backpressure. The Browser check covers concurrent Native-rooted picture, voice and file forwarding, room-owned history, independent picture playback and process restart. Generated evidence stays under ignored build/.

The real session and App integration tests live with the Server/App runtime. Build this participant first; CHANNEL_NATIVE_EXECUTABLE can select its executable when using a custom Cargo target directory.