-
Notifications
You must be signed in to change notification settings - Fork 5
Audio session fixes #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hi @mikaelwills
Here is fragment of code from Apple CallKit documentation In contains very usable comment, explaining usage pattern: Stage 'configure audio' should be first and it's done internally by webrtc; Here is updated source code of plugin, which we testing and going to publish.
|
e08727b to
e4854d3
Compare
|
@siprix awesome, Justed tested the new file and it seems to be good so far after repeated calls! |
|
@siprix Well it worked when i first built with the new file, 20 calls in a row were fine. Came back to it latter and now the audio session wont connect at all when receiving and incoming call. Whats stands out to me is this Config is invalid: min_bitrate_bps=-1; max_bitrate_bps=-1; both expected greater or equal to 0. Inside the audio_send_stream.cc |
|
Reason of issue is interruption: provided log doesn't contain details when interruption started/ended. Most probably app was in background and move it to foreground would trigger log like: Checking how to handle this automatically. |
|
Published updated version 1.0.33 which includes previously provided impl and also addresses handling interruption. |
iOS CallKit Audio Session Race Condition Fix - PR Description
Incoming calls on iOS with CallKit were failing because of a race condition between WebRTC (used internally by Siprix) and CallKit competing for audio session control. WebRTC needs to initialize audio immediately when the SIP INVITE arrives (to generate the SDP answer), but CallKit expects to control when the audio session activates. When WebRTC wins the race, iOS doesn't call the
didActivatecallback, which means we never actually accept the call even though the UI shows "connected".Changes
1. Defer SIP Accept Until didActivate
Instead of accepting the SIP call immediately in
CXAnswerCallAction, we now:_callPendingAnswerdidActivateto fireWhy it's critical: Accepting the call before the audio session is ready leads to no audio routing. iOS needs to know the audio path exists before the SIP connection completes.
2. Fulfill CXAnswerCallAction Immediately
Fulfill the action right away to tell CallKit we're ready to proceed:
Why it's critical: If we don't fulfill, CallKit won't proceed with audio activation, so
didActivatenever fires and we're stuck waiting forever.3. Force Reset Interrupted Audio Sessions
In
didActivate, detect when WebRTC has already activated the audio session:Why it's critical: WebRTC activating audio before CallKit leaves the session in an "interrupted" state. Resetting clears this and lets us reconfigure for VoIP properly.
4. Audio Configuration in didActivate (Not onSipConnected)
Added
ensureAudioSessionConfigured()method that sets up VoIP audio settings:Called from
didActivate(before SIP accept), notonSipConnected(after connection).Why it's critical: Configuring audio AFTER the SIP connection is too late - iOS has already determined there's no audio path. Must happen in
didActivatewhich fires BEFORE we send the SIP accept.Why This Approach
We can't prevent WebRTC from initializing early - it's required for SIP to work (needs to check hardware capabilities to generate the SDP answer). So instead, we work around it:
The deferred answer pattern ensures everything happens in the right order: fulfill action → activate session → configure audio → accept call. Doing it any other way leaves the audio routing broken.
@siprix let me know your thoughts on whether this is all appropriate or not. After these changes ive personally noticed a dramatic increase in call reliability when receiving a call from the foreground/background and from an app killed state.