mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-17 05:41:56 -05:00
LocalSink: refactored LocalSinkThread to LocalSinkWorker object moved to thread. Equivalent to FileInput changes
This commit is contained in:
parent
7cddf7ce0b
commit
141d3fa03d
@ -6,7 +6,7 @@ set(localsink_SOURCES
|
||||
localsinksink.cpp
|
||||
localsinksettings.cpp
|
||||
localsinkwebapiadapter.cpp
|
||||
localsinkthread.cpp
|
||||
localsinkworker.cpp
|
||||
localsinkplugin.cpp
|
||||
)
|
||||
|
||||
@ -16,7 +16,7 @@ set(localsink_HEADERS
|
||||
localsinksink.h
|
||||
localsinksettings.h
|
||||
localsinkwebapiadapter.h
|
||||
localsinkthread.h
|
||||
localsinkworker.h
|
||||
localsinkplugin.h
|
||||
)
|
||||
|
||||
|
@ -22,11 +22,11 @@
|
||||
#include "dsp/devicesamplesource.h"
|
||||
#include "dsp/hbfilterchainconverter.h"
|
||||
|
||||
#include "localsinkthread.h"
|
||||
#include "localsinkworker.h"
|
||||
#include "localsinksink.h"
|
||||
|
||||
LocalSinkSink::LocalSinkSink() :
|
||||
m_sinkThread(nullptr),
|
||||
m_sinkWorker(nullptr),
|
||||
m_running(false),
|
||||
m_centerFrequency(0),
|
||||
m_frequencyOffset(0),
|
||||
@ -54,22 +54,23 @@ void LocalSinkSink::start(DeviceSampleSource *deviceSource)
|
||||
stop();
|
||||
}
|
||||
|
||||
m_sinkThread = new LocalSinkThread();
|
||||
m_sinkThread->setSampleFifo(&m_sampleFifo);
|
||||
m_sinkWorker = new LocalSinkWorker();
|
||||
m_sinkWorker->moveToThread(&m_sinkWorkerThread);
|
||||
m_sinkWorker->setSampleFifo(&m_sampleFifo);
|
||||
|
||||
if (deviceSource) {
|
||||
m_sinkThread->setDeviceSampleFifo(deviceSource->getSampleFifo());
|
||||
m_sinkWorker->setDeviceSampleFifo(deviceSource->getSampleFifo());
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
&m_sampleFifo,
|
||||
&SampleSinkFifo::dataReady,
|
||||
m_sinkThread,
|
||||
&LocalSinkThread::handleData,
|
||||
m_sinkWorker,
|
||||
&LocalSinkWorker::handleData,
|
||||
Qt::QueuedConnection
|
||||
);
|
||||
|
||||
m_sinkThread->startStop(true);
|
||||
startWorker();
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
@ -80,20 +81,33 @@ void LocalSinkSink::stop()
|
||||
QObject::disconnect(
|
||||
&m_sampleFifo,
|
||||
&SampleSinkFifo::dataReady,
|
||||
m_sinkThread,
|
||||
&LocalSinkThread::handleData
|
||||
m_sinkWorker,
|
||||
&LocalSinkWorker::handleData
|
||||
);
|
||||
|
||||
if (m_sinkThread != 0)
|
||||
if (m_sinkWorker != 0)
|
||||
{
|
||||
m_sinkThread->startStop(false);
|
||||
m_sinkThread->deleteLater();
|
||||
m_sinkThread = 0;
|
||||
stopWorker();
|
||||
m_sinkWorker->deleteLater();
|
||||
m_sinkWorker = nullptr;
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void LocalSinkSink::startWorker()
|
||||
{
|
||||
m_sinkWorker->startStop(true);
|
||||
m_sinkWorkerThread.start();
|
||||
}
|
||||
|
||||
void LocalSinkSink::stopWorker()
|
||||
{
|
||||
m_sinkWorker->startStop(false);
|
||||
m_sinkWorkerThread.quit();
|
||||
m_sinkWorkerThread.wait();
|
||||
}
|
||||
|
||||
void LocalSinkSink::applySettings(const LocalSinkSettings& settings, bool force)
|
||||
{
|
||||
qDebug() << "LocalSinkSink::applySettings:"
|
||||
|
@ -19,13 +19,14 @@
|
||||
#define INCLUDE_LOCALSINKSINK_H_
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
|
||||
#include "dsp/channelsamplesink.h"
|
||||
|
||||
#include "localsinksettings.h"
|
||||
|
||||
class DeviceSampleSource;
|
||||
class LocalSinkThread;
|
||||
class LocalSinkWorker;
|
||||
|
||||
class LocalSinkSink : public QObject, public ChannelSampleSink {
|
||||
Q_OBJECT
|
||||
@ -44,7 +45,8 @@ public:
|
||||
private:
|
||||
SampleSinkFifo m_sampleFifo;
|
||||
LocalSinkSettings m_settings;
|
||||
LocalSinkThread *m_sinkThread;
|
||||
LocalSinkWorker *m_sinkWorker;
|
||||
QThread m_sinkWorkerThread;
|
||||
bool m_running;
|
||||
|
||||
uint64_t m_centerFrequency;
|
||||
@ -52,6 +54,8 @@ private:
|
||||
uint32_t m_sampleRate;
|
||||
uint32_t m_deviceSampleRate;
|
||||
|
||||
void startWorker();
|
||||
void stopWorker();
|
||||
};
|
||||
|
||||
#endif // INCLUDE_LOCALSINKSINK_H_
|
||||
|
@ -17,62 +17,41 @@
|
||||
|
||||
#include "dsp/samplesinkfifo.h"
|
||||
|
||||
#include "localsinkthread.h"
|
||||
#include "localsinkworker.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(LocalSinkThread::MsgStartStop, Message)
|
||||
MESSAGE_CLASS_DEFINITION(LocalSinkWorker::MsgStartStop, Message)
|
||||
|
||||
LocalSinkThread::LocalSinkThread(QObject* parent) :
|
||||
QThread(parent),
|
||||
LocalSinkWorker::LocalSinkWorker(QObject* parent) :
|
||||
QObject(parent),
|
||||
m_running(false),
|
||||
m_sampleFifo(0)
|
||||
{
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
LocalSinkThread::~LocalSinkThread()
|
||||
LocalSinkWorker::~LocalSinkWorker()
|
||||
{
|
||||
qDebug("LocalSinkThread::~LocalSinkThread");
|
||||
qDebug("LocalSinkWorker::~LocalSinkWorker");
|
||||
}
|
||||
|
||||
void LocalSinkThread::startStop(bool start)
|
||||
void LocalSinkWorker::startStop(bool start)
|
||||
{
|
||||
MsgStartStop *msg = MsgStartStop::create(start);
|
||||
m_inputMessageQueue.push(msg);
|
||||
}
|
||||
|
||||
void LocalSinkThread::startWork()
|
||||
void LocalSinkWorker::startWork()
|
||||
{
|
||||
qDebug("LocalSinkThread::startWork");
|
||||
m_startWaitMutex.lock();
|
||||
start();
|
||||
while(!m_running)
|
||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||
m_startWaitMutex.unlock();
|
||||
qDebug("LocalSinkWorker::startWork");
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
void LocalSinkThread::stopWork()
|
||||
void LocalSinkWorker::stopWork()
|
||||
{
|
||||
qDebug("LocalSinkThread::stopWork");
|
||||
m_running = false;
|
||||
wait();
|
||||
}
|
||||
|
||||
void LocalSinkThread::run()
|
||||
{
|
||||
qDebug("LocalSinkThread::run: begin");
|
||||
m_running = true;
|
||||
m_startWaiter.wakeAll();
|
||||
|
||||
while (m_running)
|
||||
{
|
||||
sleep(1); // Do nothing as everything is in the data handler (dequeuer)
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
qDebug("LocalSinkThread::run: end");
|
||||
}
|
||||
|
||||
void LocalSinkThread::handleData()
|
||||
void LocalSinkWorker::handleData()
|
||||
{
|
||||
while ((m_sampleFifo->fill() > 0) && (m_inputMessageQueue.size() == 0))
|
||||
{
|
||||
@ -100,7 +79,7 @@ void LocalSinkThread::handleData()
|
||||
}
|
||||
}
|
||||
|
||||
void LocalSinkThread::handleInputMessages()
|
||||
void LocalSinkWorker::handleInputMessages()
|
||||
{
|
||||
Message* message;
|
||||
|
||||
@ -109,7 +88,7 @@ void LocalSinkThread::handleInputMessages()
|
||||
if (MsgStartStop::match(*message))
|
||||
{
|
||||
MsgStartStop* notif = (MsgStartStop*) message;
|
||||
qDebug("LocalSinkThread::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
|
||||
qDebug("LocalSinkWorker::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
|
||||
|
||||
if (notif->getStartStop()) {
|
||||
startWork();
|
@ -15,10 +15,10 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef PLUGINS_CHANNELRX_LOCALSINK_LOCALSINKTHREAD_H_
|
||||
#define PLUGINS_CHANNELRX_LOCALSINK_LOCALSINKTHREAD_H_
|
||||
#ifndef PLUGINS_CHANNELRX_LOCALSINK_LOCALSINKWORKER_H_
|
||||
#define PLUGINS_CHANNELRX_LOCALSINK_LOCALSINKWORKER_H_
|
||||
|
||||
#include <QThread>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
class SampleSinkFifo;
|
||||
|
||||
class LocalSinkThread : public QThread {
|
||||
class LocalSinkWorker : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@ -51,8 +51,8 @@ public:
|
||||
{ }
|
||||
};
|
||||
|
||||
LocalSinkThread(QObject* parent = 0);
|
||||
~LocalSinkThread();
|
||||
LocalSinkWorker(QObject* parent = 0);
|
||||
~LocalSinkWorker();
|
||||
|
||||
void startStop(bool start);
|
||||
void setSampleFifo(SampleSinkFifo *sampleFifo) { m_sampleFifo = sampleFifo; }
|
||||
@ -62,21 +62,17 @@ public slots:
|
||||
void handleData(); //!< Handle data when samples have to be processed
|
||||
|
||||
private:
|
||||
QMutex m_startWaitMutex;
|
||||
QWaitCondition m_startWaiter;
|
||||
volatile bool m_running;
|
||||
SampleSinkFifo *m_sampleFifo;
|
||||
SampleSinkFifo *m_deviceSampleFifo;
|
||||
|
||||
MessageQueue m_inputMessageQueue;
|
||||
|
||||
void startWork();
|
||||
void stopWork();
|
||||
void run();
|
||||
void startWork();
|
||||
void stopWork();
|
||||
|
||||
private slots:
|
||||
void handleInputMessages();
|
||||
};
|
||||
|
||||
#endif // PLUGINS_CHANNELRX_LOCALSINK_LOCALSINKTHREAD_H_
|
||||
#endif // PLUGINS_CHANNELRX_LOCALSINK_LOCALSINKWORKER_H_
|
||||
|
Loading…
Reference in New Issue
Block a user