1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00

AirspyHF: Update threading model

This commit is contained in:
Jon Beniston 2022-09-20 15:04:00 +01:00
parent 53df5fe5d7
commit 63282ebfcd
2 changed files with 21 additions and 41 deletions

View File

@ -50,6 +50,7 @@ AirspyHFInput::AirspyHFInput(DeviceAPI *deviceAPI) :
m_settings(),
m_dev(nullptr),
m_airspyHFWorker(nullptr),
m_airspyHFWorkerThread(nullptr),
m_deviceDescription("AirspyHF"),
m_running(false)
{
@ -174,10 +175,15 @@ bool AirspyHFInput::start()
stop();
}
m_airspyHFWorkerThread = new QThread(this);
m_airspyHFWorker = new AirspyHFWorker(m_dev, &m_sampleFifo);
m_airspyHFWorker->moveToThread(&m_airspyHFWorkerThread);
m_airspyHFWorker->moveToThread(m_airspyHFWorkerThread);
int sampleRateIndex = m_settings.m_devSampleRateIndex;
QObject::connect(m_airspyHFWorkerThread, &QThread::started, m_airspyHFWorker, &AirspyHFWorker::startWork);
QObject::connect(m_airspyHFWorkerThread, &QThread::finished, m_airspyHFWorker, &QObject::deleteLater);
QObject::connect(m_airspyHFWorkerThread, &QThread::finished, m_airspyHFWorkerThread, &QThread::deleteLater);
if (m_settings.m_devSampleRateIndex >= m_sampleRates.size()) {
sampleRateIndex = m_sampleRates.size() - 1;
}
@ -190,40 +196,15 @@ bool AirspyHFInput::start()
m_airspyHFWorker->setIQOrder(m_settings.m_iqOrder);
mutexLocker.unlock();
if (startWorker())
{
m_airspyHFWorkerThread->start();
qDebug("AirspyHFInput::startInput: started");
applySettings(m_settings, true);
m_running = true;
}
else
{
m_running = false;
}
return m_running;
}
bool AirspyHFInput::startWorker()
{
if (m_airspyHFWorker->startWork())
{
m_airspyHFWorkerThread.start();
return true;
}
else
{
return false;
}
}
void AirspyHFInput::stopWorker()
{
m_airspyHFWorker->stopWork();
m_airspyHFWorkerThread.quit();
m_airspyHFWorkerThread.wait();
}
void AirspyHFInput::closeDevice()
{
if (m_dev)
@ -241,10 +222,11 @@ void AirspyHFInput::stop()
qDebug("AirspyHFInput::stop");
QMutexLocker mutexLocker(&m_mutex);
if (m_airspyHFWorker)
if (m_airspyHFWorkerThread)
{
stopWorker();
delete m_airspyHFWorker;
m_airspyHFWorkerThread->quit();
m_airspyHFWorkerThread->wait();
m_airspyHFWorkerThread = nullptr;
m_airspyHFWorker = nullptr;
}

View File

@ -142,15 +142,13 @@ private:
AirspyHFSettings m_settings;
airspyhf_device_t* m_dev;
AirspyHFWorker* m_airspyHFWorker;
QThread m_airspyHFWorkerThread;
QThread *m_airspyHFWorkerThread;
QString m_deviceDescription;
std::vector<uint32_t> m_sampleRates;
bool m_running;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
bool startWorker();
void stopWorker();
bool openDevice();
void closeDevice();
bool applySettings(const AirspyHFSettings& settings, bool force);