1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2016 The WebRTC Project Authors. All rights reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #import "RTCAudioSession.h" 12*d9f75844SAndroid Build Coastguard Worker 13*d9f75844SAndroid Build Coastguard Worker NS_ASSUME_NONNULL_BEGIN 14*d9f75844SAndroid Build Coastguard Worker 15*d9f75844SAndroid Build Coastguard Worker @class RTC_OBJC_TYPE(RTCAudioSessionConfiguration); 16*d9f75844SAndroid Build Coastguard Worker 17*d9f75844SAndroid Build Coastguard Worker @interface RTC_OBJC_TYPE (RTCAudioSession) 18*d9f75844SAndroid Build Coastguard Worker () 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker /** Number of times setActive:YES has succeeded without a balanced call to 21*d9f75844SAndroid Build Coastguard Worker * setActive:NO. 22*d9f75844SAndroid Build Coastguard Worker */ 23*d9f75844SAndroid Build Coastguard Worker @property(nonatomic, readonly) int activationCount; 24*d9f75844SAndroid Build Coastguard Worker 25*d9f75844SAndroid Build Coastguard Worker /** The number of times `beginWebRTCSession` was called without a balanced call 26*d9f75844SAndroid Build Coastguard Worker * to `endWebRTCSession`. 27*d9f75844SAndroid Build Coastguard Worker */ 28*d9f75844SAndroid Build Coastguard Worker @property(nonatomic, readonly) int webRTCSessionCount; 29*d9f75844SAndroid Build Coastguard Worker 30*d9f75844SAndroid Build Coastguard Worker /** Convenience BOOL that checks useManualAudio and isAudioEnebled. */ 31*d9f75844SAndroid Build Coastguard Worker @property(readonly) BOOL canPlayOrRecord; 32*d9f75844SAndroid Build Coastguard Worker 33*d9f75844SAndroid Build Coastguard Worker /** Tracks whether we have been sent an interruption event that hasn't been matched by either an 34*d9f75844SAndroid Build Coastguard Worker * interrupted end event or a foreground event. 35*d9f75844SAndroid Build Coastguard Worker */ 36*d9f75844SAndroid Build Coastguard Worker @property(nonatomic, assign) BOOL isInterrupted; 37*d9f75844SAndroid Build Coastguard Worker 38*d9f75844SAndroid Build Coastguard Worker /** Adds the delegate to the list of delegates, and places it at the front of 39*d9f75844SAndroid Build Coastguard Worker * the list. This delegate will be notified before other delegates of 40*d9f75844SAndroid Build Coastguard Worker * audio events. 41*d9f75844SAndroid Build Coastguard Worker */ 42*d9f75844SAndroid Build Coastguard Worker - (void)pushDelegate:(id<RTC_OBJC_TYPE(RTCAudioSessionDelegate)>)delegate; 43*d9f75844SAndroid Build Coastguard Worker 44*d9f75844SAndroid Build Coastguard Worker /** Signals RTCAudioSession that a WebRTC session is about to begin and 45*d9f75844SAndroid Build Coastguard Worker * audio configuration is needed. Will configure the audio session for WebRTC 46*d9f75844SAndroid Build Coastguard Worker * if not already configured and if configuration is not delayed. 47*d9f75844SAndroid Build Coastguard Worker * Successful calls must be balanced by a call to endWebRTCSession. 48*d9f75844SAndroid Build Coastguard Worker */ 49*d9f75844SAndroid Build Coastguard Worker - (BOOL)beginWebRTCSession:(NSError **)outError; 50*d9f75844SAndroid Build Coastguard Worker 51*d9f75844SAndroid Build Coastguard Worker /** Signals RTCAudioSession that a WebRTC session is about to end and audio 52*d9f75844SAndroid Build Coastguard Worker * unconfiguration is needed. Will unconfigure the audio session for WebRTC 53*d9f75844SAndroid Build Coastguard Worker * if this is the last unmatched call and if configuration is not delayed. 54*d9f75844SAndroid Build Coastguard Worker */ 55*d9f75844SAndroid Build Coastguard Worker - (BOOL)endWebRTCSession:(NSError **)outError; 56*d9f75844SAndroid Build Coastguard Worker 57*d9f75844SAndroid Build Coastguard Worker /** Configure the audio session for WebRTC. This call will fail if the session 58*d9f75844SAndroid Build Coastguard Worker * is already configured. On other failures, we will attempt to restore the 59*d9f75844SAndroid Build Coastguard Worker * previously used audio session configuration. 60*d9f75844SAndroid Build Coastguard Worker * `lockForConfiguration` must be called first. 61*d9f75844SAndroid Build Coastguard Worker * Successful calls to configureWebRTCSession must be matched by calls to 62*d9f75844SAndroid Build Coastguard Worker * `unconfigureWebRTCSession`. 63*d9f75844SAndroid Build Coastguard Worker */ 64*d9f75844SAndroid Build Coastguard Worker - (BOOL)configureWebRTCSession:(NSError **)outError; 65*d9f75844SAndroid Build Coastguard Worker 66*d9f75844SAndroid Build Coastguard Worker /** Unconfigures the session for WebRTC. This will attempt to restore the 67*d9f75844SAndroid Build Coastguard Worker * audio session to the settings used before `configureWebRTCSession` was 68*d9f75844SAndroid Build Coastguard Worker * called. 69*d9f75844SAndroid Build Coastguard Worker * `lockForConfiguration` must be called first. 70*d9f75844SAndroid Build Coastguard Worker */ 71*d9f75844SAndroid Build Coastguard Worker - (BOOL)unconfigureWebRTCSession:(NSError **)outError; 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker /** Returns a configuration error with the given description. */ 74*d9f75844SAndroid Build Coastguard Worker - (NSError *)configurationErrorWithDescription:(NSString *)description; 75*d9f75844SAndroid Build Coastguard Worker 76*d9f75844SAndroid Build Coastguard Worker /** Notifies the receiver that a playout glitch was detected. */ 77*d9f75844SAndroid Build Coastguard Worker - (void)notifyDidDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches; 78*d9f75844SAndroid Build Coastguard Worker 79*d9f75844SAndroid Build Coastguard Worker /** Notifies the receiver that there was an error when starting an audio unit. */ 80*d9f75844SAndroid Build Coastguard Worker - (void)notifyAudioUnitStartFailedWithError:(OSStatus)error; 81*d9f75844SAndroid Build Coastguard Worker 82*d9f75844SAndroid Build Coastguard Worker // Properties and methods for tests. 83*d9f75844SAndroid Build Coastguard Worker - (void)notifyDidBeginInterruption; 84*d9f75844SAndroid Build Coastguard Worker - (void)notifyDidEndInterruptionWithShouldResumeSession:(BOOL)shouldResumeSession; 85*d9f75844SAndroid Build Coastguard Worker - (void)notifyDidChangeRouteWithReason:(AVAudioSessionRouteChangeReason)reason 86*d9f75844SAndroid Build Coastguard Worker previousRoute:(AVAudioSessionRouteDescription *)previousRoute; 87*d9f75844SAndroid Build Coastguard Worker - (void)notifyMediaServicesWereLost; 88*d9f75844SAndroid Build Coastguard Worker - (void)notifyMediaServicesWereReset; 89*d9f75844SAndroid Build Coastguard Worker - (void)notifyDidChangeCanPlayOrRecord:(BOOL)canPlayOrRecord; 90*d9f75844SAndroid Build Coastguard Worker - (void)notifyDidStartPlayOrRecord; 91*d9f75844SAndroid Build Coastguard Worker - (void)notifyDidStopPlayOrRecord; 92*d9f75844SAndroid Build Coastguard Worker 93*d9f75844SAndroid Build Coastguard Worker @end 94*d9f75844SAndroid Build Coastguard Worker 95*d9f75844SAndroid Build Coastguard Worker NS_ASSUME_NONNULL_END 96