D:/Storage/CVS_Head/h323plus/src/opalvxml.cxx

00001 /*
00002  * vxml.cxx
00003  *
00004  * VXML control for for Opal
00005  *
00006  * A H.323 IVR application.
00007  *
00008  * Copyright (C) 2002 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Log: opalvxml.cxx,v $
00027  * Revision 1.1  2007/08/06 20:51:07  shorne
00028  * First commit of h323plus
00029  *
00030  * Revision 1.22  2004/07/15 11:20:38  rjongbloed
00031  * Migrated changes from crs_vxnml_devel branch into main trunk
00032  *
00033  * Revision 1.21  2004/07/15 03:18:00  csoutheren
00034  * Migrated changes from crs_vxnml_devel branch into main trunk
00035  *
00036  * Revision 1.20.2.1  2004/07/07 07:10:11  csoutheren
00037  * Changed to use new factory based PWAVFile
00038  * Removed redundant blocking/unblocking when using G.723.1
00039  *
00040  * Revision 1.20  2004/05/04 23:23:39  csoutheren
00041  * Removed usage of lpc10 and mscodecs
00042  *
00043  * Revision 1.19  2004/05/03 13:21:45  rjongbloed
00044  * Converted everything to be codec plug in freindly
00045  * Removed GSM and G.729 as now plug ins are "the way"!
00046  *
00047  * Revision 1.18  2002/12/10 23:50:25  robertj
00048  * Fixed some tracing issues
00049  *
00050  * Revision 1.17  2002/08/27 02:21:31  craigs
00051  * Added silence detection capability to fake G.723.1codec
00052  *
00053  * Revision 1.16  2002/08/15 04:55:26  robertj
00054  * Fixed shutdown problems with closing vxml session, leaks a thread.
00055  * Fixed potential problems with indirect channel Close() function.
00056  *
00057  * Revision 1.15  2002/08/15 02:19:42  robertj
00058  * Adjusted trace log levels for G.723.1 file codec read/write tracking.
00059  *
00060  * Revision 1.14  2002/08/07 13:53:05  craigs
00061  * Fixed problem with included opalvxml.h thanks to Vladmir Toncar
00062  *
00063  * Revision 1.13  2002/08/06 05:10:59  craigs
00064  * Moved most of stuff to ptclib
00065  *
00066  * Revision 1.12  2002/08/05 09:43:30  robertj
00067  * Added pragma interface/implementation
00068  * Moved virtual into .cxx file
00069  *
00070  * Revision 1.11  2002/07/29 15:10:36  craigs
00071  * Added autodelete option to PlayFile
00072  *
00073  * Revision 1.10  2002/07/29 12:54:42  craigs
00074  * Removed usages of cerr
00075  *
00076  * Revision 1.9  2002/07/18 04:17:12  robertj
00077  * Moved virtuals to source and changed name of G.723.1 file capability
00078  *
00079  * Revision 1.8  2002/07/10 13:16:58  craigs
00080  * Moved some VXML classes from Opal back into PTCLib
00081  * Added ability to repeat outputted data
00082  *
00083  * Revision 1.7  2002/07/09 08:48:41  craigs
00084  * Fixed trace messages
00085  *
00086  * Revision 1.6  2002/07/05 06:34:04  craigs
00087  * Changed comments and trace messages
00088  *
00089  * Revision 1.5  2002/07/03 04:58:13  robertj
00090  * Changed for compatibility with older GNU compilers
00091  *
00092  * Revision 1.4  2002/07/02 06:32:51  craigs
00093  * Added recording functions
00094  *
00095  * Revision 1.3  2002/06/28 02:42:11  craigs
00096  * Fixed problem with G.723.1 file naming conventions
00097  * Fixed problem with incorrect file open mode
00098  *
00099  * Revision 1.2  2002/06/28 01:24:03  robertj
00100  * Fixe dproblem with compiling without expat library.
00101  *
00102  * Revision 1.1  2002/06/27 05:44:11  craigs
00103  * Initial version
00104  *
00105  * Revision 1.2  2002/06/26 09:05:28  csoutheren
00106  * Added ability to utter various "sayas" types within prompts
00107  *
00108  * Revision 1.1  2002/06/26 01:13:53  csoutheren
00109  * Disassociated VXML and Opal/OpenH323 specific elements
00110  *
00111  * Revision 1.2  2002/06/21 08:18:22  csoutheren
00112  * Added start of grammar handling
00113  *
00114  * Revision 1.1  2002/06/20 06:35:44  csoutheren
00115  * Initial version
00116  *
00117  */
00118 
00119 #include <ptlib.h>
00120 
00121 #ifdef __GNUC__
00122 #pragma implementation "opalvxml.h"
00123 #endif
00124 
00125 #include "opalvxml.h"
00126 
00127 #if P_EXPAT
00128 
00129 #include <ptclib/delaychan.h>
00130 #include <ptclib/pwavfile.h>
00131 #include <ptclib/memfile.h>
00132 
00133 #endif
00134 
00135 #include "codecs.h"
00136 
00137 #define G7231_SAMPLES_PER_BLOCK 240
00138 #define G7231_BANDWIDTH               (6300/100)
00139 
00141 
00142 G7231_File_Capability::G7231_File_Capability()
00143   : H323AudioCapability(8, 4)
00144 {
00145 }
00146 
00147 unsigned G7231_File_Capability::GetSubType() const
00148 {
00149   return H245_AudioCapability::e_g7231;
00150 }
00151 
00152 PString G7231_File_Capability::GetFormatName() const
00153 {
00154   return "G.723.1{file}";
00155 }
00156 
00157 BOOL G7231_File_Capability::OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const
00158 {
00159   // set the choice to the correct type
00160   cap.SetTag(GetSubType());
00161 
00162   // get choice data
00163   H245_AudioCapability_g7231 & g7231 = cap;
00164 
00165   // max number of audio frames per PDU we want to send
00166   g7231.m_maxAl_sduAudioFrames = packetSize; 
00167 
00168   // enable silence suppression
00169   g7231.m_silenceSuppression = TRUE;
00170 
00171   return TRUE;
00172 }
00173 
00174 BOOL G7231_File_Capability::OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize)
00175 {
00176   const H245_AudioCapability_g7231 & g7231 = cap;
00177   packetSize = g7231.m_maxAl_sduAudioFrames;
00178   return TRUE;
00179 }
00180 
00181 PObject * G7231_File_Capability::Clone() const
00182 {
00183   return new G7231_File_Capability(*this);
00184 }
00185 
00186 H323Codec * G7231_File_Capability::CreateCodec(H323Codec::Direction direction) const
00187 {
00188   return new G7231_File_Codec(direction);
00189 }
00190 
00192 
00193 G7231_File_Codec::G7231_File_Codec(Direction dir)
00194   : H323AudioCodec(OPAL_G7231_6k3, dir)
00195 {
00196   lastFrameLen = 4;
00197 }
00198 
00199 
00200 int G7231_File_Codec::GetFrameLen(int val)
00201 {
00202   static const int frameLen[] = { 24, 20, 4, 1 };
00203   return frameLen[val & 3];
00204 }
00205 
00206 BOOL G7231_File_Codec::Read(BYTE * buffer, unsigned & length, RTP_DataFrame &)
00207 {
00208   if (rawDataChannel == NULL)
00209     return FALSE;
00210     
00211   if (!rawDataChannel->Read(buffer, 24)) {
00212     PTRACE(1, "G7231WAV\tRead failed");
00213     return FALSE;
00214   }
00215 
00216   lastFrameLen = length = G7231_File_Codec::GetFrameLen(buffer[0]);
00217 
00218   return TRUE;
00219 }
00220 
00221 
00222 BOOL G7231_File_Codec::Write(const BYTE * buffer,
00223                              unsigned length,
00224                              const RTP_DataFrame & /* rtp */,
00225                              unsigned & writtenLength)
00226 {
00227   if (rawDataChannel == NULL)
00228     return TRUE;
00229 
00230   static const BYTE silence[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00231                                   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00232                                   0, 0, 0, 0};
00233 
00234   // If the length is zero, output silence to the file..
00235   if (length == 0) {
00236     PTRACE(6,"G7231WAV\tZero length frame");
00237     writtenLength = 0;
00238     return rawDataChannel->Write(silence, 24);
00239   }
00240 
00241   int writeLen;
00242   switch (buffer[0]&3) {
00243     case 0:
00244       writeLen = 24;
00245       break;
00246     case 1:
00247       writeLen = 20;
00248       break;
00249     case 2:
00250       // Windows Media Player cannot play 4 byte SID (silence) frames.
00251       // So write out a 24 byte frame of silence instead.
00252       PTRACE(5, "G7231WAV\tReplacing SID with 24 byte frame");
00253       writtenLength = 4;
00254       return rawDataChannel->Write(silence, 24);
00255     default :
00256       writeLen = 1;
00257       break;
00258   }
00259 
00260   PTRACE(6, "G7231WAV\tFrame length = " <<writeLen);
00261 
00262   writtenLength = writeLen;
00263 
00264   return rawDataChannel->Write(buffer, writeLen);
00265 }
00266 
00267 
00268 unsigned G7231_File_Codec::GetBandwidth() const
00269 { 
00270   return G7231_BANDWIDTH; 
00271 }
00272 
00273 
00274 BOOL G7231_File_Codec::IsRawDataChannelNative() const
00275 {
00276   return TRUE;
00277 }
00278 
00279 unsigned G7231_File_Codec::GetAverageSignalLevel()
00280 {
00281   if (lastFrameLen == 4)
00282     return 0;
00283   else
00284     return UINT_MAX;
00285 }
00286 
00288 
00289 #if P_EXPAT
00290 
00291 OpalVXMLSession::OpalVXMLSession(H323Connection * _conn, PTextToSpeech * tts, BOOL autoDelete)
00292   : PVXMLSession(tts, autoDelete), conn(_conn)
00293 {
00294 }
00295 
00296 
00297 BOOL OpalVXMLSession::Close()
00298 {
00299   BOOL ok = PVXMLSession::Close();
00300   conn->ClearCall();
00301   return ok;
00302 }
00303 
00304 
00305 
00306 
00307 #endif
00308 
00309 
00310 // End of File /////////////////////////////////////////////////////////////

Generated on Thu Oct 25 13:43:28 2007 for h323plus by  doxygen 1.5.2