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

📄 main.cxx

📁 网络电话(VOIP)软件Pchone 1、按照OpenH323库中readme.txt说明编译OpenH323库 2、再用VC编译PCPhone代码
💻 CXX
📖 第 1 页 / 共 5 页
字号:

  if (GetCallMode() == Active323CallMode) {
    H323Connection * connection = endpoint.FindConnectionWithLock(currentCallToken);
    if (connection != NULL) {
      H323Channel * channel = connection->FindChannel(RTP_Session::DefaultAudioSessionID, FALSE);
      if (channel != NULL) {
        H323Codec * codec = channel->GetCodec();
        if (codec != NULL && codec->IsDescendant(H323AudioCodec::Class()))
            ((H323AudioCodec*)codec)->SetSilenceDetectionMode(
                                            endpoint.GetSilenceDetectionMode(),
                                            0, dlg.signalDeadband, dlg.silenceDeadband);
      }
      connection->Unlock();
    }
  }

  endpoint.SetMaxAudioDelayJitter(dlg.jitter);
  config.SetInteger(JitterConfigKey, dlg.jitter);

  PString oldSection = config.GetDefaultSection();
  config.SetDefaultSection(CodecsConfigSection);
  config.DeleteSection();
  for (i = 0; i < dlg.codecList->GetCount(); i++)
    config.SetString(psprintf(CodecsConfigKey, i+1), dlg.codecList->GetString(i));
  config.SetDefaultSection(oldSection);

  endpoint.LoadCapabilities(config);
}


void AudioCodecOptionsDlg::SelectCodec(PStringListBox & list, INT)
{
  PINDEX selection = list.GetSelection();
  PINDEX count = list.GetCount();

  up->Enable(selection > 0 && selection < count);
  down->Enable(selection < count-1);
  enabledCodec->Enable(selection < count);
  packetSizeBox->Enable(selection < count);

  PString value = list.GetString(selection);
  enabledCodec->SetValue(value.Find(OffCodecSuffix) == P_MAX_INDEX);
  PINDEX left = value.FindLast('[');
  PINDEX right = value.FindLast(']');
  if (left != P_MAX_INDEX && right != P_MAX_INDEX)
    packetSizeBox->SetValue(value(left+1, right-1).AsUnsigned());
}


void AudioCodecOptionsDlg::MoveUp(PTextButton &, INT)
{
  PINDEX selection = codecList->GetSelection();
  codecList->InsertString(codecList->GetString(selection), selection-1, FALSE);
  codecList->DeleteEntry(selection+1);
  codecList->SetSelection(selection-1);
}


void AudioCodecOptionsDlg::MoveDown(PTextButton &, INT)
{
  PINDEX selection = codecList->GetSelection();
  codecList->InsertString(codecList->GetString(selection), selection+2, FALSE);
  codecList->DeleteEntry(selection);
  codecList->SetSelection(selection+1);
}


void AudioCodecOptionsDlg::EnableCodec(PCheckBox & box, INT)
{
  PINDEX selection = codecList->GetSelection();
  if (selection == P_MAX_INDEX)
    return;

  PString str = codecList->GetString(selection);
  if (box.GetValue())
    str.Replace(OffCodecSuffix, OnCodecSuffix);
  else
    str.Replace(OnCodecSuffix, OffCodecSuffix);
  codecList->SetString(str, selection);
  codecList->SetSelection(selection);
}


void AudioCodecOptionsDlg::PacketSizeChange(PIntegerEditBox & box, INT code)
{
  if (code != PEditBox::EndEdit)
    return;

  PINDEX selection = codecList->GetSelection();
  if (selection == P_MAX_INDEX)
    return;

  PString str = codecList->GetString(selection);
  PINDEX left = str.FindLast('[');
  PINDEX right = str.FindLast(']');
  if (left != P_MAX_INDEX && right != P_MAX_INDEX) {
    str.Splice(psprintf("%u", box.GetValue()), left+1, right-left-1);
    codecList->SetString(str, selection);
    codecList->SetSelection(selection);
  }
}


void AudioCodecOptionsDlg::SignalDeadbandChange(PHorizontalScrollBar &, INT)
{
  signalDeadbandMS->SetName(psprintf("%ums", (signalDeadband+7)/8));
}


