13b1f36d4a
punktfunk-core client/rumble.rs: a per-connection policy engine consumes seq-gated wire
updates and emits EFFECTIVE actuator commands — re-emits on renewals (duration APIs stay
re-armed), self-silences at the v2 lease, a UNIFORM 1 s legacy-host staleness replacing the
per-platform zoo (Apple 1.6 s / Android 60 s / SDL 1.5 s / Deck 1 s), quirk-declared
actuator keepalives (Deck 40 ms + LSB dedupe-defeat jitter), and one stop per buzzing pad
on connection close. Per-pad mailbox semantics: a stalled embedder wakes to ONE current
command, and a stop can structurally never be the update an overflowing queue drops.
New API/ABI: NativeClient::{next_rumble_command,set_rumble_quirks} +
punktfunk_connection_next_rumble_cmd/_set_rumble_quirks (next_rumble/next_rumble2 stay for
un-migrated embedders; both consumers are fed). Migrations DELETE the platform forks:
pf-client-core loses RumbleState + the Deck keepalive loop + LEGACY_RUMBLE_CEILING_MS and
physically silences a slot at close; Android loses the 60 s legacy one-shot (backstop
repack, cancel-on-zero); Apple loses envelopeDeadline + sessionStaleSeconds + both tick
watchdogs (CoreHaptics realization untouched; mac xcframework rebuilt locally).
design/rumble-root-fix.md par. D. Engine 10/10 unit tests; core tests 176 Linux / 175
Windows + clippy -D warnings; swift build + RumbleTuningTests; Kotlin + android-native
compile green.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
71 lines
3.4 KiB
Rust
71 lines
3.4 KiB
Rust
//! `WorkerArgs` (the pump's constructor payload) and `reject_from_close`.
|
|
|
|
use super::*;
|
|
use crate::config::{CompositorPref, GamepadPref, Mode};
|
|
use crate::error::Result;
|
|
use crate::input::InputEvent;
|
|
use crate::quic::{HdrMeta, HidOutput, RichInput};
|
|
use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64};
|
|
use std::sync::mpsc::SyncSender;
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
pub(crate) struct WorkerArgs {
|
|
pub(crate) host: String,
|
|
pub(crate) port: u16,
|
|
pub(crate) mode: Mode,
|
|
pub(crate) compositor: CompositorPref,
|
|
pub(crate) gamepad: GamepadPref,
|
|
pub(crate) bitrate_kbps: u32,
|
|
pub(crate) video_caps: u8,
|
|
pub(crate) audio_channels: u8,
|
|
pub(crate) video_codecs: u8,
|
|
pub(crate) preferred_codec: u8,
|
|
pub(crate) display_hdr: Option<HdrMeta>,
|
|
pub(crate) launch: Option<String>,
|
|
pub(crate) pin: Option<[u8; 32]>,
|
|
pub(crate) identity: Option<(String, String)>,
|
|
pub(crate) frames: Arc<FrameChannel>,
|
|
pub(crate) audio_tx: SyncSender<AudioPacket>,
|
|
pub(crate) rumble_tx: SyncSender<RumbleUpdate>,
|
|
/// Feed half of the rumble policy engine — its `Drop` (demux task end) marks the engine
|
|
/// closed, so the command API always observes connection teardown.
|
|
pub(crate) rumble_feed: super::rumble::RumbleFeed,
|
|
pub(crate) hidout_tx: SyncSender<HidOutput>,
|
|
pub(crate) hdr_meta_tx: SyncSender<HdrMeta>,
|
|
pub(crate) host_timing_tx: SyncSender<crate::quic::HostTiming>,
|
|
pub(crate) input_rx: tokio::sync::mpsc::UnboundedReceiver<InputEvent>,
|
|
pub(crate) mic_rx: tokio::sync::mpsc::Receiver<(u32, u64, Vec<u8>)>,
|
|
pub(crate) rich_input_rx: tokio::sync::mpsc::UnboundedReceiver<RichInput>,
|
|
pub(crate) ctrl_rx: tokio::sync::mpsc::Receiver<CtrlRequest>,
|
|
pub(crate) ctrl_tx: tokio::sync::mpsc::Sender<CtrlRequest>,
|
|
pub(crate) ready_tx: std::sync::mpsc::Sender<Result<Negotiated>>,
|
|
pub(crate) shutdown: Arc<AtomicBool>,
|
|
/// Deliberate-quit flag (see [`NativeClient::quit`]): the worker closes with the quit code if set.
|
|
pub(crate) quit: Arc<AtomicBool>,
|
|
pub(crate) mode_slot: Arc<std::sync::Mutex<Mode>>,
|
|
pub(crate) probe: Arc<Mutex<ProbeState>>,
|
|
pub(crate) frames_dropped: Arc<AtomicU64>,
|
|
pub(crate) fec_recovered: Arc<AtomicU64>,
|
|
pub(crate) hot_tids: Arc<Mutex<Vec<i32>>>,
|
|
/// The live clock offset (see [`NativeClient::clock_offset`]): the worker seeds it with the
|
|
/// connect-time estimate; the control task's mid-stream re-syncs update it.
|
|
pub(crate) clock_offset: Arc<AtomicI64>,
|
|
/// Decode-stage latency samples from the embedder (see [`NativeClient::decode_lat`]): the pump
|
|
/// drains a window mean into the adaptive-bitrate controller's decode signal.
|
|
pub(crate) decode_lat: Arc<Mutex<DecodeLatAcc>>,
|
|
}
|
|
|
|
/// The worker: QUIC handshake, then the input/datagram/control tasks + the blocking
|
|
/// data-plane pump.
|
|
/// The host's stated rejection, if this connection was closed with a typed application code
|
|
/// (see [`crate::reject`]) — `None` for local errors, bare/legacy closes (including our own
|
|
/// `LocallyClosed`), and transport failures, which keep their original error.
|
|
pub(crate) fn reject_from_close(conn: &quinn::Connection) -> Option<crate::reject::RejectReason> {
|
|
match conn.close_reason()? {
|
|
quinn::ConnectionError::ApplicationClosed(ac) => u32::try_from(u64::from(ac.error_code))
|
|
.ok()
|
|
.and_then(crate::reject::RejectReason::from_close_code),
|
|
_ => None,
|
|
}
|
|
}
|