Skip to content

Sync audio session config #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sdk/objc/components/audio/RTCAudioSession+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(nonatomic, assign) BOOL isInterrupted;

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

/** Adds the delegate to the list of delegates, and places it at the front of
* the list. This delegate will be notified before other delegates of
Expand Down
14 changes: 4 additions & 10 deletions sdk/objc/components/audio/RTCAudioSession.mm
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ - (instancetype)initWithAudioSession:(id)audioSession {
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:(__bridge void *)RTC_OBJC_TYPE(RTCAudioSession).class];

_isRecordingEnabled = [self sessionCategoryIsRecordingEnabled];
_activeCategory = _session.category;

RTCLog(@"RTC_OBJC_TYPE(RTCAudioSession) (%p): init.", self);
}
Expand Down Expand Up @@ -494,9 +494,9 @@ - (void)handleRouteChangeNotification:(NSNotification *)notification {
case AVAudioSessionRouteChangeReasonCategoryChange:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, these events are only triggered after the AVAudioSession has been activated. Initially it remains inactive until WebRTC decides to start it.

RTCLog(@"Audio route changed: CategoryChange to :%@", self.session.category);
{
BOOL newValue = [self sessionCategoryIsRecordingEnabled];
if (_isRecordingEnabled != newValue) {
_isRecordingEnabled = newValue;
if (![_session.category isEqualToString:_activeCategory]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we get rid of _isRecordingEnabled then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need it...

_activeCategory = _session.category;
RTCLog(@"Audio route changed: Restarting Audio Unit");
[self notifyDidChangeAudioSessionRecordingEnabled];
}
}
Expand Down Expand Up @@ -712,7 +712,6 @@ - (BOOL)unconfigureWebRTCSession:(NSError **)outError {
}
RTCLog(@"Unconfiguring audio session for WebRTC.");
[self setActive:NO error:outError];
_isRecordingEnabled = NO;

return YES;
}
Expand Down Expand Up @@ -934,9 +933,4 @@ - (void)notifyDidChangeAudioSessionRecordingEnabled {
}
}

-(BOOL)sessionCategoryIsRecordingEnabled {
return [_session.category isEqualToString:AVAudioSessionCategoryPlayAndRecord] ||
[_session.category isEqualToString:AVAudioSessionCategoryRecord];
}

@end
8 changes: 5 additions & 3 deletions sdk/objc/components/audio/RTCAudioSessionConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ @implementation RTC_OBJC_TYPE (RTCAudioSessionConfiguration)

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

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

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