fix(ios): recover a silently stopped AVAudioEngine after a configuration change - #621
Open
mdridley wants to merge 1 commit into
Open
fix(ios): recover a silently stopped AVAudioEngine after a configuration change#621mdridley wants to merge 1 commit into
mdridley wants to merge 1 commit into
Conversation
…ion change A route change, or another app reconfiguring the shared session, can stop AVAudioEngine without ever posting an AVAudioSession interruption — capture ends silently with no state change to observe. AVAudioEngine does not restart itself; the input tap must be reinstalled against the (possibly changed) input format and the engine started again. Opt-in via IosRecordConfig.restartOnEngineConfigurationChange, defaulting to false to keep this a no-op for existing callers.
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.
Problem
On iOS,
RecorderStreamDelegateonly observesAVAudioSession.interruptionNotification. A route change (headset connect/disconnect, another app reconfiguring the shared session) postsAVAudioEngineConfigurationChangeNotificationinstead, which stops the engine without any interruption ever firing — capture ends silently, with no state change for callers to observe.AVAudioEnginedoes not restart itself after this notification; per Apple's docs the caller is expected to reinstall the tap against the (possibly changed) input format and start the engine again.Fix
Adds an observer for
AVAudioEngine.configurationChangeNotificationscoped to the engine instance. On fire: remove the tap, re-readinputNode.inputFormat, rebuild theAudioStreamProcessoragainst it, reinstall the tap, and restart the engine — the same sequencestart()already does. On success this callsonRecord()same as the interruption-resume path, so callers observingRecordStatesee the recovery. On failure it callsstop()rather than leaving the engine silently wedged.Opt-in via a new
IosRecordConfig.restartOnEngineConfigurationChange(defaultfalse), so this is a no-op for existing callers and only changes behavior for those who ask for it.Testing
Not yet device-tested — I'm about to wire this into my own app via a git override on this branch and will report back with real results (route changes, Bluetooth connect/disconnect, another app taking the session) once I have them. Opening the PR now for early feedback on the approach/flag naming while I do that.