aboutsummaryrefslogtreecommitdiffstats
path: root/channels/h323/ast_h323.h
blob: 2d499ac3af875a67fc8a51c89dc6b781cbed51fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
 * ast_h323.h
 *
 * OpenH323 Channel Driver for ASTERISK PBX.
 *			By Jeremy McNamara
 *                      For The NuFone Network 
 * 
 * This code has been derived from code created by
 *              Michael Manousos and Mark Spencer
 *
 * This file is part of the chan_h323 driver for Asterisk
 *
 * chan_h323 is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * chan_h323 is distributed WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Version Info: $Id$
 */

#ifndef AST_H323_H
#define AST_H323_H

#define VERSION(a,b,c) ((a)*10000+(b)*100+(c))

/**This class describes the G.711 codec capability.
 */
class AST_G711Capability : public H323AudioCapability
{
	PCLASSINFO(AST_G711Capability, H323AudioCapability);

public:
	AST_G711Capability(int rx_frames = 125, H323_G711Capability::Mode _mode = H323_G711Capability::muLaw, H323_G711Capability::Speed _speed = H323_G711Capability::At64k);
	virtual PObject *Clone() const;
	virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;
	virtual unsigned GetSubType() const;
	virtual PString GetFormatName() const;

protected:
	H323_G711Capability::Mode mode;
	H323_G711Capability::Speed speed;
};

/**This class describes the G.723.1 codec capability.
 */
class AST_G7231Capability : public H323AudioCapability
{
	PCLASSINFO(AST_G7231Capability, H323AudioCapability);

public:
	AST_G7231Capability(int rx_frames = 7, BOOL annexA = TRUE);
	Comparison Compare(const PObject & obj) const;
	virtual PObject * Clone() const;
	virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;
	virtual unsigned GetSubType() const;
	virtual PString GetFormatName() const;
	virtual BOOL OnSendingPDU(H245_AudioCapability & pdu, unsigned packetSize) const;
	virtual BOOL OnReceivedPDU(const H245_AudioCapability & pdu, unsigned & packetSize);

protected:
	BOOL annexA;
};

/**This class describes the (fake) G729 codec capability.
 */
class AST_G729Capability : public H323AudioCapability
{
	PCLASSINFO(AST_G729Capability, H323AudioCapability);

public:
	AST_G729Capability(int rx_frames = 24);
	/* Create a copy of the object. */
	virtual PObject * Clone() const;

	/* Create the codec instance, allocating resources as required. */
	virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;

	/* Get the sub-type of the capability. This is a code dependent on the
	   main type of the capability.

	   This returns one of the four possible combinations of mode and speed
	   using the enum values of the protocol ASN H245_AudioCapability class. */
	virtual unsigned GetSubType() const;

	/* Get the name of the media data format this class represents. */
	virtual PString GetFormatName() const;
};

/* This class describes the VoiceAge G729A codec capability. */
class AST_G729ACapability : public H323AudioCapability
{
	PCLASSINFO(AST_G729ACapability, H323AudioCapability);

public:
	/* Create a new G.729A capability. */
	AST_G729ACapability(int rx_frames = 24);

	/* Create a copy of the object. */
	virtual PObject * Clone() const;
	/* Create the codec instance, allocating resources as required. */
	virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;

	/* Get the sub-type of the capability. This is a code dependent on the
	   main type of the capability.

	   This returns one of the four possible combinations of mode and speed
	   using the enum values of the protocol ASN H245_AudioCapability class. */
	virtual unsigned GetSubType() const;

	/* Get the name of the media data format this class represents. */
	virtual PString GetFormatName() const;
};

/* This class describes the GSM-06.10 codec capability. */
class AST_GSM0610Capability : public H323AudioCapability
{
	PCLASSINFO(AST_GSM0610Capability, H323AudioCapability);

public:
	/* Create a new GSM capability. */
	AST_GSM0610Capability(int rx_frames = 24, int comfortNoise = 0, int scrambled = 0);

	/* Create a copy of the object. */
	virtual PObject * Clone() const;

	/* Create the codec instance, allocating resources as required. */
	virtual H323Codec * CreateCodec(H323Codec::Direction direction) const;

	/* Get the sub-type of the capability. This is a code dependent on the
	   main type of the capability.

	   This returns one of the four possible combinations of mode and speed
	   using the enum values of the protocol ASN H245_AudioCapability class. */
	virtual unsigned GetSubType() const;

	/* Get the name of the media data format this class represents. */
	virtual PString GetFormatName() const;

	BOOL OnSendingPDU(H245_AudioCapability & pdu, unsigned packetSize) const;
	BOOL OnReceivedPDU(const H245_AudioCapability & pdu, unsigned & packetSize);

protected:
	int comfortNoise;
	int scrambled;
};

