1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

DV serial: alternate timeout handling. Primitives to get information about worker status

This commit is contained in:
f4exb 2016-10-11 20:24:08 +02:00
parent 32595f81b9
commit 13e832a20e
3 changed files with 18 additions and 13 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -21,6 +21,7 @@
#include <QObject>
#include <QDebug>
#include <QTimer>
#include <QDateTime>
#include <vector>
@ -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 {