Beispiel #1
0
void CMobileOpalDlg::OnTimer(UINT_PTR nIDEvent)
{
  if (nIDEvent == TimerID && m_opal != NULL) {
    OpalMessage * message = OpalGetMessage(m_opal, 0);
    if (message != NULL) {
      switch (message->m_type) {
        case OpalIndRegistration :
          if (message->m_param.m_registrationStatus.m_error == NULL ||
              message->m_param.m_registrationStatus.m_error[0] == '\0')
            SetStatusText(IDS_REGISTERED);
          else {
            CString text(message->m_param.m_registrationStatus.m_error);
            m_ctrlStatus.SetWindowText(text);
          }
          break;

        case OpalIndIncomingCall :
          SetStatusText(IDS_INCOMING_CALL);
          SetCallButton(true, IDS_ANSWER);
          m_ctrlAddress.EnableWindow(false);
          ShowWindow(true);
          BringWindowToTop();
          break;

        case OpalIndAlerting :
          SetStatusText(IDS_RINGING);
          break;

        case OpalIndEstablished :
          SetStatusText(IDS_ESTABLISHED);
          break;

        case OpalIndUserInput :
          if (message->m_param.m_userInput.m_userInput != NULL) {
            CString text(message->m_param.m_callCleared.m_reason);
            m_ctrlStatus.SetWindowText(text);
          }
          break;

        case OpalIndCallCleared :
          SetCallButton(true, IDS_CALL);
          m_ctrlAddress.EnableWindow(true);
          m_currentCallToken.Empty();

          if (message->m_param.m_callCleared.m_reason == NULL)
            SetStatusText(IDS_READY);
          else {
            CString text(message->m_param.m_callCleared.m_reason);
            m_ctrlStatus.SetWindowText(text);
          }
      }
      OpalFreeMessage(message);
    }
  }

  CDialog::OnTimer(nIDEvent);
}
Beispiel #2
0
void CMobileOpalDlg::OnTimer(UINT_PTR nIDEvent)
{
  if (m_opal == NULL)
    InitialiseOPAL();

  if (nIDEvent == TimerID && m_opal != NULL) {
    OpalMessage * message = OpalGetMessage(m_opal, 0);
    if (message != NULL) {
      HandleMessage(*message);
      OpalFreeMessage(message);
    }
  }

  CDialog::OnTimer(nIDEvent);
}
Beispiel #3
0
void CMobileOpalDlg::InitialiseOPAL()
{
  /////////////////////////////////////////////////////////////////////
  // Start up and initialise OPAL

  if (m_opal == NULL) {
    m_opal = OpalInitialise(&m_opalVersion, "pc h323 sip " TRACE_OPTIONS);
    if (m_opal == NULL) {
      ErrorBox(IDS_INIT_FAIL);
      EndDialog(IDCANCEL);
      return;
    }
  }

  OpalMessage command;
  OpalMessage * response;

  // SIP registrar un-regisration
  CStringA strAOR = GetOptionStringA(RegistrarAorKey);
  CStringA strHost = GetOptionStringA(RegistrarHostKey);
  if (!m_currentAOR.IsEmpty() && (m_currentAOR != strAOR || m_currentHost != strHost)) {
    // Registration changed, so unregister the previous name
    memset(&command, 0, sizeof(command));
    command.m_type = OpalCmdRegistration;
    command.m_param.m_registrationInfo.m_protocol = "sip";
    command.m_param.m_registrationInfo.m_identifier = m_currentAOR;
    command.m_param.m_registrationInfo.m_hostName = m_currentHost;
    response = OpalSendMessage(m_opal, &command);
    if (response != NULL && response->m_type == OpalCmdRegistration) {
      OpalFreeMessage(response);

      UpdateWindow();

      // Wait for unregister to complete.
      while ((response = OpalGetMessage(m_opal, 30000)) != NULL) {
        HandleMessage(*response);
        if (response->m_type == OpalIndRegistration && response->m_param.m_registrationStatus.m_status == OpalRegisterRemoved)
          break;
      }
    }
    OpalFreeMessage(response);
    m_currentAOR.Empty();
    m_currentHost.Empty();
  }

  /* Calucalte some configuration strings, determine position of a QCIF
     window so is in bottom left corner, and a preview window for camera
     in lower right corner, scaled to fit remaining space. */
  static const unsigned videoWidth = 176;
  static const unsigned videoHeight = 144;
  CRect box;
  GetClientRect(&box);

  CRect commandBox;
  m_dlgCommandBar.GetWindowRect(&commandBox);
  box.bottom -= commandBox.Height();

  CStringA strVideoOutputDevice;
  strVideoOutputDevice.Format("MSWIN STYLE=0x%08X PARENT=0x%08X X=%i Y=%i WIDTH=%u HEIGHT=%u",
                              WS_CHILD|WS_BORDER, GetSafeHwnd(),
                              0, box.Height()-videoHeight,
                              videoWidth, videoHeight);

  unsigned previewWidth = box.Width() - videoWidth - 2;
  unsigned previewHeight = previewWidth*videoHeight/videoWidth;
  CStringA strVideoPreviewDevice;
  strVideoPreviewDevice.Format("MSWIN STYLE=0x%08X PARENT=0x%08X X=%i Y=%i WIDTH=%u HEIGHT=%u",
                               WS_CHILD|WS_BORDER, GetSafeHwnd(),
                               videoWidth+2, box.Height()-previewHeight,
                               previewWidth, previewHeight);

  CStringA strMediaOptions;
  strMediaOptions.Format("Video:Max Bit Rate=128000\n"
                         "Video:Target Bit Rate=128000\n"
                         "Video:Frame Time=9000\n" // 10 frames/second
                         "Video:Frame Width=%u\n"
                         "Video:Frame Height=%u\n"
                         "Video:Max Rx Frame Width=%u\n"
                         "Video:Max Rx Frame Height=%u\n"
                         "H.264:Level=1b\n",
                          videoWidth, videoHeight,
                          videoWidth, videoHeight);

  // General options
  memset(&command, 0, sizeof(command));
  command.m_type = OpalCmdSetGeneralParameters;

  CStringA strStunServer = GetOptionStringA(STUNServerKey);
  command.m_param.m_general.m_stunServer = strStunServer;
  command.m_param.m_general.m_audioPlayerDevice = "Audio Output";
  command.m_param.m_general.m_audioRecordDevice = "Audio Input";
  command.m_param.m_general.m_videoInputDevice = "CAM1:";
  command.m_param.m_general.m_videoOutputDevice = strVideoOutputDevice;
  command.m_param.m_general.m_videoPreviewDevice = strVideoPreviewDevice;
  command.m_param.m_general.m_mediaMask = "RFC4175*\nMPEG4";
  command.m_param.m_general.m_mediaOptions = strMediaOptions;
  command.m_param.m_general.m_autoTxMedia = GetOptionInt(AutoStartTxVideoKey, true) != 0 ? "audio video" : "audio";
  command.m_param.m_general.m_rtpMaxPayloadSize = 1400;

  if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError)
    ErrorBox(IDS_CONFIGURATION_FAIL, response);
  OpalFreeMessage(response);

  // Options across all protocols
  memset(&command, 0, sizeof(command));
  command.m_type = OpalCmdSetProtocolParameters;

  CStringA strUserName = GetOptionStringA(UserNameKey);
  command.m_param.m_protocol.m_userName = strUserName;

  CStringA strDisplayName = GetOptionStringA(UserNameKey);
  command.m_param.m_protocol.m_displayName = strDisplayName;

  CStringA interfaceAddress = GetOptionStringA(InterfaceAddressKey, L"*");
  command.m_param.m_protocol.m_interfaceAddresses = interfaceAddress;

  if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError)
    ErrorBox(IDS_LISTEN_FAIL, response);
  OpalFreeMessage(response);

  // H.323 gatekeeper registration
  memset(&command, 0, sizeof(command));
  command.m_type = OpalCmdRegistration;

  UINT gkType = GetOptionInt(GkTypeKey);
  if (gkType > 0) {
    command.m_param.m_registrationInfo.m_protocol = "h323";

    CStringA strAliasName = GetOptionStringA(GkAliasKey);
    command.m_param.m_registrationInfo.m_identifier = strAliasName;

    CStringA strGkId = GetOptionStringA(GkIdKey);
    command.m_param.m_registrationInfo.m_adminEntity = strGkId;

    CStringA strGkHost = GetOptionStringA(GkHostKey);
    command.m_param.m_registrationInfo.m_hostName = strGkHost;

    CStringA strGkAuthUser = GetOptionStringA(GkAuthUserKey);
    command.m_param.m_registrationInfo.m_authUserName = strGkAuthUser;

    CStringA strGkPassword = GetOptionStringA(GkPasswordKey);
    command.m_param.m_registrationInfo.m_password = strGkPassword;

    SetStatusText(IDS_REGISTERING);
    if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError)
      ErrorBox(IDS_REGISTRATION_FAIL, response);
    OpalFreeMessage(response);
  }

  // SIP registrar registration
  if (strAOR.IsEmpty())
    SetStatusText(IDS_READY);
  else {
    memset(&command, 0, sizeof(command));
    command.m_type = OpalCmdRegistration;

    command.m_param.m_registrationInfo.m_protocol = "sip";

    command.m_param.m_registrationInfo.m_identifier = strAOR;
    command.m_param.m_registrationInfo.m_hostName = strHost;

    CStringA strAuthUser = GetOptionStringA(RegistrarUserKey);
    command.m_param.m_registrationInfo.m_authUserName = strAuthUser;

    CStringA strPassword = GetOptionStringA(RegistrarPassKey);
    command.m_param.m_registrationInfo.m_password = strPassword;

    CStringA strRealm = GetOptionStringA(RegistrarRealmKey);
    command.m_param.m_registrationInfo.m_adminEntity = strRealm;

    command.m_param.m_registrationInfo.m_timeToLive = 300;

    SetStatusText(IDS_REGISTERING);
    if ((response = OpalSendMessage(m_opal, &command)) != NULL && response->m_type != OpalIndCommandError) {
      m_currentAOR = strAOR;
      m_currentHost = strHost;
    }
    else {
      ErrorBox(IDS_REGISTRATION_FAIL, response);
      SetStatusText(IDS_READY);
    }
    OpalFreeMessage(response);
  }

  PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE);
}
Beispiel #4
0
void CMobileOpalDlg::InitialiseOPAL()
{
  /////////////////////////////////////////////////////////////////////
  // Start up and initialise OPAL

  if (m_opal == NULL) {
    m_opal = OpalInitialise(&m_opalVersion, "pc h323 sip " TRACE_OPTIONS);
    if (m_opal == NULL) {
      ErrorBox(IDS_INIT_FAIL);
      EndDialog(IDCANCEL);
      return;
    }
  }

  OpalMessage command;
  OpalMessage * response;

  // SIP registrar un-regisration
  CStringA strAOR = GetOptionStringA(RegistrarAorKey);
  CStringA strHost = GetOptionStringA(RegistrarHostKey);
  if (!m_currentAOR.IsEmpty() && (m_currentAOR != strAOR || m_currentHost != strHost)) {
    // Registration changed, so unregister the previous name
    memset(&command, 0, sizeof(command));
    command.m_type = OpalCmdRegistration;
    command.m_param.m_registrationInfo.m_protocol = "sip";
    command.m_param.m_registrationInfo.m_identifier = m_currentAOR;
    command.m_param.m_registrationInfo.m_hostName = m_currentHost;
    response = OpalSendMessage(m_opal, &command);
    if (response != NULL && response->m_type == OpalCmdRegistration) {
      OpalFreeMessage(response);

      UpdateWindow();

      // Wait for unregister to complete.
      while ((response = OpalGetMessage(m_opal, 30000)) != NULL) {
        HandleMessage(*response);
        if (response->m_type == OpalIndRegistration && response->m_param.m_registrationStatus.m_status == OpalRegisterRemoved)
          break;
      }
    }
    OpalFreeMessage(response);
    m_currentAOR.Empty();
    m_currentHost.Empty();
  }

  // General options
  memset(&command, 0, sizeof(command));
  command.m_type = OpalCmdSetGeneralParameters;

  CStringA strStunServer = GetOptionStringA(STUNServerKey);
  command.m_param.m_general.m_stunServer = strStunServer;

  if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError)
    ErrorBox(IDS_CONFIGURATION_FAIL, response);
  OpalFreeMessage(response);

  // Options across all protocols
  memset(&command, 0, sizeof(command));
  command.m_type = OpalCmdSetProtocolParameters;

  CStringA strUserName = GetOptionStringA(UserNameKey);
  command.m_param.m_protocol.m_userName = strUserName;

  CStringA strDisplayName = GetOptionStringA(UserNameKey);
  command.m_param.m_protocol.m_displayName = strDisplayName;

  CStringA interfaceAddress = GetOptionStringA(InterfaceAddressKey, L"*");
  command.m_param.m_protocol.m_interfaceAddresses = interfaceAddress;

  if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError)
    ErrorBox(IDS_LISTEN_FAIL, response);
  OpalFreeMessage(response);

  // H.323 gatekeeper registration
  memset(&command, 0, sizeof(command));
  command.m_type = OpalCmdRegistration;

  UINT gkType = GetOptionInt(GkTypeKey);
  if (gkType > 0) {
    command.m_param.m_registrationInfo.m_protocol = "h323";

    CStringA strAliasName = GetOptionStringA(GkAliasKey);
    command.m_param.m_registrationInfo.m_identifier = strAliasName;

    CStringA strGkId = GetOptionStringA(GkIdKey);
    command.m_param.m_registrationInfo.m_adminEntity = strGkId;

    CStringA strGkHost = GetOptionStringA(GkHostKey);
    command.m_param.m_registrationInfo.m_hostName = strGkHost;

    CStringA strGkAuthUser = GetOptionStringA(GkAuthUserKey);
    command.m_param.m_registrationInfo.m_authUserName = strGkAuthUser;

    CStringA strGkPassword = GetOptionStringA(GkPasswordKey);
    command.m_param.m_registrationInfo.m_password = strGkPassword;

    SetStatusText(IDS_REGISTERING);
    if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError)
      ErrorBox(IDS_REGISTRATION_FAIL, response);
    OpalFreeMessage(response);
  }

  // SIP registrar registration
  if (strAOR.IsEmpty())
    SetStatusText(IDS_READY);
  else {
    memset(&command, 0, sizeof(command));
    command.m_type = OpalCmdRegistration;

    command.m_param.m_registrationInfo.m_protocol = "sip";

    command.m_param.m_registrationInfo.m_identifier = strAOR;
    command.m_param.m_registrationInfo.m_hostName = strHost;

    CStringA strAuthUser = GetOptionStringA(RegistrarUserKey);
    command.m_param.m_registrationInfo.m_authUserName = strAuthUser;

    CStringA strPassword = GetOptionStringA(RegistrarPassKey);
    command.m_param.m_registrationInfo.m_password = strPassword;

    CStringA strRealm = GetOptionStringA(RegistrarRealmKey);
    command.m_param.m_registrationInfo.m_adminEntity = strRealm;

    command.m_param.m_registrationInfo.m_timeToLive = 300;
    command.m_param.m_registrationInfo.m_messageWaiting = 300;

    SetStatusText(IDS_REGISTERING);
    if ((response = OpalSendMessage(m_opal, &command)) != NULL && response->m_type != OpalIndCommandError) {
      m_currentAOR = strAOR;
      m_currentHost = strHost;
    }
    else {
      ErrorBox(IDS_REGISTRATION_FAIL, response);
      SetStatusText(IDS_READY);
    }
    OpalFreeMessage(response);
  }
}