JackTrip
|
UDP implementation of DataProtocol class. More...
#include <UdpDataProtocol.h>
Signals | |
void | signalWatingTooLong (int wait_msec) |
Signals when waiting every 10 milliseconds, with the total wait on wait_msec. |
Public Member Functions | |
UdpDataProtocol (JackTrip *jacktrip, const runModeT runmode, int bind_port, int peer_port, unsigned int udp_redundancy_factor=1) | |
The class constructor. | |
virtual | ~UdpDataProtocol () |
The class destructor. | |
void | setPeerAddress (const char *peerHostOrIP) |
Set the Peer address to connect to. | |
virtual int | receivePacket (QUdpSocket &UdpSocket, char *buf, const size_t n) |
Receives a packet. It blocks until a packet is received. | |
virtual int | sendPacket (QUdpSocket &UdpSocket, const QHostAddress &PeerAddress, const char *buf, const size_t n) |
Sends a packet. | |
virtual void | getPeerAddressFromFirstPacket (QUdpSocket &UdpSocket, QHostAddress &peerHostAddress, uint16_t &port) |
Obtains the peer address from the first UDP packet received. This address is used by the SERVER mode to connect back to the client. | |
void | setBindPort (int port) |
Sets the bind port number. | |
void | setPeerPort (int port) |
Sets the peer port number. | |
virtual void | run () |
Implements the Thread Loop. To start the thread, call start() ( DO NOT CALL run() ) | |
![]() | |
DataProtocol (JackTrip *jacktrip, const runModeT runmode, int bind_port, int peer_port) | |
The class constructor. | |
virtual | ~DataProtocol () |
The class destructor. | |
virtual void | stop () |
Stops the execution of the Thread. | |
void | setAudioPacketSize (const size_t size_bytes) |
Sets the size of the audio part of the packets. | |
size_t | getAudioPacketSizeInBites () |
Get the size of the audio part of the packets. |
Private Slots | |
void | printUdpWaitedTooLong (int wait_msec) |
Private Member Functions | |
void | bindSocket (QUdpSocket &UdpSocket) |
Binds the UDP socket to the available address and specified port. | |
bool | waitForReady (QUdpSocket &UdpSocket, int timeout_msec) |
This function blocks until data is available for reading in the QUdpSocket. The function will timeout after timeout_msec microseconds. | |
void | receivePacketRedundancy (QUdpSocket &UdpSocket, int8_t *full_redundant_packet, int full_redundant_packet_size, int full_packet_size, uint16_t ¤t_seq_num, uint16_t &last_seq_num, uint16_t &newer_seq_num) |
Redundancy algorythm at the receiving end. | |
void | sendPacketRedundancy (QUdpSocket &UdpSocket, QHostAddress &PeerAddress, int8_t *full_redundant_packet, int full_redundant_packet_size, int full_packet_size) |
Redundancy algorythm at the sender end. |
Private Attributes | |
int | mBindPort |
Local Port number to Bind. | |
int | mPeerPort |
Peer Port number. | |
const runModeT | mRunMode |
Run mode, either SENDER or RECEIVER. | |
QHostAddress | mPeerAddress |
The Peer Address. | |
int8_t * | mAudioPacket |
Buffer to store Audio Packets. | |
int8_t * | mFullPacket |
Buffer to store Full Packet (audio+header) | |
unsigned int | mUdpRedundancyFactor |
Factor of redundancy. |
Static Private Attributes | |
static QMutex | sUdpMutex |
Mutex to make thread safe the binding process. |
Additional Inherited Members | |
![]() | |
enum | packetHeaderTypeT { DEFAULT, JAMLINK, EMPTY } |
Enum to define packet header types. More... | |
enum | runModeT { SENDER, RECEIVER } |
Enum to define class modes, SENDER or RECEIVER. More... | |
![]() | |
runModeT | getRunMode () const |
Get the Run Mode of the object. | |
![]() | |
volatile bool | mStopped |
Boolean stop the execution of the thread. | |
volatile bool | mHasPeerAddress |
Boolean to indicate if the RECEIVER is waiting to obtain peer address. | |
volatile bool | mHasPacketsToReceive |
Boolean that indicates if a packet was received. | |
JackTrip * | mJackTrip |
JackTrip mediator class. |
UDP implementation of DataProtocol class.
The class has a bind port
and a peer port
. The meaning of these depends on the runModeT. If it's a SENDER, bind port
is the source port and peer port
is the destination port for each UDP packet. If it's a RECEIVER, the bind port
destination port (for incoming packets) and the peer port
is the source port.
The SENDER and RECEIVER socket can share the same port/address pair (for compatibility with the JamLink boxes). This is achieved setting the resusable property in the socket for address and port. You have to externaly check if the port is already binded if you want to avoid re-binding to the same port.
UdpDataProtocol::UdpDataProtocol | ( | JackTrip * | jacktrip, |
const runModeT | runmode, | ||
int | bind_port, | ||
int | peer_port, | ||
unsigned int | udp_redundancy_factor = 1 |
||
) |
The class constructor.
jacktrip | Pointer to the JackTrip class that connects all classes (mediator) |
runmode | Sets the run mode, use either SENDER or RECEIVER |
bind_port | Port number to bind for this socket (this is the receive or send port depending on the runmode) |
peer_port | Peer port number (this is the receive or send port depending on the runmode) |
udp_redundancy_factor | Number of redundant packets |
|
virtual |
The class destructor.
|
private |
Binds the UDP socket to the available address and specified port.
|
virtual |
Obtains the peer address from the first UDP packet received. This address is used by the SERVER mode to connect back to the client.
peerHostAddress | QHostAddress to store the peer address |
port | Receiving port |
|
privateslot |
|
virtual |
Receives a packet. It blocks until a packet is received.
This function makes sure we recieve a complete packet of size n
buf | Buffer to store the recieved packet |
n | size of packet to receive |
|
private |
Redundancy algorythm at the receiving end.
|
virtual |
Implements the Thread Loop. To start the thread, call start() ( DO NOT CALL run() )
This function creats and binds all the socket and start the connection loop thread.
Implements DataProtocol.
|
virtual |
Sends a packet.
This function meakes sure we send a complete packet of size n
buf | Buffer to send |
n | size of packet to receive |
|
private |
Redundancy algorythm at the sender end.
|
inline |
Sets the bind port number.
|
virtual |
Set the Peer address to connect to.
peerHostOrIP | IPv4 number or host name |
Implements DataProtocol.
|
inlinevirtual |
Sets the peer port number.
Implements DataProtocol.
|
signal |
Signals when waiting every 10 milliseconds, with the total wait on wait_msec.
wait_msec | Total wait in milliseconds |
|
private |
This function blocks until data is available for reading in the QUdpSocket. The function will timeout after timeout_msec microseconds.
This function is intended to replace QAbstractSocket::waitForReadyRead which has some problems with multithreading.
|
private |
Buffer to store Audio Packets.
|
private |
Local Port number to Bind.
|
private |
Buffer to store Full Packet (audio+header)
|
private |
The Peer Address.
|
private |
Peer Port number.
|
private |
Run mode, either SENDER or RECEIVER.
|
private |
Factor of redundancy.
|
staticprivate |
Mutex to make thread safe the binding process.