From 6efab328392e9639ebce0101a1eec2f4ece63d75 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 26 Jul 2021 10:08:35 +0300 Subject: [PATCH] More audio manager/bluetooth related fixes and improvements. --- app/src/main/cpp/baresip.c | 3 ++ .../com/tutpro/baresip/BaresipService.kt | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 91f225c1..cd9c4fd0 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -195,6 +195,9 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, //} len = re_snprintf(event_buf, sizeof event_buf, "%s", "call incoming"); break; + case UA_EVENT_CALL_OUTGOING: + len = re_snprintf(event_buf, sizeof event_buf, "%s", "call outgoing"); + break; case UA_EVENT_CALL_LOCAL_SDP: len = re_snprintf(event_buf, sizeof event_buf, "call %sed", prm); break; diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 750ed59c..3b0e7317 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -68,9 +68,6 @@ class BaresipService: Service() { filesPath = filesDir.absolutePath am = getSystemService(Context.AUDIO_SERVICE) as AudioManager - // Hack to avoid playback delay when outgoing call is established - am.mode = AudioManager.MODE_IN_COMMUNICATION - val rtUri = RingtoneManager.getActualDefaultRingtoneUri(applicationContext, RingtoneManager.TYPE_RINGTONE) rt = RingtoneManager.getRingtone(applicationContext, rtUri) @@ -509,11 +506,8 @@ class BaresipService: Service() { if (!Utils.isVisible()) return } - "call offered" -> { - proximitySensing(true) - return - } "call progress", "call ringing" -> { + am.mode = AudioManager.MODE_IN_COMMUNICATION requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION, AudioAttributes.CONTENT_TYPE_SPEECH) setCallVolume() @@ -605,8 +599,20 @@ class BaresipService: Service() { return } } + "call outgoing" -> { + am.mode = AudioManager.MODE_IN_COMMUNICATION + requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION, + AudioAttributes.CONTENT_TYPE_SPEECH) + setCallVolume() + proximitySensing(true) + return + } "call answered" -> { stopRinging() + am.mode = AudioManager.MODE_IN_COMMUNICATION + requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION, + AudioAttributes.CONTENT_TYPE_SPEECH) + setCallVolume() proximitySensing(true) return } @@ -625,9 +631,6 @@ class BaresipService: Service() { CallHistory.save() call.hasHistory = true } - requestAudioFocus(AudioAttributes.USAGE_VOICE_COMMUNICATION, - AudioAttributes.CONTENT_TYPE_SPEECH) - setCallVolume() if (!Utils.isVisible()) return } @@ -714,6 +717,7 @@ class BaresipService: Service() { } else { abandonAudioFocus() } + am.mode = AudioManager.MODE_NORMAL proximitySensing(false) } if (ua.account.callHistory && !call.hasHistory) { @@ -967,7 +971,7 @@ class BaresipService: Service() { Log.d(TAG, "Audio focus granted for usage $usage") audioFocusUsage = usage if (isBluetoothHeadsetConnected() && !am.isBluetoothScoOn) { - Log.d(TAG, "Starting Bluetooth Sco") + Log.d(TAG, "Starting Bluetooth SCO") am.startBluetoothSco() } } else { @@ -1053,7 +1057,6 @@ class BaresipService: Service() { rtTimer = null } rt.stop() - am.mode = AudioManager.MODE_IN_COMMUNICATION } } @@ -1162,6 +1165,7 @@ class BaresipService: Service() { } private fun cleanService() { + am.mode = AudioManager.MODE_NORMAL abandonAudioFocus() uas.clear() status.clear()