Files
AAA c501215c95 fix(native): meet the SDK's deadlines on Windows without waiting for the system tick
The engine pump slept until the SDK's next deadline with a tokio timer. On
Windows that timer fires on the system tick, 15.6 ms unless a process has
raised it, and Windows 11 does not keep a raised period for a process that is
neither visible nor audible. Measured here: a 2 ms tokio sleep returns about
14 ms late, std::thread::sleep about 0.5 ms late.

The pacer and the bandwidth probes need those deadlines. With the default tick
a Native sender's estimate stayed between 200 and 300 kbit/s for twenty
seconds on loopback, so the allocator rejected the optional flow of the
recovery fixture and its test failed on every run on this machine. With the
deadlines met the same fixture reaches 11.7 Mbit/s in two seconds.

One thread per pump now sleeps on its behalf: an interruptible wait while the
instant is far, then slices of a millisecond on the high-resolution timer that
std::thread::sleep uses since Windows 10 1803. Other platforms keep the tokio
timer. The thread's CPU cost during a session is not measured; it wakes at
most once a millisecond while a deadline is within 32 ms.

All 206 Native tests pass here with the default tick, the recovery test
included.
c501215c95 · 2026-11-26 06:50:52 +08:00
History
..

Native channel participant

This 3.0 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 identity, directory views and transport leases. Room admission stays with this runtime. 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. Signed chat/history and replies travel through the domain WebSocket to this room's SQLite owner. Reading does not create a peer path. Voice, file bytes and file-pull control use the base paths, and screen startup reuses them 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 or software H264, software VP8, bitrate, keyframe requests and ordered output. Before a Windows Native share starts, its encoding method can be Automatic or Software. Automatic uses the existing hardware H264 path; Software uses the system CPU H264 encoder. With Auto codec selection, a failed H264 startup can try software VP8. An explicit H264 selection reports its own startup failure. Software availability is advertised from the local component; actual startup still requires an independent encoded frame. This choice belongs to the capture and all its encodings, including child-process replacement. Remote forwarding uses the receiving device's own encoding policy. Software H264 and VP8 share one synchronous scheduling, adaptation and NV12 readback owner. Their measured encoding time also feeds the shared quality policy, which adjusts pixels or frame rate according to the selected preference. The measurement ends before output delivery and does not represent GPU-copy or network pressure. 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. Its volume and audio bitrate belong to the publication, so preparing or committing another picture cannot restore older sound settings. Turning off the microphone cancels only microphone preparation; picture and system-sound preparation keep their owners. 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, Android, macOS and Linux expose the shared detail/balanced/motion preference inside each encoder through the pinned WebRTC quality policy and optional codec QP feedback. The network owner defines source intent, restrictions and recovery. Remaining platform acceptance stays in TODO. 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. Changes to remote-control policy identify the selected capture lease, so a late request for a replaced source cannot enable control on its replacement. 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 use rtc-rtp and rtc-shared from the official 81fde93b46f8fb1c1a191415558fa3574e48d5c7 commit. It includes PR #308, merged on 2026-11-11: a new H264 FU-A start clears unfinished fragments, and an incomplete STAP-A length returns an error. These two package trees and their workspace dependency definitions are identical to the former bug-fix fork. Using the same revision for rtc-shared keeps public error and marshal types under one identity. The published 0.21.1 crates predate the repair, so Cargo patch entries still select this official revision until a release passes the consumer checks below. STUN and crypto use the published 0.21.1 crates. The three workspace roots take rtc-turn 0.21.1 from native/third_party/rtc-turn, based on the published archive (SHA-256 c53078a0696df5a3a5e4947bc550c5e903b59803b252f1d39062d637ebd3d17e) at upstream commit 2a732df5. The retained MIT and Apache-2.0 notices accompany the source. The local change retries a Refresh challenged by a stale nonce once, preserving the requested lifetime and using a new signed transaction. When an official release passes the Refresh nonce-rotation regression and the Piik relay check, remove the local crate and override from all three roots and update their lockfiles. The existing url crate parses UDP STUN and TURN addresses. TURN also supports TCP and TLS over TCP, using the same trust sources as signaling and the rtc-shared TURN stream decoder. ICE advertises the allocated UDP relay address. 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. Actual SPS identifies each H264 representation; the SDK matches negotiated profiles and packetization. The profile compatibility contract owns compatible derivation and forwarding-only reception within the network design.

Cargo's patches belong to each workspace root. All three consuming manifests and lockfiles carry the same official Git revision for rtc-rtp and rtc-shared. Upstream MIT/Apache-2.0 licensing is retained; 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 for the remaining temporary forks below; it prepares review candidates without changing their current pins.

Native pins netwatch and portmapper 0.20.0, and Server pins netwatch, to the same net-tools revision. On desktop, interface address and IPv6 DAD changes reach the existing monitor. A connecting Native pair can then advertise a newly usable address on its original UDP socket until ICE selects its first path. Android takes an interface snapshot when creating the pair.

The socket-owned mapping worker delegates synchronous gateway discovery to Tokio's blocking pool. When a gateway advertises NAT-PMP and explicitly reports that PCP mapping is unsupported, the worker can create a NAT-PMP lease and renew it if the gateway changes the external port. PCP renewal reuses the active lease's nonce, as required by RFC 6887. An expired availability probe does not change the active lease's protocol. Both crates retain their upstream MIT/Apache-2.0 licensing. Upstream PR #268 covers the scheduling fix requested in issue #266. Return both dependencies to an upstream release once it covers the scheduling, interface notification and lease fixes. Regenerate the Native, Server and Android locks and verify IPv6 trickle, mapping lifecycle and package notices.

Native, Server and Android use str0m 0.26.0 with the rust-crypto provider from revision 5f1f6346, based on official release commit 6b996d99. The temporary SDK repair separates send-consent expiry from candidate connectivity, retains authorized playback during ICE restart, and permits another valid tuple to recover after expiry or authenticated revocation. The read-only Rtc::has_send_consent query exposes the SDK's current selected-path authorization. Native keeps established media through recoverable disconnection and retires expired paths on the SDK's existing wakeups; remote input retains its stricter connection and grant checks. The SDK's is, str0m-proto and str0m-rust-crypto packages remain in its official workspace layout and share that Git revision and MIT/Apache-2.0 licensing. Return to a published upstream version when it covers these behaviors and passes the retained consent/restart controls and Native/Browser interoperability checks; update the single Native dependency and all three consuming lockfiles. The official 0.26.0 baseline also suppresses duplicate NACK repairs within one round trip, bounds loss-based bandwidth estimates by acknowledged throughput and the minimum bitrate, and preserves locked SDP payload mappings.

The Native consumer comparison owns retransmission evidence for its recorded revisions. Selected Original supply provides the SDK's minimum transmit demand; the SDK owns padding and probing within its estimate. The adapter adds no retransmission-history state.

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.

Verification status owns current evidence boundaries. Package receipts retain their exact source and tested runtime; TODO owns remaining platform and adaptation work. Earlier local runtime and dependency checks remain indexed by build/native-current-assembly/receipt.json; each entry applies to its recorded source and environment, rather than the current build by default.

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_OWNER_KEY = "<the configured site owner bootstrap 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 site owner's stable bootstrap 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.