2014-05-18 11:52:39 -04:00
|
|
|
#include <QThread>
|
2015-08-12 03:03:02 -04:00
|
|
|
#include <QDebug>
|
2014-05-18 11:52:39 -04:00
|
|
|
#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);
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
ThreadedSampleSink::~ThreadedSampleSink()
|
|
|
|
{
|
|
|
|
wait();
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void ThreadedSampleSink::start()
|
|
|
|
{
|
|
|
|
QThread::start();
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void ThreadedSampleSink::stop()
|
|
|
|
{
|
|
|
|
exit();
|
|
|
|
wait();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void ThreadedSampleSink::run()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
connect(&m_syncMessenger, SIGNAL(messageSent(const Message&)), this, SLOT(handleSynchronousMessages(const Message&)), Qt::QueuedConnection);
|
|
|
|
exec();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void ThreadedSampleSink::feed(SampleVector::const_iterator& begin, SampleVector::const_iterator& end, bool positiveOnly)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSink->feed(begin, end, positiveOnly);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool ThreadedSampleSink::sendWaitSink(const Message& cmd)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_syncMessenger.sendWait(cmd);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void ThreadedSampleSink::handleSynchronousMessages(const Message& message)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_sampleSink->handleMessage(message); // just delegate to the sink
|
|
|
|
m_syncMessenger.done();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
QString ThreadedSampleSink::getSampleSinkObjectName() const
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
return m_sampleSink->objectName();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
|
|
|
|
/*
|
2014-05-18 11:52:39 -04:00
|
|
|
void ThreadedSampleSink::handleData()
|
|
|
|
{
|
2014-06-15 04:32:25 -04:00
|
|
|
bool positiveOnly = false;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
|
|
|
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) {
|
2014-05-18 11:52:39 -04:00
|
|
|
// 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);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
// 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);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
}*/
|
2014-05-18 11:52:39 -04:00
|
|
|
|