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