Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSession.h

Issue 1822543002: Support delayed AudioUnit initialization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #import <AVFoundation/AVFoundation.h> 11 #import <AVFoundation/AVFoundation.h>
12 #import <Foundation/Foundation.h> 12 #import <Foundation/Foundation.h>
13 13
14 NS_ASSUME_NONNULL_BEGIN 14 NS_ASSUME_NONNULL_BEGIN
15 15
16 extern NSString * const kRTCAudioSessionErrorDomain; 16 extern NSString * const kRTCAudioSessionErrorDomain;
17 /** Method that requires lock was called without lock. */ 17 /** Method that requires lock was called without lock. */
18 extern NSInteger const kRTCAudioSessionErrorLockRequired; 18 extern NSInteger const kRTCAudioSessionErrorLockRequired;
19 /** Unknown configuration error occurred. */ 19 /** Unknown configuration error occurred. */
20 extern NSInteger const kRTCAudioSessionErrorConfiguration; 20 extern NSInteger const kRTCAudioSessionErrorConfiguration;
21 21
22 @class RTCAudioSession; 22 @class RTCAudioSession;
23 @class RTCAudioSessionConfiguration; 23 @class RTCAudioSessionConfiguration;
24 24
25 // Surfaces AVAudioSession events. WebRTC will listen directly for notifications 25 // Surfaces AVAudioSession events. WebRTC will listen directly for notifications
26 // from AVAudioSession and handle them before calling these delegate methods, 26 // from AVAudioSession and handle them before calling these delegate methods,
27 // at which point applications can perform additional processing if required. 27 // at which point applications can perform additional processing if required.
28 @protocol RTCAudioSessionDelegate <NSObject> 28 @protocol RTCAudioSessionDelegate <NSObject>
29 29
30 /** Called when AVAudioSession starts an interruption event. */ 30 @optional
31 /** Called on a system notification thread when AVAudioSession starts an
32 * interruption event.
33 */
31 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session; 34 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session;
32 35
33 /** Called when AVAudioSession ends an interruption event. */ 36 /** Called on a system notification thread when AVAudioSession ends an
37 * interruption event.
38 */
34 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session 39 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session
35 shouldResumeSession:(BOOL)shouldResumeSession; 40 shouldResumeSession:(BOOL)shouldResumeSession;
36 41
37 /** Called when AVAudioSession changes the route. */ 42 /** Called on a system notification thread when AVAudioSession changes the
43 * route.
44 */
38 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session 45 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session
39 reason:(AVAudioSessionRouteChangeReason)reason 46 reason:(AVAudioSessionRouteChangeReason)reason
40 previousRoute:(AVAudioSessionRouteDescription *)previousRoute; 47 previousRoute:(AVAudioSessionRouteDescription *)previousRoute;
41 48
42 /** Called when AVAudioSession media server terminates. */ 49 /** Called on a system notification thread when AVAudioSession media server
50 * terminates.
51 */
43 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session; 52 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session;
44 53
45 /** Called when AVAudioSession media server restarts. */ 54 /** Called on a system notification thread when AVAudioSession media server
55 * restarts.
56 */
46 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session; 57 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session;
47 58
48 /** Called when WebRTC needs to take over audio. Applications should call 59 // TODO(tkchin): Maybe handle SilenceSecondaryAudioHintNotification.
49 * -[RTCAudioSession configure] to allow WebRTC to play and record audio. 60
50 * TODO(tkchin): Implement this behavior in RTCAudioSession. 61 /** Called on a WebRTC thread when WebRTC needs to take over audio. Applications
62 * should call -[RTCAudioSession configureWebRTCSession] to allow WebRTC to
63 * play and record audio. Will only occur if shouldDelayAudioConfiguration is
64 * set to YES.
51 */ 65 */
52 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session; 66 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session;
53 67
54 /** Called when WebRTC no longer requires audio. Applications should restore 68 /** Called on a WebRTC thread when WebRTC no longer requires audio. Applications
55 * their audio state at this point. 69 * should call -[RTCAudioSession unconfigureWebRTCSession] to restore their
56 * TODO(tkchin): Implement this behavior in RTCAudioSession. 70 * audio session settings. Will only occur if shouldDelayAudioConfiguration is
71 * set to YES.
57 */ 72 */
58 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session; 73 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session;
59 74
60 // TODO(tkchin): Maybe handle SilenceSecondaryAudioHintNotification. 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;
61 84
62 @end 85 @end
63 86
64 /** Proxy class for AVAudioSession that adds a locking mechanism similar to 87 /** Proxy class for AVAudioSession that adds a locking mechanism similar to
65 * AVCaptureDevice. This is used to that interleaving configurations between 88 * AVCaptureDevice. This is used to that interleaving configurations between
66 * WebRTC and the application layer are avoided. Only setter methods are 89 * WebRTC and the application layer are avoided.
67 * currently proxied. Getters can be accessed directly off AVAudioSession.
68 * 90 *
69 * RTCAudioSession also coordinates activation so that the audio session is 91 * RTCAudioSession also coordinates activation so that the audio session is
70 * activated only once. See |setActive:error:|. 92 * activated only once. See |setActive:error:|.
71 */ 93 */
72 @interface RTCAudioSession : NSObject 94 @interface RTCAudioSession : NSObject
73 95
74 /** Convenience property to access the AVAudioSession singleton. Callers should 96 /** Convenience property to access the AVAudioSession singleton. Callers should
75 * not call setters on AVAudioSession directly, but other method invocations 97 * not call setters on AVAudioSession directly, but other method invocations
76 * are fine. 98 * are fine.
77 */ 99 */
78 @property(nonatomic, readonly) AVAudioSession *session; 100 @property(nonatomic, readonly) AVAudioSession *session;
79 101
80 /** Our best guess at whether the session is active based on results of calls to 102 /** Our best guess at whether the session is active based on results of calls to
81 * AVAudioSession. 103 * AVAudioSession.
82 */ 104 */
83 @property(nonatomic, readonly) BOOL isActive; 105 @property(nonatomic, readonly) BOOL isActive;
84 /** Whether RTCAudioSession is currently locked for configuration. */ 106 /** Whether RTCAudioSession is currently locked for configuration. */
85 @property(nonatomic, readonly) BOOL isLocked; 107 @property(nonatomic, readonly) BOOL isLocked;
86 108
87 /** If YES, WebRTC will not initialize the audio unit automatically when an 109 /** If YES, WebRTC will not initialize the audio unit automatically when an
88 * audio track is ready for playout or recording. Instead, applications should 110 * audio track is ready for playout or recording. Instead, applications should
89 * listen to the delegate method |audioSessionShouldConfigure| and configure 111 * listen to the delegate method |audioSessionShouldConfigure| and configure
90 * the session manually. This should be set before making WebRTC media calls. 112 * the session manually. This should be set before making WebRTC media calls
91 * TODO(tkchin): Implement behavior. Currently this just stores a BOOL. 113 * and should not be changed while a call is active.
92 */ 114 */
93 @property(nonatomic, assign) BOOL shouldDelayAudioConfiguration; 115 @property(nonatomic, assign) BOOL shouldDelayAudioConfiguration;
94 116
95 // Proxy properties. 117 // Proxy properties.
96 @property(readonly) NSString *category; 118 @property(readonly) NSString *category;
97 @property(readonly) AVAudioSessionCategoryOptions categoryOptions; 119 @property(readonly) AVAudioSessionCategoryOptions categoryOptions;
98 @property(readonly) NSString *mode; 120 @property(readonly) NSString *mode;
99 @property(readonly) BOOL secondaryAudioShouldBeSilencedHint; 121 @property(readonly) BOOL secondaryAudioShouldBeSilencedHint;
100 @property(readonly) AVAudioSessionRouteDescription *currentRoute; 122 @property(readonly) AVAudioSessionRouteDescription *currentRoute;
101 @property(readonly) NSInteger maximumInputNumberOfChannels; 123 @property(readonly) NSInteger maximumInputNumberOfChannels;
(...skipping 10 matching lines...) Expand all
112 @property(readonly, nullable) 134 @property(readonly, nullable)
113 AVAudioSessionDataSourceDescription *outputDataSource; 135 AVAudioSessionDataSourceDescription *outputDataSource;
114 @property(readonly) double sampleRate; 136 @property(readonly) double sampleRate;
115 @property(readonly) NSInteger inputNumberOfChannels; 137 @property(readonly) NSInteger inputNumberOfChannels;
116 @property(readonly) NSInteger outputNumberOfChannels; 138 @property(readonly) NSInteger outputNumberOfChannels;
117 @property(readonly) float outputVolume; 139 @property(readonly) float outputVolume;
118 @property(readonly) NSTimeInterval inputLatency; 140 @property(readonly) NSTimeInterval inputLatency;
119 @property(readonly) NSTimeInterval outputLatency; 141 @property(readonly) NSTimeInterval outputLatency;
120 @property(readonly) NSTimeInterval IOBufferDuration; 142 @property(readonly) NSTimeInterval IOBufferDuration;
121 143
122 /** Default constructor. Do not call init. */ 144 /** Default constructor. */
123 + (instancetype)sharedInstance; 145 + (instancetype)sharedInstance;
146 - (instancetype)init NS_UNAVAILABLE;
124 147
125 /** Adds a delegate, which is held weakly. */ 148 /** Adds a delegate, which is held weakly. */
126 - (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate; 149 - (void)addDelegate:(id<RTCAudioSessionDelegate>)delegate;
127 /** Removes an added delegate. */ 150 /** Removes an added delegate. */
128 - (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate; 151 - (void)removeDelegate:(id<RTCAudioSessionDelegate>)delegate;
129 152
130 /** Request exclusive access to the audio session for configuration. This call 153 /** Request exclusive access to the audio session for configuration. This call
131 * will block if the lock is held by another object. 154 * will block if the lock is held by another object.
132 */ 155 */
133 - (void)lockForConfiguration; 156 - (void)lockForConfiguration;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 error:(NSError **)outError; 189 error:(NSError **)outError;
167 - (BOOL)setInputDataSource:(AVAudioSessionDataSourceDescription *)dataSource 190 - (BOOL)setInputDataSource:(AVAudioSessionDataSourceDescription *)dataSource
168 error:(NSError **)outError; 191 error:(NSError **)outError;
169 - (BOOL)setOutputDataSource:(AVAudioSessionDataSourceDescription *)dataSource 192 - (BOOL)setOutputDataSource:(AVAudioSessionDataSourceDescription *)dataSource
170 error:(NSError **)outError; 193 error:(NSError **)outError;
171 194
172 @end 195 @end
173 196
174 @interface RTCAudioSession (Configuration) 197 @interface RTCAudioSession (Configuration)
175 198
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
176 /** Applies the configuration to the current session. Attempts to set all 205 /** Applies the configuration to the current session. Attempts to set all
177 * properties even if previous ones fail. Only the last error will be 206 * properties even if previous ones fail. Only the last error will be
178 * returned. Also calls setActive with |active|. 207 * returned. Also calls setActive with |active|.
179 * |lockForConfiguration| must be called first. 208 * |lockForConfiguration| must be called first.
180 */ 209 */
181 - (BOOL)setConfiguration:(RTCAudioSessionConfiguration *)configuration 210 - (BOOL)setConfiguration:(RTCAudioSessionConfiguration *)configuration
182 active:(BOOL)active 211 active:(BOOL)active
183 error:(NSError **)outError; 212 error:(NSError **)outError;
184 213
185 /** Configure the audio session for WebRTC. On failure, we will attempt to 214 /** Configure the audio session for WebRTC. This call will fail if the session
186 * restore the previously used audio session configuration. 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.
187 * |lockForConfiguration| must be called first. 226 * |lockForConfiguration| must be called first.
188 */ 227 */
189 - (BOOL)configureWebRTCSession:(NSError **)outError; 228 - (BOOL)unconfigureWebRTCSession:(NSError **)outError;
190 229
191 @end 230 @end
192 231
193 NS_ASSUME_NONNULL_END 232 NS_ASSUME_NONNULL_END
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/ios/audio_session_observer.h ('k') | webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698