ast_h323.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * ast_h323.h
  3. *
  4. * OpenH323 Channel Driver for ASTERISK PBX.
  5. * By Jeremy McNamara
  6. * For The NuFone Network
  7. *
  8. * This code has been derived from code created by
  9. * Michael Manousos and Mark Spencer
  10. *
  11. * This file is part of the chan_h323 driver for Asterisk
  12. *
  13. * chan_h323 is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * chan_h323 is distributed WITHOUT ANY WARRANTY; without even
  19. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  20. * PURPOSE. See the GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. * Version Info: $Id$
  27. */
  28. #include <ptlib.h>
  29. #include <h323.h>
  30. #include <h323pdu.h>
  31. #include <mediafmt.h>
  32. #include <lid.h>
  33. #include <list>
  34. #include <string>
  35. #include <algorithm>
  36. #include "chan_h323.h"
  37. /** These need to be redefined here because the C++
  38. side of this driver is blind to the asterisk headers */
  39. /*! G.723.1 compression */
  40. #define AST_FORMAT_G723_1 (1 << 0)
  41. /*! GSM compression */
  42. #define AST_FORMAT_GSM (1 << 1)
  43. /*! Raw mu-law data (G.711) */
  44. #define AST_FORMAT_ULAW (1 << 2)
  45. /*! Raw A-law data (G.711) */
  46. #define AST_FORMAT_ALAW (1 << 3)
  47. /*! MPEG-2 layer 3 */
  48. #define AST_FORMAT_MP3 (1 << 4)
  49. /*! ADPCM (whose?) */
  50. #define AST_FORMAT_ADPCM (1 << 5)
  51. /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
  52. #define AST_FORMAT_SLINEAR (1 << 6)
  53. /*! LPC10, 180 samples/frame */
  54. #define AST_FORMAT_LPC10 (1 << 7)
  55. /*! G.729A audio */
  56. #define AST_FORMAT_G729A (1 << 8)
  57. /*! SpeeX Free Compression */
  58. #define AST_FORMAT_SPEEX (1 << 9)
  59. /*! ILBC Free Codec */
  60. #define AST_FORMAT_ILBC (1 << 10)
  61. /**This class describes the G.723.1 codec capability.
  62. */
  63. class H323_G7231Capability : public H323AudioCapability
  64. {
  65. PCLASSINFO(H323_G7231Capability, H323AudioCapability);
  66. public:
  67. H323_G7231Capability(
  68. BOOL annexA = TRUE /// Enable Annex A silence insertion descriptors
  69. );
  70. Comparison Compare(const PObject & obj) const;
  71. PObject * Clone() const;
  72. virtual H323Codec * CreateCodec(
  73. H323Codec::Direction direction /// Direction in which this instance runs
  74. ) const;
  75. unsigned GetSubType() const;
  76. PString GetFormatName() const;
  77. BOOL OnSendingPDU(
  78. H245_AudioCapability & pdu, /// PDU to set information on
  79. unsigned packetSize /// Packet size to use in capability
  80. ) const;
  81. BOOL OnReceivedPDU(
  82. const H245_AudioCapability & pdu, /// PDU to get information from
  83. unsigned & packetSize /// Packet size to use in capability
  84. );
  85. protected:
  86. BOOL annexA;
  87. };
  88. /**This class describes the (fake) G729 codec capability.
  89. */
  90. class AST_G729Capability : public H323AudioCapability
  91. {
  92. PCLASSINFO(AST_G729Capability, H323AudioCapability);
  93. public:
  94. /**@name Construction */
  95. //@{
  96. /**Create a new G.729 capability.
  97. */
  98. AST_G729Capability();
  99. //@}
  100. /**@name Overrides from class PObject */
  101. //@{
  102. /**Create a copy of the object.
  103. */
  104. virtual PObject * Clone() const;
  105. //@}
  106. /**@name Operations */
  107. //@{
  108. /**Create the codec instance, allocating resources as required.
  109. */
  110. virtual H323Codec * CreateCodec(
  111. H323Codec::Direction direction /// Direction in which this instance runs
  112. ) const;
  113. //@}
  114. /**@name Identification functions */
  115. //@{
  116. /**Get the sub-type of the capability. This is a code dependent on the
  117. main type of the capability.
  118. This returns one of the four possible combinations of mode and speed
  119. using the enum values of the protocol ASN H245_AudioCapability class.
  120. */
  121. virtual unsigned GetSubType() const;
  122. /**Get the name of the media data format this class represents.
  123. */
  124. virtual PString GetFormatName() const;
  125. //@}
  126. };
  127. /**This class describes the VoiceAge G729A codec capability.
  128. */
  129. class AST_G729ACapability : public H323AudioCapability
  130. {
  131. PCLASSINFO(AST_G729ACapability, H323AudioCapability);
  132. public:
  133. /**@name Construction */
  134. //@{
  135. /**Create a new G.729A capability.
  136. */
  137. AST_G729ACapability();
  138. //@}
  139. /**@name Overrides from class PObject */
  140. //@{
  141. /**Create a copy of the object.
  142. */
  143. virtual PObject * Clone() const;
  144. //@}
  145. /**@name Operations */
  146. //@{
  147. /**Create the codec instance, allocating resources as required.
  148. */
  149. virtual H323Codec * CreateCodec(
  150. H323Codec::Direction direction /// Direction in which this instance runs
  151. ) const;
  152. //@}
  153. /**@name Identification functions */
  154. //@{
  155. /**Get the sub-type of the capability. This is a code dependent on the
  156. main type of the capability.
  157. This returns one of the four possible combinations of mode and speed
  158. using the enum values of the protocol ASN H245_AudioCapability class.
  159. */
  160. virtual unsigned GetSubType() const;
  161. /**Get the name of the media data format this class represents.
  162. */
  163. virtual PString GetFormatName() const;
  164. //@}
  165. };
  166. class MyH323EndPoint : public H323EndPoint {
  167. PCLASSINFO(MyH323EndPoint, H323EndPoint);
  168. public:
  169. int MakeCall(const PString &, PString &, unsigned int *, unsigned int, char *);
  170. BOOL ClearCall(const PString &);
  171. void OnClosedLogicalChannel(H323Connection &, const H323Channel &);
  172. void OnConnectionEstablished(H323Connection &, const PString &);
  173. void OnConnectionCleared(H323Connection &, const PString &);
  174. H323Connection * CreateConnection(unsigned, void *);
  175. void SendUserTone(const PString &, char);
  176. H323Capabilities GetCapabilities(void);
  177. BOOL OnConnectionForwarded(H323Connection &, const PString &, const H323SignalPDU &);
  178. BOOL ForwardConnection(H323Connection &, const PString &, const H323SignalPDU &);
  179. PStringArray SupportedPrefixes;
  180. void SetEndpointTypeInfo( H225_EndpointType & info ) const;
  181. void SetGateway(void);
  182. };
  183. class MyH323Connection : public H323Connection {
  184. PCLASSINFO(MyH323Connection, H323Connection);
  185. public:
  186. MyH323Connection(MyH323EndPoint &, unsigned, unsigned);
  187. ~MyH323Connection();
  188. H323Channel * CreateRealTimeLogicalChannel(const H323Capability &, H323Channel::Directions, unsigned,
  189. const H245_H2250LogicalChannelParameters *);
  190. H323Connection::AnswerCallResponse OnAnswerCall(const PString &, const H323SignalPDU &, H323SignalPDU &);
  191. void OnReceivedReleaseComplete(const H323SignalPDU &);
  192. BOOL OnAlerting(const H323SignalPDU &, const PString &);
  193. BOOL OnSendReleaseComplete(H323SignalPDU &);
  194. BOOL OnReceivedSignalSetup(const H323SignalPDU &);
  195. BOOL OnReceivedFacility(const H323SignalPDU &);
  196. BOOL OnSendSignalSetup(H323SignalPDU &);
  197. BOOL OnStartLogicalChannel(H323Channel &);
  198. BOOL OnClosingLogicalChannel(H323Channel &);
  199. void SendUserInputTone(char, unsigned);
  200. void OnUserInputTone(char, unsigned, unsigned, unsigned);
  201. void OnUserInputString(const PString &value);
  202. PString sourceAliases;
  203. PString destAliases;
  204. PString sourceE164;
  205. PString destE164;
  206. PIPSocket::Address externalIpAddress; // IP address of media server
  207. PIPSocket::Address remoteIpAddress; // IP Address of remote endpoint
  208. WORD externalPort; // local media server Data port (control is dataPort+1)
  209. WORD remotePort; // remote endpoint Data port (control is dataPort+1)
  210. WORD sessionId;
  211. BOOL bridging; // Used to help determine which IP to use
  212. };
  213. /**
  214. * The MyProcess is a necessary descendant PProcess class so that the H323EndPoint
  215. * objected to be created from within that class. (Who owns main() problem).
  216. */
  217. class MyProcess : public PProcess {
  218. PCLASSINFO(MyProcess, PProcess);
  219. public:
  220. MyProcess();
  221. void Main();
  222. };