diff --git a/sdrbase/dsp/dvserialengine.cpp b/sdrbase/dsp/dvserialengine.cpp index 3d126775d..2f50a1c3c 100644 --- a/sdrbase/dsp/dvserialengine.cpp +++ b/sdrbase/dsp/dvserialengine.cpp @@ -199,7 +199,6 @@ bool DVSerialEngine::scan() connect(controller.worker, SIGNAL(finished()), controller.worker, SLOT(deleteLater())); connect(controller.thread, SIGNAL(finished()), controller.thread, SLOT(deleteLater())); connect(&controller.worker->m_inputMessageQueue, SIGNAL(messageEnqueued()), controller.worker, SLOT(handleInputMessages())); - connect(controller.worker->m_timer, SIGNAL(timeout()), controller.worker, SLOT(releaseQueue())); controller.thread->start(); m_controllers.push_back(controller); @@ -255,12 +254,12 @@ void DVSerialEngine::pushMbeFrame(const unsigned char *mbeFrame, int mbeRateInde while (it != m_controllers.end()) { - if (it->worker->m_audioFifo == audioFifo) + if (it->worker->hasFifo(audioFifo)) { it->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo); done = true; } - else if (it->worker->m_audioFifo == 0) + else if (it->worker->isAvailable()) { itAvail = it; } diff --git a/sdrbase/dsp/dvserialworker.cpp b/sdrbase/dsp/dvserialworker.cpp index 330c3797b..16cf47842 100644 --- a/sdrbase/dsp/dvserialworker.cpp +++ b/sdrbase/dsp/dvserialworker.cpp @@ -33,13 +33,10 @@ DVSerialWorker::DVSerialWorker() : m_audioBuffer.resize(48000); m_audioBufferFill = 0; m_audioFifo = 0; - m_timer = new QTimer(this); - m_timer->setSingleShot(true); } DVSerialWorker::~DVSerialWorker() { - delete m_timer; } bool DVSerialWorker::open(const std::string& serialDevice) @@ -73,7 +70,6 @@ void DVSerialWorker::stop() void DVSerialWorker::handleInputMessages() { - m_timer->stop(); // suspend FIFO queue holding timeout Message* message; m_audioBufferFill = 0; AudioFifo *audioFifo = 0; @@ -109,7 +105,7 @@ void DVSerialWorker::handleInputMessages() } } - m_timer->start(1000); // FIFO queue holding timeout + m_timestamp = QDateTime::currentDateTime(); } void DVSerialWorker::pushMbeFrame(const unsigned char *mbeFrame, @@ -121,10 +117,18 @@ void DVSerialWorker::pushMbeFrame(const unsigned char *mbeFrame, m_inputMessageQueue.push(MsgMbeDecode::create(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, audioFifo)); } -void DVSerialWorker::releaseQueue() +bool DVSerialWorker::isAvailable() { - qDebug("DVSerialWorker::releaseQueue: release %p", m_audioFifo); - m_audioFifo = 0; + if (m_audioFifo == 0) { + return true; + } + + return m_timestamp.time().msecsTo(QDateTime::currentDateTime().time()) > 1000; // 1 second inactivity timeout +} + +bool DVSerialWorker::hasFifo(AudioFifo *audioFifo) +{ + return m_audioFifo == audioFifo; } void DVSerialWorker::upsample6(short *in, int nbSamplesIn, unsigned char channels, AudioFifo *audioFifo) diff --git a/sdrbase/dsp/dvserialworker.h b/sdrbase/dsp/dvserialworker.h index 57010ddae..36ef2c4fa 100644 --- a/sdrbase/dsp/dvserialworker.h +++ b/sdrbase/dsp/dvserialworker.h @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -94,6 +95,8 @@ public: void close(); void process(); void stop(); + bool isAvailable(); + bool hasFifo(AudioFifo *audioFifo); void postTest() { @@ -103,14 +106,13 @@ public: MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication AudioFifo *m_audioFifo; - QTimer *m_timer; + QDateTime m_timestamp; signals: void finished(); public slots: void handleInputMessages(); - void releaseQueue(); private: struct AudioSample {