The Android twin of `pf-client-core`'s pad_audio: drain the host's per-pad DualSense streams, Opus-decode haptics (kind 0) and speaker (kind 1), interleave into the pad's own 4-channel layout, and render on the pad itself. Every other client hands that stream to the platform's audio graph. Android cannot: AOSP's UsbAlsaManager denylists the DualSense's output by VID/PID, so the kernel enumerates the pad's playback node and the framework discards it — `hasOutput: false`, nothing for setPreferredDevice to target, /dev/snd closed by SELinux, and UsbRequest rejects non-bulk/interrupt endpoints. So this drives the pad's isochronous endpoint directly via uac-host on the descriptor Java owns. That is measured, not assumed. On a Nothing Phone (3): the claim succeeds unprivileged, the gamepad and the pad's microphone both keep working, and the underrun-free floor is 4 ms — holding under eight-core load with the SoC in severe thermal throttling. The renderer runs at 6 ms, one step of headroom, because the same measurement found transient events that are not depth-dependent. Structured to the crate's own convention: the mixer and PLC are ungated so they compile and unit-test in the host workspace (8 tests), while everything touching an Android-only dependency is cfg'd to android. Two details worth review: - The kinds arrive on different cadences (5 ms vs 10 ms), so each has its own write cursor and both shift together on overflow — a haptics-only session renders with a silent speaker pair instead of stalling on a kind that will never arrive, and the two can never skew. - An unrecognised kind is dropped rather than folded into the coil pair. A `min(1)` clamp would have rendered a future kind straight into the actuators. Lifecycle mirrors MicCapture: dropping the handle joins the thread, and nativeStopPadAudio returns only once it has, so Kotlin may close the UsbDeviceConnection as soon as it returns and not before. usbfs-iso/uac-host enter as git dependencies pinned by revision — a transport under a real-time deadline should move when we choose. They become version dependencies once published to crates.io.
78 lines
5.1 KiB
TOML
78 lines
5.1 KiB
TOML
[package]
|
|
name = "punktfunk-client-android"
|
|
description = "punktfunk Android client — JNI bridge ('nativecore') over punktfunk-core (Rust-heavy client model)"
|
|
version.workspace = true
|
|
edition.workspace = true
|
|
rust-version.workspace = true
|
|
license.workspace = true
|
|
authors.workspace = true
|
|
repository.workspace = true
|
|
|
|
[lib]
|
|
# `libpunktfunk_android.so` — loaded by Kotlin via `System.loadLibrary("punktfunk_android")`.
|
|
name = "punktfunk_android"
|
|
crate-type = ["cdylib"]
|
|
|
|
[dependencies]
|
|
# The whole protocol/transport/FEC/crypto + the embeddable NativeClient connector. `quic` pulls
|
|
# the punktfunk/1 control plane (now ring-only — no aws-lc, see punktfunk-core/Cargo.toml).
|
|
punktfunk-core = { path = "../../../crates/punktfunk-core", features = ["quic"] }
|
|
jni = "0.21"
|
|
log = "0.4"
|
|
# LAN host discovery: browse the host's `_punktfunk._udp` mDNS advert — the SAME crate + service the
|
|
# Linux/Windows clients use (`crates/pf-client-core/src/discovery.rs`), replacing Android's per-OEM
|
|
# `NsdManager` system daemon with one tested browse path. Pure Rust (socket2/if-addrs/mio), so it
|
|
# cross-compiles to the Android targets AND builds on the host (the JNI seam links into
|
|
# `cargo build --workspace`). Kotlin keeps only the Wi-Fi `MulticastLock` + permission UX.
|
|
mdns-sd = "0.20"
|
|
|
|
# Android-only deps. Gated so `cargo build --workspace` on the Linux/macOS dev boxes + CI still
|
|
# compiles this crate (as a host cdylib) — the Android-framework glue (logging, AMediaCodec + AAudio
|
|
# via `ndk`, the Opus codec) is only pulled in for the real `*-linux-android` targets.
|
|
[target.'cfg(target_os = "android")'.dependencies]
|
|
android_logger = "0.14"
|
|
# Feature bridge, no code here: punktfunk-core logs through `tracing`, but this client only
|
|
# installs `android_logger` (a `log` backend). Core transport warnings (e.g. "UDP socket buffer
|
|
# capped well below target") reach logcat only via tracing's "log" feature, which forwards events
|
|
# as `log` records when no tracing subscriber is set (always, here). Today that feature happens to
|
|
# be enabled transitively — quinn's default `log` feature unifies `tracing/log` onto the whole
|
|
# graph — but nothing about this client's logging should hinge on a QUIC crate's default feature
|
|
# set, so declare it explicitly.
|
|
tracing = { version = "0.1", default-features = false, features = ["std", "log"] }
|
|
# NDK bindings. "media" = AMediaCodec/ANativeWindow (video); "audio" = AAudio (audio playback).
|
|
# Pure-Rust FFI to libmediandk/libnativewindow/libaaudio — no C++/libc++_shared to bundle. Decode +
|
|
# audio run entirely in Rust on native threads (the "no async on the hot path" invariant).
|
|
# api-level-28 matches the app's minSdk floor (Android 9). AAudio (26), AMediaCodec (21) and
|
|
# ANativeWindow_setBuffersDataSpace (28) are all ≤28; every call above the floor —
|
|
# ANativeWindow_setFrameRate (30), …WithChangeStrategy (31), AMediaCodec_setOnFrameRenderedCallback
|
|
# (33), the ADPF hints — is dlsym-resolved at runtime (decode::try_set_frame_rate,
|
|
# decode::install_render_callback, adpf), never linked, so the .so still loads on API 28+.
|
|
ndk = { version = "0.9", features = ["media", "audio", "nativewindow", "api-level-28"] }
|
|
# Raw FFI *types* for the one AMediaCodec entry point the `ndk` wrapper lacks:
|
|
# `AMediaCodec_setOnFrameRenderedCallback` — the per-frame render-timestamp callback behind the
|
|
# HUD's `display` stage (see decode::DisplayTracker). The symbol is API 33 ("Available since
|
|
# Android T"), ABOVE the minSdk-28 floor, so it is dlsym-resolved at runtime
|
|
# (decode::install_render_callback), NEVER hard-linked: 0.9.0 hard-linked it and
|
|
# `System.loadLibrary` failed on every pre-Android-13 device. Only ndk-sys's pointer/typedef
|
|
# types are referenced, which creates no import. Reaching it needs the codec's raw pointer, which
|
|
# is why the workspace pins `ndk` to the vendored copy whose only patch makes `MediaCodec::as_ptr`
|
|
# public (vendor/ndk, wired in the root Cargo.toml).
|
|
ndk-sys = { version = "0.6", features = ["media"] }
|
|
# setpriority/gettid to raise the decode thread toward URGENT_DISPLAY (see decode::boost_thread_priority).
|
|
libc = "0.2"
|
|
# Opus decode for the host→client audio plane (0xC9: 48 kHz stereo, 5 ms frames). Same crate the
|
|
# host + Linux client use. audiopus_sys vendors libopus (pure C) and builds it static via cmake —
|
|
# the cargo-ndk build sets LIBOPUS_STATIC=1/LIBOPUS_NO_PKG=1 so it links the bundled lib, not the host's.
|
|
opus = "0.3"
|
|
# Tier-A pad audio (WP9). Android's audio framework denylists the DualSense's output by VID/PID,
|
|
# so the pad's isochronous endpoint is driven directly on the fd `UsbDeviceConnection` hands over.
|
|
# Our own crates, developed openly because the hole they fill — isochronous USB in Rust — is an
|
|
# ecosystem-wide one: https://github.com/unom-io/usbfs-iso
|
|
# Pinned by revision rather than floating: this is a transport under a real-time deadline and it
|
|
# should move when we choose to. Becomes a plain version dependency once the crates are published.
|
|
uac-host = { git = "https://github.com/unom-io/usbfs-iso", rev = "fb01ea69c59e3bf08b3918f53a159287b5187ed2" }
|
|
usbfs-iso = { git = "https://github.com/unom-io/usbfs-iso", rev = "fb01ea69c59e3bf08b3918f53a159287b5187ed2" }
|
|
|
|
[lints]
|
|
workspace = true
|