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 #include <QMutex>
00045
00046 #include "DataProtocol.h"
00047 #include "jacktrip_types.h"
00048 #include "jacktrip_globals.h"
00049
00064 class UdpDataProtocol : public DataProtocol
00065 {
00066 Q_OBJECT;
00067
00068 public:
00069
00077 UdpDataProtocol(JackTrip* jacktrip, const runModeT runmode,
00078 int bind_port, int peer_port,
00079 unsigned int udp_redundancy_factor = 1);
00080
00083 virtual ~UdpDataProtocol();
00084
00088 void setPeerAddress(const char* peerHostOrIP);
00089
00098
00099 virtual int receivePacket(QUdpSocket& UdpSocket, char* buf, const size_t n);
00100
00109 virtual int sendPacket(QUdpSocket& UdpSocket, const QHostAddress& PeerAddress,
00110 const char* buf, const size_t n);
00111
00117 virtual void getPeerAddressFromFirstPacket(QUdpSocket& UdpSocket,
00118 QHostAddress& peerHostAddress,
00119 uint16_t& port);
00120
00123 void setBindPort(int port)
00124 { mBindPort = port; }
00125
00128 void setPeerPort(int port)
00129 { mPeerPort = port; }
00130
00136 virtual void run();
00137
00138
00139 private slots:
00140 void printUdpWaitedTooLong(int wait_msec);
00141
00142
00143 signals:
00144
00147 void signalWatingTooLong(int wait_msec);
00148
00149
00150
00151 protected:
00152
00155 void bindSocket(QUdpSocket& UdpSocket);
00156
00166 bool waitForReady(QUdpSocket& UdpSocket, int timeout_msec);
00167
00170 virtual void receivePacketRedundancy(QUdpSocket& UdpSocket,
00171 int8_t* full_redundant_packet,
00172 int full_redundant_packet_size,
00173 int full_packet_size,
00174 uint16_t& current_seq_num,
00175 uint16_t& last_seq_num,
00176 uint16_t& newer_seq_num);
00177
00180 virtual void sendPacketRedundancy(QUdpSocket& UdpSocket,
00181 QHostAddress& PeerAddress,
00182 int8_t* full_redundant_packet,
00183 int full_redundant_packet_size,
00184 int full_packet_size);
00185
00186
00187 private:
00188
00189 int mBindPort;
00190 int mPeerPort;
00191 const runModeT mRunMode;
00192
00193 QHostAddress mPeerAddress;
00194
00195 int8_t* mAudioPacket;
00196 int8_t* mFullPacket;
00197
00198 unsigned int mUdpRedundancyFactor;
00199 static QMutex sUdpMutex;
00200 };
00201
00202 #endif // __UDPDATAPROTOCOL_H__