#ifdef __GNUC__
#define H323_STATIC_LIB #endif
#include \
#include \
#define new PNEW
// 这个东西里边可能封装了标准的main函数 PCREATE_PROCESS(SimpleH323Process);
/////////////////////////////////////////////////////////////// //几个宏都在version.h里面定义
SimpleH323Process::SimpleH323Process()
: PProcess(\
MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER) {
endpoint = NULL; }
SimpleH323Process::~SimpleH323Process() {
delete endpoint; }
void SimpleH323Process::Main() {
cout << GetName()
<< \<< \
<< \
<< \// Get and parse all of the command line arguments. // 分析命令行参数, 略去数行
PArgList & args = GetArguments(); args.Parse(
\\\\” FALSE);
if (args.HasOption(h) || (!args.HasOption(l) && args.GetCount() == 0))
{
//如果没有参数或者参数是h, 就输出如何使用, 此处略去数行 }
//这个东西暂时不管 #if PTRACING #endif
// Create the H.323 endpoint and initialise it
// H323 EndPoint 创建了, 并且把命令参数传过去初始化, 初始化的时候做了一些事
endpoint = new SimpleH323EndPoint; if (!endpoint->Initialise(args)) return;
//看看命令行里是不是想直接呼叫另一个H323的endpoint.有没有l(listen)的option
//如果是就MakeCall,
// See if making a call or just listening. if (args.HasOption(l))
cout << \endpoint->GetLocalUserName() << \else {
cout << \endpoint->MakeCall(args[0], endpoint->currentCallToken); }
cout << \// Simplest possible user interface // 简单的用户界面, 会有一个提示> // 取pid是我加的 for (;;) {
pid_t thispid; char prom[20];
thispid = getpid();
sprintf(prom, \cout << prom << flush; PCaselessString cmd; cin >> cmd;
if (cmd == \break;
if (cmd.FindOneOf(\H323Connection*connection;
//使用lock就是怕别的线程把它给删了 //因为这里正用着呢
connection=endpoint->FindConnectionWithLock(endpoint->currentCallToken);
if (connection != NULL) { if (cmd == \
connection->ClearCall(); else if (cmd == \
connection->AnsweringCall(H323Connection::AnswerCallNow); else if (cmd == \
connection->AnsweringCall(H323Connection::AnswerCallDenied); connection->Unlock(); } } }
cout << \}
// Main 函数结束
// 自己的Init函数
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(); // 设定改Endpoint的username SetLocalUserName(aliases[0]);
// 设定Aliases 就是每个Endpoint可以有好多名字的意思 for (PINDEX i = 1; i < aliases.GetSize(); i++) AddAliasName(aliases[i]); }
// Set the various options //设置静音检测否
SetSilenceDetectionMode(args.HasOption(e) ? H323AudioCodec::NoSilenceDetection
: H323AudioCodec::AdaptiveSilenceDetection); //快速连接?
DisableFastStart(args.HasOption(f));
//H245通道
DisableH245Tunneling(args.HasOption(T)); autoAnswer = args.HasOption(a);
busyForwardParty = args.GetOptionString(B);
if (args.HasOption()) {
initialBandwidth = args.GetOptionString().AsUnsigned()*100; if (initialBandwidth == 0) {
cerr << \return FALSE; } }
if (args.HasOption(j)) {
unsigned jitter = args.GetOptionString(j).AsUnsigned(); //设定音频抖动的, 应该影响到接收的缓存 if (jitter >= 20 && jitter <= 10000) SetMaxAudioDelayJitter(jitter); else { cerr << \should be between 20 milliseconds and 10 seconds.\<< endl; return FALSE; } }
//设定声音设备
//也可以不用声音设备, 比如Openh323工程的子项目 OpenAM和OpenMCU //都使演示了如何不使用声音物理设备的方法, 我想那里边的东西会对某些朋友们
//的需求比较合适
if (!SetSoundDevice(args, \return FALSE;
if (!SetSoundDevice(args, \return FALSE;
if (!SetSoundDevice(args, \return FALSE;
if (!SetSoundDevice(args, \return FALSE;
// 设定decode encode的能力
// H323 EndPoint在真正进行数据通讯之前要进行能力的交换, 说明自己能够接收和发送
什么标准的数据, g.711是必须支持的.
// Set the default codecs available on sound cards.
AddAllCapabilities(0, 0, \AddAllCapabilities(0, 0, \AddAllCapabilities(0, 0, \AddAllUserInputCapabilities(0, 1);
RemoveCapabilities(args.GetOptionString(D).Lines()); ReorderCapabilities(args.GetOptionString(P).Lines());
cout << \<< \H323AudioCodec::
NoSilenceDetection ? \<< \
<< \\
<< \is \<< (IsH245TunnelingDisabled() ? \: \<< \d\\n\
<< \
<< \\<< \GetCapabilities() < < endl;
//启动一个来电的监听
//可以使用配置的端口, 也可以使用default的端口 // Start the listener thread for incoming calls. H323ListenerTCP * listener;
if (args.GetOptionString(i).IsEmpty()) listener = new H323ListenerTCP(*this); else {
PIPSocket::Address interfaceAddress(args.GetOptionString(i)); listener = new H323ListenerTCP(*this, interfaceAddress); }
if (!StartListener(listener)) {
cerr << \<< listener->GetListenerPort() << endl; delete listener; return FALSE; }
//这是连接GateKeeper相关的东西, 先不讨论了 // Initialise the security info