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 Attributes | List of all members
UDPSinkUtil< T > Class Template Reference

#include <udpsinkutil.h>

Public Member Functions

 UDPSinkUtil (QObject *parent, unsigned int udpSize)
 
 UDPSinkUtil (QObject *parent, unsigned int udpSize, unsigned int port)
 
 UDPSinkUtil (QObject *parent, unsigned int udpSize, QHostAddress &address, unsigned int port)
 
 ~UDPSinkUtil ()
 
void moveToThread (QThread *thread)
 
void setAddress (QString &address)
 
void setPort (unsigned int port)
 
void setDestination (const QString &address, int port)
 
void write (T sample)
 
void write (T *samples, int nbSamples)
 

Private Attributes

int m_udpSize
 
int m_udpSamples
 
QHostAddress m_address
 
unsigned int m_port
 
QUdpSocket * m_socket
 
T * m_sampleBuffer
 
int m_sampleBufferIndex
 

Detailed Description

template<typename T>
class UDPSinkUtil< T >

Definition at line 30 of file udpsinkutil.h.

Constructor & Destructor Documentation

◆ UDPSinkUtil() [1/3]

template<typename T>
UDPSinkUtil< T >::UDPSinkUtil ( QObject *  parent,
unsigned int  udpSize 
)
inline

Definition at line 33 of file udpsinkutil.h.

33  :
34  m_udpSize(udpSize),
35  m_udpSamples(udpSize/sizeof(T)),
36  m_address(QHostAddress::LocalHost),
37  m_port(9999),
39  {
40  assert(m_udpSamples > 0);
42  m_socket = new QUdpSocket(parent);
43  }
QHostAddress m_address
Definition: udpsinkutil.h:136
unsigned int m_port
Definition: udpsinkutil.h:137
int m_udpSamples
Definition: udpsinkutil.h:135
T * m_sampleBuffer
Definition: udpsinkutil.h:139
int m_sampleBufferIndex
Definition: udpsinkutil.h:139
QUdpSocket * m_socket
Definition: udpsinkutil.h:138

◆ UDPSinkUtil() [2/3]

template<typename T>
UDPSinkUtil< T >::UDPSinkUtil ( QObject *  parent,
unsigned int  udpSize,
unsigned int  port 
)
inline

Definition at line 45 of file udpsinkutil.h.

45  :
46  m_udpSize(udpSize),
47  m_udpSamples(udpSize/sizeof(T)),
48  m_address(QHostAddress::LocalHost),
49  m_port(port),
51  {
52  assert(m_udpSamples > 0);
54  m_socket = new QUdpSocket(parent);
55  }
QHostAddress m_address
Definition: udpsinkutil.h:136
unsigned int m_port
Definition: udpsinkutil.h:137
int m_udpSamples
Definition: udpsinkutil.h:135
T * m_sampleBuffer
Definition: udpsinkutil.h:139
int m_sampleBufferIndex
Definition: udpsinkutil.h:139
QUdpSocket * m_socket
Definition: udpsinkutil.h:138

◆ UDPSinkUtil() [3/3]

template<typename T>
UDPSinkUtil< T >::UDPSinkUtil ( QObject *  parent,
unsigned int  udpSize,
QHostAddress &  address,
unsigned int  port 
)
inline

Definition at line 57 of file udpsinkutil.h.

57  :
58  m_udpSize(udpSize),
59  m_udpSamples(udpSize/sizeof(T)),
60  m_address(address),
61  m_port(port),
63  {
64  assert(m_udpSamples > 0);
66  m_socket = new QUdpSocket(parent);
67  }
QHostAddress m_address
Definition: udpsinkutil.h:136
unsigned int m_port
Definition: udpsinkutil.h:137
int m_udpSamples
Definition: udpsinkutil.h:135
T * m_sampleBuffer
Definition: udpsinkutil.h:139
int m_sampleBufferIndex
Definition: udpsinkutil.h:139
QUdpSocket * m_socket
Definition: udpsinkutil.h:138

◆ ~UDPSinkUtil()

template<typename T>
UDPSinkUtil< T >::~UDPSinkUtil ( )
inline

Definition at line 69 of file udpsinkutil.h.

70  {
71  delete[] m_sampleBuffer;
72  delete m_socket;
73  }
T * m_sampleBuffer
Definition: udpsinkutil.h:139
QUdpSocket * m_socket
Definition: udpsinkutil.h:138

Member Function Documentation

◆ moveToThread()

template<typename T>
void UDPSinkUtil< T >::moveToThread ( QThread *  thread)
inline

Definition at line 75 of file udpsinkutil.h.

76  {
77  m_socket->moveToThread(thread);
78  }
QUdpSocket * m_socket
Definition: udpsinkutil.h:138

◆ setAddress()

template<typename T>
void UDPSinkUtil< T >::setAddress ( QString &  address)
inline

Definition at line 80 of file udpsinkutil.h.

