Skip to content

Fix android crash when recording repeated sessions#1101

Open
Traviskn wants to merge 2 commits into
software-mansion:mainfrom
Traviskn:fix/android-recorder-repeated-sessions
Open

Fix android crash when recording repeated sessions#1101
Traviskn wants to merge 2 commits into
software-mansion:mainfrom
Traviskn:fix/android-recorder-repeated-sessions

Conversation

@Traviskn

Copy link
Copy Markdown
Contributor

Introduced changes

Symptoms

I hit an Android-only crash/freeze and follow-on callback-output failure when using AudioRecorder with file output (.m4a, FFmpeg enabled) and callback output across repeated recording sessions.

In my app, the first recording could start, stop, and save, but repeated recording sessions exposed two related Android failures:

  1. An outright app crash/freeze during or shortly after stopping/saving a recording.
  2. After addressing/retrying that path, subsequent recording attempts could fail with:
Callback output is unavailable

The user-facing results were either a frozen/crashed app, a recording that could not be saved, or a saved recording with 0:00 captured duration.

Validation

After applying this patch locally, I tested repeated recordings on a physical Android device:

  1. Start recording
  2. Record for ~1 minute
  3. Stop recording
  4. Save recording
  5. Repeat by starting a new recording

Results:

  • No app crash/freeze during stop/save
  • No Callback output is unavailable log
  • No SIGABRT, SIGSEGV, or crash_dump
  • AudioFlinger showed the record track released after save
  • The app showed nonzero captured durations for repeated recordings

This PR fixes both the original crash/freeze and the later callback-output failure.

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage N/A
  • Added support for web N/A
  • Updated old arch android spec file N/A

Traviskn and others added 2 commits June 11, 2026 11:36
Two related fixes for repeated start/stop/save recording cycles on
Android when using file output (FFmpeg) together with callback output:

- AndroidAudioRecorder::stop() moved the data callback out of the
  recorder, so the next start() with callback output enabled failed
  with "Callback output is unavailable". Copy the shared_ptr instead
  to keep the JS callback subscription registered across sessions.

- FFmpegAudioFileWriter::closeFile() destroyed the TaskOffloader only
  after draining the FIFO and encoder, leaving the offloader thread
  free to race with finalization and crash during stop/save. Reset it
  first so all offloaded writes complete before the file is finalized.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Traviskn Traviskn changed the title Fix android recorder repeated sessions Fix android crash when recording repeated sessions Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant