jrtplib  3.6.0
rtpudpv6transmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2006 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the "Expertisecentrum Digitale Media"
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31 */
32 
37 #ifndef RTPUDPV6TRANSMITTER_H
38 
39 #define RTPUDPV6TRANSMITTER_H
40 
41 #include "rtpconfig.h"
42 
43 #ifdef RTP_SUPPORT_IPV6
44 
45 #include "rtptransmitter.h"
46 #include "rtpipv6destination.h"
47 #include "rtphashtable.h"
48 #include "rtpkeyhashtable.h"
49 #if ! (defined(WIN32) || defined(_WIN32_WCE))
50  #include <netinet/in.h>
51 #endif // WIN32
52 #include <string.h>
53 #include <list>
54 
55 #ifdef RTP_SUPPORT_THREAD
56  #include <jmutex.h>
57 #endif // RTP_SUPPORT_THREAD
58 
59 #define RTPUDPV6TRANS_HASHSIZE 8317
60 #define RTPUDPV6TRANS_DEFAULTPORTBASE 5000
61 
64 {
65 public:
66  RTPUDPv6TransmissionParams():RTPTransmissionParams(RTPTransmitter::IPv6UDPProto) { portbase = RTPUDPV6TRANS_DEFAULTPORTBASE; for (int i = 0 ; i < 16 ; i++) bindIP.s6_addr[i] = 0; multicastTTL = 1; mcastifidx = 0; }
67 
69  void SetBindIP(in6_addr ip) { bindIP = ip; }
70 
72  void SetMulticastInterfaceIndex(unsigned int idx) { mcastifidx = idx; }
73 
75  void SetPortbase(uint16_t pbase) { portbase = pbase; }
76 
78  void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; }
79 
81  void SetLocalIPList(std::list<in6_addr> &iplist) { localIPs = iplist; }
82 
87  void ClearLocalIPList() { localIPs.clear(); }
88 
90  in6_addr GetBindIP() const { return bindIP; }
91 
93  unsigned int GetMulticastInterfaceIndex() const { return mcastifidx; }
94 
96  uint16_t GetPortbase() const { return portbase; }
97 
99  uint8_t GetMulticastTTL() const { return multicastTTL; }
100 
102  const std::list<in6_addr> &GetLocalIPList() const { return localIPs; }
103 private:
104  uint16_t portbase;
105  in6_addr bindIP;
106  unsigned int mcastifidx;
107  std::list<in6_addr> localIPs;
108  uint8_t multicastTTL;
109 };
110 
113 {
114 public:
115 #if ! (defined(WIN32) || defined(_WIN32_WCE))
116  RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist,int rtpsock,int rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto)
117 #else
118  RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist,SOCKET rtpsock,SOCKET rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto)
119 #endif // WIN32
120  { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; }
121 
122  ~RTPUDPv6TransmissionInfo() { }
123 
125  std::list<in6_addr> GetLocalIPList() const { return localIPlist; }
126 #if ! (defined(WIN32) || defined(_WIN32_WCE))
127 
128  int GetRTPSocket() const { return rtpsocket; }
129 
131  int GetRTCPSocket() const { return rtcpsocket; }
132 #else
133  SOCKET GetRTPSocket() const { return rtpsocket; }
134  SOCKET GetRTCPSocket() const { return rtcpsocket; }
135 #endif // WIN32
136 private:
137  std::list<in6_addr> localIPlist;
138 #if ! (defined(WIN32) || defined(_WIN32_WCE))
139  int rtpsocket,rtcpsocket;
140 #else
141  SOCKET rtpsocket,rtcpsocket;
142 #endif // WIN32
143 };
144 
145 class RTPUDPv6Trans_GetHashIndex_IPv6Dest
146 {
147 public:
148  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; }
149 };
150 
151 class RTPUDPv6Trans_GetHashIndex_in6_addr
152 {
153 public:
154  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; }
155 };
156 
157 #define RTPUDPV6TRANS_HEADERSIZE (40+8)
158 
167 {
168 public:
171 
172  int Init(bool treadsafe);
173  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
174  void Destroy();
175  RTPTransmissionInfo *GetTransmissionInfo();
176 
177  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
178  bool ComesFromThisTransmitter(const RTPAddress *addr);
179  size_t GetHeaderOverhead() { return RTPUDPV6TRANS_HEADERSIZE; }
180 
181  int Poll();
182  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
183  int AbortWait();
184 
185  int SendRTPData(const void *data,size_t len);
186  int SendRTCPData(const void *data,size_t len);
187 
188  int AddDestination(const RTPAddress &addr);
189  int DeleteDestination(const RTPAddress &addr);
190  void ClearDestinations();
191 
192  bool SupportsMulticasting();
193  int JoinMulticastGroup(const RTPAddress &addr);
194  int LeaveMulticastGroup(const RTPAddress &addr);
195  void LeaveAllMulticastGroups();
196 
197  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
198  int AddToIgnoreList(const RTPAddress &addr);
199  int DeleteFromIgnoreList(const RTPAddress &addr);
200  void ClearIgnoreList();
201  int AddToAcceptList(const RTPAddress &addr);
202  int DeleteFromAcceptList(const RTPAddress &addr);
203  void ClearAcceptList();
204  int SetMaximumPacketSize(size_t s);
205 
206  bool NewDataAvailable();
207  RTPRawPacket *GetNextPacket();
208 #ifdef RTPDEBUG
209  void Dump();
210 #endif // RTPDEBUG
211 private:
212  int CreateLocalIPList();
213  bool GetLocalIPList_Interfaces();
214  void GetLocalIPList_DNS();
215  void AddLoopbackAddress();
216  void FlushPackets();
217  int PollSocket(bool rtp);
218  int ProcessAddAcceptIgnoreEntry(in6_addr ip,uint16_t port);
219  int ProcessDeleteAcceptIgnoreEntry(in6_addr ip,uint16_t port);
220 #ifdef RTP_SUPPORT_IPV6MULTICAST
221  bool SetMulticastTTL(uint8_t ttl);
222 #endif // RTP_SUPPORT_IPV6MULTICAST
223  bool ShouldAcceptData(in6_addr srcip,uint16_t srcport);
224  void ClearAcceptIgnoreInfo();
225 
226  bool init;
227  bool created;
228  bool waitingfordata;
229 #if (defined(WIN32) || defined(_WIN32_WCE))
230  SOCKET rtpsock,rtcpsock;
231 #else // not using winsock
232  int rtpsock,rtcpsock;
233 #endif // WIN32
234  in6_addr bindIP;
235  unsigned int mcastifidx;
236  std::list<in6_addr> localIPs;
237  uint16_t portbase;
238  uint8_t multicastTTL;
239  RTPTransmitter::ReceiveMode receivemode;
240 
241  uint8_t *localhostname;
242  size_t localhostnamelength;
243 
244  RTPHashTable<const RTPIPv6Destination,RTPUDPv6Trans_GetHashIndex_IPv6Dest,RTPUDPV6TRANS_HASHSIZE> destinations;
245 #ifdef RTP_SUPPORT_IPV6MULTICAST
246  RTPHashTable<const in6_addr,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> multicastgroups;
247 #endif // RTP_SUPPORT_IPV6MULTICAST
248  std::list<RTPRawPacket*> rawpacketlist;
249 
250  bool supportsmulticasting;
251  size_t maxpacksize;
252 
253  class PortInfo
254  {
255  public:
256  PortInfo() { all = false; }
257 
258  bool all;
259  std::list<uint16_t> portlist;
260  };
261 
262  RTPKeyHashTable<const in6_addr,PortInfo*,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> acceptignoreinfo;
263 
264  // notification descriptors for AbortWait (0 is for reading, 1 for writing)
265 #if (defined(WIN32) || defined(_WIN32_WCE))
266  SOCKET abortdesc[2];
267 #else
268  int abortdesc[2];
269 #endif // WIN32
270  int CreateAbortDescriptors();
271  void DestroyAbortDescriptors();
272  void AbortWaitInternal();
273 #ifdef RTP_SUPPORT_THREAD
274  JMutex mainmutex,waitmutex;
275  int threadsafe;
276 #endif // RTP_SUPPORT_THREAD
277 };
278 
279 #endif // RTP_SUPPORT_IPV6
280 
281 #endif // RTPUDPV6TRANSMITTER_H
282 
uint8_t GetMulticastTTL() const
Returns the multicast TTL which will be used (default is 1).
Definition: rtpudpv6transmitter.h:99
void SetMulticastTTL(uint8_t mcastTTL)
Sets the multicast TTL to be used to mcastTTL.
Definition: rtpudpv6transmitter.h:78
Parameters for the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:63
void SetMulticastInterfaceIndex(unsigned int idx)
Sets the multicast interface index.
Definition: rtpudpv6transmitter.h:72
in6_addr GetBindIP() const
Returns the IP address which will be used to bind the sockets.
Definition: rtpudpv6transmitter.h:90
A memory manager.
Definition: rtpmemorymanager.h:144
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:77
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:236
Specifies the internal UDP over IPv6 transmitter.
Definition: rtptransmitter.h:68
int GetRTCPSocket() const
Returns the socket descriptor used for receiving and transmitting RTCP packets.
Definition: rtpudpv6transmitter.h:131
This class is used by the transmission component to store the incoming RTP and RTCP data in...
Definition: rtprawpacket.h:48
An UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:166
ReceiveMode
Three kind of receive modes can be specified.
Definition: rtptransmitter.h:73
Abstract class from which actual transmission components should be derived.
Definition: rtptransmitter.h:57
void SetBindIP(in6_addr ip)
Sets the IP address which is used to bind the sockets to ip.
Definition: rtpudpv6transmitter.h:69
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:47
void ClearLocalIPList()
Clears the list of local IP addresses.
Definition: rtpudpv6transmitter.h:87
const std::list< in6_addr > & GetLocalIPList() const
Returns the list of local IP addresses.
Definition: rtpudpv6transmitter.h:102
std::list< in6_addr > GetLocalIPList() const
Returns the list of IPv6 addresses the transmitter considers to be the local IP addresses.
Definition: rtpudpv6transmitter.h:125
void SetPortbase(uint16_t pbase)
Sets the RTP portbase to pbase.
Definition: rtpudpv6transmitter.h:75
uint16_t GetPortbase() const
Returns the RTP portbase which will be used (default is 5000).
Definition: rtpudpv6transmitter.h:96
Additional information about the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:112
void SetLocalIPList(std::list< in6_addr > &iplist)
Passes a list of IP addresses which will be used as the local IP addresses.
Definition: rtpudpv6transmitter.h:81
int GetRTPSocket() const
Returns the socket descriptor used for receiving and transmitting RTP packets.
Definition: rtpudpv6transmitter.h:128
Base class for transmission parameters.
Definition: rtptransmitter.h:217
unsigned int GetMulticastInterfaceIndex() const
Returns the multicast interface index.
Definition: rtpudpv6transmitter.h:93