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 UdpMasterListener; // 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(UdpMasterListener* udpmasterlistener, int BufferQueueLength = gDefaultQueueLength, JackTrip::underrunModeT UnderRunMode = JackTrip::WAVETABLE);
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 
101 private slots:
102  void slotTest()
103  { std::cout << "--- JackTripWorker TEST SLOT ---" << std::endl; }
104 
105 
106 signals:
107  void signalRemoveThread();
108 
109 
110 private:
111  int setJackTripFromClientHeader(JackTrip& jacktrip);
112  JackTrip::connectionModeT getConnectionModeFromHeader();
113 
114  UdpMasterListener* mUdpMasterListener;
115  //QHostAddress mClientAddress; ///< Client Address
116  QString mClientAddress;
117  uint16_t mServerPort;
118  bool m_connectDefaultAudioPorts;
119 
121  uint16_t mClientPort;
122 
125  volatile bool mSpawning;
126  QMutex mMutex;
127  JackTrip::underrunModeT mUnderRunMode;
128  int mBufferQueueLength;
129 
130  int mID;
131  int mNumChans;
132 #ifdef WAIR // wair
133  int mNumNetRevChans;
134  bool mWAIR;
135 #endif // endwhere
136 };
137 
138 
139 #endif //__JACKTRIPWORKER_H__
JackTrip::WAVETABLE
@ WAVETABLE
Loops on the last received packet.
Definition: JackTrip.h:91
JackTripWorker::getID
int getID()
Definition: JackTripWorker.h:95
JackTripWorker::JackTripWorker
JackTripWorker(UdpMasterListener *udpmasterlistener, int BufferQueueLength=gDefaultQueueLength, JackTrip::underrunModeT UnderRunMode=JackTrip::WAVETABLE)
The class constructor.
Definition: JackTripWorker.cpp:60
uint16_t
quint16 uint16_t
Typedef for unsigned short. This type is guaranteed to be 16-bit.
Definition: jacktrip_types.h:71
JackTrip
Main class to creates a SERVER (to listen) or a CLIENT (to connect to a listening server) to send aud...
Definition: JackTrip.h:67
JackTripWorker::isSpawning
bool isSpawning()
Check if the Thread is Spawning.
Definition: JackTripWorker.cpp:323
JackTripWorker::setJackTrip
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:87
JackTripWorker
Prototype of the worker class that will be cloned through sending threads to the Thread Pool.
Definition: JackTripWorker.h:67
JackTrip::underrunModeT
underrunModeT
Enum for the JackTrip Underrun Mode, when packets.
Definition: JackTrip.h:90
JackTripWorker::~JackTripWorker
virtual ~JackTripWorker()
The class destructor.
Definition: JackTripWorker.cpp:80
JackTrip::connectionModeT
connectionModeT
Enum for Connection Mode (in packet header)
Definition: JackTrip.h:102
jacktrip_globals.h
UdpMasterListener
Master UDP listener on the Server.
Definition: UdpMasterListener.h:67
JackTrip.h
JackTripWorker::run
void run()
Implements the Thread Loop. To start the thread, call start() ( DO NOT CALL run() ).
Definition: JackTripWorker.cpp:110
JackTripWorker::stopThread
void stopThread()
Stop and remove thread from pool.
Definition: JackTripWorker.cpp:331
JackTripWorker::signalRemoveThread
void signalRemoveThread()
Definition: moc_JackTripWorker.cpp:139
gDefaultQueueLength
const int gDefaultQueueLength
Definition: jacktrip_globals.h:85