mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-29 13:32:26 -04:00
Channel Analyzer: improved baseband thread management
This commit is contained in:
parent
181efe4b1c
commit
fe520f5ae5
@ -40,9 +40,8 @@ ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) :
|
|||||||
qDebug("ChannelAnalyzer::ChannelAnalyzer");
|
qDebug("ChannelAnalyzer::ChannelAnalyzer");
|
||||||
setObjectName(m_channelId);
|
setObjectName(m_channelId);
|
||||||
|
|
||||||
m_thread = new QThread(this);
|
|
||||||
m_basebandSink = new ChannelAnalyzerBaseband();
|
m_basebandSink = new ChannelAnalyzerBaseband();
|
||||||
m_basebandSink->moveToThread(m_thread);
|
m_basebandSink->moveToThread(&m_thread);
|
||||||
|
|
||||||
applySettings(m_settings, true);
|
applySettings(m_settings, true);
|
||||||
|
|
||||||
@ -54,8 +53,12 @@ ChannelAnalyzer::~ChannelAnalyzer()
|
|||||||
{
|
{
|
||||||
m_deviceAPI->removeChannelSinkAPI(this);
|
m_deviceAPI->removeChannelSinkAPI(this);
|
||||||
m_deviceAPI->removeChannelSink(this);
|
m_deviceAPI->removeChannelSink(this);
|
||||||
|
|
||||||
|
if (m_basebandSink->isRunning()) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
delete m_basebandSink;
|
delete m_basebandSink;
|
||||||
delete m_thread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly)
|
void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly)
|
||||||
@ -64,24 +67,28 @@ void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const Samp
|
|||||||
m_basebandSink->feed(begin, end);
|
m_basebandSink->feed(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ChannelAnalyzer::start()
|
void ChannelAnalyzer::start()
|
||||||
{
|
{
|
||||||
qDebug() << "ChannelAnalyzer::start";
|
qDebug() << "ChannelAnalyzer::start";
|
||||||
|
|
||||||
if (m_basebandSampleRate != 0) {
|
|
||||||
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_basebandSink->reset();
|
m_basebandSink->reset();
|
||||||
m_thread->start();
|
m_basebandSink->startWork();
|
||||||
|
m_thread.start();
|
||||||
|
|
||||||
|
DSPSignalNotification *dspMsg = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency);
|
||||||
|
m_basebandSink->getInputMessageQueue()->push(dspMsg);
|
||||||
|
|
||||||
|
ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband *msg =
|
||||||
|
ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband::create(m_settings, true);
|
||||||
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelAnalyzer::stop()
|
void ChannelAnalyzer::stop()
|
||||||
{
|
{
|
||||||
qDebug() << "ChannelAnalyzer::stop";
|
qDebug() << "ChannelAnalyzer::stop";
|
||||||
m_thread->exit();
|
m_basebandSink->stopWork();
|
||||||
m_thread->wait();
|
m_thread.quit();
|
||||||
|
m_thread.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChannelAnalyzer::handleMessage(const Message& cmd)
|
bool ChannelAnalyzer::handleMessage(const Message& cmd)
|
||||||
@ -99,6 +106,7 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd)
|
|||||||
{
|
{
|
||||||
DSPSignalNotification& cfg = (DSPSignalNotification&) cmd;
|
DSPSignalNotification& cfg = (DSPSignalNotification&) cmd;
|
||||||
m_basebandSampleRate = cfg.getSampleRate();
|
m_basebandSampleRate = cfg.getSampleRate();
|
||||||
|
m_centerFrequency = cfg.getCenterFrequency();
|
||||||
DSPSignalNotification *notif = new DSPSignalNotification(cfg);
|
DSPSignalNotification *notif = new DSPSignalNotification(cfg);
|
||||||
m_basebandSink->getInputMessageQueue()->push(notif);
|
m_basebandSink->getInputMessageQueue()->push(notif);
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#define INCLUDE_CHANALYZER_H
|
#define INCLUDE_CHANALYZER_H
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QThread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "dsp/basebandsamplesink.h"
|
#include "dsp/basebandsamplesink.h"
|
||||||
@ -29,7 +30,6 @@
|
|||||||
|
|
||||||
#include "chanalyzerbaseband.h"
|
#include "chanalyzerbaseband.h"
|
||||||
|
|
||||||
class QThread;
|
|
||||||
class DownChannelizer;
|
class DownChannelizer;
|
||||||
|
|
||||||
class ChannelAnalyzer : public BasebandSampleSink, public ChannelAPI {
|
class ChannelAnalyzer : public BasebandSampleSink, public ChannelAPI {
|
||||||
@ -98,11 +98,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceAPI *m_deviceAPI;
|
DeviceAPI *m_deviceAPI;
|
||||||
QThread *m_thread;
|
QThread m_thread;
|
||||||
ChannelAnalyzerBaseband *m_basebandSink;
|
ChannelAnalyzerBaseband *m_basebandSink;
|
||||||
ChannelAnalyzerSettings m_settings;
|
ChannelAnalyzerSettings m_settings;
|
||||||
SpectrumVis m_spectrumVis;
|
SpectrumVis m_spectrumVis;
|
||||||
int m_basebandSampleRate; //!< stored from device message used when starting baseband sink
|
int m_basebandSampleRate; //!< stored from device message used when starting baseband sink
|
||||||
|
qint64 m_centerFrequency; //!< stored from device message used when starting baseband sink
|
||||||
|
|
||||||
void applySettings(const ChannelAnalyzerSettings& settings, bool force = false);
|
void applySettings(const ChannelAnalyzerSettings& settings, bool force = false);
|
||||||
};
|
};
|
||||||
|
@ -26,12 +26,30 @@
|
|||||||
MESSAGE_CLASS_DEFINITION(ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband, Message)
|
MESSAGE_CLASS_DEFINITION(ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband, Message)
|
||||||
|
|
||||||
ChannelAnalyzerBaseband::ChannelAnalyzerBaseband() :
|
ChannelAnalyzerBaseband::ChannelAnalyzerBaseband() :
|
||||||
|
m_running(false),
|
||||||
m_mutex(QMutex::Recursive)
|
m_mutex(QMutex::Recursive)
|
||||||
{
|
{
|
||||||
qDebug("ChannelAnalyzerBaseband::ChannelAnalyzerBaseband");
|
qDebug("ChannelAnalyzerBaseband::ChannelAnalyzerBaseband");
|
||||||
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000));
|
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000));
|
||||||
m_channelizer = new DownChannelizer(&m_sink);
|
m_channelizer = new DownChannelizer(&m_sink);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChannelAnalyzerBaseband::~ChannelAnalyzerBaseband()
|
||||||
|
{
|
||||||
|
m_inputMessageQueue.clear();
|
||||||
|
delete m_channelizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChannelAnalyzerBaseband::reset()
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
m_inputMessageQueue.clear();
|
||||||
|
m_sampleFifo.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChannelAnalyzerBaseband::startWork()
|
||||||
|
{
|
||||||
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&m_sampleFifo,
|
&m_sampleFifo,
|
||||||
&SampleSinkFifo::dataReady,
|
&SampleSinkFifo::dataReady,
|
||||||
@ -39,19 +57,21 @@ ChannelAnalyzerBaseband::ChannelAnalyzerBaseband() :
|
|||||||
&ChannelAnalyzerBaseband::handleData,
|
&ChannelAnalyzerBaseband::handleData,
|
||||||
Qt::QueuedConnection
|
Qt::QueuedConnection
|
||||||
);
|
);
|
||||||
|
|
||||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
||||||
|
m_running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelAnalyzerBaseband::~ChannelAnalyzerBaseband()
|
void ChannelAnalyzerBaseband::stopWork()
|
||||||
{
|
|
||||||
delete m_channelizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChannelAnalyzerBaseband::reset()
|
|
||||||
{
|
{
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
m_sampleFifo.reset();
|
disconnect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
||||||
|
QObject::disconnect(
|
||||||
|
&m_sampleFifo,
|
||||||
|
&SampleSinkFifo::dataReady,
|
||||||
|
this,
|
||||||
|
&ChannelAnalyzerBaseband::handleData
|
||||||
|
);
|
||||||
|
m_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelAnalyzerBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
|
void ChannelAnalyzerBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
|
||||||
|
@ -59,6 +59,9 @@ public:
|
|||||||
ChannelAnalyzerBaseband();
|
ChannelAnalyzerBaseband();
|
||||||
~ChannelAnalyzerBaseband();
|
~ChannelAnalyzerBaseband();
|
||||||
void reset();
|
void reset();
|
||||||
|
void startWork();
|
||||||
|
void stopWork();
|
||||||
|
bool isRunning() const { return m_running; }
|
||||||
void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end);
|
void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end);
|
||||||
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication
|
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication
|
||||||
int getChannelSampleRate() const;
|
int getChannelSampleRate() const;
|
||||||
@ -77,6 +80,7 @@ private:
|
|||||||
ChannelAnalyzerSink m_sink;
|
ChannelAnalyzerSink m_sink;
|
||||||
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
|
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
|
||||||
ChannelAnalyzerSettings m_settings;
|
ChannelAnalyzerSettings m_settings;
|
||||||
|
bool m_running;
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
|
|
||||||
bool handleMessage(const Message& cmd);
|
bool handleMessage(const Message& cmd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user