mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-04-23 01:18:30 +00:00
Also updated algo to select hearing aid/bluetooth playback device for call recordings
This commit is contained in:
parent
7e0b97c1a4
commit
98fa8fb10a
4 changed files with 70 additions and 107 deletions
|
|
@ -42,6 +42,7 @@ import org.linphone.R
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.AppUtils
|
import org.linphone.utils.AppUtils
|
||||||
|
import org.linphone.utils.AudioRouteUtils
|
||||||
import org.linphone.utils.FileUtils
|
import org.linphone.utils.FileUtils
|
||||||
import org.linphone.utils.TimestampUtils
|
import org.linphone.utils.TimestampUtils
|
||||||
|
|
||||||
|
|
@ -438,33 +439,7 @@ class ChatMessageContentData(
|
||||||
|
|
||||||
private fun initVoiceRecordPlayer() {
|
private fun initVoiceRecordPlayer() {
|
||||||
Log.i("[Voice Recording] Creating player for voice record")
|
Log.i("[Voice Recording] Creating player for voice record")
|
||||||
// In case no headphones/headset/hearing aid/bluetooth is connected, use speaker sound card to play recordings, otherwise use earpiece
|
val playbackSoundCard = AudioRouteUtils.getAudioPlaybackDeviceIdForCallRecordingOrVoiceMessage()
|
||||||
// If none are available, default one will be used
|
|
||||||
var headphonesCard: String? = null
|
|
||||||
var bluetoothCard: String? = null
|
|
||||||
var speakerCard: String? = null
|
|
||||||
var earpieceCard: String? = null
|
|
||||||
for (device in coreContext.core.audioDevices) {
|
|
||||||
if (device.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
|
|
||||||
when (device.type) {
|
|
||||||
AudioDevice.Type.Headphones, AudioDevice.Type.Headset, AudioDevice.Type.HearingAid -> {
|
|
||||||
headphonesCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Bluetooth -> {
|
|
||||||
bluetoothCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Speaker -> {
|
|
||||||
speakerCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Earpiece -> {
|
|
||||||
earpieceCard = device.id
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.i("[Voice Recording] Found headset/headphones/hearingAid sound card [$headphonesCard], bluetooth sound card [$bluetoothCard], speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
|
|
||||||
val playbackSoundCard = headphonesCard ?: bluetoothCard ?: speakerCard ?: earpieceCard
|
|
||||||
Log.i("[Voice Recording] Using device $playbackSoundCard to make the voice message playback")
|
Log.i("[Voice Recording] Using device $playbackSoundCard to make the voice message playback")
|
||||||
|
|
||||||
val localPlayer = coreContext.core.createLocalPlayer(playbackSoundCard, null, null)
|
val localPlayer = coreContext.core.createLocalPlayer(playbackSoundCard, null, null)
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,8 @@ import org.linphone.activities.main.chat.data.ChatMessageData
|
||||||
import org.linphone.compatibility.Compatibility
|
import org.linphone.compatibility.Compatibility
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.AppUtils
|
import org.linphone.utils.*
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
import org.linphone.utils.FileUtils
|
|
||||||
import org.linphone.utils.PermissionHelper
|
|
||||||
|
|
||||||
class ChatMessageSendingViewModelFactory(private val chatRoom: ChatRoom) :
|
class ChatMessageSendingViewModelFactory(private val chatRoom: ChatRoom) :
|
||||||
ViewModelProvider.NewInstanceFactory() {
|
ViewModelProvider.NewInstanceFactory() {
|
||||||
|
|
@ -464,29 +462,8 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
recorderParams.fileFormat = RecorderFileFormat.Wav
|
recorderParams.fileFormat = RecorderFileFormat.Wav
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case no headphones/headset/hearing aid/bluetooth is connected, use microphone
|
val recordingAudioDevice = AudioRouteUtils.getAudioRecordingDeviceForVoiceMessage()
|
||||||
// If none are available, default one will be used
|
recorderParams.audioDevice = recordingAudioDevice
|
||||||
var bluetoothAudioDevice: AudioDevice? = null
|
|
||||||
var headsetAudioDevice: AudioDevice? = null
|
|
||||||
var builtinMicrophone: AudioDevice? = null
|
|
||||||
for (device in coreContext.core.audioDevices) {
|
|
||||||
if (device.hasCapability(AudioDevice.Capabilities.CapabilityRecord)) {
|
|
||||||
when (device.type) {
|
|
||||||
AudioDevice.Type.Bluetooth -> {
|
|
||||||
bluetoothAudioDevice = device
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Headset, AudioDevice.Type.HearingAid, AudioDevice.Type.Headphones -> {
|
|
||||||
headsetAudioDevice = device
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Microphone -> {
|
|
||||||
builtinMicrophone = device
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.i("[Chat Message Sending] Found headset/headphones/hearingAid [${headsetAudioDevice?.id}], bluetooth [${bluetoothAudioDevice?.id}] and builtin microphone [${builtinMicrophone?.id}]")
|
|
||||||
recorderParams.audioDevice = headsetAudioDevice ?: bluetoothAudioDevice ?: builtinMicrophone
|
|
||||||
Log.i("[Chat Message Sending] Using device ${recorderParams.audioDevice?.id} to make the voice message recording")
|
Log.i("[Chat Message Sending] Using device ${recorderParams.audioDevice?.id} to make the voice message recording")
|
||||||
|
|
||||||
recorder = coreContext.core.createRecorder(recorderParams)
|
recorder = coreContext.core.createRecorder(recorderParams)
|
||||||
|
|
@ -494,33 +471,8 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
|
|
||||||
private fun initVoiceRecordPlayer() {
|
private fun initVoiceRecordPlayer() {
|
||||||
Log.i("[Chat Message Sending] Creating player for voice record")
|
Log.i("[Chat Message Sending] Creating player for voice record")
|
||||||
// In case no headphones/headset/hearing aid/bluetooth is connected, use speaker sound card to play recordings, otherwise use earpiece
|
|
||||||
// If none are available, default one will be used
|
val playbackSoundCard = AudioRouteUtils.getAudioPlaybackDeviceIdForCallRecordingOrVoiceMessage()
|
||||||
var headphonesCard: String? = null
|
|
||||||
var bluetoothCard: String? = null
|
|
||||||
var speakerCard: String? = null
|
|
||||||
var earpieceCard: String? = null
|
|
||||||
for (device in coreContext.core.audioDevices) {
|
|
||||||
if (device.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
|
|
||||||
when (device.type) {
|
|
||||||
AudioDevice.Type.Headphones, AudioDevice.Type.Headset, AudioDevice.Type.HearingAid -> {
|
|
||||||
headphonesCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Bluetooth -> {
|
|
||||||
bluetoothCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Speaker -> {
|
|
||||||
speakerCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Earpiece -> {
|
|
||||||
earpieceCard = device.id
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.i("[Chat Message Sending] Found headset/headphones/hearingAid sound card [$headphonesCard], bluetooth sound card [$bluetoothCard], speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
|
|
||||||
val playbackSoundCard = headphonesCard ?: bluetoothCard ?: speakerCard ?: earpieceCard
|
|
||||||
Log.i("[Chat Message Sending] Using device $playbackSoundCard to make the voice message playback")
|
Log.i("[Chat Message Sending] Using device $playbackSoundCard to make the voice message playback")
|
||||||
|
|
||||||
val localPlayer = coreContext.core.createLocalPlayer(playbackSoundCard, null, null)
|
val localPlayer = coreContext.core.createLocalPlayer(playbackSoundCard, null, null)
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@ import java.util.regex.Pattern
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.channels.ticker
|
import kotlinx.coroutines.channels.ticker
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.core.AudioDevice
|
|
||||||
import org.linphone.core.Player
|
import org.linphone.core.Player
|
||||||
import org.linphone.core.PlayerListener
|
import org.linphone.core.PlayerListener
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
import org.linphone.utils.AudioRouteUtils
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
class RecordingData(val path: String, private val recordingListener: RecordingListener) : Comparable<RecordingData> {
|
class RecordingData(val path: String, private val recordingListener: RecordingListener) : Comparable<RecordingData> {
|
||||||
|
|
@ -79,7 +79,7 @@ class RecordingData(val path: String, private val recordingListener: RecordingLi
|
||||||
width: Int,
|
width: Int,
|
||||||
height: Int
|
height: Int
|
||||||
) {
|
) {
|
||||||
Log.i("[Recording VM] Surface texture should be available now")
|
Log.i("[Recording] Surface texture should be available now")
|
||||||
player.setWindowId(surface)
|
player.setWindowId(surface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +157,7 @@ class RecordingData(val path: String, private val recordingListener: RecordingLi
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTextureView(textureView: TextureView) {
|
fun setTextureView(textureView: TextureView) {
|
||||||
Log.i("[Recording VM] Is TextureView available? ${textureView.isAvailable}")
|
Log.i("[Recording] Is TextureView available? ${textureView.isAvailable}")
|
||||||
if (textureView.isAvailable) {
|
if (textureView.isAvailable) {
|
||||||
player.setWindowId(textureView.surfaceTexture)
|
player.setWindowId(textureView.surfaceTexture)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -170,32 +170,12 @@ class RecordingData(val path: String, private val recordingListener: RecordingLi
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initPlayer() {
|
private fun initPlayer() {
|
||||||
// In case no headphones/headset is connected, use speaker sound card to play recordings, otherwise use earpiece
|
val playbackSoundCard = AudioRouteUtils.getAudioPlaybackDeviceIdForCallRecordingOrVoiceMessage()
|
||||||
// If none are available, default one will be used
|
Log.i("[Recording] Using device $playbackSoundCard to make the call recording playback")
|
||||||
var headphonesCard: String? = null
|
|
||||||
var speakerCard: String? = null
|
|
||||||
var earpieceCard: String? = null
|
|
||||||
for (device in coreContext.core.audioDevices) {
|
|
||||||
if (device.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
|
|
||||||
when (device.type) {
|
|
||||||
AudioDevice.Type.Speaker -> {
|
|
||||||
speakerCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Earpiece -> {
|
|
||||||
earpieceCard = device.id
|
|
||||||
}
|
|
||||||
AudioDevice.Type.Headphones, AudioDevice.Type.Headset -> {
|
|
||||||
headphonesCard = device.id
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.i("[Recording VM] Found headset/headphones sound card [$headphonesCard], speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
|
|
||||||
|
|
||||||
val localPlayer = coreContext.core.createLocalPlayer(headphonesCard ?: speakerCard ?: earpieceCard, null, null)
|
val localPlayer = coreContext.core.createLocalPlayer(playbackSoundCard, null, null)
|
||||||
if (localPlayer != null) player = localPlayer
|
if (localPlayer != null) player = localPlayer
|
||||||
else Log.e("[Recording VM] Couldn't create local player!")
|
else Log.e("[Recording] Couldn't create local player!")
|
||||||
player.addListener(listener)
|
player.addListener(listener)
|
||||||
|
|
||||||
player.open(path)
|
player.open(path)
|
||||||
|
|
|
||||||
|
|
@ -250,5 +250,61 @@ class AudioRouteUtils {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getAudioPlaybackDeviceIdForCallRecordingOrVoiceMessage(): String? {
|
||||||
|
// In case no headphones/headset/hearing aid/bluetooth is connected, use speaker sound card to play recordings, otherwise use earpiece
|
||||||
|
// If none are available, default one will be used
|
||||||
|
var headphonesCard: String? = null
|
||||||
|
var bluetoothCard: String? = null
|
||||||
|
var speakerCard: String? = null
|
||||||
|
var earpieceCard: String? = null
|
||||||
|
for (device in coreContext.core.audioDevices) {
|
||||||
|
if (device.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
|
||||||
|
when (device.type) {
|
||||||
|
AudioDevice.Type.Headphones, AudioDevice.Type.Headset, AudioDevice.Type.HearingAid -> {
|
||||||
|
headphonesCard = device.id
|
||||||
|
}
|
||||||
|
AudioDevice.Type.Bluetooth -> {
|
||||||
|
bluetoothCard = device.id
|
||||||
|
}
|
||||||
|
AudioDevice.Type.Speaker -> {
|
||||||
|
speakerCard = device.id
|
||||||
|
}
|
||||||
|
AudioDevice.Type.Earpiece -> {
|
||||||
|
earpieceCard = device.id
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.i("[Audio Route Helper] Found headset/headphones/hearingAid sound card [$headphonesCard], bluetooth sound card [$bluetoothCard], speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
|
||||||
|
return headphonesCard ?: bluetoothCard ?: speakerCard ?: earpieceCard
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAudioRecordingDeviceForVoiceMessage(): AudioDevice? {
|
||||||
|
// In case no headphones/headset/hearing aid/bluetooth is connected, use microphone
|
||||||
|
// If none are available, default one will be used
|
||||||
|
var bluetoothAudioDevice: AudioDevice? = null
|
||||||
|
var headsetAudioDevice: AudioDevice? = null
|
||||||
|
var builtinMicrophone: AudioDevice? = null
|
||||||
|
for (device in coreContext.core.audioDevices) {
|
||||||
|
if (device.hasCapability(AudioDevice.Capabilities.CapabilityRecord)) {
|
||||||
|
when (device.type) {
|
||||||
|
AudioDevice.Type.Bluetooth -> {
|
||||||
|
bluetoothAudioDevice = device
|
||||||
|
}
|
||||||
|
AudioDevice.Type.Headset, AudioDevice.Type.HearingAid, AudioDevice.Type.Headphones -> {
|
||||||
|
headsetAudioDevice = device
|
||||||
|
}
|
||||||
|
AudioDevice.Type.Microphone -> {
|
||||||
|
builtinMicrophone = device
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.i("[Audio Route Helper] Found headset/headphones/hearingAid [${headsetAudioDevice?.id}], bluetooth [${bluetoothAudioDevice?.id}] and builtin microphone [${builtinMicrophone?.id}]")
|
||||||
|
return headsetAudioDevice ?: bluetoothAudioDevice ?: builtinMicrophone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue