jrtplib  3.7.0
rtpudpv6transmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2007 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 
62 #define RTPUDPV6TRANS_RTPRECEIVEBUFFER 32768
63 #define RTPUDPV6TRANS_RTCPRECEIVEBUFFER 32768
64 #define RTPUDPV6TRANS_RTPTRANSMITBUFFER 32768
65 #define RTPUDPV6TRANS_RTCPTRANSMITBUFFER 32768
66 
69 {
70 public:
71  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; }
72 
74  void SetBindIP(in6_addr ip) { bindIP = ip; }
75 
77  void SetMulticastInterfaceIndex(unsigned int idx) { mcastifidx = idx; }
78 
80  void SetPortbase(uint16_t pbase) { portbase = pbase; }
81 
83  void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; }
84 
86  void SetLocalIPList(std::list<in6_addr> &iplist) { localIPs = iplist; }
87 
92  void ClearLocalIPList() { localIPs.clear(); }
93 
95  in6_addr GetBindIP() const { return bindIP; }
96 
98  unsigned int GetMulticastInterfaceIndex() const { return mcastifidx; }
99 
101  uint16_t GetPortbase() const { return portbase; }
102 
104  uint8_t GetMulticastTTL() const { return multicastTTL; }
105 
107  const std::list<in6_addr> &GetLocalIPList() const { return localIPs; }
108 
110  void SetRTPSendBuffer(int s) { rtpsendbuf = s; }
111 
113  void SetRTPReceiveBuffer(int s) { rtprecvbuf = s; }
114 
116  void SetRTCPSendBuffer(int s) { rtcpsendbuf = s; }
117 
119  void SetRTCPReceiveBuffer(int s) { rtcprecvbuf = s; }
120 
122  int GetRTPSendBuffer() const { return rtpsendbuf; }
123 
125  int GetRTPReceiveBuffer() const { return rtprecvbuf; }
126 
128  int GetRTCPSendBuffer() const { return rtcpsendbuf; }
129 
131  int GetRTCPReceiveBuffer() const { return rtcprecvbuf; }
132 private:
133  uint16_t portbase;
134  in6_addr bindIP;
135  unsigned int mcastifidx;
136  std::list<in6_addr> localIPs;
137  uint8_t multicastTTL;
138  int rtpsendbuf, rtprecvbuf;
139  int rtcpsendbuf, rtcprecvbuf;
140 };
141 
144 {
145 public:
146 #if ! (defined(WIN32) || defined(_WIN32_WCE))
147  RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist,int rtpsock,int rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto)
148 #else
149  RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist,SOCKET rtpsock,SOCKET rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto)
150 #endif // WIN32
151  { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; }
152 
153  ~RTPUDPv6TransmissionInfo() { }
154 
156  std::list<in6_addr> GetLocalIPList() const { return localIPlist; }
157 #if ! (defined(WIN32) || defined(_WIN32_WCE))
158 
159  int GetRTPSocket() const { return rtpsocket; }
160 
162  int GetRTCPSocket() const { return rtcpsocket; }
163 #else
164  SOCKET GetRTPSocket() const { return rtpsocket; }
165  SOCKET GetRTCPSocket() const { return rtcpsocket; }
166 #endif // WIN32
167 private:
168  std::list<in6_addr> localIPlist;
169 #if ! (defined(WIN32) || defined(_WIN32_WCE))
170  int rtpsocket,rtcpsocket;
171 #else
172  SOCKET rtpsocket,rtcpsocket;
173 #endif // WIN32
174 };
175 
176 class RTPUDPv6Trans_GetHashIndex_IPv6Dest
177 {
178 public:
179  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; }
180 };
181 
182 class RTPUDPv6Trans_GetHashIndex_in6_addr
183 {
184 public:
185  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; }
186 };
187 
188 #define RTPUDPV6TRANS_HEADERSIZE (40+8)
189 
198 {
199 public:
202 
203  int Init(bool treadsafe);
204  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
205  void Destroy();
206  RTPTransmissionInfo *GetTransmissionInfo();
207 
208  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
209  bool ComesFromThisTransmitter(const RTPAddress *addr);
210  size_t GetHeaderOverhead() { return RTPUDPV6TRANS_HEADERSIZE; }
211 
212  int Poll();
213  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
214  int AbortWait();
215 
216  int SendRTPData(const void *data,size_t len);
217  int SendRTCPData(const void *data,size_t len);
218 
219  int AddDestination(const RTPAddress &addr);
220  int DeleteDestination(const RTPAddress &addr);
221  void ClearDestinations();
222 
223  bool SupportsMulticasting();
224  int JoinMulticastGroup(const RTPAddress &addr);
225  int LeaveMulticastGroup(const RTPAddress &addr);
226  void LeaveAllMulticastGroups();
227 
228  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
229  int AddToIgnoreList(const RTPAddress &addr);
230  int DeleteFromIgnoreList(const RTPAddress &addr);
231  void ClearIgnoreList();
232  int AddToAcceptList(const RTPAddress &addr);
233  int DeleteFromAcceptList(const RTPAddress &addr);
234  void ClearAcceptList();
235  int SetMaximumPacketSize(size_t s);
236 
237  bool NewDataAvailable();
238  RTPRawPacket *GetNextPacket();
239 #ifdef RTPDEBUG
240  void Dump();
241 #endif // RTPDEBUG
242 private:
243  int CreateLocalIPList();
244  bool GetLocalIPList_Interfaces();
245  void GetLocalIPList_DNS();
246  void AddLoopbackAddress();
247  void FlushPackets();
248  int PollSocket(bool rtp);
249  int ProcessAddAcceptIgnoreEntry(in6_addr ip,uint16_t port);
250  int ProcessDeleteAcceptIgnoreEntry(in6_addr ip,uint16_t port);
251 #ifdef RTP_SUPPORT_IPV6MULTICAST
252  bool SetMulticastTTL(uint8_t ttl);
253 #endif // RTP_SUPPORT_IPV6MULTICAST
254  bool ShouldAcceptData(in6_addr srcip,uint16_t srcport);
255  void ClearAcceptIgnoreInfo();
256 
257  bool init;
258  bool created;
259  bool waitingfordata;
260 #if (defined(WIN32) || defined(_WIN32_WCE))
261  SOCKET rtpsock,rtcpsock;
262 #else // not using winsock
263  int rtpsock,rtcpsock;
264 #endif // WIN32
265  in6_addr bindIP;
266  unsigned int mcastifidx;
267  std::list<in6_addr> localIPs;
268  uint16_t portbase;
269  uint8_t multicastTTL;
270  RTPTransmitter::ReceiveMode receivemode;
271 
272  uint8_t *localhostname;
273  size_t localhostnamelength;
274 
275  RTPHashTable<const RTPIPv6Destination,RTPUDPv6Trans_GetHashIndex_IPv6Dest,RTPUDPV6TRANS_HASHSIZE> destinations;
276 #ifdef RTP_SUPPORT_IPV6MULTICAST
277  RTPHashTable<const in6_addr,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> multicastgroups;
278 #endif // RTP_SUPPORT_IPV6MULTICAST
279  std::list<RTPRawPacket*> rawpacketlist;
280 
281  bool supportsmulticasting;
282  size_t maxpacksize;
283 
284  class PortInfo
285  {
286  public:
287  PortInfo() { all = false; }
288 
289  bool all;
290  std::list<uint16_t> portlist;
291  };
292 
293  RTPKeyHashTable<const in6_addr,PortInfo*,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> acceptignoreinfo;
294 
295  // notification descriptors for AbortWait (0 is for reading, 1 for writing)
296 #if (defined(WIN32) || defined(_WIN32_WCE))
297  SOCKET abortdesc[2];
298 #else
299  int abortdesc[2];
300 #endif // WIN32
301  int CreateAbortDescriptors();
302  void DestroyAbortDescriptors();
303  void AbortWaitInternal();
304 #ifdef RTP_SUPPORT_THREAD
305  JMutex mainmutex,waitmutex;
306  int threadsafe;
307 #endif // RTP_SUPPORT_THREAD
308 };
309 
310 #endif // RTP_SUPPORT_IPV6
311 
312 #endif // RTPUDPV6TRANSMITTER_H
313 
uint8_t GetMulticastTTL() const
Returns the multicast TTL which will be used (default is 1).
Definition: rtpudpv6transmitter.h:104
void SetMulticastTTL(uint8_t mcastTTL)
Sets the multicast TTL to be used to mcastTTL.
Definition: rtpudpv6transmitter.h:83
Parameters for the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:68
void SetMulticastInterfaceIndex(unsigned int idx)
Sets the multicast interface index.
Definition: rtpudpv6transmitter.h:77
in6_addr GetBindIP() const
Returns the IP address which will be used to bind the sockets.
Definition: rtpudpv6transmitter.h:95
A memory manager.
Definition: rtpmemorymanager.h:144
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:77
void SetRTPReceiveBuffer(int s)
Sets the RTP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:113
void SetRTCPReceiveBuffer(int s)
Sets the RTCP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:119
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:236
int GetRTPSendBuffer() const
Returns the RTP socket's send buffer size.
Definition: rtpudpv6transmitter.h:122
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:162
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:197
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 SetRTCPSendBuffer(int s)
Sets the RTCP socket's send buffer size.
Definition: rtpudpv6transmitter.h:116
void SetBindIP(in6_addr ip)
Sets the IP address which is used to bind the sockets to ip.
Definition: rtpudpv6transmitter.h:74
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:47
int GetRTCPReceiveBuffer() const
Returns the RTCP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:131
void ClearLocalIPList()
Clears the list of local IP addresses.
Definition: rtpudpv6transmitter.h:92
const std::list< in6_addr > & GetLocalIPList() const
Returns the list of local IP addresses.
Definition: rtpudpv6transmitter.h:107
std::list< in6_addr > GetLocalIPList() const
Returns the list of IPv6 addresses the transmitter considers to be the local IP addresses.
Definition: rtpudpv6transmitter.h:156
void SetPortbase(uint16_t pbase)
Sets the RTP portbase to pbase.
Definition: rtpudpv6transmitter.h:80
void SetRTPSendBuffer(int s)
Sets the RTP socket's send buffer size.
Definition: rtpudpv6transmitter.h:110
uint16_t GetPortbase() const
Returns the RTP portbase which will be used (default is 5000).
Definition: rtpudpv6transmitter.h:101
Additional information about the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:143
int GetRTCPSendBuffer() const
Returns the RTCP socket's send buffer size.
Definition: rtpudpv6transmitter.h:128
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:86
int GetRTPSocket() const
Returns the socket descriptor used for receiving and transmitting RTP packets.
Definition: rtpudpv6transmitter.h:159
Base class for transmission parameters.
Definition: rtptransmitter.h:217
unsigned int GetMulticastInterfaceIndex() const
Returns the multicast interface index.
Definition: rtpudpv6transmitter.h:98
int GetRTPReceiveBuffer() const
Returns the RTP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:125