JackTrip
UdpHubListener.h
Go to the documentation of this file.
1 //*****************************************************************
2 /*
3  JackTrip: A System for High-Quality Audio Network Performance
4  over the Internet
5 
6  Copyright (c) 2008 Juan-Pablo Caceres, Chris Chafe.
7  SoundWIRE group at CCRMA, Stanford University.
8 
9  Permission is hereby granted, free of charge, to any person
10  obtaining a copy of this software and associated documentation
11  files (the "Software"), to deal in the Software without
12  restriction, including without limitation the rights to use,
13  copy, modify, merge, publish, distribute, sublicense, and/or sell
14  copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following
16  conditions:
17 
18  The above copyright notice and this permission notice shall be
19  included in all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  OTHER DEALINGS IN THE SOFTWARE.
29 */
30 //*****************************************************************
31 
38 #ifndef __UDPHUBLISTENER_H__
39 #define __UDPHUBLISTENER_H__
40 
41 #include <iostream>
42 #include <stdexcept>
43 
44 #include <QThread>
45 #include <QThreadPool>
46 #include <QUdpSocket>
47 #include <QHostAddress>
48 #include <QTcpSocket>
49 #include <QTcpServer>
50 #include <QMutex>
51 
52 #include "JackTrip.h"
53 #include "jacktrip_types.h"
54 #include "jacktrip_globals.h"
55 class JackTripWorker; // forward declaration
56 class Settings;
57 
58 typedef struct {
59  QString address;
62 
68 class UdpHubListener : public QThread
69 {
70  Q_OBJECT;
71 
72 public:
73  UdpHubListener(int server_port = gServerUdpPort);
74  virtual ~UdpHubListener();
75 
78  void run();
79 
81  void stop() { mStopped = true; }
82 
83  int releaseThread(int id);
84 
85  void setConnectDefaultAudioPorts(bool connectDefaultAudioPorts) { m_connectDefaultAudioPorts = connectDefaultAudioPorts; }
86 
87  void setSettings(Settings* s) {m_settings = s;}
88  Settings* getSettings() const {return m_settings;}
89 
90 private slots:
91  void testReceive()
92  { std::cout << "========= TEST RECEIVE SLOT ===========" << std::endl; }
93 
94 signals:
95  void Listening();
96  void ClientAddressSet();
97  void signalRemoveThread(int id);
98 
99 
100 private:
105  static void bindUdpSocket(QUdpSocket& udpsocket, int port);
106 
107  int readClientUdpPort(QTcpSocket* clientConnection);
108  int sendUdpPort(QTcpSocket* clientConnection, int udp_port);
109 
110 
115  //void sendToPoolPrototype(int id);
116 
121  int isNewAddress(QString address, uint16_t port);
122 
126  int getPoolID(QString address, uint16_t port);
127 
128  //QUdpSocket mUdpHubSocket; ///< The UDP socket
129  //QHostAddress mPeerAddress; ///< The Peer Address
130 
131  //JackTripWorker* mJTWorker; ///< Class that will be used as prototype
132  QVector<JackTripWorker*>* mJTWorkers;
133  QThreadPool mThreadPool;
134 
135  int mServerPort; //< Server known port number
136  int mBasePort;
137  addressPortPair mActiveAddress[gMaxThreads];
138  QHash<QString, uint16_t> mActiveAddressPortPair;
139 
141  volatile bool mStopped;
142  int mTotalRunningThreads;
143  QMutex mMutex;
144  JackTrip::underrunModeT mUnderRunMode;
145  int mBufferQueueLength;
146 
147  bool m_connectDefaultAudioPorts;
148  Settings* m_settings;
149 
150 #ifdef WAIR // wair
151  bool mWAIR;
152  void connectMesh(bool spawn);
153  void enumerateRunningThreadIDs();
154 public :
155  void setWAIR(int b) {mWAIR = b;}
156  bool isWAIR() {return mWAIR;}
157 #endif // endwhere
158  void connectPatch(bool spawn);
159 public :
160  unsigned int mHubPatch;
161  void setHubPatch(unsigned int p) {mHubPatch = p;}
162  unsigned int getHubPatch() {return mHubPatch;}
163 
164  void setUnderRunMode(JackTrip::underrunModeT UnderRunMode) { mUnderRunMode = UnderRunMode; }
165  void setBufferQueueLength(int BufferQueueLength) { mBufferQueueLength = BufferQueueLength; }
166 };
167 
168 
169 #endif //__UDPHUBLISTENER_H__
UdpHubListener::run
void run()
Implements the Thread Loop. To start the thread, call start() ( DO NOT CALL run() )
Definition: UdpHubListener.cpp:114
UdpHubListener::getHubPatch
unsigned int getHubPatch()
Definition: UdpHubListener.h:162
UdpHubListener::ClientAddressSet
void ClientAddressSet()
Definition: moc_UdpHubListener.cpp:166
UdpHubListener::stop
void stop()
Stops the execution of the Thread.
Definition: UdpHubListener.h:81
UdpHubListener::mHubPatch
unsigned int mHubPatch
Definition: UdpHubListener.h:160
uint16_t
quint16 uint16_t
Typedef for unsigned short. This type is guaranteed to be 16-bit.
Definition: jacktrip_types.h:71
UdpHubListener
Hub UDP listener on the Server.
Definition: UdpHubListener.h:69
addressPortPair::address
QString address
Definition: UdpHubListener.h:59
UdpHubListener::setConnectDefaultAudioPorts
void setConnectDefaultAudioPorts(bool connectDefaultAudioPorts)
Definition: UdpHubListener.h:85
UdpHubListener::signalRemoveThread
void signalRemoveThread(int id)
Definition: moc_UdpHubListener.cpp:172
UdpHubListener::setHubPatch
void setHubPatch(unsigned int p)
Definition: UdpHubListener.h:161
Settings
Class to set usage options and parse settings from input.
Definition: Settings.h:56
JackTripWorker
Prototype of the worker class that will be cloned through sending threads to the Thread Pool.
Definition: JackTripWorker.h:68
UdpHubListener::~UdpHubListener
virtual ~UdpHubListener()
Definition: UdpHubListener.cpp:97
UdpHubListener::releaseThread
int releaseThread(int id)
Definition: UdpHubListener.cpp:429
UdpHubListener::setUnderRunMode
void setUnderRunMode(JackTrip::underrunModeT UnderRunMode)
Definition: UdpHubListener.h:164
addressPortPair::port
int16_t port
Definition: UdpHubListener.h:60
JackTrip::underrunModeT
underrunModeT
Enum for the JackTrip Underrun Mode, when packets.
Definition: JackTrip.h:90
gServerUdpPort
const int gServerUdpPort
Public well-known UDP port to where the clients will connect.
Definition: jacktrip_globals.h:143
gMaxThreads
const int gMaxThreads
Maximum Threads that can be run at the same time.
Definition: jacktrip_globals.h:140
jacktrip_globals.h
UdpHubListener::setBufferQueueLength
void setBufferQueueLength(int BufferQueueLength)
Definition: UdpHubListener.h:165
UdpHubListener::getSettings
Settings * getSettings() const
Definition: UdpHubListener.h:88
JackTrip.h
addressPortPair
Definition: UdpHubListener.h:58
jacktrip_types.h
UdpHubListener::setSettings
void setSettings(Settings *s)
Definition: UdpHubListener.h:87
UdpHubListener::UdpHubListener
UdpHubListener(int server_port=gServerUdpPort)
Definition: UdpHubListener.cpp:56
int16_t
qint16 int16_t
Typedef for signed short. This type is guaranteed to be 16-bit.
Definition: jacktrip_types.h:80
UdpHubListener::Listening
void Listening()
Definition: moc_UdpHubListener.cpp:160