⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lid.cxx

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* * lid.cxx * * Line Interface Device * * Open Phone Abstraction Library * * Copyright (c) 1999-2000 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 Open H323 Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Contributor(s): ______________________________________. * * $Log: lid.cxx,v $ * Revision 1.32  2000/07/13 16:03:25  robertj * Removed transmission of 1 byte repeat CNG frames in G.723.1 as it crashes other peoples stacks. * * Revision 1.31  2000/07/12 10:25:37  robertj * Renamed all codecs so obvious whether software or hardware. * * Revision 1.30  2000/07/09 15:23:00  robertj * Changed G.728 not to use Cisco hack. Cisco is just wrong! * Fixed output of silence in G.711 so works with any sized frame. * * Revision 1.29  2000/07/02 14:09:49  craigs * Fill uLaw and aLaw silence with 0x80 rather than 0x00 * * Revision 1.28  2000/06/19 00:32:22  robertj * Changed functionf or adding all lid capabilities to not assume it is to an endpoint. * * Revision 1.27  2000/06/01 07:52:30  robertj * Changed some LID capability code back again so does not unneedfully break existing API. * * Revision 1.26  2000/05/30 10:19:28  robertj * Added function to add capabilities given a LID. * Improved LID capabilities so cannot create one that is not explicitly supported. * * Revision 1.25  2000/05/24 06:43:16  craigs * Added routines to get xJack volume * Fixed problem with receiving G>723.1 NULL frames * * Revision 1.24  2000/05/11 03:47:48  craigs * Added extra debugging * * Revision 1.23  2000/05/10 04:05:34  robertj * Changed capabilities so has a function to get name of codec, instead of relying on PrintOn. * * Revision 1.22  2000/05/04 12:56:43  robertj * Fixed GNU warning. * * Revision 1.21  2000/05/04 11:52:35  robertj * Added Packets Too Late statistics, requiring major rearrangement of jitter *    buffer code, not also changes semantics of codec Write() function slightly. * * Revision 1.20  2000/05/02 04:32:27  robertj * Fixed copyright notice comment. * * Revision 1.19  2000/04/30 03:57:14  robertj * Added PTRACE of read/write frame sizes required by LID. * * Revision 1.18  2000/04/19 02:04:30  robertj * BeOS port changes. * * Revision 1.17  2000/04/14 17:18:07  robertj * Fixed problem with error reporting from LID hardware. * * Revision 1.16  2000/04/10 17:45:11  robertj * Added higher level "DialOut" function for PSTN lines. * Added hook flash function. * * Revision 1.15  2000/04/05 18:04:12  robertj * Changed caller ID code for better portability. * * Revision 1.14  2000/04/03 19:25:14  robertj * Optimised G.711 codec to read/write larger chunks of data. * * Revision 1.13  2000/03/31 19:50:51  robertj * Fixed receiver loop being able to deal with RTP packets smaller than expected. * * Revision 1.12  2000/03/30 19:32:35  robertj * Added swab function which seems to be missing on Linux. * * Revision 1.11  2000/03/30 01:57:16  robertj * Added hacks so G.728 works with (I think) broken cisco gateways. * * Revision 1.10  2000/03/29 21:01:52  robertj * Changed codec to use number of frames rather than number of bytes. * Added function on LID to get available codecs. * Fixed codec table for G.729 codec * * Revision 1.9  2000/03/28 05:22:05  robertj * Fixed translation of text country code to numeric code. * * Revision 1.8  2000/03/23 23:36:49  robertj * Added more calling tone detection functionality. * * Revision 1.7  2000/03/21 03:06:50  robertj * Changes to make RTP TX of exact numbers of frames in some codecs. * * Revision 1.6  2000/01/13 12:39:29  robertj * Added string based country codes to LID. * * Revision 1.5  2000/01/13 04:03:46  robertj * Added video transmission * * Revision 1.4  2000/01/07 10:01:26  robertj * GCC/Linux compatibility * * Revision 1.3  2000/01/07 08:28:09  robertj * Additions and changes to line interface device base class. * * Revision 1.2  1999/12/29 01:18:07  craigs * Fixed problem with codecs other than G.711 not working after reorganisation * * Revision 1.1  1999/12/23 23:02:36  robertj * File reorganision for separating RTP from H.323 and creation of LID for VPB support. * */#include <ptlib.h>#include "lid.h"#include "h323.h"#include "h245.h"#define new PNEW//#define CISCO_G728_HACK#if defined(CISCO_G728_HACK) && (defined(P_LINUX) || defined(__BEOS__))void swab(char * from, char * to, size_t len){  while (len > 1) {    char b = from[0];    to[0] = from[1];    to[1] = b;    from += 2;    to += 2;    len -= 2;  }}#endif///////////////////////////////////////////////////////////////////////////////#if PTRACINGconst char * const OpalLineInterfaceDevice::CallProgressTonesNames[NumTones] = {  "DialTone", "RingTone", "BusyTone", "ClearTone"};#endifOpalLineInterfaceDevice::OpalLineInterfaceDevice(){  os_handle = -1;  osError = 0;  countryCode = UnknownCountry;}BOOL OpalLineInterfaceDevice::IsOpen() const{  return os_handle >= 0;}BOOL OpalLineInterfaceDevice::Close(){  if (os_handle < 0)    return FALSE;  os_handle = -1;  return TRUE;}BOOL OpalLineInterfaceDevice::IsLineTerminal(unsigned){  return FALSE;}BOOL OpalLineInterfaceDevice::IsLinePresent(unsigned){  return TRUE;}BOOL OpalLineInterfaceDevice::HookFlash(unsigned line, unsigned flashTime){  if (!IsLineOffHook(line))    return FALSE;  if (!SetLineOnHook(line))    return FALSE;  PThread::Current()->Sleep(flashTime);  return SetLineOffHook(line);}BOOL OpalLineInterfaceDevice::IsLineRinging(unsigned, DWORD *){  return FALSE;}BOOL OpalLineInterfaceDevice::RingLine(unsigned, DWORD){  return FALSE;}BOOL OpalLineInterfaceDevice::IsLineDisconnected(unsigned line){  return IsToneDetected(line) == BusyTone;}BOOL OpalLineInterfaceDevice::SetLineToLineDirect(unsigned, unsigned, BOOL){  return FALSE;}BOOL OpalLineInterfaceDevice::IsLineToLineDirect(unsigned, unsigned){  return FALSE;}PIntArray OpalLineInterfaceDevice::GetPayloadTypes() const{  PIntArray codecs(1);  codecs[0] = RTP_DataFrame::L16_Mono;  return codecs;}BOOL OpalLineInterfaceDevice::SetReadCodec(unsigned, RTP_DataFrame::PayloadTypes){  return FALSE;}BOOL OpalLineInterfaceDevice::SetWriteCodec(unsigned, RTP_DataFrame::PayloadTypes){  return FALSE;}BOOL OpalLineInterfaceDevice::StopReadCodec(unsigned){  return FALSE;}BOOL OpalLineInterfaceDevice::StopWriteCodec(unsigned){  return FALSE;}BOOL OpalLineInterfaceDevice::SetReadFrameSize(unsigned, PINDEX){  return FALSE;}PINDEX OpalLineInterfaceDevice::SetWriteFrameSize(unsigned, PINDEX){  return FALSE;}unsigned OpalLineInterfaceDevice::GetAverageSignalLevel(unsigned){  return UINT_MAX;}BOOL OpalLineInterfaceDevice::EnableAudio(unsigned, BOOL){  return TRUE;}BOOL OpalLineInterfaceDevice::SetRecordVolume(unsigned, unsigned){  return FALSE;}BOOL OpalLineInterfaceDevice::GetRecordVolume(unsigned, unsigned &){  return FALSE;}BOOL OpalLineInterfaceDevice::SetPlayVolume(unsigned, unsigned){  return FALSE;}BOOL OpalLineInterfaceDevice::GetPlayVolume(unsigned, unsigned &){  return FALSE;}OpalLineInterfaceDevice::AECLevels OpalLineInterfaceDevice::GetAEC(unsigned){  return AECError;}BOOL OpalLineInterfaceDevice::SetAEC(unsigned, AECLevels){  return FALSE;}BOOL OpalLineInterfaceDevice::GetCallerID(unsigned, PString & id, BOOL){  id = PString();  return FALSE;}BOOL OpalLineInterfaceDevice::SetCallerID(unsigned, const PString &){  return FALSE;}BOOL OpalLineInterfaceDevice::PlayDTMF(unsigned, const char *, DWORD, DWORD){  return FALSE;}char OpalLineInterfaceDevice::ReadDTMF(unsigned){  return '\0';}BOOL OpalLineInterfaceDevice::GetRemoveDTMF(unsigned){  return FALSE;}BOOL OpalLineInterfaceDevice::SetRemoveDTMF(unsigned, BOOL){  return FALSE;}OpalLineInterfaceDevice::CallProgressTones                            OpalLineInterfaceDevice::IsToneDetected(unsigned){  return NumTones;}OpalLineInterfaceDevice::CallProgressTones               OpalLineInterfaceDevice::WaitForToneDetect(unsigned line, unsigned timeout){  static const unsigned sampleRate = 25;  timeout = (timeout+sampleRate-1)/sampleRate;  unsigned retry;  for (retry = 0; retry < timeout; retry++) {    CallProgressTones tone = IsToneDetected(line);    if (tone != NumTones) {      PTRACE(2, "LID\tTone " << tone << " detected after " << (retry*sampleRate) << " ms");      return tone;    }    PThread::Current()->Sleep(25);  }  PTRACE(3, "LID\tTone detection timeout " << (retry*sampleRate) << " ms");  return NumTones;}BOOL OpalLineInterfaceDevice::WaitForTone(unsigned line,                                          CallProgressTones tone,                                          unsigned timeout){  return WaitForToneDetect(line, timeout) == tone;}BOOL OpalLineInterfaceDevice::PlayTone(unsigned, CallProgressTones){  return FALSE;}BOOL OpalLineInterfaceDevice::IsTonePlaying(unsigned){  return FALSE;}BOOL OpalLineInterfaceDevice::StopTone(unsigned){  return FALSE;}OpalLineInterfaceDevice::CallProgressTones                OpalLineInterfaceDevice::DialOut(unsigned line,                                                 const PString & number,                                                 BOOL requireTone){  PTRACE(3, "LID\tDialOut to " << number);  if (IsLineTerminal(line))    return NumTones;  if (!SetLineOffHook(line))    return NumTones;  // Should get dial tone within 2 seconds of going off hook  if (!WaitForTone(line, DialTone, 2000)) {    if (requireTone)      return DialTone;  }  // Dial the string  PINDEX lastPos = 0;  PINDEX nextPos;  while ((nextPos = number.FindOneOf("!@,")) != P_MAX_INDEX) {    PlayDTMF(line, number(lastPos, nextPos-1));    lastPos = nextPos+1;    switch (number[nextPos]) {      case '!' :        if (!HookFlash(line))          return NumTones;        break;      case '@' :        if (!WaitForTone(line, DialTone, 3000)) {          if (requireTone)            return DialTone;        }        break;      case ',' :        PThread::Current()->Sleep(2000);        break;    }  }  PlayDTMF(line, number.Mid(lastPos));  // Wait for busy or ring back  CallProgressTones tone;  while ((tone = WaitForToneDetect(line, 5000)) != NumTones) {    if (tone != DialTone)      return tone;  }  if (requireTone)    return NumTones;  return RingTone;}static const char * CountryNames[OpalLineInterfaceDevice::NumCountryCodes] = {  "Japan", "Albania", "Algeria", "AmericanSamoa", "Germany", "Anguilla", "AntiguaAndBarbuda",  "Argentina", "Ascension", "Australia", "Austria", "Bahamas", "Bahrain", "Bangladesh",  "Barbados", "Belgium", "Belize", "Benin", "Bermudas", "Bhutan", "Bolivia", "Botswana",  "Brazil", "BritishAntarcticTerritory", "BritishIndianOceanTerritory",  "BritishVirginIslands", "BruneiDarussalam", "Bulgaria", "Myanmar", "Burundi",  "Byelorussia", "Cameroon", "Canada", "CapeVerde", "CaymanIslands",  "CentralAfricanRepublic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo",  "CookIslands", "CostaRica", "Cuba", "Cyprus", "Czechoslovakia", "Cambodia",  "DemocraticPeoplesRepublicOfKorea", "Denmark", "Djibouti", "DominicanRepublic",  "Dominica", "Ecuador", "Egypt", "ElSalvador", "EquatorialGuinea", "Ethiopia",  "FalklandIslands", "Fiji", "Finland", "France", "FrenchPolynesia",  "FrenchSouthernAndAntarcticLands", "Gabon", "Gambia", "Germany2", "Angola", "Ghana",  "Gibraltar", "Greece", "Grenada", "Guam", "Guatemala", "Guernsey", "Guinea", "GuineaBissau",  "Guayana", "Haiti", "Honduras", "Hongkong", "Hungary", "Iceland", "India", "Indonesia",  "Iran", "Iraq", "Ireland", "Israel", "Italy", "CotedIvoire", "Jamaica", "Afghanistan",  "Jersey", "Jordan", "Kenya", "Kiribati", "KoreaRepublic", "Kuwait", "Lao", "Lebanon",  "Lesotho", "Liberia", "Libya", "Liechtenstein", "Luxemborg", "Macao", "Madagascar",  "Malaysia", "Malawi", "Maldives", "Mali", "Malta", "Mauritania", "Mauritius", "Mexico",  "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Nauru", "Nepal",  "Netherlands", "NetherlandsAntilles", "NewCaledonia", "NewZealand", "Nicaragua",  "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "PapuaNewGuinea", "Paraguay",  "Peru", "Philippines", "Poland", "Portugal", "PuertoRico", "Qatar", "Romania", "Rwanda",  "SaintKittsAndNevis", "SaintCroix", "SaintHelenaAndAscension", "SaintLucia",  "SanMarino", "SaintThomas", "SaoTomeAndPrincipe", "SaintVicentAndTheGrenadines",  "SaudiArabia", "Senegal", "Seychelles", "SierraLeone", "Singapore", "SolomonIslands",  "Somalia", "SouthAfrica", "Spain", "SriLanka", "Sudan", "Suriname", "Swaziland", "Sweden",  "Switzerland", "Syria", "Tanzania", "Thailand", "Togo", "Tonga", "TrinidadAndTobago",  "Tunisia", "Turkey", "TurksAndCaicosIslands", "Tuvalu", "Uganda", "Ukraine",  "UnitedArabEmirates", "UnitedKingdom", "UnitedStates", "BurkinaFaso", "Uruguay",  "USSR", "Vanuatu", "VaticanCityState", "Venezuela", "VietNam", "WallisAndFutuna",  "WesternSamoa", "Yemen", "Yemen2", "Yugoslavia", "Zaire", "Zambia", "Zimbabwe"};PString OpalLineInterfaceDevice::GetCountryCodeName() const{  if (countryCode >= 0 && countryCode < NumCountryCodes)    return CountryNames[countryCode];  return "<Unknown>";}BOOL OpalLineInterfaceDevice::SetCountryCode(T35CountryCodes country){  countryCode = country;  PTRACE(2, "LID\tCountry set to " << GetCountryCodeName());  return TRUE;}BOOL OpalLineInterfaceDevice::SetCountryCode(const PString & countryName){  PINDEX code = Japan;  while (code < NumCountryCodes) {    if (countryName *= CountryNames[code])      return SetCountryCode((T35CountryCodes)code);    code++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -