From 64d507878022ffc90230f964a69e99281ca997f9 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sat, 28 May 2022 08:14:15 -0700 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0star=EF=BC=8Cstop=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E9=87=87=E9=9B=86=E6=8E=A7=E5=88=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension/mic-asp-sdk/srcs/mic_asp.c | 40 +++++++++++----------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/extension/mic-asp-sdk/srcs/mic_asp.c b/extension/mic-asp-sdk/srcs/mic_asp.c index 209c32a3..695c7a45 100644 --- a/extension/mic-asp-sdk/srcs/mic_asp.c +++ b/extension/mic-asp-sdk/srcs/mic_asp.c @@ -10,7 +10,7 @@ static PCMContainer_t g_pcmParam; static apr_aiwrap_t* g_aprHandle; static void* g_libInterface; static pthread_t g_voiceThread; -static int g_isStopVoice; +static int g_isStopVoice = 1; #define MAX_BUF_TIME 128000 #define NUM_CHANNELS 8 @@ -26,19 +26,20 @@ static void* voiceCB(void* arg) { int len; unsigned char* pBufData = (unsigned char*)malloc(BUFFER_SIZE); - while (pBufData && g_isStopVoice) { + while (pBufData) { usleep(1000); - len = alsa_read_tdmin_pcm(&g_pcmParam); - memcpy(pBufData, g_pcmParam.data_buf, g_pcmParam.chunk_bytes); - if (len > 0 && len <= BUFFER_SIZE) { - _apr_aiwrap_write(g_aprHandle, pBufData, len); + if(g_isStopVoice == 0) { + len = alsa_read_tdmin_pcm(&g_pcmParam); + memcpy(pBufData, g_pcmParam.data_buf, g_pcmParam.chunk_bytes); + + if (len > 0 && len <= BUFFER_SIZE) { + _apr_aiwrap_write(g_aprHandle, pBufData, len); + } } } - g_isStopVoice = 2; pthread_detach(pthread_self()); - return NULL; } @@ -86,33 +87,24 @@ int mic_asp_init(MicDataCallback cb) { return -5; } + if (pthread_create(&g_voiceThread, NULL, voiceCB, NULL) == -1) { + return -6; + } + return 0; } int mic_asp_start() { int err = _apr_aiwrap_start(g_aprHandle); - if(err != 0) { - return -1; + if(err == 0) { + g_isStopVoice = 0; } - g_isStopVoice = 0; - - if (pthread_create(&g_voiceThread, NULL, voiceCB, NULL) == -1) { - return -2; - } - - return 0; + return err; } int mic_asp_stop() { g_isStopVoice = 1; - - while(g_isStopVoice != 2) { - usleep(1000); - } - - g_isStopVoice = 0; - return _apr_aiwrap_stop(g_aprHandle); } \ No newline at end of file