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 | Static Public Attributes | Private Attributes | List of all members
UDPSinkFEC Class Reference

#include <udpsinkfec.h>

Inherits QObject.

+ Collaboration diagram for UDPSinkFEC:

Public Member Functions

 UDPSinkFEC ()
 
 ~UDPSinkFEC ()
 
void start ()
 
void stop ()
 
void write (const SampleVector::iterator &begin, uint32_t sampleChunkSize)
 
std::string error ()
 
void setSampleRate (uint32_t sampleRate)
 
void setNbBlocksFEC (uint32_t nbBlocksFEC)
 
void setTxDelay (float txDelayRatio)
 
void setRemoteAddress (const QString &address, uint16_t port)
 
 operator bool () const
 

Static Public Attributes

static const uint32_t m_udpSize = 512
 Size of UDP block in number of bytes. More...
 
static const uint32_t m_nbOriginalBlocks = 128
 Number of original blocks in a protected block sequence. More...
 

Private Attributes

std::string m_error
 
uint32_t m_sampleRate
 sample rate in Hz More...
 
uint32_t m_nbSamples
 total number of samples sent int the last frame More...
 
QHostAddress m_ownAddress
 
CRC64 m_crc64
 
uint8_tm_bufMeta
 
uint8_tm_buf
 
RemoteMetaDataFEC m_currentMetaFEC
 Meta data for current frame. More...
 
uint32_t m_nbBlocksFEC
 Variable number of FEC blocks. More...
 
float m_txDelayRatio
 Delay in ratio of nominal frame period. More...
 
uint32_t m_txDelay
 Delay in microseconds (usleep) between each sending of an UDP datagram. More...
 
RemoteSuperBlock m_txBlocks [4][256]
 UDP blocks to send with original data + FEC. More...
 
RemoteSuperBlock m_superBlock
 current super block being built More...
 
int m_txBlockIndex
 Current index in blocks to transmit in the Tx row. More...
 
int m_txBlocksIndex
 Current index of Tx blocks row. More...
 
uint16_t m_frameCount
 transmission frame count More...
 
int m_sampleIndex
 Current sample index in protected block data. More...
 
UDPSinkFECWorkerm_udpWorker
 
QString m_remoteAddress
 
uint16_t m_remotePort
 

Detailed Description

Definition at line 34 of file udpsinkfec.h.

Constructor & Destructor Documentation

◆ UDPSinkFEC()

UDPSinkFEC::UDPSinkFEC ( )

Construct UDP sink

Definition at line 30 of file udpsinkfec.cpp.

References RemoteMetaDataFEC::init(), m_buf, m_bufMeta, m_currentMetaFEC, m_superBlock, m_txBlocks, and m_udpSize.