Referenced by UDPSink::applySettings().

80 { m_address.setAddress(address); }
QHostAddress m_address
Definition: udpsinkutil.h:136
+ Here is the caller graph for this function:

◆ setDestination()

template<typename T>
void UDPSinkUtil< T >::setDestination ( const QString &  address,
int  port 
)
inline

Definition at line 83 of file udpsinkutil.h.

84  {
85  m_address.setAddress(const_cast<QString&>(address));
86  m_port = port;
87  }
QHostAddress m_address
Definition: udpsinkutil.h:136
unsigned int m_port
Definition: udpsinkutil.h:137

◆ setPort()

template<typename T>
void UDPSinkUtil< T >::setPort ( unsigned int  port)
inline

Definition at line 81 of file udpsinkutil.h.

Referenced by UDPSink::applySettings().

81 { m_port = port; }
unsigned int m_port
Definition: udpsinkutil.h:137
+ Here is the caller graph for this function:

◆ write() [1/2]

template<typename T>
void UDPSinkUtil< T >::write ( sample)
inline

Write one sample

Definition at line 92 of file udpsinkutil.h.

Referenced by UDPSink::udpWrite(), UDPSink::udpWriteMono(), UDPSink::udpWriteNorm(), and UDPSink::udpWriteNormMono().

93  {
95  {
98  }
99  else
100  {
101  m_socket->writeDatagram((const char*)&m_sampleBuffer[0], (qint64 ) m_udpSize, m_address, m_port);
102  m_sampleBuffer[0] = sample;
104  }
105  }
QHostAddress m_address
Definition: udpsinkutil.h:136
unsigned int m_port
Definition: udpsinkutil.h:137
int m_udpSamples
Definition: udpsinkutil.h:135
T * m_sampleBuffer
Definition: udpsinkutil.h:139
int m_sampleBufferIndex
Definition: udpsinkutil.h:139
QUdpSocket * m_socket
Definition: udpsinkutil.h:138
+ Here is the caller graph for this function:

◆ write() [2/2]

template<typename T>
void UDPSinkUtil< T >::write ( T *  samples,
int  nbSamples 
)
inline

Write a bunch of samples

Definition at line 110 of file udpsinkutil.h.

111  {
112  int samplesIndex = 0;
113 
114  if (m_sampleBufferIndex + nbSamples > m_udpSamples) // fill remainder of buffer and send it
115  {
116  memcpy(&m_sampleBuffer[m_sampleBufferIndex], &samples[samplesIndex], (m_udpSamples - m_sampleBufferIndex)*sizeof(T)); // fill remainder of buffer
117  m_socket->writeDatagram((const char*)&m_sampleBuffer[0], (qint64 ) m_udpSize, m_address, m_port); // send buffer
118  samplesIndex += (m_udpSamples - m_sampleBufferIndex);
119  nbSamples -= (m_udpSamples - m_sampleBufferIndex);
120  m_sampleBufferIndex = 0;
121  }
122 
123  while (nbSamples > m_udpSamples) // send directly from input without buffering
124  {
125  m_socket->writeDatagram((const char*)&samples[samplesIndex], (qint64 ) m_udpSize, m_address, m_port);
126  samplesIndex += m_udpSamples;
127  nbSamples -= m_udpSamples;
128  }
129 
130  memcpy(&m_sampleBuffer[m_sampleBufferIndex], &samples[samplesIndex], nbSamples*sizeof(T)); // copy remainder of input to buffer
131  }
QHostAddress m_address
Definition: udpsinkutil.h:136
unsigned int m_port
Definition: udpsinkutil.h:137
int m_udpSamples
Definition: udpsinkutil.h:135
T * m_sampleBuffer
Definition: udpsinkutil.h:139
int m_sampleBufferIndex
Definition: udpsinkutil.h:139
QUdpSocket * m_socket
Definition: udpsinkutil.h:138

Member Data Documentation

◆ m_address

template<typename T>
QHostAddress UDPSinkUtil< T >::m_address
private

◆ m_port

template<typename T>
unsigned int UDPSinkUtil< T >::m_port
private

◆ m_sampleBuffer

template<typename T>
T* UDPSinkUtil< T >::m_sampleBuffer
private

◆ m_sampleBufferIndex

template<typename T>
int UDPSinkUtil< T >::m_sampleBufferIndex
private

Definition at line 139 of file udpsinkutil.h.

Referenced by UDPSinkUtil< UDPSink::Sample16 >::write().

◆ m_socket

template<typename T>
QUdpSocket* UDPSinkUtil< T >::m_socket
private

◆ m_udpSamples

template<typename T>
int UDPSinkUtil< T >::m_udpSamples
private

◆ m_udpSize

template<typename T>
int UDPSinkUtil< T >::m_udpSize
private

Definition at line 134 of file udpsinkutil.h.

Referenced by UDPSinkUtil< UDPSink::Sample16 >::write().


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