mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-06 07:07:48 -04:00
SDRdaemonSink: added the thread worker class
This commit is contained in:
parent
8b703a1302
commit
edc0c3d47c
@ -5,7 +5,7 @@ set(sdrdaemonsink_SOURCES
|
|||||||
# sdrdaemonsinkoutput.cpp
|
# sdrdaemonsinkoutput.cpp
|
||||||
# sdrdaemonsinkplugin.cpp
|
# sdrdaemonsinkplugin.cpp
|
||||||
sdrdaemonsinksettings.cpp
|
sdrdaemonsinksettings.cpp
|
||||||
# sdrdaemonsinkthread.cpp
|
sdrdaemonsinkthread.cpp
|
||||||
udpsinkfec.cpp
|
udpsinkfec.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ set(sdrdaemonsink_HEADERS
|
|||||||
# sdrdaemonsinkoutput.h
|
# sdrdaemonsinkoutput.h
|
||||||
# sdrdaemonsinkplugin.h
|
# sdrdaemonsinkplugin.h
|
||||||
sdrdaemonsinksettings.h
|
sdrdaemonsinksettings.h
|
||||||
# sdrdaemonsinkthread.h
|
sdrdaemonsinkthread.h
|
||||||
udpsinkfec.h
|
udpsinkfec.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,19 +26,14 @@
|
|||||||
SDRdaemonSinkThread::SDRdaemonSinkThread(std::ofstream *samplesStream, SampleSourceFifo* sampleFifo, QObject* parent) :
|
SDRdaemonSinkThread::SDRdaemonSinkThread(std::ofstream *samplesStream, SampleSourceFifo* sampleFifo, QObject* parent) :
|
||||||
QThread(parent),
|
QThread(parent),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
m_ofstream(samplesStream),
|
|
||||||
m_bufsize(0),
|
|
||||||
m_samplesChunkSize(0),
|
m_samplesChunkSize(0),
|
||||||
m_sampleFifo(sampleFifo),
|
m_sampleFifo(sampleFifo),
|
||||||
m_samplesCount(0),
|
m_samplesCount(0),
|
||||||
m_samplerate(0),
|
m_samplerate(0),
|
||||||
m_log2Interpolation(0),
|
|
||||||
m_throttlems(SDRDAEMONSINK_THROTTLE_MS),
|
m_throttlems(SDRDAEMONSINK_THROTTLE_MS),
|
||||||
m_throttleToggle(false),
|
m_throttleToggle(false),
|
||||||
m_buf(0),
|
|
||||||
m_maxThrottlems(50)
|
m_maxThrottlems(50)
|
||||||
{
|
{
|
||||||
assert(m_ofstream != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDRdaemonSinkThread::~SDRdaemonSinkThread()
|
SDRdaemonSinkThread::~SDRdaemonSinkThread()
|
||||||
@ -46,17 +41,11 @@ SDRdaemonSinkThread::~SDRdaemonSinkThread()
|
|||||||
if (m_running) {
|
if (m_running) {
|
||||||
stopWork();
|
stopWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_buf) delete[] m_buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRdaemonSinkThread::startWork()
|
void SDRdaemonSinkThread::startWork()
|
||||||
{
|
{
|
||||||
qDebug() << "SDRdaemonSinkThread::startWork: ";
|
qDebug() << "SDRdaemonSinkThread::startWork: ";
|
||||||
|
|
||||||
if (m_ofstream->is_open())
|
|
||||||
{
|
|
||||||
qDebug() << "SDRdaemonSinkThread::startWork: file stream open, starting...";
|
|
||||||
m_maxThrottlems = 0;
|
m_maxThrottlems = 0;
|
||||||
m_startWaitMutex.lock();
|
m_startWaitMutex.lock();
|
||||||
m_elapsedTimer.start();
|
m_elapsedTimer.start();
|
||||||
@ -65,11 +54,6 @@ void SDRdaemonSinkThread::startWork()
|
|||||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||||
m_startWaitMutex.unlock();
|
m_startWaitMutex.unlock();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "SDRdaemonSinkThread::startWork: file stream closed, not starting.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDRdaemonSinkThread::stopWork()
|
void SDRdaemonSinkThread::stopWork()
|
||||||
{
|
{
|
||||||
@ -99,10 +83,6 @@ void SDRdaemonSinkThread::setSamplerate(int samplerate)
|
|||||||
m_sampleFifo->resize(samplerate); // 1s buffer
|
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_samplerate = samplerate;
|
||||||
m_samplesChunkSize = (m_samplerate * m_throttlems) / 1000;
|
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()
|
void SDRdaemonSinkThread::run()
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
@ -191,7 +138,8 @@ void SDRdaemonSinkThread::tick()
|
|||||||
SampleVector::iterator beginRead = readUntil - m_samplesChunkSize;
|
SampleVector::iterator beginRead = readUntil - m_samplesChunkSize;
|
||||||
m_samplesCount += 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
|
// interpolation is done on the far side
|
||||||
// if (m_log2Interpolation == 0)
|
// if (m_log2Interpolation == 0)
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#include "dsp/inthalfbandfilter.h"
|
#include "dsp/inthalfbandfilter.h"
|
||||||
#include "dsp/interpolators.h"
|
#include "dsp/interpolators.h"
|
||||||
|
|
||||||
|
#include "udpsinkfec.h"
|
||||||
|
|
||||||
#define SDRDAEMONSINK_THROTTLE_MS 50
|
#define SDRDAEMONSINK_THROTTLE_MS 50
|
||||||
|
|
||||||
class SampleSourceFifo;
|
class SampleSourceFifo;
|
||||||
@ -44,8 +46,10 @@ public:
|
|||||||
void startWork();
|
void startWork();
|
||||||
void stopWork();
|
void stopWork();
|
||||||
void setSamplerate(int samplerate);
|
void setSamplerate(int samplerate);
|
||||||
void setLog2Interpolation(int log2Interpolation);
|
|
||||||
void setBuffer(std::size_t chunksize);
|
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; }
|
bool isRunning() const { return m_running; }
|
||||||
std::size_t getSamplesCount() const { return m_samplesCount; }
|
std::size_t getSamplesCount() const { return m_samplesCount; }
|
||||||
void setSamplesCount(int samplesCount) { m_samplesCount = samplesCount; }
|
void setSamplesCount(int samplesCount) { m_samplesCount = samplesCount; }
|
||||||
@ -57,21 +61,17 @@ private:
|
|||||||
QWaitCondition m_startWaiter;
|
QWaitCondition m_startWaiter;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
|
|
||||||
std::ofstream* m_ofstream;
|
|
||||||
std::size_t m_bufsize;
|
|
||||||
unsigned int m_samplesChunkSize;
|
unsigned int m_samplesChunkSize;
|
||||||
SampleSourceFifo* m_sampleFifo;
|
SampleSourceFifo* m_sampleFifo;
|
||||||
std::size_t m_samplesCount;
|
std::size_t m_samplesCount;
|
||||||
|
|
||||||
int m_samplerate;
|
int m_samplerate;
|
||||||
int m_log2Interpolation;
|
|
||||||
int m_throttlems;
|
int m_throttlems;
|
||||||
int m_maxThrottlems;
|
int m_maxThrottlems;
|
||||||
QElapsedTimer m_elapsedTimer;
|
QElapsedTimer m_elapsedTimer;
|
||||||
bool m_throttleToggle;
|
bool m_throttleToggle;
|
||||||
|
|
||||||
Interpolators<qint16, SDR_SAMP_SZ, 16> m_interpolators;
|
UDPSinkFEC m_udpSinkFEC;
|
||||||
int16_t *m_buf;
|
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
@ -186,6 +186,12 @@ UDPSinkFECWorker::UDPSinkFECWorker() : m_remotePort(9090)
|
|||||||
|
|
||||||
UDPSinkFECWorker::~UDPSinkFECWorker()
|
UDPSinkFECWorker::~UDPSinkFECWorker()
|
||||||
{
|
{
|
||||||
|
Message* message;
|
||||||
|
|
||||||
|
while ((message = m_inputMessageQueue.pop()) != 0)
|
||||||
|
{
|
||||||
|
delete message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPSinkFECWorker::pushTxFrame(const UDPSinkFEC::SuperBlock *txBlocks,
|
void UDPSinkFECWorker::pushTxFrame(const UDPSinkFEC::SuperBlock *txBlocks,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user