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

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

Issue 1778793005: Refactor AVAudioSession intialization code. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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 extern NSInteger const kRTCAudioSessionErrorLockRequired; 17 extern NSInteger const kRTCAudioSessionErrorLockRequired;
18 18
19 @class RTCAudioSession; 19 @class RTCAudioSession;
20 @class RTCAudioSessionConfiguration;
20 21
21 // Surfaces AVAudioSession events. WebRTC will listen directly for notifications 22 // Surfaces AVAudioSession events. WebRTC will listen directly for notifications
22 // from AVAudioSession and handle them before calling these delegate methods, 23 // from AVAudioSession and handle them before calling these delegate methods,
23 // at which point applications can perform additional processing if required. 24 // at which point applications can perform additional processing if required.
24 @protocol RTCAudioSessionDelegate <NSObject> 25 @protocol RTCAudioSessionDelegate <NSObject>
25 26
26 /** Called when AVAudioSession starts an interruption event. */ 27 /** Called when AVAudioSession starts an interruption event. */
27 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session; 28 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session;
28 29
29 /** Called when AVAudioSession ends an interruption event. */ 30 /** Called when AVAudioSession ends an interruption event. */
30 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session 31 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session
31 shouldResumeSession:(BOOL)shouldResumeSession; 32 shouldResumeSession:(BOOL)shouldResumeSession;
32 33
33 /** Called when AVAudioSession changes the route. */ 34 /** Called when AVAudioSession changes the route. */
34 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session 35 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session
35 reason:(AVAudioSessionRouteChangeReason)reason 36 reason:(AVAudioSessionRouteChangeReason)reason
36 previousRoute:(AVAudioSessionRouteDescription *)previousRoute; 37 previousRoute:(AVAudioSessionRouteDescription *)previousRoute;
37 38
38 /** Called when AVAudioSession media server terminates. */ 39 /** Called when AVAudioSession media server terminates. */
39 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session; 40 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session;
40 41
41 /** Called when AVAudioSession media server restarts. */ 42 /** Called when AVAudioSession media server restarts. */
42 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session; 43 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session;
43 44
45 /** Called when WebRTC needs to take over audio. Applications should call
46 * -[RTCAudioSession configure] to allow WebRTC to play and record audio.
47 * TODO(tkchin): Implement this behavior in RTCAudioSession.
48 */
49 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session;
50
51 /** Called when WebRTC no longer requires audio. Applications should restore
52 * their audio state at this point.
53 * TODO(tkchin): Implement this behavior in RTCAudioSession.
54 */
55 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session;
56
44 // TODO(tkchin): Maybe handle SilenceSecondaryAudioHintNotification. 57 // TODO(tkchin): Maybe handle SilenceSecondaryAudioHintNotification.
45 58
46 @end 59 @end
47 60
48 /** Proxy class for AVAudioSession that adds a locking mechanism similar to 61 /** Proxy class for AVAudioSession that adds a locking mechanism similar to
49 * AVCaptureDevice. This is used to that interleaving configurations between 62 * AVCaptureDevice. This is used to that interleaving configurations between
50 * WebRTC and the application layer are avoided. Only setter methods are 63 * WebRTC and the application layer are avoided. Only setter methods are
51 * currently proxied. Getters can be accessed directly off AVAudioSession. 64 * currently proxied. Getters can be accessed directly off AVAudioSession.
52 * 65 *
53 * RTCAudioSession also coordinates activation so that the audio session is 66 * RTCAudioSession also coordinates activation so that the audio session is
54 * activated only once. See |setActive:error:|. 67 * activated only once. See |setActive:error:|.
55 */ 68 */
56 @interface RTCAudioSession : NSObject 69 @interface RTCAudioSession : NSObject
57 70
58 /** Convenience property to access the AVAudioSession singleton. Callers should 71 /** Convenience property to access the AVAudioSession singleton. Callers should
59 * not call setters on AVAudioSession directly, but other method invocations 72 * not call setters on AVAudioSession directly, but other method invocations
60 * are fine. 73 * are fine.
61 */ 74 */
62 @property(nonatomic, readonly) AVAudioSession *session; 75 @property(nonatomic, readonly) AVAudioSession *session;
63 76
64 /** Our best guess at whether the session is active based on results of calls to 77 /** Our best guess at whether the session is active based on results of calls to
65 * AVAudioSession. 78 * AVAudioSession.
66 */ 79 */
67 @property(nonatomic, readonly) BOOL isActive; 80 @property(nonatomic, readonly) BOOL isActive;
68 /** Whether RTCAudioSession is currently locked for configuration. */ 81 /** Whether RTCAudioSession is currently locked for configuration. */
69 @property(nonatomic, readonly) BOOL isLocked; 82 @property(nonatomic, readonly) BOOL isLocked;
70 83
84 /** If YES, WebRTC will not initialize the audio unit automatically when an
85 * audio track is ready for playout or recording. Instead, applications should
86 * listen to the delegate method |audioSessionShouldConfigure| and configure
87 * the session manually. This should be set before making WebRTC media calls.
88 * TODO(tkchin): Implement behavior. Currently this just stores a BOOL.
89 */
90 @property(nonatomic, assign) BOOL shouldDelayAudioConfiguration;
91
71 // Proxy properties. 92 // Proxy properties.
72 @property(readonly) NSString *category; 93 @property(readonly) NSString *category;
73 @property(readonly) AVAudioSessionCategoryOptions categoryOptions; 94 @property(readonly) AVAudioSessionCategoryOptions categoryOptions;
74 @property(readonly) NSString *mode; 95 @property(readonly) NSString *mode;
75 @property(readonly) BOOL secondaryAudioShouldBeSilencedHint; 96 @property(readonly) BOOL secondaryAudioShouldBeSilencedHint;
76 @property(readonly) AVAudioSessionRouteDescription *currentRoute; 97 @property(readonly) AVAudioSessionRouteDescription *currentRoute;
77 @property(readonly) NSInteger maximumInputNumberOfChannels; 98 @property(readonly) NSInteger maximumInputNumberOfChannels;
78 @property(readonly) NSInteger maximumOutputNumberOfChannels; 99 @property(readonly) NSInteger maximumOutputNumberOfChannels;
79 @property(readonly) float inputGain; 100 @property(readonly) float inputGain;
80 @property(readonly) BOOL inputGainSettable; 101 @property(readonly) BOOL inputGainSettable;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 error:(NSError **)outError; 164 error:(NSError **)outError;
144 - (BOOL)setPreferredInput:(AVAudioSessionPortDescription *)inPort 165 - (BOOL)setPreferredInput:(AVAudioSessionPortDescription *)inPort
145 error:(NSError **)outError; 166 error:(NSError **)outError;
146 - (BOOL)setInputDataSource:(AVAudioSessionDataSourceDescription *)dataSource 167 - (BOOL)setInputDataSource:(AVAudioSessionDataSourceDescription *)dataSource
147 error:(NSError **)outError; 168 error:(NSError **)outError;
148 - (BOOL)setOutputDataSource:(AVAudioSessionDataSourceDescription *)dataSource 169 - (BOOL)setOutputDataSource:(AVAudioSessionDataSourceDescription *)dataSource
149 error:(NSError **)outError; 170 error:(NSError **)outError;
150 171
151 @end 172 @end
152 173
174 @interface RTCAudioSession (Configuration)
175
176 /** Returns YES if the audio session is correctly configured for WebRTC.
177 * |lockForConfiguration| must be called first.
178 */
179 - (BOOL)isConfiguredForWebRTC;
180
181 /** Applies the configuration to the current session. Attempts to set all
182 * properties even if previous ones fail. Only the last error will be
183 * returned.
184 * Also calls setActive with |active|.
185 */
186 - (BOOL)setConfiguration:(RTCAudioSessionConfiguration *)configuration
187 active:(BOOL)active
188 error:(NSError **)outError;
189
190 /** Configure the audio session for WebRTC. On failure, we will attempt to
191 * restore the previously used audio session configuration.
192 */
193 - (BOOL)configureWebRTCSession:(NSError **)outError;
194
195 @end
196
153 NS_ASSUME_NONNULL_END 197 NS_ASSUME_NONNULL_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698