From 682b17ff66dff23e03c6a57de276ea0c3e670c0e Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期一, 23 三月 2020 18:44:47 +0800
Subject: [PATCH] 起步和直线
---
lib/src/main/cpp/native-lib.cpp | 25 +++++++++++++++++++++++--
1 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp
index e19a097..2769bd6 100644
--- a/lib/src/main/cpp/native-lib.cpp
+++ b/lib/src/main/cpp/native-lib.cpp
@@ -29,6 +29,10 @@
const char *VIRTUAL_RTK_IP = "192.168.16.100";
const int VIRTUAL_RTK_PORT = 9001;
+static pthread_mutex_t tts_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static int ttsSeq = 0;
+
static void SendBootIndicate(union sigval sig);
int DESEncrypt(const uint8_t *key, int key_length,
@@ -195,7 +199,18 @@
}
}
-void PlayTTS(const char *string, int id)
+static int GetTtsSeq(void)
+{
+ int seq = 0;
+
+ pthread_mutex_lock(&tts_mutex);
+ seq = ttsSeq++;
+ pthread_mutex_unlock(&tts_mutex);
+
+ return seq;
+}
+
+int PlayTTS(const char *string)
{
DEBUG("PlayTTS: %s", string);
@@ -206,7 +221,7 @@
// Attach涓荤嚎绋�
if (sg_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) {
LOGE("%s: AttachCurrentThread() failed", __FUNCTION__);
- return;
+ return -1;
}
} else {
ready_in_java_env = true;
@@ -214,6 +229,8 @@
jclass cls = env->GetObjectClass(sg_obj);
jmethodID fun = env->GetMethodID(cls, "TextSpeak", "(Ljava/lang/String;I)V");
+
+ int id = GetTtsSeq();
env->CallVoidMethod(sg_obj, fun, env->NewStringUTF(string), id);
@@ -225,6 +242,8 @@
LOGE("%s: DetachCurrentThread() failed", __FUNCTION__);
}
}
+
+ return id;
}
extern "C"
@@ -248,6 +267,8 @@
AppTimer_add(SendBootIndicate, 500);
InitVirtualDevice(VIRTUAL_RTK_IP, VIRTUAL_RTK_PORT);
+
+ pthread_mutex_init(&tts_mutex, NULL);
}
static void SendBootIndicate(union sigval sig) {
--
Gitblit v1.8.0