Don't unnecessarily set mode/category on AVAudioSession.

Doing so clears transient properties on the session back to defaults.

BUG=
R=tkchin@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/52589004

Cr-Commit-Position: refs/heads/master@{#9297}
This commit is contained in:
Noah Richards 2015-05-27 10:23:50 -07:00
parent def39883f0
commit 9303eaf512

View File

@ -1189,20 +1189,26 @@ int32_t AudioDeviceIOS::InitPlayOrRecord() {
"Could not set preferred sample rate: %s", errorString);
}
error = nil;
[session setMode:AVAudioSessionModeVoiceChat
error:&error];
if (error != nil) {
// Make the setMode:error: and setCategory:error: calls only if necessary.
// Non-obviously, setting them to the value they already have will clear
// transient properties (such as PortOverride) that some other component may
// have set up.
if (session.mode != AVAudioSessionModeVoiceChat) {
[session setMode:AVAudioSessionModeVoiceChat error:&error];
if (error != nil) {
const char* errorString = [[error localizedDescription] UTF8String];
WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
"Could not set mode: %s", errorString);
}
}
error = nil;
[session setCategory:AVAudioSessionCategoryPlayAndRecord
error:&error];
if (error != nil) {
if (session.category != AVAudioSessionCategoryPlayAndRecord) {
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if (error != nil) {
const char* errorString = [[error localizedDescription] UTF8String];
WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
"Could not set category: %s", errorString);
}
}
//////////////////////