JackTrip

DataProtocol.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 __DATAPROTOCOL_H__
39 #define __DATAPROTOCOL_H__
40
41 #ifdef __WIN_32__
42 #include <winsock.h>
43 #endif
44
45 #ifndef __WIN_32__
46 #include <netinet/in.h> //sockaddr_in{} and other Internet defns
47 #include <arpa/inet.h> //inet(3) functions
48 #include <netdb.h>
49 //#include <tr1/memory> //for shared_ptr
50 #endif
51
52 #include <iostream>
53
54 #include <QThread>
55 #include <QHostAddress>
56 #include <QMutex>
57 #include <QMutexLocker>
58
59 class JackTrip; // forward declaration
60
61
92 class DataProtocol : public QThread
93 {
94 Q_OBJECT;
95
96 public:
97
98 //----------ENUMS------------------------------------------
100 enum packetHeaderTypeT {
101 DEFAULT,
102 JAMLINK,
103 EMPTY
104 };
105
107 enum runModeT {
108 SENDER,
109 RECEIVER
110 };
111 //---------------------------------------------------------
112
113
122 DataProtocol(JackTrip* jacktrip,
123 const runModeT runmode,
124 int bind_port, int peer_port);
125
127 virtual ~DataProtocol();
128
134 virtual void run() = 0;
135
137 virtual void stop() {
138 QMutexLocker lock(&mMutex);
139 mStopped = true;
140 }
141
145 void setAudioPacketSize(const size_t size_bytes){ mAudioPacketSize = size_bytes; }
146
150 size_t getAudioPacketSizeInBites() { return(mAudioPacketSize); }
151
156 virtual void setPeerAddress(const char* peerHostOrIP) = 0;
157
162 virtual void setPeerPort(int port) = 0;
163
164 //virtual void getPeerAddressFromFirstPacket(QHostAddress& peerHostAddress,
165 // uint16_t& port) = 0;
166
167
168 signals:
169
170 void signalError(const char* error_message);
171 void signalReceivedConnectionFromPeer();
172
173
174 protected:
175
179 runModeT getRunMode() const { return mRunMode; }
180
182 volatile bool mStopped;
184 volatile bool mHasPeerAddress;
186 volatile bool mHasPacketsToReceive;
187 QMutex mMutex;
188
189
190 private:
191
192 int mLocalPort;
193 int mPeerPort;
194 const runModeT mRunMode;
195
196 struct sockaddr_in mLocalIPv4Addr;
197 struct sockaddr_in mPeerIPv4Addr;
198
201 static int sClientsRunning;
202
203 size_t mAudioPacketSize;
204
205
207 protected:
208 //PacketHeader* mHeader; ///< Packet Header
209 JackTrip* mJackTrip;
210
211 };
212
213 #endif
DataProtocol::EMPTY
Empty Header.
Definition: DataProtocol.h:103
DataProtocol::SENDER
Set class as a Sender (send packets)
Definition: DataProtocol.h:108
DataProtocol::signalReceivedConnectionFromPeer
void signalReceivedConnectionFromPeer()
Definition: moc_DataProtocol.cpp:144
DataProtocol::mHasPeerAddress
volatile bool mHasPeerAddress
Boolean to indicate if the RECEIVER is waiting to obtain peer address.
Definition: DataProtocol.h:184
DataProtocol::setPeerAddress
virtual void setPeerAddress(const char *peerHostOrIP)=0
Set the peer address.
DataProtocol::mJackTrip
JackTrip * mJackTrip
JackTrip mediator class.
Definition: DataProtocol.h:209
DataProtocol::packetHeaderTypeT
packetHeaderTypeT
Enum to define packet header types.
Definition: DataProtocol.h:100
DataProtocol::setPeerPort
virtual void setPeerPort(int port)=0
Set the peer incomming (receiving) port number.
DataProtocol::JAMLINK
Header to use with Jamlinks.
Definition: DataProtocol.h:102
DataProtocol::getRunMode
runModeT getRunMode() const
Get the Run Mode of the object.
Definition: DataProtocol.h:179
DataProtocol::DataProtocol
DataProtocol(JackTrip *jacktrip, const runModeT runmode, int bind_port, int peer_port)
The class constructor.
Definition: DataProtocol.cpp:52
DataProtocol::mHasPacketsToReceive
volatile bool mHasPacketsToReceive
Boolean that indicates if a packet was received.
Definition: DataProtocol.h:186
DataProtocol::~DataProtocol
virtual ~DataProtocol()
The class destructor.
Definition: DataProtocol.cpp:60
DataProtocol::mMutex
QMutex mMutex
Definition: DataProtocol.h:187
DataProtocol::setAudioPacketSize
void setAudioPacketSize(const size_t size_bytes)
Sets the size of the audio part of the packets.
Definition: DataProtocol.h:145
DataProtocol
Base class that defines the transmission protocol.
Definition: DataProtocol.h:92
DataProtocol::stop
virtual void stop()
Stops the execution of the Thread.
Definition: DataProtocol.h:137
DataProtocol::run
virtual void run()=0
Implements the thread loop.
DataProtocol::getAudioPacketSizeInBites
size_t getAudioPacketSizeInBites()
Get the size of the audio part of the packets.
Definition: DataProtocol.h:150
DataProtocol::DEFAULT
Default application header.
Definition: DataProtocol.h:101
DataProtocol::runModeT
runModeT
Enum to define class modes, SENDER or RECEIVER.
Definition: DataProtocol.h:107
DataProtocol::mStopped
volatile bool mStopped
Boolean stop the execution of the thread.
Definition: DataProtocol.h:182
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
DataProtocol::RECEIVER
Set class as a Receiver (receives packets)
Definition: DataProtocol.h:109
DataProtocol::signalError
void signalError(const char *error_message)
Definition: moc_DataProtocol.cpp:137