blob: 8ee4fddd7fe8838e8ad01e8488181e238ec9362a [file] [log] [blame]
Zeke Chinb3fb71c2016-02-18 15:44:07 -08001/*
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 Carlsson7bca8ca2018-08-30 09:30:29 +020011#import "RTCAudioSession.h"
Zeke Chinb3fb71c2016-02-18 15:44:07 -080012
13NS_ASSUME_NONNULL_BEGIN
14
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020015@class RTC_OBJC_TYPE(RTCAudioSessionConfiguration);
Tze Kwang Chin307a0922016-03-21 13:57:40 -070016
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020017@interface RTC_OBJC_TYPE (RTCAudioSession)
18()
Zeke Chinb3fb71c2016-02-18 15:44:07 -080019
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020020 /** Number of times setActive:YES has succeeded without a balanced call to
21 * setActive:NO.
22 */
23 @property(nonatomic, readonly) int activationCount;
Tze Kwang Chin307a0922016-03-21 13:57:40 -070024
Artem Titovd7ac5812021-07-27 12:23:39 +020025/** The number of times `beginWebRTCSession` was called without a balanced call
26 * to `endWebRTCSession`.
Tze Kwang Chin307a0922016-03-21 13:57:40 -070027 */
28@property(nonatomic, readonly) int webRTCSessionCount;
29
tkchind2511962016-05-06 18:54:15 -070030/** Convenience BOOL that checks useManualAudio and isAudioEnebled. */
31@property(readonly) BOOL canPlayOrRecord;
Zeke Chinb3fb71c2016-02-18 15:44:07 -080032
tkchin93dd6342016-07-27 10:17:14 -070033/** Tracks whether we have been sent an interruption event that hasn't been matched by either an
34 * interrupted end event or a foreground event.
35 */
36@property(nonatomic, assign) BOOL isInterrupted;
37
tkchine54467f2016-03-15 16:54:03 -070038/** Adds the delegate to the list of delegates, and places it at the front of
39 * the list. This delegate will be notified before other delegates of
40 * audio events.
41 */
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020042- (void)pushDelegate:(id<RTC_OBJC_TYPE(RTCAudioSessionDelegate)>)delegate;
tkchine54467f2016-03-15 16:54:03 -070043
Tze Kwang Chin307a0922016-03-21 13:57:40 -070044/** Signals RTCAudioSession that a WebRTC session is about to begin and
45 * audio configuration is needed. Will configure the audio session for WebRTC
46 * if not already configured and if configuration is not delayed.
47 * Successful calls must be balanced by a call to endWebRTCSession.
48 */
49- (BOOL)beginWebRTCSession:(NSError **)outError;
50
51/** Signals RTCAudioSession that a WebRTC session is about to end and audio
52 * unconfiguration is needed. Will unconfigure the audio session for WebRTC
53 * if this is the last unmatched call and if configuration is not delayed.
54 */
55- (BOOL)endWebRTCSession:(NSError **)outError;
56
tkchind2511962016-05-06 18:54:15 -070057/** Configure the audio session for WebRTC. This call will fail if the session
58 * is already configured. On other failures, we will attempt to restore the
59 * previously used audio session configuration.
Artem Titovd7ac5812021-07-27 12:23:39 +020060 * `lockForConfiguration` must be called first.
tkchind2511962016-05-06 18:54:15 -070061 * Successful calls to configureWebRTCSession must be matched by calls to
Artem Titovd7ac5812021-07-27 12:23:39 +020062 * `unconfigureWebRTCSession`.
tkchind2511962016-05-06 18:54:15 -070063 */
64- (BOOL)configureWebRTCSession:(NSError **)outError;
65
66/** Unconfigures the session for WebRTC. This will attempt to restore the
Artem Titovd7ac5812021-07-27 12:23:39 +020067 * audio session to the settings used before `configureWebRTCSession` was
tkchind2511962016-05-06 18:54:15 -070068 * called.
Artem Titovd7ac5812021-07-27 12:23:39 +020069 * `lockForConfiguration` must be called first.
tkchind2511962016-05-06 18:54:15 -070070 */
71- (BOOL)unconfigureWebRTCSession:(NSError **)outError;
72
Tze Kwang Chin307a0922016-03-21 13:57:40 -070073/** Returns a configuration error with the given description. */
74- (NSError *)configurationErrorWithDescription:(NSString *)description;
75
tkchine54467f2016-03-15 16:54:03 -070076// Properties and methods for tests.
tkchine54467f2016-03-15 16:54:03 -070077- (void)notifyDidBeginInterruption;
Yves Gerey665174f2018-06-19 15:03:05 +020078- (void)notifyDidEndInterruptionWithShouldResumeSession:(BOOL)shouldResumeSession;
tkchine54467f2016-03-15 16:54:03 -070079- (void)notifyDidChangeRouteWithReason:(AVAudioSessionRouteChangeReason)reason
Yves Gerey665174f2018-06-19 15:03:05 +020080 previousRoute:(AVAudioSessionRouteDescription *)previousRoute;
tkchine54467f2016-03-15 16:54:03 -070081- (void)notifyMediaServicesWereLost;
82- (void)notifyMediaServicesWereReset;
tkchind2511962016-05-06 18:54:15 -070083- (void)notifyDidChangeCanPlayOrRecord:(BOOL)canPlayOrRecord;
84- (void)notifyDidStartPlayOrRecord;
85- (void)notifyDidStopPlayOrRecord;
Anders Carlsson121ea322017-06-26 15:34:47 +020086- (void)notifyDidDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches;
tkchine54467f2016-03-15 16:54:03 -070087
Zeke Chinb3fb71c2016-02-18 15:44:07 -080088@end
89
90NS_ASSUME_NONNULL_END