File: opalvxml.cxx

package info (click to toggle)
openh323 1.18.0.dfsg-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,616 kB
  • ctags: 26,979
  • sloc: cpp: 178,986; ansic: 33,179; sh: 3,483; makefile: 937
file content (307 lines) | stat: -rw-r--r-- 7,847 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
 * vxml.cxx
 *
 * VXML control for for Opal
 *
 * A H.323 IVR application.
 *
 * Copyright (C) 2002 Equivalence Pty. Ltd.
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is Portable Windows Library.
 *
 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
 *
 * Contributor(s): ______________________________________.
 *
 * $Log: opalvxml.cxx,v $
 * Revision 1.22  2004/07/15 11:20:38  rjongbloed
 * Migrated changes from crs_vxnml_devel branch into main trunk
 *
 * Revision 1.21  2004/07/15 03:18:00  csoutheren
 * Migrated changes from crs_vxnml_devel branch into main trunk
 *
 * Revision 1.20.2.1  2004/07/07 07:10:11  csoutheren
 * Changed to use new factory based PWAVFile
 * Removed redundant blocking/unblocking when using G.723.1
 *
 * Revision 1.20  2004/05/04 23:23:39  csoutheren
 * Removed usage of lpc10 and mscodecs
 *
 * Revision 1.19  2004/05/03 13:21:45  rjongbloed
 * Converted everything to be codec plug in freindly
 * Removed GSM and G.729 as now plug ins are "the way"!
 *
 * Revision 1.18  2002/12/10 23:50:25  robertj
 * Fixed some tracing issues
 *
 * Revision 1.17  2002/08/27 02:21:31  craigs
 * Added silence detection capability to fake G.723.1codec
 *
 * Revision 1.16  2002/08/15 04:55:26  robertj
 * Fixed shutdown problems with closing vxml session, leaks a thread.
 * Fixed potential problems with indirect channel Close() function.
 *
 * Revision 1.15  2002/08/15 02:19:42  robertj
 * Adjusted trace log levels for G.723.1 file codec read/write tracking.
 *
 * Revision 1.14  2002/08/07 13:53:05  craigs
 * Fixed problem with included opalvxml.h thanks to Vladmir Toncar
 *
 * Revision 1.13  2002/08/06 05:10:59  craigs
 * Moved most of stuff to ptclib
 *
 * Revision 1.12  2002/08/05 09:43:30  robertj
 * Added pragma interface/implementation
 * Moved virtual into .cxx file
 *
 * Revision 1.11  2002/07/29 15:10:36  craigs
 * Added autodelete option to PlayFile
 *
 * Revision 1.10  2002/07/29 12:54:42  craigs
 * Removed usages of cerr
 *
 * Revision 1.9  2002/07/18 04:17:12  robertj
 * Moved virtuals to source and changed name of G.723.1 file capability
 *
 * Revision 1.8  2002/07/10 13:16:58  craigs
 * Moved some VXML classes from Opal back into PTCLib
 * Added ability to repeat outputted data
 *
 * Revision 1.7  2002/07/09 08:48:41  craigs
 * Fixed trace messages
 *
 * Revision 1.6  2002/07/05 06:34:04  craigs
 * Changed comments and trace messages
 *
 * Revision 1.5  2002/07/03 04:58:13  robertj
 * Changed for compatibility with older GNU compilers
 *
 * Revision 1.4  2002/07/02 06:32:51  craigs
 * Added recording functions
 *
 * Revision 1.3  2002/06/28 02:42:11  craigs
 * Fixed problem with G.723.1 file naming conventions
 * Fixed problem with incorrect file open mode
 *
 * Revision 1.2  2002/06/28 01:24:03  robertj
 * Fixe dproblem with compiling without expat library.
 *
 * Revision 1.1  2002/06/27 05:44:11  craigs
 * Initial version
 *
 * Revision 1.2  2002/06/26 09:05:28  csoutheren
 * Added ability to utter various "sayas" types within prompts
 *
 * Revision 1.1  2002/06/26 01:13:53  csoutheren
 * Disassociated VXML and Opal/OpenH323 specific elements
 *
 * Revision 1.2  2002/06/21 08:18:22  csoutheren
 * Added start of grammar handling
 *
 * Revision 1.1  2002/06/20 06:35:44  csoutheren
 * Initial version
 *
 */

#include <ptlib.h>

#ifdef __GNUC__
#pragma implementation "opalvxml.h"
#endif

#include "opalvxml.h"

