mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-05 22:57:47 -04:00
Merge pull request #1436 from srcejon/airspyhfp_thread
Update threading in airspyhf source
This commit is contained in:
commit
8f0b7287e3
@ -50,6 +50,7 @@ AirspyHFInput::AirspyHFInput(DeviceAPI *deviceAPI) :
|
|||||||
m_settings(),
|
m_settings(),
|
||||||
m_dev(nullptr),
|
m_dev(nullptr),
|
||||||
m_airspyHFWorker(nullptr),
|
m_airspyHFWorker(nullptr),
|
||||||
|
m_airspyHFWorkerThread(nullptr),
|
||||||
m_deviceDescription("AirspyHF"),
|
m_deviceDescription("AirspyHF"),
|
||||||
m_running(false)
|
m_running(false)
|
||||||
{
|
{
|
||||||
@ -174,10 +175,15 @@ bool AirspyHFInput::start()
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_airspyHFWorker = new AirspyHFWorker(m_dev, &m_sampleFifo);
|
m_airspyHFWorkerThread = new QThread();
|
||||||
m_airspyHFWorker->moveToThread(&m_airspyHFWorkerThread);
|
m_airspyHFWorker = new AirspyHFWorker(m_dev, &m_sampleFifo);
|
||||||
|
m_airspyHFWorker->moveToThread(m_airspyHFWorkerThread);
|
||||||
int sampleRateIndex = m_settings.m_devSampleRateIndex;
|
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()) {
|
if (m_settings.m_devSampleRateIndex >= m_sampleRates.size()) {
|
||||||
sampleRateIndex = m_sampleRates.size() - 1;
|
sampleRateIndex = m_sampleRates.size() - 1;
|
||||||
}
|
}
|
||||||
@ -190,40 +196,15 @@ bool AirspyHFInput::start()
|
|||||||
m_airspyHFWorker->setIQOrder(m_settings.m_iqOrder);
|
m_airspyHFWorker->setIQOrder(m_settings.m_iqOrder);
|
||||||
mutexLocker.unlock();
|
mutexLocker.unlock();
|
||||||
|
|
||||||
if (startWorker())
|
m_airspyHFWorkerThread->start();
|
||||||
{
|
|
||||||
qDebug("AirspyHFInput::startInput: started");
|
qDebug("AirspyHFInput::startInput: started");
|
||||||
applySettings(m_settings, true);
|
applySettings(m_settings, true);
|
||||||
m_running = true;
|
m_running = true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_running;
|
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()
|
void AirspyHFInput::closeDevice()
|
||||||
{
|
{
|
||||||
if (m_dev)
|
if (m_dev)
|
||||||
@ -241,12 +222,13 @@ void AirspyHFInput::stop()
|
|||||||
qDebug("AirspyHFInput::stop");
|
qDebug("AirspyHFInput::stop");
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
if (m_airspyHFWorker)
|
if (m_airspyHFWorkerThread)
|
||||||
{
|
{
|
||||||
stopWorker();
|
m_airspyHFWorkerThread->quit();
|
||||||
delete m_airspyHFWorker;
|
m_airspyHFWorkerThread->wait();
|
||||||
m_airspyHFWorker = nullptr;
|
m_airspyHFWorkerThread = nullptr;
|
||||||
}
|
m_airspyHFWorker = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
m_running = false;
|
m_running = false;
|
||||||
}
|
}
|
||||||
|
@ -142,15 +142,13 @@ private:
|
|||||||
AirspyHFSettings m_settings;
|
AirspyHFSettings m_settings;
|
||||||
airspyhf_device_t* m_dev;
|
airspyhf_device_t* m_dev;
|
||||||
AirspyHFWorker* m_airspyHFWorker;
|
AirspyHFWorker* m_airspyHFWorker;
|
||||||
QThread m_airspyHFWorkerThread;
|
QThread *m_airspyHFWorkerThread;
|
||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
std::vector<uint32_t> m_sampleRates;
|
std::vector<uint32_t> m_sampleRates;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
QNetworkAccessManager *m_networkManager;
|
QNetworkAccessManager *m_networkManager;
|
||||||
QNetworkRequest m_networkRequest;
|
QNetworkRequest m_networkRequest;
|
||||||
|
|
||||||
bool startWorker();
|
|
||||||
void stopWorker();
|
|
||||||
bool openDevice();
|
bool openDevice();
|
||||||
void closeDevice();
|
void closeDevice();
|
||||||
bool applySettings(const AirspyHFSettings& settings, bool force);
|
bool applySettings(const AirspyHFSettings& settings, bool force);
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
AirspyHFWorker::AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
AirspyHFWorker::AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_running(false),
|
|
||||||
m_dev(dev),
|
m_dev(dev),
|
||||||
m_convertBuffer(AIRSPYHF_BLOCKSIZE),
|
m_convertBuffer(AIRSPYHF_BLOCKSIZE),
|
||||||
m_sampleFifo(sampleFifo),
|
m_sampleFifo(sampleFifo),
|
||||||
@ -41,22 +40,14 @@ AirspyHFWorker::~AirspyHFWorker()
|
|||||||
stopWork();
|
stopWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AirspyHFWorker::startWork()
|
void AirspyHFWorker::startWork()
|
||||||
{
|
{
|
||||||
qDebug("AirspyHFWorker::startWork");
|
qDebug("AirspyHFWorker::startWork");
|
||||||
airspyhf_error rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, this);
|
airspyhf_error rc = (airspyhf_error) airspyhf_start(m_dev, rx_callback, this);
|
||||||
|
|
||||||
if (rc == AIRSPYHF_SUCCESS)
|
if (rc != AIRSPYHF_SUCCESS) {
|
||||||
{
|
|
||||||
m_running = (airspyhf_is_streaming(m_dev) != 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qCritical("AirspyHFWorker::run: failed to start Airspy HF Rx");
|
qCritical("AirspyHFWorker::run: failed to start Airspy HF Rx");
|
||||||
m_running = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_running;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AirspyHFWorker::stopWork()
|
void AirspyHFWorker::stopWork()
|
||||||
@ -69,8 +60,6 @@ void AirspyHFWorker::stopWork()
|
|||||||
} else {
|
} else {
|
||||||
qDebug("AirspyHFWorker::run: failed to stop Airspy HF Rx");
|
qDebug("AirspyHFWorker::run: failed to stop Airspy HF Rx");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_running = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AirspyHFWorker::setSamplerate(uint32_t samplerate)
|
void AirspyHFWorker::setSamplerate(uint32_t samplerate)
|
||||||
|
@ -33,14 +33,13 @@ public:
|
|||||||
AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
AirspyHFWorker(airspyhf_device_t* dev, SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
||||||
~AirspyHFWorker();
|
~AirspyHFWorker();
|
||||||
|
|
||||||
bool startWork();
|
void startWork();
|
||||||
void stopWork();
|
void stopWork();
|
||||||
void setSamplerate(uint32_t samplerate);
|
void setSamplerate(uint32_t samplerate);
|
||||||
void setLog2Decimation(unsigned int log2_decim);
|
void setLog2Decimation(unsigned int log2_decim);
|
||||||
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_running;
|
|
||||||
|
|
||||||
airspyhf_device_t* m_dev;
|
airspyhf_device_t* m_dev;
|
||||||
qint16 m_buf[2*AIRSPYHF_BLOCKSIZE];
|
qint16 m_buf[2*AIRSPYHF_BLOCKSIZE];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user