jrtplib 3.7.1
|
00001 /* 00002 00003 This class allows for jrtp to process packets without sending them out 00004 anywhere. 00005 The incoming messages are handed in to jrtp through the TransmissionParams 00006 and can be retreived from jrtp through the normal polling mecanisms. 00007 The outgoing RTP/RTCP packets are given to jrtp through the normal 00008 session->SendPacket() and those packets are handed back out to the 00009 client through a callback function (packet_ready_cb). 00010 00011 example usage : Allows for integration of RTP into gstreamer. 00012 00013 Copyright (c) 2005 Philippe Khalaf <burger@speedy.org> 00014 00015 This file is a part of JRTPLIB 00016 Copyright (c) 1999-2004 Jori Liesenborgs 00017 00018 Contact: jori.liesenborgs@gmail.com 00019 00020 This library was developed at the "Expertisecentrum Digitale Media" 00021 (http://www.edm.luc.ac.be), a research center of the "Limburgs Universitair 00022 Centrum" (http://www.luc.ac.be). The library is based upon work done for 00023 my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 00024 00025 Permission is hereby granted, free of charge, to any person obtaining a 00026 copy of this software and associated documentation files (the "Software"), 00027 to deal in the Software without restriction, including without limitation 00028 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00029 and/or sell copies of the Software, and to permit persons to whom the 00030 Software is furnished to do so, subject to the following conditions: 00031 00032 The above copyright notice and this permission notice shall be included 00033 in all copies or substantial portions of the Software. 00034 00035 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00036 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00037 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00038 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00039 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00040 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 00041 IN THE SOFTWARE. 00042 00043 */ 00044 00045 #ifndef RTPFAKETRANSMITTER_H 00046 00047 #define RTPFAKETRANSMITTER_H 00048 00049 #include "rtpconfig.h" 00050 00051 #include "rtptransmitter.h" 00052 #include "rtpipv4destination.h" 00053 #include "rtphashtable.h" 00054 #include "rtpkeyhashtable.h" 00055 #include <list> 00056 00057 #ifdef RTP_SUPPORT_THREAD 00058 #include <jmutex.h> 00059 #endif // RTP_SUPPORT_THREAD 00060 00061 #define RTPFAKETRANS_HASHSIZE 8317 00062 #define RTPFAKETRANS_DEFAULTPORTBASE 5000 00063 00064 // Definition of a callback that is called when a packet is ready for sending 00065 // params (*data, data_len, dest_addr, dest_port, rtp [1 if rtp, 0 if rtcp]) 00066 typedef void(*packet_ready_cb)(void*, uint8_t*, uint16_t, uint32_t, uint16_t, int rtp); 00067 00068 class RTPFakeTransmissionParams : public RTPTransmissionParams 00069 { 00070 public: 00071 RTPFakeTransmissionParams():RTPTransmissionParams(RTPTransmitter::UserDefinedProto) { portbase = RTPFAKETRANS_DEFAULTPORTBASE; bindIP = 0; multicastTTL = 1; currentdata = NULL;} 00072 void SetBindIP(uint32_t ip) { bindIP = ip; } 00073 void SetPortbase(uint16_t pbase) { portbase = pbase; } 00074 void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; } 00075 void SetLocalIPList(std::list<uint32_t> &iplist) { localIPs = iplist; } 00076 void ClearLocalIPList() { localIPs.clear(); } 00077 void SetCurrentData(uint8_t *data) { currentdata = data; } 00078 void SetCurrentDataLen(uint16_t len) { currentdatalen = len; } 00079 void SetCurrentDataAddr(uint32_t addr) { currentdataaddr = addr; } 00080 void SetCurrentDataPort(uint16_t port) { currentdataport = port; } 00081 void SetCurrentDataType(bool type) { currentdatatype = type; } 00082 void SetPacketReadyCB(packet_ready_cb cb) { packetreadycb = cb; }; 00083 void SetPacketReadyCBData(void *data) { packetreadycbdata = data; }; 00084 uint32_t GetBindIP() const { return bindIP; } 00085 uint16_t GetPortbase() const { return portbase; } 00086 uint8_t GetMulticastTTL() const { return multicastTTL; } 00087 const std::list<uint32_t> &GetLocalIPList() const { return localIPs; } 00088 uint8_t* GetCurrentData() const { return currentdata; } 00089 uint16_t GetCurrentDataLen() const { return currentdatalen; } 00090 uint32_t GetCurrentDataAddr() const { return currentdataaddr; } 00091 uint16_t GetCurrentDataPort() const { return currentdataport; } 00092 bool GetCurrentDataType() const { return currentdatatype; } 00093 packet_ready_cb GetPacketReadyCB() const { return packetreadycb; } 00094 void* GetPacketReadyCBData() const { return packetreadycbdata; } 00095 private: 00096 uint16_t portbase; 00097 uint32_t bindIP; 00098 std::list<uint32_t> localIPs; 00099 uint8_t multicastTTL; 00100 uint8_t* currentdata; 00101 uint16_t currentdatalen; 00102 uint32_t currentdataaddr; 00103 uint16_t currentdataport; 00104 bool currentdatatype; 00105 packet_ready_cb packetreadycb; 00106 void *packetreadycbdata; 00107 }; 00108 00109 class RTPFakeTransmissionInfo : public RTPTransmissionInfo 00110 { 00111 public: 00112 RTPFakeTransmissionInfo(std::list<uint32_t> iplist, 00113 RTPFakeTransmissionParams *transparams) : 00114 RTPTransmissionInfo(RTPTransmitter::UserDefinedProto) 00115 { localIPlist = iplist; params = transparams; } 00116 00117 ~RTPFakeTransmissionInfo() { } 00118 std::list<uint32_t> GetLocalIPList() const { return localIPlist; } 00119 RTPFakeTransmissionParams* GetTransParams() { return params; } 00120 private: 00121 std::list<uint32_t> localIPlist; 00122 RTPFakeTransmissionParams *params; 00123 }; 00124 00125 class RTPFakeTrans_GetHashIndex_IPv4Dest 00126 { 00127 public: 00128 static int GetIndex(const RTPIPv4Destination &d) { return d.GetIP()%RTPFAKETRANS_HASHSIZE; } 00129 }; 00130 00131 class RTPFakeTrans_GetHashIndex_uint32_t 00132 { 00133 public: 00134 static int GetIndex(const uint32_t &k) { return k%RTPFAKETRANS_HASHSIZE; } 00135 }; 00136 00137 #define RTPFAKETRANS_HEADERSIZE (20+8) 00138 00139 class RTPFakeTransmitter : public RTPTransmitter 00140 { 00141 public: 00142 RTPFakeTransmitter(RTPMemoryManager *mgr); 00143 ~RTPFakeTransmitter(); 00144 00145 int Init(bool treadsafe); 00146 int Create(size_t maxpacksize,const RTPTransmissionParams *transparams); 00147 void Destroy(); 00148 RTPTransmissionInfo *GetTransmissionInfo(); 00149 00150 int GetLocalHostName(uint8_t *buffer,size_t *bufferlength); 00151 bool ComesFromThisTransmitter(const RTPAddress *addr); 00152 size_t GetHeaderOverhead() { return RTPFAKETRANS_HEADERSIZE; } 00153 00154 int Poll(); 00155 int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0); 00156 int AbortWait(); 00157 00158 int SendRTPData(const void *data,size_t len); 00159 int SendRTCPData(const void *data,size_t len); 00160 00161 int AddDestination(const RTPAddress &addr); 00162 int DeleteDestination(const RTPAddress &addr); 00163 void ClearDestinations(); 00164 00165 bool SupportsMulticasting(); 00166 int JoinMulticastGroup(const RTPAddress &addr); 00167 int LeaveMulticastGroup(const RTPAddress &addr); 00168 void LeaveAllMulticastGroups(); 00169 00170 int SetReceiveMode(RTPTransmitter::ReceiveMode m); 00171 int AddToIgnoreList(const RTPAddress &addr); 00172 int DeleteFromIgnoreList(const RTPAddress &addr); 00173 void ClearIgnoreList(); 00174 int AddToAcceptList(const RTPAddress &addr); 00175 int DeleteFromAcceptList(const RTPAddress &addr); 00176 void ClearAcceptList(); 00177 int SetMaximumPacketSize(size_t s); 00178 00179 bool NewDataAvailable(); 00180 RTPRawPacket *GetNextPacket(); 00181 #ifdef RTPDEBUG 00182 void Dump(); 00183 #endif // RTPDEBUG 00184 private: 00185 int CreateLocalIPList(); 00186 bool GetLocalIPList_Interfaces(); 00187 void GetLocalIPList_DNS(); 00188 void AddLoopbackAddress(); 00189 void FlushPackets(); 00190 int FakePoll(); 00191 int ProcessAddAcceptIgnoreEntry(uint32_t ip,uint16_t port); 00192 int ProcessDeleteAcceptIgnoreEntry(uint32_t ip,uint16_t port); 00193 #ifdef RTP_SUPPORT_IPV4MULTICAST 00194 bool SetMulticastTTL(uint8_t ttl); 00195 #endif // RTP_SUPPORT_IPV4MULTICAST 00196 bool ShouldAcceptData(uint32_t srcip,uint16_t srcport); 00197 void ClearAcceptIgnoreInfo(); 00198 00199 RTPFakeTransmissionParams *params; 00200 bool init; 00201 bool created; 00202 bool waitingfordata; 00203 std::list<uint32_t> localIPs; 00204 uint16_t portbase; 00205 uint8_t multicastTTL; 00206 RTPTransmitter::ReceiveMode receivemode; 00207 00208 uint8_t *localhostname; 00209 size_t localhostnamelength; 00210 00211 RTPHashTable<const RTPIPv4Destination,RTPFakeTrans_GetHashIndex_IPv4Dest,RTPFAKETRANS_HASHSIZE> destinations; 00212 #ifdef RTP_SUPPORT_IPV4MULTICAST 00213 // RTPHashTable<const uint32_t,RTPFakeTrans_GetHashIndex_uint32_t,RTPFAKETRANS_HASHSIZE> multicastgroups; 00214 #endif // RTP_SUPPORT_IPV4MULTICAST 00215 std::list<RTPRawPacket*> rawpacketlist; 00216 00217 bool supportsmulticasting; 00218 size_t maxpacksize; 00219 00220 class PortInfo 00221 { 00222 public: 00223 PortInfo() { all = false; } 00224 00225 bool all; 00226 std::list<uint16_t> portlist; 00227 }; 00228 00229 RTPKeyHashTable<const uint32_t,PortInfo*,RTPFakeTrans_GetHashIndex_uint32_t,RTPFAKETRANS_HASHSIZE> acceptignoreinfo; 00230 00231 int CreateAbortDescriptors(); 00232 void DestroyAbortDescriptors(); 00233 void AbortWaitInternal(); 00234 #ifdef RTP_SUPPORT_THREAD 00235 JMutex mainmutex,waitmutex; 00236 int threadsafe; 00237 #endif // RTP_SUPPORT_THREAD 00238 }; 00239 00240 #endif // RTPFakeTRANSMITTER_H 00241