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