rtpudpv4transmitter.h

Go to the documentation of this file.
00001 /*
00002 
00003   This file is a part of JRTPLIB
00004   Copyright (c) 1999-2007 Jori Liesenborgs
00005 
00006   Contact: jori.liesenborgs@gmail.com
00007 
00008   This library was developed at the "Expertisecentrum Digitale Media"
00009   (http://www.edm.uhasselt.be), a research center of the Hasselt University
00010   (http://www.uhasselt.be). The library is based upon work done for 
00011   my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
00012 
00013   Permission is hereby granted, free of charge, to any person obtaining a
00014   copy of this software and associated documentation files (the "Software"),
00015   to deal in the Software without restriction, including without limitation
00016   the rights to use, copy, modify, merge, publish, distribute, sublicense,
00017   and/or sell copies of the Software, and to permit persons to whom the
00018   Software is furnished to do so, subject to the following conditions:
00019 
00020   The above copyright notice and this permission notice shall be included
00021   in all copies or substantial portions of the Software.
00022 
00023   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00024   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00026   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00028   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00029   IN THE SOFTWARE.
00030 
00031 */
00032 
00037 #ifndef RTPUDPV4TRANSMITTER_H
00038 
00039 #define RTPUDPV4TRANSMITTER_H
00040 
00041 #include "rtpconfig.h"
00042 #include "rtptransmitter.h"
00043 #include "rtpipv4destination.h"
00044 #include "rtphashtable.h"
00045 #include "rtpkeyhashtable.h"
00046 #include <list>
00047 
00048 #ifdef RTP_SUPPORT_THREAD
00049         #include <jmutex.h>
00050 #endif // RTP_SUPPORT_THREAD
00051 
00052 #define RTPUDPV4TRANS_HASHSIZE                                                                  8317
00053 #define RTPUDPV4TRANS_DEFAULTPORTBASE                                                           5000
00054 
00055 #define RTPUDPV4TRANS_RTPRECEIVEBUFFER                                                  32768
00056 #define RTPUDPV4TRANS_RTCPRECEIVEBUFFER                                                 32768
00057 #define RTPUDPV4TRANS_RTPTRANSMITBUFFER                                                 32768
00058 #define RTPUDPV4TRANS_RTCPTRANSMITBUFFER                                                32768
00059 
00061 class RTPUDPv4TransmissionParams : public RTPTransmissionParams
00062 {
00063 public:
00064         RTPUDPv4TransmissionParams():RTPTransmissionParams(RTPTransmitter::IPv4UDPProto)        { portbase = RTPUDPV4TRANS_DEFAULTPORTBASE; bindIP = 0; multicastTTL = 1; mcastifaceIP = 0; rtpsendbuf = RTPUDPV4TRANS_RTPTRANSMITBUFFER; rtprecvbuf= RTPUDPV4TRANS_RTPRECEIVEBUFFER; rtcpsendbuf = RTPUDPV4TRANS_RTCPTRANSMITBUFFER; rtcprecvbuf = RTPUDPV4TRANS_RTCPRECEIVEBUFFER; }
00065 
00067         void SetBindIP(uint32_t ip)                                                                     { bindIP = ip; }
00068 
00070         void SetMulticastInterfaceIP(uint32_t ip)                                       { mcastifaceIP = ip; }
00071 
00073         void SetPortbase(uint16_t pbase)                                                        { portbase = pbase; }
00074 
00076         void SetMulticastTTL(uint8_t mcastTTL)                                          { multicastTTL = mcastTTL; }
00077 
00079         void SetLocalIPList(std::list<uint32_t> &iplist)                        { localIPs = iplist; } 
00080 
00085         void ClearLocalIPList()                                                                         { localIPs.clear(); }
00086 
00088         uint32_t GetBindIP() const                                                                      { return bindIP; }
00089 
00091         uint32_t GetMulticastInterfaceIP() const                                        { return mcastifaceIP; }
00092 
00094         uint16_t GetPortbase() const                                                            { return portbase; }
00095 
00097         uint8_t GetMulticastTTL() const                                                         { return multicastTTL; }
00098 
00100         const std::list<uint32_t> &GetLocalIPList() const                       { return localIPs; }
00101 
00103         void SetRTPSendBuffer(int s)                                                            { rtpsendbuf = s; }
00104 
00106         void SetRTPReceiveBuffer(int s)                                                         { rtprecvbuf = s; }
00107 
00109         void SetRTCPSendBuffer(int s)                                                           { rtcpsendbuf = s; }
00110 
00112         void SetRTCPReceiveBuffer(int s)                                                        { rtcprecvbuf = s; }
00113 
00115         int GetRTPSendBuffer() const                                                            { return rtpsendbuf; }
00116 
00118         int GetRTPReceiveBuffer() const                                                         { return rtprecvbuf; }
00119 
00121         int GetRTCPSendBuffer() const                                                           { return rtcpsendbuf; }
00122 
00124         int GetRTCPReceiveBuffer() const                                                        { return rtcprecvbuf; }
00125 private:
00126         uint16_t portbase;
00127         uint32_t bindIP, mcastifaceIP;
00128         std::list<uint32_t> localIPs;
00129         uint8_t multicastTTL;
00130         int rtpsendbuf, rtprecvbuf;
00131         int rtcpsendbuf, rtcprecvbuf;
00132 };
00133 
00135 class RTPUDPv4TransmissionInfo : public RTPTransmissionInfo
00136 {
00137 public:
00138 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00139         RTPUDPv4TransmissionInfo(std::list<uint32_t> iplist,int rtpsock,int rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv4UDPProto) 
00140 #else
00141         RTPUDPv4TransmissionInfo(std::list<uint32_t> iplist,SOCKET rtpsock,SOCKET rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv4UDPProto) 
00142 #endif  // WIN32
00143                                                                                                                         { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; }
00144 
00145         ~RTPUDPv4TransmissionInfo()                                                             { }
00146         
00148         std::list<uint32_t> GetLocalIPList() const                              { return localIPlist; }
00149 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00150 
00151         int GetRTPSocket() const                                                                { return rtpsocket; }
00152 
00154         int GetRTCPSocket() const                                                               { return rtcpsocket; }
00155 #else
00156         SOCKET GetRTPSocket() const                                                             { return rtpsocket; }
00157         SOCKET GetRTCPSocket() const                                                    { return rtcpsocket; }
00158 #endif // WIN32
00159 private:
00160         std::list<uint32_t> localIPlist;
00161 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00162         int rtpsocket,rtcpsocket;
00163 #else
00164         SOCKET rtpsocket,rtcpsocket;
00165 #endif // WIN32
00166 };
00167         
00168 class RTPUDPv4Trans_GetHashIndex_IPv4Dest
00169 {
00170 public:
00171         static int GetIndex(const RTPIPv4Destination &d)                                                        { return d.GetIP()%RTPUDPV4TRANS_HASHSIZE; }
00172 };
00173 
00174 class RTPUDPv4Trans_GetHashIndex_uint32_t
00175 {
00176 public:
00177         static int GetIndex(const uint32_t &k)                                                                  { return k%RTPUDPV4TRANS_HASHSIZE; }
00178 };
00179 
00180 #define RTPUDPV4TRANS_HEADERSIZE                                                (20+8)
00181         
00189 class RTPUDPv4Transmitter : public RTPTransmitter
00190 {
00191 public:
00192         RTPUDPv4Transmitter(RTPMemoryManager *mgr);
00193         ~RTPUDPv4Transmitter();
00194 
00195         int Init(bool treadsafe);
00196         int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
00197         void Destroy();
00198         RTPTransmissionInfo *GetTransmissionInfo();
00199 
00200         int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
00201         bool ComesFromThisTransmitter(const RTPAddress *addr);
00202         size_t GetHeaderOverhead()                                                      { return RTPUDPV4TRANS_HEADERSIZE; }
00203         
00204         int Poll();
00205         int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
00206         int AbortWait();
00207         
00208         int SendRTPData(const void *data,size_t len);   
00209         int SendRTCPData(const void *data,size_t len);
00210 
00211         int AddDestination(const RTPAddress &addr);
00212         int DeleteDestination(const RTPAddress &addr);
00213         void ClearDestinations();
00214 
00215         bool SupportsMulticasting();
00216         int JoinMulticastGroup(const RTPAddress &addr);
00217         int LeaveMulticastGroup(const RTPAddress &addr);
00218         void LeaveAllMulticastGroups();
00219 
00220         int SetReceiveMode(RTPTransmitter::ReceiveMode m);
00221         int AddToIgnoreList(const RTPAddress &addr);
00222         int DeleteFromIgnoreList(const RTPAddress &addr);
00223         void ClearIgnoreList();
00224         int AddToAcceptList(const RTPAddress &addr);
00225         int DeleteFromAcceptList(const RTPAddress &addr);
00226         void ClearAcceptList();
00227         int SetMaximumPacketSize(size_t s);     
00228         
00229         bool NewDataAvailable();
00230         RTPRawPacket *GetNextPacket();
00231 #ifdef RTPDEBUG
00232         void Dump();
00233 #endif // RTPDEBUG
00234 private:
00235         int CreateLocalIPList();
00236         bool GetLocalIPList_Interfaces();
00237         void GetLocalIPList_DNS();
00238         void AddLoopbackAddress();
00239         void FlushPackets();
00240         int PollSocket(bool rtp);
00241         int ProcessAddAcceptIgnoreEntry(uint32_t ip,uint16_t port);
00242         int ProcessDeleteAcceptIgnoreEntry(uint32_t ip,uint16_t port);
00243 #ifdef RTP_SUPPORT_IPV4MULTICAST
00244         bool SetMulticastTTL(uint8_t ttl);
00245 #endif // RTP_SUPPORT_IPV4MULTICAST
00246         bool ShouldAcceptData(uint32_t srcip,uint16_t srcport);
00247         void ClearAcceptIgnoreInfo();
00248         
00249         bool init;
00250         bool created;
00251         bool waitingfordata;
00252 #if (defined(WIN32) || defined(_WIN32_WCE))
00253         SOCKET rtpsock,rtcpsock;
00254 #else // not using winsock
00255         int rtpsock,rtcpsock;
00256 #endif // WIN32
00257         uint32_t bindIP, mcastifaceIP;
00258         std::list<uint32_t> localIPs;
00259         uint16_t portbase;
00260         uint8_t multicastTTL;
00261         RTPTransmitter::ReceiveMode receivemode;
00262 
00263         uint8_t *localhostname;
00264         size_t localhostnamelength;
00265         
00266         RTPHashTable<const RTPIPv4Destination,RTPUDPv4Trans_GetHashIndex_IPv4Dest,RTPUDPV4TRANS_HASHSIZE> destinations;
00267 #ifdef RTP_SUPPORT_IPV4MULTICAST
00268         RTPHashTable<const uint32_t,RTPUDPv4Trans_GetHashIndex_uint32_t,RTPUDPV4TRANS_HASHSIZE> multicastgroups;
00269 #endif // RTP_SUPPORT_IPV4MULTICAST
00270         std::list<RTPRawPacket*> rawpacketlist;
00271 
00272         bool supportsmulticasting;
00273         size_t maxpacksize;
00274 
00275         class PortInfo
00276         {
00277         public:
00278                 PortInfo() { all = false; }
00279                 
00280                 bool all;
00281                 std::list<uint16_t> portlist;
00282         };
00283 
00284         RTPKeyHashTable<const uint32_t,PortInfo*,RTPUDPv4Trans_GetHashIndex_uint32_t,RTPUDPV4TRANS_HASHSIZE> acceptignoreinfo;
00285 
00286         // notification descriptors for AbortWait (0 is for reading, 1 for writing)
00287 #if (defined(WIN32) || defined(_WIN32_WCE))
00288         SOCKET abortdesc[2];
00289 #else
00290         int abortdesc[2];
00291 #endif // WIN32
00292         int CreateAbortDescriptors();
00293         void DestroyAbortDescriptors();
00294         void AbortWaitInternal();
00295 #ifdef RTP_SUPPORT_THREAD
00296         JMutex mainmutex,waitmutex;
00297         int threadsafe;
00298 #endif // RTP_SUPPORT_THREAD
00299 };
00300 
00301 #endif // RTPUDPV4TRANSMITTER_H
00302 

Generated on Thu Feb 8 16:22:05 2007 for jrtplib by  doxygen 1.5.1