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.
Classes | Public Slots | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
RemoteSinkThread Class Reference

#include <remotesinkthread.h>

Inherits QThread.

+ Collaboration diagram for RemoteSinkThread:

Classes

class  MsgStartStop
 

Public Slots

void processDataBlock (RemoteDataBlock *dataBlock)
 

Public Member Functions

 RemoteSinkThread (QObject *parent=0)
 
 ~RemoteSinkThread ()
 
void startStop (bool start)
 

Private Slots

void handleInputMessages ()
 

Private Member Functions

void startWork ()
 
void stopWork ()
 
void run ()
 
void handleDataBlock (RemoteDataBlock &dataBlock)
 

Private Attributes

QMutex m_startWaitMutex
 
QWaitCondition m_startWaiter
 
volatile bool m_running
 
CM256 m_cm256
 
CM256 * m_cm256p
 
QHostAddress m_address
 
QUdpSocket * m_socket
 
MessageQueue m_inputMessageQueue
 

Detailed Description

Definition at line 41 of file remotesinkthread.h.

Constructor & Destructor Documentation

◆ RemoteSinkThread()

RemoteSinkThread::RemoteSinkThread ( QObject *  parent = 0)

Definition at line 33 of file remotesinkthread.cpp.

Referenced by RemoteSinkThread::MsgStartStop::MsgStartStop().

33  :
34  QThread(parent),
35  m_running(false),
36  m_address(QHostAddress::LocalHost),
37  m_socket(0)
38 {
39 
40  m_cm256p = m_cm256.isInitialized() ? &m_cm256 : 0;
41  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
42 }
QUdpSocket * m_socket
QHostAddress m_address
MessageQueue m_inputMessageQueue
volatile bool m_running
+ Here is the caller graph for this function:

◆ ~RemoteSinkThread()

RemoteSinkThread::~RemoteSinkThread ( )

Definition at line 44 of file remotesinkthread.cpp.

Referenced by RemoteSinkThread::MsgStartStop::MsgStartStop().

45 {
46  qDebug("RemoteSinkThread::~RemoteSinkThread");
47 }
+ Here is the caller graph for this function:

Member Function Documentation

◆ handleDataBlock()

void RemoteSinkThread::handleDataBlock ( RemoteDataBlock dataBlock)
private

< Main interface with CM256 encoder

< Pointers to data for CM256 encoder

< FEC data

Definition at line 96 of file remotesinkthread.cpp.

References i, m_address, m_cm256p, RemoteTxControlBlock::m_dataAddress, RemoteTxControlBlock::m_dataPort, RemoteTxControlBlock::m_frameIndex, RemoteTxControlBlock::m_nbBlocksFEC, m_socket, RemoteDataBlock::m_superBlocks, RemoteDataBlock::m_txControlBlock, and RemoteTxControlBlock::m_txDelay.

Referenced by processDataBlock().

97 {
98  CM256::cm256_encoder_params cm256Params;
99  CM256::cm256_block descriptorBlocks[256];
100  RemoteProtectedBlock fecBlocks[256];
101 
102  uint16_t frameIndex = dataBlock.m_txControlBlock.m_frameIndex;
103  int nbBlocksFEC = dataBlock.m_txControlBlock.m_nbBlocksFEC;
104  int txDelay = dataBlock.m_txControlBlock.m_txDelay;
105  m_address.setAddress(dataBlock.m_txControlBlock.m_dataAddress);
106  uint16_t dataPort = dataBlock.m_txControlBlock.m_dataPort;
107  RemoteSuperBlock *txBlockx = dataBlock.m_superBlocks;
108 
109  if ((nbBlocksFEC == 0) || !m_cm256p) // Do not FEC encode
110  {
111  if (m_socket)
112  {
113  for (int i = 0; i < RemoteNbOrginalBlocks; i++)
114  {
115  // send block via UDP
116  m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) RemoteUdpSize, m_address, dataPort);
117  usleep(txDelay);
118  }
119  }
120  }
121  else
122  {
123  cm256Params.BlockBytes = sizeof(RemoteProtectedBlock);
124  cm256Params.OriginalCount = RemoteNbOrginalBlocks;
125  cm256Params.RecoveryCount = nbBlocksFEC;
126 
127  // Fill pointers to data
128  for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; ++i)
129  {
130  if (i >= cm256Params.OriginalCount) {
131  memset((void *) &txBlockx[i].m_protectedBlock, 0, sizeof(RemoteProtectedBlock));
132  }
133 
134  txBlockx[i].m_header.m_frameIndex = frameIndex;
135  txBlockx[i].m_header.m_blockIndex = i;
136  txBlockx[i].m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
138  descriptorBlocks[i].Block = (void *) &(txBlockx[i].m_protectedBlock);
139  descriptorBlocks[i].Index = txBlockx[i].m_header.m_blockIndex;
140  }
141 
142  // Encode FEC blocks
143  if (m_cm256p->cm256_encode(cm256Params, descriptorBlocks, fecBlocks))
144  {
145  qWarning("RemoteSinkThread::handleDataBlock: CM256 encode failed. No transmission.");
146  // TODO: send without FEC changing meta data to set indication of no FEC
147  }
148 
149  // Merge FEC with data to transmit
150  for (int i = 0; i < cm256Params.RecoveryCount; i++)
151  {
152  txBlockx[i + cm256Params.OriginalCount].m_protectedBlock = fecBlocks[i];
153  }
154 
155  // Transmit all blocks
156  if (m_socket)
157  {
158  for (int i = 0; i < cm256Params.OriginalCount + cm256Params.RecoveryCount; i++)
159  {
160  // send block via UDP
161  m_socket->writeDatagram((const char*)&txBlockx[i], (qint64 ) RemoteUdpSize, m_address, dataPort);
162  usleep(txDelay);
163  }
164  }
165  }
166 
167  dataBlock.m_txControlBlock.m_processed = true;
168 }
QUdpSocket * m_socket
RemoteSuperBlock * m_superBlocks
QHostAddress m_address
RemoteProtectedBlock m_protectedBlock
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
unsigned short uint16_t
Definition: rtptypes_win.h:44
uint8_t m_sampleBytes
number of bytes per sample (2 or 4) for this block
int32_t i
Definition: decimators.h:244
uint8_t m_blockIndex
RemoteTxControlBlock m_txControlBlock
RemoteHeader m_header
uint16_t m_frameIndex
uint8_t m_sampleBits
number of bits per sample
+ Here is the caller graph for this function:

