1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-15 21:01:45 -05:00

Only run sink worker thread during acqusition

This commit is contained in:
Jon Beniston 2020-11-06 22:33:16 +00:00
parent a5ce12ffab
commit c2dc5808a6
5 changed files with 40 additions and 6 deletions

View File

@ -112,6 +112,7 @@ void ADSBDemod::start()
m_worker->reset(); m_worker->reset();
m_worker->startWork(); m_worker->startWork();
m_basebandSink->reset(); m_basebandSink->reset();
m_basebandSink->startWork();
m_thread->start(); m_thread->start();
ADSBDemodWorker::MsgConfigureADSBDemodWorker *msg = ADSBDemodWorker::MsgConfigureADSBDemodWorker::create(m_settings, true); ADSBDemodWorker::MsgConfigureADSBDemodWorker *msg = ADSBDemodWorker::MsgConfigureADSBDemodWorker::create(m_settings, true);
@ -121,6 +122,7 @@ void ADSBDemod::start()
void ADSBDemod::stop() void ADSBDemod::stop()
{ {
qDebug() << "ADSBDemod::stop"; qDebug() << "ADSBDemod::stop";
m_basebandSink->stopWork();
m_worker->stopWork(); m_worker->stopWork();
m_thread->exit(); m_thread->exit();
m_thread->wait(); m_thread->wait();

View File

@ -56,6 +56,16 @@ void ADSBDemodBaseband::reset()
m_sampleFifo.reset(); m_sampleFifo.reset();
} }
void ADSBDemodBaseband::startWork()
{
m_sink.startWorker();
}
void ADSBDemodBaseband::stopWork()
{
m_sink.stopWorker();
}
void ADSBDemodBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) void ADSBDemodBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
{ {
m_sampleFifo.write(begin, end); m_sampleFifo.write(begin, end);

View File

@ -60,6 +60,8 @@ public:
ADSBDemodBaseband(); ADSBDemodBaseband();
~ADSBDemodBaseband(); ~ADSBDemodBaseband();
void reset(); void reset();
void startWork();
void stopWork();
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;

View File

@ -55,7 +55,6 @@ ADSBDemodSink::ADSBDemodSink() :
ADSBDemodSink::~ADSBDemodSink() ADSBDemodSink::~ADSBDemodSink()
{ {
stopWorker();
for (int i = 0; i < m_buffers; i++) for (int i = 0; i < m_buffers; i++)
delete m_sampleBuffer[i]; delete m_sampleBuffer[i];
} }
@ -140,7 +139,8 @@ void ADSBDemodSink::processOneSample(Real magsq)
boost::chrono::duration<double> sec = boost::chrono::steady_clock::now() - m_startPoint; boost::chrono::duration<double> sec = boost::chrono::steady_clock::now() - m_startPoint;
m_feedTime += sec.count(); m_feedTime += sec.count();
m_bufferWrite[m_writeBuffer].acquire(); if (m_worker.isRunning())
m_bufferWrite[m_writeBuffer].acquire();
m_startPoint = boost::chrono::steady_clock::now(); m_startPoint = boost::chrono::steady_clock::now();
@ -148,6 +148,13 @@ void ADSBDemodSink::processOneSample(Real magsq)
} }
} }
void ADSBDemodSink::startWorker()
{
qDebug() << "ADSBDemodSink::startWorker";
if (!m_worker.isRunning())
m_worker.start();
}
void ADSBDemodSink::stopWorker() void ADSBDemodSink::stopWorker()
{ {
if (m_worker.isRunning()) if (m_worker.isRunning())
@ -161,14 +168,25 @@ void ADSBDemodSink::stopWorker()
m_bufferRead[i].release(1); m_bufferRead[i].release(1);
} }
m_worker.wait(); m_worker.wait();
// If this is called from ADSBDemod, we need to also
// make sure baseband sink thread isnt blocked in processOneSample
for (int i = 0; i < m_buffers; i++)
{
if (m_bufferWrite[i].available() == 0)
m_bufferWrite[i].release(1);
}
qDebug() << "ADSBDemodSink::stopWorker: Worker stopped"; qDebug() << "ADSBDemodSink::stopWorker: Worker stopped";
} }
} }
void ADSBDemodSink::init(int samplesPerBit) void ADSBDemodSink::init(int samplesPerBit)
{ {
// Stop worker as we're going to delete the buffers bool restart = m_worker.isRunning();
stopWorker(); if (restart)
{
// Stop worker as we're going to delete the buffers
stopWorker();
}
// Reset state of semaphores // Reset state of semaphores
for (int i = 0; i < m_buffers; i++) for (int i = 0; i < m_buffers; i++)
{ {
@ -192,7 +210,8 @@ void ADSBDemodSink::init(int samplesPerBit)
for (int i = 0; i < m_buffers; i++) for (int i = 0; i < m_buffers; i++)
m_sampleBuffer[i] = new Real[m_bufferSize]; m_sampleBuffer[i] = new Real[m_bufferSize];
m_worker.start(); if (restart)
startWorker();
} }
void ADSBDemodSink::applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force) void ADSBDemodSink::applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force)

View File

@ -60,6 +60,8 @@ public:
void applySettings(const ADSBDemodSettings& settings, bool force = false); void applySettings(const ADSBDemodSettings& settings, bool force = false);
void setMessageQueueToGUI(MessageQueue *messageQueue) { m_messageQueueToGUI = messageQueue; } void setMessageQueueToGUI(MessageQueue *messageQueue) { m_messageQueueToGUI = messageQueue; }
void setMessageQueueToWorker(MessageQueue *messageQueue) { m_messageQueueToWorker = messageQueue; } void setMessageQueueToWorker(MessageQueue *messageQueue) { m_messageQueueToWorker = messageQueue; }
void startWorker();
void stopWorker();
private: private:
friend ADSBDemodSinkWorker; friend ADSBDemodSinkWorker;
@ -113,7 +115,6 @@ private:
MessageQueue *m_messageQueueToWorker; MessageQueue *m_messageQueueToWorker;
void init(int samplesPerBit); void init(int samplesPerBit);
void stopWorker();
Real inline complexMagSq(Complex& ci) Real inline complexMagSq(Complex& ci)
{ {
double magsqRaw = ci.real()*ci.real() + ci.imag()*ci.imag(); double magsqRaw = ci.real()*ci.real() + ci.imag()*ci.imag();