Utilise new MergeSym feature to no longer overwrite the source .DEF file when buildin...
[openh323.git] / src / opalvxml.cxx
blobdd8c9501c4e5a174835b50ba666e56e396cfce84
1 /*
2 * vxml.cxx
4 * VXML control for for Opal
6 * A H.323 IVR application.
8 * Copyright (C) 2002 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
26 * $Log$
27 * Revision 1.22 2004/07/15 11:20:38 rjongbloed
28 * Migrated changes from crs_vxnml_devel branch into main trunk
30 * Revision 1.21 2004/07/15 03:18:00 csoutheren
31 * Migrated changes from crs_vxnml_devel branch into main trunk
33 * Revision 1.20.2.1 2004/07/07 07:10:11 csoutheren
34 * Changed to use new factory based PWAVFile
35 * Removed redundant blocking/unblocking when using G.723.1
37 * Revision 1.20 2004/05/04 23:23:39 csoutheren
38 * Removed usage of lpc10 and mscodecs
40 * Revision 1.19 2004/05/03 13:21:45 rjongbloed
41 * Converted everything to be codec plug in freindly
42 * Removed GSM and G.729 as now plug ins are "the way"!
44 * Revision 1.18 2002/12/10 23:50:25 robertj
45 * Fixed some tracing issues
47 * Revision 1.17 2002/08/27 02:21:31 craigs
48 * Added silence detection capability to fake G.723.1codec
50 * Revision 1.16 2002/08/15 04:55:26 robertj
51 * Fixed shutdown problems with closing vxml session, leaks a thread.
52 * Fixed potential problems with indirect channel Close() function.
54 * Revision 1.15 2002/08/15 02:19:42 robertj
55 * Adjusted trace log levels for G.723.1 file codec read/write tracking.
57 * Revision 1.14 2002/08/07 13:53:05 craigs
58 * Fixed problem with included opalvxml.h thanks to Vladmir Toncar
60 * Revision 1.13 2002/08/06 05:10:59 craigs
61 * Moved most of stuff to ptclib
63 * Revision 1.12 2002/08/05 09:43:30 robertj
64 * Added pragma interface/implementation
65 * Moved virtual into .cxx file
67 * Revision 1.11 2002/07/29 15:10:36 craigs
68 * Added autodelete option to PlayFile
70 * Revision 1.10 2002/07/29 12:54:42 craigs
71 * Removed usages of cerr
73 * Revision 1.9 2002/07/18 04:17:12 robertj
74 * Moved virtuals to source and changed name of G.723.1 file capability
76 * Revision 1.8 2002/07/10 13:16:58 craigs
77 * Moved some VXML classes from Opal back into PTCLib
78 * Added ability to repeat outputted data
80 * Revision 1.7 2002/07/09 08:48:41 craigs
81 * Fixed trace messages
83 * Revision 1.6 2002/07/05 06:34:04 craigs
84 * Changed comments and trace messages
86 * Revision 1.5 2002/07/03 04:58:13 robertj
87 * Changed for compatibility with older GNU compilers
89 * Revision 1.4 2002/07/02 06:32:51 craigs
90 * Added recording functions
92 * Revision 1.3 2002/06/28 02:42:11 craigs
93 * Fixed problem with G.723.1 file naming conventions
94 * Fixed problem with incorrect file open mode
96 * Revision 1.2 2002/06/28 01:24:03 robertj
97 * Fixe dproblem with compiling without expat library.
99 * Revision 1.1 2002/06/27 05:44:11 craigs
100 * Initial version
102 * Revision 1.2 2002/06/26 09:05:28 csoutheren
103 * Added ability to utter various "sayas" types within prompts
105 * Revision 1.1 2002/06/26 01:13:53 csoutheren
106 * Disassociated VXML and Opal/OpenH323 specific elements
108 * Revision 1.2 2002/06/21 08:18:22 csoutheren
109 * Added start of grammar handling
111 * Revision 1.1 2002/06/20 06:35:44 csoutheren
112 * Initial version
116 #include <ptlib.h>
118 #ifdef __GNUC__
119 #pragma implementation "opalvxml.h"
120 #endif
122 #include "opalvxml.h"
124 #if P_EXPAT
126 #include <ptclib/delaychan.h>
127 #include <ptclib/pwavfile.h>
128 #include <ptclib/memfile.h>
130 #endif
132 #include "codecs.h"
134 #define G7231_SAMPLES_PER_BLOCK 240
135 #define G7231_BANDWIDTH (6300/100)
137 ///////////////////////////////////////////////////////////////
139 G7231_File_Capability::G7231_File_Capability()
140 : H323AudioCapability(8, 4)
144 unsigned G7231_File_Capability::GetSubType() const
146 return H245_AudioCapability::e_g7231;
149 PString G7231_File_Capability::GetFormatName() const
151 return "G.723.1{file}";
154 BOOL G7231_File_Capability::OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const
156 // set the choice to the correct type
157 cap.SetTag(GetSubType());
159 // get choice data
160 H245_AudioCapability_g7231 & g7231 = cap;
162 // max number of audio frames per PDU we want to send
163 g7231.m_maxAl_sduAudioFrames = packetSize;
165 // enable silence suppression
166 g7231.m_silenceSuppression = TRUE;
168 return TRUE;
171 BOOL G7231_File_Capability::OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize)
173 const H245_AudioCapability_g7231 & g7231 = cap;
174 packetSize = g7231.m_maxAl_sduAudioFrames;
175 return TRUE;
178 PObject * G7231_File_Capability::Clone() const
180 return new G7231_File_Capability(*this);
183 H323Codec * G7231_File_Capability::CreateCodec(H323Codec::Direction direction) const
185 return new G7231_File_Codec(direction);
188 ///////////////////////////////////////////////////////////////
190 G7231_File_Codec::G7231_File_Codec(Direction dir)
191 : H323AudioCodec(OPAL_G7231_6k3, dir)
193 lastFrameLen = 4;
197 int G7231_File_Codec::GetFrameLen(int val)
199 static const int frameLen[] = { 24, 20, 4, 1 };
200 return frameLen[val & 3];
203 BOOL G7231_File_Codec::Read(BYTE * buffer, unsigned & length, RTP_DataFrame &)
205 if (rawDataChannel == NULL)
206 return FALSE;
208 if (!rawDataChannel->Read(buffer, 24)) {
209 PTRACE(1, "G7231WAV\tRead failed");
210 return FALSE;
213 lastFrameLen = length = G7231_File_Codec::GetFrameLen(buffer[0]);
215 return TRUE;
219 BOOL G7231_File_Codec::Write(const BYTE * buffer,
220 unsigned length,
221 const RTP_DataFrame & /* rtp */,
222 unsigned & writtenLength)
224 if (rawDataChannel == NULL)
225 return TRUE;
227 static const BYTE silence[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
228 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
229 0, 0, 0, 0};
231 // If the length is zero, output silence to the file..
232 if (length == 0) {
233 PTRACE(6,"G7231WAV\tZero length frame");
234 writtenLength = 0;
235 return rawDataChannel->Write(silence, 24);
238 int writeLen;
239 switch (buffer[0]&3) {
240 case 0:
241 writeLen = 24;
242 break;
243 case 1:
244 writeLen = 20;
245 break;
246 case 2:
247 // Windows Media Player cannot play 4 byte SID (silence) frames.
248 // So write out a 24 byte frame of silence instead.
249 PTRACE(5, "G7231WAV\tReplacing SID with 24 byte frame");
250 writtenLength = 4;
251 return rawDataChannel->Write(silence, 24);
252 default :
253 writeLen = 1;
254 break;
257 PTRACE(6, "G7231WAV\tFrame length = " <<writeLen);
259 writtenLength = writeLen;
261 return rawDataChannel->Write(buffer, writeLen);
265 unsigned G7231_File_Codec::GetBandwidth() const
267 return G7231_BANDWIDTH;
271 BOOL G7231_File_Codec::IsRawDataChannelNative() const
273 return TRUE;
276 unsigned G7231_File_Codec::GetAverageSignalLevel()
278 if (lastFrameLen == 4)
279 return 0;
280 else
281 return UINT_MAX;
284 ///////////////////////////////////////////////////////////////
286 #if P_EXPAT
288 OpalVXMLSession::OpalVXMLSession(H323Connection * _conn, PTextToSpeech * tts, BOOL autoDelete)
289 : PVXMLSession(tts, autoDelete), conn(_conn)
294 BOOL OpalVXMLSession::Close()
296 BOOL ok = PVXMLSession::Close();
297 conn->ClearCall();
298 return ok;
304 #endif
307 // End of File /////////////////////////////////////////////////////////////