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

📄 main.cxx

📁 mgcp协议源代码。支持多种编码:g711
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* * main.cxx * * A simple H.323 "net telephone" application. * * Copyright (c) 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 Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Contributor(s): ______________________________________. * * $Log: main.cxx,v $ * Revision 1.5  2000/06/20 02:38:27  robertj * Changed H323TransportAddress to default to IP. * * Revision 1.4  2000/06/07 05:47:55  robertj * Added call forwarding. * * Revision 1.3  2000/05/23 11:32:27  robertj * Rewrite of capability table to combine 2 structures into one and move functionality into that class *    allowing some normalisation of usage across several applications. * Changed H323Connection so gets a copy of capabilities instead of using endponts, allows adjustments *    to be done depending on the remote client application. * * Revision 1.2  2000/05/11 10:00:02  robertj * Fixed setting and resetting of current call token variable. * * Revision 1.1  2000/05/11 04:05:57  robertj * Simple sample program. * */#include <ptlib.h>#include <gsmcodec.h>#include "main.h"#include "version.h"#define new PNEWPCREATE_PROCESS(SimpleH323Process);///////////////////////////////////////////////////////////////SimpleH323Process::SimpleH323Process()  : PProcess("OpenH323 Project", "SimpleH323",             MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER){  endpoint = NULL;#if PTRACING  traceOutput = NULL;#endif}SimpleH323Process::~SimpleH323Process(){  delete endpoint;#if PTRACING  if (traceOutput != NULL) {    PTrace::SetStream(NULL);    delete traceOutput;  }#endif}void SimpleH323Process::Main(){  cout << GetName()       << " Version " << GetVersion(TRUE)       << " by " << GetManufacturer()       << " on " << GetOSClass() << ' ' << GetOSName()       << " (" << GetOSVersion() << '-' << GetOSHardware() << ")\n\n";  // Get and parse all of the command line arguments.  PArgList & args = GetArguments();  args.Parse(             "a-auto-answer."             "b-bandwidth:"             "B-forward-busy:"             "D-disable:"             "e-silence."             "f-fast-disable."             "g-gatekeeper:"             "h-help."             "i-interface:"             "j-jitter:"             "l-listen."             "n-no-gatekeeper."#if PTRACING             "o-output:"#endif             "P-prefer:"             "r-require-gatekeeper."             "s-sound:"             "-sound-in:"             "-sound-out:"             "T-h245tunneldisable."#if PTRACING             "t-trace."#endif             "u-user:"          , FALSE);  if (args.HasOption('h') || (!args.HasOption('l') && args.GetCount() == 0)) {    cout << "Usage : " << GetName() << " [options] -l\n"            "      : " << GetName() << " [options] [alias@]hostname   (no gatekeeper)\n"            "      : " << GetName() << " [options] alias[@hostname]   (with gatekeeper)\n"            "Options:\n"            "  -l --listen             : Listen for incoming calls.\n"            "  -g --gatekeeper host    : Specify gatekeeper host.\n"            "  -n --no-gatekeeper      : Disable gatekeeper discovery.\n"            "  -r --require-gatekeeper : Exit if gatekeeper discovery fails.\n"            "  -a --auto-answer        : Automatically answer incoming calls.\n"            "  -u --user name          : Set local alias name(s) (defaults to login name).\n"            "  -b --bandwidth bps      : Limit bandwidth usage to bps bits/second.\n"            "  -j --jitter delay       : Set jitter buffer to delay milliseconds.\n"            "  -D --disable codec      : Disable the specified codec (may be used multiple times)\n"            "  -P --prefer codec       : Prefer the specified codec (may be used multiple times)\n"            "  -i --interface ipnum    : Select interface to bind to.\n"            "  -B --forward-busy party : Forward to remote party if busy.\n"            "  -e --silence            : Disable transmitter silence detection.\n"            "  -f --fast-disable       : Disable fast start.\n"            "  -T --h245tunneldisable  : Disable H245 tunnelling.\n"            "  -s --sound device       : Select sound input/output device.\n"            "     --sound-in device    : Select sound input device.\n"            "     --sound-out device   : Select sound output device.\n"#if PTRACING            "  -t --trace              : Enable trace, use multiple times for more detail.\n"            "  -o --output             : File for trace output, default is stderr.\n"#endif            "  -h --help               : This help message.\n"            << endl;    return;  }#if PTRACING  // If we have a tracing version, then open trace file and set modes  PTrace::SetOptions(PTrace::Timestamp | PTrace::Thread | PTrace::Blocks);  PTrace::SetLevel(args.GetOptionCount('t'));  if (args.HasOption('o')) {    traceOutput = new PTextFile;    if (traceOutput->Open(args.GetOptionString('o'), PFile::WriteOnly))      PTrace::SetStream(traceOutput);    else {      cout << "Warning: could not open trace output file \""           << args.GetOptionString('o') << '"' << endl;      delete traceOutput;      traceOutput = NULL;    }  }  PTRACE(1, GetName()         << " Version " << GetVersion(TRUE)         << " by " << GetManufacturer()         << " on " << GetOSClass() << ' ' << GetOSName()         << " (" << GetOSVersion() << '-' << GetOSHardware() << ')');#endif  // Create the H.323 endpoint and initialise it  endpoint = new SimpleH323EndPoint;  if (!endpoint->Initialise(args))    return;  // See if making a call or just listening.  if (args.HasOption('l'))    cout << "Waiting for incoming calls for \"" << endpoint->GetLocalUserName() << "\"\n";  else {    cout << "Initiating call to \"" << args[0] << "\"\n";    endpoint->MakeCall(args[0], endpoint->currentCallToken);  }  cout << "Press X to exit." << endl;  // Simplest possible user interface  for (;;) {    cout << "H323> " << flush;    PCaselessString cmd;    cin >> cmd;    if (cmd == "X")      break;    if (cmd.FindOneOf("HYN") != P_MAX_INDEX) {      H323Connection * connection = endpoint->FindConnectionWithLock(endpoint->currentCallToken);      if (connection != NULL) {        if (cmd == "H")          connection->ClearCall();        else if (cmd == "Y")          connection->AnsweringCall(H323Connection::AnswerCallNow);        else if (cmd == "N")          connection->AnsweringCall(H323Connection::AnswerCallDenied);        connection->Unlock();      }    }  }  cout << "Exiting " << GetName() << endl;}///////////////////////////////////////////////////////////////SimpleH323EndPoint::SimpleH323EndPoint(){}BOOL SimpleH323EndPoint::Initialise(PArgList & args){  // Get local username, multiple uses of -u indicates additional aliases  if (args.HasOption('u')) {    PStringArray aliases = args.GetOptionString('u').Lines();    SetLocalUserName(aliases[0]);    for (PINDEX i = 1; i < aliases.GetSize(); i++)      AddAliasName(aliases[i]);  }  // Set the various options  silenceOn            = !args.HasOption('e');  autoAnswer           = args.HasOption('a');  noFastStart          = args.HasOption('f');  doH245Tunnelling     = !args.HasOption('h');  busyForwardParty     = args.GetOptionString('B');  if (args.HasOption('b')) {    initialBandwidth = args.GetOptionString('b').AsUnsigned()*100;    if (initialBandwidth == 0) {      cerr << "Illegal bandwidth specified." << endl;      return FALSE;    }  }  if (args.HasOption('j')) {    unsigned jitter = args.GetOptionString('j').AsUnsigned();    if (jitter >= 20 && jitter <= 10000)      SetMaxAudioDelayJitter(jitter);    else {      cerr << "Jitter should be between 20 milliseconds and 10 seconds." << endl;      return FALSE;    }  }  if (!SetSoundDevice(args, "sound", PSoundChannel::Recorder))    return FALSE;  if (!SetSoundDevice(args, "sound", PSoundChannel::Player))    return FALSE;  if (!SetSoundDevice(args, "sound-in", PSoundChannel::Recorder))    return FALSE;  if (!SetSoundDevice(args, "sound-out", PSoundChannel::Player))    return FALSE;  // Set the default codecs available on sound cards.  SetCapability(0, 0, new H323_GSM0610Capability);  SetCapability(0, 0, new H323_G711Capability(H323_G711Capability::muLaw));  SetCapability(0, 0, new H323_G711Capability(H323_G711Capability::ALaw));  SetCapability(0, 1, new H323_UserInputCapability);  capabilities.Remove(args.GetOptionString('D').Lines());  capabilities.Reorder(args.GetOptionString('P').Lines());  cout << "Local username: " << GetLocalUserName() << "\n"       << "Silence compression is " << silenceOn << "\n"       << "Auto answer is " << autoAnswer << "\n"       << "FastConnect is " << !noFastStart << "\n"       << "H245Tunnelling is " << doH245Tunnelling << "\n"       << "Jitter buffer: "  << GetMaxAudioDelayJitter() << " ms\n"       << "Sound output device: \"" << GetSoundChannelPlayDevice() << "\"\n"          "Sound  input device: \"" << GetSoundChannelRecordDevice() << "\"\n"       <<  "Codecs (in preference order):\n" << setprecision(2) << capabilities << endl;

⌨️ 快捷键说明

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