30  :
31  m_sampleRate(48000),
32  m_nbSamples(0),
33  m_nbBlocksFEC(0),
34  m_txDelayRatio(0.0),
35  m_txDelay(0),
36  m_txBlockIndex(0),
37  m_txBlocksIndex(0),
38  m_frameCount(0),
39  m_sampleIndex(0),
40  m_udpWorker(0),
41  m_remoteAddress("127.0.0.1"),
42  m_remotePort(9090)
43 {
44  memset((char *) m_txBlocks, 0, 4*256*sizeof(RemoteSuperBlock));
45  memset((char *) &m_superBlock, 0, sizeof(RemoteSuperBlock));
48  m_buf = new uint8_t[m_udpSize];
49 }
uint32_t m_sampleRate
sample rate in Hz
Definition: udpsinkfec.h:81
int m_txBlocksIndex
Current index of Tx blocks row.
Definition: udpsinkfec.h:97
uint16_t m_remotePort
Definition: udpsinkfec.h:103
int m_sampleIndex
Current sample index in protected block data.
Definition: udpsinkfec.h:99
uint32_t m_txDelay
Delay in microseconds (usleep) between each sending of an UDP datagram.
Definition: udpsinkfec.h:93
float m_txDelayRatio
Delay in ratio of nominal frame period.
Definition: udpsinkfec.h:92
QString m_remoteAddress
Definition: udpsinkfec.h:102
uint8_t * m_bufMeta
Definition: udpsinkfec.h:87
unsigned char uint8_t
Definition: rtptypes_win.h:42
RemoteMetaDataFEC m_currentMetaFEC
Meta data for current frame.
Definition: udpsinkfec.h:90
uint32_t m_nbSamples
total number of samples sent int the last frame
Definition: udpsinkfec.h:82
RemoteSuperBlock m_txBlocks[4][256]
UDP blocks to send with original data + FEC.
Definition: udpsinkfec.h:94
RemoteSuperBlock m_superBlock
current super block being built
Definition: udpsinkfec.h:95
static const uint32_t m_udpSize
Size of UDP block in number of bytes.
Definition: udpsinkfec.h:38
UDPSinkFECWorker * m_udpWorker
Definition: udpsinkfec.h:101
int m_txBlockIndex
Current index in blocks to transmit in the Tx row.
Definition: udpsinkfec.h:96
uint16_t m_frameCount
transmission frame count
Definition: udpsinkfec.h:98
uint8_t * m_buf
Definition: udpsinkfec.h:88
uint32_t m_nbBlocksFEC
Variable number of FEC blocks.
Definition: udpsinkfec.h:91
+ Here is the call graph for this function:

◆ ~UDPSinkFEC()

UDPSinkFEC::~UDPSinkFEC ( )

Destroy UDP sink

Definition at line 51 of file udpsinkfec.cpp.

References m_buf, and m_bufMeta.

52 {
53  delete[] m_buf;
54  delete[] m_bufMeta;
55 }
uint8_t * m_bufMeta
Definition: udpsinkfec.h:87
uint8_t * m_buf
Definition: udpsinkfec.h:88

Member Function Documentation

◆ error()

std::string UDPSinkFEC::error ( )
inline

Return the last error, or return an empty string if there is no error.

Definition at line 58 of file udpsinkfec.h.

References m_error, setNbBlocksFEC(), setRemoteAddress(), setSampleRate(), and setTxDelay().

59  {
60  std::string ret(m_error);
61  m_error.clear();
62  return ret;
63  }
std::string m_error
Definition: udpsinkfec.h:79
+ Here is the call graph for this function:

◆ operator bool()

UDPSinkFEC::operator bool ( ) const
inline

Return true if the stream is OK, return false if there is an error.

Definition at line 73 of file udpsinkfec.h.

References m_error.

74  {
75  return m_error.empty();
76  }
std::string m_error
Definition: udpsinkfec.h:79

◆ setNbBlocksFEC()

void UDPSinkFEC::setNbBlocksFEC ( uint32_t  nbBlocksFEC)

Definition at line 87 of file udpsinkfec.cpp.

References m_nbBlocksFEC, m_txDelayRatio, and setTxDelay().

Referenced by error(), and RemoteOutputThread::setNbBlocksFEC().

88 {
89  qDebug() << "UDPSinkFEC::setNbBlocksFEC: nbBlocksFEC: " << nbBlocksFEC;
90  m_nbBlocksFEC = nbBlocksFEC;
92 }
void setTxDelay(float txDelayRatio)
Definition: udpsinkfec.cpp:74
float m_txDelayRatio
Delay in ratio of nominal frame period.
Definition: udpsinkfec.h:92
uint32_t m_nbBlocksFEC
Variable number of FEC blocks.
Definition: udpsinkfec.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRemoteAddress()

void UDPSinkFEC::setRemoteAddress ( const QString &  address,
uint16_t  port 
)

Definition at line 101 of file udpsinkfec.cpp.

References m_remoteAddress, m_remotePort, m_udpWorker, and UDPSinkFECWorker::setRemoteAddress().

Referenced by error(), and RemoteOutputThread::setDataAddress().

