RTCAudioSession

Superclass:
NSObject
Declared In:

Introduction

Proxy class for AVAudioSession that adds a locking mechanism similar to AVCaptureDevice. This is used to that interleaving configurations between WebRTC and the application layer are avoided. Only setter methods are currently proxied. Getters can be accessed directly off AVAudioSession.

RTCAudioSession also coordinates activation so that the audio session is activated only once. See |setActive:error:|.



Methods

-addDelegate:
-lockForConfiguration
-removeDelegate:
-setActive:error:
+sharedInstance
-unlockForConfiguration

addDelegate:


- (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate; 
Discussion

Adds a delegate, which is held weakly. Even though it's held weakly, callers should still call |removeDelegate| when it's no longer required to ensure proper dealloc. This is due to internal use of an NSHashTable.


lockForConfiguration


- (void)lockForConfiguration; 
Discussion

Request exclusive access to the audio session for configuration. This call will block if the lock is held by another object.


removeDelegate:


- (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate; 
Discussion

Removes an added delegate.


setActive:error:


- (BOOL)setActive:(BOOL)active error:(NSError **)outError; 
Discussion

If |active|, activates the audio session if it isn't already active. Successful calls must be balanced with a setActive:NO when activation is no longer required. If not |active|, deactivates the audio session if one is active and this is the last balanced call. When deactivating, the AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation option is passed to AVAudioSession.


sharedInstance


+ (instancetype)sharedInstance; 
Discussion

Default constructor. Do not call init.


unlockForConfiguration


- (void)unlockForConfiguration; 
Discussion

Relinquishes exclusive access to the audio session.


Properties

inputDataSource
isActive
isLocked
outputDataSource
session

inputDataSource


@property(readonly,
    nullable) AVAudioSessionDataSourceDescription *inputDataSource; 
Discussion

NSArray<AVAudioSessionDataSourceDescription *> * inputDataSources;


isActive


@property(nonatomic,
    readonly) BOOL isActive; 
Discussion

Our best guess at whether the session is active based on results of calls to AVAudioSession.


isLocked


@property(nonatomic,
    readonly) BOOL isLocked; 
Discussion

Whether RTCAudioSession is currently locked for configuration.


outputDataSource


@property(readonly,
    nullable) AVAudioSessionDataSourceDescription *outputDataSource; 
Discussion

NSArray<AVAudioSessionDataSourceDescription *> * outputDataSources;


session


@property(nonatomic,
    readonly) AVAudioSession *session; 
Discussion

Convenience property to access the AVAudioSession singleton. Callers should not call setters on AVAudioSession directly, but other method invocations are fine.