void AudioCodecOptionsDlg::SilenceDeadbandChange(PHorizontalScrollBar &, INT)
{
  silenceDeadbandMS->SetName(psprintf("%ums", (silenceDeadband+7)/8));
}


void MainWindow::VideoOptionsCmd()
{
  PConfig config;
  VideoOptionsDlg dlg(this);

  PINDEX i;
  PStringArray devices = PVideoInputDevice().GetDeviceNames();
  for (i = 0; i < devices.GetSize(); i++)
    dlg.videoDeviceBox->AddString(devices[i]);
  dlg.videoDeviceBox->AddString("Frame test N.0 - Moving line");
  dlg.videoDeviceBox->AddString("Frame test N.1 - Moving line");
  dlg.videoDeviceBox->AddString("Frame test N.2 - Moving boxes");
  dlg.videoDeviceBox->AddString("Frame test N.3 - Still colors");
  dlg.videoDevice = dlg.videoDeviceBox->FindString(config.GetString(VideoDeviceConfigKey));
  if (dlg.videoDevice == P_MAX_INDEX)
    dlg.videoDevice = 0;

  dlg.rxqcif = config.GetBoolean(H261QCIFConfigKey, TRUE);
  dlg.rxcif = config.GetBoolean(H261CIFConfigKey, TRUE);
  dlg.rxauto = config.GetBoolean(AutoReceiveVideoConfigKey, TRUE);
  dlg.txsize = config.GetInteger(VideoSizeConfigKey, 1);
  dlg.source = config.GetInteger(VideoSourceConfigKey, -1)+1;
  dlg.format = config.GetInteger(VideoFormatConfigKey, 1);
  dlg.quality = config.GetInteger(VideoQualityConfigKey, 15);
  dlg.localVideo = config.GetBoolean(VideoLocalConfigKey, FALSE);
  dlg.flipLocal = config.GetBoolean(VideoFlipLocalConfigKey, FALSE);
  dlg.flipRemote = config.GetBoolean(VideoFlipRemoteConfigKey, FALSE);
  
  if (!dlg.RunModal())
    return;

  config.SetString(VideoDeviceConfigKey, dlg.videoDeviceBox->GetString(dlg.videoDevice));
  config.SetBoolean(H261QCIFConfigKey, dlg.rxqcif);
  config.SetBoolean(H261CIFConfigKey, dlg.rxcif);
  config.SetBoolean(AutoReceiveVideoConfigKey, dlg.rxauto);
  config.SetInteger(VideoSizeConfigKey, dlg.txsize);
  config.SetInteger(VideoSourceConfigKey, dlg.source-1);
  config.SetInteger(VideoFormatConfigKey, dlg.format);
  config.SetInteger(VideoQualityConfigKey, dlg.quality);
  config.SetBoolean(VideoLocalConfigKey, dlg.localVideo);
  config.SetBoolean(VideoFlipLocalConfigKey, dlg.flipLocal);
  config.SetBoolean(VideoFlipRemoteConfigKey, dlg.flipRemote);
  endpoint.LoadCapabilities(config);
}


#if PTRACING

void MainWindow::TraceOptionsCmd()
{
  TraceOptionsDlg dlg(this);
  PConfig config;

  dlg.traceFlag = myTraceFile != NULL; // tracing has been enabled
  if (myTraceFile != NULL)
    dlg.traceFile = myTraceFile->GetName();
  else
    dlg.traceFile = PFilePath("trace.txt");
  dlg.traceLevel = PTrace::GetLevel();
  dlg.traceBlocks = (PTrace::GetOptions()&PTrace::Blocks) != 0;
  dlg.dateAndTime = (PTrace::GetOptions()&PTrace::DateAndTime) != 0;
  dlg.timestamp = (PTrace::GetOptions()&PTrace::Timestamp) != 0;
  dlg.threads = (PTrace::GetOptions()&PTrace::Thread) != 0;
  dlg.threadAddr = (PTrace::GetOptions()&PTrace::ThreadAddress) != 0;
  dlg.levelDisplay = (PTrace::GetOptions()&PTrace::TraceLevel) != 0;
  dlg.fileAndLine = (PTrace::GetOptions()&PTrace::FileAndLine) != 0;

  dlg.TraceSet(*(PCheckBox *)NULL, 0);

  if (!dlg.RunModal())
    return;

  if (dlg.traceFlag)
    config.SetString(TraceFileConfigKey, dlg.traceFile);
  else
    config.SetString(TraceFileConfigKey, "");

  config.SetInteger(TraceLevelConfigKey, dlg.traceLevel);
  config.SetBoolean(TraceBlockConfigKey, dlg.traceBlocks);
  config.SetBoolean(TraceDateTimeConfigKey, dlg.dateAndTime);
  config.SetBoolean(TraceTimestampConfigKey, dlg.timestamp);
  config.SetBoolean(TraceThreadsConfigKey, dlg.threads);
  config.SetBoolean(TraceThreadAddresssConfigKey, dlg.threadAddr);
  config.SetBoolean(TraceLevelDisplayConfigKey, dlg.levelDisplay);
  config.SetBoolean(TraceFileLineConfigKey, dlg.fileAndLine);
  OpenTraceFile(config);
}


