00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
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
00160 cap.SetTag(GetSubType());
00161
00162
00163 H245_AudioCapability_g7231 & g7231 = cap;
00164
00165
00166 g7231.m_maxAl_sduAudioFrames = packetSize;
00167
00168
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 & ,
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
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
00251
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