class MyH323EndPoint : public H323EndPoint
{
	PCLASSINFO(MyH323EndPoint, H323EndPoint);

public:
	MyH323EndPoint();
	int MyMakeCall(const PString &, PString &, void *_callReference, void *_opts);
	BOOL ClearCall(const PString &, H323Connection::CallEndReason reason);
	BOOL ClearCall(const PString &);

	void OnClosedLogicalChannel(H323Connection &, const H323Channel &);
	void OnConnectionEstablished(H323Connection &, const PString &);
	void OnConnectionCleared(H323Connection &, const PString &);
	virtual H323Connection * CreateConnection(unsigned, void *, H323Transport *, H323SignalPDU *);
	void SendUserTone(const PString &, char);
	BOOL OnConnectionForwarded(H323Connection &, const PString &, const H323SignalPDU &);
	BOOL ForwardConnection(H323Connection &, const PString &, const H323SignalPDU &);
	void SetEndpointTypeInfo( H225_EndpointType & info ) const;
	void SetGateway(void);
	PStringArray SupportedPrefixes;
};

class MyH323Connection : public H323Connection
{
	PCLASSINFO(MyH323Connection, H323Connection);

public:
	MyH323Connection(MyH323EndPoint &, unsigned, unsigned);
	~MyH323Connection();
	H323Channel * CreateRealTimeLogicalChannel(const H323Capability &,
			H323Channel::Directions,
			unsigned,
			const H245_H2250LogicalChannelParameters *,
			RTP_QOS *);
	H323Connection::AnswerCallResponse OnAnswerCall(const PString &,
			const H323SignalPDU &,
			H323SignalPDU &);
	void OnReceivedReleaseComplete(const H323SignalPDU &);
	BOOL OnAlerting(const H323SignalPDU &, const PString &);
	BOOL OnSendReleaseComplete(H323SignalPDU &);
	BOOL OnReceivedSignalSetup(const H323SignalPDU &);
	BOOL OnReceivedFacility(const H323SignalPDU &);
	BOOL OnSendSignalSetup(H323SignalPDU &);
	BOOL OnStartLogicalChannel(H323Channel &);
	BOOL OnClosingLogicalChannel(H323Channel &);
	virtual void SendUserInputTone(char tone, unsigned duration = 0, unsigned logicalChannel = 0, unsigned rtpTimestamp = 0);
	virtual void OnUserInputTone(char, unsigned, unsigned, unsigned);
	virtual void OnUserInputString(const PString &value);
	BOOL OnReceivedProgress(const H323SignalPDU &);
	void OnSendCapabilitySet(H245_TerminalCapabilitySet &);
	void OnSetLocalCapabilities();
	void SetCapabilities(int, int, void *, int);
	BOOL OnReceivedCapabilitySet(const H323Capabilities &, const H245_MultiplexCapability *,
			H245_TerminalCapabilitySetReject &);
	void SetCause(int _cause) { cause = _cause; };
	virtual BOOL StartControlChannel(const H225_TransportAddress & h245Address);
	void SetCallOptions(void *opts, BOOL isIncoming);
	void SetCallDetails(void *callDetails, const H323SignalPDU &setupPDU, BOOL isIncoming);
#ifdef TUNNELLING
	virtual BOOL HandleSignalPDU(H323SignalPDU &pdu);
	BOOL EmbedTunneledInfo(H323SignalPDU &pdu);
#endif

	PString sourceAliases;
	PString destAliases;
	PString sourceE164;
	PString destE164;
	PString rdnis;
	int redirect_reason;

	WORD sessionId;
	BOOL bridging;
#ifdef TUNNELLING
	int remoteTunnelOptions;
	int tunnelOptions;
#endif

	unsigned progressSetup;
	unsigned progressAlert;
	int cause;

	RTP_DataFrame::PayloadTypes dtmfCodec;
	int dtmfMode;
};

class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel
{
	PCLASSINFO(MyH323_ExternalRTPChannel, H323_ExternalRTPChannel);

public:
	MyH323_ExternalRTPChannel(
			MyH323Connection & connection,
			const H323Capability & capability,
			Directions direction,
			unsigned sessionID);

	~MyH323_ExternalRTPChannel();

	/* Overrides */
	BOOL Start(void);
	BOOL OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param);

protected:
	BYTE payloadCode;

	PIPSocket::Address localIpAddr;
	PIPSocket::Address remoteIpAddr;
	WORD localPort;
	WORD remotePort;
};

/**
 * The MyProcess is a necessary descendant PProcess class so that the H323EndPoint
 * objected to be created from within that class. (Solves the who owns main() problem).
 */
class MyProcess : public PProcess
{
	PCLASSINFO(MyProcess, PProcess);

public:
	MyProcess();
	~MyProcess();
	void Main();
};

#include "compat_h323.h"

#endif /* !defined AST_H323_H */