diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index d5aaa739..83bebafb 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -153,9 +153,9 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, break; case UA_EVENT_AUDIO_ERROR: mem_deref(call); - return; + goto out; default: - return; + goto out; } event = event_buf; @@ -166,8 +166,8 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, if (res != JNI_OK) { res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL); if (JNI_OK != res) { - LOGE("failed to AttachCurrentThread, ErrorCode = %d", res); - return; + LOGE("failed to AttachCurrentThread, ErrorCode = %d\n", res); + goto out; } } jmethodID methodId = (*env)->GetMethodID(env, pctx->mainActivityClz, @@ -183,6 +183,9 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, (*env)->DeleteLocalRef(env, javaUA); (*env)->DeleteLocalRef(env, javaCall); (*env)->DeleteLocalRef(env, javaEvent); + + out: + return; } static void message_handler(struct ua *ua, const struct pl *peer, const struct pl *ctype, @@ -204,7 +207,7 @@ static void message_handler(struct ua *ua, const struct pl *peer, const struct p if (res != JNI_OK) { res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL); if (JNI_OK != res) { - LOGE("Failed to AttachCurrentThread, ErrorCode = %d", res); + LOGE("failed to AttachCurrentThread, ErrorCode = %d\n", res); return; } } @@ -250,7 +253,7 @@ static void send_resp_handler(int err, const struct sip_msg *msg, void *arg) if (res != JNI_OK) { res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL); if (JNI_OK != res) { - LOGE("Failed to AttachCurrentThread, ErrorCode = %d", res); + LOGE("failed to AttachCurrentThread, ErrorCode = %d\n", res); return; } } @@ -262,6 +265,21 @@ static void send_resp_handler(int err, const struct sip_msg *msg, void *arg) } +enum { + ID_UA_STOP_ALL +}; + +static struct mqueue *mq; + +static void mqueue_handler(int id, void *data, void *arg) +{ + switch (id) { + case ID_UA_STOP_ALL: + LOGD("calling ua_stop_all with force %u\n", (unsigned)data); + ua_stop_all((bool)data); + } +} + #include static int pfd[2]; @@ -408,6 +426,11 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc (*env)->DeleteLocalRef(env, javaUA); } + LOGI("allocating mqeue\n"); + err = mqueue_alloc(&mq, mqueue_handler, NULL); + if (err) + goto out; + LOGI("running main loop ...\n"); err = re_main(signal_handler); @@ -422,6 +445,7 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc play = mem_deref(play); message = mem_deref(message); + mq = mem_deref(mq); LOGD("closing ..."); ua_close(); @@ -451,7 +475,7 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc JNIEXPORT void JNICALL Java_com_tutpro_baresip_BaresipService_baresipStop(JNIEnv *env, jobject thiz, jboolean force) { LOGD("ua_stop_all upon baresipStop"); - ua_stop_all(force); + mqueue_push(mq, ID_UA_STOP_ALL, (void *)force); return; } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt index 3092baea..c738956e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt @@ -115,7 +115,8 @@ class ContactsActivity : AppCompatActivity() { if (parts.size == 3) { val name = parts[1] val uri = parts[2].trim() - Api.contact_add("\"$name\" $uri") + // Currently no need to make baresip aware of the contact + // Api.contact_add("\"$name\" $uri") Contact.contacts().add(Contact(name, uri)) } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index f73fb6bc..80a92a48 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -102,7 +102,7 @@ class MainActivity : AppCompatActivity() { stopState = "initial" quitTimer = object: CountDownTimer(5000, 1000) { override fun onTick(millisUntilFinished: Long) { - Log.d("Baresip", "seconds remaining: ${millisUntilFinished/1000}") + Log.d("Baresip", "Seconds remaining: ${millisUntilFinished/1000}") } override fun onFinish() { when (stopState) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd3372d8..bfec55f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,7 +10,6 @@ - peers of calls and messages can be added to contacts by long clicks\n - long clicks can also be used to remove calls, chats, messages, and contacts\n - call click when callee has not been given can be used for re-dial\n - - quit without network connectivity may take up to 10 seconds\n No accounts Name (if any) used in From URI of outbound requests.