Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

aaudio: dynamic buffer tuning never grows the buffer (set_buffer_size_in_frames reports Err on success)

Aperta Adatta ai principianti
#1,414 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@dannyward630 ci sta già lavorando.

Dal 25/10/2026.

  • #1415 di @dannyward630 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
79/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, rust

Direzione di ricerca

Inizia in src/host/aaudio.rs, in corrispondenza di build_output_stream, e segui il percorso di regolazione del buffer attivato da xrun. Controlla come ndk 0.9.0 segnala i risultati di set_buffer_size_in_frames e se la lettura di buffer_size_in_frames() conferma la dimensione richiesta. Aggiorna il controllo del successo in modo che mixer_bursts avanzi quando il ridimensionamento riesce, quindi verifica che il tuner non richieda più un buffer più piccolo dopo un underrun.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

host - aaudio platform - android

On Android, the AAudio host's dynamic buffer tuning never grows the buffer. On a low-latency stream it can actually shrink the buffer after the first underrun.

Cause

build_output_stream in src/host/aaudio.rs turns tuning on when config.buffer_size == BufferSize::Default. On each xrun-count increase it runs:

if stream.set_buffer_size_in_frames(buffer_size).is_ok() {
    tuning_for_callback.mixer_bursts.store(new_mixer_bursts, Ordering::Relaxed);
}

With ndk 0.9.0, set_buffer_size_in_frames returns Err(AudioError::__Unknown(new_size)) whenever the call succeeds (rust-mobile/ndk#520). So:

  • .is_ok() is always false, and mixer_bursts stays at its initial value.
  • If aaudio.mixer_bursts is unset, cpal falls back to its default of 2.
  • Every underrun therefore sets the buffer to (2 + 1) × burst, never larger.

Observed

  • Device: Samsung Galaxy A56, Android 16. aaudio.mixer_bursts is unset, burst is 96 frames.
  • An AAudio LowLatency/Shared output stream on this device opens with a 768-frame buffer (8 bursts).
  • With the code above, the first underrun resizes it to 288 frames (3 bursts), which is a shrink.
  • Later underruns set 288 again, so the tuner can never back off.

I confirmed the ndk return value directly on the device: set_buffer_size_in_frames(192) returns Err(__Unknown(192)), and buffer_size_in_frames() reads 192 afterwards. The cpal tuner path follows from the code; I didn't instrument it in cpal itself. This is in cpal 0.18.2 and still on master.

Suggested fix

Until ndk is fixed, treat a positive __Unknown value as success, or read the size back:

let _ = stream.set_buffer_size_in_frames(buffer_size);
if stream.buffer_size_in_frames() >= buffer_size {
    tuning_for_callback.mixer_bursts.store(new_mixer_bursts, Ordering::Relaxed);
}

Reading back also handles AAudio rounding the requested size up.

Lingua principale
Rust
Stelle
4k
Fork
554
Merge medio
2g 11h
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di RustAudio/cpal

Tutte le issue di RustAudio/cpal

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.