#if P_EXPAT

#include <ptclib/delaychan.h>
#include <ptclib/pwavfile.h>
#include <ptclib/memfile.h>

#endif

#include "codecs.h"

#define	G7231_SAMPLES_PER_BLOCK	240
#define	G7231_BANDWIDTH		      (6300/100)

///////////////////////////////////////////////////////////////

G7231_File_Capability::G7231_File_Capability()
  : H323AudioCapability(8, 4)
{
}

unsigned G7231_File_Capability::GetSubType() const
{
  return H245_AudioCapability::e_g7231;
}

PString G7231_File_Capability::GetFormatName() const
{
  return "G.723.1{file}";
}

BOOL G7231_File_Capability::OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const
{
  // set the choice to the correct type
  cap.SetTag(GetSubType());

  // get choice data
  H245_AudioCapability_g7231 & g7231 = cap;

  // max number of audio frames per PDU we want to send
  g7231.m_maxAl_sduAudioFrames = packetSize; 

  // enable silence suppression
  g7231.m_silenceSuppression = TRUE;

  return TRUE;
}

BOOL G7231_File_Capability::OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize)
{
  const H245_AudioCapability_g7231 & g7231 = cap;
  packetSize = g7231.m_maxAl_sduAudioFrames;
  return TRUE;
}

PObject * G7231_File_Capability::Clone() const
{
  return new G7231_File_Capability(*this);
}

H323Codec * G7231_File_Capability::CreateCodec(H323Codec::Direction direction) const
{
  return new G7231_File_Codec(direction);
}

///////////////////////////////////////////////////////////////

G7231_File_Codec::G7231_File_Codec(Direction dir)
  : H323AudioCodec(OPAL_G7231_6k3, dir)
{
  lastFrameLen = 4;
}


int G7231_File_Codec::GetFrameLen(int val)
{
  static const int frameLen[] = { 24, 20, 4, 1 };
  return frameLen[val & 3];
}

BOOL G7231_File_Codec::Read(BYTE * buffer, unsigned & length, RTP_DataFrame &)
{
  if (rawDataChannel == NULL)
    return FALSE;
    
  if (!rawDataChannel->Read(buffer, 24)) {
    PTRACE(1, "G7231WAV\tRead failed");
    return FALSE;
  }

  lastFrameLen = length = G7231_File_Codec::GetFrameLen(buffer[0]);

  return TRUE;
}


BOOL G7231_File_Codec::Write(const BYTE * buffer,
                             unsigned length,
                             const RTP_DataFrame & /* rtp */,
                             unsigned & writtenLength)
{
  if (rawDataChannel == NULL)
    return TRUE;

  static const BYTE silence[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                  0, 0, 0, 0};

  // If the length is zero, output silence to the file..
  if (length == 0) {
    PTRACE(6,"G7231WAV\tZero length frame");
    writtenLength = 0;
    return rawDataChannel->Write(silence, 24);
  }

  int writeLen;
  switch (buffer[0]&3) {
    case 0:
      writeLen = 24;
      break;
    case 1:
      writeLen = 20;
      break;
    case 2:
      // Windows Media Player cannot play 4 byte SID (silence) frames.
      // So write out a 24 byte frame of silence instead.
      PTRACE(5, "G7231WAV\tReplacing SID with 24 byte frame");
      writtenLength = 4;
      return rawDataChannel->Write(silence, 24);
    default :
      writeLen = 1;
      break;
  }

  PTRACE(6, "G7231WAV\tFrame length = " <<writeLen);

  writtenLength = writeLen;

  return rawDataChannel->Write(buffer, writeLen);
}


unsigned G7231_File_Codec::GetBandwidth() const
{ 
  return G7231_BANDWIDTH; 
}


BOOL G7231_File_Codec::IsRawDataChannelNative() const
{
  return TRUE;
}

unsigned G7231_File_Codec::GetAverageSignalLevel()
{
  if (lastFrameLen == 4)
    return 0;
  else
    return UINT_MAX;
}

///////////////////////////////////////////////////////////////

#if P_EXPAT

OpalVXMLSession::OpalVXMLSession(H323Connection * _conn, PTextToSpeech * tts, BOOL autoDelete)
  : PVXMLSession(tts, autoDelete), conn(_conn)
{
}


BOOL OpalVXMLSession::Close()
{
  BOOL ok = PVXMLSession::Close();
  conn->ClearCall();
  return ok;
}




#endif


// End of File /////////////////////////////////////////////////////////////