rtpudpv6transmitter.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 RTPUDPV6TRANSMITTER_H
00038 
00039 #define RTPUDPV6TRANSMITTER_H
00040 
00041 #include "rtpconfig.h"
00042 
00043 #ifdef RTP_SUPPORT_IPV6
00044 
00045 #include "rtptransmitter.h"
00046 #include "rtpipv6destination.h"
00047 #include "rtphashtable.h"
00048 #include "rtpkeyhashtable.h"
00049 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00050         #include <netinet/in.h>
00051 #endif // WIN32
00052 #include <string.h>
00053 #include <list>
00054 
00055 #ifdef RTP_SUPPORT_THREAD
00056         #include <jmutex.h>
00057 #endif // RTP_SUPPORT_THREAD
00058 
00059 #define RTPUDPV6TRANS_HASHSIZE                                                                          8317
00060 #define RTPUDPV6TRANS_DEFAULTPORTBASE                                                           5000
00061 
00062 #define RTPUDPV6TRANS_RTPRECEIVEBUFFER                                                  32768
00063 #define RTPUDPV6TRANS_RTCPRECEIVEBUFFER                                                 32768
00064 #define RTPUDPV6TRANS_RTPTRANSMITBUFFER                                                 32768
00065 #define RTPUDPV6TRANS_RTCPTRANSMITBUFFER                                                32768
00066 
00068 class RTPUDPv6TransmissionParams : public RTPTransmissionParams
00069 {
00070 public:
00071         RTPUDPv6TransmissionParams():RTPTransmissionParams(RTPTransmitter::IPv6UDPProto)        { portbase = RTPUDPV6TRANS_DEFAULTPORTBASE; for (int i = 0 ; i < 16 ; i++) bindIP.s6_addr[i] = 0; multicastTTL = 1; mcastifidx = 0; rtpsendbuf = RTPUDPV6TRANS_RTPTRANSMITBUFFER; rtprecvbuf= RTPUDPV6TRANS_RTPRECEIVEBUFFER; rtcpsendbuf = RTPUDPV6TRANS_RTCPTRANSMITBUFFER; rtcprecvbuf = RTPUDPV6TRANS_RTCPRECEIVEBUFFER; }
00072 
00074         void SetBindIP(in6_addr ip)                                                                                     { bindIP = ip; }
00075 
00077         void SetMulticastInterfaceIndex(unsigned int idx)                                       { mcastifidx = idx; }
00078 
00080         void SetPortbase(uint16_t pbase)                                                                        { portbase = pbase; }
00081 
00083         void SetMulticastTTL(uint8_t mcastTTL)                                                          { multicastTTL = mcastTTL; }
00084 
00086         void SetLocalIPList(std::list<in6_addr> &iplist)                                        { localIPs = iplist; } 
00087 
00092         void ClearLocalIPList()                                                                                         { localIPs.clear(); }
00093 
00095         in6_addr GetBindIP() const                                                                                      { return bindIP; }
00096 
00098         unsigned int GetMulticastInterfaceIndex() const                                         { return mcastifidx; }
00099 
00101         uint16_t GetPortbase() const                                                                            { return portbase; }
00102 
00104         uint8_t GetMulticastTTL() const                                                                         { return multicastTTL; }
00105 
00107         const std::list<in6_addr> &GetLocalIPList() const                                       { return localIPs; }
00108 
00110         void SetRTPSendBuffer(int s)                                                            { rtpsendbuf = s; }
00111 
00113         void SetRTPReceiveBuffer(int s)                                                         { rtprecvbuf = s; }
00114 
00116         void SetRTCPSendBuffer(int s)                                                           { rtcpsendbuf = s; }
00117 
00119         void SetRTCPReceiveBuffer(int s)                                                        { rtcprecvbuf = s; }
00120 
00122         int GetRTPSendBuffer() const                                                            { return rtpsendbuf; }
00123 
00125         int GetRTPReceiveBuffer() const                                                         { return rtprecvbuf; }
00126 
00128         int GetRTCPSendBuffer() const                                                           { return rtcpsendbuf; }
00129 
00131         int GetRTCPReceiveBuffer() const                                                        { return rtcprecvbuf; }
00132 private:
00133         uint16_t portbase;
00134         in6_addr bindIP;
00135         unsigned int mcastifidx;
00136         std::list<in6_addr> localIPs;
00137         uint8_t multicastTTL;
00138         int rtpsendbuf, rtprecvbuf;
00139         int rtcpsendbuf, rtcprecvbuf;
00140 };
00141 
00143 class RTPUDPv6TransmissionInfo : public RTPTransmissionInfo
00144 {
00145 public:
00146 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00147         RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist,int rtpsock,int rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto) 
00148 #else
00149         RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist,SOCKET rtpsock,SOCKET rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto) 
00150 #endif  // WIN32
00151                                                                                                                         { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; }
00152 
00153         ~RTPUDPv6TransmissionInfo()                                                             { }
00154 
00156         std::list<in6_addr> GetLocalIPList() const                              { return localIPlist; }
00157 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00158 
00159         int GetRTPSocket() const                                                                { return rtpsocket; }
00160 
00162         int GetRTCPSocket() const                                                               { return rtcpsocket; }
00163 #else
00164         SOCKET GetRTPSocket() const                                                             { return rtpsocket; }
00165         SOCKET GetRTCPSocket() const                                                    { return rtcpsocket; }
00166 #endif // WIN32
00167 private:
00168         std::list<in6_addr> localIPlist;
00169 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00170         int rtpsocket,rtcpsocket;
00171 #else
00172         SOCKET rtpsocket,rtcpsocket;
00173 #endif // WIN32
00174 };
00175                 
00176 class RTPUDPv6Trans_GetHashIndex_IPv6Dest
00177 {
00178 public:
00179         static int GetIndex(const RTPIPv6Destination &d)                                        { in6_addr ip = d.GetIP(); return ((((uint32_t)ip.s6_addr[12])<<24)|(((uint32_t)ip.s6_addr[13])<<16)|(((uint32_t)ip.s6_addr[14])<<8)|((uint32_t)ip.s6_addr[15]))%RTPUDPV6TRANS_HASHSIZE; }
00180 };
00181 
00182 class RTPUDPv6Trans_GetHashIndex_in6_addr
00183 {
00184 public:
00185         static int GetIndex(const in6_addr &ip)                                                 { return ((((uint32_t)ip.s6_addr[12])<<24)|(((uint32_t)ip.s6_addr[13])<<16)|(((uint32_t)ip.s6_addr[14])<<8)|((uint32_t)ip.s6_addr[15]))%RTPUDPV6TRANS_HASHSIZE; }
00186 };
00187 
00188 #define RTPUDPV6TRANS_HEADERSIZE                                                                (40+8)
00189         
00197 class RTPUDPv6Transmitter : public RTPTransmitter
00198 {
00199 public:
00200         RTPUDPv6Transmitter(RTPMemoryManager *mgr);
00201         ~RTPUDPv6Transmitter();
00202 
00203         int Init(bool treadsafe);
00204         int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
00205         void Destroy();
00206         RTPTransmissionInfo *GetTransmissionInfo();
00207 
00208         int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
00209         bool ComesFromThisTransmitter(const RTPAddress *addr);
00210         size_t GetHeaderOverhead()                                                              { return RTPUDPV6TRANS_HEADERSIZE; }
00211         
00212         int Poll();
00213         int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
00214         int AbortWait();
00215         
00216         int SendRTPData(const void *data,size_t len);   
00217         int SendRTCPData(const void *data,size_t len);
00218 
00219         int AddDestination(const RTPAddress &addr);
00220         int DeleteDestination(const RTPAddress &addr);
00221         void ClearDestinations();
00222 
00223         bool SupportsMulticasting();
00224         int JoinMulticastGroup(const RTPAddress &addr);
00225         int LeaveMulticastGroup(const RTPAddress &addr);
00226         void LeaveAllMulticastGroups();
00227 
00228         int SetReceiveMode(RTPTransmitter::ReceiveMode m);
00229         int AddToIgnoreList(const RTPAddress &addr);
00230         int DeleteFromIgnoreList(const RTPAddress &addr);
00231         void ClearIgnoreList();
00232         int AddToAcceptList(const RTPAddress &addr);
00233         int DeleteFromAcceptList(const RTPAddress &addr);
00234         void ClearAcceptList();
00235         int SetMaximumPacketSize(size_t s);     
00236         
00237         bool NewDataAvailable();
00238         RTPRawPacket *GetNextPacket();
00239 #ifdef RTPDEBUG
00240         void Dump();
00241 #endif // RTPDEBUG
00242 private:
00243         int CreateLocalIPList();
00244         bool GetLocalIPList_Interfaces();
00245         void GetLocalIPList_DNS();
00246         void AddLoopbackAddress();
00247         void FlushPackets();
00248         int PollSocket(bool rtp);
00249         int ProcessAddAcceptIgnoreEntry(in6_addr ip,uint16_t port);
00250         int ProcessDeleteAcceptIgnoreEntry(in6_addr ip,uint16_t port);
00251 #ifdef RTP_SUPPORT_IPV6MULTICAST
00252         bool SetMulticastTTL(uint8_t ttl);
00253 #endif // RTP_SUPPORT_IPV6MULTICAST
00254         bool ShouldAcceptData(in6_addr srcip,uint16_t srcport);
00255         void ClearAcceptIgnoreInfo();
00256         
00257         bool init;
00258         bool created;
00259         bool waitingfordata;
00260 #if (defined(WIN32) || defined(_WIN32_WCE))
00261         SOCKET rtpsock,rtcpsock;
00262 #else // not using winsock
00263         int rtpsock,rtcpsock;
00264 #endif // WIN32
00265         in6_addr bindIP;
00266         unsigned int mcastifidx;
00267         std::list<in6_addr> localIPs;
00268         uint16_t portbase;
00269         uint8_t multicastTTL;
00270         RTPTransmitter::ReceiveMode receivemode;
00271 
00272         uint8_t *localhostname;
00273         size_t localhostnamelength;
00274         
00275         RTPHashTable<const RTPIPv6Destination,RTPUDPv6Trans_GetHashIndex_IPv6Dest,RTPUDPV6TRANS_HASHSIZE> destinations;
00276 #ifdef RTP_SUPPORT_IPV6MULTICAST
00277         RTPHashTable<const in6_addr,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> multicastgroups;
00278 #endif // RTP_SUPPORT_IPV6MULTICAST
00279         std::list<RTPRawPacket*> rawpacketlist;
00280 
00281         bool supportsmulticasting;
00282         size_t maxpacksize;
00283 
00284         class PortInfo
00285         {
00286         public:
00287                 PortInfo() { all = false; }
00288                 
00289                 bool all;
00290                 std::list<uint16_t> portlist;
00291         };
00292 
00293         RTPKeyHashTable<const in6_addr,PortInfo*,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> acceptignoreinfo;
00294 
00295         // notification descriptors for AbortWait (0 is for reading, 1 for writing)
00296 #if (defined(WIN32) || defined(_WIN32_WCE))
00297         SOCKET abortdesc[2];
00298 #else
00299         int abortdesc[2];
00300 #endif // WIN32
00301         int CreateAbortDescriptors();
00302         void DestroyAbortDescriptors();
00303         void AbortWaitInternal();
00304 #ifdef RTP_SUPPORT_THREAD
00305         JMutex mainmutex,waitmutex;
00306         int threadsafe;
00307 #endif // RTP_SUPPORT_THREAD
00308 };
00309 
00310 #endif // RTP_SUPPORT_IPV6
00311 
00312 #endif // RTPUDPV6TRANSMITTER_H
00313 

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