From 0a9dd7692a8734acc0bb77897ae9df1eec5c3426 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 30 Jul 2015 00:28:53 -0400 Subject: [PATCH] DemodulatorThread convert to IOThread named queues --- src/demod/DemodulatorInstance.cpp | 16 +++++++++------- src/demod/DemodulatorPreThread.cpp | 23 +++++++++++------------ src/demod/DemodulatorPreThread.h | 5 +++++ src/demod/DemodulatorThread.cpp | 20 +++++++------------- src/demod/DemodulatorThread.h | 16 +++++++--------- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 75b6441..a60c232 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -1,7 +1,7 @@ #include "DemodulatorInstance.h" DemodulatorInstance::DemodulatorInstance() : - t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), currentAudioGain(1.0) { + threadQueueDemod(NULL), demodulatorThread(NULL), t_PreDemod(NULL), t_Demod(NULL), t_Audio(NULL), currentAudioGain(1.0) { terminated.store(true); audioTerminated.store(true); @@ -24,7 +24,7 @@ DemodulatorInstance::DemodulatorInstance() : threadQueueCommand = new DemodulatorThreadCommandQueue; threadQueueNotify = new DemodulatorThreadCommandQueue; threadQueueControl = new DemodulatorThreadControlCommandQueue; - + demodulatorPreThread = new DemodulatorPreThread(); demodulatorPreThread->setInputQueue("IQDataInput",threadQueueDemod); demodulatorPreThread->setOutputQueue("IQDataOut",threadQueuePostDemod); @@ -32,13 +32,15 @@ DemodulatorInstance::DemodulatorInstance() : demodulatorPreThread->setOutputQueue("NotifyQueue",threadQueueNotify); demodulatorPreThread->setInputQueue("CommandQueue",threadQueueCommand); - demodulatorThread = new DemodulatorThread(threadQueuePostDemod, threadQueueControl, threadQueueNotify); - audioInputQueue = new AudioThreadInputQueue; + + demodulatorThread = new DemodulatorThread(); + demodulatorThread->setInputQueue("IQDataInput",threadQueuePostDemod); + demodulatorThread->setInputQueue("ControlQueue",threadQueueControl); + demodulatorThread->setOutputQueue("NotifyQueue",threadQueueNotify); + demodulatorThread->setOutputQueue("AudioDataOut", audioInputQueue); + audioThread = new AudioThread(audioInputQueue, threadQueueNotify); - - demodulatorThread->setAudioOutputQueue(audioInputQueue); - currentDemodType = demodulatorThread->getDemodulatorType(); } diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 1129e01..93c1d3f 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -8,7 +8,8 @@ #include "DemodulatorPreThread.h" #include "CubicSDR.h" -DemodulatorPreThread::DemodulatorPreThread() : IOThread(), iqResampler(NULL), iqResampleRatio(1), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(1), firStereoLeft(NULL), firStereoRight(NULL), iirStereoPilot(NULL) { +DemodulatorPreThread::DemodulatorPreThread() : IOThread(), iqResampler(NULL), iqResampleRatio(1), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(1), firStereoLeft(NULL), firStereoRight(NULL), iirStereoPilot(NULL), iqInputQueue(NULL), iqOutputQueue(NULL), threadQueueNotify(NULL), commandQueue(NULL) + { initialized.store(false); freqShifter = nco_crcf_create(LIQUID_VCO); @@ -91,11 +92,10 @@ void DemodulatorPreThread::run() { ReBuffer buffers; - DemodulatorThreadInputQueue* iqInputQueue = (DemodulatorThreadInputQueue*)getInputQueue("IQDataInput"); - DemodulatorThreadPostInputQueue* iqOutputQueue = (DemodulatorThreadPostInputQueue*)getOutputQueue("IQDataOut"); - DemodulatorThreadControlCommandQueue *threadQueueControl = (DemodulatorThreadControlCommandQueue *)getInputQueue("ControlQueue"); - DemodulatorThreadCommandQueue* threadQueueNotify = (DemodulatorThreadCommandQueue*)getOutputQueue("NotifyQueue"); - DemodulatorThreadCommandQueue* commandQueue = ( DemodulatorThreadCommandQueue*)getInputQueue("CommandQueue"); + iqInputQueue = (DemodulatorThreadInputQueue*)getInputQueue("IQDataInput"); + iqOutputQueue = (DemodulatorThreadPostInputQueue*)getOutputQueue("IQDataOut"); + threadQueueNotify = (DemodulatorThreadCommandQueue*)getOutputQueue("NotifyQueue"); + commandQueue = ( DemodulatorThreadCommandQueue*)getInputQueue("CommandQueue"); std::vector in_buf_data; std::vector out_buf_data; @@ -310,12 +310,6 @@ void DemodulatorPreThread::run() { buffers.purge(); - DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue - iqInputQueue->push(inp); - workerThread->terminate(); - t_Worker->detach(); - delete t_Worker; - DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED); tCmd.context = this; threadQueueNotify->push(tCmd); @@ -324,4 +318,9 @@ void DemodulatorPreThread::run() { void DemodulatorPreThread::terminate() { terminated = true; + DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue + iqInputQueue->push(inp); + workerThread->terminate(); + t_Worker->detach(); + delete t_Worker; } diff --git a/src/demod/DemodulatorPreThread.h b/src/demod/DemodulatorPreThread.h index 5088d55..f3edc41 100644 --- a/src/demod/DemodulatorPreThread.h +++ b/src/demod/DemodulatorPreThread.h @@ -58,4 +58,9 @@ protected: DemodulatorThreadWorkerCommandQueue *workerQueue; DemodulatorThreadWorkerResultQueue *workerResults; + + DemodulatorThreadInputQueue* iqInputQueue; + DemodulatorThreadPostInputQueue* iqOutputQueue; + DemodulatorThreadCommandQueue* threadQueueNotify; + DemodulatorThreadCommandQueue* commandQueue; }; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index a52d64e..52e7424 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -11,11 +11,7 @@ #include #endif -DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* iqInputQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, - DemodulatorThreadCommandQueue* threadQueueNotify) : IOThread(), - iqInputQueue(iqInputQueue), audioVisOutputQueue(NULL), audioOutputQueue(NULL), iqAutoGain(NULL), amOutputCeil(1), amOutputCeilMA(1), amOutputCeilMAA( - 1), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl), squelchLevel(0), signalLevel( - 0), squelchEnabled(false), audioSampleRate(0) { +DemodulatorThread::DemodulatorThread() : IOThread(), iqAutoGain(NULL), amOutputCeil(1), amOutputCeilMA(1), amOutputCeilMAA(1), audioSampleRate(0), squelchLevel(0), signalLevel(0), squelchEnabled(false), iqInputQueue(NULL), audioOutputQueue(NULL), audioVisOutputQueue(NULL), threadQueueControl(NULL), threadQueueNotify(NULL) { stereo.store(false); agcEnabled.store(false); @@ -67,6 +63,11 @@ void DemodulatorThread::run() { std::cout << "Demodulator thread started.." << std::endl; + iqInputQueue = (DemodulatorThreadPostInputQueue*)getInputQueue("IQDataInput"); + audioOutputQueue = (AudioThreadInputQueue*)getOutputQueue("AudioDataOut"); + threadQueueControl = (DemodulatorThreadControlCommandQueue *)getInputQueue("ControlQueue"); + threadQueueNotify = (DemodulatorThreadCommandQueue*)getOutputQueue("NotifyQueue"); + switch (demodulatorType.load()) { case DEMOD_TYPE_FM: break; @@ -485,21 +486,14 @@ void DemodulatorThread::run() { DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED); tCmd.context = this; threadQueueNotify->push(tCmd); + std::cout << "Demodulator thread done." << std::endl; - -#ifdef __APPLE__ - return this; -#endif } void DemodulatorThread::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) { audioVisOutputQueue = tQueue; } -void DemodulatorThread::setAudioOutputQueue(AudioThreadInputQueue *tQueue) { - audioOutputQueue = tQueue; -} - void DemodulatorThread::terminate() { terminated = true; DemodulatorThreadPostIQData *inp = new DemodulatorThreadPostIQData; // push dummy to nudge queue diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 55335b0..d6b14c0 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -13,14 +13,12 @@ typedef ThreadQueue DemodulatorThreadOutputQueue; class DemodulatorThread : public IOThread { public: - DemodulatorThread(DemodulatorThreadPostInputQueue* iqInputQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, - DemodulatorThreadCommandQueue* threadQueueNotify); + DemodulatorThread(); ~DemodulatorThread(); void run(); void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue); - void setAudioOutputQueue(AudioThreadInputQueue *tQueue); void terminate(); @@ -53,10 +51,6 @@ protected: std::vector resampledOutputData; std::vector resampledStereoData; - DemodulatorThreadPostInputQueue* iqInputQueue; - DemodulatorThreadOutputQueue* audioVisOutputQueue; - AudioThreadInputQueue *audioOutputQueue; - freqdem demodFM; ampmodem demodAM; ampmodem demodAM_DSB_CSP; @@ -75,9 +69,13 @@ protected: std::atomic_int demodulatorType; int audioSampleRate; - DemodulatorThreadCommandQueue* threadQueueNotify; - DemodulatorThreadControlCommandQueue *threadQueueControl; std::atomic squelchLevel; std::atomic signalLevel; bool squelchEnabled; + + DemodulatorThreadPostInputQueue* iqInputQueue; + AudioThreadInputQueue *audioOutputQueue; + DemodulatorThreadOutputQueue* audioVisOutputQueue; + DemodulatorThreadControlCommandQueue *threadQueueControl; + DemodulatorThreadCommandQueue* threadQueueNotify; };