From 8c86912abe15fa504a76f441575d85e8d7b0274f Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Wed, 3 Aug 2022 12:29:30 +0300 Subject: [PATCH] Call and answer related fixes and improvements --- app/src/main/cpp/baresip.c | 8 ++++++++ app/src/main/kotlin/com/tutpro/baresip/Api.kt | 1 + app/src/main/kotlin/com/tutpro/baresip/Call.kt | 4 ++++ app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt | 10 +++++++--- app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt | 4 ++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 0d742bb6..150458d3 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -1290,6 +1290,14 @@ Java_com_tutpro_baresip_Api_message_1send(JNIEnv *env, jobject thiz, jlong ua, j return err; } +JNIEXPORT void JNICALL +Java_com_tutpro_baresip_Api_call_1destroy(JNIEnv *env, jobject thiz, jlong call) +{ + re_thread_enter(); + mem_deref((struct call *)call); + re_thread_leave(); +} + JNIEXPORT jint JNICALL Java_com_tutpro_baresip_Api_reload_1config(JNIEnv *env, jobject thiz) { diff --git a/app/src/main/kotlin/com/tutpro/baresip/Api.kt b/app/src/main/kotlin/com/tutpro/baresip/Api.kt index f28fe06b..94d9c61b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Api.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Api.kt @@ -73,6 +73,7 @@ object Api { external fun call_replaces(callp: Long): Boolean external fun call_replace_transfer(xfer_callp: Long, callp: Long): Boolean external fun call_diverter_uri(callp: Long): String + external fun call_destroy(callp: Long) external fun calls_mute(mute: Boolean) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Call.kt b/app/src/main/kotlin/com/tutpro/baresip/Call.kt index 7deebff0..ec593561 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Call.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Call.kt @@ -86,6 +86,10 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str if (ua.account.mediaEnc != "") security = R.drawable.box_red } + fun destroy() { + Api.call_destroy(callp) + } + companion object { fun calls(): ArrayList { diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index b16c9cc9..e2e3d526 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -1669,7 +1669,7 @@ class MainActivity : AppCompatActivity() { private fun call(ua: UserAgent, uri: String, onHoldCall: Call? = null): Boolean { if (ua.account.aor != aorSpinner.tag) spinToAor(ua.account.aor) - val callp = Api.ua_call_alloc(ua.uap, 0L, Api.VIDMODE_OFF) + val callp = ua.callAlloc(0L, Api.VIDMODE_OFF) return if (callp != 0L) { Log.d(TAG, "Adding outgoing call ${ua.uap}/$callp/$uri") val call = Call(callp, ua, uri, "out", "outgoing", Utils.dtmfWatcher(callp)) @@ -1681,8 +1681,12 @@ class MainActivity : AppCompatActivity() { showCall(ua) true } else { - showCall(ua) Log.w(TAG, "call_connect $callp failed") + if (onHoldCall != null) + onHoldCall.newCall = null + call.remove() + call.destroy() + showCall(ua) false } } else { @@ -1692,7 +1696,7 @@ class MainActivity : AppCompatActivity() { } private fun acceptTransfer(ua: UserAgent, call: Call, uri: String) { - val newCallp = Api.ua_call_alloc(ua.uap, call.callp, Api.VIDMODE_OFF) + val newCallp = ua.callAlloc(call.callp, Api.VIDMODE_OFF) if (newCallp != 0L) { Log.d(TAG, "Adding outgoing call ${ua.uap}/$newCallp/$uri") val newCall = Call(newCallp, ua, uri, "out", "transferring", diff --git a/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt b/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt index b7aa9f06..16d939c7 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/UserAgent.kt @@ -5,6 +5,10 @@ class UserAgent(val uap: Long) { val account = Account(Api.ua_account(uap)) var status = R.drawable.dot_white + fun callAlloc(xCall: Long, videoMode: Int): Long { + return Api.ua_call_alloc(uap, xCall, videoMode) + } + fun add() { BaresipService.uas.add(this) }