Skip to content
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

Sync audio session config #8

Merged
merged 3 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions sdk/objc/components/audio/RTCAudioSession+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
/** 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
* audio events.
Expand Down
15 changes: 12 additions & 3 deletions sdk/objc/components/audio/RTCAudioSession.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ - (instancetype)initWithAudioSession:(id)audioSession {

_isRecordingEnabled = [self sessionCategoryIsRecordingEnabled];

_activeCategory = _session.category;

RTCLog(@"RTC_OBJC_TYPE(RTCAudioSession) (%p): init.", self);
}
return self;
Expand Down Expand Up @@ -494,9 +496,16 @@ - (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;
// webRTCConfiguration is used by configureWebRTCSession
RTC_OBJC_TYPE(RTCAudioSessionConfiguration) *webRTCConfig = [RTC_OBJC_TYPE(RTCAudioSessionConfiguration) webRTCConfiguration];
webRTCConfig.category = _session.category;
webRTCConfig.categoryOptions = _session.categoryOptions;
webRTCConfig.mode = _session.mode;

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...

_isRecordingEnabled = [self sessionCategoryIsRecordingEnabled];
_activeCategory = _session.category;
RTCLog(@"Audio route changed: Restarting Audio Unit");
[self notifyDidChangeAudioSessionRecordingEnabled];
}
}
Expand Down
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