📄 main.cxx
字号:
/*
* main.cxx
*
*/
#include <pwlib.h>
#include <math.h>
#include "main.h"
#include "version.h"
#include "ixjlid.h"
#include "vblasterlid.h"
#if PTRACING
#include "resources.h"
#else
#include "resources_notrace.h"
#endif
#include "gsmcodec.h"
#include "mscodecs.h"
#include "lpc10codec.h"
#include "h261codec.h"
#ifdef TESTING_T120
#include "h323t120.h"
#endif
#include "rtp2wav.h"
#define ENABLE_TRANSMITTER 1 // Clear to temporarily disable the transmitter start up
#define ENABLE_RECEIVER 1 // Clear to temporarily disable the receiver acceptance
PCREATE_PROCESS(OpenPhone);
const char CodecsConfigSection[] = "Codecs";
const char RecentCallsConfigSection[] = "Recent Calls";
const char SpeedDialConfigSection[] = "Speed Dial";
const char MainWindowTopConfigKey[] = "MainWindowTop";
const char MainWindowLeftConfigKey[] = "MainWindowLeft";
const char MainWindowWidthConfigKey[] = "MainWindowWidth";
const char MainWindowHeightConfigKey[] = "MainWindowHeight";
const char LocalVideoWindowTopConfigKey[] = "LocalVideoWindowTop";
const char LocalVideoWindowLeftConfigKey[] = "LocalVideoWindowLeft";
const char RemoteVideoWindowTopConfigKey[] = "RemoteVideoWindowTop";
const char RemoteVideoWindowLeftConfigKey[] = "RemoteVideoWindowLeft";
const char AutoAnswerConfigKey[] = "AutoAnswer";
const char DtmfAsStringConfigKey[] = "DtmfAsString";
const char UserInputModeConfigKey[] = "UserInputMode";
const char SilenceDetectConfigKey[] = "SilenceDetect";
const char SilenceDeadbandConfigKey[] = "SilenceDeadband";
const char SignalDeadbandConfigKey[] = "SignalDeadband";
const char NoFastStartConfigKey[] = "NoFastStart";
const char NoTunnelingConfigKey[] = "NoTunneling";
const char NoH245inSetupConfigKey[] = "NoH245inSetup";
const char MaxRecentCallsConfigKey[] = "MaxRecentCalls";
const char TCPPortBaseConfigKey[] = "TCPPortBase";
const char TCPPortMaxConfigKey[] = "TCPPortMax";
const char UDPPortBaseConfigKey[] = "UDPPortBase";
const char UDPPortMaxConfigKey[] = "UDPPortMax";
const char RTPPortBaseConfigKey[] = "RTPPortBase";
const char RTPPortMaxConfigKey[] = "RTPPortMax";
const char IpTosConfigKey[] = "IpTOS";
const char UsernameConfigKey[] = "Username";
const char AliasConfigKey[] = "Alias %u";
const char AlwaysForwardPartyConfigKey[] = "AlwaysForwardParty";
const char BusyForwardPartyConfigKey[] = "BusyForwardParty";
const char NoAnswerForwardPartyConfigKey[] = "NoAnswerForwardParty";
const char CallIntrusionTypeKey[] = "CallIntrusionTypeKey";
const char CallIntrusionProtectionLevelKey[] = "CallIntrusionProtectionLevel";
const char CallIntrusionCapabilityLevelKey[] = "CallIntrusionCapabilityLevel";
const char TransferProtocolConfigKey[] = "TransferProtocol";
const char NoAnswerTimeConfigKey[] = "NoAnswerTime";
const char RingSoundFileConfigKey[] = "RingSoundFile";
const char SoundBuffersConfigKey[] = "SoundBuffers";
const char AECConfigKey[] = "AEC";
const char CountryConfigKey[] = "Country";
const char JitterConfigKey[] = "Jitter";
const char BandwidthTypeConfigKey[] = "BandwidthType";
const char BandwidthConfigKey[] = "Bandwidth";
const char UseGatekeeperConfigKey[] = "UseGatekeeper";
const char RequireGatekeeperConfigKey[] = "RequireGatekeeper";
const char TimeToLiveConfigKey[] = "TimeToLive";
const char AccessTokenOIDConfigKey[] = "AccessTokenOID";
const char GatekeeperHostConfigKey[] = "GatekeeperHost";
const char GatekeeperIdConfigKey[] = "GatekeeperId";
const char GatekeeperPasswordConfigKey[] = "GatekeeperPassword";
const char SoundPlayConfigKey[] = "SoundPlayDevice";
const char SoundRecordConfigKey[] = "SoundRecordDevice";
const char SpeakerVolumeConfigKey[] = "SpeakerVolume";
const char MicrophoneVolumeConfigKey[] = "MicrophoneVolume";
const char UseQuicknetConfigKey[] = "UseQuicknet";
const char QuicknetDeviceConfigKey[] = "QuicknetDevice";
const char DeviceTypeConfigKey[] = "LineInterfaceDeviceType";
const char DeviceNameConfigKey[] = "LineInterfaceDeviceName";
const char H261QCIFConfigKey[] = "H261_QCIF";
const char H261CIFConfigKey[] = "H261_CIF";
const char AutoReceiveVideoConfigKey[] = "AutoReceiveVideo";
const char VideoDeviceConfigKey[] = "VideoDevice";
const char VideoSizeConfigKey[] = "VideoSize";
const char VideoSourceConfigKey[] = "VideoSource";
const char VideoFormatConfigKey[] = "VideoFormat";
const char VideoQualityConfigKey[] = "VideoQuality";
const char VideoLocalConfigKey[] = "VideoLocal";
const char VideoFlipLocalConfigKey[] = "VideoFlipLocal";
const char VideoFlipRemoteConfigKey[] = "VideoFlipRemote";
#if PTRACING
const char TraceFileConfigKey[] = "TraceFile";
const char TraceLevelConfigKey[] = "TraceLevel";
const char TraceBlockConfigKey[] = "TraceBlocks";
const char TraceDateTimeConfigKey[] = "TraceDateAndTime";
const char TraceTimestampConfigKey[] = "TraceTimestamp";
const char TraceThreadsConfigKey[] = "TraceThreads";
const char TraceThreadAddresssConfigKey[] = "TraceThreadAddresss";
const char TraceLevelDisplayConfigKey[] = "TraceLevelDisplay";
const char TraceFileLineConfigKey[] = "TraceFileAndLine";
#endif
enum {
SoundDeviceTypeCode = 1,
QuicknetDeviceTypeCode = 2,
BlasterDeviceTypeCode = 3
};
const char InternalGatewayName[] = "<<Local-PSTN>>";
const char CodecsConfigKey[] = "Codec%u";
const char OnCodecSuffix[] = " (On)";
const char OffCodecSuffix[] = " (Off)";
const DWORD RingCadence = 0x145; // 0001 0100 0101
const PDIMENSION StatusWindowHeight = 100;
const PDIMENSION CallButtonHeight = 15;
const PDIMENSION ScrollBarHeight = 12;
const PDIMENSION VUMeterHeight = 8;
const PDIMENSION SpeedDialButtonHeight = 12;
#define new PNEW
///////////////////////////////////////////////////////////////////////////////
OpenPhone::OpenPhone()
: PApplication("Self", "PCPhone",
MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER)
{
}
void OpenPhone::Main()
{
// create the main window and endpoint
// InitSkinLoad(GetCurrentThreadId());
// LoadSkin("xp_normal.skin");
// InitEasySkinLib(AfxGetInstanceHandle(),NULL,NULL,NULL);
new MainWindow(GetArguments());
// enter the main loop
PApplication::Main();
}
void OpenPhone::OnAbout()
{
AboutDialog dlg(mainWindow);
dlg.version->SetName(dlg.version->GetName() + GetVersion(TRUE));
dlg.RunModal();
}
///////////////////////////////////////////////////////////////////////////////
MainWindow::MainWindow(PArgList & /*args*/)
#ifdef _MSC_VER
#pragma warning(disable:4355)
#endif
: endpoint(this)
#ifdef _MSC_VER
#pragma warning(default:4355)
#endif
{
PConfig config;
#if PTRACING
myTraceFile = NULL;
OpenTraceFile(config);
#endif
SetTitle(PResourceString(IDS_TITLE));
SetIcon(PIcon(IDI_MAIN_WINDOW));
// myMainMenu = new MainMenu(this);
// SetMenu(myMainMenu);
// set the background colour and load the image
SetBackgroundColour(PColour::Grey);
// 设置
SetMinSize(150, 137, LocalCoords);
// Set remembered position of main window
PPoint pos(config.GetInteger(MainWindowLeftConfigKey, INT_MAX),
config.GetInteger(MainWindowTopConfigKey, INT_MAX));
if (pos != PPoint(INT_MAX, INT_MAX))
SetPosition(pos, TopLeftPixels, TopLeftPixels);
PDim dim(config.GetInteger(MainWindowWidthConfigKey, 0),
config.GetInteger(MainWindowHeightConfigKey, 0));
if (dim != PDim(0, 0))
SetDimensions(dim, PixelCoords);
else
SetDimensions(210, 30,
/*StatusWindowHeight +
CallButtonHeight +
ScrollBarHeight +
SpeedDialButtonHeight,*/
LocalCoords);
dim = GetDimensions(LocalCoords);
//创建窗口
statusWindow = new PStringListBox(this, PListBox::NotSorted);
statusWindow->SetDimensions(dim.Width(), StatusWindowHeight, LocalCoords);
statusWindow->SetPosition(0, 0);
statusWindow->SetBackgroundColour(PColour::Black);
statusWindow->SetForegroundColour(PColour::Green);
statusWindow->Show();
answerButton = new PTextButton(this, PResourceString(IDS_ANSWERCALL), PCREATE_NOTIFIER(OnAnswerButton));
answerButton->SetDimensions(dim.Width()/2, CallButtonHeight, LocalCoords);
answerButton->SetPosition(0, StatusWindowHeight);
refuseButton = new PTextButton(this, PResourceString(IDS_REFUSECALL), PCREATE_NOTIFIER(OnRefuseButton));
refuseButton->SetDimensions(dim.Width()/2, CallButtonHeight, LocalCoords);
refuseButton->SetPosition(dim.Width()/2, StatusWindowHeight);
hangUpButton = new PTextButton(this, PResourceString(IDS_HANGUP), PCREATE_NOTIFIER(OnHangUpButton));
hangUpButton->SetDimensions(dim.Width()/2, CallButtonHeight, LocalCoords);
hangUpButton->SetPosition(0, StatusWindowHeight);
//speakerButton = new PTextButton(this, PResourceString(IDS_SPEAKERPHONE), PCREATE_NOTIFIER(OnSpeakerButton));
//speakerButton->SetDimensions(dim.Width()/4, CallButtonHeight, LocalCoords);
//speakerButton->SetPosition(dim.Width()/4, StatusWindowHeight);
//transferButton = new PTextButton(this, PResourceString(IDS_TRANSFER), PCREATE_NOTIFIER(OnTransferButton));
//transferButton->SetDimensions(dim.Width()/4, CallButtonHeight, LocalCoords);
//transferButton->SetPosition(dim.Width()/2, StatusWindowHeight);
holdButton = new PTextButton(this, PResourceString(IDS_HOLD), PCREATE_NOTIFIER(OnHoldButton));
holdButton->SetDimensions(dim.Width()/2, CallButtonHeight, LocalCoords);
holdButton->SetPosition(dim.Width()/2, StatusWindowHeight);
// intrudeCallButton = new PTextButton(this, PResourceString(IDS_INTRUDECALL), PCREATE_NOTIFIER(OnIntrudeButton));
// intrudeCallButton->SetDimensions(dim.Width()/2, CallButtonHeight, LocalCoords);
// intrudeCallButton->SetPosition(dim.Width()/2, StatusWindowHeight);
makeCallButton = new PTextButton(this, PResourceString(IDS_MAKECALL), PCREATE_NOTIFIER(OnCallButton));
makeCallButton->SetDimensions(dim.Width(), CallButtonHeight, LocalCoords);
makeCallButton->SetPosition(0, StatusWindowHeight);
speakerEnable = new PCheckBox(this, PResourceString(IDS_SPEAKER), PCREATE_NOTIFIER(OnSpeakerEnable));
speakerEnable->SetValue(TRUE);
PDim boxSize = speakerEnable->GetDimensions(LocalCoords);
boxSize.AddWidth(4);
speakerEnable->SetDimensions(boxSize, LocalCoords);
PSCROLLBAR_VALUE spkrVolume = (PSCROLLBAR_VALUE)config.GetInteger(SpeakerVolumeConfigKey, 128);
speakerVolume = new PHorizontalScrollBar(this, PCREATE_NOTIFIER(OnSpeakerVolume),
100, 0, spkrVolume, 5, 20);
PDIMENSION scrollBarWidth = dim.Width()/2 - boxSize.Width();
speakerVolume->SetDimensions(scrollBarWidth, ScrollBarHeight, LocalCoords);
speakerVolume->SetPosition(0, StatusWindowHeight+CallButtonHeight);
speakerEnable->SetPosition(scrollBarWidth, StatusWindowHeight+CallButtonHeight+(ScrollBarHeight-boxSize.Height())/2);
speakerVU = new VUMeter(this);
speakerVU->SetDimensions(dim.Width()/2-2, VUMeterHeight, LocalCoords);
speakerVU->SetPosition(1, StatusWindowHeight+CallButtonHeight+ScrollBarHeight+1);
speakerVU->SetForegroundColour(PColour::Red);
speakerVU->SetBackgroundColour(PColour::Black);
microphoneEnable = new PCheckBox(this, PResourceString(IDS_MICROPHONE), PCREATE_NOTIFIER(OnMicrophoneEnable));
microphoneEnable->SetValue(TRUE);
boxSize = microphoneEnable->GetDimensions(LocalCoords);
boxSize.AddWidth(4);
microphoneEnable->SetDimensions(boxSize, LocalCoords);
microphoneEnable->SetPosition(dim.Width()/2-boxSize.Width(), StatusWindowHeight+CallButtonHeight+(ScrollBarHeight-boxSize.Height())/2);
PSCROLLBAR_VALUE mikeVolume = (PSCROLLBAR_VALUE)config.GetInteger(MicrophoneVolumeConfigKey, 128);
microphoneVolume = new PHorizontalScrollBar(this, PCREATE_NOTIFIER(OnMicrophoneVolume),
100, 0, mikeVolume, 5, 20);
microphoneVolume->SetDimensions(dim.Width()/2-boxSize.Width(), ScrollBarHeight, LocalCoords);
microphoneVolume->SetPosition(dim.Width()/2, StatusWindowHeight+CallButtonHeight);
microphoneVU = new VUMeter(this);
microphoneVU->SetDimensions(dim.Width()/2-2, VUMeterHeight, LocalCoords);
microphoneVU->SetPosition(dim.Width()/2+1, StatusWindowHeight+CallButtonHeight+ScrollBarHeight+1);
microphoneVU->SetForegroundColour(PColour::Red);
microphoneVU->SetBackgroundColour(PColour::Black);
AddSpeedDialButtons();
statisticsDialog = new StatisticsDlg(this);
statisticsDialog->Hide();
//display the window
UpdateCommandSources();
Show();
SetCallMode(IdleCallMode);
speakerphoneSwitch = FALSE;
// Get some parameters
autoAnswer = config.GetBoolean(AutoAnswerConfigKey, FALSE);
maxRecentCalls = config.GetInteger(MaxRecentCallsConfigKey, 10);
noAnswerForwardParty = config.GetString(NoAnswerForwardPartyConfigKey);
noAnswerTime = PTimeInterval(0, config.GetInteger(NoAnswerTimeConfigKey, 30));
ringSoundFile = config.GetString(RingSoundFileConfigKey);
ringSoundTimer.SetNotifier(PCREATE_NOTIFIER(OnRingSoundAgain));
noAnswerTimer.SetNotifier(PCREATE_NOTIFIER(OnNoAnswerTimeout));
vuTimer.SetNotifier(PCREATE_NOTIFIER(OnUpdateVU));
// Initialisation of H323 stuff
if (endpoint.Initialise(config)) {
OutputStatus(IDS_LISTENING);
endpoint.lid->SetPlayVolume(endpoint.potsLine, spkrVolume);
endpoint.lid->SetRecordVolume(endpoint.potsLine, mikeVolume);
}
else
SetCallMode(NoGatekeeperMode);
recorder = NULL;
}
MainWindow::~MainWindow()
{
currentCallMode = ApplicationShuttingDown;
// Do this now, if leave to endpoint destructor callbacks on the main window
// are accessing destroyed object.
endpoint.ClearAllCalls();
#if PTRACING
if (myTraceFile) {
PTrace::SetStream(NULL);
myTraceFile->Close();
}
delete myTraceFile;
#endif
}
void MainWindow::OutputStatus(PRESOURCE_ID strId, ...)
{
if (currentCallMode == ApplicationShuttingDown)
return;
va_list args;
va_start(args, strId);
PResourceString fmt = strId;
PStringArray lines = pvsprintf(fmt, args).Lines();
for (PINDEX i = 0; i < lines.GetSize(); i++)
statusWindow->AddString(lines[i]);
PINDEX count = statusWindow->GetCount();
if (count > 3)
statusWindow->SetTopIndex(count - 3);
}
BOOL MainWindow::AllowClose(BOOL)
{
PWaitAndSignal mutex(callModeMutex);
switch (currentCallMode) {
case IdleCallMode :
case NoGatekeeperMode :
case ApplicationShuttingDown :
break;
default :
if (!PSimpleDialog::YesNo(this, IDS_INCALLEXIT))
return FALSE;
break;
}
currentCallMode = ApplicationShuttingDown;
return TRUE;
}
void MainWindow::OnClose()
{
if (GetSizeMode() != Normalised)
return;
PConfig config;
PPoint pos = GetPosition(PixelCoords);
config.SetInteger(MainWindowLeftConfigKey, pos.X());
config.SetInteger(MainWindowTopConfigKey, pos.Y());
PDim dim = GetDimensions(PixelCoords);
config.SetInteger(MainWindowWidthConfigKey, dim.Width());
config.SetInteger(MainWindowHeightConfigKey, dim.Height());
/// ExitSkinLoad();
}
void MainWindow::OnResize(const PDim & newSize, ResizeType type)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -