mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 17:28:50 -05:00
M17 demod: updated threading model. Part of #1346
This commit is contained in:
parent
aab8b0f15d
commit
54ca369d6f
@ -54,17 +54,13 @@ const int M17Demod::m_udpBlockSize = 512;
|
||||
M17Demod::M17Demod(DeviceAPI *deviceAPI) :
|
||||
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_thread(nullptr),
|
||||
m_basebandSink(nullptr),
|
||||
m_running(false),
|
||||
m_basebandSampleRate(0)
|
||||
{
|
||||
qDebug("M17Demod::M17Demod");
|
||||
setObjectName(m_channelId);
|
||||
|
||||
m_thread = new QThread(this);
|
||||
m_basebandSink = new M17DemodBaseband();
|
||||
m_basebandSink->setChannel(this);
|
||||
m_basebandSink->setDemodInputMessageQueue(&m_inputMessageQueue);
|
||||
m_basebandSink->moveToThread(m_thread);
|
||||
|
||||
applySettings(m_settings, QList<QString>(), true);
|
||||
|
||||
m_deviceAPI->addChannelSink(this);
|
||||
@ -83,6 +79,8 @@ M17Demod::M17Demod(DeviceAPI *deviceAPI) :
|
||||
this,
|
||||
&M17Demod::handleIndexInDeviceSetChanged
|
||||
);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
M17Demod::~M17Demod()
|
||||
@ -96,8 +94,7 @@ M17Demod::~M17Demod()
|
||||
delete m_networkManager;
|
||||
m_deviceAPI->removeChannelSinkAPI(this);
|
||||
m_deviceAPI->removeChannelSink(this);
|
||||
delete m_basebandSink;
|
||||
delete m_thread;
|
||||
stop();
|
||||
}
|
||||
|
||||
void M17Demod::setDeviceAPI(DeviceAPI *deviceAPI)
|
||||
@ -120,12 +117,27 @@ uint32_t M17Demod::getNumberOfDeviceStreams() const
|
||||
void M17Demod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)
|
||||
{
|
||||
(void) firstOfBurst;
|
||||
|
||||
if (m_running) {
|
||||
m_basebandSink->feed(begin, end);
|
||||
}
|
||||
}
|
||||
|
||||
void M17Demod::start()
|
||||
{
|
||||
if (m_running) {
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "M17Demod::start";
|
||||
m_thread = new QThread(this);
|
||||
m_basebandSink = new M17DemodBaseband();
|
||||
m_basebandSink->setChannel(this);
|
||||
m_basebandSink->setDemodInputMessageQueue(&m_inputMessageQueue);
|
||||
m_basebandSink->moveToThread(m_thread);
|
||||
|
||||
QObject::connect(m_thread, &QThread::finished, m_basebandSink, &QObject::deleteLater);
|
||||
QObject::connect(m_thread, &QThread::finished, m_thread, &QThread::deleteLater);
|
||||
|
||||
if (m_basebandSampleRate != 0) {
|
||||
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
|
||||
@ -133,11 +145,17 @@ void M17Demod::start()
|
||||
|
||||
m_basebandSink->reset();
|
||||
m_thread->start();
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
void M17Demod::stop()
|
||||
{
|
||||
if (!m_running) {
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "M17Demod::stop";
|
||||
m_running = false;
|
||||
m_thread->exit();
|
||||
m_thread->wait();
|
||||
}
|
||||
@ -158,10 +176,15 @@ bool M17Demod::handleMessage(const Message& cmd)
|
||||
{
|
||||
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
||||
m_basebandSampleRate = notif.getSampleRate();
|
||||
// Forward to the sink
|
||||
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
|
||||
qDebug() << "M17Demod::handleMessage: DSPSignalNotification";
|
||||
|
||||
// Forward to the sink
|
||||
if (m_running)
|
||||
{
|
||||
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
|
||||
m_basebandSink->getInputMessageQueue()->push(rep);
|
||||
}
|
||||
|
||||
// Forward to GUI if any
|
||||
if (getMessageQueueToGUI()) {
|
||||
getMessageQueueToGUI()->push(new DSPSignalNotification(notif));
|
||||
@ -258,8 +281,11 @@ void M17Demod::applySettings(const M17DemodSettings& settings, const QList<QStri
|
||||
}
|
||||
}
|
||||
|
||||
if (m_running)
|
||||
{
|
||||
M17DemodBaseband::MsgConfigureM17DemodBaseband *msg = M17DemodBaseband::MsgConfigureM17DemodBaseband::create(settings, settingsKeys, force);
|
||||
m_basebandSink->getInputMessageQueue()->push(msg);
|
||||
}
|
||||
|
||||
if (settingsKeys.contains("m_useReverseAPI"))
|
||||
{
|
||||
@ -543,9 +569,13 @@ void M17Demod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response
|
||||
getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples);
|
||||
|
||||
response.getM17DemodReport()->setChannelPowerDb(CalcDb::dbPower(magsqAvg));
|
||||
|
||||
if (m_running)
|
||||
{
|
||||
response.getM17DemodReport()->setAudioSampleRate(m_basebandSink->getAudioSampleRate());
|
||||
response.getM17DemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate());
|
||||
response.getM17DemodReport()->setSquelch(m_basebandSink->getSquelchOpen() ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void M17Demod::webapiReverseSendSettings(const QList<QString>& channelSettingsKeys, const M17DemodSettings& settings, bool force)
|
||||
@ -707,7 +737,7 @@ void M17Demod::networkManagerFinished(QNetworkReply *reply)
|
||||
|
||||
void M17Demod::handleIndexInDeviceSetChanged(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
if (!m_running || (index < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -268,6 +268,7 @@ private:
|
||||
DeviceAPI *m_deviceAPI;
|
||||
QThread *m_thread;
|
||||
M17DemodBaseband *m_basebandSink;
|
||||
bool m_running;
|
||||
M17DemodSettings m_settings;
|
||||
int m_basebandSampleRate; //!< stored from device message used when starting baseband sink
|
||||
|
||||
|
@ -25,11 +25,11 @@
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(M17DemodBaseband::MsgConfigureM17DemodBaseband, Message)
|
||||
|
||||
M17DemodBaseband::M17DemodBaseband()
|
||||
M17DemodBaseband::M17DemodBaseband() :
|
||||
m_channelizer(&m_sink)
|
||||
{
|
||||
qDebug("M17DemodBaseband::M17DemodBaseband");
|
||||
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000));
|
||||
m_channelizer = new DownChannelizer(&m_sink);
|
||||
|
||||
QObject::connect(
|
||||
&m_sampleFifo,
|
||||
@ -49,7 +49,6 @@ M17DemodBaseband::M17DemodBaseband()
|
||||
M17DemodBaseband::~M17DemodBaseband()
|
||||
{
|
||||
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(m_sink.getAudioFifo());
|
||||
delete m_channelizer;
|
||||
}
|
||||
|
||||
void M17DemodBaseband::reset()
|
||||
@ -84,12 +83,12 @@ void M17DemodBaseband::handleData()
|
||||
|
||||
// first part of FIFO data
|
||||
if (part1begin != part1end) {
|
||||
m_channelizer->feed(part1begin, part1end);
|
||||
m_channelizer.feed(part1begin, part1end);
|
||||
}
|
||||
|
||||
// second part of FIFO data (used when block wraps around)
|
||||
if(part2begin != part2end) {
|
||||
m_channelizer->feed(part2begin, part2end);
|
||||
m_channelizer.feed(part2begin, part2end);
|
||||
}
|
||||
|
||||
m_sampleFifo.readCommit((unsigned int) count);
|
||||
@ -126,13 +125,13 @@ bool M17DemodBaseband::handleMessage(const Message& cmd)
|
||||
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
||||
qDebug() << "M17DemodBaseband::handleMessage: DSPSignalNotification: basebandSampleRate: " << notif.getSampleRate();
|
||||
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(notif.getSampleRate()));
|
||||
m_channelizer->setBasebandSampleRate(notif.getSampleRate());
|
||||
m_sink.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset());
|
||||
m_channelizer.setBasebandSampleRate(notif.getSampleRate());
|
||||
m_sink.applyChannelSettings(m_channelizer.getChannelSampleRate(), m_channelizer.getChannelFrequencyOffset());
|
||||
|
||||
if (m_channelSampleRate != m_channelizer->getChannelSampleRate())
|
||||
if (m_channelSampleRate != m_channelizer.getChannelSampleRate())
|
||||
{
|
||||
m_sink.applyAudioSampleRate(m_sink.getAudioSampleRate()); // reapply when channel sample rate changes
|
||||
m_channelSampleRate = m_channelizer->getChannelSampleRate();
|
||||
m_channelSampleRate = m_channelizer.getChannelSampleRate();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -147,13 +146,13 @@ void M17DemodBaseband::applySettings(const M17DemodSettings& settings, const QLi
|
||||
{
|
||||
if (settingsKeys.contains("inputFrequencyOffset") || force)
|
||||
{
|
||||
m_channelizer->setChannelization(48000, settings.m_inputFrequencyOffset);
|
||||
m_sink.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset());
|
||||
m_channelizer.setChannelization(48000, settings.m_inputFrequencyOffset);
|
||||
m_sink.applyChannelSettings(m_channelizer.getChannelSampleRate(), m_channelizer.getChannelFrequencyOffset());
|
||||
|
||||
if (m_channelSampleRate != m_channelizer->getChannelSampleRate())
|
||||
if (m_channelSampleRate != m_channelizer.getChannelSampleRate())
|
||||
{
|
||||
m_sink.applyAudioSampleRate(m_sink.getAudioSampleRate()); // reapply when channel sample rate changes
|
||||
m_channelSampleRate = m_channelizer->getChannelSampleRate();
|
||||
m_channelSampleRate = m_channelizer.getChannelSampleRate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,12 +181,12 @@ void M17DemodBaseband::applySettings(const M17DemodSettings& settings, const QLi
|
||||
|
||||
int M17DemodBaseband::getChannelSampleRate() const
|
||||
{
|
||||
return m_channelizer->getChannelSampleRate();
|
||||
return m_channelizer.getChannelSampleRate();
|
||||
}
|
||||
|
||||
|
||||
void M17DemodBaseband::setBasebandSampleRate(int sampleRate)
|
||||
{
|
||||
m_channelizer->setBasebandSampleRate(sampleRate);
|
||||
m_sink.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset());
|
||||
m_channelizer.setBasebandSampleRate(sampleRate);
|
||||
m_sink.applyChannelSettings(m_channelizer.getChannelSampleRate(), m_channelizer.getChannelFrequencyOffset());
|
||||
}
|
||||
|
@ -22,12 +22,12 @@
|
||||
#include <QRecursiveMutex>
|
||||
|
||||
#include "dsp/samplesinkfifo.h"
|
||||
#include "dsp/downchannelizer.h"
|
||||
#include "util/message.h"
|
||||
#include "util/messagequeue.h"
|
||||
|
||||
#include "m17demodsink.h"
|
||||
|
||||
class DownChannelizer;
|
||||
class ChannelAPI;
|
||||
|
||||
class M17DemodBaseband : public QObject
|
||||
@ -124,7 +124,7 @@ public:
|
||||
|
||||
private:
|
||||
SampleSinkFifo m_sampleFifo;
|
||||
DownChannelizer *m_channelizer;
|
||||
DownChannelizer m_channelizer;
|
||||
int m_channelSampleRate;
|
||||
M17DemodSink m_sink;
|
||||
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
|
||||
|
Loading…
Reference in New Issue
Block a user