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
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
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
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
119 #pragma implementation "opalvxml.h"
122 #include "opalvxml.h"
126 #include <ptclib/delaychan.h>
127 #include <ptclib/pwavfile.h>
128 #include <ptclib/memfile.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());
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
;
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
;
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
)
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
)
208 if (!rawDataChannel
->Read(buffer
, 24)) {
209 PTRACE(1, "G7231WAV\tRead failed");
213 lastFrameLen
= length
= G7231_File_Codec::GetFrameLen(buffer
[0]);
219 BOOL
G7231_File_Codec::Write(const BYTE
* buffer
,
221 const RTP_DataFrame
& /* rtp */,
222 unsigned & writtenLength
)
224 if (rawDataChannel
== NULL
)
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,
231 // If the length is zero, output silence to the file..
233 PTRACE(6,"G7231WAV\tZero length frame");
235 return rawDataChannel
->Write(silence
, 24);
239 switch (buffer
[0]&3) {
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");
251 return rawDataChannel
->Write(silence
, 24);
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
276 unsigned G7231_File_Codec::GetAverageSignalLevel()
278 if (lastFrameLen
== 4)
284 ///////////////////////////////////////////////////////////////
288 OpalVXMLSession::OpalVXMLSession(H323Connection
* _conn
, PTextToSpeech
* tts
, BOOL autoDelete
)
289 : PVXMLSession(tts
, autoDelete
), conn(_conn
)
294 BOOL
OpalVXMLSession::Close()
296 BOOL ok
= PVXMLSession::Close();
307 // End of File /////////////////////////////////////////////////////////////