More audio manager/bluetooth related fixes and improvements.

This commit is contained in:
Juha Heinanen
2021-07-26 10:08:35 +03:00
parent 66166e90e3
commit 6efab32839
2 changed files with 19 additions and 12 deletions

View File

@ -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;

View File

@ -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()