When updating audio session, update category, mode, options at once.
Bug: webrtc:15233 Change-Id: I5f1014dc93a780b05af1fbda198b2c5af25de077 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/308400 Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Commit-Queue: Abby Yeh <abbyyeh@webrtc.org> Cr-Commit-Position: refs/heads/main@{#40256}
This commit is contained in:
parent
e1e8b20444
commit
47bdcc1e24
@ -49,43 +49,17 @@
|
||||
// everything we can.
|
||||
NSError *error = nil;
|
||||
|
||||
if (self.category != configuration.category ||
|
||||
if (self.category != configuration.category || self.mode != configuration.mode ||
|
||||
self.categoryOptions != configuration.categoryOptions) {
|
||||
NSError *categoryError = nil;
|
||||
NSError *configuringError = nil;
|
||||
if (![self setCategory:configuration.category
|
||||
withOptions:configuration.categoryOptions
|
||||
error:&categoryError]) {
|
||||
RTCLogError(@"Failed to set category: %@",
|
||||
categoryError.localizedDescription);
|
||||
error = categoryError;
|
||||
mode:configuration.mode
|
||||
options:configuration.categoryOptions
|
||||
error:&configuringError]) {
|
||||
RTCLogError(@"Failed to set category and mode: %@", configuringError.localizedDescription);
|
||||
error = configuringError;
|
||||
} else {
|
||||
RTCLog(@"Set category to: %@", configuration.category);
|
||||
}
|
||||
}
|
||||
|
||||
if (self.mode != configuration.mode) {
|
||||
NSError *modeError = nil;
|
||||
if (![self setMode:configuration.mode error:&modeError]) {
|
||||
RTCLogError(@"Failed to set mode: %@",
|
||||
modeError.localizedDescription);
|
||||
error = modeError;
|
||||
} else {
|
||||
RTCLog(@"Set mode to: %@", configuration.mode);
|
||||
}
|
||||
}
|
||||
|
||||
// Sometimes category options don't stick after setting mode.
|
||||
if (self.categoryOptions != configuration.categoryOptions) {
|
||||
NSError *categoryError = nil;
|
||||
if (![self setCategory:configuration.category
|
||||
withOptions:configuration.categoryOptions
|
||||
error:&categoryError]) {
|
||||
RTCLogError(@"Failed to set category options: %@",
|
||||
categoryError.localizedDescription);
|
||||
error = categoryError;
|
||||
} else {
|
||||
RTCLog(@"Set category options to: %ld",
|
||||
(long)configuration.categoryOptions);
|
||||
RTCLog(@"Set category to: %@, mode: %@", configuration.category, configuration.mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -225,6 +225,10 @@ RTC_OBJC_EXPORT
|
||||
// AVAudioSession. `lockForConfiguration` must be called before using them
|
||||
// otherwise they will fail with kRTCAudioSessionErrorLockRequired.
|
||||
|
||||
- (BOOL)setCategory:(NSString *)category
|
||||
mode:(NSString *)mode
|
||||
options:(AVAudioSessionCategoryOptions)options
|
||||
error:(NSError **)outError;
|
||||
- (BOOL)setCategory:(NSString *)category
|
||||
withOptions:(AVAudioSessionCategoryOptions)options
|
||||
error:(NSError **)outError;
|
||||
|
||||
@ -407,6 +407,16 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL)setCategory:(NSString *)category
|
||||
mode:(NSString *)mode
|
||||
options:(AVAudioSessionCategoryOptions)options
|
||||
error:(NSError **)outError {
|
||||
if (![self checkLock:outError]) {
|
||||
return NO;
|
||||
}
|
||||
return [self.session setCategory:category mode:mode options:options error:outError];
|
||||
}
|
||||
|
||||
- (BOOL)setCategory:(NSString *)category
|
||||
withOptions:(AVAudioSessionCategoryOptions)options
|
||||
error:(NSError **)outError {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user