1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-05 16:31:15 -05:00
sdrangel/sdrbase/dsp/threadedsamplesink.cpp

86 lines
1.9 KiB
C++
Raw Normal View History

#include <QThread>
#include <QDebug>
#include "dsp/threadedsamplesink.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()
{
QThread::start();
}
2015-08-17 02:29:34 -04:00
void ThreadedSampleSink::stop()
{
exit();
wait();
}
2015-08-17 02:29:34 -04:00
void ThreadedSampleSink::run()
{
2015-08-17 02:29:34 -04:00
connect(&m_syncMessenger, SIGNAL(messageSent(const Message&)), this, SLOT(handleSynchronousMessages(const Message&)), Qt::QueuedConnection);
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);
}
2015-08-17 02:29:34 -04:00
bool ThreadedSampleSink::sendWaitSink(const Message& cmd)
{
2015-08-17 02:29:34 -04:00
m_syncMessenger.sendWait(cmd);
}
2015-08-17 02:29:34 -04:00
void ThreadedSampleSink::handleSynchronousMessages(const Message& message)
{
2015-08-17 02:29:34 -04:00
m_sampleSink->handleMessage(message); // just delegate to the sink
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
}*/