102 {
103  qDebug() << "UDPSinkFEC::setRemoteAddress: address: " << address << " port: " << port;
104  m_remoteAddress = address;
105  m_remotePort = port;
106 
107  if (m_udpWorker) {
109  }
110 }
uint16_t m_remotePort
Definition: udpsinkfec.h:103
QString m_remoteAddress
Definition: udpsinkfec.h:102
UDPSinkFECWorker * m_udpWorker
Definition: udpsinkfec.h:101
void setRemoteAddress(const QString &address, uint16_t port)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSampleRate()

void UDPSinkFEC::setSampleRate ( uint32_t  sampleRate)

Set sample rate given in S/s

Definition at line 94 of file udpsinkfec.cpp.

References m_sampleRate, m_txDelayRatio, and setTxDelay().

Referenced by error(), and RemoteOutputThread::setSamplerate().

95 {
96  qDebug() << "UDPSinkFEC::setSampleRate: sampleRate: " << sampleRate;
97  m_sampleRate = sampleRate;
99 }
uint32_t m_sampleRate
sample rate in Hz
Definition: udpsinkfec.h:81
void setTxDelay(float txDelayRatio)
Definition: udpsinkfec.cpp:74
float m_txDelayRatio
Delay in ratio of nominal frame period.
Definition: udpsinkfec.h:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTxDelay()

void UDPSinkFEC::setTxDelay ( float  txDelayRatio)

Definition at line 74 of file udpsinkfec.cpp.

References m_txDelayRatio.

Referenced by error(), setNbBlocksFEC(), setSampleRate(), and RemoteOutputThread::setTxDelay().

75 {
76  // delay is calculated from the fraction of the nominal UDP block process time
77  // frame size: 127 * (126 or 63 samples depending on I or Q sample bytes of 2 or 4 bytes respectively)
78  // divided by sample rate gives the frame process time
79  // divided by the number of actual blocks including FEC blocks gives the block (i.e. UDP block) process time
80  m_txDelayRatio = txDelayRatio;
81  int samplesPerBlock = RemoteNbBytesPerBlock / (SDR_RX_SAMP_SZ <= 16 ? 4 : 8);
82  double delay = ((127*samplesPerBlock*txDelayRatio) / m_sampleRate)/(128 + m_nbBlocksFEC);
83  m_txDelay = delay * 1e6;
84  qDebug() << "UDPSinkFEC::setTxDelay: txDelay: " << txDelayRatio << " m_txDelay: " << m_txDelay << " us";
85 }
uint32_t m_sampleRate
sample rate in Hz
Definition: udpsinkfec.h:81
uint32_t m_txDelay
Delay in microseconds (usleep) between each sending of an UDP datagram.
Definition: udpsinkfec.h:93
float m_txDelayRatio
Delay in ratio of nominal frame period.
Definition: udpsinkfec.h:92
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
uint32_t m_nbBlocksFEC
Variable number of FEC blocks.
Definition: udpsinkfec.h:91
+ Here is the caller graph for this function:

◆ start()

void UDPSinkFEC::start ( )

Definition at line 57 of file udpsinkfec.cpp.

References m_remoteAddress, m_remotePort, m_udpWorker, UDPSinkFECWorker::setRemoteAddress(), and UDPSinkFECWorker::startStop().

Referenced by RemoteOutputThread::startWork().

58 {
61  m_udpWorker->startStop(true);
62 }
uint16_t m_remotePort
Definition: udpsinkfec.h:103
QString m_remoteAddress
Definition: udpsinkfec.h:102
void startStop(bool start)
UDPSinkFECWorker * m_udpWorker
Definition: udpsinkfec.h:101
void setRemoteAddress(const QString &address, uint16_t port)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stop()

void UDPSinkFEC::stop ( )

Definition at line 64 of file udpsinkfec.cpp.

References m_udpWorker, and UDPSinkFECWorker::startStop().

Referenced by RemoteOutputThread::stopWork().

65 {
66  if (m_udpWorker)
67  {
68  m_udpWorker->startStop(false);
69  m_udpWorker->deleteLater();
70  m_udpWorker = 0;
71  }
72 }
void startStop(bool start)
UDPSinkFECWorker * m_udpWorker
Definition: udpsinkfec.h:101
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

void UDPSinkFEC::write ( const SampleVector::iterator &  begin,
uint32_t  sampleChunkSize 
)

Write IQ samples

Definition at line 112 of file udpsinkfec.cpp.

References leansdr::crc32(), RemoteMetaDataFEC::m_centerFrequency, RemoteMetaDataFEC::m_crc32, m_currentMetaFEC, m_frameCount, m_nbBlocksFEC, RemoteMetaDataFEC::m_nbFECBlocks, m_nbOriginalBlocks, RemoteMetaDataFEC::m_nbOriginalBlocks, RemoteMetaDataFEC::m_sampleBits, RemoteMetaDataFEC::m_sampleBytes, RemoteMetaDataFEC::m_sampleRate, m_sampleRate, m_superBlock, RemoteMetaDataFEC::m_tv_sec, RemoteMetaDataFEC::m_tv_usec, m_txBlockIndex, m_txBlocks, m_txBlocksIndex, TimeUtil::nowus(), and SDR_RX_SAMP_SZ.

Referenced by RemoteOutputThread::tick().

113 {
114  const SampleVector::iterator end = begin + sampleChunkSize;
115  SampleVector::iterator it = begin;
116 
117  while (it != end)
118  {
119  int inRemainingSamples = end - it;
120 
121  if (m_txBlockIndex == 0) // Tx block index 0 is a block with only meta data
122  {
123  RemoteMetaDataFEC metaData;
124 
125  uint64_t ts_usecs = TimeUtil::nowus();
126 
127  metaData.m_centerFrequency = 0; // frequency not set by stream
128  metaData.m_sampleRate = m_sampleRate;
129  metaData.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
130  metaData.m_sampleBits = SDR_RX_SAMP_SZ;
132  metaData.m_nbFECBlocks = m_nbBlocksFEC;
133  metaData.m_tv_sec = ts_usecs / 1000000UL;
134  metaData.m_tv_usec = ts_usecs % 1000000UL;
135 
136  boost::crc_32_type crc32;
137  crc32.process_bytes(&metaData, sizeof(RemoteMetaDataFEC)-4);
138 
139  metaData.m_crc32 = crc32.checksum();
140 
141  memset((char *) &m_superBlock, 0, sizeof(m_superBlock));
142 
143  m_superBlock.m_header.m_frameIndex = m_frameCount;
144  m_superBlock.m_header.m_blockIndex = m_txBlockIndex;
145  m_superBlock.m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
146  m_superBlock.m_header.m_sampleBits = SDR_RX_SAMP_SZ;
147 
148  RemoteMetaDataFEC *destMeta = (RemoteMetaDataFEC *) &m_superBlock.m_protectedBlock;
149  *destMeta = metaData;
150 
151  if (!(metaData == m_currentMetaFEC))
152  {
153  qDebug() << "UDPSinkFEC::write: meta: "
154  << "|" << metaData.m_centerFrequency
155  << ":" << metaData.m_sampleRate
156  << ":" << (int) (metaData.m_sampleBytes & 0xF)
157  << ":" << (int) metaData.m_sampleBits
158  << "|" << (int) metaData.m_nbOriginalBlocks
159  << ":" << (int) metaData.m_nbFECBlocks
160  << "|" << metaData.m_tv_sec
161  << ":" << metaData.m_tv_usec
162  << "|";
163 
164  m_currentMetaFEC = metaData;
165  }
166 
168  m_txBlockIndex = 1; // next Tx block with data
169  }
170 
171  int samplesPerBlock = RemoteNbBytesPerBlock / (SDR_RX_SAMP_SZ <= 16 ? 4 : 8); // two I or Q samples
172 
173  if (m_sampleIndex + inRemainingSamples < samplesPerBlock) // there is still room in the current super block
174  {
175  memcpy((char *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
176  (const char *) &(*it),
177  inRemainingSamples * sizeof(Sample));
178  m_sampleIndex += inRemainingSamples;
179  it = end; // all input samples are consumed
180  }
181  else // complete super block and initiate the next if not end of frame
182  {
183  memcpy((char *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
184  (const char *) &(*it),
185  (samplesPerBlock - m_sampleIndex) * sizeof(Sample));
186  it += samplesPerBlock - m_sampleIndex;
187  m_sampleIndex = 0;
188 
189  m_superBlock.m_header.m_frameIndex = m_frameCount;
190  m_superBlock.m_header.m_blockIndex = m_txBlockIndex;
191  m_superBlock.m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
192  m_superBlock.m_header.m_sampleBits = SDR_RX_SAMP_SZ;
194 
195  if (m_txBlockIndex == m_nbOriginalBlocks - 1) // frame complete
196  {
197  int nbBlocksFEC = m_nbBlocksFEC;
198  int txDelay = m_txDelay;
199 
200  if (m_udpWorker) {
202  }
203 
204  m_txBlocksIndex = (m_txBlocksIndex + 1) % 4;
205  m_txBlockIndex = 0;
206  m_frameCount++;
207  }
208  else
209  {
210  m_txBlockIndex++;
211  }
212  }
213  }
214 }
uint32_t m_sampleRate
12 sample rate in Hz
uint32_t m_sampleRate
sample rate in Hz
Definition: udpsinkfec.h:81
void pushTxFrame(RemoteSuperBlock *txBlocks, uint32_t nbBlocksFEC, uint32_t txDelay, uint16_t frameIndex)
int m_txBlocksIndex
Current index of Tx blocks row.
Definition: udpsinkfec.h:97
int m_sampleIndex
Current sample index in protected block data.
Definition: udpsinkfec.h:99
uint32_t m_txDelay
Delay in microseconds (usleep) between each sending of an UDP datagram.
Definition: udpsinkfec.h:93
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
uint8_t m_sampleBytes
13 4 LSB: number of bytes per sample (2 or 4)
RemoteMetaDataFEC m_currentMetaFEC
Meta data for current frame.
Definition: udpsinkfec.h:90
RemoteSuperBlock m_txBlocks[4][256]
UDP blocks to send with original data + FEC.
Definition: udpsinkfec.h:94
uint32_t m_crc32
28 CRC32 of the above
uint8_t m_nbFECBlocks
16 number of blocks carrying FEC
uint32_t m_tv_usec
24 microseconds of timestamp at start time of super-frame processing
uint8_t m_sampleBits
14 number of effective bits per sample (deprecated)
static const uint32_t m_nbOriginalBlocks
Number of original blocks in a protected block sequence.
Definition: udpsinkfec.h:39
uint32_t m_tv_sec
20 seconds of timestamp at start time of super-frame processing
RemoteSuperBlock m_superBlock
current super block being built
Definition: udpsinkfec.h:95
UDPSinkFECWorker * m_udpWorker
Definition: udpsinkfec.h:101
static uint64_t nowus()
returns the current epoch in microseconds
Definition: timeutil.cpp:30
uint8_t m_nbOriginalBlocks
15 number of blocks with original (protected) data
int m_txBlockIndex
Current index in blocks to transmit in the Tx row.
Definition: udpsinkfec.h:96
uint32_t crc32(const uint8_t *buf, int len)
Definition: crc.h:58
uint64_t m_centerFrequency
8 center frequency in kHz
uint16_t m_frameCount
transmission frame count
Definition: udpsinkfec.h:98
uint32_t m_nbBlocksFEC
Variable number of FEC blocks.
Definition: udpsinkfec.h:91
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_buf

uint8_t* UDPSinkFEC::m_buf
private

Definition at line 88 of file udpsinkfec.h.

Referenced by UDPSinkFEC(), and ~UDPSinkFEC().

◆ m_bufMeta

uint8_t* UDPSinkFEC::m_bufMeta
private

Definition at line 87 of file udpsinkfec.h.

Referenced by UDPSinkFEC(), and ~UDPSinkFEC().

◆ m_crc64

CRC64 UDPSinkFEC::m_crc64
private

Definition at line 86 of file udpsinkfec.h.

◆ m_currentMetaFEC

RemoteMetaDataFEC UDPSinkFEC::m_currentMetaFEC
private

Meta data for current frame.

Definition at line 90 of file udpsinkfec.h.

Referenced by UDPSinkFEC(), and write().

◆ m_error

std::string UDPSinkFEC::m_error
private

Definition at line 79 of file udpsinkfec.h.

Referenced by error(), and operator bool().

◆ m_frameCount

uint16_t UDPSinkFEC::m_frameCount
private

transmission frame count

Definition at line 98 of file udpsinkfec.h.

Referenced by write().

◆ m_nbBlocksFEC

uint32_t UDPSinkFEC::m_nbBlocksFEC
private

Variable number of FEC blocks.

Definition at line 91 of file udpsinkfec.h.

Referenced by setNbBlocksFEC(), and write().

◆ m_nbOriginalBlocks

const uint32_t UDPSinkFEC::m_nbOriginalBlocks = 128
static

Number of original blocks in a protected block sequence.

Definition at line 39 of file udpsinkfec.h.

Referenced by write().

◆ m_nbSamples

uint32_t UDPSinkFEC::m_nbSamples
private

total number of samples sent int the last frame

Definition at line 82 of file udpsinkfec.h.

◆ m_ownAddress

QHostAddress UDPSinkFEC::m_ownAddress
private

Definition at line 84 of file udpsinkfec.h.

◆ m_remoteAddress

QString UDPSinkFEC::m_remoteAddress
private

Definition at line 102 of file udpsinkfec.h.

Referenced by setRemoteAddress(), and start().

◆ m_remotePort

uint16_t UDPSinkFEC::m_remotePort
private

Definition at line 103 of file udpsinkfec.h.

Referenced by setRemoteAddress(), and start().

◆ m_sampleIndex

int UDPSinkFEC::m_sampleIndex
private

Current sample index in protected block data.

Definition at line 99 of file udpsinkfec.h.

◆ m_sampleRate

uint32_t UDPSinkFEC::m_sampleRate
private

sample rate in Hz

Definition at line 81 of file udpsinkfec.h.

Referenced by setSampleRate(), and write().

◆ m_superBlock

RemoteSuperBlock UDPSinkFEC::m_superBlock
private

current super block being built

Definition at line 95 of file udpsinkfec.h.

Referenced by UDPSinkFEC(), and write().

◆ m_txBlockIndex

int UDPSinkFEC::m_txBlockIndex
private

Current index in blocks to transmit in the Tx row.

Definition at line 96 of file udpsinkfec.h.

Referenced by write().

◆ m_txBlocks

RemoteSuperBlock UDPSinkFEC::m_txBlocks[4][256]
private

UDP blocks to send with original data + FEC.

Definition at line 94 of file udpsinkfec.h.

Referenced by UDPSinkFEC(), and write().

◆ m_txBlocksIndex

int UDPSinkFEC::m_txBlocksIndex
private

Current index of Tx blocks row.

Definition at line 97 of file udpsinkfec.h.

Referenced by write().

◆ m_txDelay

uint32_t UDPSinkFEC::m_txDelay
private

Delay in microseconds (usleep) between each sending of an UDP datagram.

Definition at line 93 of file udpsinkfec.h.

◆ m_txDelayRatio

float UDPSinkFEC::m_txDelayRatio
private

Delay in ratio of nominal frame period.

Definition at line 92 of file udpsinkfec.h.

Referenced by setNbBlocksFEC(), setSampleRate(), and setTxDelay().

◆ m_udpSize

const uint32_t UDPSinkFEC::m_udpSize = 512
static

Size of UDP block in number of bytes.

Definition at line 38 of file udpsinkfec.h.

Referenced by UDPSinkFEC().

◆ m_udpWorker

UDPSinkFECWorker* UDPSinkFEC::m_udpWorker
private

Definition at line 101 of file udpsinkfec.h.

Referenced by setRemoteAddress(), start(), and stop().


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