JRTPLIB  3.11.1
rtpudpv6transmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2017 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 #include "rtpsocketutil.h"
50 #include "rtpabortdescriptors.h"
51 #include <string.h>
52 #include <list>
53 
54 #ifdef RTP_SUPPORT_THREAD
55  #include <jthread/jmutex.h>
56 #endif // RTP_SUPPORT_THREAD
57 
58 #define RTPUDPV6TRANS_HASHSIZE 8317
59 #define RTPUDPV6TRANS_DEFAULTPORTBASE 5000
60 
61 #define RTPUDPV6TRANS_RTPRECEIVEBUFFER 32768
62 #define RTPUDPV6TRANS_RTCPRECEIVEBUFFER 32768
63 #define RTPUDPV6TRANS_RTPTRANSMITBUFFER 32768
64 #define RTPUDPV6TRANS_RTCPTRANSMITBUFFER 32768
65 
66 namespace jrtplib
67 {
68 
70 class JRTPLIB_IMPORTEXPORT RTPUDPv6TransmissionParams : public RTPTransmissionParams
71 {
72 public:
74 
76  void SetBindIP(in6_addr ip) { bindIP = ip; }
77 
79  void SetMulticastInterfaceIndex(unsigned int idx) { mcastifidx = idx; }
80 
82  void SetPortbase(uint16_t pbase) { portbase = pbase; }
83 
85  void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; }
86 
88  void SetLocalIPList(std::list<in6_addr> &iplist) { localIPs = iplist; }
89 
94  void ClearLocalIPList() { localIPs.clear(); }
95 
97  in6_addr GetBindIP() const { return bindIP; }
98 
100  unsigned int GetMulticastInterfaceIndex() const { return mcastifidx; }
101 
103  uint16_t GetPortbase() const { return portbase; }
104 
106  uint8_t GetMulticastTTL() const { return multicastTTL; }
107 
109  const std::list<in6_addr> &GetLocalIPList() const { return localIPs; }
110 
112  void SetRTPSendBuffer(int s) { rtpsendbuf = s; }
113 
115  void SetRTPReceiveBuffer(int s) { rtprecvbuf = s; }
116 
118  void SetRTCPSendBuffer(int s) { rtcpsendbuf = s; }
119 
121  void SetRTCPReceiveBuffer(int s) { rtcprecvbuf = s; }
122 
126  void SetCreatedAbortDescriptors(RTPAbortDescriptors *desc) { m_pAbortDesc = desc; }
127 
129  int GetRTPSendBuffer() const { return rtpsendbuf; }
130 
132  int GetRTPReceiveBuffer() const { return rtprecvbuf; }
133 
135  int GetRTCPSendBuffer() const { return rtcpsendbuf; }
136 
138  int GetRTCPReceiveBuffer() const { return rtcprecvbuf; }
139 
143  RTPAbortDescriptors *GetCreatedAbortDescriptors() const { return m_pAbortDesc; }
144 private:
145  uint16_t portbase;
146  in6_addr bindIP;
147  unsigned int mcastifidx;
148  std::list<in6_addr> localIPs;
149  uint8_t multicastTTL;
150  int rtpsendbuf, rtprecvbuf;
151  int rtcpsendbuf, rtcprecvbuf;
152 
153  RTPAbortDescriptors *m_pAbortDesc;
154 };
155 
156 inline RTPUDPv6TransmissionParams::RTPUDPv6TransmissionParams()
158 {
159  portbase = RTPUDPV6TRANS_DEFAULTPORTBASE;
160  for (int i = 0 ; i < 16 ; i++)
161  bindIP.s6_addr[i] = 0;
162 
163  multicastTTL = 1;
164  mcastifidx = 0;
165  rtpsendbuf = RTPUDPV6TRANS_RTPTRANSMITBUFFER;
166  rtprecvbuf= RTPUDPV6TRANS_RTPRECEIVEBUFFER;
167  rtcpsendbuf = RTPUDPV6TRANS_RTCPTRANSMITBUFFER;
168  rtcprecvbuf = RTPUDPV6TRANS_RTCPRECEIVEBUFFER;
169 
170  m_pAbortDesc = 0;
171 }
172 
174 class JRTPLIB_IMPORTEXPORT RTPUDPv6TransmissionInfo : public RTPTransmissionInfo
175 {
176 public:
177  RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist, SocketType rtpsock, SocketType rtcpsock,
178  uint16_t rtpport, uint16_t rtcpport) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto)
179  { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; m_rtpPort = rtpport; m_rtcpPort = rtcpport; }
180 
182 
184  std::list<in6_addr> GetLocalIPList() const { return localIPlist; }
185 
187  SocketType GetRTPSocket() const { return rtpsocket; }
188 
190  SocketType GetRTCPSocket() const { return rtcpsocket; }
191 
193  uint16_t GetRTPPort() const { return m_rtpPort; }
194 
196  uint16_t GetRTCPPort() const { return m_rtcpPort; }
197 private:
198  std::list<in6_addr> localIPlist;
199  SocketType rtpsocket,rtcpsocket;
200  uint16_t m_rtpPort, m_rtcpPort;
201 };
202 
203 class JRTPLIB_IMPORTEXPORT RTPUDPv6Trans_GetHashIndex_IPv6Dest
204 {
205 public:
206  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; }
207 };
208 
209 class JRTPLIB_IMPORTEXPORT RTPUDPv6Trans_GetHashIndex_in6_addr
210 {
211 public:
212  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; }
213 };
214 
215 #define RTPUDPV6TRANS_HEADERSIZE (40+8)
216 
224 class JRTPLIB_IMPORTEXPORT RTPUDPv6Transmitter : public RTPTransmitter
225 {
226 public:
229 
230  int Init(bool treadsafe);
231  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
232  void Destroy();
233  RTPTransmissionInfo *GetTransmissionInfo();
234  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
235 
236  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
237  bool ComesFromThisTransmitter(const RTPAddress *addr);
238  size_t GetHeaderOverhead() { return RTPUDPV6TRANS_HEADERSIZE; }
239 
240  int Poll();
241  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
242  int AbortWait();
243 
244  int SendRTPData(const void *data,size_t len);
245  int SendRTCPData(const void *data,size_t len);
246 
247  int AddDestination(const RTPAddress &addr);
248  int DeleteDestination(const RTPAddress &addr);
249  void ClearDestinations();
250 
251  bool SupportsMulticasting();
252  int JoinMulticastGroup(const RTPAddress &addr);
253  int LeaveMulticastGroup(const RTPAddress &addr);
254  void LeaveAllMulticastGroups();
255 
256  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
257  int AddToIgnoreList(const RTPAddress &addr);
258  int DeleteFromIgnoreList(const RTPAddress &addr);
259  void ClearIgnoreList();
260  int AddToAcceptList(const RTPAddress &addr);
261  int DeleteFromAcceptList(const RTPAddress &addr);
262  void ClearAcceptList();
263  int SetMaximumPacketSize(size_t s);
264 
265  bool NewDataAvailable();
266  RTPRawPacket *GetNextPacket();
267 #ifdef RTPDEBUG
268  void Dump();
269 #endif // RTPDEBUG
270 private:
271  int CreateLocalIPList();
272  bool GetLocalIPList_Interfaces();
273  void GetLocalIPList_DNS();
274  void AddLoopbackAddress();
275  void FlushPackets();
276  int PollSocket(bool rtp);
277  int ProcessAddAcceptIgnoreEntry(in6_addr ip,uint16_t port);
278  int ProcessDeleteAcceptIgnoreEntry(in6_addr ip,uint16_t port);
279 #ifdef RTP_SUPPORT_IPV6MULTICAST
280  bool SetMulticastTTL(uint8_t ttl);
281 #endif // RTP_SUPPORT_IPV6MULTICAST
282  bool ShouldAcceptData(in6_addr srcip,uint16_t srcport);
283  void ClearAcceptIgnoreInfo();
284 
285  bool init;
286  bool created;
287  bool waitingfordata;
288  SocketType rtpsock,rtcpsock;
289  in6_addr bindIP;
290  unsigned int mcastifidx;
291  std::list<in6_addr> localIPs;
292  uint16_t portbase;
293  uint8_t multicastTTL;
294  RTPTransmitter::ReceiveMode receivemode;
295 
296  uint8_t *localhostname;
297  size_t localhostnamelength;
298 
299  RTPHashTable<const RTPIPv6Destination,RTPUDPv6Trans_GetHashIndex_IPv6Dest,RTPUDPV6TRANS_HASHSIZE> destinations;
300 #ifdef RTP_SUPPORT_IPV6MULTICAST
301  RTPHashTable<const in6_addr,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> multicastgroups;
302 #endif // RTP_SUPPORT_IPV6MULTICAST
303  std::list<RTPRawPacket*> rawpacketlist;
304 
305  bool supportsmulticasting;
306  size_t maxpacksize;
307 
308  class PortInfo
309  {
310  public:
311  PortInfo() { all = false; }
312 
313  bool all;
314  std::list<uint16_t> portlist;
315  };
316 
317  RTPKeyHashTable<const in6_addr,PortInfo*,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> acceptignoreinfo;
318  RTPAbortDescriptors m_abortDesc;
319  RTPAbortDescriptors *m_pAbortDesc;
320 
321 #ifdef RTP_SUPPORT_THREAD
322  jthread::JMutex mainmutex,waitmutex;
323  int threadsafe;
324 #endif // RTP_SUPPORT_THREAD
325 };
326 
327 } // end namespace
328 
329 #endif // RTP_SUPPORT_IPV6
330 
331 #endif // RTPUDPV6TRANSMITTER_H
332 
void SetBindIP(in6_addr ip)
Sets the IP address which is used to bind the sockets to ip.
Definition: rtpudpv6transmitter.h:76
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:229
SocketType GetRTCPSocket() const
Returns the socket descriptor used for receiving and transmitting RTCP packets.
Definition: rtpudpv6transmitter.h:190
void SetRTCPSendBuffer(int s)
Sets the RTCP socket&#39;s send buffer size.
Definition: rtpudpv6transmitter.h:118
uint16_t GetRTPPort() const
Returns the port number that the RTP socket receives packets on.
Definition: rtpudpv6transmitter.h:193
uint16_t GetPortbase() const
Returns the RTP portbase which will be used (default is 5000).
Definition: rtpudpv6transmitter.h:103
SocketType GetRTPSocket() const
Returns the socket descriptor used for receiving and transmitting RTP packets.
Definition: rtpudpv6transmitter.h:187
int GetRTPReceiveBuffer() const
Returns the RTP socket&#39;s receive buffer size.
Definition: rtpudpv6transmitter.h:132
void SetRTPSendBuffer(int s)
Sets the RTP socket&#39;s send buffer size.
Definition: rtpudpv6transmitter.h:112
Additional information about the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:174
int GetRTCPReceiveBuffer() const
Returns the RTCP socket&#39;s receive buffer size.
Definition: rtpudpv6transmitter.h:138
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:79
An UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:224
void SetMulticastTTL(uint8_t mcastTTL)
Sets the multicast TTL to be used to mcastTTL.
Definition: rtpudpv6transmitter.h:85
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:88
Abstract class from which actual transmission components should be derived.
Definition: rtptransmitter.h:62
ReceiveMode
Three kind of receive modes can be specified.
Definition: rtptransmitter.h:80
const std::list< in6_addr > & GetLocalIPList() const
Returns the list of local IP addresses.
Definition: rtpudpv6transmitter.h:109
Definition: rtpfaketransmitter.h:64
void SetRTPReceiveBuffer(int s)
Sets the RTP socket&#39;s receive buffer size.
Definition: rtpudpv6transmitter.h:115
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:84
A memory manager.
Definition: rtpmemorymanager.h:150
in6_addr GetBindIP() const
Returns the IP address which will be used to bind the sockets.
Definition: rtpudpv6transmitter.h:97
void SetRTCPReceiveBuffer(int s)
Sets the RTCP socket&#39;s receive buffer size.
Definition: rtpudpv6transmitter.h:121
uint8_t GetMulticastTTL() const
Returns the multicast TTL which will be used (default is 1).
Definition: rtpudpv6transmitter.h:106
void ClearLocalIPList()
Clears the list of local IP addresses.
Definition: rtpudpv6transmitter.h:94
Specifies the internal UDP over IPv6 transmitter.
Definition: rtptransmitter.h:73
unsigned int GetMulticastInterfaceIndex() const
Returns the multicast interface index.
Definition: rtpudpv6transmitter.h:100
int GetRTPSendBuffer() const
Returns the RTP socket&#39;s send buffer size.
Definition: rtpudpv6transmitter.h:129
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:248
Parameters for the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:70
Helper class for several RTPTransmitter instances, to be able to cancel a call to &#39;select&#39;...
Definition: rtpabortdescriptors.h:64
uint16_t GetRTCPPort() const
Returns the port number that the RTCP socket receives packets on.
Definition: rtpudpv6transmitter.h:196
int GetRTCPSendBuffer() const
Returns the RTCP socket&#39;s send buffer size.
Definition: rtpudpv6transmitter.h:135
RTPAbortDescriptors * GetCreatedAbortDescriptors() const
If non-null, this RTPAbortDescriptors instance will be used internally, which can be useful when crea...
Definition: rtpudpv6transmitter.h:143
std::list< in6_addr > GetLocalIPList() const
Returns the list of IPv6 addresses the transmitter considers to be the local IP addresses.
Definition: rtpudpv6transmitter.h:184
void SetPortbase(uint16_t pbase)
Sets the RTP portbase to pbase.
Definition: rtpudpv6transmitter.h:82
void SetCreatedAbortDescriptors(RTPAbortDescriptors *desc)
If non null, the specified abort descriptors will be used to cancel the function that&#39;s waiting for p...
Definition: rtpudpv6transmitter.h:126