📄 sipxtapi.cpp
字号:
pInst->pCodecFactory = new SdpCodecFactory() ; // Instantiate the call processing subsystem UtlString localAddress; UtlString utlIdentity(szIdentity); if (!utlIdentity.contains("@")) { OsSocket::getHostIp(&localAddress); char *szBuf = (char*) calloc(64 + utlIdentity.length(), 1) ; sprintf(szBuf, "sip:%s@%s:%d", szIdentity, localAddress.data(), pInst->pSipUserAgent->getUdpPort()) ; localAddress = szBuf ; free(szBuf) ; } else { localAddress = utlIdentity; } // get the rtp end port int rtpPortEnd = rtpPortStart + (2*maxConnections); pInst->pCallManager = new CallManager(FALSE, pInst->pLineManager, TRUE, // early media in 180 ringing pInst->pCodecFactory, rtpPortStart, // rtp start rtpPortEnd, // rtp end localAddress.data(), localAddress.data(), pInst->pSipUserAgent, 0, // sipSessionReinviteTimer NULL, // mgcpStackTask NULL, // defaultCallExtension Connection::RING, // availableBehavior NULL, // unconditionalForwardUrl -1, // forwardOnNoAnswerSeconds NULL, // forwardOnNoAnswerUrl Connection::BUSY, // busyBehavior NULL, // sipForwardOnBusyUrl NULL, // speedNums CallManager::SIP_CALL, // phonesetOutgoingCallProtocol 4, // numDialPlanDigits CallManager::NEAR_END_HOLD, // holdType 5000, // offeringDelay "", CP_MAXIMUM_RINGING_EXPIRE_SECONDS, QOS_LAYER3_LOW_DELAY_IP_TOS, 10, sipXmediaFactoryFactory(NULL)); // Start up the call processing system pInst->pCallManager->setOutboundLine(localAddress) ; pInst->pCallManager->start(); CpMediaInterfaceFactoryImpl* pInterface = pInst->pCallManager->getMediaInterfaceFactory()->getFactoryImplementation() ; sipxConfigSetAudioCodecPreferences(pInst, AUDIO_CODEC_BW_NORMAL); sipxConfigSetVideoCodecPreferences(pInst, VIDEO_CODEC_BW_HIGH);#if defined(_WIN32) || defined(_VXWORKS) initAudioDevices(pInst) ;#else // TBD pInst->inputAudioDevices[0] = "/dev/dsp"; pInst->outputAudioDevices[0] = "/dev/dsp"; for (int i = 1; i < MAX_AUDIO_DEVICES; i++) { pInst->inputAudioDevices[i] = NULL; pInst->outputAudioDevices[i] = NULL; }#endif *phInst = pInst ; gpSessionList->insert(new UtlVoidPtr(pInst)) ; sipxIncSessionCount();#ifdef _WIN32#ifndef VOICE_ENGINE Sleep(500) ; // Need to wait for UA and MP to startup // TODO: Need to synchronize startup#endif#endif // create the message observer pInst->pMessageObserver = new SipXMessageObserver(pInst); pInst->pMessageObserver->start(); pInst->pSipUserAgent->addMessageObserver(*(pInst->pMessageObserver->getMessageQueue()), SIP_INFO_METHOD, 1, 0, 1, 0, 0, 0, (void*)pInst); rc = SIPX_RESULT_SUCCESS ; } return rc ;}SIPXTAPI_API SIPX_RESULT sipxUnInitialize(SIPX_INST hInst){ SIPX_RESULT rc = SIPX_RESULT_INVALID_ARGS ; OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxUnInitialize hInst=%p", hInst); SIPX_INSTANCE_DATA* pInst = (SIPX_INSTANCE_DATA*) hInst ; if (pInst) { // Verify that all calls are torn down and that no lines // are present. pInst->pLock->acquire() ; int nCalls = pInst->nCalls ; int nConferences = pInst->nConferences ; int nLines = pInst->nLines ; pInst->pLock->release() ; if ( (nCalls == 0) && (nConferences == 0) && (nLines == 0) ) { // Destroy the timer task to flush timers OsTimerTask::destroyTimerTask() ; // get rid of pointer to the line manager in the refresh manager pInst->pRefreshManager->setLineMgr(NULL); pInst->pLineManager->requestShutdown(); pInst->pCallManager->requestShutdown(); pInst->pRefreshManager->requestShutdown(); pInst->pSipUserAgent->requestShutdown(); pInst->pSubscribeClient->requestShutdown(); pInst->pSubscribeServer->requestShutdown(); pInst->pMessageObserver->requestShutdown(); pInst->pCodecFactory->clearCodecs(); delete pInst->pSubscribeClient ; delete pInst->pSubscribeServer ; delete pInst->pCallManager; delete pInst->pLineManager; delete pInst->pCodecFactory; delete pInst->pRefreshManager ; pInst->pCallManager = NULL; int codecIndex; // Did we previously allocate an audio codecs array and store it in our codec settings? if (pInst->audioCodecSetting.bInitialized) { // Free up the previuosly allocated codecs and the array for (codecIndex = 0; codecIndex < pInst->audioCodecSetting.numCodecs; codecIndex++) { if (pInst->audioCodecSetting.sdpCodecArray[codecIndex]) { delete pInst->audioCodecSetting.sdpCodecArray[codecIndex]; pInst->audioCodecSetting.sdpCodecArray[codecIndex] = NULL; } } delete[] pInst->audioCodecSetting.sdpCodecArray; pInst->audioCodecSetting.sdpCodecArray = NULL; pInst->audioCodecSetting.bInitialized = false; } // Did we previously allocate a video codecs array and store it in our codec settings? if (pInst->videoCodecSetting.bInitialized) { // Free up the previuosly allocated codecs and the array for (codecIndex = 0; codecIndex < pInst->videoCodecSetting.numCodecs; codecIndex++) { if (pInst->videoCodecSetting.sdpCodecArray[codecIndex]) { delete pInst->videoCodecSetting.sdpCodecArray[codecIndex]; pInst->videoCodecSetting.sdpCodecArray[codecIndex] = NULL; } } delete[] pInst->videoCodecSetting.sdpCodecArray; pInst->videoCodecSetting.sdpCodecArray = NULL; pInst->videoCodecSetting.bInitialized = false; } for (int i=0; i<MAX_AUDIO_DEVICES; i++) { if (pInst->inputAudioDevices[i]) { free(pInst->inputAudioDevices[i]) ; pInst->inputAudioDevices[i] = NULL ; } if (pInst->outputAudioDevices[i]) { free(pInst->outputAudioDevices[i]) ; pInst->outputAudioDevices[i] = NULL ; } } sipxDecSessionCount(); if (sipxGetSessionCount() == 0) { OsStunAgentTask::releaseInstance(); } UtlVoidPtr key(pInst) ; gpSessionList->destroy(&key) ; if (pInst->pStunNotification != NULL) { delete pInst->pStunNotification ; pInst->pStunNotification = NULL ; } if (pInst->pMessageObserver) { delete pInst->pMessageObserver ; pInst->pMessageObserver = NULL ; } delete pInst->pLock ; delete pInst; pInst = NULL; // Destroy the timer task once more -- some of the destructors (SipUserAgent) // mistakenly re-creates them when terminating. OsTimerTask::destroyTimerTask() ; sipxDestroyMediaFactoryFactory() ; rc = SIPX_RESULT_SUCCESS ; } else { OsSysLog::add(FAC_SIPXTAPI, PRI_ERR, "Unable to shutdown busy SIPX_INST (0x%08X) nCalls=%d, nLines=%d, nConferences=%d", hInst, nCalls, nLines, nConferences) ; rc = SIPX_RESULT_BUSY ; } } return rc ;}/**************************************************************************** * Call Related Functions ***************************************************************************/SIPXTAPI_API SIPX_RESULT sipxCallAccept(const SIPX_CALL hCall, SIPX_VIDEO_DISPLAY* const pDisplay){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallAccept hCall=%d display=%p", hCall, pDisplay); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress ; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, NULL)) { assert(remoteAddress.length()) ; if (remoteAddress.length()) { // set the display object { SIPX_CALL_DATA *pCallData = sipxCallLookup(hCall, SIPX_LOCK_WRITE); if (pCallData) { if (pDisplay) { pCallData->display = *pDisplay; } sipxCallReleaseLock(pCallData, SIPX_LOCK_WRITE) ; } } // Only take focus if something doesn't already have it. if (!sipxIsCallInFocus()) { SIPX_CALL_DATA *pCallData = sipxCallLookup(hCall, SIPX_LOCK_WRITE) ; if (pCallData) { pCallData->bInFocus = true ; sipxCallReleaseLock(pCallData, SIPX_LOCK_WRITE) ; } pInst->pCallManager->unholdLocalTerminalConnection(callId.data()) ; } pInst->pCallManager->acceptConnection(callId.data(), remoteAddress.data(), AUTO, (void*)pDisplay) ; } sr = SIPX_RESULT_SUCCESS ; } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallReject(const SIPX_CALL hCall, const int errorCode, const char* szErrorText){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallReject hCall=%d", hCall); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress ; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, NULL)) { assert(remoteAddress.length()) ; if (remoteAddress.length()) { pInst->pCallManager->rejectConnection(callId.data(), remoteAddress.data()) ; } sr = SIPX_RESULT_SUCCESS ; } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallRedirect(const SIPX_CALL hCall, const char* szForwardURL){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallRedirect hCall=%d forwardURL=%s", hCall, szForwardURL); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress ; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, NULL)) { assert(remoteAddress.length()) ; if (remoteAddress.length() && szForwardURL) { pInst->pCallManager->redirectConnection(callId.data(), remoteAddress.data(), szForwardURL) ; } sr = SIPX_RESULT_SUCCESS ; } return sr ;}SIPXTAPI_API SIPX_RESULT sipxCallAnswer(const SIPX_CALL hCall){ OsSysLog::add(FAC_SIPXTAPI, PRI_INFO, "sipxCallAnswer hCall=%d", hCall); SIPX_RESULT sr = SIPX_RESULT_FAILURE ; SIPX_INSTANCE_DATA* pInst ; UtlString callId ; UtlString remoteAddress ; if (sipxCallGetCommonData(hCall, &pInst, &callId, &remoteAddress, NULL)) { assert(remoteAddress.length()) ; if (remoteAddress.length()) { SIPX_VIDEO_DISPLAY display; // Only take focus if something doesn't already have it. if (!sipxIsCallInFocus()) { SIPX_CALL_DATA *pCallData = sipxCallLookup(hCall, SIPX_LOCK_WRITE) ; if (pCallData) { pCallData->bInFocus = true ; sipxCallReleaseLock(pCallData, SIPX_LOCK_WRITE) ; } pInst->pCallManager->unholdLocalTerminalConnection(callId.data()) ; } SIPX_CALL_DATA *pCallData = sipxCallLookup(hCall, SIPX_LOCK_WRITE); if (pCallData) { display = pCallData->display; sipxCallReleaseLock(pCallData, SIPX_LOCK_WRITE) ; } if (display.handle) { pInst->pCallManager->answerTerminalConnection(callId.data(), remoteAddress.data(), "unused", &display) ; } else { pInst->pCallManager->answerTerminalConnection(callId.data(), remoteAddress.data(), "unused") ; } } sr = SIPX_RESULT_SUCCESS ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -