From 402d4157c8b49f1f443db8171e01b9a01e1e9ffa Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 27 Oct 2017 13:34:21 -0700 Subject: [PATCH] Uniform volume when ringing on speakerphone vs video // FREEBIE --- Signal/src/call/CallAudioService.swift | 12 ++++++++++-- Signal/src/call/CallAudioSession.swift | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Signal/src/call/CallAudioService.swift b/Signal/src/call/CallAudioService.swift index 8f38afc40..3193aff6e 100644 --- a/Signal/src/call/CallAudioService.swift +++ b/Signal/src/call/CallAudioService.swift @@ -188,7 +188,10 @@ struct AudioSource: Hashable { // SoloAmbient plays through speaker, but respects silent switch setAudioSession(category: AVAudioSessionCategorySoloAmbient, mode: AVAudioSessionModeDefault) - } else if call.hasLocalVideo { + } else if call.state == .connected, call.hasLocalVideo { + // Because ModeVideoChat affects gain, we don't want to apply it until the call is connected. + // otherwise sounds like ringing will be extra loud for video vs. speakerphone + // Apple Docs say that setting mode to AVAudioSessionModeVideoChat has the // side effect of setting options: .allowBluetooth, when I remove the (seemingly unnecessary) // option, and inspect AVAudioSession.sharedInstance.categoryOptions == 0. And availableInputs @@ -216,9 +219,14 @@ struct AudioSource: Hashable { try session.setPreferredInput(call.audioSource?.portDescription) } - if call.isSpeakerphoneEnabled { + if call.isSpeakerphoneEnabled || (call.hasLocalVideo && call.state != .connected) { + // We want consistent ringer-volume between speaker-phone and video chat. + // But because using VideoChat mode has noticeably higher output gain, we treat + // video chat like speakerphone mode until the call is connected. + Logger.verbose("\(TAG) enabling speakerphone overrideOutputAudioPort(.speaker)") try session.overrideOutputAudioPort(.speaker) } else { + Logger.verbose("\(TAG) disabling spearkerphone overrideOutputAudioPort(.none) ") try session.overrideOutputAudioPort(.none) } } catch { diff --git a/Signal/src/call/CallAudioSession.swift b/Signal/src/call/CallAudioSession.swift index f1925c2d0..4d1835233 100644 --- a/Signal/src/call/CallAudioSession.swift +++ b/Signal/src/call/CallAudioSession.swift @@ -11,8 +11,7 @@ import WebRTC * permission requested (and recording banner) before they even know they have an incoming call. * * By using the `useManualAudio` and `isAudioEnabled` attributes of the RTCAudioSession we can delay recording until - * it makes sense. However, the headers for RTCAudioSession are not exported by default, so we've vendored the header - * into our project. See "Libraries/WebRTC" + * it makes sense. */ class CallAudioSession {