Skip to content

android: reset nativeCalledInitRecording when initRecording fails - #320

Open
ofyy wants to merge 2 commits into
livekit:m150_releasefrom
ofyy:android-reset-init-recording-flag
Open

ofyy wants to merge 2 commits into
livekit:m150_releasefrom
ofyy:android-reset-init-recording-flag

Conversation

@ofyy

@ofyy ofyy commented Oct 26, 2026

Copy link
Copy Markdown

initRecording() sets nativeCalledInitRecording before it calls initRecordingImpl(). If that call fails, the flag stays true. The only reset is in stopRecording(), and native never calls it after a failed init: AudioRecordJni::StopRecording() returns early while initialized_ is false. From then on every InitRecording on the same ADM fails with "InitRecording called twice without StopRecording." and the mic stays silent until the process restarts.

This resets the flag when an init started by native fails.

Refs #315, same root cause, crash variant through prewarm.

Reproduce: Android emulator. Deny RECORD_AUDIO and start a call. Grant it and start another call on the same ADM. The second call fails with "called twice" and sends 0 packets.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow failure-path reset aligns Java state with native failure handling under the existing lock, with no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes Android audio recording recovery after native initialization fails, allowing later calls to retry on the same audio device module.

Changes:

  • Clears nativeCalledInitRecording when initRecordingImpl() returns a failure.
  • Preserves successful initialization behavior and returns the original result.
File Description
sdk/​android/​src/​java/​org/​webrtc/​audio/​WebRtcAudioRecord.java Resets the native initialization flag on failure so subsequent attempts are not rejected as duplicate initialization.

Review effort: Balanced

@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

3 participants