fix: 🐛 Prevent Android recorder crash from stopping unstarted muxer#497
Open
lavigarg-simform wants to merge 1 commit into
Open
fix: 🐛 Prevent Android recorder crash from stopping unstarted muxer#497lavigarg-simform wants to merge 1 commit into
lavigarg-simform wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes an Android-only native crash that occurs when recording is stopped before the muxer has started writing any track, plus two related race/error-handling issues in the recording thread.
Existing behavior: When
stop()was called shortly afterstart()(i.e. before theMediaMuxerreceived its first frame and was started), the encoder unconditionally calledmediaMuxer?.stop(). Stopping a muxer that was never started throws and triggers the nativeMPEG4Writer"track not started" crash, taking down the app.Two further problems made this worse:
audioRecord.read()after theAudioRecordwas released duringstop(), because the read loop was not guaranteed to be stopped and joined before release.AudioRecord.read()errors (negative return values such asERROR_INVALID_OPERATION/ERROR_DEAD_OBJECT) were ignored, so the loop kept retrying a failing read.Changes:
CommonEncoder.kt— guardmediaMuxer?.stop()with the existingisMuxerStartedflag so an unstarted muxer is only released, never stopped.AudioRecorder.kt— instop(), setRecorderState.Stoppedand join the recording thread before releasingAudioRecord, so the read loop can never touch a released object.AudioRecorder.kt— bail out of the read loop on a negativeread()result instead of spinning on a permanently failing read.recordingThread?.join()callback passed intoinitCodec(join is now handled centrally instop()).Checklist
fix:,feat:,docs:etc).docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Closes #482