📄 mainwindowsub.cxx
字号:
//// 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 CPhone, a cross platform voip gui.//// The Initial Developer of the Original Code is Derek Smithies.//// Copyright (C) 2002 Indranet Technologies Ltd, // http://www.indranet-technologies.com// All Rights Reserved.//// Contributor(s): _______________/* * * $Log: mainwindowSub.cxx,v $ * Revision 1.6 2003/05/20 03:32:28 dereksmithies * Better handling of ixj handset states, and call progress states. * * Revision 1.5 2003/05/09 04:34:46 dereksmithies * Tidy up gatekeeper finding. Works reliably. * * Revision 1.4 2003/05/09 03:08:24 dereksmithies * Fix Microtelco handling, and message display * * Revision 1.3 2003/05/06 22:40:36 dereksmithies * Fixes to get it working correctly on microtelco. * * Revision 1.2 2003/04/04 04:37:49 dereksmithies * Major upgrade. * Ixj & microtelco support added. Fix threading issues. * * Revision 1.1.1.1 2002/05/12 22:55:05 dereksmithies * Initial release. * * * * */#include <ptlib.h>#include <qapplication.h>#include <qlabel.h>#include <qapp.h>#include "addressbookSub.h"#include "audiopropertiesSub.h"#include "callanswer.h"#include "callanswerSub.h"#include "cpendpoint.h"#include "main.h"#include "mainwindowSub.h"#include "message.h"#include "qtvid.h"#include "settingsSub.h"#include "videopropertiesSub.h"#include "h323pdu.h"#include <h323.h>MainUi::MainUi() :FormMainWindow(0, "main ui", FALSE, WDestructiveClose | WType_TopLevel){ move(20,20); epState = epNoTone; QCustomEvent *ce =new QCustomEvent(MAIN_UI_UP); QApplication::postEvent(this, ce);}MainUi::~MainUi(){ if (transmitVideoChannel != NULL) delete transmitVideoChannel; if (receiveVideoChannel != NULL) delete receiveVideoChannel;}void MainUi::InitialiseConfiguration(){ remoteComputer = ""; localVideoThread = NULL; transmitVideoChannel = NULL; receiveVideoChannel = NULL; firstErrorOpenAudioChannel = TRUE; applicationIsExiting = FALSE;#ifdef HAS_IXJ ixjCardNames = OpalIxJDevice::GetDeviceNames();#endif connectOpts.Initialise(); videoOpts.Initialise(); audioOpts.Initialise(); soundCardNames = PSoundChannel::GetDeviceNames(PSoundChannel::Player); InitialiseVideoDisplay(); CPhone::Current().SetWindowId(eMainUi, winId()); CreateLocalVideoDisplayThread(); audioOpts.AudioDeviceChange(); if (InitialiseVoipSettings() == FALSE) { cerr << "Program cannot run due to an initialisation failure." << endl; exit(00); }}void MainUi::AudioClicked_slot(){ if (CPhone::Current().GetWindow(eAudioProperties) != NULL) { CPhone::Current().GetWindow(eAudioProperties)->raise(); return; } AudioProperties *audioProperties = new AudioProperties(audioOpts); audioProperties->show();}void MainUi::ConnectClicked_slot(){ if (CPhone::Current().GetWindow(eAddressBook) != NULL) { CPhone::Current().GetWindow(eAddressBook)->raise(); return; } AddressBook *addressBook = new AddressBook(); addressBook->show();}void MainUi::VideoClicked_slot(){ if (CPhone::Current().GetWindow(eVideoProperties) != NULL) { CPhone::Current().GetWindow(eVideoProperties)->raise(); return; } VideoProperties *videoProperties = new VideoProperties(videoOpts); videoProperties->show();}void MainUi::SettingsClicked_slot(){ if (CPhone::Current().GetWindow(eSettings) != NULL) { CPhone::Current().GetWindow(eSettings)->raise(); return; } Settings *settingsCall = new Settings(connectOpts); settingsCall->show();}void MainUi::ExitClicked_slot(){ close(TRUE);}void MainUi::HangupClicked_slot(){ ExitCurrentCall();}PVideoOutputDevice *MainUi::GetDisplayModule (BOOL isEncoding, BOOL isFlipped){ VideoDisplay *displayWidget = ((isEncoding) ? FormMainWindow::VideoDisplayLocal : FormMainWindow::VideoDisplayReceived); return new QtVideoDevice(isEncoding, displayWidget, isFlipped);}BOOL MainUi::CreateLocalVideoDisplayThread(){ if (!videoOpts.GetDisplayLocal()) return TRUE; if (localVideoThread != NULL) return TRUE; transmitVideoChannel->AttachVideoPlayer(GetDisplayModule(TRUE, videoOpts.GetFlipLocal()), FALSE); localVideoThread = new LocalVideoDisplayThread(transmitVideoChannel); return TRUE;}BOOL MainUi::DeleteLocalVideoDisplayThread(){ if (localVideoThread != NULL) { localVideoThread->InitiateTermination(); localVideoThread->WaitForTermination(); delete localVideoThread; localVideoThread = NULL; } return TRUE;}void MainUi::SetDisplayString(QString qMessage){ LabelDisplayUserInformation->prepareDisplayText(qMessage); QCustomEvent *ce =new QCustomEvent(QEvent::User); QApplication::postEvent(LabelDisplayUserInformation, ce); killTimers(); startTimer(20 * 1000); //display text for 20 seconds;}void MainUi::DisplayCriticalError(QString message){ ThreadSafeMessage * error = new ThreadSafeMessage(); error->DisplayError(message);}void MainUi::DisplayCriticalError(PString message){ QString qMessage(message.GetPointer()); DisplayCriticalError(qMessage);}void MainUi::DisplayCriticalError(char * message){ QString qMessage(message); DisplayCriticalError(qMessage);}void MainUi::QueryCallAnswer(PString remoteNode){ if (CPhone::Current().GetWindow(eCallAnswer) != NULL) return; remoteComputer = remoteNode.GetPointer(); QString incomingCall("Incoming call from " + remoteComputer); DisplayMessage(incomingCall);#if defined(HAS_IXJ) lidThread.RingPhone();#endif QApplication::postEvent(this, new QCustomEvent(CALL_ANSWER_INITIATE));}void MainUi::closeEvent(QCloseEvent *e){ StartTerminationProcess(); e->accept();}void MainUi::customEvent(QCustomEvent *e){ //THESE three options are generated by the callanswer window. //The CallAnswer window guarantees one response per instantiation. if (e->type() == CALL_ANSWER_RESPONSE_YES) { AnswerCall(H323Connection::AnswerCallNow); //yes from callanswer. DisplayMessage("In call with " + remoteComputer); } if (e->type() == CALL_ANSWER_RESPONSE_NO) AnswerCall(H323Connection::AnswerCallDenied); //no from callanswer. if (e->type() == CALL_ANSWER_RESPONSE_TMO) AnswerCall(H323Connection::AnswerCallDenied); //timeout from callanswer. //THIS option is generated when this class is created. //ensures that the endpoint is made after this class. if (e->type() == MAIN_UI_UP) InitialiseConfiguration(); if (e->type() == CALL_ANSWER_INITIATE) { CallAnswer * dialogCallAnswer = new CallAnswer(remoteComputer); dialogCallAnswer->show(); } return; }void MainUi::timerEvent(QTimerEvent *){ LabelDisplayUserInformation->clear(); //setText("");}void MainUi::OnConnectionEstablished(PString message){ //Before the current call starts to use video, delete the local display. DeleteLocalVideoDisplayThread(); DisplayMessage(message); OnConnectionEstablished(TRUE);}void MainUi::OnConnectionCleared(PString message){ DisplayMessage(message); videoOpts.AttachVideoCodec(NULL); CreateLocalVideoDisplayThread(); CpVideoChannel *receiveVideoChannel = GetReceiveVideoChannel(); receiveVideoChannel->RemoveVideoImage(); OnConnectionEstablished(FALSE);}void MainUi::OnConnectionEstablished(BOOL isEstablished){ Settings *settingsCall = (Settings *)CPhone::Current().GetWindow(eSettings); if (settingsCall != NULL) settingsCall->OnConnectionEstablished(isEstablished); AudioProperties *audioProperties = (AudioProperties *)CPhone::Current().GetWindow(eAudioProperties); if (audioProperties != NULL) audioProperties->OnConnectionEstablished(isEstablished); AddressBook *addressBook = (AddressBook *)CPhone::Current().GetWindow(eAddressBook); if (addressBook != NULL) addressBook->OnConnectionEstablished(isEstablished);}void MainUi::DisplayMessage(PString message){ DisplayMessage(QString((const char *)message));}void MainUi::DisplayMessage(char * message){ DisplayMessage(QString(message));}void MainUi::DisplayMessage(QString message){ SetDisplayString(message);}BOOL MainUi::DisplayLocalIsNow(BOOL doDisplayLocal){ if (doDisplayLocal) transmitVideoChannel->AttachVideoPlayer(GetDisplayModule(TRUE, videoOpts.GetFlipLocal()), FALSE); else transmitVideoChannel->AttachVideoPlayer(new PVideoOutputDeviceNULL(), FALSE); if (IsInCall()) return TRUE; if (doDisplayLocal) CreateLocalVideoDisplayThread(); else DeleteLocalVideoDisplayThread(); return TRUE;}void MainUi:: TranslateTCPAddress(PIPSocket::Address &localAddr, const PIPSocket::Address &remoteAddr){ if (connectOpts.doNatTraversal) // && (remoteAddr.Byte1() != 192)) localAddr = masqAddress; return;}BOOL MainUi::AttachPlayerReaderToVideoChannel(BOOL isEncoding){ CpVideoChannel *vChannel= isEncoding ? transmitVideoChannel : receiveVideoChannel; BOOL doFlip = isEncoding ? videoOpts.GetFlipLocal() : videoOpts.GetFlipReceived(); if (isEncoding) { if (videoOpts.GetDisplayLocal()) vChannel->AttachVideoPlayer(GetDisplayModule(isEncoding, doFlip), FALSE); vChannel->AttachVideoReader(NULL, FALSE); vChannel->AttachVideoReader(videoOpts.GetNewVideoGrabber(), FALSE); } else vChannel->AttachVideoPlayer(GetDisplayModule(isEncoding, doFlip), FALSE); return TRUE;}BOOL MainUi::InitialiseVideoDisplay(){ if (transmitVideoChannel == NULL) transmitVideoChannel = new CpVideoChannel(); if (receiveVideoChannel == NULL) receiveVideoChannel = new CpVideoChannel(); videoOpts.AttachVideoChannels(receiveVideoChannel, transmitVideoChannel); AttachPlayerReaderToVideoChannel(TRUE); //Encoding AttachPlayerReaderToVideoChannel(FALSE); //Decoding return TRUE;}void MainUi::DeleteVideoDisplay(){ if (receiveVideoChannel != NULL) receiveVideoChannel->AttachVideoPlayer(NULL, FALSE); if (transmitVideoChannel != NULL) { transmitVideoChannel->AttachVideoPlayer(NULL, FALSE); transmitVideoChannel->AttachVideoReader(NULL, FALSE); }}void MainUi::UpdateUdpPorts(){ SetRtpIpPorts(connectOpts.lowUdpPort, connectOpts.highUdpPort); /* PortBase, PortMax*/}PStringToString MainUi::GetInterfaceAddressList(){ PIPSocket::InterfaceTable if_table; if (!PIPSocket::GetInterfaceTable(if_table)) { cerr << "GetInterfaceTable() failed. No interface table" << endl; exit(0); } PStringToString interfaceList; for (PINDEX i = 0; i < if_table.GetSize(); i++) interfaceList.SetAt(if_table[i].GetName(), if_table[i].GetAddress()); return interfaceList;}BOOL MainUi::InitialiseVoipSettings(){ if (!connectOpts.userName.IsEmpty()) SetLocalUserName(connectOpts.userName); initialBandwidth = 100000; // Standard 10base LAN in 100's of bits/sec soundChannelBuffers = audioOpts.GetBuffers(); PINDEX i; PStringToString nameIpAddress = GetInterfaceAddressList(); for (i = 0; i < nameIpAddress.GetSize(); i++) { PString interfaceStr = nameIpAddress.GetDataAt(i); PIPSocket::Address interfaceAddress(interfaceStr); H323ListenerTCP * listener = new H323ListenerTCP(*this, interfaceAddress, H323EndPoint::DefaultTcpPort); if (!StartListener(listener)) { cerr << "Warning:: could not open H.323 listener port on " << interfaceAddress << PString(":") << PString(H323EndPoint::DefaultTcpPort) << endl; delete listener; } } if (GetListeners().GetSize() == 0) { cerr << "\n\nError: could not get any H323 listeners on ::" << endl << nameIpAddress << endl << "\n\nIs there another copy of CPhone already running?" << endl; return FALSE; } UpdateUdpPorts(); AddAllCapabilities(); connectOpts.LoadCapabilitiesFromDisk(); RebuildCapabilityTable(); if (connectOpts.doMicroTelco) { connectOpts.doMicroTelco = MicroTelcoActivate(TRUE); if (!connectOpts.doMicroTelco) DisplayCriticalError("Failed to connect to MicroTelco \n" + GetGatekeeperRegistrationMessage()); } if (!InitialiseGatekeeper()) DisplayCriticalError("Gatekeeper discovery process \n" + GetGatekeeperRegistrationMessage()); return TRUE;} void MainUi::AddAllCapabilities(){ int packetUtilisation = connectOpts.packetUtilization; int g711Opts[11] = {10, 12, 14, 18, 24, 30, 47, 80, 130, 190, 240}; int g711Frames = g711Opts[packetUtilisation]; int gsmFrames = (int) (((double)packetUtilisation * 6)/10) + 1; capabilities.RemoveAll();#if defined(HAS_IXJ) lidThread.AddIxjCapabilities(capabilities);#endif H323_GSM0610Capability * gsmCap; SetCapability(0, 0, gsmCap = new H323_GSM0610Capability); gsmCap->SetTxFramesInPacket(gsmFrames); MicrosoftGSMAudioCapability * msGsmCap; SetCapability(0, 0, msGsmCap = new MicrosoftGSMAudioCapability); msGsmCap->SetTxFramesInPacket(gsmFrames); H323_G711Capability * g711uCap; SetCapability(0, 0, g711uCap = new H323_G711Capability(H323_G711Capability::muLaw)); g711uCap->SetTxFramesInPacket(g711Frames); H323_G711Capability * g711aCap; SetCapability(0, 0, g711aCap = new H323_G711Capability(H323_G711Capability::ALaw)); g711aCap->SetTxFramesInPacket(g711Frames); SetCapability(0, 0, new SpeexNarrow2AudioCapability()); SetCapability(0, 0, new SpeexNarrow3AudioCapability()); SetCapability(0, 0, new SpeexNarrow4AudioCapability()); SetCapability(0, 0, new SpeexNarrow5AudioCapability()); SetCapability(0, 0, new SpeexNarrow6AudioCapability()); SetCapability(0, 0, new H323_G726_Capability(*this, H323_G726_Capability::e_16k)); SetCapability(0, 0, new H323_G726_Capability(*this, H323_G726_Capability::e_24k)); SetCapability(0, 0, new H323_G726_Capability(*this, H323_G726_Capability::e_32k)); SetCapability(0, 0, new H323_G726_Capability(*this, H323_G726_Capability::e_40k)); SetCapability(0, 0, new H323_LPC10Capability(*this)); //AddCapability puts the codec into the list of codecs we can send //SetCapability puts the codec into the list of codecs we can send and receive SetCapability(0, 1, new H323_H261Capability(2, 0, FALSE, FALSE, 6217)); SetCapability(0, 1, new H323_H261Capability(0, 4, FALSE, FALSE, 6217)); H323_UserInputCapability::AddAllCapabilities(capabilities, 0, P_MAX_INDEX); PStringList availableCapabilities; for(PINDEX i = 0; i < capabilities.GetSize(); i++) availableCapabilities += capabilities[i].GetFormatName(); connectOpts.SetAvailableCapabilities(availableCapabilities);}void MainUi::ReorderCapabilities(){ PStringArray toRemove = connectOpts.GetDisabledCapabilities(); capabilities.Remove(toRemove); PStringArray toReorder = connectOpts.GetEnabledCapabilities(); capabilities.Reorder(toReorder);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -