JackTrip
JackTripWorker.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 __JACKTRIPWORKER_H__
39 #define __JACKTRIPWORKER_H__
40 
41 #include <iostream>
42 
43 #include <QThreadPool>
44 #include <QObject>
45 #include <QEventLoop>
46 #include <QHostAddress>
47 #include <QMutex>
48 
49 #include "JackTrip.h"
50 #include "jacktrip_globals.h"
51 
52 //class JackTrip; // forward declaration
53 class UdpHubListener; // forward declaration
54 
55 
65 // Note that it is not possible to start run() as an event loop. That has to be implemented
66 // inside a QThread
67 class JackTripWorker : public QObject, public QRunnable
68 {
69  Q_OBJECT; // QRunnable is not a QObject, so I have to inherit from QObject as well
70 
71 public:
73  JackTripWorker(UdpHubListener* udphublistener, int BufferQueueLength = gDefaultQueueLength, JackTrip::underrunModeT UnderRunMode = JackTrip::WAVETABLE, QString clientName = "");
75  virtual ~JackTripWorker();
76 
79  void run();
82  bool isSpawning();
86  void setJackTrip(int id,
87  QString client_address,
88  uint16_t server_port,
89  uint16_t client_port,
90  int num_channels,
91  bool connectDefaultAudioPorts
92  );
94  void stopThread();
95  int getID()
96  {
97  return mID;
98  }
99 
100  void setBufferStrategy(int BufferStrategy) { mBufferStrategy = BufferStrategy; }
101  void setNetIssuesSimulation(double loss, double jitter, double delay_rel)
102  {
103  mSimulatedLossRate = loss;
104  mSimulatedJitterRate = jitter;
105  mSimulatedDelayRel = delay_rel;
106  }
107  void setBroadcast(int broadcast_queue) {mBroadcastQueue = broadcast_queue;}
108  void setUseRtUdpPriority(bool use) {mUseRtUdpPriority = use;}
109 
110  void setIOStatTimeout(int timeout) { mIOStatTimeout = timeout; }
111  void setIOStatStream(QSharedPointer<std::ofstream> statStream) { mIOStatStream = statStream; }
112 
113 private slots:
114  void slotTest()
115  { std::cout << "--- JackTripWorker TEST SLOT ---" << std::endl; }
116 
117 
118 signals:
119  void signalRemoveThread();
120 
121 private:
122  int setJackTripFromClientHeader(JackTrip& jacktrip);
123  JackTrip::connectionModeT getConnectionModeFromHeader();
124 
125  UdpHubListener* mUdpHubListener;
126  //QHostAddress mClientAddress; ///< Client Address
127  QString mClientAddress;
128  uint16_t mServerPort;
129  bool m_connectDefaultAudioPorts;
130 
132  uint16_t mClientPort;
133 
134  int mBufferQueueLength;
135  JackTrip::underrunModeT mUnderRunMode;
136  QString mClientName;
137 
140  volatile bool mSpawning;
141  QMutex mMutex;
142 
143  int mID;
144  int mNumChans;
145 
146  int mBufferStrategy;
147  int mBroadcastQueue;
148  double mSimulatedLossRate;
149  double mSimulatedJitterRate;
150  double mSimulatedDelayRel;
151  bool mUseRtUdpPriority;
152 
153  int mIOStatTimeout;
154  QSharedPointer<std::ofstream> mIOStatStream;
155 #ifdef WAIR // wair
156  int mNumNetRevChans;
157  bool mWAIR;
158 #endif // endwhere
159 };
160 
161 
162 #endif //__JACKTRIPWORKER_H__
Main class to creates a SERVER (to listen) or a CLIENT (to connect to a listening server) to send aud...
Definition: JackTrip.h:72
connectionModeT
Enum for Connection Mode (in packet header)
Definition: JackTrip.h:106
underrunModeT
Enum for the JackTrip Underrun Mode, when packets.
Definition: JackTrip.h:94
@ WAVETABLE
Loops on the last received packet.
Definition: JackTrip.h:95
Prototype of the worker class that will be cloned through sending threads to the Thread Pool.
Definition: JackTripWorker.h:68
JackTripWorker(UdpHubListener *udphublistener, int BufferQueueLength=gDefaultQueueLength, JackTrip::underrunModeT UnderRunMode=JackTrip::WAVETABLE, QString clientName="")
The class constructor.
Definition: JackTripWorker.cpp:61
int getID()
Definition: JackTripWorker.h:95
void setBufferStrategy(int BufferStrategy)
Definition: JackTripWorker.h:100
void setIOStatTimeout(int timeout)
Definition: JackTripWorker.h:110
bool isSpawning()
Check if the Thread is Spawning.
Definition: JackTripWorker.cpp:346
void setIOStatStream(QSharedPointer< std::ofstream > statStream)
Definition: JackTripWorker.h:111
virtual ~JackTripWorker()
The class destructor.
Definition: JackTripWorker.cpp:89
void setNetIssuesSimulation(double loss, double jitter, double delay_rel)
Definition: JackTripWorker.h:101
void setUseRtUdpPriority(bool use)
Definition: JackTripWorker.h:108
void signalRemoveThread()
Definition: moc_JackTripWorker.cpp:140
void run()
Implements the Thread Loop. To start the thread, call start() ( DO NOT CALL run() ).
Definition: JackTripWorker.cpp:119
void setBroadcast(int broadcast_queue)
Definition: JackTripWorker.h:107
void stopThread()
Stop and remove thread from pool.
Definition: JackTripWorker.cpp:354
void setJackTrip(int id, QString client_address, uint16_t server_port, uint16_t client_port, int num_channels, bool connectDefaultAudioPorts)
Sets the JackTripWorker properties.
Definition: JackTripWorker.cpp:96
Hub UDP listener on the Server.
Definition: UdpHubListener.h:70
const int gDefaultQueueLength
Definition: jacktrip_globals.h:86
quint16 uint16_t
Typedef for unsigned short. This type is guaranteed to be 16-bit.
Definition: jacktrip_types.h:71