Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00038 #ifndef __UDPDATAPROTOCOL_H__
00039 #define __UDPDATAPROTOCOL_H__
00040
00041 #include <QThread>
00042 #include <QUdpSocket>
00043 #include <QHostAddress>
00044
00045 #include "DataProtocol.h"
00046 #include "jacktrip_types.h"
00047 #include "jacktrip_globals.h"
00048
00063 class UdpDataProtocol : public DataProtocol
00064 {
00065 Q_OBJECT;
00066
00067 public:
00068
00076 UdpDataProtocol(JackTrip* jacktrip, const runModeT runmode,
00077 int bind_port, int peer_port,
00078 unsigned int udp_redundancy_factor = 1);
00079
00082 virtual ~UdpDataProtocol();
00083
00087 void setPeerAddress(const char* peerHostOrIP);
00088
00097
00098 virtual int receivePacket(QUdpSocket& UdpSocket, char* buf, const size_t n);
00099
00108 virtual int sendPacket(QUdpSocket& UdpSocket, const QHostAddress& PeerAddress,
00109 const char* buf, const size_t n);
00110
00116 virtual void getPeerAddressFromFirstPacket(QUdpSocket& UdpSocket,
00117 QHostAddress& peerHostAddress,
00118 uint16_t& port);
00119
00122 void setBindPort(int port)
00123 { mBindPort = port; }
00124
00127 void setPeerPort(int port)
00128 { mPeerPort = port; }
00129
00135 virtual void run();
00136
00137
00138 private slots:
00139 void printUdpWaitedTooLong(int wait_msec);
00140
00141
00142 signals:
00143
00146 void signalWatingTooLong(int wait_msec);
00147
00148
00149 private:
00150
00153 void bindSocket(QUdpSocket& UdpSocket);
00154
00164 bool waitForReady(QUdpSocket& UdpSocket, int timeout_msec);
00165
00168 void receivePacketRedundancy(QUdpSocket& UdpSocket,
00169 int8_t* full_redundant_packet,
00170 int full_redundant_packet_size,
00171 int full_packet_size,
00172 uint16_t& current_seq_num,
00173 uint16_t& last_seq_num,
00174 uint16_t& newer_seq_num);
00175
00178 void sendPacketRedundancy(QUdpSocket& UdpSocket,
00179 QHostAddress& PeerAddress,
00180 int8_t* full_redundant_packet,
00181 int full_redundant_packet_size,
00182 int full_packet_size);
00183
00184 int mBindPort;
00185 int mPeerPort;
00186 const runModeT mRunMode;
00187
00188 QHostAddress mPeerAddress;
00189
00190 int8_t* mAudioPacket;
00191 int8_t* mFullPacket;
00192
00193 unsigned int mUdpRedundancyFactor;
00194 static QMutex sUdpMutex;
00195 };
00196
00197 #endif // __UDPDATAPROTOCOL_H__