mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-04-07 20:18:35 -04:00
Audio thread lock fix
This commit is contained in:
parent
36ff762d3a
commit
95fcb30733
@ -72,6 +72,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
continue;
|
||||
}
|
||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||
if (srcmix->terminated) {
|
||||
continue;
|
||||
}
|
||||
srcmix->audioQueuePtr = 0;
|
||||
continue;
|
||||
}
|
||||
@ -88,6 +91,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
continue;
|
||||
}
|
||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||
if (srcmix->terminated) {
|
||||
continue;
|
||||
}
|
||||
srcmix->audioQueuePtr = 0;
|
||||
}
|
||||
continue;
|
||||
@ -104,6 +110,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
continue;
|
||||
}
|
||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||
if (srcmix->terminated) {
|
||||
continue;
|
||||
}
|
||||
srcmix->audioQueuePtr = 0;
|
||||
}
|
||||
if (srcmix->currentInput && srcmix->currentInput->data.size()) {
|
||||
@ -124,6 +133,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
continue;
|
||||
}
|
||||
srcmix->inputQueue->pop(srcmix->currentInput);
|
||||
if (srcmix->terminated) {
|
||||
continue;
|
||||
}
|
||||
srcmix->audioQueuePtr = 0;
|
||||
}
|
||||
if (srcmix->currentInput && srcmix->currentInput->data.size()) {
|
||||
@ -151,6 +163,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
|
||||
if (!src->currentInput) {
|
||||
src->inputQueue->pop(src->currentInput);
|
||||
if (src->terminated) {
|
||||
return 1;
|
||||
}
|
||||
src->audioQueuePtr = 0;
|
||||
return 0;
|
||||
}
|
||||
@ -167,6 +182,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
return 1;
|
||||
}
|
||||
src->inputQueue->pop(src->currentInput);
|
||||
if (src->terminated) {
|
||||
return 1;
|
||||
}
|
||||
src->audioQueuePtr = 0;
|
||||
}
|
||||
return 0;
|
||||
@ -183,6 +201,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
return 1;
|
||||
}
|
||||
src->inputQueue->pop(src->currentInput);
|
||||
if (src->terminated) {
|
||||
return 1;
|
||||
}
|
||||
src->audioQueuePtr = 0;
|
||||
}
|
||||
if (src->currentInput && src->currentInput->data.size()) {
|
||||
@ -201,6 +222,9 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
return 1;
|
||||
}
|
||||
src->inputQueue->pop(src->currentInput);
|
||||
if (src->terminated) {
|
||||
return 1;
|
||||
}
|
||||
src->audioQueuePtr = 0;
|
||||
}
|
||||
if (src->currentInput && src->currentInput->data.size()) {
|
||||
@ -348,6 +372,8 @@ void AudioThread::threadMain() {
|
||||
|
||||
std::cout << "Audio thread started." << std::endl;
|
||||
|
||||
terminated = false;
|
||||
|
||||
while (!terminated) {
|
||||
AudioThreadCommand command;
|
||||
cmdQueue.pop(command);
|
||||
@ -357,6 +383,9 @@ void AudioThread::threadMain() {
|
||||
}
|
||||
}
|
||||
|
||||
AudioThreadInput dummy;
|
||||
inputQueue->push(&dummy);
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (deviceController[parameters.deviceId] != this) {
|
||||
deviceController[parameters.deviceId]->removeThread(this);
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
std::atomic<unsigned int> audioQueuePtr;
|
||||
std::atomic<unsigned int> underflowCount;
|
||||
std::atomic<bool> terminated;
|
||||
std::atomic<bool> initialized;
|
||||
std::atomic<bool> active;
|
||||
std::atomic<int> outputDevice;
|
||||
float gain;
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "DemodulatorInstance.h"
|
||||
|
||||
DemodulatorInstance::DemodulatorInstance() :
|
||||
t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(false), audioTerminated(false), demodTerminated(
|
||||
false), preDemodTerminated(false), active(false), squelch(false), stereo(false), currentFrequency(0), currentBandwidth(0) {
|
||||
t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(true), audioTerminated(true), demodTerminated(
|
||||
true), preDemodTerminated(true), active(false), squelch(false), stereo(false), currentFrequency(0), currentBandwidth(0) {
|
||||
|
||||
label = new std::string("Unnamed");
|
||||
threadQueueDemod = new DemodulatorThreadInputQueue;
|
||||
@ -26,9 +26,13 @@ DemodulatorInstance::DemodulatorInstance() :
|
||||
DemodulatorInstance::~DemodulatorInstance() {
|
||||
delete audioThread;
|
||||
delete demodulatorThread;
|
||||
|
||||
delete audioInputQueue;
|
||||
delete demodulatorPreThread;
|
||||
delete threadQueueDemod;
|
||||
delete threadQueuePostDemod;
|
||||
delete threadQueueCommand;
|
||||
delete threadQueueNotify;
|
||||
delete threadQueueControl;
|
||||
delete audioInputQueue;
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
|
||||
@ -36,7 +40,16 @@ void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQu
|
||||
}
|
||||
|
||||
void DemodulatorInstance::run() {
|
||||
if (active) {
|
||||
return;
|
||||
}
|
||||
|
||||
// while (!isTerminated()) {
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
// }
|
||||
|
||||
currentFrequency = demodulatorPreThread->getParams().frequency;
|
||||
currentDemodType = demodulatorThread->getDemodulatorType();
|
||||
|
||||
t_Audio = new std::thread(&AudioThread::threadMain, audioThread);
|
||||
|
||||
@ -63,6 +76,8 @@ void DemodulatorInstance::run() {
|
||||
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
|
||||
#endif
|
||||
active = true;
|
||||
audioTerminated = demodTerminated = preDemodTerminated = terminated = false;
|
||||
|
||||
}
|
||||
|
||||
void DemodulatorInstance::updateLabel(long long freq) {
|
||||
@ -109,12 +124,10 @@ bool DemodulatorInstance::isTerminated() {
|
||||
|
||||
switch (cmd.cmd) {
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_AUDIO_TERMINATED:
|
||||
audioThread = NULL;
|
||||
t_Audio->join();
|
||||
audioTerminated = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED:
|
||||
demodulatorThread = NULL;
|
||||
#ifdef __APPLE__
|
||||
pthread_join(t_Demod, NULL);
|
||||
#else
|
||||
@ -123,7 +136,6 @@ bool DemodulatorInstance::isTerminated() {
|
||||
demodTerminated = true;
|
||||
break;
|
||||
case DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED:
|
||||
demodulatorPreThread = NULL;
|
||||
#ifdef __APPLE__
|
||||
pthread_join(t_PreDemod, NULL);
|
||||
#else
|
||||
@ -146,8 +158,12 @@ bool DemodulatorInstance::isActive() {
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setActive(bool state) {
|
||||
if (active && !state) {
|
||||
audioThread->setActive(state);
|
||||
} else if (!active && state) {
|
||||
audioThread->setActive(state);
|
||||
}
|
||||
active = state;
|
||||
audioThread->setActive(state);
|
||||
}
|
||||
|
||||
bool DemodulatorInstance::isStereo() {
|
||||
|
@ -70,6 +70,8 @@ void DemodulatorPreThread::threadMain() {
|
||||
std::vector<liquid_float_complex> in_buf_data;
|
||||
std::vector<liquid_float_complex> out_buf_data;
|
||||
|
||||
terminated = false;
|
||||
|
||||
while (!terminated) {
|
||||
DemodulatorThreadIQData *inp;
|
||||
iqInputQueue->pop(inp);
|
||||
|
@ -32,6 +32,10 @@ public:
|
||||
return params;
|
||||
}
|
||||
|
||||
void setParams(DemodulatorThreadParameters ¶ms_in) {
|
||||
params = params_in;
|
||||
}
|
||||
|
||||
void initialize();
|
||||
void terminate();
|
||||
|
||||
|
@ -92,6 +92,8 @@ void DemodulatorThread::threadMain() {
|
||||
|
||||
std::cout << "Demodulator thread started.." << std::endl;
|
||||
|
||||
terminated = false;
|
||||
|
||||
while (!terminated) {
|
||||
DemodulatorThreadPostIQData *inp;
|
||||
iqInputQueue->pop(inp);
|
||||
|
Loading…
Reference in New Issue
Block a user