1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-04-04 18:48:34 -04:00

SDRdaemonSink: added the thread worker class

This commit is contained in:
f4exb 2017-05-21 04:41:47 +02:00
parent 8b703a1302
commit edc0c3d47c
4 changed files with 23 additions and 69 deletions

View File

@ -5,7 +5,7 @@ set(sdrdaemonsink_SOURCES
# sdrdaemonsinkoutput.cpp
# sdrdaemonsinkplugin.cpp
sdrdaemonsinksettings.cpp
# sdrdaemonsinkthread.cpp
sdrdaemonsinkthread.cpp
udpsinkfec.cpp
)
@ -14,7 +14,7 @@ set(sdrdaemonsink_HEADERS
# sdrdaemonsinkoutput.h
# sdrdaemonsinkplugin.h
sdrdaemonsinksettings.h
# sdrdaemonsinkthread.h
sdrdaemonsinkthread.h
udpsinkfec.h
)

View File

@ -26,19 +26,14 @@
SDRdaemonSinkThread::SDRdaemonSinkThread(std::ofstream *samplesStream, SampleSourceFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
m_ofstream(samplesStream),
m_bufsize(0),
m_samplesChunkSize(0),
m_sampleFifo(sampleFifo),
m_samplesCount(0),
m_samplerate(0),
m_log2Interpolation(0),
m_throttlems(SDRDAEMONSINK_THROTTLE_MS),
m_throttleToggle(false),
m_buf(0),
m_maxThrottlems(50)
{
assert(m_ofstream != 0);
}
SDRdaemonSinkThread::~SDRdaemonSinkThread()
@ -46,29 +41,18 @@ SDRdaemonSinkThread::~SDRdaemonSinkThread()
if (m_running) {
stopWork();
}
if (m_buf) delete[] m_buf;
}
void SDRdaemonSinkThread::startWork()
{
qDebug() << "SDRdaemonSinkThread::startWork: ";
if (m_ofstream->is_open())
{
qDebug() << "SDRdaemonSinkThread::startWork: file stream open, starting...";
m_maxThrottlems = 0;
m_startWaitMutex.lock();
m_elapsedTimer.start();
start();
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();
}
else
{
qDebug() << "SDRdaemonSinkThread::startWork: file stream closed, not starting.";
}
m_maxThrottlems = 0;
m_startWaitMutex.lock();
m_elapsedTimer.start();
start();
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();
}
void SDRdaemonSinkThread::stopWork()
@ -99,10 +83,6 @@ void SDRdaemonSinkThread::setSamplerate(int samplerate)
m_sampleFifo->resize(samplerate); // 1s buffer
}
// resize output buffer
if (m_buf) delete[] m_buf;
m_buf = new int16_t[samplerate*(1<<m_log2Interpolation)*2];
m_samplerate = samplerate;
m_samplesChunkSize = (m_samplerate * m_throttlems) / 1000;
@ -112,39 +92,6 @@ void SDRdaemonSinkThread::setSamplerate(int samplerate)
}
}
void SDRdaemonSinkThread::setLog2Interpolation(int log2Interpolation)
{
if ((log2Interpolation < 0) || (log2Interpolation > 6))
{
return;
}
if (log2Interpolation != m_log2Interpolation)
{
qDebug() << "SDRdaemonSinkThread::setLog2Interpolation:"
<< " new:" << log2Interpolation
<< " old:" << m_log2Interpolation;
bool wasRunning = false;
if (m_running)
{
stopWork();
wasRunning = true;
}
// resize output buffer
if (m_buf) delete[] m_buf;
m_buf = new int16_t[m_samplerate*(1<<log2Interpolation)*2];
m_log2Interpolation = log2Interpolation;
if (wasRunning) {
startWork();
}
}
}
void SDRdaemonSinkThread::run()
{
int res;
@ -191,7 +138,8 @@ void SDRdaemonSinkThread::tick()
SampleVector::iterator beginRead = readUntil - m_samplesChunkSize;
m_samplesCount += m_samplesChunkSize;
m_ofstream->write(reinterpret_cast<char*>(&(*beginRead)), m_samplesChunkSize*sizeof(Sample)); // send samples
m_udpSinkFEC.write(beginRead, m_samplesChunkSize);
// m_ofstream->write(reinterpret_cast<char*>(&(*beginRead)), m_samplesChunkSize*sizeof(Sample)); // send samples
// interpolation is done on the far side
// if (m_log2Interpolation == 0)

View File

@ -30,6 +30,8 @@
#include "dsp/inthalfbandfilter.h"
#include "dsp/interpolators.h"
#include "udpsinkfec.h"
#define SDRDAEMONSINK_THROTTLE_MS 50
class SampleSourceFifo;
@ -44,8 +46,10 @@ public:
void startWork();
void stopWork();
void setSamplerate(int samplerate);
void setLog2Interpolation(int log2Interpolation);
void setBuffer(std::size_t chunksize);
void setNbBlocksFEC(uint32_t nbBlocksFEC) { m_udpSinkFEC.setNbBlocksFEC(nbBlocksFEC); };
void setTxDelay(uint32_t txDelay) { m_udpSinkFEC.setTxDelay(txDelay); };
void setRemoteAddress(const QString& address, uint16_t port) { m_udpSinkFEC.setRemoteAddress(address, port); }
bool isRunning() const { return m_running; }
std::size_t getSamplesCount() const { return m_samplesCount; }
void setSamplesCount(int samplesCount) { m_samplesCount = samplesCount; }
@ -57,21 +61,17 @@ private:
QWaitCondition m_startWaiter;
bool m_running;
std::ofstream* m_ofstream;
std::size_t m_bufsize;
unsigned int m_samplesChunkSize;
SampleSourceFifo* m_sampleFifo;
std::size_t m_samplesCount;
int m_samplerate;
int m_log2Interpolation;
int m_throttlems;
int m_maxThrottlems;
QElapsedTimer m_elapsedTimer;
bool m_throttleToggle;
Interpolators<qint16, SDR_SAMP_SZ, 16> m_interpolators;
int16_t *m_buf;
UDPSinkFEC m_udpSinkFEC;
void run();

View File

@ -186,6 +186,12 @@ UDPSinkFECWorker::UDPSinkFECWorker() : m_remotePort(9090)
UDPSinkFECWorker::~UDPSinkFECWorker()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
delete message;
}
}
void UDPSinkFECWorker::pushTxFrame(const UDPSinkFEC::SuperBlock *txBlocks,