fix: vec allocation for AudioRing, catch_unwind on tracing init, profiling
Some checks failed
Build Release Binaries / build-amd64 (push) Failing after 3m49s

- AudioRing: use vec![].into_boxed_slice() instead of Box::new([]) to
  avoid 32KB stack allocation that crashes scudo on Android
- JNI bridge: wrap tracing_subscriber init in catch_unwind to survive
  sharded_slab allocation failures on some devices
- Engine: per-step encode profiling (avg_agc_us, avg_opus_us, avg_fec_us,
  avg_send_us) logged every 5 seconds in send stats

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-04-06 15:41:46 +04:00
parent 31d2306915
commit 33fab9a049
2 changed files with 12 additions and 7 deletions

View File

@@ -19,7 +19,7 @@ const RING_MASK: usize = RING_CAPACITY - 1;
/// Lock-free single-producer single-consumer ring buffer for i16 PCM samples. /// Lock-free single-producer single-consumer ring buffer for i16 PCM samples.
pub struct AudioRing { pub struct AudioRing {
buf: Box<[i16; RING_CAPACITY]>, buf: Box<[i16]>,
/// Monotonically increasing write cursor. ONLY written by producer. /// Monotonically increasing write cursor. ONLY written by producer.
write_pos: AtomicUsize, write_pos: AtomicUsize,
/// Monotonically increasing read cursor. ONLY written by consumer. /// Monotonically increasing read cursor. ONLY written by consumer.
@@ -41,7 +41,7 @@ impl AudioRing {
pub fn new() -> Self { pub fn new() -> Self {
debug_assert!(RING_CAPACITY.is_power_of_two()); debug_assert!(RING_CAPACITY.is_power_of_two());
Self { Self {
buf: Box::new([0i16; RING_CAPACITY]), buf: vec![0i16; RING_CAPACITY].into_boxed_slice(),
write_pos: AtomicUsize::new(0), write_pos: AtomicUsize::new(0),
read_pos: AtomicUsize::new(0), read_pos: AtomicUsize::new(0),
overflow_count: AtomicU64::new(0), overflow_count: AtomicU64::new(0),

View File

@@ -35,12 +35,17 @@ static INIT_LOGGING: Once = Once::new();
/// Safe to call multiple times — only the first call takes effect. /// Safe to call multiple times — only the first call takes effect.
fn init_logging() { fn init_logging() {
INIT_LOGGING.call_once(|| { INIT_LOGGING.call_once(|| {
// Wrap in catch_unwind — sharded_slab allocation inside
// tracing_subscriber::registry() can crash on some Android
// devices if scudo malloc fails during early initialization.
let _ = std::panic::catch_unwind(|| {
use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::util::SubscriberInitExt;
if let Ok(layer) = tracing_android::layer("wzp_android") { if let Ok(layer) = tracing_android::layer("wzp_android") {
let _ = tracing_subscriber::registry().with(layer).try_init(); let _ = tracing_subscriber::registry().with(layer).try_init();
} }
}); });
});
} }
#[unsafe(no_mangle)] #[unsafe(no_mangle)]