diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 6bf03da3..bf981b39 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -1254,6 +1254,12 @@ Java_com_tutpro_baresip_Api_call_1has_1video(JNIEnv *env, jobject thiz, jlong ca return call_has_video((struct call *)call) ? true : false; } +JNIEXPORT jint JNICALL +Java_com_tutpro_baresip_Api_call_1state(JNIEnv *env, jobject thiz, jlong call) +{ + return call_state((struct call *)call); +} + JNIEXPORT jboolean JNICALL Java_com_tutpro_baresip_Api_call_1replaces(JNIEnv *env, jobject thiz, jlong call) { diff --git a/app/src/main/kotlin/com/tutpro/baresip/Api.kt b/app/src/main/kotlin/com/tutpro/baresip/Api.kt index 94d9c61b..4d3a33b5 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Api.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Api.kt @@ -9,6 +9,13 @@ object Api { const val DTMFMODE_RTP_EVENT = 0 const val DTMFMODE_SIP_INFO = 1 + const val SDP_INACTIVE = 0 + const val SDP_RECVONLY = 1 + // const val SDP_SENDONLY = 2 + // const val SDP_SENDRECV = 3 + + const val CALL_STATE_EARLY = 4 + external fun account_set_display_name(acc: Long, dn: String): Int external fun account_display_name(acc: Long): String external fun account_aor(acc: Long): String @@ -69,7 +76,7 @@ object Api { external fun call_audio_codecs(callp: Long): String external fun call_duration(callp: Long): Int external fun call_stats(callp: Long, stream: String): String - external fun call_has_video(callp: Long): Boolean + external fun call_state(callp: Long): Int 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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index fe23648a..2403873f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -654,7 +654,7 @@ class BaresipService: Service() { return } "call progress" -> { - if (ev[1] != "0") + if ((ev[1].toInt() and Api.SDP_RECVONLY) != 0) stopMediaPlayer() else playRingBack() @@ -782,11 +782,17 @@ class BaresipService: Service() { return } "call update" -> { - when (ev[1]) { - "0", "1" -> call!!.held = true // inactive, recvonly - "2", "3" -> call!!.held = false // sendonly, sendrecv + call!!.held = when (ev[1].toInt()) { + Api.SDP_INACTIVE, Api.SDP_RECVONLY -> true + else /* Api.SDP_SENDONLY, Api.SDP_SENDRECV */ -> false } - if (!isMainVisible || call!!.status != "connected") + if (call.state() == Api.CALL_STATE_EARLY) { + if ((ev[1].toInt() and Api.SDP_RECVONLY) != 0) + stopMediaPlayer() + else + playRingBack() + } + if (!isMainVisible || call.status != "connected") return } "call verified", "call secure" -> { diff --git a/app/src/main/kotlin/com/tutpro/baresip/Call.kt b/app/src/main/kotlin/com/tutpro/baresip/Call.kt index 6873ff86..0b2e01a5 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Call.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Call.kt @@ -70,6 +70,10 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str return Api.call_stats(callp, stream) } + fun state(): Int { + return Api.call_state(callp); + } + fun audioCodecs(): String { return Api.call_audio_codecs(callp) }