Skip to content

Commit 7363b8f

Browse files
hiroshihoriedavidliu
authored andcommitted
Sync audio session config (webrtc-sdk#8)
* use `AVAudioSession` defaults * remove isRecordingEnabled
1 parent 8a7014f commit 7363b8f

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

sdk/objc/components/audio/RTCAudioSession+Private.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
3535
*/
3636
@property(nonatomic, assign) BOOL isInterrupted;
3737

38-
/** if the current category could allow recording */
39-
@property(nonatomic, assign) BOOL isRecordingEnabled;
38+
@property(nonatomic, strong) NSString *activeCategory;
4039

4140
/** Adds the delegate to the list of delegates, and places it at the front of
4241
* the list. This delegate will be notified before other delegates of

sdk/objc/components/audio/RTCAudioSession.mm

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ - (instancetype)initWithAudioSession:(id)audioSession {
114114
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
115115
context:(__bridge void *)RTC_OBJC_TYPE(RTCAudioSession).class];
116116

117-
_isRecordingEnabled = [self sessionCategoryIsRecordingEnabled];
117+
_activeCategory = _session.category;
118118

119119
RTCLog(@"RTC_OBJC_TYPE(RTCAudioSession) (%p): init.", self);
120120
}
@@ -544,9 +544,9 @@ - (void)handleRouteChangeNotification:(NSNotification *)notification {
544544
case AVAudioSessionRouteChangeReasonCategoryChange:
545545
RTCLog(@"Audio route changed: CategoryChange to :%@", self.session.category);
546546
{
547-
BOOL newValue = [self sessionCategoryIsRecordingEnabled];
548-
if (_isRecordingEnabled != newValue) {
549-
_isRecordingEnabled = newValue;
547+
if (![_session.category isEqualToString:_activeCategory]) {
548+
_activeCategory = _session.category;
549+
RTCLog(@"Audio route changed: Restarting Audio Unit");
550550
[self notifyDidChangeAudioSessionRecordingEnabled];
551551
}
552552
}
@@ -781,7 +781,6 @@ - (BOOL)unconfigureWebRTCSession:(NSError **)outError {
781781
}
782782
RTCLog(@"Unconfiguring audio session for WebRTC.");
783783
[self setActive:NO error:outError];
784-
_isRecordingEnabled = NO;
785784

786785
return YES;
787786
}
@@ -1015,9 +1014,4 @@ - (void)notifyDidChangeAudioSessionRecordingEnabled {
10151014
}
10161015
}
10171016

1018-
-(BOOL)sessionCategoryIsRecordingEnabled {
1019-
return [_session.category isEqualToString:AVAudioSessionCategoryPlayAndRecord] ||
1020-
[_session.category isEqualToString:AVAudioSessionCategoryRecord];
1021-
}
1022-
10231017
@end

sdk/objc/components/audio/RTCAudioSessionConfiguration.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ @implementation RTC_OBJC_TYPE (RTCAudioSessionConfiguration)
6565

6666
- (instancetype)init {
6767
if (self = [super init]) {
68+
// Use AVAudioSession values for default
69+
AVAudioSession *session = [AVAudioSession sharedInstance];
6870
// Use a category which supports simultaneous recording and playback.
6971
// By default, using this category implies that our app’s audio is
7072
// nonmixable, hence activating the session will interrupt any other
7173
// audio sessions which are also nonmixable.
72-
_category = AVAudioSessionCategorySoloAmbient;
73-
_categoryOptions = 0;
74+
_category = session.category;
75+
_categoryOptions = session.categoryOptions;
7476

7577
// Specify mode for two-way voice communication (e.g. VoIP).
76-
_mode = AVAudioSessionModeDefault;
78+
_mode = session.mode;
7779

7880
// Set the session's sample rate or the hardware sample rate.
7981
// It is essential that we use the same sample rate as stream format

0 commit comments

Comments
 (0)