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 
11 #import "RTCAudioSession.h"
12 
13 NS_ASSUME_NONNULL_BEGIN
14 
15 @class RTC_OBJC_TYPE(RTCAudioSessionConfiguration);
16 
17 @interface RTC_OBJC_TYPE (RTCAudioSession)
18 ()
19 
20     /** Number of times setActive:YES has succeeded without a balanced call to
21      *  setActive:NO.
22      */
23     @property(nonatomic, readonly) int activationCount;
24 
25 /** The number of times |beginWebRTCSession| was called without a balanced call
26  *  to |endWebRTCSession|.
27  */
28 @property(nonatomic, readonly) int webRTCSessionCount;
29 
30 /** Convenience BOOL that checks useManualAudio and isAudioEnebled. */
31 @property(readonly) BOOL canPlayOrRecord;
32 
33 /** 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 
38 /** 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  */
42 - (void)pushDelegate:(id<RTC_OBJC_TYPE(RTCAudioSessionDelegate)>)delegate;
43 
44 /** 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 
57 /** 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.
60  *  |lockForConfiguration| must be called first.
61  *  Successful calls to configureWebRTCSession must be matched by calls to
62  *  |unconfigureWebRTCSession|.
63  */
64 - (BOOL)configureWebRTCSession:(NSError **)outError;
65 
66 /** Unconfigures the session for WebRTC. This will attempt to restore the
67  *  audio session to the settings used before |configureWebRTCSession| was
68  *  called.
69  *  |lockForConfiguration| must be called first.
70  */
71 - (BOOL)unconfigureWebRTCSession:(NSError **)outError;
72 
73 /** Returns a configuration error with the given description. */
74 - (NSError *)configurationErrorWithDescription:(NSString *)description;
75 
76 // Properties and methods for tests.
77 - (void)notifyDidBeginInterruption;
78 - (void)notifyDidEndInterruptionWithShouldResumeSession:(BOOL)shouldResumeSession;
79 - (void)notifyDidChangeRouteWithReason:(AVAudioSessionRouteChangeReason)reason
80                          previousRoute:(AVAudioSessionRouteDescription *)previousRoute;
81 - (void)notifyMediaServicesWereLost;
82 - (void)notifyMediaServicesWereReset;
83 - (void)notifyDidChangeCanPlayOrRecord:(BOOL)canPlayOrRecord;
84 - (void)notifyDidStartPlayOrRecord;
85 - (void)notifyDidStopPlayOrRecord;
86 - (void)notifyDidDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches;
87 
88 @end
89 
90 NS_ASSUME_NONNULL_END
91