OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 */ | 51 */ |
52 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session; | 52 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session; |
53 | 53 |
54 /** Called on a system notification thread when AVAudioSession media server | 54 /** Called on a system notification thread when AVAudioSession media server |
55 * restarts. | 55 * restarts. |
56 */ | 56 */ |
57 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session; | 57 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session; |
58 | 58 |
59 // TODO(tkchin): Maybe handle SilenceSecondaryAudioHintNotification. | 59 // TODO(tkchin): Maybe handle SilenceSecondaryAudioHintNotification. |
60 | 60 |
61 /** Called on a WebRTC thread when WebRTC needs to take over audio. Applications | 61 - (void)audioSession:(RTCAudioSession *)session |
62 * should call -[RTCAudioSession configureWebRTCSession] to allow WebRTC to | 62 didChangeCanPlayOrRecord:(BOOL)canPlayOrRecord; |
63 * play and record audio. Will only occur if shouldDelayAudioConfiguration is | 63 |
64 * set to YES. | 64 /** Called on a WebRTC thread when the audio device is notified to begin |
| 65 * playback or recording. |
65 */ | 66 */ |
66 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session; | 67 - (void)audioSessionDidStartPlayOrRecord:(RTCAudioSession *)session; |
67 | 68 |
68 /** Called on a WebRTC thread when WebRTC no longer requires audio. Applications | 69 /** Called on a WebRTC thread when the audio device is notified to stop |
69 * should call -[RTCAudioSession unconfigureWebRTCSession] to restore their | 70 * playback or recording. |
70 * audio session settings. Will only occur if shouldDelayAudioConfiguration is | |
71 * set to YES. | |
72 */ | 71 */ |
73 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session; | 72 - (void)audioSessionDidStopPlayOrRecord:(RTCAudioSession *)session; |
74 | |
75 /** Called on a WebRTC thread when WebRTC has configured the audio session for | |
76 * WebRTC audio. | |
77 */ | |
78 - (void)audioSessionDidConfigure:(RTCAudioSession *)session; | |
79 | |
80 /** Called on a WebRTC thread when WebRTC has unconfigured the audio session for | |
81 * WebRTC audio. | |
82 */ | |
83 - (void)audioSessionDidUnconfigure:(RTCAudioSession *)session; | |
84 | 73 |
85 @end | 74 @end |
86 | 75 |
87 /** Proxy class for AVAudioSession that adds a locking mechanism similar to | 76 /** Proxy class for AVAudioSession that adds a locking mechanism similar to |
88 * AVCaptureDevice. This is used to that interleaving configurations between | 77 * AVCaptureDevice. This is used to that interleaving configurations between |
89 * WebRTC and the application layer are avoided. | 78 * WebRTC and the application layer are avoided. |
90 * | 79 * |
91 * RTCAudioSession also coordinates activation so that the audio session is | 80 * RTCAudioSession also coordinates activation so that the audio session is |
92 * activated only once. See |setActive:error:|. | 81 * activated only once. See |setActive:error:|. |
93 */ | 82 */ |
94 @interface RTCAudioSession : NSObject | 83 @interface RTCAudioSession : NSObject |
95 | 84 |
96 /** Convenience property to access the AVAudioSession singleton. Callers should | 85 /** Convenience property to access the AVAudioSession singleton. Callers should |
97 * not call setters on AVAudioSession directly, but other method invocations | 86 * not call setters on AVAudioSession directly, but other method invocations |
98 * are fine. | 87 * are fine. |
99 */ | 88 */ |
100 @property(nonatomic, readonly) AVAudioSession *session; | 89 @property(nonatomic, readonly) AVAudioSession *session; |
101 | 90 |
102 /** Our best guess at whether the session is active based on results of calls to | 91 /** Our best guess at whether the session is active based on results of calls to |
103 * AVAudioSession. | 92 * AVAudioSession. |
104 */ | 93 */ |
105 @property(nonatomic, readonly) BOOL isActive; | 94 @property(nonatomic, readonly) BOOL isActive; |
106 /** Whether RTCAudioSession is currently locked for configuration. */ | 95 /** Whether RTCAudioSession is currently locked for configuration. */ |
107 @property(nonatomic, readonly) BOOL isLocked; | 96 @property(nonatomic, readonly) BOOL isLocked; |
108 | 97 |
109 /** If YES, WebRTC will not initialize the audio unit automatically when an | 98 /** If YES, WebRTC will not initialize the audio unit automatically when an |
110 * audio track is ready for playout or recording. Instead, applications should | 99 * audio track is ready for playout or recording. Instead, applications should |
111 * listen to the delegate method |audioSessionShouldConfigure| and configure | 100 * call setIsAudioEnabled. If NO, WebRTC will initialize the audio unit |
112 * the session manually. This should be set before making WebRTC media calls | 101 * as soon as an audio track is ready for playout or recording. |
113 * and should not be changed while a call is active. | |
114 */ | 102 */ |
115 @property(nonatomic, assign) BOOL shouldDelayAudioConfiguration; | 103 @property(nonatomic, assign) BOOL useManualAudio; |
| 104 |
| 105 /** This property is only effective if useManualAudio is YES. |
| 106 * Represents permission for WebRTC to initialize the VoIP audio unit. |
| 107 * When set to NO, if the VoIP audio unit used by WebRTC is active, it will be |
| 108 * stopped and uninitialized. This will stop incoming and outgoing audio. |
| 109 * When set to YES, WebRTC will initialize and start the audio unit when it is |
| 110 * needed (e.g. due to establishing an audio connection). |
| 111 * This property was introduced to work around an issue where if an AVPlayer is |
| 112 * playing audio while the VoIP audio unit is initialized, its audio would be |
| 113 * either cut off completely or played at a reduced volume. By preventing |
| 114 * the audio unit from being initialized until after the audio has completed, |
| 115 * we are able to prevent the abrupt cutoff. |
| 116 */ |
| 117 @property(nonatomic, assign) BOOL isAudioEnabled; |
116 | 118 |
117 // Proxy properties. | 119 // Proxy properties. |
118 @property(readonly) NSString *category; | 120 @property(readonly) NSString *category; |
119 @property(readonly) AVAudioSessionCategoryOptions categoryOptions; | 121 @property(readonly) AVAudioSessionCategoryOptions categoryOptions; |
120 @property(readonly) NSString *mode; | 122 @property(readonly) NSString *mode; |
121 @property(readonly) BOOL secondaryAudioShouldBeSilencedHint; | 123 @property(readonly) BOOL secondaryAudioShouldBeSilencedHint; |
122 @property(readonly) AVAudioSessionRouteDescription *currentRoute; | 124 @property(readonly) AVAudioSessionRouteDescription *currentRoute; |
123 @property(readonly) NSInteger maximumInputNumberOfChannels; | 125 @property(readonly) NSInteger maximumInputNumberOfChannels; |
124 @property(readonly) NSInteger maximumOutputNumberOfChannels; | 126 @property(readonly) NSInteger maximumOutputNumberOfChannels; |
125 @property(readonly) float inputGain; | 127 @property(readonly) float inputGain; |
126 @property(readonly) BOOL inputGainSettable; | 128 @property(readonly) BOOL inputGainSettable; |
127 @property(readonly) BOOL inputAvailable; | 129 @property(readonly) BOOL inputAvailable; |
128 @property(readonly, nullable) | 130 @property(readonly, nullable) |
129 NSArray<AVAudioSessionDataSourceDescription *> * inputDataSources; | 131 NSArray<AVAudioSessionDataSourceDescription *> * inputDataSources; |
130 @property(readonly, nullable) | 132 @property(readonly, nullable) |
131 AVAudioSessionDataSourceDescription *inputDataSource; | 133 AVAudioSessionDataSourceDescription *inputDataSource; |
132 @property(readonly, nullable) | 134 @property(readonly, nullable) |
133 NSArray<AVAudioSessionDataSourceDescription *> * outputDataSources; | 135 NSArray<AVAudioSessionDataSourceDescription *> * outputDataSources; |
134 @property(readonly, nullable) | 136 @property(readonly, nullable) |
135 AVAudioSessionDataSourceDescription *outputDataSource; | 137 AVAudioSessionDataSourceDescription *outputDataSource; |
136 @property(readonly) double sampleRate; | 138 @property(readonly) double sampleRate; |
| 139 @property(readonly) double preferredSampleRate; |
137 @property(readonly) NSInteger inputNumberOfChannels; | 140 @property(readonly) NSInteger inputNumberOfChannels; |
138 @property(readonly) NSInteger outputNumberOfChannels; | 141 @property(readonly) NSInteger outputNumberOfChannels; |
139 @property(readonly) float outputVolume; | 142 @property(readonly) float outputVolume; |
140 @property(readonly) NSTimeInterval inputLatency; | 143 @property(readonly) NSTimeInterval inputLatency; |
141 @property(readonly) NSTimeInterval outputLatency; | 144 @property(readonly) NSTimeInterval outputLatency; |
142 @property(readonly) NSTimeInterval IOBufferDuration; | 145 @property(readonly) NSTimeInterval IOBufferDuration; |
| 146 @property(readonly) NSTimeInterval preferredIOBufferDuration; |
143 | 147 |
144 /** Default constructor. */ | 148 /** Default constructor. */ |
145 + (instancetype)sharedInstance; | 149 + (instancetype)sharedInstance; |
146 - (instancetype)init NS_UNAVAILABLE; | 150 - (instancetype)init NS_UNAVAILABLE; |
147 | 151 |
148 /** Adds a delegate, which is held weakly. */ | 152 /** Adds a delegate, which is held weakly. */ |
149 - (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate; | 153 - (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate; |
150 /** Removes an added delegate. */ | 154 /** Removes an added delegate. */ |
151 - (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate; | 155 - (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate; |
152 | 156 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 error:(NSError **)outError; | 193 error:(NSError **)outError; |
190 - (BOOL)setInputDataSource:(AVAudioSessionDataSourceDescription *)dataSource | 194 - (BOOL)setInputDataSource:(AVAudioSessionDataSourceDescription *)dataSource |
191 error:(NSError **)outError; | 195 error:(NSError **)outError; |
192 - (BOOL)setOutputDataSource:(AVAudioSessionDataSourceDescription *)dataSource | 196 - (BOOL)setOutputDataSource:(AVAudioSessionDataSourceDescription *)dataSource |
193 error:(NSError **)outError; | 197 error:(NSError **)outError; |
194 | 198 |
195 @end | 199 @end |
196 | 200 |
197 @interface RTCAudioSession (Configuration) | 201 @interface RTCAudioSession (Configuration) |
198 | 202 |
199 /** Whether or not |configureWebRTCSession| has been called without a balanced | |
200 * call to |unconfigureWebRTCSession|. This is not an indication of whether the | |
201 * audio session has the right settings. | |
202 */ | |
203 @property(readonly) BOOL isConfiguredForWebRTC; | |
204 | |
205 /** Applies the configuration to the current session. Attempts to set all | 203 /** Applies the configuration to the current session. Attempts to set all |
206 * properties even if previous ones fail. Only the last error will be | 204 * properties even if previous ones fail. Only the last error will be |
207 * returned. Also calls setActive with |active|. | 205 * returned. |
| 206 * |lockForConfiguration| must be called first. |
| 207 */ |
| 208 - (BOOL)setConfiguration:(RTCAudioSessionConfiguration *)configuration |
| 209 error:(NSError **)outError; |
| 210 |
| 211 /** Convenience method that calls both setConfiguration and setActive. |
208 * |lockForConfiguration| must be called first. | 212 * |lockForConfiguration| must be called first. |
209 */ | 213 */ |
210 - (BOOL)setConfiguration:(RTCAudioSessionConfiguration *)configuration | 214 - (BOOL)setConfiguration:(RTCAudioSessionConfiguration *)configuration |
211 active:(BOOL)active | 215 active:(BOOL)active |
212 error:(NSError **)outError; | 216 error:(NSError **)outError; |
213 | 217 |
214 /** Configure the audio session for WebRTC. This call will fail if the session | |
215 * is already configured. On other failures, we will attempt to restore the | |
216 * previously used audio session configuration. | |
217 * |lockForConfiguration| must be called first. | |
218 * Successful calls to configureWebRTCSession must be matched by calls to | |
219 * |unconfigureWebRTCSession|. | |
220 */ | |
221 - (BOOL)configureWebRTCSession:(NSError **)outError; | |
222 | |
223 /** Unconfigures the session for WebRTC. This will attempt to restore the | |
224 * audio session to the settings used before |configureWebRTCSession| was | |
225 * called. | |
226 * |lockForConfiguration| must be called first. | |
227 */ | |
228 - (BOOL)unconfigureWebRTCSession:(NSError **)outError; | |
229 | |
230 @end | 218 @end |
231 | 219 |
232 NS_ASSUME_NONNULL_END | 220 NS_ASSUME_NONNULL_END |
OLD | NEW |