Split capability definitions into own source file
[asterisk/asterisk.git] / channels / h323 / caps_h323.cxx
1 #include <ptlib.h>
2 #include <h323.h>
3 #include "caps_h323.h"
4
5 #define DEFINE_G711_CAPABILITY(cls, code, capName) \
6 class cls : public AST_G711Capability { \
7   public: \
8     cls() : AST_G711Capability(240, code) { } \
9 }; \
10 H323_REGISTER_CAPABILITY(cls, capName) \
11
12 DEFINE_G711_CAPABILITY(AST_G711ALaw64Capability, H323_G711Capability::ALaw, OPAL_G711_ALAW_64K);
13 DEFINE_G711_CAPABILITY(AST_G711uLaw64Capability, H323_G711Capability::muLaw, OPAL_G711_ULAW_64K);
14 H323_REGISTER_CAPABILITY(AST_G7231Capability, OPAL_G7231);
15 H323_REGISTER_CAPABILITY(AST_G729Capability,  OPAL_G729);
16 H323_REGISTER_CAPABILITY(AST_G729ACapability, OPAL_G729A);
17 H323_REGISTER_CAPABILITY(AST_GSM0610Capability, OPAL_GSM0610);
18
19 /*
20  * Capability: G.711
21  */
22 AST_G711Capability::AST_G711Capability(int rx_frames, H323_G711Capability::Mode m, H323_G711Capability::Speed s)
23         : H323AudioCapability(rx_frames, 30) // 240ms max, 30ms desired
24 {
25         mode = m;
26         speed = s;
27 }
28
29
30 PObject * AST_G711Capability::Clone() const
31 {
32         return new AST_G711Capability(*this);
33 }
34
35
36 unsigned AST_G711Capability::GetSubType() const
37 {
38         static const unsigned G711SubType[2][2] = {
39                 { H245_AudioCapability::e_g711Alaw64k, H245_AudioCapability::e_g711Alaw56k },
40                 { H245_AudioCapability::e_g711Ulaw64k, H245_AudioCapability::e_g711Ulaw56k }
41         };
42         return G711SubType[mode][speed];
43 }
44
45
46 PString AST_G711Capability::GetFormatName() const
47 {
48         static const char * const G711Name[2][2] = {
49                 { OPAL_G711_ALAW_64K, OPAL_G711_ALAW_56K },
50                 { OPAL_G711_ULAW_64K, OPAL_G711_ULAW_56K },
51         };
52         return G711Name[mode][speed];
53 }
54
55
56 H323Codec * AST_G711Capability::CreateCodec(H323Codec::Direction direction) const
57 {
58         return NULL;
59 }
60
61
62 /*
63  * Capability: G.723.1
64  */
65 AST_G7231Capability::AST_G7231Capability(int rx_frames, BOOL annexA_)
66         : H323AudioCapability(rx_frames, 4)
67 {
68         annexA = annexA_;
69 }
70
71 PObject::Comparison AST_G7231Capability::Compare(const PObject & obj) const
72 {
73         Comparison result = H323AudioCapability::Compare(obj);
74         if (result != EqualTo) {
75                 return result;
76         }
77         PINDEX otherAnnexA = ((const AST_G7231Capability &)obj).annexA;
78         if (annexA < otherAnnexA) {
79                 return LessThan;
80         }
81         if (annexA > otherAnnexA) {
82                 return GreaterThan;
83         }
84         return EqualTo;
85 }
86
87 PObject * AST_G7231Capability::Clone() const
88 {
89         return new AST_G7231Capability(*this);
90 }
91
92 PString AST_G7231Capability::GetFormatName() const
93 {
94         return (annexA ? OPAL_G7231 "A" : OPAL_G7231);
95 }
96
97 unsigned AST_G7231Capability::GetSubType() const
98 {
99         return H245_AudioCapability::e_g7231;
100 }
101
102 BOOL AST_G7231Capability::OnSendingPDU(H245_AudioCapability & cap,
103                                                                                 unsigned packetSize) const
104 {
105         cap.SetTag(H245_AudioCapability::e_g7231);
106         H245_AudioCapability_g7231 & g7231 = cap;
107         g7231.m_maxAl_sduAudioFrames = packetSize;
108         g7231.m_silenceSuppression = annexA;
109         return TRUE;
110 }
111
112 BOOL AST_G7231Capability::OnReceivedPDU(const H245_AudioCapability & cap,
113                                                                                 unsigned & packetSize)
114 {
115         if (cap.GetTag() != H245_AudioCapability::e_g7231) {
116                 return FALSE;
117         }
118         const H245_AudioCapability_g7231 & g7231 = cap;
119         packetSize = g7231.m_maxAl_sduAudioFrames;
120         annexA = g7231.m_silenceSuppression;
121         return TRUE;
122 }
123
124 H323Codec * AST_G7231Capability::CreateCodec(H323Codec::Direction direction) const
125 {
126         return NULL;
127 }
128
129 /*
130  * Capability: G.729
131  */
132 AST_G729Capability::AST_G729Capability(int rx_frames)
133         : H323AudioCapability(rx_frames, 2)
134 {
135 }
136
137 PObject * AST_G729Capability::Clone() const
138 {
139         return new AST_G729Capability(*this);
140 }
141
142 unsigned AST_G729Capability::GetSubType() const
143 {
144         return H245_AudioCapability::e_g729;
145 }
146
147 PString AST_G729Capability::GetFormatName() const
148 {
149         return OPAL_G729;
150 }
151
152 H323Codec * AST_G729Capability::CreateCodec(H323Codec::Direction direction) const
153 {
154         return NULL;
155 }
156
157 /*
158  * Capability: G.729A
159  */
160 AST_G729ACapability::AST_G729ACapability(int rx_frames)
161         : H323AudioCapability(rx_frames, 6)
162 {
163 }
164
165 PObject * AST_G729ACapability::Clone() const
166 {
167         return new AST_G729ACapability(*this);
168 }
169
170 unsigned AST_G729ACapability::GetSubType() const
171 {
172         return H245_AudioCapability::e_g729AnnexA;
173 }
174
175 PString AST_G729ACapability::GetFormatName() const
176 {
177         return OPAL_G729A;
178 }
179
180 H323Codec * AST_G729ACapability::CreateCodec(H323Codec::Direction direction) const
181 {
182         return NULL;
183 }
184
185 /*
186  * Capability: GSM full rate
187  */
188 AST_GSM0610Capability::AST_GSM0610Capability(int rx_frames, int comfortNoise_, int scrambled_)
189         : H323AudioCapability(rx_frames, 2)
190 {
191         comfortNoise = comfortNoise_;
192         scrambled = scrambled_;
193 }
194
195 PObject * AST_GSM0610Capability::Clone() const
196 {
197         return new AST_GSM0610Capability(*this);
198 }
199
200 unsigned AST_GSM0610Capability::GetSubType() const
201 {
202         return H245_AudioCapability::e_gsmFullRate;
203 }
204
205 BOOL AST_GSM0610Capability::OnSendingPDU(H245_AudioCapability & cap,
206                                                                                 unsigned packetSize) const
207 {
208         cap.SetTag(H245_AudioCapability::e_gsmFullRate);
209         H245_GSMAudioCapability & gsm = cap;
210         gsm.m_audioUnitSize = packetSize * 33;
211         gsm.m_comfortNoise = comfortNoise;
212         gsm.m_scrambled = scrambled;
213         return TRUE;
214 }
215
216 BOOL AST_GSM0610Capability::OnReceivedPDU(const H245_AudioCapability & cap,
217                                                                                 unsigned & packetSize)
218 {
219         if (cap.GetTag() != H245_AudioCapability::e_gsmFullRate)
220                 return FALSE;
221         const H245_GSMAudioCapability & gsm = cap;
222         packetSize = (gsm.m_audioUnitSize + 32) / 33;
223         comfortNoise = gsm.m_comfortNoise;
224         scrambled = gsm.m_scrambled;
225
226         return TRUE;
227 }
228
229 PString AST_GSM0610Capability::GetFormatName() const
230 {
231         return OPAL_GSM0610;
232 }
233
234 H323Codec * AST_GSM0610Capability::CreateCodec(H323Codec::Direction direction) const
235 {
236         return NULL;
237 }