Recover microphone capture when the device disappears mid-call#309
Open
MaxHeimbrock wants to merge 1 commit into
Open
Recover microphone capture when the device disappears mid-call#309MaxHeimbrock wants to merge 1 commit into
MaxHeimbrock wants to merge 1 commit into
Conversation
0283b9c to
77cb74e
Compare
77cb74e to
d7c35bd
Compare
When the active capture device vanishes (e.g. a Bluetooth headset disconnects), Unity's Microphone clip silently stops filling and capture went permanently dead. Detect and recover automatically: - Detection: the clip's position counter advances continuously while a device is alive (even in silence), so CaptureLoop treats a counter that hasn't moved for 1s - or IsRecording dropping to false - as device loss. - Recovery: end the dead device and retry until a device is available, preferring the original device if it reappears and falling back to the system default microphone otherwise. The normal start path re-measures the new device's rate and fragmentation, so recovering onto or off a misbehaving device (macOS Bluetooth HFP) works transparently. The published track is unaffected throughout: the native source's format is fixed (48kHz mono) and captured audio is resampled to it, so there is no republish or renegotiation - only a capture gap until a device is acquired. Also adds MicrophoneSource.SwitchDevice(deviceName) as the manual counterpart (same mechanism, app-initiated) and a DeviceName getter. Each CaptureLoop carries a generation token and is retired when a newer capture (restart, switch, or recovery) supersedes it, so rapid transitions cannot leave two loops reading different clips; recovery pauses while the app is backgrounded so it cannot fight the iOS pause/resume handling. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d7c35bd to
d8d5383
Compare
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.
Stacked on #308. Makes the SDK survive the active microphone disappearing mid-call — e.g. a Bluetooth headset disconnecting — instead of going permanently silent.
Behavior
CaptureLoop): the mic clip's position counter advances continuously while a device is alive — even in silence — so a counter that hasn't moved for 1 s, orMicrophone.IsRecordinggoing false, means the device is gone. No false positives from a quiet room.Also included, since it is the same mechanism app-initiated: an internal
MicrophoneSource.SwitchDevice(deviceName)(the manual primitive, kept non-public until a device-picker API is designed) and a publicDeviceNamegetter.Robustness
CaptureLoopcarries a generation token and retires itself when a newer capture (restart, switch, or recovery) supersedes it — rapid transitions can't leave two loops reading different clips.Verification
🤖 Generated with Claude Code