void TraceOptionsDlg::TraceSet(PCheckBox &, INT)
{
  traceLevelText->Enable(traceFlag);
  traceLevelBox->Enable(traceFlag);
  traceOutText->Enable(traceFlag);
  traceOutBox->Enable(traceFlag);
  traceBlocksBox->Enable(traceFlag);
  dateAndTimeBox->Enable(traceFlag);
  timestampBox->Enable(traceFlag);
  threadsBox->Enable(traceFlag);
  threadAddrBox->Enable(traceFlag);
  levelDisplayBox->Enable(traceFlag);
  fileAndLineBox->Enable(traceFlag);
}


static void SetTraceOption(PConfig & config, const char * key, unsigned option)
{
  if (config.GetBoolean(key))
    PTrace::SetOptions(option);
  else
    PTrace::ClearOptions(option);
}


BOOL MainWindow::OpenTraceFile(PConfig & config)
{
  PTrace::SetLevel(config.GetInteger(TraceLevelConfigKey, 1));

  SetTraceOption(config, TraceBlockConfigKey, PTrace::Blocks);
  SetTraceOption(config, TraceDateTimeConfigKey, PTrace::DateAndTime);
  SetTraceOption(config, TraceTimestampConfigKey, PTrace::Timestamp);
  SetTraceOption(config, TraceThreadsConfigKey, PTrace::Thread);
  SetTraceOption(config, TraceThreadAddresssConfigKey, PTrace::ThreadAddress);
  SetTraceOption(config, TraceLevelDisplayConfigKey, PTrace::TraceLevel);
  SetTraceOption(config, TraceFileLineConfigKey, PTrace::FileAndLine);

  PString traceFileName = config.GetString(TraceFileConfigKey);

  // If already have a trace file, see if need to close it
  if (myTraceFile != NULL) {
    // If no change, do nothing more
    if (myTraceFile->GetFilePath() == PFilePath(traceFileName))
      return TRUE;

    PTrace::SetStream(NULL);
    delete myTraceFile;
    myTraceFile = NULL;
  }

  // Have stopped
  if (traceFileName.IsEmpty())
    return TRUE;

  PTextFile * traceFile = new PTextFile;
  if (traceFile->Open(traceFileName, PFile::WriteOnly)) {
    myTraceFile = traceFile;
    PTrace::SetStream(traceFile);
    PProcess & process = PProcess::Current();
    PTRACE(0, process.GetName()
           << " Version " << process.GetVersion(TRUE)
           << " by " << process.GetManufacturer()
           << " on " << process.GetOSClass() << ' ' << process.GetOSName()
           << " (" << process.GetOSVersion() << '-' << process.GetOSHardware() << ')');
    return TRUE;
  }

  PSimpleDialog::Error(this, IDS_TRACE_FAIL, (const char *)traceFile->GetName());
  delete traceFile;
  return FALSE;
}


#endif


void StatisticsDlg::OnCancel()
{
  Hide();
}


