JRTPLIB  3.10.0
rtpudpv6transmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2016 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 <string.h>
51 #include <list>
52 
53 #ifdef RTP_SUPPORT_THREAD
54  #include <jthread/jmutex.h>
55 #endif // RTP_SUPPORT_THREAD
56 
57 #define RTPUDPV6TRANS_HASHSIZE 8317
58 #define RTPUDPV6TRANS_DEFAULTPORTBASE 5000
59 
60 #define RTPUDPV6TRANS_RTPRECEIVEBUFFER 32768
61 #define RTPUDPV6TRANS_RTCPRECEIVEBUFFER 32768
62 #define RTPUDPV6TRANS_RTPTRANSMITBUFFER 32768
63 #define RTPUDPV6TRANS_RTCPTRANSMITBUFFER 32768
64 
65 namespace jrtplib
66 {
67 
69 class JRTPLIB_IMPORTEXPORT RTPUDPv6TransmissionParams : public RTPTransmissionParams
70 {
71 public:
72  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; }
73 
75  void SetBindIP(in6_addr ip) { bindIP = ip; }
76 
78  void SetMulticastInterfaceIndex(unsigned int idx) { mcastifidx = idx; }
79 
81  void SetPortbase(uint16_t pbase) { portbase = pbase; }
82 
84  void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; }
85 
87  void SetLocalIPList(std::list<in6_addr> &iplist) { localIPs = iplist; }
88 
93  void ClearLocalIPList() { localIPs.clear(); }
94 
96  in6_addr GetBindIP() const { return bindIP; }
97 
99  unsigned int GetMulticastInterfaceIndex() const { return mcastifidx; }
100 
102  uint16_t GetPortbase() const { return portbase; }
103 
105  uint8_t GetMulticastTTL() const { return multicastTTL; }
106 
108  const std::list<in6_addr> &GetLocalIPList() const { return localIPs; }
109 
111  void SetRTPSendBuffer(int s) { rtpsendbuf = s; }
112 
114  void SetRTPReceiveBuffer(int s) { rtprecvbuf = s; }
115 
117  void SetRTCPSendBuffer(int s) { rtcpsendbuf = s; }
118 
120  void SetRTCPReceiveBuffer(int s) { rtcprecvbuf = s; }
121 
123  int GetRTPSendBuffer() const { return rtpsendbuf; }
124 
126  int GetRTPReceiveBuffer() const { return rtprecvbuf; }
127 
129  int GetRTCPSendBuffer() const { return rtcpsendbuf; }
130 
132  int GetRTCPReceiveBuffer() const { return rtcprecvbuf; }
133 private:
134  uint16_t portbase;
135  in6_addr bindIP;
136  unsigned int mcastifidx;
137  std::list<in6_addr> localIPs;
138  uint8_t multicastTTL;
139  int rtpsendbuf, rtprecvbuf;
140  int rtcpsendbuf, rtcprecvbuf;
141 };
142 
144 class JRTPLIB_IMPORTEXPORT RTPUDPv6TransmissionInfo : public RTPTransmissionInfo
145 {
146 public:
147  RTPUDPv6TransmissionInfo(std::list<in6_addr> iplist, SocketType rtpsock, SocketType rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto)
148  { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; }
149 
151 
153  std::list<in6_addr> GetLocalIPList() const { return localIPlist; }
154 
156  SocketType GetRTPSocket() const { return rtpsocket; }
157 
159  SocketType GetRTCPSocket() const { return rtcpsocket; }
160 private:
161  std::list<in6_addr> localIPlist;
162  SocketType rtpsocket,rtcpsocket;
163 };
164 
165 class JRTPLIB_IMPORTEXPORT RTPUDPv6Trans_GetHashIndex_IPv6Dest
166 {
167 public:
168  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; }
169 };
170 
171 class JRTPLIB_IMPORTEXPORT RTPUDPv6Trans_GetHashIndex_in6_addr
172 {
173 public:
174  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; }
175 };
176 
177 #define RTPUDPV6TRANS_HEADERSIZE (40+8)
178 
186 class JRTPLIB_IMPORTEXPORT RTPUDPv6Transmitter : public RTPTransmitter
187 {
188 public:
191 
192  int Init(bool treadsafe);
193  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
194  void Destroy();
195  RTPTransmissionInfo *GetTransmissionInfo();
196  void DeleteTransmissionInfo(RTPTransmissionInfo *inf);
197 
198  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
199  bool ComesFromThisTransmitter(const RTPAddress *addr);
200  size_t GetHeaderOverhead() { return RTPUDPV6TRANS_HEADERSIZE; }
201 
202  int Poll();
203  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
204  int AbortWait();
205 
206  int SendRTPData(const void *data,size_t len);
207  int SendRTCPData(const void *data,size_t len);
208 
209  int AddDestination(const RTPAddress &addr);
210  int DeleteDestination(const RTPAddress &addr);
211  void ClearDestinations();
212 
213  bool SupportsMulticasting();
214  int JoinMulticastGroup(const RTPAddress &addr);
215  int LeaveMulticastGroup(const RTPAddress &addr);
216  void LeaveAllMulticastGroups();
217 
218  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
219  int AddToIgnoreList(const RTPAddress &addr);
220  int DeleteFromIgnoreList(const RTPAddress &addr);
221  void ClearIgnoreList();
222  int AddToAcceptList(const RTPAddress &addr);
223  int DeleteFromAcceptList(const RTPAddress &addr);
224  void ClearAcceptList();
225  int SetMaximumPacketSize(size_t s);
226 
227  bool NewDataAvailable();
228  RTPRawPacket *GetNextPacket();
229 #ifdef RTPDEBUG
230  void Dump();
231 #endif // RTPDEBUG
232 private:
233  int CreateLocalIPList();
234  bool GetLocalIPList_Interfaces();
235  void GetLocalIPList_DNS();
236  void AddLoopbackAddress();
237  void FlushPackets();
238  int PollSocket(bool rtp);
239  int ProcessAddAcceptIgnoreEntry(in6_addr ip,uint16_t port);
240  int ProcessDeleteAcceptIgnoreEntry(in6_addr ip,uint16_t port);
241 #ifdef RTP_SUPPORT_IPV6MULTICAST
242  bool SetMulticastTTL(uint8_t ttl);
243 #endif // RTP_SUPPORT_IPV6MULTICAST
244  bool ShouldAcceptData(in6_addr srcip,uint16_t srcport);
245  void ClearAcceptIgnoreInfo();
246 
247  bool init;
248  bool created;
249  bool waitingfordata;
250  SocketType rtpsock,rtcpsock;
251  in6_addr bindIP;
252  unsigned int mcastifidx;
253  std::list<in6_addr> localIPs;
254  uint16_t portbase;
255  uint8_t multicastTTL;
256  RTPTransmitter::ReceiveMode receivemode;
257 
258  uint8_t *localhostname;
259  size_t localhostnamelength;
260 
261  RTPHashTable<const RTPIPv6Destination,RTPUDPv6Trans_GetHashIndex_IPv6Dest,RTPUDPV6TRANS_HASHSIZE> destinations;
262 #ifdef RTP_SUPPORT_IPV6MULTICAST
263  RTPHashTable<const in6_addr,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> multicastgroups;
264 #endif // RTP_SUPPORT_IPV6MULTICAST
265  std::list<RTPRawPacket*> rawpacketlist;
266 
267  bool supportsmulticasting;
268  size_t maxpacksize;
269 
270  class PortInfo
271  {
272  public:
273  PortInfo() { all = false; }
274 
275  bool all;
276  std::list<uint16_t> portlist;
277  };
278 
279  RTPKeyHashTable<const in6_addr,PortInfo*,RTPUDPv6Trans_GetHashIndex_in6_addr,RTPUDPV6TRANS_HASHSIZE> acceptignoreinfo;
280 
281  // notification descriptors for AbortWait (0 is for reading, 1 for writing)
282  SocketType abortdesc[2];
283 
284  int CreateAbortDescriptors();
285  void DestroyAbortDescriptors();
286  void AbortWaitInternal();
287 #ifdef RTP_SUPPORT_THREAD
288  jthread::JMutex mainmutex,waitmutex;
289  int threadsafe;
290 #endif // RTP_SUPPORT_THREAD
291 };
292 
293 } // end namespace
294 
295 #endif // RTP_SUPPORT_IPV6
296 
297 #endif // RTPUDPV6TRANSMITTER_H
298 
void SetBindIP(in6_addr ip)
Sets the IP address which is used to bind the sockets to ip.
Definition: rtpudpv6transmitter.h:75
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:228
SocketType GetRTCPSocket() const
Returns the socket descriptor used for receiving and transmitting RTCP packets.
Definition: rtpudpv6transmitter.h:159
void SetRTCPSendBuffer(int s)
Sets the RTCP socket's send buffer size.
Definition: rtpudpv6transmitter.h:117
uint16_t GetPortbase() const
Returns the RTP portbase which will be used (default is 5000).
Definition: rtpudpv6transmitter.h:102
SocketType GetRTPSocket() const
Returns the socket descriptor used for receiving and transmitting RTP packets.
Definition: rtpudpv6transmitter.h:156
int GetRTPReceiveBuffer() const
Returns the RTP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:126
void SetRTPSendBuffer(int s)
Sets the RTP socket's send buffer size.
Definition: rtpudpv6transmitter.h:111
Additional information about the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:144
int GetRTCPReceiveBuffer() const
Returns the RTCP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:132
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:78
An UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:186
void SetMulticastTTL(uint8_t mcastTTL)
Sets the multicast TTL to be used to mcastTTL.
Definition: rtpudpv6transmitter.h:84
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:87
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:79
const std::list< in6_addr > & GetLocalIPList() const
Returns the list of local IP addresses.
Definition: rtpudpv6transmitter.h:108
void SetRTPReceiveBuffer(int s)
Sets the RTP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:114
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:96
void SetRTCPReceiveBuffer(int s)
Sets the RTCP socket's receive buffer size.
Definition: rtpudpv6transmitter.h:120
uint8_t GetMulticastTTL() const
Returns the multicast TTL which will be used (default is 1).
Definition: rtpudpv6transmitter.h:105
void ClearLocalIPList()
Clears the list of local IP addresses.
Definition: rtpudpv6transmitter.h:93
Specifies the internal UDP over IPv6 transmitter.
Definition: rtptransmitter.h:73
unsigned int GetMulticastInterfaceIndex() const
Returns the multicast interface index.
Definition: rtpudpv6transmitter.h:99
int GetRTPSendBuffer() const
Returns the RTP socket's send buffer size.
Definition: rtpudpv6transmitter.h:123
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:247
Parameters for the UDP over IPv6 transmitter.
Definition: rtpudpv6transmitter.h:69
int GetRTCPSendBuffer() const
Returns the RTCP socket's send buffer size.
Definition: rtpudpv6transmitter.h:129
std::list< in6_addr > GetLocalIPList() const
Returns the list of IPv6 addresses the transmitter considers to be the local IP addresses.
Definition: rtpudpv6transmitter.h:153
void SetPortbase(uint16_t pbase)
Sets the RTP portbase to pbase.
Definition: rtpudpv6transmitter.h:81