Ejemplo n.º 1
0
bool Manager::Init(PArgList &args)
{
    std::cout << __func__ << std::endl;
    // Parse various command line arguments
    args.Parse(
        "u-user:"******"c-password:"******"l-localaddress:"
        "o-opallog:"
        "p-listenport:"
        "P-protocol:"
        "R-register:"
        "x-execute:"
        "f-file:"
        "g-gatekeeper:"
        "w-gateway:"
        "h-help:"
    );


    if (args.HasOption('h')) {
        print_help();
        return false;
    }

    // enable opal logging if requested.
    if (args.HasOption('o'))
        PTrace::Initialise(5, args.GetOptionString('o'));

    if (!args.HasOption('P')) {
        std::cerr << "please define a protocol to use!" << std::endl;
        return false;
    }

    if (args.HasOption('p')) {
        TPState::Instance().SetListenPort(
            args.GetOptionString('p').AsInteger());
    }

    if (args.HasOption('l')) {
        TPState::Instance().SetLocalAddress(args.GetOptionString('l'));
    }

    string protocol = stringify(args.GetOptionString('P'));
    if (!protocol.compare("sip")) {
        cout << "initialising SIP endpoint..." << endl;
        sipep = new SIPEndPoint(*this);

        sipep->SetRetryTimeouts(10000, 30000);
        sipep->SetSendUserInputMode(OpalConnection::SendUserInputAsRFC2833);
        // AddRouteEntry("pc:.* = sip:<da>");
        // AddRouteEntry("sip:.* = pc:<db>");
        AddRouteEntry("local:.* = sip:<da>");
        AddRouteEntry("sip:.* = local:<db>");

        if (args.HasOption('u')) {
            sipep->SetDefaultLocalPartyName(args.GetOptionString('u'));
        }

        if (args.HasOption('c')) {
            SIPRegister::Params param;
            param.m_registrarAddress = args.GetOptionString('w');
            param.m_addressOfRecord = args.GetOptionString('u');
            param.m_password = args.GetOptionString('c');
            param.m_realm = args.GetOptionString('g');

            PString *aor = new PString("");
            //sipep->SetProxy(args.GetOptionString('w'));

            if (!StartListener()) {
                return false;
            }

            if (!sipep->Register(param, *aor)) {
                cout
                        << "Could not register to "
                        << param.m_registrarAddress << endl;
                return false;
            }
            else {
                cout
                        << "registered as "
                        << aor->GetPointer(aor->GetSize()) << endl;
            }
        }

        TPState::Instance().SetProtocol(TPState::SIP);

    } else if (!protocol.compare("h323")) {
        cout << "initialising H.323 endpoint..." << endl;
        h323ep = new H323EndPoint(*this);
        AddRouteEntry("pc:.*             = h323:<da>");
        AddRouteEntry("h323:.* = pc:<da>");
        if (args.HasOption('u')) {
            h323ep->SetDefaultLocalPartyName(args.GetOptionString('u'));
        }

        TPState::Instance().SetProtocol(TPState::H323);

    } else if (!protocol.compare("rtp")) {
        cout << "initialising RTP endpoint..." << endl;
        TPState::Instance().SetProtocol(TPState::RTP);

    } else {
        std::cerr << "invalid protocol" << std::endl;
        return false;
    }

    if (args.HasOption('w')) {
        std::string val = args.GetOptionString('w');
        TPState::Instance().SetGateway(val);
    }

    SetAudioJitterDelay(20, 1000);
    DisableDetectInBandDTMF(true);

    localep = new LocalEndPoint(*this);

    TPState::Instance().SetManager(this);
    return true;
}
Ejemplo n.º 2
0
BOOL CMyPhoneEndPoint::Initialise(CMyPhoneDlg *dlg, CVideoDlg *vdlg)
{
	m_dialog = dlg;
        m_vdlg = vdlg;
	isIncomingCall = FALSE;

	SetAudioJitterDelay(50, config.GetInteger(JitterConfigKey, GetMaxAudioJitterDelay()));
	SetSoundChannelBufferDepth(config.GetInteger(BufferCountConfigKey, GetSoundChannelBufferDepth()));
	
	// UserInput mode
    // Backward compatibility configuration entry
    unsigned mode = H323Connection::SendUserInputAsString;
	m_fDtmfAsString=true;
    if (config.HasKey(DtmfAsStringConfigKey)) {
		if (!config.GetBoolean(DtmfAsStringConfigKey))
		{
			mode = H323Connection::SendUserInputAsTone;
			m_fDtmfAsString=false;
		}
		config.DeleteKey(DtmfAsStringConfigKey);
	}
	mode = config.GetInteger(UserInputModeConfigKey, mode);
	SetSendUserInputMode((H323Connection::SendUserInputModes)mode);

//        SetSoundChannelPlayDriver("WindowsMutimedia");
//        SetSoundChannelRecordDriver("WindowsMultimedia");
//        SetSoundChannelPlayDriver("DirectSound");
//        SetSoundChannelRecordDriver("DirectSound");
	
        PString soundPlayStr = config.GetString(SoundPlayConfigKey, GetSoundChannelPlayDevice());
        PStringArray soundPlayer = soundPlayStr.Tokenise('\t');
        BOOL fPlayerAvailable;
        if(soundPlayer.GetSize()==1)
        {  
         SetSoundChannelPlayDriver("WindowsMutimedia");
	 fPlayerAvailable = SetSoundChannelPlayDevice(soundPlayer[0]);
         PTRACE(1, "MyPhone\tSetSoundPlayer Driver:WindowsMultimedia, Device:" << soundPlayer[0]);
        }
        else
        {
         SetSoundChannelPlayDriver(soundPlayer[0]);
	 fPlayerAvailable = SetSoundChannelPlayDevice(soundPlayer[1]);
         PTRACE(1, "MyPhone\tSetSoundPlayer Driver:" << soundPlayer[0] << ", Device:" << soundPlayer[1]);
	}

        PString soundRecordStr = config.GetString(SoundRecordConfigKey, GetSoundChannelRecordDevice());
        PStringArray soundRecorder = soundRecordStr.Tokenise('\t');
        BOOL fRecorderAvailable;
        if(soundRecorder.GetSize()==1)
        {  
         SetSoundChannelRecordDriver("WindowsMutimedia");
	 fRecorderAvailable = SetSoundChannelRecordDevice(soundRecorder[0]);
         PTRACE(1, "MyPhone\tSetSoundRecorder Driver:WindowsMultimedia, Device:" << soundRecorder[0]);
        }
        else
        {
         SetSoundChannelRecordDriver(soundRecorder[0]);
	 fRecorderAvailable = SetSoundChannelRecordDevice(soundRecorder[1]);
         PTRACE(1, "MyPhone\tSetSoundRecorder Driver:" << soundRecorder[0] << ", Device:" << soundRecorder[1]);
	}

	m_fAECOn = config.GetBoolean(AECEnableConfigKey, FALSE);
	m_fAGCOn = config.GetInteger(AGCEnableConfigKey, FALSE);
	SetAECAlgo(m_fAECOn);
	agc = m_fAGCOn;
	             
	// set some oter settings from Config
	m_fNoFastStart =  config.GetBoolean(NoFastStartConfigKey, FALSE);
    DisableFastStart(m_fNoFastStart);
	m_fStrictSingleLine =  config.GetBoolean(StrictSingleLineConfigKey, FALSE);
    StrictSingleLine(m_fStrictSingleLine);

	m_fDoH245Tunnelling = !(config.GetBoolean(NoTunnelingConfigKey, FALSE));
    DisableH245Tunneling(!m_fDoH245Tunnelling);
	m_fSilenceOn = config.GetBoolean(SilenceDetectConfigKey, TRUE);
    SetSilenceDetectionMode(m_fSilenceOn
		? H323AudioCodec::AdaptiveSilenceDetection
		: H323AudioCodec::NoSilenceDetection);
    SetLocalUserName(config.GetString(UsernameConfigKey, GetLocalUserName()));
    SetInitialBandwidth((unsigned)(config.GetReal(BandwidthConfigKey, 10000)*20));
    SetRtpIpTypeofService(config.GetInteger(IpTosConfigKey, GetRtpIpTypeofService()));
	
	SetRtpIpPorts(config.GetInteger(RTPPortBaseConfigKey, GetRtpIpPortBase()),
		config.GetInteger(RTPPortMaxConfigKey,  GetRtpIpPortBase()));
	if(config.HasKey(RouterConfigKey))
		m_router = config.GetString(RouterConfigKey, m_router.AsString());
	
	m_fAutoAnswer = config.GetBoolean(AutoAnswerConfigKey, false);
	m_fAutoMute = config.GetBoolean(AutoMuteConfigKey, false);
	
    CString alias, aliases;
	aliases = CString((const char *)config.GetString(AliasConfigKey, _T("")));
	aliases.TrimLeft();
	int iPos=0;
    while ((iPos = aliases.Find(_T("|")))>0)  // loading user aliases
	{
		alias = aliases.Left(iPos);
		aliases.Delete(0,iPos+1);
		AddAliasName((LPCTSTR)alias);
	}
	
	// The order in which capabilities are added to the capability table
	// determines which one is selected by default.
	LoadCapabilities();
	
	PString interfaces = config.GetString(ListenerInterfaceConfigKey, "*");
	if(StartListeners(interfaces.Tokenise(',')))
	{
		m_dialog->OutputStatusStr((LPCTSTR)LoadStringLang(IDS_MPREADY1STR), S_SYSTEM, (const char *)strProgName);
		return true;
	}
	else
	{
		m_dialog->OutputStatusStr((LPCTSTR)LoadStringLang(IDS_ERRLSNSTR), S_SYSTEM, (const char *)strProgName, (const char *)interfaces);
		return false;
	}
}