mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-06-25 21:45:28 -04:00
TestSource: new threading model. Part of #1346
This commit is contained in:
parent
1c75f8d326
commit
c6496b11f9
@ -22,6 +22,7 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
#include "SWGDeviceSettings.h"
|
#include "SWGDeviceSettings.h"
|
||||||
#include "SWGDeviceState.h"
|
#include "SWGDeviceState.h"
|
||||||
@ -40,6 +41,7 @@ TestSourceInput::TestSourceInput(DeviceAPI *deviceAPI) :
|
|||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
m_settings(),
|
m_settings(),
|
||||||
m_testSourceWorker(nullptr),
|
m_testSourceWorker(nullptr),
|
||||||
|
m_testSourceWorkerThread(nullptr),
|
||||||
m_deviceDescription("TestSourceInput"),
|
m_deviceDescription("TestSourceInput"),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
m_masterTimer(deviceAPI->getMasterTimer())
|
m_masterTimer(deviceAPI->getMasterTimer())
|
||||||
@ -86,7 +88,7 @@ bool TestSourceInput::start()
|
|||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
if (m_running) {
|
if (m_running) {
|
||||||
stop();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_sampleFifo.setSize(96000 * 4))
|
if (!m_sampleFifo.setSize(96000 * 4))
|
||||||
@ -95,11 +97,16 @@ bool TestSourceInput::start()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_testSourceWorkerThread = new QThread();
|
||||||
m_testSourceWorker = new TestSourceWorker(&m_sampleFifo);
|
m_testSourceWorker = new TestSourceWorker(&m_sampleFifo);
|
||||||
m_testSourceWorker->moveToThread(&m_testSourceWorkerThread);
|
m_testSourceWorker->moveToThread(m_testSourceWorkerThread);
|
||||||
|
|
||||||
|
QObject::connect(m_testSourceWorkerThread, &QThread::started, m_testSourceWorker, &TestSourceWorker::startWork);
|
||||||
|
QObject::connect(m_testSourceWorkerThread, &QThread::finished, m_testSourceWorker, &QObject::deleteLater);
|
||||||
|
QObject::connect(m_testSourceWorkerThread, &QThread::finished, m_testSourceWorkerThread, &QThread::deleteLater);
|
||||||
|
|
||||||
m_testSourceWorker->setSamplerate(m_settings.m_sampleRate);
|
m_testSourceWorker->setSamplerate(m_settings.m_sampleRate);
|
||||||
m_testSourceWorker->startWork();
|
m_testSourceWorkerThread->start();
|
||||||
m_testSourceWorkerThread.start();
|
|
||||||
m_running = true;
|
m_running = true;
|
||||||
|
|
||||||
mutexLocker.unlock();
|
mutexLocker.unlock();
|
||||||
@ -114,13 +121,13 @@ void TestSourceInput::stop()
|
|||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
m_running = false;
|
m_running = false;
|
||||||
|
|
||||||
if (m_testSourceWorker)
|
if (m_testSourceWorkerThread)
|
||||||
{
|
{
|
||||||
m_testSourceWorker->stopWork();
|
m_testSourceWorker->stopWork();
|
||||||
m_testSourceWorkerThread.quit();
|
m_testSourceWorkerThread->quit();
|
||||||
m_testSourceWorkerThread.wait();
|
m_testSourceWorkerThread->wait();
|
||||||
delete m_testSourceWorker;
|
|
||||||
m_testSourceWorker = nullptr;
|
m_testSourceWorker = nullptr;
|
||||||
|
m_testSourceWorkerThread = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
#include <dsp/devicesamplesource.h>
|
#include <dsp/devicesamplesource.h>
|
||||||
#include "testsourcesettings.h"
|
#include "testsourcesettings.h"
|
||||||
@ -31,6 +30,7 @@ class DeviceAPI;
|
|||||||
class TestSourceWorker;
|
class TestSourceWorker;
|
||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class QThread;
|
||||||
|
|
||||||
class TestSourceInput : public DeviceSampleSource {
|
class TestSourceInput : public DeviceSampleSource {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -129,8 +129,8 @@ private:
|
|||||||
DeviceAPI *m_deviceAPI;
|
DeviceAPI *m_deviceAPI;
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
TestSourceSettings m_settings;
|
TestSourceSettings m_settings;
|
||||||
TestSourceWorker* m_testSourceWorker;
|
TestSourceWorker *m_testSourceWorker;
|
||||||
QThread m_testSourceWorkerThread;
|
QThread *m_testSourceWorkerThread;
|
||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
const QTimer& m_masterTimer;
|
const QTimer& m_masterTimer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user