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 <winsock2.h>
43#include <ws2tcpip.h>
44#endif
45
46#ifndef __WIN_32__
47#include <netinet/in.h> //sockaddr_in{} and other Internet defns
48#include <arpa/inet.h> //inet(3) functions
49#include <netdb.h>
50//#include <tr1/memory> //for shared_ptr
51#endif
52
53#include <iostream>
54
55#include <QThread>
56#include <QHostAddress>
57#include <QMutex>
58#include <QMutexLocker>
59
60class JackTrip; // forward declaration
61
62
93class DataProtocol : public QThread
94{
95 Q_OBJECT;
96
97public:
98
99 //----------ENUMS------------------------------------------
104 EMPTY
105 };
106
108 enum runModeT {
110 RECEIVER
111 };
112 //---------------------------------------------------------
113
114
123 DataProtocol(JackTrip* jacktrip,
124 const runModeT runmode,
125 int bind_port, int peer_port);
126
128 virtual ~DataProtocol();
129
135 virtual void run() = 0;
136
138 virtual void stop() {
139 QMutexLocker lock(&mMutex);
140 mStopped = true;
141 }
142
146 void setAudioPacketSize(const size_t size_bytes){ mAudioPacketSize = size_bytes; }
147
151 size_t getAudioPacketSizeInBites() { return(mAudioPacketSize); }
152
157 virtual void setPeerAddress(const char* peerHostOrIP) = 0;
158
163 virtual void setPeerPort(int port) = 0;
164
165 //virtual void getPeerAddressFromFirstPacket(QHostAddress& peerHostAddress,
166 // uint16_t& port) = 0;
167
168#if defined (__WIN_32__)
169 virtual void setSocket(SOCKET &socket) = 0;
170#else
171 virtual void setSocket(int &socket) = 0;
172#endif
173
174 struct PktStat {
180 };
181 virtual bool getStats(PktStat*) {return false;}
182
183 virtual void setIssueSimulation(double /*loss*/, double /*jitter*/, double /*max_delay*/) {}
184 void setUseRtPriority(bool use) {mUseRtPriority = use;}
185
186signals:
187
188 void signalError(const char* error_message);
190 void signalCeaseTransmission(const QString &reason = "");
191
192protected:
193
197 runModeT getRunMode() const { return mRunMode; }
198
200 volatile bool mStopped;
202 volatile bool mHasPeerAddress;
204 volatile bool mHasPacketsToReceive;
205 QMutex mMutex;
206
207
208private:
209
210 int mLocalPort;
211 int mPeerPort;
212 const runModeT mRunMode;
213
214 struct sockaddr_in mLocalIPv4Addr;
215 struct sockaddr_in mPeerIPv4Addr;
216
219 static int sClientsRunning;
220
221 size_t mAudioPacketSize;
222
223
225protected:
226 //PacketHeader* mHeader; ///< Packet Header
229
230};
231
232#endif
Base class that defines the transmission protocol.
Definition: DataProtocol.h:94
void setUseRtPriority(bool use)
Definition: DataProtocol.h:184
bool mUseRtPriority
Definition: DataProtocol.h:228
JackTrip * mJackTrip
JackTrip mediator class.
Definition: DataProtocol.h:227
virtual void setIssueSimulation(double, double, double)
Definition: DataProtocol.h:183
volatile bool mStopped
Boolean stop the execution of the thread.
Definition: DataProtocol.h:200
void signalCeaseTransmission(const QString &reason="")
volatile bool mHasPacketsToReceive
Boolean that indicates if a packet was received.
Definition: DataProtocol.h:204
virtual void setSocket(int &socket)=0
virtual void setPeerPort(int port)=0
Set the peer incomming (receiving) port number.
virtual ~DataProtocol()
The class destructor.
Definition: DataProtocol.cpp:60
void signalReceivedConnectionFromPeer()
QMutex mMutex
Definition: DataProtocol.h:205
virtual void stop()
Stops the execution of the Thread.
Definition: DataProtocol.h:138
size_t getAudioPacketSizeInBites()
Get the size of the audio part of the packets.
Definition: DataProtocol.h:151
volatile bool mHasPeerAddress
Boolean to indicate if the RECEIVER is waiting to obtain peer address.
Definition: DataProtocol.h:202
virtual bool getStats(PktStat *)
Definition: DataProtocol.h:181
runModeT
Enum to define class modes, SENDER or RECEIVER.
Definition: DataProtocol.h:108
@ SENDER
Set class as a Sender (send packets)
Definition: DataProtocol.h:109
@ RECEIVER
Set class as a Receiver (receives packets)
Definition: DataProtocol.h:110
virtual void run()=0
Implements the thread loop.
void signalError(const char *error_message)
packetHeaderTypeT
Enum to define packet header types.
Definition: DataProtocol.h:101
@ DEFAULT
Default application header.
Definition: DataProtocol.h:102
@ EMPTY
Empty Header.
Definition: DataProtocol.h:104
@ JAMLINK
Header to use with Jamlinks.
Definition: DataProtocol.h:103
virtual void setPeerAddress(const char *peerHostOrIP)=0
Set the peer address.
void setAudioPacketSize(const size_t size_bytes)
Sets the size of the audio part of the packets.
Definition: DataProtocol.h:146
runModeT getRunMode() const
Get the Run Mode of the object.
Definition: DataProtocol.h:197
Main class to creates a SERVER (to listen) or a CLIENT (to connect to a listening server) to send aud...
Definition: JackTrip.h:72
quint32 uint32_t
Typedef for unsigned int. This type is guaranteed to be 32-bit.
Definition: jacktrip_types.h:73
Definition: DataProtocol.h:174
uint32_t outOfOrder
Definition: DataProtocol.h:177
uint32_t revived
Definition: DataProtocol.h:178
uint32_t statCount
Definition: DataProtocol.h:179
uint32_t lost
Definition: DataProtocol.h:176
uint32_t tot
Definition: DataProtocol.h:175