Fix build error when chan_h323 is not being built.
[asterisk/asterisk.git] / channels / h323 / caps_h323.cxx
1 #include <ptlib.h>
2 #include <h323.h>
3 #include <h245.h>
4 #include "ast_h323.h"
5 #include "caps_h323.h"
6
7 #define DEFINE_G711_CAPABILITY(cls, code, capName) \
8 class cls : public AST_G711Capability { \
9 public: \
10         cls() : AST_G711Capability(240, code) { } \
11 }; \
12 H323_REGISTER_CAPABILITY(cls, capName) \
13
14 DEFINE_G711_CAPABILITY(AST_G711ALaw64Capability, H323_G711Capability::ALaw, OPAL_G711_ALAW_64K);
15 DEFINE_G711_CAPABILITY(AST_G711uLaw64Capability, H323_G711Capability::muLaw, OPAL_G711_ULAW_64K);
16 H323_REGISTER_CAPABILITY(AST_G7231Capability, OPAL_G7231);
17 H323_REGISTER_CAPABILITY(AST_G729Capability,  OPAL_G729);
18 H323_REGISTER_CAPABILITY(AST_G729ACapability, OPAL_G729A);
19 H323_REGISTER_CAPABILITY(AST_GSM0610Capability, OPAL_GSM0610);
20 H323_REGISTER_CAPABILITY(AST_CiscoG726Capability, CISCO_G726r32);
21 H323_REGISTER_CAPABILITY(AST_CiscoDtmfCapability, CISCO_DTMF_RELAY);
22
23 OPAL_MEDIA_FORMAT_DECLARE(OpalG711ALaw64kFormat,
24         OPAL_G711_ALAW_64K,
25         OpalMediaFormat::DefaultAudioSessionID,
26         RTP_DataFrame::PCMA,
27         TRUE,   // Needs jitter
28         64000,  // bits/sec
29         8,              // bytes/frame
30         8,              // 1 millisecond/frame
31         OpalMediaFormat::AudioTimeUnits,
32         0);
33 OPAL_MEDIA_FORMAT_DECLARE(OpalG711uLaw64kFormat,
34         OPAL_G711_ULAW_64K,
35         OpalMediaFormat::DefaultAudioSessionID,
36         RTP_DataFrame::PCMU,
37         TRUE,   // Needs jitter
38         64000,  // bits/sec
39         8,              // bytes/frame
40         8,              // 1 millisecond/frame
41         OpalMediaFormat::AudioTimeUnits,
42         0);
43 OPAL_MEDIA_FORMAT_DECLARE(OpalG729Format,
44         OPAL_G729,
45         OpalMediaFormat::DefaultAudioSessionID,
46         RTP_DataFrame::G729,
47         TRUE,   // Needs jitter
48         8000,   // bits/sec
49         10,             // bytes
50         80,             // 10 milliseconds
51         OpalMediaFormat::AudioTimeUnits,
52         0);
53 OPAL_MEDIA_FORMAT_DECLARE(OpalG729AFormat,
54         OPAL_G729 "A",
55         OpalMediaFormat::DefaultAudioSessionID,
56         RTP_DataFrame::G729,
57         TRUE,   // Needs jitter
58         8000,   // bits/sec
59         10,             // bytes
60         80,             // 10 milliseconds
61         OpalMediaFormat::AudioTimeUnits,
62         0);
63 OPAL_MEDIA_FORMAT_DECLARE(OpalG7231_6k3Format,
64         OPAL_G7231_6k3,
65         OpalMediaFormat::DefaultAudioSessionID,
66         RTP_DataFrame::G7231,
67         TRUE,   // Needs jitter
68         6400,   // bits/sec
69         24,             // bytes
70         240,    // 30 milliseconds
71         OpalMediaFormat::AudioTimeUnits,
72         0);
73 OPAL_MEDIA_FORMAT_DECLARE(OpalG7231A_6k3Format,
74         OPAL_G7231A_6k3,
75         OpalMediaFormat::DefaultAudioSessionID,
76         RTP_DataFrame::G7231,
77         TRUE,   // Needs jitter
78         6400,   // bits/sec
79         24,             // bytes
80         240,    // 30 milliseconds
81         OpalMediaFormat::AudioTimeUnits,
82         0);
83 OPAL_MEDIA_FORMAT_DECLARE(OpalGSM0610Format,
84         OPAL_GSM0610,
85         OpalMediaFormat::DefaultAudioSessionID,
86         RTP_DataFrame::GSM,
87         TRUE,   // Needs jitter
88         13200,  // bits/sec
89         33,             // bytes
90         160,    // 20 milliseconds
91         OpalMediaFormat::AudioTimeUnits,
92         0);
93 OPAL_MEDIA_FORMAT_DECLARE(OpalCiscoG726Format,
94         CISCO_G726r32,
95         OpalMediaFormat::DefaultAudioSessionID,
96         RTP_DataFrame::G726,
97         TRUE,   // Needs jitter
98         32000,  // bits/sec
99         4,              // bytes
100         8,              // 1 millisecond
101         OpalMediaFormat::AudioTimeUnits,
102         0);
103 #if 0
104 OPAL_MEDIA_FORMAT_DECLARE(OpalCiscoDTMFRelayFormat,
105         CISCO_DTMF_RELAY,
106         OpalMediaFormat::DefaultAudioSessionID,
107         (RTP_DataFrame::PayloadTypes)121, // Choose this for Cisco IOS compatibility
108         TRUE,   // Needs jitter
109         100,    // bits/sec
110         4,              // bytes/frame
111         8*150,  // 150 millisecond
112         OpalMediaFormat::AudioTimeUnits,
113         0);
114 #endif
115
116 /*
117  * Capability: G.711
118  */
119 AST_G711Capability::AST_G711Capability(int rx_frames, H323_G711Capability::Mode m, H323_G711Capability::Speed s)
120         : H323AudioCapability(rx_frames, 30) // 240ms max, 30ms desired
121 {
122         mode = m;
123         speed = s;
124 }
125
126
127 PObject * AST_G711Capability::Clone() const
128 {
129         return new AST_G711Capability(*this);
130 }
131
132
133 unsigned AST_G711Capability::GetSubType() const
134 {
135         static const unsigned G711SubType[2][2] = {
136                 { H245_AudioCapability::e_g711Alaw64k, H245_AudioCapability::e_g711Alaw56k },
137                 { H245_AudioCapability::e_g711Ulaw64k, H245_AudioCapability::e_g711Ulaw56k }
138         };
139         return G711SubType[mode][speed];
140 }
141
142
143 PString AST_G711Capability::GetFormatName() const
144 {
145         static const char * const G711Name[2][2] = {
146                 { OPAL_G711_ALAW_64K, OPAL_G711_ALAW_56K },
147                 { OPAL_G711_ULAW_64K, OPAL_G711_ULAW_56K },
148         };
149         return G711Name[mode][speed];
150 }
151
152
153 H323Codec * AST_G711Capability::CreateCodec(H323Codec::Direction direction) const
154 {
155         return NULL;
156 }
157
158
159 /*
160  * Capability: G.723.1
161  */
162 AST_G7231Capability::AST_G7231Capability(int rx_frames, PBoolean annexA_)
163         : H323AudioCapability(rx_frames, 4)
164 {
165         annexA = annexA_;
166 }
167
168 PObject::Comparison AST_G7231Capability::Compare(const PObject & obj) const
169 {
170         Comparison result = H323AudioCapability::Compare(obj);
171         if (result != EqualTo) {
172                 return result;
173         }
174         PINDEX otherAnnexA = ((const AST_G7231Capability &)obj).annexA;
175         if (annexA < otherAnnexA) {
176                 return LessThan;
177         }
178         if (annexA > otherAnnexA) {
179                 return GreaterThan;
180         }
181         return EqualTo;
182 }
183
184 PObject * AST_G7231Capability::Clone() const
185 {
186         return new AST_G7231Capability(*this);
187 }
188
189 PString AST_G7231Capability::GetFormatName() const
190 {
191         return (annexA ? OPAL_G7231 "A" : OPAL_G7231);
192 }
193
194 unsigned AST_G7231Capability::GetSubType() const
195 {
196         return H245_AudioCapability::e_g7231;
197 }
198
199 PBoolean AST_G7231Capability::OnSendingPDU(H245_AudioCapability & cap,
200                                                                                 unsigned packetSize) const
201 {
202         cap.SetTag(H245_AudioCapability::e_g7231);
203         H245_AudioCapability_g7231 & g7231 = cap;
204         g7231.m_maxAl_sduAudioFrames = packetSize;
205         g7231.m_silenceSuppression = annexA;
206         return TRUE;
207 }
208
209 PBoolean AST_G7231Capability::OnReceivedPDU(const H245_AudioCapability & cap,
210                                                                                 unsigned & packetSize)
211 {
212         if (cap.GetTag() != H245_AudioCapability::e_g7231) {
213                 return FALSE;
214         }
215         const H245_AudioCapability_g7231 & g7231 = cap;
216         packetSize = g7231.m_maxAl_sduAudioFrames;
217         annexA = g7231.m_silenceSuppression;
218         return TRUE;
219 }
220
221 H323Codec * AST_G7231Capability::CreateCodec(H323Codec::Direction direction) const
222 {
223         return NULL;
224 }
225
226 /*
227  * Capability: G.729
228  */
229 AST_G729Capability::AST_G729Capability(int rx_frames)
230         : H323AudioCapability(rx_frames, 2)
231 {
232 }
233
234 PObject * AST_G729Capability::Clone() const
235 {
236         return new AST_G729Capability(*this);
237 }
238
239 unsigned AST_G729Capability::GetSubType() const
240 {
241         return H245_AudioCapability::e_g729;
242 }
243
244 PString AST_G729Capability::GetFormatName() const
245 {
246         return OPAL_G729;
247 }
248
249 H323Codec * AST_G729Capability::CreateCodec(H323Codec::Direction direction) const
250 {
251         return NULL;
252 }
253
254 /*
255  * Capability: G.729A
256  */
257 AST_G729ACapability::AST_G729ACapability(int rx_frames)
258         : H323AudioCapability(rx_frames, 6)
259 {
260 }
261
262 PObject * AST_G729ACapability::Clone() const
263 {
264         return new AST_G729ACapability(*this);
265 }
266
267 unsigned AST_G729ACapability::GetSubType() const
268 {
269         return H245_AudioCapability::e_g729AnnexA;
270 }
271
272 PString AST_G729ACapability::GetFormatName() const
273 {
274         return OPAL_G729A;
275 }
276
277 H323Codec * AST_G729ACapability::CreateCodec(H323Codec::Direction direction) const
278 {
279         return NULL;
280 }
281
282 /*
283  * Capability: GSM full rate
284  */
285 AST_GSM0610Capability::AST_GSM0610Capability(int rx_frames, int comfortNoise_, int scrambled_)
286         : H323AudioCapability(rx_frames, 2)
287 {
288         comfortNoise = comfortNoise_;
289         scrambled = scrambled_;
290 }
291
292 PObject * AST_GSM0610Capability::Clone() const
293 {
294         return new AST_GSM0610Capability(*this);
295 }
296
297 unsigned AST_GSM0610Capability::GetSubType() const
298 {
299         return H245_AudioCapability::e_gsmFullRate;
300 }
301
302 PBoolean AST_GSM0610Capability::OnSendingPDU(H245_AudioCapability & cap,
303                                                                                 unsigned packetSize) const
304 {
305         cap.SetTag(H245_AudioCapability::e_gsmFullRate);
306         H245_GSMAudioCapability & gsm = cap;
307         gsm.m_audioUnitSize = packetSize * 33;
308         gsm.m_comfortNoise = comfortNoise;
309         gsm.m_scrambled = scrambled;
310         return TRUE;
311 }
312
313 PBoolean AST_GSM0610Capability::OnReceivedPDU(const H245_AudioCapability & cap,
314                                                                                 unsigned & packetSize)
315 {
316         if (cap.GetTag() != H245_AudioCapability::e_gsmFullRate)
317                 return FALSE;
318         const H245_GSMAudioCapability & gsm = cap;
319         packetSize = (gsm.m_audioUnitSize + 32) / 33;
320         comfortNoise = gsm.m_comfortNoise;
321         scrambled = gsm.m_scrambled;
322
323         return TRUE;
324 }
325
326 PString AST_GSM0610Capability::GetFormatName() const
327 {
328         return OPAL_GSM0610;
329 }
330
331 H323Codec * AST_GSM0610Capability::CreateCodec(H323Codec::Direction direction) const
332 {
333         return NULL;
334 }
335
336 /*
337  * Capability: G.726 32 Kbps
338  */
339 AST_CiscoG726Capability::AST_CiscoG726Capability(int rx_frames)
340         : H323NonStandardAudioCapability(rx_frames, 240,
341                 181, 0, 18,
342                 (const BYTE *)"G726r32", 0)
343 {
344 }
345
346 PObject *AST_CiscoG726Capability::Clone() const
347 {
348         return new AST_CiscoG726Capability(*this);
349 }
350
351 H323Codec *AST_CiscoG726Capability::CreateCodec(H323Codec::Direction direction) const
352 {
353         return NULL;
354 }
355
356 PString AST_CiscoG726Capability::GetFormatName() const
357 {
358         return PString(CISCO_G726r32);
359 }
360
361 /*
362  * Capability: Cisco RTP DTMF Relay
363  */
364 AST_CiscoDtmfCapability::AST_CiscoDtmfCapability()
365         : H323NonStandardDataCapability(0, 181, 0, 18, (const BYTE *)"RtpDtmfRelay", 0)
366 {
367         rtpPayloadType = (RTP_DataFrame::PayloadTypes)121;
368 }
369
370 PObject *AST_CiscoDtmfCapability::Clone() const
371 {
372         return new AST_CiscoDtmfCapability(*this);
373 }
374
375 H323Codec *AST_CiscoDtmfCapability::CreateCodec(H323Codec::Direction direction) const
376 {
377         return NULL;
378 }
379
380 PString AST_CiscoDtmfCapability::GetFormatName() const
381 {
382         return PString(CISCO_DTMF_RELAY);
383 }