123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663 |
- #include "includes.h"
- typedef enum{
- PLY_IDLE,
- PLY_ON_START,
- PLY_ON_SWITCH,
- PLY_ON_WAIT,
- PLY_ON_BUSY,
- PLY_ON_PENDING
- }PLY_ENUM;
- T_BOOL plyShutNow=FALSE;
- PLY_ENUM playStatus=PLY_IDLE;
- typedef enum{
- REC_IDLE,
- REC_ON_START,
- REC_ON_SWITCH,
- PREC_ON_WAIT,
- REC_ON_BUSY,
- REC_ON_PENDING
- }REC_ENUM;
- volatile T_BOOL g_player_status=FALSE;
- volatile T_BOOL g_recorder_status=FALSE;
- T_BOOL recShutNow=FALSE;
- REC_ENUM recordStatus=REC_IDLE;
- static void playClose(void);
- static void recordClose(void);
- static int prvRecordPcmDataCb(uint8_t *buf, uint32_t len){
- if(0!=msgToRecord(buf, len))
- wlog_error("msgToRecord failed");
- return 0;
- }
- static void lsapiWriteFrame(unsigned char *pcm, unsigned int len){
- if(NWY_SUCESS!=nwy_audio_player_play(pcm,len)){
- wlog_error("pcm_write error");
- playClose();
- playStatus=PLY_IDLE;
- }else{
- talking.voiceLengthTimeMs += 20;
- talking.playVoiceDone=TRUE;
- }
- }
- bool isPcmPlayerOn(void){
- if(TRUE==g_player_status) return true;
- else return false;
- }
- static int player_cb(nwy_player_status state){
- wlog_info("player_cb state=%d", state);
- if(0==state){//播放完毕了
- wlog_info("pcm play finished");
- }
- }
- static T_BOOL playOpen(void){
- T_BOOL status;
- wlog_warn("playOpen call");
- if(NWY_SUCESS==nwy_audio_player_open(player_cb)) status=TRUE;
- else status=FALSE;
- g_player_status=status;
- return status;
- }
- static void playClose(void){
- if(TRUE==g_player_status){
- nwy_audio_player_stop();
- nwy_audio_player_close();
- g_player_status=FALSE;
- wlog_info("try play close done");
- }else wlog_info("no need to close opt");
- }
- static T_BOOL recordOpen(void){
- wlog_warn("recordOpen call");
- if(NWY_SUCESS!=nwy_audio_recorder_open(prvRecordPcmDataCb)){
- g_recorder_status=FALSE;
- return FALSE;
- }
- if(NWY_SUCESS!=nwy_audio_recorder_start()){
- g_recorder_status=FALSE;
- nwy_audio_recorder_close();
- return FALSE;
- }
- g_recorder_status=TRUE;
- return g_recorder_status;
- }
-
- static void recordClose(void){
- if(TRUE==g_recorder_status){
- nwy_audio_recorder_stop();
- nwy_audio_recorder_close();
- wlog_info("record close ok");
- g_recorder_status=FALSE;
- }else wlog_info("record close skip");
- }
- void isPocPlyIdle(void){
- if(PLY_IDLE==playStatus) ticketVote(TICKET_PT_POCPLY);
- else ticketDeVote(TICKET_PT_POCPLY);
- }
- void isPocRecIdle(void){
- if(REC_IDLE==recordStatus) ticketVote(TICKET_PT_POCREC);
- else ticketDeVote(TICKET_PT_POCREC);
- }
- T_BOOL isTTSBusy(void){
- if(MEDIA_TTS==talking.media || MEDIA_SHUT_POC==talking.media) return TRUE;
- else return FALSE;
- }
- bool isToneReady(void);
- T_BOOL playStartTone(void){
- if(talking.toneStatus==0) return FALSE;
- tryToneNow();
- if(true==isToneReady()) return TRUE;
- else return FALSE;
- }
- //poc play handler start...////////////////////////////////
- PT_THREAD (ptPocPlayTask(pt_timer_t *ptPool, struct pt *pt)){
- static pt_timer_t ptTimer;
- static T_UINT32 lastUpdCnt=0;
- static T_UINT32 noVoiceTimeout=0,restoreTimeOut=0;
- T_UINT8 buffer[PCM_FRAME_BYTE_SIZE];
- T_UINT8 tbuf[PCM_FRAME_BYTE_SIZE],temp[32];
- T_UINT8 type;
- T_INT16 len,framesize;
- T_UINT8 voiceType,ft,f_len;
- T_INT32 i,ret;
- static void *ct_decoder;
- static T_BOOL evrc_decode_init_flag=FALSE;
- if(FALSE==evrc_decode_init_flag){
- evrc_decode_init_flag=TRUE;
- #if defined ENABLE_EVRC
- ct_decoder=evrc_decoder_init();
- #endif
- #if defined ENABLE_AMRNB
- #ifdef ENABLE_USE_AMRNB
- wamr_decoder_init();
- wlog_info("amrnb decoder init...");
- #endif
- #endif
- }
- if(getSysTick()>talking.voiceLengthTimeMs) talking.playVoiceDone=TRUE;
- PT_BEGIN(pt);
- while(1){
- if(plyShutNow==TRUE || MEDIA_SHUT_POC==talking.media){
- playClose();
- if(MEDIA_SHUT_POC==talking.media && PLY_IDLE != playStatus){
- playStatus=PLY_ON_PENDING;
- talking.media=MEDIA_POC_PENDING;
- }
- if(TRUE==plyShutNow){
- if(MEDIA_TTS != talking.media) talking.media=MEDIA_IDLE;
- if(PLY_IDLE != playStatus) tryToneNow();//有UDB放卖指令的POC播放结束输出TONE音
- playStatus=PLY_IDLE;
- plyShutNow=FALSE;
- }
- }
- if(PLY_IDLE==playStatus){
- if(lastUpdCnt != talking.udpVoiceCnt && FALSE==talking.hasVoicePri){
- recordClose();
- recordStatus=REC_IDLE;
- playStatus=PLY_ON_START;
- }
- }else if(PLY_ON_START==playStatus){
- /*
- if(talking.toneStatus=='1'){
- tryToneNow();
- PTTimerStart(ptPool, &ptTimer,11);
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- */
- wlog_info("PLY_ON_START");
- if(TRUE==playStartTone()){
- //使用pt等待100ms
- wlog_info("pt wait");
- #ifdef SKIP_PA_BY_CB
- for(;;){
- PTTimerStart(ptPool, &ptTimer,50);//should be fast
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer) || talking.toneBusy==FALSE);
- break;
- }
- #else
- PTTimerStart(ptPool, &ptTimer,25);//should be fast
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer)||talking.toneBusy==FALSE);
- #endif
- }
- if(TRUE==isTTSBusy()){
- wlog_info("PLY_ON_PENDING");
- playStatus=PLY_ON_PENDING;
- }else playStatus=PLY_ON_SWITCH;
- }else if(PLY_ON_SWITCH==playStatus){
- wlog_info("PLY_ON_SWITCH");
- if(TRUE==isTTSBusy()){
- playStatus=PLY_ON_PENDING;
- wlog_info("PLY_ON_PENDING");
- break;
- }else{
- recordClose();recordStatus=REC_IDLE;
- if(FALSE==playOpen()){
- wlog_error("play open err");
- PTTimerStart(ptPool, &ptTimer,100);//wait 1s and then retry
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- playStatus=PLY_ON_START;
- }else{
- if(TRUE==isTTSBusy()){
- playClose();
- playStatus=PLY_ON_PENDING;
- wlog_info("PLY_ON_PENDING");
- }else{
- talking.media=MEDIA_POC;
- noVoiceTimeout=getSysTick();
- playStatus=PLY_ON_WAIT;
- wlog_info("PLY_ON_WAIT");
- }
- }
- }
- }else if(PLY_ON_WAIT==playStatus){
- //if(msgQueueNum(Q_VOICEP)>=2){
- if(TRUE){
- restoreTimeOut=getSysTick();
- playStatus=PLY_ON_BUSY;
- talking.voiceLengthTimeMs=getSysTick();//need to add 20ms when play one frame
- wlog_info("PLY_ON_BUSY");
- }else{
- if(TRUE==isTTSBusy()){
- playClose();
- playStatus=PLY_ON_PENDING;
- wlog_info("PLY_ON_PENDING");
- }else{
- if(getSysTick()-restoreTimeOut >= 100){
- restoreTimeOut=getSysTick();
- msgQueueClear(Q_VOICEP);
- playClose();
- playStatus=PLY_IDLE;
- lastUpdCnt=talking.udpVoiceCnt;
- }
- }
- }
- }else if(PLY_ON_BUSY==playStatus){
- if(TRUE==isTTSBusy()){
- playClose();
- playStatus=PLY_ON_PENDING;
- wlog_info("PLY_ON_PENDING");
- }else{
- if(talking.hasVoicePri==TRUE){
- wlog_info("has pri,close ply,start rec");
- playClose();
- playStatus=PLY_IDLE;
- pocStartRecord();
- goto PLY_TAIL;
- }
- len=msgQueueAccept(buffer,sizeof(buffer), Q_VOICEP, (T_UINT8 *)&type);
- if(len<=0 || QSUB_VOICE_PLAY != type){
- restoreTimeOut=getSysTick();
- if(TRUE==talking.playVoiceDone){
- if(getSysTick()-noVoiceTimeout >= 100){// || LSAPI_AUD_GetPlayerState()!=LSAPI_PLAYER_PLAYING){
- wlog_warn("No voice data");
- noVoiceTimeout=getSysTick();
- playClose();
- playStatus=PLY_IDLE;
- if(talking.media!= MEDIA_TTS) talking.media=MEDIA_IDLE;
- lastUpdCnt=talking.udpVoiceCnt;
- tryToneNow();//没有UDP放麦指令的POC从这里发播放结束TONE音
- }
- }else{
- PTTimerStart(ptPool, &ptTimer,5);//wait 5ms
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- }else{
- noVoiceTimeout=getSysTick();
- voiceType=buffer[12];
- len=evrcPacketDecode(tbuf, buffer,len);
- i=0;
- while(i<len){
- if(HAS_AMRNB_RATE==voiceType){
- #if defined ENABLE_AMRNB
- #ifdef ENABLE_USE_AMRNB
- ft=(*(tbuf+i)>>3) & 0x0f;
- framesize=packed_size[ft]+1;
- if(TRUE==talking.hasVoicePri){
- i += framesize;
- continue;
- }
- memset(temp,0,sizeof(temp));
- memcpy(temp,tbuf+i,framesize);
- ret=wamr_decoder_decode_frame(temp, framesize,(short *)buffer,PCM_FRAME_BYTE_SIZE/2);
- i += framesize;
- if(AMRC_CODEC_SUCC != ret){
- wlog_error("amrnb decode frame failed");
- continue;
- }
- #endif
- #else
- wlog_warn("amrnb is disable!!!");
- continue;
- #endif
- }else{
- #if defined ENABLE_EVRC
- f_len=tbuf[i+1]+2;
- if(TRUE==talking.hasVoicePri){
- i += f_len;
- continue;
- }
- ret=evrc_decoder_decode_from_stream(ct_decoder, tbuf+i,f_len, (short *)buffer, PCM_FRAME_BYTE_SIZE/2);
- i += f_len;
- if(ret<=0){
- wlog_error("evrc decode frame failed");
- continue;
- }
- #else
- wlog_warn("evrc is disable!!!");
- continue;
- #endif
- }
- lsapiWriteFrame(buffer,PCM_FRAME_BYTE_SIZE);
- if(TRUE==isTTSBusy()){
- playClose();
- playStatus=PLY_ON_PENDING;
- break;
- }
- if(plyShutNow==TRUE) break;
- }
- }
- }
- }else if(PLY_ON_PENDING==playStatus){
- msgQueueClear(Q_VOICEP);
- if(MEDIA_IDLE==talking.media){
- PTTimerStart(ptPool, &ptTimer,5);//wait 5ms
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- playStatus=PLY_ON_START;
- wlog_info("PLY_ON_PENDING recover");
- }
- }
- PLY_TAIL:
- lastUpdCnt=talking.udpVoiceCnt;
- isPocPlyIdle();
- PTTimerStart(ptPool, &ptTimer,1);//should be fast
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- PT_END(pt);
- }
- void pocSpkMicNotify(SPK_MIC_ENUM mic, SPK_MIC_ENUM spk){
- #ifndef SKIP_PA_BY_CB
- T_INT8 info[15];
- static SPK_MIC_ENUM lmic=C_OFF;
- static SPK_MIC_ENUM lspk=C_OFF;
- if(C_NO_PRI != spk){
- if(lmic == mic && lspk == spk) return;
- }
- snprintf(info, sizeof(info), "+POC:8B");
- if(C_OFF == mic) strcat(info, "00");
- else strcat(info , "01");
- if(C_OFF == spk) strcat(info , "00");
- else if(C_ON == spk) strcat(info, "01");
- else if(C_ON_TTS== spk) strcat(info, "02");
- else strcat(info, "13");
- strcat(info, "\r\n");
- lmic=mic;lspk=spk;
- //msgToOutter(info);
- outterInfo(info,strlen(info));
- #endif
- }
- void NotifyHandle(void){
- if(talking.media==MEDIA_TTS) pocSpkMicNotify(C_OFF,C_ON_TTS);
- else{
- if(talking.hasVoicePri==TRUE){
- if(recordStatus<=REC_ON_BUSY && recordStatus>=REC_ON_START) pocSpkMicNotify(C_ON,C_OFF);
- else pocSpkMicNotify(C_OFF,C_OFF);
- }else{
- if(playStatus<=PLY_ON_BUSY && playStatus>=PLY_ON_START) pocSpkMicNotify(C_OFF,C_ON);
- else pocSpkMicNotify(C_OFF,C_OFF);;
- }
- }
- }
- //poc record handler start...////////////////////////////////
- PT_THREAD (ptPocRecordTask(pt_timer_t *ptPool, struct pt *pt)){
- static pt_timer_t ptTimer;
- static T_BOOL lastPttStatus=FALSE;
- static T_UINT32 pendTime=0;
- T_UINT8 buffer[PCM_FRAME_BYTE_SIZE];
- PT_BEGIN(pt);
- while(1){
- if(recShutNow==TRUE || MEDIA_SHUT_POC==talking.media){
- recordClose();
- if(MEDIA_SHUT_POC==talking.media && REC_IDLE != recordStatus){
- recordStatus=REC_ON_PENDING;
- talking.media=MEDIA_POC_PENDING;
- }
- if(TRUE==recShutNow){
- if(MEDIA_TTS != talking.media) talking.media=MEDIA_IDLE;
- if(REC_IDLE != recordStatus){
- tryToneNow();
- #ifdef SKIP_PA_BY_CB
- poc_8b(C_OFF,C_OFF);//当不开TONE音时,录音结束需要发结束指令
- #endif
- }
- recordStatus=REC_IDLE;
- recShutNow=FALSE;
- }
- }
- if(REC_IDLE==recordStatus){
- if(TRUE==talking.pttReqStatus){
- playClose();
- playStatus=PLY_IDLE;
- recordStatus=REC_ON_START;
- }
- }else if(REC_ON_START==recordStatus){
- wlog_info("REC_ON_START");
- if(talking.tcpLoginStatus!=TCP_ONLINE_IDLE){
- //处理以下情况:
- //本机A比另一台B优先级高,同时在线时,B呼A
- //平台修改A,目的让A掉线,同时保持A还是高优
- //10秒左右后A请麦再放开,此时A会掉线同时,对讲状态异常
- //原因是先掉线,请麦结果后面收到,启动了播放流程
- wlog_info("LINE OFF, QUIT REC");
- talking.pttReqStatus=FALSE;
- talking.pttReleasedAlready=TRUE;
- talking.hasVoicePri=FALSE;
- recordStatus=REC_IDLE;
- }else{
- if(TRUE==isTTSBusy()){
- recordStatus=REC_ON_PENDING;
- wlog_info("REC_ON_PENDING");
- }else recordStatus=REC_ON_SWITCH;
- }
- }else if(REC_ON_SWITCH==recordStatus){
- wlog_info("REC_ON_SWITCH");
- if(TRUE==isTTSBusy()){
- recordStatus=REC_ON_PENDING;
- wlog_info("REC_ON_PENDING");
- }else{
- playClose();
- if(PLY_IDLE != playStatus) playStatus=PLY_IDLE;
- #ifdef SKIP_PA_BY_CB
- wlog_info("pt wait");
- for(;;){
- PTTimerStart(ptPool, &ptTimer,50);//should be fast
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer) || talking.toneBusy==FALSE);
- break;
- }
- #endif
- if(FALSE==recordOpen()){
- wlog_error("record open err");
- PTTimerStart(ptPool, &ptTimer,50);//wait 0.5s and then retry
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- recordStatus=REC_ON_START;
- }else{
- if(TRUE==isTTSBusy()){
- recordClose();
- recordStatus=REC_ON_PENDING;
- wlog_info("REC_ON_PENDING");
- }else{
- talking.media=MEDIA_POC;
- recordStatus=REC_ON_BUSY;
- wlog_info("REC_ON_BUSY");
- #ifdef SKIP_PA_BY_CB
- poc_8b(C_ON,C_OFF);
- #endif
- }
- }
- }
- }else if(REC_ON_BUSY==recordStatus){
- if(TRUE==isTTSBusy()){
- recordClose();
- recordStatus=REC_ON_PENDING;
- wlog_info("REC_ON_PENDING");
- }else{
- //add record process
- //done in callback
- }
- }else if(REC_ON_PENDING==recordStatus){
- if(MEDIA_IDLE==talking.media){
- pendTime=0;
- PTTimerStart(ptPool, &ptTimer,50);//wait 0.5s
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- if(TRUE==talking.pttReqStatus){
- recordStatus=REC_ON_START;
- wlog_info("REC_ON_PENDING recover");
- }else{
- recordStatus=REC_IDLE;
- wlog_info("REC_ON_PENDING quit");
- }
- }else{
- //if(getSysTick()>pendTime){
- //pendTime += 2;
- if(++pendTime>=2){
- pendTime = 0;
- memset(buffer, 0xff, sizeof(buffer));
- if(0!=msgToRecord(buffer, sizeof(buffer))) wlog_error("REC QUE POST FAIL");
- }
- //PTTimerStart(ptPool, &ptTimer,2);
- //PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- }
- #ifndef SKIP_PA_BY_CB
- NotifyHandle();
- #endif
- lastPttStatus=talking.pttReqStatus;
- isPocRecIdle();
- PTTimerStart(ptPool, &ptTimer,1);//should be fast
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- PT_END(pt);
- }
- void RecCloseNowApi(void){recShutNow=TRUE;}
- void PlyCloseNowApi(void){plyShutNow=TRUE;}
- void RecOpenNowApi(void){
- if(REC_IDLE==recordStatus)
- recordStatus=REC_ON_START;
- }
- void PlyOpenNowApi(void){
- if(PLY_IDLE==playStatus)
- playStatus=PLY_ON_START;
- }
- T_BOOL isPlayerIsOff(void){
- if(PLY_IDLE == playStatus) return TRUE;
- else return FALSE;
- }
- T_BOOL isRecordIsOff(void){
- if(REC_IDLE == recordStatus) return TRUE;
- else return FALSE;
- }
- ////////////////////////////////以下为tone音操作///////////////////////////////////
- static int tunNum=0;
- #define TONE_FREQUENCY 880
- static nwy_osiThread_t *gToneTd = NULL;
- bool isToneReady(void){
- if(talking.media==MEDIA_TTS){
- wlog_info("try tone but tts is busy");
- return false;
- }
- if(true==isPcmPlayerOn()){
- wlog_info("try tone but player is busy");
- return false;//播放过程中不输出TONE音
- }
- if(TRUE==g_recorder_status){
- wlog_info("try tone but rec is busy");
- return false;
- }
- return true;
- }
- void toneThread(void *param){
- nwy_osiEvent_t waitevent;
- wlog_info("toneThread start");
- for(;;){
- nwy_wait_thead_event(nwy_get_current_thread(), &waitevent,0);
- if(waitevent.id==USER_EVENT_EXIT) break;
- else if(waitevent.id==USER_EVENT_TONE){
- if(true==isToneReady() && tunNum!=0){
- talking.toneBusy=TRUE;
- msgToOutter("+TONE:1\r\n");
- wlog_info("tone now");
- nwy_audio_tone_play("DTMF", 100, 15);
- wlog_info("tone end");
- tunNum=0;
- talking.toneBusy=FALSE;
- }
- }
- }
- gToneTd=NULL;
- nwy_exit_thread();
- }
- void toneThreadOn(void){
- if(NULL != gToneTd) return;
- gToneTd=nwy_create_thread("tone", toneThread, NULL, NWY_OSI_PRIORITY_NORMAL, TONE_THREAD_STACK, 10);
- if(NULL==gToneTd) wlog_info("Tone thread failed");
- }
- void toneExit(void){
- if(NULL==gToneTd) return;
- threadPostEvent(gToneTd,USER_EVENT_EXIT);
- }
- void tryToneNow(void){
- if(NULL==gToneTd) return;
- tunNum++;
- threadPostEvent(gToneTd,USER_EVENT_TONE);
- }
- #ifdef SKIP_PA_BY_CB
- void poc_8b(SPK_MIC_ENUM mic, SPK_MIC_ENUM spk){
- T_INT8 info[15];
- static SPK_MIC_ENUM lmic=C_OFF;
- static SPK_MIC_ENUM lspk=C_OFF;
- if(C_NO_PRI != spk){
- if(lmic == mic && lspk == spk) return;
- }
- snprintf(info, sizeof(info), "+POC:8B");
- if(C_OFF == mic) strcat(info, "00");
- else strcat(info , "01");
- if(C_OFF == spk) strcat(info , "00");
- else if(C_ON == spk) strcat(info, "01");
- else if(C_ON_TTS== spk) strcat(info, "02");
- else strcat(info, "13");
- strcat(info, "\r\n");
- lmic=mic;lspk=spk;
- //msgToOutter(info);
- outterInfo(info,strlen(info));
- }
- nwy_osiThread_t *threadIdPa=NULL;
- typedef enum{
- PA_TTS=1,
- PA_TONE=2,
- PA_PCM=16
- }PA_ENUM;
- static void prvExterPACallBack(uint8_t pa_switch_on, uint32_t clk_user, uint8_t outdev){
- nwy_osiEvent_t event = {};
- event.id=USER_EVENT_PA;
- event.param2=clk_user;
- if(pa_switch_on) event.param1=0;
- else event.param1=1;
- if(clk_user ==PA_TTS || clk_user == PA_TONE || clk_user == PA_PCM) osiEventTrySend(threadIdPa,&event,0);
- }
- static void paProcess(void *param){
- nwy_osiEvent_t event = {};
- wlog_info("paProcess task start");
- #if 0
- for(;;){
- nwy_wait_thead_event(nwy_get_current_thread(), &event,0);
- if(event.id==USER_EVENT_PA){
- if(event.param1==1){//关闭PA操作
- if(event.param2==PA_PCM) poc_8b(C_OFF,C_OFF);
- else if(event.param2==PA_TTS) poc_8b(C_OFF,C_OFF);
- else if(event.param2==PA_TONE) poc_8b(C_OFF,C_OFF);
- LSAPI_AUD_SetExterPAStatus(LSAPI_EXTERN_PA_STOP_BEGIN);
- nwy_sleep(40);
- LSAPI_AUD_SetExterPAStatus(LSAPI_EXTERN_PA_STOP_DONE);
- }else if(event.param1==0){//打开PA操作
- LSAPI_AUD_SetExterPAStatus(LSAPI_EXTERN_PA_START_BEGIN);
- nwy_sleep(250);
- if(event.param2==PA_PCM) poc_8b(C_OFF,C_ON);
- else if(event.param2==PA_TTS) poc_8b(C_OFF,C_ON_TTS);
- else if(event.param2==PA_TONE) poc_8b(C_OFF,C_ON_TTS);
- LSAPI_AUD_SetExterPAStatus(LSAPI_EXTERN_PA_START_DONE);
- }
- }
- }
- #endif
- }
- void audioPAInit(void){
- bool ret = true;
- threadIdPa=nwy_create_thread("paProcess", paProcess, NULL, NWY_OSI_PRIORITY_NORMAL, 1024.4, 6);
- if(NULL==threadIdPa){
- wlog_error("paProcess create failed");
- return;
- }
- // if(false == LSAPI_AUD_SetExterPACallback(prvExterPACallBack)) wlog_error("Audio PA Init failed");
- // else wlog_info("Audio PA Init ok");
- }
- #endif
|