BOOL MainWindow::SpeedDial(const PString & key)
{
  PConfig config(SpeedDialConfigSection);

  PString str = config.GetString(key);
  if (str.IsEmpty())
    return FALSE;

  PINDEX tab = str.Find('\t');
  if (tab != P_MAX_INDEX)
    return MakeCall(str.Left(tab), str.Mid(tab+1));
  else
    return MakeCall(str, "");
}


BOOL MainWindow::MakeCall(const PString & address, const PString & gateway)
{
	PString fullAddress;
/*	PString strNull("000");
  if(!address.GetLength())
	  fullAddress = strNull;
  else*/
  fullAddress = address;
	  
  if (!gateway)
    fullAddress += '@' + gateway;

  OutputStatus(IDS_CALLING, (const char *)fullAddress);

  if (gateway *= InternalGatewayName) {
    if (!endpoint.lid->IsLinePresent(endpoint.pstnLine))
      return FALSE;

    SetCallMode(ActiveLineCallMode);
    endpoint.lid->SetLineToLineDirect(endpoint.potsLine, endpoint.pstnLine, TRUE);
    switch (endpoint.lid->DialOut(endpoint.pstnLine, address)) {
      case OpalLineInterfaceDevice::DialTone :
        OutputStatus(IDS_NODIALTONE);
        break;
      case OpalLineInterfaceDevice::BusyTone :
        OutputStatus(IDS_LINEBUSY, (const char *)address);
        break;
      case OpalLineInterfaceDevice::RingTone :
        OutputStatus(IDS_LINECALLDIALLED);
        break;
      default :
        OutputStatus(IDS_LINECALLFAILED);
        break;
    }
    return TRUE;
  }

  SetCallMode(MakingCallMode);
  endpoint.lid->PlayTone(endpoint.potsLine, OpalLineInterfaceDevice::RingTone);
  if (endpoint.MakeCall(fullAddress, currentCallToken))
    return TRUE;

  OutputStatus(IDS_INVALIDADDRESS, (const char *)fullAddress);

  SetCallMode(IdleCallMode);
  return FALSE;
}


BOOL MainWindow::IntrudeCall(const PString & address, const PString & gateway, unsigned capabilityLevel)
{
  PString fullAddress = address;
  if (!gateway)
    fullAddress += '@' + gateway;

  OutputStatus(IDS_INTRUDING, (const char *)fullAddress);

  if (gateway *= InternalGatewayName) {
    if (!endpoint.lid->IsLinePresent(endpoint.pstnLine))
      return FALSE;

    SetCallMode(ActiveLineCallMode);
    endpoint.lid->SetLineToLineDirect(endpoint.potsLine, endpoint.pstnLine, TRUE);
    switch (endpoint.lid->DialOut(endpoint.pstnLine, address)) {
      case OpalLineInterfaceDevice::DialTone :
        OutputStatus(IDS_NODIALTONE);
        break;
      case OpalLineInterfaceDevice::BusyTone :
        OutputStatus(IDS_LINEBUSY, (const char *)address);
        break;
      case OpalLineInterfaceDevice::RingTone :
        OutputStatus(IDS_LINECALLDIALLED);
        break;
      default :
        OutputStatus(IDS_LINECALLFAILED);
        break;
    }
    return TRUE;
  }

  SetCallMode(MakingCallMode);
  endpoint.lid->PlayTone(endpoint.potsLine, OpalLineInterfaceDevice::RingTone);
  if (endpoint.IntrudeCall(fullAddress, currentCallToken, capabilityLevel))
    return TRUE;

  OutputStatus(IDS_INVALIDADDRESS, (const char *)fullAddress);

  SetCallMode(IdleCallMode);
  return FALSE;
}


void MainWindow::AnswerCall(BOOL accept)
{
  if (currentCallMode != IncomingCallWait)
    return;

  endpoint.lid->RingLine(endpoint.potsLine, 0);
  ringSoundTimer.Stop();
  noAnswerTimer.Stop();

  H323Connection * connection = endpoint.FindConnectionWithLock(currentCallToken);
  if (connection == NULL)
    SetCallMode(IdleCallMode);
  else {
    connection->AnsweringCall(accept ? H323Connection::AnswerCallNow
                                     : H323Connection::AnswerCallDenied);
    connection->Unlock();
  }
}


BOOL MainWindow::OnAnswerCall(const H

⌨️ 快捷键说明

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