5262e28b79
apple / swift (push) Successful in 54s
windows-msix / package (push) Successful in 1m1s
decky / build-publish (push) Has been cancelled
deb / build-publish (push) Has been cancelled
rpm / build-publish (bazzite, punktfunk-fedora-rpm) (push) Has been cancelled
rpm / build-publish (fedora-44, punktfunk-fedora44-rpm) (push) Has been cancelled
windows / build (push) Successful in 55s
ci / docs-site (push) Successful in 31s
audit / cargo-audit (push) Failing after 1m8s
android / android (push) Failing after 2m12s
ci / web (push) Successful in 31s
ci / bench (push) Successful in 4m31s
ci / rust (push) Successful in 6m31s
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 5s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 35s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 2m44s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 4s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 2m25s
flatpak / build-publish (push) Successful in 5m5s
docker / deploy-docs (push) Successful in 20s
Stats HUD (mirrors the Apple client): the decode thread accumulates FPS, receive throughput, and capture->client latency (p50/p95, skew-corrected) in Rust (clients/android/native/src/stats.rs); nativeVideoStats drains a snapshot ~1 Hz over JNI as a DoubleArray. StreamScreen renders a Compose overlay (W*H@Hz / fps / Mb/s / latency, + dropped-under-loss), toggled by a Settings switch (persisted, default on) or a 3-finger tap. Performance (decode.rs): - ANativeWindow_setFrameRate(refresh_hz): align display vsync to the stream rate (no 60-in-120 judder); safe since minSdk 31 >= API 30. - Raise the decode thread toward URGENT_DISPLAY (best-effort setpriority) so background work can't preempt it under load. - Codec low-latency hints KEY_PRIORITY=0 (realtime) + KEY_OPERATING_RATE. Verified host-side: cargo build/clippy/fmt --workspace (the ungated stats + JNI accessor). The android-gated decode.rs (NDK) and the Kotlin build only in CI (android.yml: gradle + cargo-ndk) -- APIs verified against crate sources. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
3.0 KiB
Rust
76 lines
3.0 KiB
Rust
//! punktfunk Android client — the JNI bridge ("nativecore") over `punktfunk-core`.
|
|
//!
|
|
//! Architecture: the **Rust-heavy** client model (like `punktfunk-client-linux`, *not* the
|
|
//! thin-native-over-C-ABI Apple model). This `cdylib` links `punktfunk-core` directly and drives
|
|
//! the whole `punktfunk/1` protocol through [`punktfunk_core::client::NativeClient`]; Kotlin owns
|
|
//! only the Android-framework surface (Compose UI, `SurfaceView` lifecycle, input capture,
|
|
//! `NsdManager` discovery, Keystore). The JNI seam below is the one place the two languages meet.
|
|
//!
|
|
//! Why Rust-heavy: Kotlin cannot `import` the cbindgen C header the way Swift can, so a native
|
|
//! bridge is unavoidable. Writing it in Rust lets the Android client reuse the Linux client's
|
|
//! orchestration verbatim — audio jitter ring, the VK keymap inverse, latency/skew math, the
|
|
//! input capture state machine, trust/pairing logic — instead of re-porting it into Kotlin.
|
|
//!
|
|
//! JNI symbols map to `io.unom.punktfunk.kit.NativeBridge` in the `:kit` Gradle module
|
|
//! (`clients/android`). The current surface is the scaffold's native-link proof
|
|
//! (`abiVersion`/`coreVersion`) plus the session handle lifecycle in [`session`]; the per-plane
|
|
//! pumps (video → AMediaCodec, audio → Oboe), input, audio, pairing and mode renegotiation are
|
|
//! the next milestone (see the TODOs in [`session`]).
|
|
|
|
use jni::objects::JObject;
|
|
use jni::sys::jint;
|
|
use jni::JNIEnv;
|
|
|
|
#[cfg(target_os = "android")]
|
|
mod audio;
|
|
#[cfg(target_os = "android")]
|
|
mod decode;
|
|
mod feedback;
|
|
#[cfg(target_os = "android")]
|
|
mod mic;
|
|
mod session;
|
|
mod stats;
|
|
|
|
/// Initialize `android_logger` once when the JVM loads the library. Logs land in logcat under the
|
|
/// `punktfunk` tag. Android-only — there is no JVM (and no logcat) on the host build.
|
|
#[cfg(target_os = "android")]
|
|
#[no_mangle]
|
|
pub extern "system" fn JNI_OnLoad(
|
|
_vm: *mut jni::sys::JavaVM,
|
|
_reserved: *mut std::ffi::c_void,
|
|
) -> jint {
|
|
android_logger::init_once(
|
|
android_logger::Config::default()
|
|
.with_max_level(log::LevelFilter::Info)
|
|
.with_tag("punktfunk"),
|
|
);
|
|
log::info!(
|
|
"punktfunk_android loaded (core ABI v{})",
|
|
punktfunk_core::ABI_VERSION
|
|
);
|
|
jni::sys::JNI_VERSION_1_6
|
|
}
|
|
|
|
/// `NativeBridge.abiVersion(): Int` — the core's C-ABI version. A non-error return is the
|
|
/// scaffold's proof that `System.loadLibrary` found the `.so`, the JNI symbol resolved, and the
|
|
/// linked `punktfunk-core` is the one we expect.
|
|
#[no_mangle]
|
|
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_abiVersion(
|
|
_env: JNIEnv,
|
|
_this: JObject,
|
|
) -> jint {
|
|
punktfunk_core::ABI_VERSION as jint
|
|
}
|
|
|
|
/// `NativeBridge.coreVersion(): String` — the crate version, proving JNI string marshaling works.
|
|
#[no_mangle]
|
|
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_coreVersion<'local>(
|
|
env: JNIEnv<'local>,
|
|
_this: JObject<'local>,
|
|
) -> jni::sys::jstring {
|
|
match env.new_string(env!("CARGO_PKG_VERSION")) {
|
|
Ok(s) => s.into_raw(),
|
|
Err(_) => JObject::null().into_raw(),
|
|
}
|
|
}
|