SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
RemoteOutputThread Class Reference

#include <remoteoutputthread.h>

Inherits QThread.

+ Collaboration diagram for RemoteOutputThread:

Public Member Functions

 RemoteOutputThread (SampleSourceFifo *sampleFifo, QObject *parent=0)
 
 ~RemoteOutputThread ()
 
void startWork ()
 
void stopWork ()
 
void setSamplerate (int samplerate)
 
void setNbBlocksFEC (uint32_t nbBlocksFEC)
 
void setTxDelay (float txDelay)
 
void setDataAddress (const QString &address, uint16_t port)
 
bool isRunning () const
 
uint32_t getSamplesCount (uint64_t &ts_usecs) const
 
void setSamplesCount (int samplesCount)
 
void setChunkCorrection (int chunkCorrection)
 
void connectTimer (const QTimer &timer)
 

Private Slots

void tick ()
 

Private Member Functions

void run ()
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
volatile bool m_running
 
int m_samplesChunkSize
 
SampleSourceFifom_sampleFifo
 
uint32_t m_samplesCount
 
int m_chunkCorrection
 
int m_samplerate
 
int m_throttlems
 
int m_maxThrottlems
 
QElapsedTimer m_elapsedTimer
 
bool m_throttleToggle
 
UDPSinkFEC m_udpSinkFEC
 

Detailed Description

Definition at line 42 of file remoteoutputthread.h.

Constructor & Destructor Documentation

◆ RemoteOutputThread()

RemoteOutputThread::RemoteOutputThread ( SampleSourceFifo sampleFifo,
QObject *  parent = 0 
)

Definition at line 28 of file remoteoutputthread.cpp.

28  :
29  QThread(parent),
30  m_running(false),
32  m_sampleFifo(sampleFifo),
33  m_samplesCount(0),
35  m_samplerate(0),
37  m_maxThrottlems(50),
38  m_throttleToggle(false)
39 {
40 }
volatile bool m_running
SampleSourceFifo * m_sampleFifo
#define REMOTEOUTPUT_THROTTLE_MS

◆ ~RemoteOutputThread()

RemoteOutputThread::~RemoteOutputThread ( )

Definition at line 42 of file remoteoutputthread.cpp.

References m_running, and stopWork().

43 {
44  if (m_running) {
45  stopWork();
46  }
47 }
volatile bool m_running
+ Here is the call graph for this function:

Member Function Documentation

◆ connectTimer()

void RemoteOutputThread::connectTimer ( const QTimer &  timer)

Definition at line 114 of file remoteoutputthread.cpp.

References tick().

Referenced by setChunkCorrection(), and RemoteOutput::start().

115 {
116  qDebug() << "RemoteOutputThread::connectTimer";
117  connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
118 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSamplesCount()

uint32_t RemoteOutputThread::getSamplesCount ( uint64_t ts_usecs) const

Definition at line 144 of file remoteoutputthread.cpp.

References m_samplesCount, and TimeUtil::nowus().

Referenced by RemoteOutput::analyzeApiReply(), isRunning(), and RemoteOutput::webapiFormatDeviceReport().

145 {
146  ts_usecs = TimeUtil::nowus();
147  return m_samplesCount;
148 }
static uint64_t nowus()
returns the current epoch in microseconds
Definition: timeutil.cpp:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRunning()

bool RemoteOutputThread::isRunning ( ) const
inline

Definition at line 57 of file remoteoutputthread.h.

References getSamplesCount(), and m_running.

57 { return m_running; }
volatile bool m_running
+ Here is the call graph for this function:

◆ run()

void RemoteOutputThread::run ( )
private

Definition at line 101 of file remoteoutputthread.cpp.

References m_running, and m_startWaiter.

102 {
103  m_running = true;
104  m_startWaiter.wakeAll();
105 
106  while(m_running) // actual work is in the tick() function
107  {
108  sleep(1);
109  }
110 
111  m_running = false;
112 }
volatile bool m_running
QWaitCondition m_startWaiter

◆ setChunkCorrection()

void RemoteOutputThread::setChunkCorrection ( int  chunkCorrection)
inline

Definition at line 61 of file remoteoutputthread.h.

References connectTimer(), and m_chunkCorrection.

Referenced by RemoteOutput::handleMessage().

61 { m_chunkCorrection = chunkCorrection; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDataAddress()

void RemoteOutputThread::setDataAddress ( const QString &  address,
uint16_t  port 
)
inline

Definition at line 55 of file remoteoutputthread.h.

References m_udpSinkFEC, and UDPSinkFEC::setRemoteAddress().

Referenced by RemoteOutput::applySettings(), and RemoteOutput::start().

55 { m_udpSinkFEC.setRemoteAddress(address, port); }
void setRemoteAddress(const QString &address, uint16_t port)
Definition: udpsinkfec.cpp:101
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setNbBlocksFEC()

void RemoteOutputThread::setNbBlocksFEC ( uint32_t  nbBlocksFEC)
inline

Definition at line 53 of file remoteoutputthread.h.

References m_udpSinkFEC, and UDPSinkFEC::setNbBlocksFEC().

Referenced by RemoteOutput::applySettings(), and RemoteOutput::start().

53 { m_udpSinkFEC.setNbBlocksFEC(nbBlocksFEC); };
void setNbBlocksFEC(uint32_t nbBlocksFEC)
Definition: udpsinkfec.cpp:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSamplerate()

void RemoteOutputThread::setSamplerate ( int  samplerate)

Definition at line 70 of file remoteoutputthread.cpp.

References m_running, m_sampleFifo, m_samplerate, m_samplesChunkSize, m_throttlems, m_udpSinkFEC, SampleSourceFifo::resize(), UDPSinkFEC::setSampleRate(), startWork(), and stopWork().

Referenced by RemoteOutput::applySettings(), and RemoteOutput::start().

71 {
72  if (samplerate != m_samplerate)
73  {
74  qDebug() << "RemoteOutputThread::setSamplerate:"
75  << " new:" << samplerate
76  << " old:" << m_samplerate;
77 
78  bool wasRunning = false;
79 
80  if (m_running)
81  {
82  stopWork();
83  wasRunning = true;
84  }
85 
86  // resize sample FIFO
87  if (m_sampleFifo) {
88  m_sampleFifo->resize(samplerate); // 1s buffer
89  }
90 
91  m_samplerate = samplerate;
92  m_samplesChunkSize = (m_samplerate * m_throttlems) / 1000;
93  m_udpSinkFEC.setSampleRate(m_samplerate);
94 
95  if (wasRunning) {
96  startWork();
97  }
98  }
99 }
volatile bool m_running
SampleSourceFifo * m_sampleFifo
void resize(uint32_t size)
void setSampleRate(uint32_t sampleRate)
Definition: udpsinkfec.cpp:94
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSamplesCount()

void RemoteOutputThread::setSamplesCount ( int  samplesCount)
inline

Definition at line 60 of file remoteoutputthread.h.

References m_samplesCount.

60 { m_samplesCount = samplesCount; }

◆ setTxDelay()

void RemoteOutputThread::setTxDelay ( float  txDelay)
inline

Definition at line 54 of file remoteoutputthread.h.

References m_udpSinkFEC, and UDPSinkFEC::setTxDelay().

Referenced by RemoteOutput::applySettings(), and RemoteOutput::start().

54 { m_udpSinkFEC.setTxDelay(txDelay); };
void setTxDelay(float txDelayRatio)
Definition: udpsinkfec.cpp:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startWork()

void RemoteOutputThread::startWork ( )

Definition at line 49 of file remoteoutputthread.cpp.

References m_elapsedTimer, m_maxThrottlems, m_running, m_startWaiter, m_startWaitMutex, m_udpSinkFEC, and UDPSinkFEC::start().

Referenced by RemoteOutput::handleMessage(), setSamplerate(), and RemoteOutput::start().

50 {
51  qDebug() << "RemoteOutputThread::startWork: ";
53  m_maxThrottlems = 0;
54  m_startWaitMutex.lock();
55  m_elapsedTimer.start();
56  start();
57  while(!m_running)
58  m_startWaiter.wait(&m_startWaitMutex, 100);
59  m_startWaitMutex.unlock();
60 }
volatile bool m_running
void start()
Definition: udpsinkfec.cpp:57
QWaitCondition m_startWaiter
QElapsedTimer m_elapsedTimer
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stopWork()

void RemoteOutputThread::stopWork ( )

Definition at line 62 of file remoteoutputthread.cpp.

References m_running, m_udpSinkFEC, and UDPSinkFEC::stop().

Referenced by RemoteOutput::handleMessage(), setSamplerate(), RemoteOutput::stop(), and ~RemoteOutputThread().

63 {
64  qDebug() << "RemoteOutputThread::stopWork";
65  m_running = false;
66  wait();
68 }
void stop()
Definition: udpsinkfec.cpp:64
volatile bool m_running
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tick

void RemoteOutputThread::tick ( )
privateslot

Definition at line 120 of file remoteoutputthread.cpp.

References m_chunkCorrection, m_elapsedTimer, m_running, m_sampleFifo, m_samplerate, m_samplesChunkSize, m_samplesCount, m_throttlems, m_throttleToggle, m_udpSinkFEC, SampleSourceFifo::readAdvance(), and UDPSinkFEC::write().

Referenced by connectTimer().

121 {
122  if (m_running)
123  {
124  qint64 throttlems = m_elapsedTimer.restart();
125 
126  if (throttlems != m_throttlems)
127  {
128  m_throttlems = throttlems;
132  }
133 
134  SampleVector::iterator readUntil;
135 
136  m_sampleFifo->readAdvance(readUntil, m_samplesChunkSize); // pull samples
137  SampleVector::iterator beginRead = readUntil - m_samplesChunkSize;
139 
140  m_udpSinkFEC.write(beginRead, m_samplesChunkSize);
141  }
142 }
void write(const SampleVector::iterator &begin, uint32_t sampleChunkSize)
Definition: udpsinkfec.cpp:112
volatile bool m_running
void readAdvance(SampleVector::iterator &readUntil, unsigned int nbSamples)
SampleSourceFifo * m_sampleFifo
QElapsedTimer m_elapsedTimer
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_chunkCorrection

int RemoteOutputThread::m_chunkCorrection
private

Definition at line 73 of file remoteoutputthread.h.

Referenced by setChunkCorrection(), and tick().

◆ m_elapsedTimer

QElapsedTimer RemoteOutputThread::m_elapsedTimer
private

Definition at line 78 of file remoteoutputthread.h.

Referenced by startWork(), and tick().

◆ m_maxThrottlems

int RemoteOutputThread::m_maxThrottlems
private

Definition at line 77 of file remoteoutputthread.h.

Referenced by startWork().

◆ m_running

volatile bool RemoteOutputThread::m_running
private

◆ m_sampleFifo

SampleSourceFifo* RemoteOutputThread::m_sampleFifo
private

Definition at line 71 of file remoteoutputthread.h.

Referenced by setSamplerate(), and tick().

◆ m_samplerate

int RemoteOutputThread::m_samplerate
private

Definition at line 75 of file remoteoutputthread.h.

Referenced by setSamplerate(), and tick().

◆ m_samplesChunkSize

int RemoteOutputThread::m_samplesChunkSize
private

Definition at line 70 of file remoteoutputthread.h.

Referenced by setSamplerate(), and tick().

◆ m_samplesCount

uint32_t RemoteOutputThread::m_samplesCount
private

Definition at line 72 of file remoteoutputthread.h.

Referenced by getSamplesCount(), setSamplesCount(), and tick().

◆ m_startWaiter

QWaitCondition RemoteOutputThread::m_startWaiter
private

Definition at line 67 of file remoteoutputthread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex RemoteOutputThread::m_startWaitMutex
private

Definition at line 66 of file remoteoutputthread.h.

Referenced by startWork().

◆ m_throttlems

int RemoteOutputThread::m_throttlems
private

Definition at line 76 of file remoteoutputthread.h.

Referenced by setSamplerate(), and tick().

◆ m_throttleToggle

bool RemoteOutputThread::m_throttleToggle
private

Definition at line 79 of file remoteoutputthread.h.

Referenced by tick().

◆ m_udpSinkFEC

UDPSinkFEC RemoteOutputThread::m_udpSinkFEC
private

The documentation for this class was generated from the following files: