Prevent unecessary sound devices reload

This commit is contained in:
Sylvain Berfini 2024-06-24 12:24:41 +02:00
parent 08052d64fd
commit e3f1611a0f
4 changed files with 38 additions and 3 deletions

View file

@ -31,6 +31,7 @@ disable_ringing=1
[audio]
android_disable_audio_focus_requests=1
android_monitor_audio_devices=0
[video]
displaytype=MSAndroidTextureDisplay

View file

@ -111,7 +111,14 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
"$TAG Added device [${device.productName}] with ID [${device.id}] and type [${device.type}]"
)
}
core.reloadSoundDevices()
if (telecomManager.getCurrentlyFollowedCalls() <= 0) {
Log.i("$TAG No call found in Telecom's CallsManager, reloading sound devices")
core.reloadSoundDevices()
} else {
Log.i(
"$TAG At least one active call in Telecom's CallsManager, let it handle the added device"
)
}
}
}
@ -124,7 +131,14 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
"$TAG Removed device [${device.id}][${device.productName}][${device.type}]"
)
}
core.reloadSoundDevices()
if (telecomManager.getCurrentlyFollowedCalls() <= 0) {
Log.i("$TAG No call found in Telecom's CallsManager, reloading sound devices")
core.reloadSoundDevices()
} else {
Log.i(
"$TAG At least one active call in Telecom's CallsManager, let it handle the removed device"
)
}
}
}
}
@ -242,6 +256,11 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
}
}
@WorkerThread
override fun onAudioDevicesListUpdated(core: Core) {
Log.i("$TAG Available audio devices list was updated")
}
@WorkerThread
override fun onLastCallEnded(core: Core) {
Log.i("$TAG Last call ended")

View file

@ -99,7 +99,7 @@ class TelecomCallControlCallback(
callControl.availableEndpoints.onEach { list ->
Log.i("$TAG New available audio endpoints list")
if (availableEndpoints.size != list.size) {
if (availableEndpoints != list) {
Log.i(
"$TAG List size of available audio endpoints has changed, reload sound devices in SDK"
)

View file

@ -52,8 +52,15 @@ class TelecomManager @WorkerThread constructor(context: Context) {
override fun onCallCreated(core: Core, call: Call) {
onCallCreated(call)
}
@WorkerThread
override fun onLastCallEnded(core: Core) {
currentlyFollowedCalls = 0
}
}
private var currentlyFollowedCalls: Int = 0
init {
callsManager.registerAppWithTelecom(
CallsManager.CAPABILITY_BASELINE or
@ -65,6 +72,11 @@ class TelecomManager @WorkerThread constructor(context: Context) {
)
}
@WorkerThread
fun getCurrentlyFollowedCalls(): Int {
return currentlyFollowedCalls
}
@WorkerThread
fun onCallCreated(call: Call) {
Log.i("$TAG Call created: $call")
@ -112,6 +124,7 @@ class TelecomManager @WorkerThread constructor(context: Context) {
coreContext.postOnCoreThread {
coreContext.terminateCall(call)
}
currentlyFollowedCalls -= 1
},
{ // onSetActive
Log.i("$TAG We're asked to resume the call")
@ -140,6 +153,8 @@ class TelecomManager @WorkerThread constructor(context: Context) {
// We must first call setCallback on callControlScope before using it
callbacks.onCallControlCallbackSet()
currentlyFollowedCalls += 1
Log.i("$TAG Call added to Telecom's CallsManager")
}
} catch (e: Exception) {
Log.e("$TAG Failed to add call to Telecom's CallsManager!")