◆ handleInputMessages

void RemoteSinkThread::handleInputMessages ( )
privateslot

Definition at line 170 of file remotesinkthread.cpp.

References RemoteSinkThread::MsgStartStop::getStartStop(), m_inputMessageQueue, Message::match(), MessageQueue::pop(), startWork(), and stopWork().

171 {
172  Message* message;
173 
174  while ((message = m_inputMessageQueue.pop()) != 0)
175  {
176  if (MsgStartStop::match(*message))
177  {
178  MsgStartStop* notif = (MsgStartStop*) message;
179  qDebug("RemoteSinkThread::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
180 
181  if (notif->getStartStop()) {
182  startWork();
183  } else {
184  stopWork();
185  }
186 
187  delete message;
188  }
189  }
190 }
Message * pop()
Pop message from queue.
MessageQueue m_inputMessageQueue
static bool match(const Message *message)
Definition: message.cpp:45
+ Here is the call graph for this function:

◆ processDataBlock

void RemoteSinkThread::processDataBlock ( RemoteDataBlock dataBlock)
slot

Definition at line 90 of file remotesinkthread.cpp.

References handleDataBlock().

Referenced by RemoteSinkThread::MsgStartStop::MsgStartStop().

91 {
92  handleDataBlock(*dataBlock);
93  delete dataBlock;
94 }
void handleDataBlock(RemoteDataBlock &dataBlock)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void RemoteSinkThread::run ( )
private

Definition at line 75 of file remotesinkthread.cpp.

References m_running, and m_startWaiter.

76 {
77  qDebug("RemoteSinkThread::run: begin");
78  m_running = true;
79  m_startWaiter.wakeAll();
80 
81  while (m_running)
82  {
83  sleep(1); // Do nothing as everything is in the data handler (dequeuer)
84  }
85 
86  m_running = false;
87  qDebug("RemoteSinkThread::run: end");
88 }
QWaitCondition m_startWaiter
volatile bool m_running

◆ startStop()

void RemoteSinkThread::startStop ( bool  start)

Definition at line 49 of file remotesinkthread.cpp.

References RemoteSinkThread::MsgStartStop::create(), m_inputMessageQueue, and MessageQueue::push().

Referenced by RemoteSinkThread::MsgStartStop::MsgStartStop(), RemoteSink::start(), and RemoteSink::stop().

50 {
51  MsgStartStop *msg = MsgStartStop::create(start);
53 }
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static MsgStartStop * create(bool startStop)
MessageQueue m_inputMessageQueue
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startWork()

void RemoteSinkThread::startWork ( )
private

Definition at line 55 of file remotesinkthread.cpp.

References m_running, m_socket, m_startWaiter, and m_startWaitMutex.

Referenced by handleInputMessages().

56 {
57  qDebug("RemoteSinkThread::startWork");
58  m_startWaitMutex.lock();
59  m_socket = new QUdpSocket(this);
60  start();
61  while(!m_running)
62  m_startWaiter.wait(&m_startWaitMutex, 100);
63  m_startWaitMutex.unlock();
64 }
QUdpSocket * m_socket
QWaitCondition m_startWaiter
volatile bool m_running
+ Here is the caller graph for this function:

◆ stopWork()

void RemoteSinkThread::stopWork ( )
private

Definition at line 66 of file remotesinkthread.cpp.

References m_running, and m_socket.

Referenced by handleInputMessages().

67 {
68  qDebug("RemoteSinkThread::stopWork");
69  delete m_socket;
70  m_socket = 0;
71  m_running = false;
72  wait();
73 }
QUdpSocket * m_socket
volatile bool m_running
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_address

QHostAddress RemoteSinkThread::m_address
private

Definition at line 80 of file remotesinkthread.h.

Referenced by handleDataBlock().

◆ m_cm256

CM256 RemoteSinkThread::m_cm256
private

Definition at line 77 of file remotesinkthread.h.

◆ m_cm256p

CM256* RemoteSinkThread::m_cm256p
private

Definition at line 78 of file remotesinkthread.h.

Referenced by handleDataBlock().

◆ m_inputMessageQueue

MessageQueue RemoteSinkThread::m_inputMessageQueue
private

Definition at line 83 of file remotesinkthread.h.

Referenced by handleInputMessages(), and startStop().

◆ m_running

volatile bool RemoteSinkThread::m_running
private

Definition at line 75 of file remotesinkthread.h.

Referenced by run(), startWork(), and stopWork().

◆ m_socket

QUdpSocket* RemoteSinkThread::m_socket
private

Definition at line 81 of file remotesinkthread.h.

Referenced by handleDataBlock(), startWork(), and stopWork().

◆ m_startWaiter

QWaitCondition RemoteSinkThread::m_startWaiter
private

Definition at line 74 of file remotesinkthread.h.

Referenced by run(), and startWork().

◆ m_startWaitMutex

QMutex RemoteSinkThread::m_startWaitMutex
private

Definition at line 73 of file remotesinkthread.h.

Referenced by startWork().


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