revert(android): roll back to build #6 (35642d1) — pre-oboe known-good state
Some checks failed
Mirror to GitHub / mirror (push) Failing after 36s
Build Release Binaries / build-amd64 (push) Failing after 3m51s

Spent 10+ builds chasing a __init_tcb+4 / pthread_create SIGSEGV after
adding the oboe audio backend. Every "fix" made things worse. Reverting
all Android-specific files to the state at 35642d1 (build #6), which
was the last commit where the Tauri Android app actually launched,
rendered the home screen, and successfully registered on a relay.

Reverted files (all back to their 35642d1 content):
  - desktop/src-tauri/Cargo.toml        (no build-dep cc, no tracing-android)
  - desktop/src-tauri/build.rs          (git hash only, no Oboe / cc build)
  - desktop/src-tauri/src/lib.rs        (engine cfg-gated on non-android)
  - desktop/src-tauri/src/main.rs       (two-line desktop entry)
  - desktop/src-tauri/src/engine.rs     (desktop-only audio setup)
  - scripts/Dockerfile.android-builder  (no android24→26 clang shim)
  - scripts/build-tauri-android.sh      (no linker env vars / manifest patch)

Deleted (were added between b314138 and e2e023d):
  - desktop/src-tauri/cpp/getauxval_fix.c
  - desktop/src-tauri/cpp/oboe_bridge.{h,cpp}
  - desktop/src-tauri/cpp/oboe_stub.cpp
  - desktop/src-tauri/src/oboe_audio.rs

Next: rebuild image on remote (to drop the baked-in clang shim), build
an APK, install on Pixel 6, verify the UI renders the same way build #6
did. From there we add features back ONE at a time so we can actually
bisect which one triggers the tao::ndk_glue crash. User's rule:
"if you want to change stack, change incrementally, so we can debug".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-04-09 14:22:57 +04:00
parent e2e023d2bc
commit 530993854f
12 changed files with 118 additions and 900 deletions

View File

@@ -1,11 +1,5 @@
//! Call engine for the Tauri app — desktop and Android share this exact file.
//!
//! Desktop (macOS/Linux/Windows) uses `wzp_client::audio_io::{AudioCapture,
//! AudioPlayback}` on top of CPAL (and VoiceProcessingIO on macOS for OS-level
//! AEC). Android uses `crate::oboe_audio::OboeHandle` which wraps the C++ Oboe
//! bridge on high-priority AAudio callback threads. Both expose the same
//! `Arc<AudioRing>` shape (`available()` / `read()` / `write()`) so the
//! send/recv tasks below are identical across platforms.
//! Call engine for the desktop app — wraps wzp-client audio + transport
//! into a clean async interface for Tauri commands.
use std::net::SocketAddr;
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, Ordering};
@@ -15,20 +9,10 @@ use std::time::Instant;
use tokio::sync::Mutex;
use tracing::{error, info};
use wzp_client::audio_io::{AudioCapture, AudioPlayback};
use wzp_client::call::{CallConfig, CallEncoder};
use wzp_proto::{CodecId, MediaTransport, QualityProfile};
// Ring buffer type used by the send/recv tasks. Different concrete type on
// each platform but both provide the same method surface: `available()`,
// `read(&mut [i16]) -> usize`, `write(&[i16]) -> usize`.
#[cfg(not(target_os = "android"))]
use wzp_client::audio_ring::AudioRing;
#[cfg(not(target_os = "android"))]
use wzp_client::audio_io::{AudioCapture, AudioPlayback};
#[cfg(target_os = "android")]
use crate::oboe_audio::{AudioRing, OboeHandle};
const FRAME_SAMPLES_40MS: usize = 1920;
/// Resolve a quality string from the UI to a QualityProfile.
@@ -111,11 +95,32 @@ impl CallEngine {
let relay_addr: SocketAddr = relay.parse()?;
// Load or generate identity. Uses the same helper as the signaling
// commands so the desktop and the Android app both read from the
// platform-correct data dir (resolved via Tauri's path().app_data_dir()).
let seed = crate::load_or_create_seed()
.map_err(|e| anyhow::anyhow!("identity: {e}"))?;
// Load or generate identity
let seed = {
let path = {
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
std::path::PathBuf::from(home).join(".wzp").join("identity")
};
if path.exists() {
if let Ok(hex) = std::fs::read_to_string(&path) {
if let Ok(s) = wzp_crypto::Seed::from_hex(hex.trim()) {
s
} else {
wzp_crypto::Seed::generate()
}
} else {
wzp_crypto::Seed::generate()
}
} else {
let s = wzp_crypto::Seed::generate();
if let Some(p) = path.parent() {
std::fs::create_dir_all(p).ok();
}
let hex: String = s.0.iter().map(|b| format!("{b:02x}")).collect();
std::fs::write(&path, hex).ok();
s
}
};
let fp = seed.derive_identity().public_identity().fingerprint;
let fingerprint = fp.to_string();
@@ -139,28 +144,12 @@ impl CallEngine {
info!("connected to relay, handshake complete");
event_cb("connected", &format!("joined room {room}"));
// Audio I/O — platform-dispatched.
// macOS VoiceProcessingIO (OS AEC) with CPAL fallback
// Linux/Win plain CPAL
// Android Oboe (AAudio / OpenSLES) via the C++ bridge
//
// The `audio_handle` must outlive the send/recv tasks so audio streams
// keep running — stored in the CallEngine below.
let (capture_ring, playout_ring, audio_handle): (
Arc<AudioRing>,
Arc<AudioRing>,
Box<dyn std::any::Any + Send>,
) = {
#[cfg(target_os = "android")]
{
let _ = _os_aec; // AEC TBD on Android (step 6 polish)
let (cr, pr, handle) = OboeHandle::start()?;
info!("using Oboe backend (AAudio/OpenSLES)");
(cr, pr, Box::new(handle))
}
#[cfg(target_os = "macos")]
{
if _os_aec {
// Audio I/O — VPIO (OS AEC) on macOS, plain CPAL otherwise.
// The audio handle must be stored in CallEngine to keep streams alive.
let (capture_ring, playout_ring, audio_handle): (_, _, Box<dyn std::any::Any + Send>) =
if _os_aec {
#[cfg(target_os = "macos")]
{
match wzp_client::audio_vpio::VpioAudio::start() {
Ok(v) => {
let cr = v.capture_ring().clone();
@@ -177,25 +166,23 @@ impl CallEngine {
(cr, pr, Box::new((capture, playback)))
}
}
} else {
}
#[cfg(not(target_os = "macos"))]
{
info!("OS AEC not available on this platform, using CPAL");
let capture = AudioCapture::start()?;
let playback = AudioPlayback::start()?;
let cr = capture.ring().clone();
let pr = playback.ring().clone();
(cr, pr, Box::new((capture, playback)))
}
}
#[cfg(all(not(target_os = "macos"), not(target_os = "android")))]
{
let _ = _os_aec; // OS AEC not available on Linux/Windows here
info!("OS AEC not available on this platform, using CPAL");
} else {
let capture = AudioCapture::start()?;
let playback = AudioPlayback::start()?;
let cr = capture.ring().clone();
let pr = playback.ring().clone();
(cr, pr, Box::new((capture, playback)))
}
};
};
let running = Arc::new(AtomicBool::new(true));
let mic_muted = Arc::new(AtomicBool::new(false));

View File

@@ -6,12 +6,12 @@
windows_subsystem = "windows"
)]
// Call engine — compiled on every platform. Audio backend is cfg-switched
// inside engine.rs (CPAL/VPIO on desktop, Oboe on Android).
// CPAL-backed audio engine — desktop only. On Android we'll plug in an
// oboe/AAudio backend in a later step.
#[cfg(not(target_os = "android"))]
mod engine;
#[cfg(target_os = "android")]
mod oboe_audio;
#[cfg(not(target_os = "android"))]
use engine::CallEngine;
use serde::Serialize;
@@ -83,6 +83,7 @@ struct CallStatus {
}
struct AppState {
#[cfg(not(target_os = "android"))]
engine: Mutex<Option<CallEngine>>,
signal: Arc<Mutex<SignalState>>,
}
@@ -151,7 +152,7 @@ async fn ping_relay(relay: String) -> Result<PingResult, String> {
/// Falls back to `$HOME/.wzp` on the desktop side if the OnceLock hasn't been
/// initialised yet (shouldn't happen in normal startup, but keeps the fn
/// total).
pub(crate) fn identity_dir() -> PathBuf {
fn identity_dir() -> PathBuf {
if let Some(dir) = APP_DATA_DIR.get() {
return dir.clone();
}
@@ -172,7 +173,7 @@ fn identity_path() -> std::path::PathBuf {
}
/// Load the persisted seed, or generate-and-persist a new one if missing.
pub(crate) fn load_or_create_seed() -> Result<wzp_crypto::Seed, String> {
fn load_or_create_seed() -> Result<wzp_crypto::Seed, String> {
let path = identity_path();
if path.exists() {
let hex = std::fs::read_to_string(&path).map_err(|e| format!("read identity: {e}"))?;
@@ -220,6 +221,7 @@ fn get_app_info() -> Result<AppInfo, String> {
})
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
async fn connect(
state: tauri::State<'_, Arc<AppState>>,
@@ -255,6 +257,7 @@ async fn connect(
}
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
async fn disconnect(state: tauri::State<'_, Arc<AppState>>) -> Result<String, String> {
let mut engine_lock = state.engine.lock().await;
@@ -266,6 +269,7 @@ async fn disconnect(state: tauri::State<'_, Arc<AppState>>) -> Result<String, St
}
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
async fn toggle_mic(state: tauri::State<'_, Arc<AppState>>) -> Result<bool, String> {
let engine_lock = state.engine.lock().await;
@@ -276,6 +280,7 @@ async fn toggle_mic(state: tauri::State<'_, Arc<AppState>>) -> Result<bool, Stri
}
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
async fn toggle_speaker(state: tauri::State<'_, Arc<AppState>>) -> Result<bool, String> {
let engine_lock = state.engine.lock().await;
@@ -286,6 +291,7 @@ async fn toggle_speaker(state: tauri::State<'_, Arc<AppState>>) -> Result<bool,
}
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
async fn get_status(state: tauri::State<'_, Arc<AppState>>) -> Result<CallStatus, String> {
let engine_lock = state.engine.lock().await;
@@ -329,6 +335,62 @@ async fn get_status(state: tauri::State<'_, Arc<AppState>>) -> Result<CallStatus
}
}
// ─── Android stubs for engine-backed commands ────────────────────────────────
//
// Step 1 of the Android rewrite: signal-only. Audio is wired up in Step 3.
// These keep the JS frontend happy (same `invoke` surface) without pulling
// in CPAL, which doesn't support Android.
#[cfg(target_os = "android")]
#[tauri::command]
async fn connect(
_state: tauri::State<'_, Arc<AppState>>,
_app: tauri::AppHandle,
_relay: String,
_room: String,
_alias: String,
_os_aec: bool,
_quality: String,
) -> Result<String, String> {
Err("audio backend not yet wired on Android (step 3)".into())
}
#[cfg(target_os = "android")]
#[tauri::command]
async fn disconnect(_state: tauri::State<'_, Arc<AppState>>) -> Result<String, String> {
Ok("not connected".into())
}
#[cfg(target_os = "android")]
#[tauri::command]
async fn toggle_mic(_state: tauri::State<'_, Arc<AppState>>) -> Result<bool, String> {
Err("not connected".into())
}
#[cfg(target_os = "android")]
#[tauri::command]
async fn toggle_speaker(_state: tauri::State<'_, Arc<AppState>>) -> Result<bool, String> {
Err("not connected".into())
}
#[cfg(target_os = "android")]
#[tauri::command]
async fn get_status(_state: tauri::State<'_, Arc<AppState>>) -> Result<CallStatus, String> {
Ok(CallStatus {
active: false,
mic_muted: false,
spk_muted: false,
participants: vec![],
encode_fps: 0,
recv_fps: 0,
audio_level: 0,
call_duration_secs: 0.0,
fingerprint: String::new(),
tx_codec: String::new(),
rx_codec: String::new(),
})
}
// ─── Signaling commands — platform independent ───────────────────────────────
struct SignalState {
@@ -446,6 +508,7 @@ pub fn run() {
tracing_subscriber::fmt().init();
let state = Arc::new(AppState {
#[cfg(not(target_os = "android"))]
engine: Mutex::new(None),
signal: Arc::new(Mutex::new(SignalState {
transport: None, fingerprint: String::new(), signal_status: "idle".into(),

View File

@@ -1,220 +0,0 @@
//! Android audio backend for WarzonePhone Tauri mobile.
//!
//! Wraps the C++ Oboe bridge (cpp/oboe_bridge.cpp) — Oboe runs on high-priority
//! AAudio/OpenSL callback threads and reads/writes two shared SPSC ring buffers.
//! The Rust side drains the capture ring into the Opus encoder and fills the
//! playout ring with decoded PCM — no locking, no allocations, no cross-thread
//! channels on the hot path.
//!
//! Mirror of the proven implementation from `crates/wzp-android/src/audio_android.rs`
//! but stripped of the JNI-centric bits — this crate is a pure Tauri mobile lib.
#![cfg(target_os = "android")]
use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::Arc;
use tracing::info;
/// 20 ms @ 48 kHz mono.
pub const FRAME_SAMPLES: usize = 960;
/// 8 frames × 960 samples = 160 ms headroom at 48 kHz.
const RING_CAPACITY: usize = 7680;
// ─── FFI to cpp/oboe_bridge.cpp ─────────────────────────────────────────────
#[repr(C)]
#[allow(non_snake_case)]
struct WzpOboeConfig {
sample_rate: i32,
frames_per_burst: i32,
channel_count: i32,
}
#[repr(C)]
#[allow(non_snake_case)]
struct WzpOboeRings {
capture_buf: *mut i16,
capture_capacity: i32,
capture_write_idx: *mut AtomicI32,
capture_read_idx: *mut AtomicI32,
playout_buf: *mut i16,
playout_capacity: i32,
playout_write_idx: *mut AtomicI32,
playout_read_idx: *mut AtomicI32,
}
unsafe impl Send for WzpOboeRings {}
unsafe impl Sync for WzpOboeRings {}
unsafe extern "C" {
fn wzp_oboe_start(config: *const WzpOboeConfig, rings: *const WzpOboeRings) -> i32;
fn wzp_oboe_stop();
fn wzp_oboe_capture_latency_ms() -> f32;
fn wzp_oboe_playout_latency_ms() -> f32;
fn wzp_oboe_is_running() -> i32;
}
// ─── Lock-free SPSC ring buffer (shared with C++ via AtomicI32) ────────────
/// Single-producer single-consumer ring buffer shared with the C++ Oboe callback.
///
/// The exposed method names (`available`, `read`, `write`) mirror
/// `wzp_client::audio_ring::AudioRing` so the CallEngine code can treat both
/// backends interchangeably via a cfg-switched type alias.
pub struct AudioRing {
buf: Vec<i16>,
capacity: usize,
write_idx: AtomicI32,
read_idx: AtomicI32,
}
// SAFETY: SPSC — producer owns write_idx, consumer owns read_idx, atomics
// provide acquire/release visibility between threads.
unsafe impl Send for AudioRing {}
unsafe impl Sync for AudioRing {}
impl AudioRing {
pub fn new() -> Self {
Self {
buf: vec![0i16; RING_CAPACITY],
capacity: RING_CAPACITY,
write_idx: AtomicI32::new(0),
read_idx: AtomicI32::new(0),
}
}
/// Samples currently available to read.
pub fn available(&self) -> usize {
let w = self.write_idx.load(Ordering::Acquire);
let r = self.read_idx.load(Ordering::Relaxed);
let avail = w - r;
if avail < 0 {
(avail + self.capacity as i32) as usize
} else {
avail as usize
}
}
/// Samples that can still be written without overflowing.
pub fn available_write(&self) -> usize {
self.capacity.saturating_sub(1).saturating_sub(self.available())
}
/// Producer side: write `data.len()` samples if room permits, else as many
/// as fit. Returns the number of samples actually written.
pub fn write(&self, data: &[i16]) -> usize {
let avail = self.available_write();
let count = data.len().min(avail);
if count == 0 {
return 0;
}
let mut w = self.write_idx.load(Ordering::Relaxed) as usize;
let cap = self.capacity;
let buf_ptr = self.buf.as_ptr() as *mut i16;
for sample in &data[..count] {
unsafe { *buf_ptr.add(w) = *sample; }
w += 1;
if w >= cap { w = 0; }
}
self.write_idx.store(w as i32, Ordering::Release);
count
}
/// Consumer side: read up to `out.len()` samples. Returns count actually read.
pub fn read(&self, out: &mut [i16]) -> usize {
let avail = self.available();
let count = out.len().min(avail);
if count == 0 {
return 0;
}
let mut r = self.read_idx.load(Ordering::Relaxed) as usize;
let cap = self.capacity;
let buf_ptr = self.buf.as_ptr();
for slot in &mut out[..count] {
unsafe { *slot = *buf_ptr.add(r); }
r += 1;
if r >= cap { r = 0; }
}
self.read_idx.store(r as i32, Ordering::Release);
count
}
fn buf_ptr(&self) -> *mut i16 {
self.buf.as_ptr() as *mut i16
}
fn write_idx_ptr(&self) -> *mut AtomicI32 {
&self.write_idx as *const AtomicI32 as *mut AtomicI32
}
fn read_idx_ptr(&self) -> *mut AtomicI32 {
&self.read_idx as *const AtomicI32 as *mut AtomicI32
}
}
// ─── Owning handle: starts/stops the Oboe streams and holds the rings alive ──
/// Owns both ring buffers and the active Oboe streams. Dropping this handle
/// stops the streams; the rings cannot outlive it because they're owned inside.
pub struct OboeHandle {
capture: Arc<AudioRing>,
playout: Arc<AudioRing>,
started: bool,
}
impl OboeHandle {
/// Allocate ring buffers and start the Oboe capture + playout streams.
/// Returns the handle plus cloned ring Arcs for the CallEngine's send/recv tasks.
pub fn start() -> Result<(Arc<AudioRing>, Arc<AudioRing>, Self), anyhow::Error> {
let capture = Arc::new(AudioRing::new());
let playout = Arc::new(AudioRing::new());
let config = WzpOboeConfig {
sample_rate: 48_000,
frames_per_burst: FRAME_SAMPLES as i32,
channel_count: 1,
};
let rings = WzpOboeRings {
capture_buf: capture.buf_ptr(),
capture_capacity: capture.capacity as i32,
capture_write_idx: capture.write_idx_ptr(),
capture_read_idx: capture.read_idx_ptr(),
playout_buf: playout.buf_ptr(),
playout_capacity: playout.capacity as i32,
playout_write_idx: playout.write_idx_ptr(),
playout_read_idx: playout.read_idx_ptr(),
};
let ret = unsafe { wzp_oboe_start(&config, &rings) };
if ret != 0 {
return Err(anyhow::anyhow!("wzp_oboe_start failed: code {ret}"));
}
info!(capture_latency_ms = unsafe { wzp_oboe_capture_latency_ms() },
playout_latency_ms = unsafe { wzp_oboe_playout_latency_ms() },
"oboe backend started");
Ok((
capture.clone(),
playout.clone(),
Self { capture, playout, started: true },
))
}
#[allow(unused)]
pub fn is_running(&self) -> bool {
unsafe { wzp_oboe_is_running() != 0 }
}
}
impl Drop for OboeHandle {
fn drop(&mut self) {
if self.started {
unsafe { wzp_oboe_stop() };
info!("oboe backend stopped");
self.started = false;
}
// Rings live as long as their Arcs do — the C++ side has already
// stopped, so no more callbacks will touch the atomics.
let _ = (&self.capture, &self.playout);
}
}