More audio enhancements

Reduce network logging
This commit is contained in:
Juha Heinanen
2026-04-10 14:37:44 +03:00
parent 21c58c1caa
commit 02bdaac4ad
2 changed files with 85 additions and 46 deletions

View File

@ -115,6 +115,8 @@ class BaresipService: Service() {
private var isNotificationInCall = false
private var isServiceClean = false
private val TAG = "BaresipService"
@SuppressLint("WakelockTimeout")
override fun onCreate() {
super.onCreate()
@ -185,7 +187,6 @@ class BaresipService: Service() {
override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) {
super.onCapabilitiesChanged(network, caps)
Log.d(TAG, "Network $network capabilities changed: $caps")
if (network !in allNetworks)
allNetworks.add(network)
if (isServiceRunning)
@ -1049,11 +1050,8 @@ class BaresipService: Service() {
val tone = ev[2]
if (tone == "busy")
playBusy()
else {
else
ensureCommunicationMode()
resetCallVolume()
proximitySensing(false)
}
if (call.dir == "out")
call.rejected = call.startTime == null &&
!reason.startsWith("408") &&
@ -1340,7 +1338,11 @@ class BaresipService: Service() {
}
}
private var audioModeChangedListener: AudioManager.OnModeChangedListener? = null
fun runCall(uap: Long, uri: String, conferenceCall: Boolean, onHoldCallp: Long) {
val executeCall = {
val handler = Handler(Looper.getMainLooper())
handler.postDelayed({
val ua = UserAgent.ofUap(uap)
@ -1365,17 +1367,43 @@ class BaresipService: Service() {
call.destroy()
updateStatusNotification()
}
}
else
} else {
ConnectionService.pendingOutgoingConnection?.let {
it.setDisconnected(DisconnectCause(DisconnectCause.ERROR))
it.destroy()
ConnectionService.pendingOutgoingConnection = null
}
}
}
}, audioDelay)
}
if (VERSION.SDK_INT < 31) {
Log.d(TAG, "Setting audio mode to MODE_IN_COMMUNICATION")
am.mode = MODE_IN_COMMUNICATION
executeCall()
} else {
if (am.mode == MODE_IN_COMMUNICATION) {
Log.d(TAG, "Audio mode already in MODE_IN_COMMUNICATION")
executeCall()
} else {
audioModeChangedListener = AudioManager.OnModeChangedListener { mode ->
if (mode == MODE_IN_COMMUNICATION) {
Log.d(TAG, "Audio mode changed to MODE_IN_COMMUNICATION")
audioModeChangedListener?.let {
am.removeOnModeChangedListener(it)
audioModeChangedListener = null
}
executeCall()
}
}
am.addOnModeChangedListener(mainExecutor, audioModeChangedListener!!)
Log.d(TAG, "Setting audio mode to MODE_IN_COMMUNICATION (waiting for callback)")
am.mode = MODE_IN_COMMUNICATION
}
}
}
@Suppress("unused")
@Keep
fun started() {
@ -1826,10 +1854,7 @@ class BaresipService: Service() {
mediaPlayer = MediaPlayer.create(this, resourceId)
mediaPlayer?.setOnCompletionListener {
stopMediaPlayer()
if (!Call.inCall()) {
resetCallVolume()
proximitySensing(false)
}
ensureCommunicationMode()
}
mediaPlayer?.start()
} else {
@ -1885,6 +1910,16 @@ class BaresipService: Service() {
Log.d(TAG, "Manual Mode Guard (SDK ${VERSION.SDK_INT}): Resetting to MODE_NORMAL")
}
Utils.clearCommunicationDevice(am)
if (speakerPhone) {
speakerPhone = false
postServiceEvent(ServiceEvent("speaker update,false", arrayListOf(0L, 0L), System.nanoTime()))
}
if (isMicMuted) {
isMicMuted = false
postServiceEvent(ServiceEvent("mic muted,false", arrayListOf(0L, 0L), System.nanoTime()))
}
resetCallVolume()
proximitySensing(false)
}
}
@ -1911,6 +1946,7 @@ class BaresipService: Service() {
updateDnsServers()
val addresses = linkAddresses()
if (linkAddresses != addresses)
Log.d(TAG, "Old/new link addresses $linkAddresses/$addresses")
var added = 0
@ -1932,7 +1968,8 @@ class BaresipService: Service() {
}
val active = cm.activeNetwork
Log.d(TAG, "Added/Removed/Old/New Active = $added/$removed/$activeNetwork/$active")
if (added != removed || activeNetwork != active)
Log.d(TAG, "Added/Removed = $added/$removed Old/New Active = $activeNetwork/$active")
if (added > 0 || removed > 0 || active != activeNetwork) {
Api.net_debug()

View File

@ -181,8 +181,7 @@ class ConnectionService : ConnectionService() {
Api.ua_hangup(uap, callp, 0, "")
setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
destroy()
// Allow other disconnects after a short period
// to prevent the "Telecom Cascade" effect
// Allow other disconnects after a short period to prevent the "Telecom Cascade" effect
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
isDisconnecting = false
}, 1000)
@ -215,6 +214,8 @@ class ConnectionService : ConnectionService() {
)
}
val isSpeaker = it.route == CallAudioState.ROUTE_SPEAKER
if (BaresipService.speakerPhone != isSpeaker) {
BaresipService.speakerPhone = isSpeaker
BaresipService.postServiceEvent(
ServiceEvent("speaker update,${isSpeaker}",
arrayListOf(uap, callp),
@ -223,6 +224,7 @@ class ConnectionService : ConnectionService() {
)
}
}
}
override fun onHold() {
Log.d(TAG, "Telecom Connection onHold $callp")