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

📄 mainwindowsub.cxx

📁 使用VOIP技术.能够无连接接通远程用户
💻 CXX
📖 第 1 页 / 共 2 页
字号:
  if ((toReorder.GetStringsIndex("H.261-CIF") != P_MAX_INDEX) ||      (toReorder.GetStringsIndex("H.261-QCIF") != P_MAX_INDEX)   ) {    autoStartTransmitVideo = TRUE;    autoStartReceiveVideo  = TRUE;  }}void MainUi::RebuildCapabilityTable(){  AddAllCapabilities();  ReorderCapabilities();}BOOL MainUi::SetSoundDevice(const char * optionName,                                    PSoundChannel::Directions dir){  PString dev = audioOpts.GetAudioDevice();  if (dir == PSoundChannel::Player) {    if (SetSoundChannelPlayDevice(dev))      return TRUE;  }  else {    if (SetSoundChannelRecordDevice(dev))      return TRUE;  }  cerr << "SET SOUND DEVICE to be "<< dev << " failed."<< endl;    return FALSE;}H323Connection * MainUi::CreateConnection(unsigned callReference){  unsigned opt = 0;  if (connectOpts.noFastStart)    opt += H323Connection::FastStartOptionDisable;  if (connectOpts.noH245Tunnelling)     opt += H323Connection::H245TunnelingOptionDisable;  return new CpConnection(callReference, opt);}BOOL MainUi::OnIncomingCall(H323Connection & connection,                                    const H323SignalPDU & setupPDU,                                    H323SignalPDU &){  if (applicationIsExiting)    return FALSE;  if (setupPDU.m_h323_uu_pdu.HasOptionalField(H225_H323_UU_PDU::e_nonStandardData)) {    PString param = setupPDU.m_h323_uu_pdu.m_nonStandardData.m_data.AsString();    if (!param)      cout << "Incoming setup PDU contains non-standard parameter: \"" << param << "\"." << endl;  }  if (!currentCallToken.IsEmpty())    cout << "WARNING: current call token not empty" << endl;  if (currentCallToken.IsEmpty()  ) {    currentCallToken = connection.GetCallToken();    return TRUE;  }  PTime now;  PString msg = "Call from \"" + connection.GetRemotePartyName() + "\" ignored";  DisplayMessage(msg);  connection.ClearCall(H323Connection::EndedByLocalBusy);  return FALSE;}BOOL MainUi::WaitingForACall(){  return currentCallToken.IsEmpty();}void MainUi::OnNoAnswerTimeout(){  H323Connection * connection = FindConnectionWithLock(currentCallToken);  if (connection == NULL)    return;  connection->ClearCall(H323Connection::EndedByNoAnswer);  connection->Unlock();}void MainUi::OnConnectionEstablished(H323Connection & connection,                                             const PString & /*token*/){  OnConnectionEstablished( "Call with \"" +connection.GetRemotePartyName() + "\" started");  epState = epCallInProgress;}void MainUi::OnConnectionCleared(H323Connection & connection, const PString & clearedCallToken){  firstErrorOpenAudioChannel = TRUE;  // stop any request for "Call Answer Y/N"  StopCallAnswer();    audioOpts.AttachAudioChannel(TRUE, NULL); //IsEncoding channel is set to NULL  audioOpts.AttachAudioChannel(FALSE, NULL);//receiving channel is set to NULL  // ignore connections that are not the current connection  if (clearedCallToken != currentCallToken) {    return;  }  currentCallToken = PString(); // indicate that our connection is now cleared  // indicate call has hungup  epState = epCallHungup;  PString remoteName = "\"" + connection.GetRemotePartyName() + "\"";  PString message;  switch (connection.GetCallEndReason()) {  case H323Connection::EndedByCallForwarded :    message = "";    break;  case H323Connection::EndedByRemoteUser :    message = remoteName + " has cleared the call";    break;  case H323Connection::EndedByCallerAbort :    message = remoteName + " has stopped calling";    break;  case H323Connection::EndedByRefusal :    message = remoteName + " did not accept your call";    break;  case H323Connection::EndedByRemoteBusy :    message = remoteName + " was busy";    break;  case H323Connection::EndedByRemoteCongestion :    message = PString("Congested link to ") + remoteName;    break;  case H323Connection::EndedByNoAnswer :    message = remoteName + " did not answer your call";    break;  case H323Connection::EndedByTransportFail :    message = "Call with " + remoteName + " ended abnormally";    break;  case H323Connection::EndedByCapabilityExchange :    message = "Could not find common codec with " + remoteName;    break;  case H323Connection::EndedByNoAccept :    message = "Did not accept incoming call from " + remoteName;    break;  case H323Connection::EndedByAnswerDenied :    message = "Refused incoming call from " + remoteName;    break;  case H323Connection::EndedByNoUser :    message = "Gatekeeper could find user " + remoteName;    break;  case H323Connection::EndedByNoBandwidth :    message = "Call to " + remoteName + " aborted, insufficient bandwidth";    break;  case H323Connection::EndedByUnreachable :    message = remoteName + " could not be reached";    break;  case H323Connection::EndedByHostOffline :    message = remoteName + " is not online";    break;  case H323Connection::EndedByNoEndPoint :    message = "No phone running for " + remoteName;    break;  case H323Connection::EndedByConnectFail :    message = "Transport error calling " + remoteName;    break;  default :    PTimeInterval timeInt = PTime() - connection.GetConnectionStartTime() ;    message = "Goodbye " + remoteName;    if (IsInCall())      message += ". Duration: " + timeInt.AsString(0);  }#if defined(HAS_IXJ)  lidThread.RingPhone(FALSE);#endif  OnConnectionCleared(message);}//When a connection to a remote computer is created, this routine is called lots//of times (4). We want to avoid displaying 4 Critical error messages.//The variable firstErrorOpenAudioChannel is used to do this.BOOL MainUi::OpenAudioChannel(H323Connection & connection,                                         BOOL isEncoding,                                         unsigned bufferSize,                                         H323AudioCodec & codec){#if defined(HAS_IXJ)  if (lidThread.lid.IsOpen()) {    PTRACE(2, "ep\tAttaching " << lidThread.GetDeviceName() << " to codec");    if (!codec.AttachChannel(new OpalLineChannel(lidThread.lid, OpalIxJDevice::POTSLine, codec)))      return FALSE;  }  else#endif  if (!H323EndPoint::OpenAudioChannel(connection, isEncoding, bufferSize, codec)) {    PStringStream str;    if (isEncoding)      str << GetSoundChannelRecordDevice();    else      str << GetSoundChannelPlayDevice();        PString thisMessage = "Sound device \"" + str + "\" could not be opened.\n\n" +                      "Check:\n" +                     "           1)Full duplex device, \n" +                     "           2)permissions" ;    if (firstErrorOpenAudioChannel) {      firstErrorOpenAudioChannel = FALSE;      DisplayCriticalError(thisMessage) ;    }    return FALSE;  }  codec.SetSilenceDetectionMode(audioOpts.GetDisableSilence() ?				H323AudioCodec::NoSilenceDetection     :				H323AudioCodec::AdaptiveSilenceDetection );  PChannel *channel = codec.GetRawDataChannel();  audioOpts.AttachAudioChannel(isEncoding, channel);  if (isEncoding)    audioOpts.VolumeMicrophoneChange();  else    audioOpts.VolumeSpeakerChange();  return TRUE;}BOOL MainUi::OpenVideoChannel(H323Connection & connection,                                     BOOL isEncoding,                                     H323VideoCodec & codec){  CpVideoChannel      * channel;  channel = isEncoding ? transmitVideoChannel : receiveVideoChannel;  if (isEncoding) {    codec.SetTxQualityLevel(videoOpts.GetTransmitQuality());    codec.SetBackgroundFill(4); //The videoFill parameter in ohphone);       codec.SetMaxBitRate(0);     // this disables bitrate control    videoOpts.AttachVideoCodec(&codec);  }   //Select false, do NOT delete video channel on closing codec.  return codec.AttachChannel(channel, FALSE);}////  if gateway is empty,     dest is assumed to be IP address[:port]//  if gateway is non-empty, //             - gateway is assumed to be an IP address[:port]port,//             - dest is an e164 address which is passed to the gateway.//void MainUi::MakeOutgoingCall(const PString & dest,                                      const PString & gateway){  DisplayMessage("Call " + dest);  PString fullAddress;  if (!gateway.IsEmpty()) {    fullAddress = gateway;    fullAddress = dest.Trim() + '@' + fullAddress;  } else    fullAddress = dest;  if (!MakeCall(fullAddress, currentCallToken)) {    DisplayMessage("Cannot make call to \"" + fullAddress + "\"");    return;  }  epState = epConnectingCall;}void MainUi::StartCall(const PString & ostr){  MakeOutgoingCall(ostr, PString());  return;}void MainUi::StartTerminationProcess(){  applicationIsExiting = TRUE;  videoOpts.SaveSettings();  audioOpts.SaveSettings();  connectOpts.SaveSettings();  ClearAllCalls();#ifdef HAS_IXJ  lidThread.TerminateThread();  lidThread.WaitForTermination();#endif  epState = epDialTone;  SendDieMessageToWindow(eAddressBook);  SendDieMessageToWindow(eAudioProperties);  SendDieMessageToWindow(eSettings);  SendDieMessageToWindow(eVideoProperties);  DeleteLocalVideoDisplayThread();  DeleteVideoDisplay();}void MainUi::ExitCurrentCall(){  StopCallAnswer();  if ((epState ==  epDialTone) || (epState == epNoTone))    return;  if (currentCallToken.IsEmpty())    DisplayMessage("Ending call setup");  else    DisplayMessage("Closing call with " + currentCallToken);    ClearAllCalls();}BOOL MainUi::SearchForAGatekeeper(PString gkName){  BOOL foundGk = FALSE;  if(gkName.IsEmpty()) {    //Search for a gatekeeper of unknown name.    DisplayMessage("Searching for gatekeeper");    foundGk = DiscoverGatekeeper(new H323TransportUDP(*this));  } else {    //Search for gatekeeper of known name.    DisplayMessage("Search for \"" + gkName + "\"");    foundGk = LocateGatekeeper(gkName);  }  if (foundGk) {    PStringStream str;    str << *gatekeeper;    DisplayMessage("Gatekeeper \"" + str + "\" found");    connectOpts.gatekeeperName = str;  } else {    if(gkName.IsEmpty())      DisplayMessage("Sorry: Gatekeeper discovery failed");    else      DisplayMessage("Gatekeeper \"" + gkName + "\" not found");  }    return foundGk;}void MainUi::AnswerCall(H323Connection::AnswerCallResponse response){  if (epState != epAnsweringCall)    return;    //Make absolutely certain, "Call Answer Y/N"  has died.  StopCallAnswer();  H323Connection * connection = FindConnectionWithLock(currentCallToken);  if (connection == NULL)    return;  connection->AnsweringCall(response);  connection->Unlock();  if (response == H323Connection::AnswerCallNow)         epState = epCallInProgress;  else     epState = epCallHungup;}void MainUi::SendDieMessageToWindow(enum WindowName name){  QWidget *dialog = CPhone::Current().GetWindow(name); if (dialog != NULL)     QApplication::sendEvent(dialog, new QCustomEvent(CUSTOM_EVENT_DIE));}void MainUi::StopCallAnswer(){  SendDieMessageToWindow(eCallAnswer);}BOOL MainUi::SetDisableSilenceDetection(BOOL disableSilence){  SetSilenceDetectionMode(disableSilence ? 			  H323AudioCodec::NoSilenceDetection     :			  H323AudioCodec::AdaptiveSilenceDetection );  return TRUE;}BOOL MainUi::SetEchoCancellation(PString newEchoCancellation){#if defined(HAS_IXJ)  PStringArray names = GetAvailableEchoCancNames();  for (PINDEX i = 0; i < names.GetSize(); i++)    if (strcmp(newEchoCancellation, names[i]) == 0) {      return lidThread.SetEchoCancellation(i);    }#endif  return FALSE;};PStringArray MainUi::GetAvailableDeviceNames(){  return soundCardNames + ixjCardNames;}PStringArray MainUi::GetAvailableEchoCancNames(){  const char *cNames[] = {"Off", "Low", "Medium", "High", "Auto AEC", "Auto AEC/AGC"};  PStringArray names(6, cNames, FALSE);  return names;}void MainUi::SetSoundChannelBufferDepth(unsigned int newDepth){  H323EndPoint::SetSoundChannelBufferDepth(newDepth);}void MainUi::SetAudioJitterDelay(unsigned int low, unsigned int high){  H323EndPoint::SetAudioJitterDelay(low, high);}BOOL MainUi::SetSoundChannelRecordDevice(const PString &newDevice){  return H323EndPoint::SetSoundChannelRecordDevice(newDevice);}BOOL MainUi::SetSoundChannelPlayDevice(const PString &newDevice){  return H323EndPoint::SetSoundChannelPlayDevice(newDevice);}  void MainUi::UpdateNatTraversalAddress(){  masqAddress = PIPSocket::Address(connectOpts.externalNatAddress);}BOOL  MainUi::MicroTelcoActivate(BOOL doActivate){  if (doActivate) {    SetLocalUserName(connectOpts.userName); /*Which removes old alisases */    AddAliasName(connectOpts.microTelcoAccount);    SetGatekeeperPassword(connectOpts.microTelcoPassword);    return SetGatekeeper("gk.microtelco.com", new H323TransportUDP(*this));  }  RemoveGatekeeper();  return TRUE;}PString MainUi::GetGatekeeperName(){  H323Gatekeeper *gk =  CPhone::GetUi().GetGatekeeper();  if (gk == NULL)     return PString();  return gk->GetName();}BOOL MainUi::InitialiseGatekeeper(){ BOOL success = TRUE; if (connectOpts.searchForGatekeeper)       return DiscoverGatekeeper(new H323TransportUDP(*this)); if (connectOpts.gatekeeperName.IsEmpty())    RemoveGatekeeper(); else   success = SetGatekeeper(connectOpts.gatekeeperName);    return success;}PString MainUi::GetGatekeeperRegistrationMessage(){  H323Gatekeeper *gk = GetGatekeeper();  if (gk == NULL)    return "No gatekeeper in system";  switch (gk->GetRegistrationFailReason()) {  case  H323Gatekeeper::RegistrationSuccessful:         return "Successful";  case  H323Gatekeeper::UnregisteredLocally:            return "Unregistered locally";  case  H323Gatekeeper::UnregisteredByGatekeeper:       return "Unregistered by gatekeeper";  case  H323Gatekeeper::GatekeeperLostRegistration:     return "Lost registration";  case  H323Gatekeeper::InvalidListener:                return "Invalid listener";  case  H323Gatekeeper::DuplicateAlias:                 return "Duplicate alias";  case  H323Gatekeeper::SecurityDenied:                 return "Security denied";  case  H323Gatekeeper::TransportError:                 return "Transport error";  default:                              return "Unknown registration reason";  }  return "Unkonwn registration reason";}void MainUi::UpdateUserName(){  PString newUserName = (const char *)connectOpts.userName;  SetLocalUserName(newUserName);}H323Connection::AnswerCallResponse MainUi::AnswerCallConditional(const PString & caller, PString newCallToken){  currentCallToken = newCallToken;  if (connectOpts.autoAnswer) {    DisplayMessage("Commence call: " + PTime().AsString());    return H323Connection::AnswerCallNow;  }  epState = epAnsweringCall;  QueryCallAnswer(caller);    return H323Connection::AnswerCallPending;}void MainUi::HandleHandsetDown(BOOL isDown){#ifdef HAS_IXJ  DisplayMessage(lidThread.GetDeviceName() + " has gone " + (isDown ? "on" : "off") + " hook");  if (isDown) {    ExitCurrentCall();    epState = epNoTone;  } else {    if (CPhone::Current().GetWindow(eCallAnswer) != NULL)       QApplication::postEvent(this, new QCustomEvent(CALL_ANSWER_RESPONSE_YES));    else      epState = epDialTone;  }#endif}

⌨️ 快捷键说明

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