Skip to content

[Enhancement]Improved audio session management #906

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

Merged
merged 29 commits into from
Aug 8, 2025

Conversation

ipavlidakis
Copy link
Contributor

@ipavlidakis ipavlidakis commented Jul 31, 2025

🔗 Issue Links

Resolves https://linear.app/stream/issue/IOS-1046/audio-issues

🎯 Goal

Provide a consistent and centralised way for managing AudioSession updates across SDK Components and Calls.

🛠 Implementation

This revision introduces RTCAudioStore which is meant to be the control centre for AudioSession for the SDK, completely abstracting AVAudioSession and RTCAudioSession. The reason for this abstraction is that AVAudioSessionManagement and CallKit require things to happen in serial order. This order is what RTCAudioStore offers.

The architecture is Redux-based with 2 main Reducers (RTCAudioSessionReducer and CallKitAudioSessionReducer). Each of them is responsible with interacting with one external component (in this case RTCAudioSession and CallKit).

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change follows zero ⚠️ policy (required)
  • This change should receive manual QA
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (tutorial, CMS)

@ipavlidakis ipavlidakis self-assigned this Jul 31, 2025
@ipavlidakis ipavlidakis added bug Something isn't working enhancement New feature or request labels Jul 31, 2025
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jul 31, 2025

SDK Size

title develop branch diff status
StreamVideo 8.16 MB 8.18 MB +19 KB 🟢
StreamVideoSwiftUI 2.29 MB 2.29 MB 0 KB 🟢
StreamVideoUIKit 2.41 MB 2.41 MB 0 KB 🟢
StreamWebRTC 9.85 MB 9.85 MB 0 KB 🟢

Copy link

Public Interface

+ extension RTCAudioSession  
+ 
+   case isActive
+   case category
+   case mode
+   case useManualAudio
+   case isAudioEnabled
+   case device
+   case deviceIsExternal = "device.isExternal"
+   case deviceIsSpeaker = "device.isSpeaker"
+   case deviceIsReceiver = "device.isReceiver"
+   
+ 
+   public func encode(to encoder: Encoder)throws



 public enum ApplicationState: String, Sendable, Equatable  
-   case foreground, background
+   case unknown, foreground, background

Copy link

1 Message
📖 Skipping Danger since the Pull Request is classed as Draft/Work In Progress

Generated by 🚫 Danger

@ipavlidakis ipavlidakis force-pushed the enhancement/improved-audio-session-management branch 2 times, most recently from 9dd1d4d to 0ae3530 Compare August 5, 2025 11:42
@ipavlidakis ipavlidakis force-pushed the enhancement/improved-audio-session-management branch from 0ae3530 to d5c90bf Compare August 5, 2025 11:43
Copy link

github-actions bot commented Aug 6, 2025

Public Interface

 public enum ApplicationState: String, Sendable, Equatable  
-   case foreground, background
+   case unknown, foreground, background

- public struct AudioSessionConfiguration: ReflectiveStringConvertible, Equatable  
+ public struct AudioSessionConfiguration: ReflectiveStringConvertible, Equatable, Sendable  

 public class Call: @unchecked Sendable, WSEventsSubscriber  
-   public func updateAudioSessionPolicy(_ policy: AudioSessionPolicy)async throws 
+   public func updateAudioSessionPolicy(_ policy: AudioSessionPolicy)async 

Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

Really nice implementation! Left few minor comments, and let's test this extensively.

@@ -124,15 +124,7 @@ actor WebRTCStateAdapter: ObservableObject, StreamAudioSessionAdapterDelegate {
self.rtcPeerConnectionCoordinatorFactory = rtcPeerConnectionCoordinatorFactory
self.videoCaptureSessionProvider = videoCaptureSessionProvider
self.screenShareSessionProvider = screenShareSessionProvider
self.audioSession = .init(audioDeviceModule: peerConnectionFactory.audioDeviceModule)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should test audio filters and noise cancellation after these changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Audio filters shouldn't be affected as they are running directly in the WebRTC audio device module pipeline (which is the lower lever of the AudioSession we are using). In any case we should test them

@ipavlidakis ipavlidakis force-pushed the enhancement/improved-audio-session-management branch from b7a8c95 to 9b20956 Compare August 7, 2025 08:01
@ipavlidakis ipavlidakis force-pushed the enhancement/improved-audio-session-management branch from 8d31967 to 3a21a9d Compare August 7, 2025 09:49
@ipavlidakis ipavlidakis marked this pull request as ready for review August 7, 2025 16:04
@ipavlidakis ipavlidakis requested a review from a team as a code owner August 7, 2025 16:05
Copy link

sonarqubecloud bot commented Aug 7, 2025

Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

Great work! ✅

@ipavlidakis ipavlidakis merged commit 365b984 into develop Aug 8, 2025
17 of 20 checks passed
@ipavlidakis ipavlidakis deleted the enhancement/improved-audio-session-management branch August 8, 2025 08:31
@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants