1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-18 06:11:46 -05:00
sdrangel/sdrbase/dsp/threadedsamplesink.cpp

96 lines
2.3 KiB
C++
Raw Normal View History

#include <QThread>
#include <QDebug>
#include "dsp/threadedsamplesink.h"
#include "dsp/dspcommands.h"
#include "util/message.h"
ThreadedSampleSink::ThreadedSampleSink(SampleSink* sampleSink) :
m_sampleSink(sampleSink)
{
2015-08-17 02:29:34 -04:00
moveToThread(this);
}
2015-08-17 02:29:34 -04:00
ThreadedSampleSink::~ThreadedSampleSink()
{
wait();
}
2015-08-17 02:29:34 -04:00
void ThreadedSampleSink::start()
{
qDebug() << "ThreadedSampleSink::start";
DSPPing cmd;
2015-08-17 02:29:34 -04:00
QThread::start();
m_syncMessenger.sendWait(cmd);
2015-08-17 02:29:34 -04:00
}
2015-08-17 02:29:34 -04:00
void ThreadedSampleSink::stop()
{
qDebug() << "ThreadedSampleSink::stop";
2015-08-17 02:29:34 -04:00
exit();
wait();
}
2015-08-17 02:29:34 -04:00
void ThreadedSampleSink::run()
{
qDebug() << "ThreadedSampleSink::run";
connect(&m_syncMessenger, SIGNAL(messageSent()), this, SLOT(handleSynchronousMessages()), Qt::QueuedConnection);
m_syncMessenger.done(); // Release start() that is waiting in calling trhead
2015-08-17 02:29:34 -04:00
exec();
}
2015-08-17 02:29:34 -04:00
void ThreadedSampleSink::feed(SampleVector::const_iterator& begin, SampleVector::const_iterator& end, bool positiveOnly)
{
2015-08-17 02:29:34 -04:00
m_sampleSink->feed(begin, end, positiveOnly);
}
bool ThreadedSampleSink::sendWaitSink(Message& cmd)
{
2015-08-17 02:29:34 -04:00
m_syncMessenger.sendWait(cmd);
}
void ThreadedSampleSink::handleSynchronousMessages()
{
qDebug() << "ThreadedSampleSink::handleSynchronousMessages";
Message *message = m_syncMessenger.getMessage();
qDebug() << " - message: " << message->getIdentifier();
m_sampleSink->handleMessage(*message); // just delegate to the sink
2015-08-17 02:29:34 -04:00
m_syncMessenger.done();
}
2015-08-17 02:29:34 -04:00
QString ThreadedSampleSink::getSampleSinkObjectName() const
{
2015-08-17 02:29:34 -04:00
return m_sampleSink->objectName();
}
2015-08-17 02:29:34 -04:00
/*
void ThreadedSampleSink::handleData()
{
2014-06-15 04:32:25 -04:00
bool positiveOnly = false;
while((m_sampleFifo.fill() > 0) && (m_messageQueue.countPending() == 0)) {
SampleVector::iterator part1begin;
SampleVector::iterator part1end;
SampleVector::iterator part2begin;
SampleVector::iterator part2end;
size_t count = m_sampleFifo.readBegin(m_sampleFifo.fill(), &part1begin, &part1end, &part2begin, &part2end);
// first part of FIFO data
2014-11-21 10:41:58 -05:00
if(count > 0) {
// handle data
if(m_sampleSink != NULL)
2014-06-15 04:32:25 -04:00
m_sampleSink->feed(part1begin, part1end, positiveOnly);
2014-07-03 04:45:14 -04:00
m_sampleFifo.readCommit(part1end - part1begin);
}
// second part of FIFO data (used when block wraps around)
if(part2begin != part2end) {
// handle data
if(m_sampleSink != NULL)
2014-06-15 04:32:25 -04:00
m_sampleSink->feed(part2begin, part2end, positiveOnly);
2014-07-03 04:45:14 -04:00
m_sampleFifo.readCommit(part2end - part2begin);
}
}
2015-08-17 02:29:34 -04:00
}*/