OPAL  Version 3.14.3
h460_std19.h
Go to the documentation of this file.
1 /*
2  * h460_std19.h
3  *
4  * Copyright (c) 2009 ISVO (Asia) Pte Ltd. All Rights Reserved.
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Alternatively, the contents of this file may be used under the terms
12  * of the General Public License (the "GNU License"), in which case the
13  * provisions of GNU License are applicable instead of those
14  * above. If you wish to allow use of your version of this file only
15  * under the terms of the GNU License and not to allow others to use
16  * your version of this file under the MPL, indicate your decision by
17  * deleting the provisions above and replace them with the notice and
18  * other provisions required by the GNU License. If you do not delete
19  * the provisions above, a recipient may use your version of this file
20  * under either the MPL or the GNU License."
21  *
22  * Software distributed under the License is distributed on an "AS IS"
23  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
24  * the License for the specific language governing rights and limitations
25  * under the License.
26  *
27  * The Original Code is derived from and used in conjunction with the
28  * H323Plus Project (www.h323plus.org/)
29  *
30  * The Initial Developer of the Original Code is ISVO (Asia) Pte Ltd.
31  *
32  * Contributor(s): Many thanks to Simon Horne.
33  * Robert Jongbloed (robertj@voxlucida.com.au).
34  *
35  * $Revision: 31477 $
36  * $Author: rjongbloed $
37  * $Date: 2014-02-15 15:33:06 +1100 (Sat, 15 Feb 2014) $
38  */
39 
40 #ifndef OPAL_H460_STD19_H
41 #define OPAL_H460_STD19_H
42 
43 #include <h460/h4601.h>
44 
45 #if OPAL_H460_NAT
46 
47 #include <rtp/rtp.h>
48 
49 #if _MSC_VER
50 #pragma once
51 #endif
52 
53 
54 class OpalRTPSession;
56 
57 
58 class H460_FeatureStd19 : public H460_Feature
59 {
60  PCLASSINFO_WITH_CLONE(H460_FeatureStd19, H460_Feature);
61  public:
62  H460_FeatureStd19();
63 
64  static const H460_FeatureID & ID();
65  virtual bool Initialise(H323EndPoint & ep, H323Connection * con);
66 
67  // H.225.0 Messages
68  virtual bool OnSendPDU(H460_MessageType pduType, H460_FeatureDescriptor & pdu);
69  virtual void OnReceivePDU(H460_MessageType pduType, const H460_FeatureDescriptor & pdu);
70 
71  virtual bool OnSendingOLCGenericInformation(unsigned sessionID, H245_ArrayOf_GenericParameter & param, bool isAck);
72  virtual void OnReceiveOLCGenericInformation(unsigned sessionID, const H245_ArrayOf_GenericParameter & param, bool isAck);
73 
74  // Member access
75  bool IsRemoteServer() const { return m_remoteIsServer; }
76 
77  protected:
78  PNatMethod * m_natMethod;
79  bool m_disabledByH46024;
80  bool m_remoteSupportsMux;
81  bool m_remoteIsServer;
82 };
83 
84 
86 
87 class H46019Server : public PObject
88 {
89  PCLASSINFO(H46019Server, PObject)
90  public:
91  H46019Server(H323EndPoint & ep);
92  H46019Server(
93  H323EndPoint & ep,
94  const PIPSocket::Address & localInterface
95  );
96  ~H46019Server();
97 
98  unsigned GetKeepAliveTTL() const { return m_keepAliveTTL; }
99  void SetKeepAliveTTL(unsigned val) { m_keepAliveTTL = val; }
100 
101  H323TransportAddress GetKeepAliveAddress() const;
102  H323TransportAddress GetMuxRTPAddress() const;
103  H323TransportAddress GetMuxRTCPAddress() const;
104 
105  unsigned CreateMultiplexID(
106  const PIPSocketAddressAndPort & rtp,
107  const PIPSocketAddressAndPort & rtcp
108  );
109 
110  protected:
111  H323EndPoint & m_endpoint;
112  unsigned m_keepAliveTTL;
113 
114  PUDPSocket * m_keepAliveSocket;
115  PUDPSocket * m_rtpSocket;
116  PUDPSocket * m_rtcpSocket;
117 
118  struct SocketPair {
119  SocketPair(const PIPSocketAddressAndPort & rtp, const PIPSocketAddressAndPort & rtcp) : m_rtp(rtp), m_rtcp(rtcp) { }
120  PIPSocketAddressAndPort m_rtp;
121  PIPSocketAddressAndPort m_rtcp;
122  };
123  typedef map<uint32_t, SocketPair> MuxMap;
124  MuxMap m_multiplexedSockets;
125 
126  PThread * m_multiplexThread;
127  void MultiplexThread();
128  bool Multiplex(bool rtcp);
129 };
130 
131 
133 
134 class PNatMethod_H46019 : public PNatMethod
135 {
136  PCLASSINFO(PNatMethod_H46019, PNatMethod);
137  public:
138  enum { DefaultPriority = 20 };
139  PNatMethod_H46019(unsigned priority = DefaultPriority);
140 
146  virtual PCaselessString GetMethodName() const;
147  static const char * MethodName();
148 
151  virtual PString GetServer() const;
152 
161  virtual bool IsAvailable(const PIPSocket::Address & address, PObject * userData);
163 
164  protected:
165  virtual PNATUDPSocket * InternalCreateSocket(Component component, PObject * context);
166  virtual void InternalUpdate();
167 };
168 
169 
171 
172 class H46019UDPSocket : public PNATUDPSocket
173 {
174  PCLASSINFO(H46019UDPSocket, PNATUDPSocket);
175  public:
181  H46019UDPSocket(
182  PNatMethod::Component component,
183  OpalRTPSession & session
184  );
185 
186  ~H46019UDPSocket();
188 
191  virtual const char * GetNatName() const;
192 
195  void ActivateKeepAliveRTP(
196  const H323TransportAddress & address,
197  unsigned ttl
198  );
199 
200  void ActivateKeepAliveRTCP(unsigned ttl);
201 
202  void SetMultiplexID(unsigned multiplexID) { m_multiplexedTransmit = true; m_multiplexID = multiplexID; }
203 
204  RTP_DataFrame::PayloadTypes FindKeepAlivePayloadType(H323Connection & connection);
205 
206  protected:
207  bool InternalWriteTo(const Slice * slices, size_t sliceCount, const PIPSocketAddressAndPort & ipAndPort);
208 
209  // Memeber variables
210  OpalRTPSession & m_session;
211 
212  // H.460.19 keep alives
213  PIPSocketAddressAndPort m_keepAliveAddress;
214  RTP_DataFrame::PayloadTypes m_keepAlivePayloadType;
215  PTimeInterval m_keepAliveTTL;
216  WORD m_keepAliveSequence;
217 
218  PDECLARE_NOTIFIER(PTimer, H46019UDPSocket, KeepAliveTimeout);
219  PTimer m_keepAliveTimer;
220  void SendKeepAliveRTP(const PIPSocketAddressAndPort & ipAndPort);
221 
222  // H.460.19 multiplex transmit
223  bool m_multiplexedTransmit;
224  PUInt32b m_multiplexID;
225 };
226 
227 
228 #endif // OPAL_H460_NAT
229 
230 #endif // OPAL_H460_STD19_H