jrtplib  3.7.0
rtpudpv4transmitter.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 RTPUDPV4TRANSMITTER_H
38 
39 #define RTPUDPV4TRANSMITTER_H
40 
41 #include "rtpconfig.h"
42 #include "rtptransmitter.h"
43 #include "rtpipv4destination.h"
44 #include "rtphashtable.h"
45 #include "rtpkeyhashtable.h"
46 #include <list>
47 
48 #ifdef RTP_SUPPORT_THREAD
49  #include <jmutex.h>
50 #endif // RTP_SUPPORT_THREAD
51 
52 #define RTPUDPV4TRANS_HASHSIZE 8317
53 #define RTPUDPV4TRANS_DEFAULTPORTBASE 5000
54 
55 #define RTPUDPV4TRANS_RTPRECEIVEBUFFER 32768
56 #define RTPUDPV4TRANS_RTCPRECEIVEBUFFER 32768
57 #define RTPUDPV4TRANS_RTPTRANSMITBUFFER 32768
58 #define RTPUDPV4TRANS_RTCPTRANSMITBUFFER 32768
59 
62 {
63 public:
64  RTPUDPv4TransmissionParams():RTPTransmissionParams(RTPTransmitter::IPv4UDPProto) { portbase = RTPUDPV4TRANS_DEFAULTPORTBASE; bindIP = 0; multicastTTL = 1; mcastifaceIP = 0; rtpsendbuf = RTPUDPV4TRANS_RTPTRANSMITBUFFER; rtprecvbuf= RTPUDPV4TRANS_RTPRECEIVEBUFFER; rtcpsendbuf = RTPUDPV4TRANS_RTCPTRANSMITBUFFER; rtcprecvbuf = RTPUDPV4TRANS_RTCPRECEIVEBUFFER; }
65 
67  void SetBindIP(uint32_t ip) { bindIP = ip; }
68 
70  void SetMulticastInterfaceIP(uint32_t ip) { mcastifaceIP = ip; }
71 
73  void SetPortbase(uint16_t pbase) { portbase = pbase; }
74 
76  void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; }
77 
79  void SetLocalIPList(std::list<uint32_t> &iplist) { localIPs = iplist; }
80 
85  void ClearLocalIPList() { localIPs.clear(); }
86 
88  uint32_t GetBindIP() const { return bindIP; }
89 
91  uint32_t GetMulticastInterfaceIP() const { return mcastifaceIP; }
92 
94  uint16_t GetPortbase() const { return portbase; }
95 
97  uint8_t GetMulticastTTL() const { return multicastTTL; }
98 
100  const std::list<uint32_t> &GetLocalIPList() const { return localIPs; }
101 
103  void SetRTPSendBuffer(int s) { rtpsendbuf = s; }
104 
106  void SetRTPReceiveBuffer(int s) { rtprecvbuf = s; }
107 
109  void SetRTCPSendBuffer(int s) { rtcpsendbuf = s; }
110 
112  void SetRTCPReceiveBuffer(int s) { rtcprecvbuf = s; }
113 
115  int GetRTPSendBuffer() const { return rtpsendbuf; }
116 
118  int GetRTPReceiveBuffer() const { return rtprecvbuf; }
119 
121  int GetRTCPSendBuffer() const { return rtcpsendbuf; }
122 
124  int GetRTCPReceiveBuffer() const { return rtcprecvbuf; }
125 private:
126  uint16_t portbase;
127  uint32_t bindIP, mcastifaceIP;
128  std::list<uint32_t> localIPs;
129  uint8_t multicastTTL;
130  int rtpsendbuf, rtprecvbuf;
131  int rtcpsendbuf, rtcprecvbuf;
132 };
133 
136 {
137 public:
138 #if ! (defined(WIN32) || defined(_WIN32_WCE))
139  RTPUDPv4TransmissionInfo(std::list<uint32_t> iplist,int rtpsock,int rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv4UDPProto)
140 #else
141  RTPUDPv4TransmissionInfo(std::list<uint32_t> iplist,SOCKET rtpsock,SOCKET rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv4UDPProto)
142 #endif // WIN32
143  { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; }
144 
145  ~RTPUDPv4TransmissionInfo() { }
146 
148  std::list<uint32_t> GetLocalIPList() const { return localIPlist; }
149 #if ! (defined(WIN32) || defined(_WIN32_WCE))
150 
151  int GetRTPSocket() const { return rtpsocket; }
152 
154  int GetRTCPSocket() const { return rtcpsocket; }
155 #else
156  SOCKET GetRTPSocket() const { return rtpsocket; }
157  SOCKET GetRTCPSocket() const { return rtcpsocket; }
158 #endif // WIN32
159 private:
160  std::list<uint32_t> localIPlist;
161 #if ! (defined(WIN32) || defined(_WIN32_WCE))
162  int rtpsocket,rtcpsocket;
163 #else
164  SOCKET rtpsocket,rtcpsocket;
165 #endif // WIN32
166 };
167 
168 class RTPUDPv4Trans_GetHashIndex_IPv4Dest
169 {
170 public:
171  static int GetIndex(const RTPIPv4Destination &d) { return d.GetIP()%RTPUDPV4TRANS_HASHSIZE; }
172 };
173 
174 class RTPUDPv4Trans_GetHashIndex_uint32_t
175 {
176 public:
177  static int GetIndex(const uint32_t &k) { return k%RTPUDPV4TRANS_HASHSIZE; }
178 };
179 
180 #define RTPUDPV4TRANS_HEADERSIZE (20+8)
181 
190 {
191 public:
194 
195  int Init(bool treadsafe);
196  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
197  void Destroy();
198  RTPTransmissionInfo *GetTransmissionInfo();
199 
200  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
201  bool ComesFromThisTransmitter(const RTPAddress *addr);
202  size_t GetHeaderOverhead() { return RTPUDPV4TRANS_HEADERSIZE; }
203 
204  int Poll();
205  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
206  int AbortWait();
207 
208  int SendRTPData(const void *data,size_t len);
209  int SendRTCPData(const void *data,size_t len);
210 
211  int AddDestination(const RTPAddress &addr);
212  int DeleteDestination(const RTPAddress &addr);
213  void ClearDestinations();
214 
215  bool SupportsMulticasting();
216  int JoinMulticastGroup(const RTPAddress &addr);
217  int LeaveMulticastGroup(const RTPAddress &addr);
218  void LeaveAllMulticastGroups();
219 
220  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
221  int AddToIgnoreList(const RTPAddress &addr);
222  int DeleteFromIgnoreList(const RTPAddress &addr);
223  void ClearIgnoreList();
224  int AddToAcceptList(const RTPAddress &addr);
225  int DeleteFromAcceptList(const RTPAddress &addr);
226  void ClearAcceptList();
227  int SetMaximumPacketSize(size_t s);
228 
229  bool NewDataAvailable();
230  RTPRawPacket *GetNextPacket();
231 #ifdef RTPDEBUG
232  void Dump();
233 #endif // RTPDEBUG
234 private:
235  int CreateLocalIPList();
236  bool GetLocalIPList_Interfaces();
237  void GetLocalIPList_DNS();
238  void AddLoopbackAddress();
239  void FlushPackets();
240  int PollSocket(bool rtp);
241  int ProcessAddAcceptIgnoreEntry(uint32_t ip,uint16_t port);
242  int ProcessDeleteAcceptIgnoreEntry(uint32_t ip,uint16_t port);
243 #ifdef RTP_SUPPORT_IPV4MULTICAST
244  bool SetMulticastTTL(uint8_t ttl);
245 #endif // RTP_SUPPORT_IPV4MULTICAST
246  bool ShouldAcceptData(uint32_t srcip,uint16_t srcport);
247  void ClearAcceptIgnoreInfo();
248 
249  bool init;
250  bool created;
251  bool waitingfordata;
252 #if (defined(WIN32) || defined(_WIN32_WCE))
253  SOCKET rtpsock,rtcpsock;
254 #else // not using winsock
255  int rtpsock,rtcpsock;
256 #endif // WIN32
257  uint32_t bindIP, mcastifaceIP;
258  std::list<uint32_t> localIPs;
259  uint16_t portbase;
260  uint8_t multicastTTL;
261  RTPTransmitter::ReceiveMode receivemode;
262 
263  uint8_t *localhostname;
264  size_t localhostnamelength;
265 
266  RTPHashTable<const RTPIPv4Destination,RTPUDPv4Trans_GetHashIndex_IPv4Dest,RTPUDPV4TRANS_HASHSIZE> destinations;
267 #ifdef RTP_SUPPORT_IPV4MULTICAST
268  RTPHashTable<const uint32_t,RTPUDPv4Trans_GetHashIndex_uint32_t,RTPUDPV4TRANS_HASHSIZE> multicastgroups;
269 #endif // RTP_SUPPORT_IPV4MULTICAST
270  std::list<RTPRawPacket*> rawpacketlist;
271 
272  bool supportsmulticasting;
273  size_t maxpacksize;
274 
275  class PortInfo
276  {
277  public:
278  PortInfo() { all = false; }
279 
280  bool all;
281  std::list<uint16_t> portlist;
282  };
283 
284  RTPKeyHashTable<const uint32_t,PortInfo*,RTPUDPv4Trans_GetHashIndex_uint32_t,RTPUDPV4TRANS_HASHSIZE> acceptignoreinfo;
285 
286  // notification descriptors for AbortWait (0 is for reading, 1 for writing)
287 #if (defined(WIN32) || defined(_WIN32_WCE))
288  SOCKET abortdesc[2];
289 #else
290  int abortdesc[2];
291 #endif // WIN32
292  int CreateAbortDescriptors();
293  void DestroyAbortDescriptors();
294  void AbortWaitInternal();
295 #ifdef RTP_SUPPORT_THREAD
296  JMutex mainmutex,waitmutex;
297  int threadsafe;
298 #endif // RTP_SUPPORT_THREAD
299 };
300 
301 #endif // RTPUDPV4TRANSMITTER_H
302 
uint16_t GetPortbase() const
Returns the RTP portbase which will be used (default is 5000).
Definition: rtpudpv4transmitter.h:94
void SetRTCPSendBuffer(int s)
Sets the RTCP socket's send buffer size.
Definition: rtpudpv4transmitter.h:109
A memory manager.
Definition: rtpmemorymanager.h:144
uint32_t GetBindIP() const
Returns the IP address which will be used to bind the sockets.
Definition: rtpudpv4transmitter.h:88
uint8_t GetMulticastTTL() const
Returns the multicast TTL which will be used (default is 1).
Definition: rtpudpv4transmitter.h:97
void SetRTPReceiveBuffer(int s)
Sets the RTP socket's receive buffer size.
Definition: rtpudpv4transmitter.h:106
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:77
int GetRTPSocket() const
Returns the socket descriptor used for receiving and transmitting RTP packets.
Definition: rtpudpv4transmitter.h:151
Additional information about the UDP over IPv4 transmitter.
Definition: rtpudpv4transmitter.h:135
std::list< uint32_t > GetLocalIPList() const
Returns the list of IPv4 addresses the transmitter considers to be the local IP addresses.
Definition: rtpudpv4transmitter.h:148
void SetRTPSendBuffer(int s)
Sets the RTP socket's send buffer size.
Definition: rtpudpv4transmitter.h:103
void SetPortbase(uint16_t pbase)
Sets the RTP portbase to pbase.
Definition: rtpudpv4transmitter.h:73
int GetRTCPSendBuffer() const
Returns the RTCP socket's send buffer size.
Definition: rtpudpv4transmitter.h:121
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:236
void SetRTCPReceiveBuffer(int s)
Sets the RTCP socket's receive buffer size.
Definition: rtpudpv4transmitter.h:112
Parameters for the UDP over IPv4 transmitter.
Definition: rtpudpv4transmitter.h:61
Specifies the internal UDP over IPv4 transmitter.
Definition: rtptransmitter.h:67
This class is used by the transmission component to store the incoming RTP and RTCP data in...
Definition: rtprawpacket.h:48
ReceiveMode
Three kind of receive modes can be specified.
Definition: rtptransmitter.h:73
int GetRTCPReceiveBuffer() const
Returns the RTCP socket's receive buffer size.
Definition: rtpudpv4transmitter.h:124
uint32_t GetMulticastInterfaceIP() const
Returns the multicast interface IP address.
Definition: rtpudpv4transmitter.h:91
void SetBindIP(uint32_t ip)
Sets the IP address which is used to bind the sockets to ip.
Definition: rtpudpv4transmitter.h:67
int GetRTPReceiveBuffer() const
Returns the RTP socket's receive buffer size.
Definition: rtpudpv4transmitter.h:118
Abstract class from which actual transmission components should be derived.
Definition: rtptransmitter.h:57
void SetMulticastInterfaceIP(uint32_t ip)
Sets the multicast interface IP address.
Definition: rtpudpv4transmitter.h:70
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:47
const std::list< uint32_t > & GetLocalIPList() const
Returns the list of local IP addresses.
Definition: rtpudpv4transmitter.h:100
An UDP over IPv4 transmission component.
Definition: rtpudpv4transmitter.h:189
int GetRTPSendBuffer() const
Returns the RTP socket's send buffer size.
Definition: rtpudpv4transmitter.h:115
void SetLocalIPList(std::list< uint32_t > &iplist)
Passes a list of IP addresses which will be used as the local IP addresses.
Definition: rtpudpv4transmitter.h:79
Base class for transmission parameters.
Definition: rtptransmitter.h:217
void ClearLocalIPList()
Clears the list of local IP addresses.
Definition: rtpudpv4transmitter.h:85
int GetRTCPSocket() const
Returns the socket descriptor used for receiving and transmitting RTCP packets.
Definition: rtpudpv4transmitter.h:154
void SetMulticastTTL(uint8_t mcastTTL)
Sets the multicast TTL to be used to mcastTTL.
Definition: rtpudpv4transmitter.h:76