1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

ATV Demod: applied now threading model

This commit is contained in:
f4exb 2020-08-19 13:12:23 +02:00
parent a2a584440c
commit 596d2ef149
4 changed files with 46 additions and 19 deletions

View File

@ -18,7 +18,6 @@
#include <QTime>
#include <QDebug>
#include <QThread>
#include <stdio.h>
#include <complex.h>
@ -42,9 +41,8 @@ ATVDemod::ATVDemod(DeviceAPI *deviceAPI) :
qDebug("ATVDemod::ATVDemod");
setObjectName(m_channelId);
m_thread = new QThread(this);
m_basebandSink = new ATVDemodBaseband();
m_basebandSink->moveToThread(m_thread);
m_basebandSink->moveToThread(&m_thread);
applySettings(m_settings, true);
@ -57,8 +55,12 @@ ATVDemod::~ATVDemod()
qDebug("ATVDemod::~ATVDemod");
m_deviceAPI->removeChannelSinkAPI(this);
m_deviceAPI->removeChannelSink(this);
if (m_basebandSink->isRunning()) {
stop();
}
delete m_basebandSink;
delete m_thread;
}
void ATVDemod::start()
@ -66,7 +68,8 @@ void ATVDemod::start()
qDebug("ATVDemod::start");
m_basebandSink->reset();
m_thread->start();
m_basebandSink->startWork();
m_thread.start();
// re-apply essential messages
@ -80,8 +83,9 @@ void ATVDemod::start()
void ATVDemod::stop()
{
qDebug("ATVDemod::stop");
m_thread->exit();
m_thread->wait();
m_basebandSink->stopWork();
m_thread.exit();
m_thread.wait();
}
void ATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)

View File

@ -20,6 +20,7 @@
#define INCLUDE_ATVDEMOD_H
#include <QElapsedTimer>
#include <QThread>
#include <vector>
#include "dsp/basebandsamplesink.h"
@ -30,7 +31,6 @@
#include "atvdemodbaseband.h"
class QThread;
class DeviceAPI;
class ATVDemod : public BasebandSampleSink, public ChannelAPI
@ -97,7 +97,7 @@ public:
private:
DeviceAPI* m_deviceAPI;
QThread *m_thread;
QThread m_thread;
ATVDemodBaseband* m_basebandSink;
ATVDemodSettings m_settings;
qint64 m_centerFrequency; //!< center frequency stored from device message used when starting baseband sink

View File

@ -26,21 +26,12 @@
MESSAGE_CLASS_DEFINITION(ATVDemodBaseband::MsgConfigureATVDemodBaseband, Message)
ATVDemodBaseband::ATVDemodBaseband() :
m_running(false),
m_mutex(QMutex::Recursive)
{
qDebug("ATVDemodBaseband::ATVDemodBaseband");
m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000));
m_channelizer = new DownChannelizer(&m_sink);
QObject::connect(
&m_sampleFifo,
&SampleSinkFifo::dataReady,
this,
&ATVDemodBaseband::handleData,
Qt::QueuedConnection
);
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
}
ATVDemodBaseband::~ATVDemodBaseband()
@ -55,6 +46,34 @@ void ATVDemodBaseband::reset()
m_sampleFifo.reset();
}
void ATVDemodBaseband::startWork()
{
QMutexLocker mutexLocker(&m_mutex);
QObject::connect(
&m_sampleFifo,
&SampleSinkFifo::dataReady,
this,
&ATVDemodBaseband::handleData,
Qt::QueuedConnection
);
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
m_running = true;
}
void ATVDemodBaseband::stopWork()
{
QMutexLocker mutexLocker(&m_mutex);
disconnect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
QObject::disconnect(
&m_sampleFifo,
&SampleSinkFifo::dataReady,
this,
&ATVDemodBaseband::handleData
);
m_running = false;
}
void ATVDemodBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
{
m_sampleFifo.write(begin, end);

View File

@ -59,6 +59,8 @@ public:
ATVDemodBaseband();
~ATVDemodBaseband();
void reset();
void startWork();
void stopWork();
void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end);
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication
int getChannelSampleRate() const;
@ -68,6 +70,7 @@ public:
bool getBFOLocked() { return m_sink.getBFOLocked(); }
void setVideoTabIndex(int videoTabIndex) { m_sink.setVideoTabIndex(videoTabIndex); }
void setBasebandSampleRate(int sampleRate); //!< To be used when supporting thread is stopped
bool isRunning() const { return m_running; }
private:
SampleSinkFifo m_sampleFifo;
@ -75,6 +78,7 @@ private:
ATVDemodSink m_sink;
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
ATVDemodSettings m_settings;
bool m_running;
QMutex m_mutex;
bool handleMessage(const Message& cmd);