00001 //***************************************************************** 00002 /* 00003 JackTrip: A System for High-Quality Audio Network Performance 00004 over the Internet 00005 00006 Copyright (c) 2008 Juan-Pablo Caceres, Chris Chafe. 00007 SoundWIRE group at CCRMA, Stanford University. 00008 00009 Permission is hereby granted, free of charge, to any person 00010 obtaining a copy of this software and associated documentation 00011 files (the "Software"), to deal in the Software without 00012 restriction, including without limitation the rights to use, 00013 copy, modify, merge, publish, distribute, sublicense, and/or sell 00014 copies of the Software, and to permit persons to whom the 00015 Software is furnished to do so, subject to the following 00016 conditions: 00017 00018 The above copyright notice and this permission notice shall be 00019 included in all copies or substantial portions of the Software. 00020 00021 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00023 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00024 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00025 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00026 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00027 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 OTHER DEALINGS IN THE SOFTWARE. 00029 */ 00030 //***************************************************************** 00031 00038 #ifndef __DATAPROTOCOL_H__ 00039 #define __DATAPROTOCOL_H__ 00040 00041 //#include <sys/socket.h> //basic socket definitions 00042 #include <netinet/in.h> //sockaddr_in{} and other Internet defns 00043 #include <arpa/inet.h> //inet(3) functions 00044 #include <netdb.h> 00045 #include <tr1/memory> //for shared_ptr 00046 00047 #include <QThread> 00048 #include <QHostAddress> 00049 00050 class JackTrip; // forward declaration 00051 00052 00083 class DataProtocol : public QThread 00084 { 00085 public: 00086 00087 //----------ENUMS------------------------------------------ 00089 enum packetHeaderTypeT { 00090 DEFAULT, 00091 JAMLINK, 00092 EMPTY 00093 }; 00094 00096 enum runModeT { 00097 SENDER, 00098 RECEIVER 00099 }; 00100 //--------------------------------------------------------- 00101 00102 00111 DataProtocol(JackTrip* jacktrip, 00112 const runModeT runmode, 00113 int bind_port, int peer_port); 00114 00116 virtual ~DataProtocol(); 00117 00123 virtual void run() = 0; 00124 00126 virtual void stop() { mStopped = true; }; 00127 00131 void setAudioPacketSize(const size_t size_bytes){ mAudioPacketSize = size_bytes; }; 00132 00136 size_t getAudioPacketSizeInBites() { return(mAudioPacketSize); }; 00137 00142 virtual void setPeerAddress(const char* peerHostOrIP) = 0; 00143 00148 virtual void setPeerPort(int port) = 0; 00149 00150 //virtual void getPeerAddressFromFirstPacket(QHostAddress& peerHostAddress, 00151 // uint16_t& port) = 0; 00152 00153 protected: 00154 00158 runModeT getRunMode() const { return mRunMode; }; 00159 00161 volatile bool mStopped; 00163 volatile bool mHasPeerAddress; 00165 volatile bool mHasPacketsToReceive; 00166 00167 00168 private: 00169 00170 int mLocalPort; 00171 int mPeerPort; 00172 const runModeT mRunMode; 00173 00174 struct sockaddr_in mLocalIPv4Addr; 00175 struct sockaddr_in mPeerIPv4Addr; 00176 00179 static int sClientsRunning; 00180 00181 size_t mAudioPacketSize; 00182 00183 00185 protected: 00186 //PacketHeader* mHeader; ///< Packet Header 00187 JackTrip* mJackTrip; 00188 00189 }; 00190 00191 #endif