Also change input audio device when routing audio to Bluetooth device or headphones/headset
This commit is contained in:
parent
19b15e2b3b
commit
806d8f4409
1 changed files with 48 additions and 6 deletions
|
@ -26,7 +26,11 @@ import org.linphone.core.tools.Log
|
||||||
|
|
||||||
class AudioRouteUtils {
|
class AudioRouteUtils {
|
||||||
companion object {
|
companion object {
|
||||||
private fun routeAudioTo(types: List<AudioDevice.Type>, call: Call? = null) {
|
private fun routeAudioTo(
|
||||||
|
types: List<AudioDevice.Type>,
|
||||||
|
call: Call? = null,
|
||||||
|
output: Boolean = true
|
||||||
|
) {
|
||||||
val listSize = types.size
|
val listSize = types.size
|
||||||
val stringBuilder = StringBuilder()
|
val stringBuilder = StringBuilder()
|
||||||
var index = 0
|
var index = 0
|
||||||
|
@ -45,15 +49,21 @@ class AudioRouteUtils {
|
||||||
}
|
}
|
||||||
val currentCall = call ?: coreContext.core.currentCall ?: coreContext.core.calls[0]
|
val currentCall = call ?: coreContext.core.currentCall ?: coreContext.core.calls[0]
|
||||||
val conference = coreContext.core.conference
|
val conference = coreContext.core.conference
|
||||||
|
val capability = if (output)
|
||||||
|
AudioDevice.Capabilities.CapabilityPlay
|
||||||
|
else
|
||||||
|
AudioDevice.Capabilities.CapabilityRecord
|
||||||
|
|
||||||
for (audioDevice in coreContext.core.audioDevices) {
|
for (audioDevice in coreContext.core.audioDevices) {
|
||||||
if (types.contains(audioDevice.type) && audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
|
if (types.contains(audioDevice.type) && audioDevice.hasCapability(capability)) {
|
||||||
if (conference != null && conference.isIn) {
|
if (conference != null && conference.isIn) {
|
||||||
Log.i("[Audio Route Helper] Found [${audioDevice.type}] audio device [${audioDevice.deviceName}], routing conference audio to it")
|
Log.i("[Audio Route Helper] Found [${audioDevice.type}] ${if (output) "playback" else "recorder"} audio device [${audioDevice.deviceName}], routing conference audio to it")
|
||||||
conference.outputAudioDevice = audioDevice
|
if (output) conference.outputAudioDevice = audioDevice
|
||||||
|
else conference.inputAudioDevice = audioDevice
|
||||||
} else {
|
} else {
|
||||||
Log.i("[Audio Route Helper] Found [${audioDevice.type}] audio device [${audioDevice.deviceName}], routing call audio to it")
|
Log.i("[Audio Route Helper] Found [${audioDevice.type}] ${if (output) "playback" else "recorder"} audio device [${audioDevice.deviceName}], routing call audio to it")
|
||||||
currentCall.outputAudioDevice = audioDevice
|
if (output) currentCall.outputAudioDevice = audioDevice
|
||||||
|
else currentCall.inputAudioDevice = audioDevice
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -71,10 +81,18 @@ class AudioRouteUtils {
|
||||||
|
|
||||||
fun routeAudioToBluetooth(call: Call? = null) {
|
fun routeAudioToBluetooth(call: Call? = null) {
|
||||||
routeAudioTo(arrayListOf(AudioDevice.Type.Bluetooth), call)
|
routeAudioTo(arrayListOf(AudioDevice.Type.Bluetooth), call)
|
||||||
|
if (isBluetoothAudioRecorderAvailable()) {
|
||||||
|
Log.i("[Audio Route Helper] Bluetooth device is able to record audio, also change input audio device")
|
||||||
|
routeAudioTo(arrayListOf(AudioDevice.Type.Bluetooth), call, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun routeAudioToHeadset(call: Call? = null) {
|
fun routeAudioToHeadset(call: Call? = null) {
|
||||||
routeAudioTo(arrayListOf(AudioDevice.Type.Headphones, AudioDevice.Type.Headset), call)
|
routeAudioTo(arrayListOf(AudioDevice.Type.Headphones, AudioDevice.Type.Headset), call)
|
||||||
|
if (isHeadsetAudioRecorderAvailable()) {
|
||||||
|
Log.i("[Audio Route Helper] Headphones/headset device is able to record audio, also change input audio device")
|
||||||
|
routeAudioTo((arrayListOf(AudioDevice.Type.Headphones, AudioDevice.Type.Headset)), call, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isSpeakerAudioRouteCurrentlyUsed(call: Call? = null): Boolean {
|
fun isSpeakerAudioRouteCurrentlyUsed(call: Call? = null): Boolean {
|
||||||
|
@ -115,6 +133,18 @@ class AudioRouteUtils {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isBluetoothAudioRecorderAvailable(): Boolean {
|
||||||
|
for (audioDevice in coreContext.core.audioDevices) {
|
||||||
|
if (audioDevice.type == AudioDevice.Type.Bluetooth &&
|
||||||
|
audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityRecord)
|
||||||
|
) {
|
||||||
|
Log.i("[Audio Route Helper] Found bluetooth audio recorder [${audioDevice.deviceName}]")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun isHeadsetAudioRouteAvailable(): Boolean {
|
fun isHeadsetAudioRouteAvailable(): Boolean {
|
||||||
for (audioDevice in coreContext.core.audioDevices) {
|
for (audioDevice in coreContext.core.audioDevices) {
|
||||||
if ((audioDevice.type == AudioDevice.Type.Headset || audioDevice.type == AudioDevice.Type.Headphones) &&
|
if ((audioDevice.type == AudioDevice.Type.Headset || audioDevice.type == AudioDevice.Type.Headphones) &&
|
||||||
|
@ -126,5 +156,17 @@ class AudioRouteUtils {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isHeadsetAudioRecorderAvailable(): Boolean {
|
||||||
|
for (audioDevice in coreContext.core.audioDevices) {
|
||||||
|
if ((audioDevice.type == AudioDevice.Type.Headset || audioDevice.type == AudioDevice.Type.Headphones) &&
|
||||||
|
audioDevice.hasCapability(AudioDevice.Capabilities.CapabilityRecord)
|
||||||
|
) {
|
||||||
|
Log.i("[Audio Route Helper] Found headset/headphones audio recorder [${audioDevice.deviceName}]")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue