jrtplib  3.6.0
rtpudpv4transmitter.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2006 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 
57 {
58 public:
59  RTPUDPv4TransmissionParams():RTPTransmissionParams(RTPTransmitter::IPv4UDPProto) { portbase = RTPUDPV4TRANS_DEFAULTPORTBASE; bindIP = 0; multicastTTL = 1; mcastifaceIP = 0; }
60 
62  void SetBindIP(uint32_t ip) { bindIP = ip; }
63 
65  void SetMulticastInterfaceIP(uint32_t ip) { mcastifaceIP = ip; }
66 
68  void SetPortbase(uint16_t pbase) { portbase = pbase; }
69 
71  void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; }
72 
74  void SetLocalIPList(std::list<uint32_t> &iplist) { localIPs = iplist; }
75 
80  void ClearLocalIPList() { localIPs.clear(); }
81 
83  uint32_t GetBindIP() const { return bindIP; }
84 
86  uint32_t GetMulticastInterfaceIP() const { return mcastifaceIP; }
87 
89  uint16_t GetPortbase() const { return portbase; }
90 
92  uint8_t GetMulticastTTL() const { return multicastTTL; }
93 
95  const std::list<uint32_t> &GetLocalIPList() const { return localIPs; }
96 private:
97  uint16_t portbase;
98  uint32_t bindIP, mcastifaceIP;
99  std::list<uint32_t> localIPs;
100  uint8_t multicastTTL;
101 };
102 
105 {
106 public:
107 #if ! (defined(WIN32) || defined(_WIN32_WCE))
108  RTPUDPv4TransmissionInfo(std::list<uint32_t> iplist,int rtpsock,int rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv4UDPProto)
109 #else
110  RTPUDPv4TransmissionInfo(std::list<uint32_t> iplist,SOCKET rtpsock,SOCKET rtcpsock) : RTPTransmissionInfo(RTPTransmitter::IPv4UDPProto)
111 #endif // WIN32
112  { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; }
113 
114  ~RTPUDPv4TransmissionInfo() { }
115 
117  std::list<uint32_t> GetLocalIPList() const { return localIPlist; }
118 #if ! (defined(WIN32) || defined(_WIN32_WCE))
119 
120  int GetRTPSocket() const { return rtpsocket; }
121 
123  int GetRTCPSocket() const { return rtcpsocket; }
124 #else
125  SOCKET GetRTPSocket() const { return rtpsocket; }
126  SOCKET GetRTCPSocket() const { return rtcpsocket; }
127 #endif // WIN32
128 private:
129  std::list<uint32_t> localIPlist;
130 #if ! (defined(WIN32) || defined(_WIN32_WCE))
131  int rtpsocket,rtcpsocket;
132 #else
133  SOCKET rtpsocket,rtcpsocket;
134 #endif // WIN32
135 };
136 
137 class RTPUDPv4Trans_GetHashIndex_IPv4Dest
138 {
139 public:
140  static int GetIndex(const RTPIPv4Destination &d) { return d.GetIP()%RTPUDPV4TRANS_HASHSIZE; }
141 };
142 
143 class RTPUDPv4Trans_GetHashIndex_uint32_t
144 {
145 public:
146  static int GetIndex(const uint32_t &k) { return k%RTPUDPV4TRANS_HASHSIZE; }
147 };
148 
149 #define RTPUDPV4TRANS_HEADERSIZE (20+8)
150 
159 {
160 public:
163 
164  int Init(bool treadsafe);
165  int Create(size_t maxpacksize,const RTPTransmissionParams *transparams);
166  void Destroy();
167  RTPTransmissionInfo *GetTransmissionInfo();
168 
169  int GetLocalHostName(uint8_t *buffer,size_t *bufferlength);
170  bool ComesFromThisTransmitter(const RTPAddress *addr);
171  size_t GetHeaderOverhead() { return RTPUDPV4TRANS_HEADERSIZE; }
172 
173  int Poll();
174  int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0);
175  int AbortWait();
176 
177  int SendRTPData(const void *data,size_t len);
178  int SendRTCPData(const void *data,size_t len);
179 
180  int AddDestination(const RTPAddress &addr);
181  int DeleteDestination(const RTPAddress &addr);
182  void ClearDestinations();
183 
184  bool SupportsMulticasting();
185  int JoinMulticastGroup(const RTPAddress &addr);
186  int LeaveMulticastGroup(const RTPAddress &addr);
187  void LeaveAllMulticastGroups();
188 
189  int SetReceiveMode(RTPTransmitter::ReceiveMode m);
190  int AddToIgnoreList(const RTPAddress &addr);
191  int DeleteFromIgnoreList(const RTPAddress &addr);
192  void ClearIgnoreList();
193  int AddToAcceptList(const RTPAddress &addr);
194  int DeleteFromAcceptList(const RTPAddress &addr);
195  void ClearAcceptList();
196  int SetMaximumPacketSize(size_t s);
197 
198  bool NewDataAvailable();
199  RTPRawPacket *GetNextPacket();
200 #ifdef RTPDEBUG
201  void Dump();
202 #endif // RTPDEBUG
203 private:
204  int CreateLocalIPList();
205  bool GetLocalIPList_Interfaces();
206  void GetLocalIPList_DNS();
207  void AddLoopbackAddress();
208  void FlushPackets();
209  int PollSocket(bool rtp);
210  int ProcessAddAcceptIgnoreEntry(uint32_t ip,uint16_t port);
211  int ProcessDeleteAcceptIgnoreEntry(uint32_t ip,uint16_t port);
212 #ifdef RTP_SUPPORT_IPV4MULTICAST
213  bool SetMulticastTTL(uint8_t ttl);
214 #endif // RTP_SUPPORT_IPV4MULTICAST
215  bool ShouldAcceptData(uint32_t srcip,uint16_t srcport);
216  void ClearAcceptIgnoreInfo();
217 
218  bool init;
219  bool created;
220  bool waitingfordata;
221 #if (defined(WIN32) || defined(_WIN32_WCE))
222  SOCKET rtpsock,rtcpsock;
223 #else // not using winsock
224  int rtpsock,rtcpsock;
225 #endif // WIN32
226  uint32_t bindIP, mcastifaceIP;
227  std::list<uint32_t> localIPs;
228  uint16_t portbase;
229  uint8_t multicastTTL;
230  RTPTransmitter::ReceiveMode receivemode;
231 
232  uint8_t *localhostname;
233  size_t localhostnamelength;
234 
235  RTPHashTable<const RTPIPv4Destination,RTPUDPv4Trans_GetHashIndex_IPv4Dest,RTPUDPV4TRANS_HASHSIZE> destinations;
236 #ifdef RTP_SUPPORT_IPV4MULTICAST
237  RTPHashTable<const uint32_t,RTPUDPv4Trans_GetHashIndex_uint32_t,RTPUDPV4TRANS_HASHSIZE> multicastgroups;
238 #endif // RTP_SUPPORT_IPV4MULTICAST
239  std::list<RTPRawPacket*> rawpacketlist;
240 
241  bool supportsmulticasting;
242  size_t maxpacksize;
243 
244  class PortInfo
245  {
246  public:
247  PortInfo() { all = false; }
248 
249  bool all;
250  std::list<uint16_t> portlist;
251  };
252 
253  RTPKeyHashTable<const uint32_t,PortInfo*,RTPUDPv4Trans_GetHashIndex_uint32_t,RTPUDPV4TRANS_HASHSIZE> acceptignoreinfo;
254 
255  // notification descriptors for AbortWait (0 is for reading, 1 for writing)
256 #if (defined(WIN32) || defined(_WIN32_WCE))
257  SOCKET abortdesc[2];
258 #else
259  int abortdesc[2];
260 #endif // WIN32
261  int CreateAbortDescriptors();
262  void DestroyAbortDescriptors();
263  void AbortWaitInternal();
264 #ifdef RTP_SUPPORT_THREAD
265  JMutex mainmutex,waitmutex;
266  int threadsafe;
267 #endif // RTP_SUPPORT_THREAD
268 };
269 
270 #endif // RTPUDPV4TRANSMITTER_H
271 
uint16_t GetPortbase() const
Returns the RTP portbase which will be used (default is 5000).
Definition: rtpudpv4transmitter.h:89
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:83
uint8_t GetMulticastTTL() const
Returns the multicast TTL which will be used (default is 1).
Definition: rtpudpv4transmitter.h:92
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:120
Additional information about the UDP over IPv4 transmitter.
Definition: rtpudpv4transmitter.h:104
std::list< uint32_t > GetLocalIPList() const
Returns the list of IPv4 addresses the transmitter considers to be the local IP addresses.
Definition: rtpudpv4transmitter.h:117
void SetPortbase(uint16_t pbase)
Sets the RTP portbase to pbase.
Definition: rtpudpv4transmitter.h:68
Base class for additional information about the transmitter.
Definition: rtptransmitter.h:236
Parameters for the UDP over IPv4 transmitter.
Definition: rtpudpv4transmitter.h:56
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
uint32_t GetMulticastInterfaceIP() const
Returns the multicast interface IP address.
Definition: rtpudpv4transmitter.h:86
void SetBindIP(uint32_t ip)
Sets the IP address which is used to bind the sockets to ip.
Definition: rtpudpv4transmitter.h:62
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:65
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:95
An UDP over IPv4 transmission component.
Definition: rtpudpv4transmitter.h:158
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:74
Base class for transmission parameters.
Definition: rtptransmitter.h:217
void ClearLocalIPList()
Clears the list of local IP addresses.
Definition: rtpudpv4transmitter.h:80
int GetRTCPSocket() const
Returns the socket descriptor used for receiving and transmitting RTCP packets.
Definition: rtpudpv4transmitter.h:123
void SetMulticastTTL(uint8_t mcastTTL)
Sets the multicast TTL to be used to mcastTTL.
Definition: rtpudpv4transmitter.h:71