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

📄 sipconnection.cpp

📁 基于sipfoundy 公司开发的sipx协议API
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    else    {        // With sipX TAPI, send network error event.        SIPX_INFOSTATUS_INFO info;        memset((void*) &info, 0, sizeof(SIPX_INFOSTATUS_INFO));        info.event = INFOSTATUS_NETWORK_ERROR;        info.nSize = sizeof(SIPX_INFOSTATUS_INFO);        info.hInfo = 0;        info.szResponseText = (const char*)"INFO: network error";        TapiMgr::getInstance().fireEvent(this->mpCallManager,                                         EVENT_CATEGORY_INFO_STATUS, &info);    }    //delete pBody; // DONT delete here!  body is deleted by HttpMessage class    return bRet;}UtlBoolean SipConnection::answer(const void* pDisplay){#ifdef TEST_PRINT    OsSysLog::add(FAC_SIP, PRI_WARNING,        "Entering SipConnection::answer inviteMsg=0x%08x ", (int)inviteMsg);#endif    UtlBoolean answerOk = FALSE;    const SdpBody* sdpBody = NULL;    UtlString rtpAddress;    int receiveRtpPort;    int receiveRtcpPort;    int receiveVideoRtpPort;    int receiveVideoRtcpPort;    SdpCodecFactory supportedCodecs;    SdpSrtpParameters srtpParams;    int currentState = getState();    if( mpMediaInterface != NULL &&        inviteMsg && !inviteFromThisSide &&        (currentState == CONNECTION_ALERTING ||        currentState == CONNECTION_OFFERING ||        currentState == CONNECTION_INITIATED ||        currentState == CONNECTION_IDLE))    {        int numMatchingCodecs = 0;        SdpCodec** matchingCodecs = NULL;        mpMediaInterface->setVideoWindowDisplay(pDisplay);        // Get supported codecs        mpMediaInterface->getCapabilities(mConnectionId,            rtpAddress,            receiveRtpPort,            receiveRtcpPort,            receiveVideoRtpPort,        // VIDEO: TODO            receiveVideoRtcpPort,            supportedCodecs,            srtpParams);        getInitialSdpCodecs(inviteMsg, supportedCodecs,            numMatchingCodecs, matchingCodecs,            remoteRtpAddress, remoteRtpPort, remoteRtcpPort);        sdpBody = inviteMsg->getSdpBody();        if(numMatchingCodecs <= 0 && sdpBody)        {#ifdef TEST_PRINT            osPrintf("No matching codecs rejecting call\n");#endif            // No common codecs send INVITE error response            SipMessage sipResponse;            sipResponse.setInviteBadCodecs(inviteMsg, sipUserAgent);            send(sipResponse);            setState(CONNECTION_FAILED, CONNECTION_LOCAL, CONNECTION_CAUSE_RESOURCES_NOT_AVAILABLE);            fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_RESOURCES) ;        }        // Compatable codecs send OK response        else        {            // Respond with an OK#ifdef TEST_PRINT            osPrintf("Sending INVITE OK\n");#endif            // There was no SDP in the INVITE, so give them all of            // the codecs we support.            if(!sdpBody)            {#ifdef TEST_PRINT                osPrintf("Sending initial SDP in OK\n");#endif                // There were no codecs specified in the INVITE                // Give the full set of supported codecs                supportedCodecs.getCodecs(numMatchingCodecs, matchingCodecs);            }            // If there was SDP in the INVITE and it indicated hold:            if(sdpBody && remoteRtpPort <= 0)            {                rtpAddress = "0.0.0.0";  // hold address            }            OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipConnection::answer");             // Tweak Contact given request URI / settings            setContactType(selectCompatibleContactType(*inviteMsg)) ;            // Get Media Capabilties (need to call again because rtp            // addresses and ports may have changed)            mpMediaInterface->getCapabilities(mConnectionId,                rtpAddress,                receiveRtpPort,                receiveRtcpPort,                receiveVideoRtpPort,        // VIDEO: TODO                receiveVideoRtcpPort,                supportedCodecs,                srtpParams);            // Build response            SipMessage sipResponse;            sipResponse.setInviteOkData(inviteMsg, rtpAddress.data(),                receiveRtpPort, receiveRtcpPort,                 receiveVideoRtpPort, receiveVideoRtcpPort,                numMatchingCodecs, matchingCodecs,                 srtpParams,                mDefaultSessionReinviteTimer, mLocalContact.data());            // Send a INVITE OK response            if(!send(sipResponse))            {                OsSysLog::add(FAC_CP, PRI_DEBUG,                    "SipConnection::answer: INVITE OK failed: %s",                    remoteRtpAddress.data());                OsSysLog::add(FAC_CP, PRI_DEBUG,                    "SipConnection::answer: CONNECTION_FAILED, CONNECTION_LOCAL, CONNECTION_CAUSE_NORMAL");                //phoneSet->setStatusDisplay(displayMsg);                setState(CONNECTION_FAILED, CONNECTION_LOCAL, CONNECTION_CAUSE_NORMAL);                fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NETWORK) ;            }            else            {                setState(CONNECTION_ESTABLISHED, CONNECTION_LOCAL, CONNECTION_CAUSE_NORMAL);                if (mTerminalConnState == PtTerminalConnection::HELD)                {                    fireSipXEvent(CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE_HELD);                }                else                {                    fireSipXEvent(CALLSTATE_CONNECTED, CALLSTATE_CONNECTED_ACTIVE);                }                                answerOk = TRUE;                // Setup media channel#ifdef TEST_PRINT                osPrintf("Setting up flowgraph receive\n");#endif                // Start receiving media                SdpCodec recvCodec((SdpCodec::SdpCodecTypes) receiveCodec);                mpMediaInterface->startRtpReceive(mConnectionId,                    numMatchingCodecs, matchingCodecs, srtpParams);                // if we have a send codec chosen Start sending media                if(numMatchingCodecs > 0)                {                    mpMediaInterface->setConnectionDestination(mConnectionId,                        remoteRtpAddress.data(),                        remoteRtpPort,                        remoteRtcpPort,                        receiveVideoRtpPort,                        receiveVideoRtcpPort);                    // Set up the remote RTP sockets#ifdef TEST_PRINT                    osPrintf("RTP SENDING address: %s port: %d\n", remoteRtpAddress.data(), remoteRtpPort);#endif                    if(remoteRtpPort > 0)                    {                        //SdpCodec sndCodec((SdpCodec::SdpCodecTypes)                        //    sendCodec);                        mpMediaInterface->startRtpSend(mConnectionId,                            numMatchingCodecs, matchingCodecs, srtpParams);                        // If sipX TAPI, fire audio start event                        UtlString audioCodecName;                        UtlString videoCodecName;                        SIPX_CODEC_INFO tapiCodec;                        if (mpMediaInterface->getPrimaryCodec(mConnectionId,                                                               audioCodecName,                                                               videoCodecName,                                                              &tapiCodec.audioCodec.iPayloadType,                                                              &tapiCodec.videoCodec.iPayloadType) == OS_SUCCESS)                        {                            strncpy(tapiCodec.audioCodec.cName, audioCodecName.data(), SIPXTAPI_CODEC_NAMELEN-1);                            strncpy(tapiCodec.videoCodec.cName, videoCodecName.data(), SIPXTAPI_CODEC_NAMELEN-1);                            fireSipXEvent(CALLSTATE_AUDIO_EVENT, CALLSTATE_AUDIO_START, &tapiCodec) ;                        }                    }                }#ifdef TEST_PRINT                osPrintf("RECEIVING RTP\n");#endif                inviteMsg->getAllowField(mAllowedRemote);            }        }        // Free up the codec copies and array        for(int codecIndex = 0; codecIndex < numMatchingCodecs; codecIndex++)        {            delete matchingCodecs[codecIndex];            matchingCodecs[codecIndex] = NULL;        }        delete[] matchingCodecs;        matchingCodecs = NULL;    }#ifdef TEST_PRINT    OsSysLog::add(FAC_SIP, PRI_WARNING,        "Leaving SipConnection::answer inviteMsg=0x%08x ", (int)inviteMsg);#endif    return(answerOk);}UtlBoolean SipConnection::accept(int ringingTimeOutSeconds){    UtlBoolean ringingSent = FALSE;    int cause = 0;#ifdef TEST_PRINT    osPrintf("SipConnection::accept ringingTimeOutSeconds=%d\n", ringingTimeOutSeconds);#endif    if(mpMediaInterface != NULL && inviteMsg &&         !inviteFromThisSide && getState(cause) == CONNECTION_OFFERING)    {        UtlString rtpAddress;        int receiveRtpPort;        int receiveRtcpPort;        int receiveVideoRtpPort;        int receiveVideoRtcpPort;        //UtlBoolean receiveCodecSet;        //UtlBoolean sendCodecSet;        int numMatchingCodecs = 0;        SdpCodec** matchingCodecs = NULL;        SdpCodecFactory supportedCodecs;        UtlString replaceCallId;        UtlString replaceToTag;        UtlString replaceFromTag;        SdpSrtpParameters srtpParams;        // Make sure that this isn't part of a transfer.  If we find a        // REPLACES header, then we shouldn't accept the call, but rather        // we should return a 481 response.        if (inviteMsg->getReplacesData(replaceCallId, replaceToTag, replaceFromTag))        {            SipMessage badTransaction;            badTransaction.setBadTransactionData(inviteMsg);            send(badTransaction);#ifdef TEST_PRINT            osPrintf("SipConnection::accept - CONNECTION_FAILED, cause BUSY : 754\n");#endif            setState(CONNECTION_FAILED, CONNECTION_REMOTE, CONNECTION_CAUSE_BUSY);            fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_UNKNOWN) ;        }        else        {            mpMediaInterface->getCapabilities(mConnectionId,                rtpAddress,                receiveRtpPort,                receiveRtcpPort,                receiveVideoRtpPort,    // VIDEO: TODO                receiveVideoRtcpPort,                supportedCodecs,                srtpParams);            // Get the codecs if SDP is provided            getInitialSdpCodecs(inviteMsg,                supportedCodecs,                numMatchingCodecs, matchingCodecs,                remoteRtpAddress, remoteRtpPort, remoteRtcpPort);            // Try to setup for early receipt of media.            if(numMatchingCodecs > 0)            {                SdpCodec recvCodec((SdpCodec::SdpCodecTypes) receiveCodec);                mpMediaInterface->startRtpReceive(mConnectionId,                        numMatchingCodecs, matchingCodecs, srtpParams);            }            ringingSent = TRUE;            proceedToRinging(inviteMsg, sipUserAgent, -1, mLineAvailableBehavior);            // Keep track of the fact that this is a transfer            if(cause != CONNECTION_CAUSE_TRANSFER)            {                cause = CONNECTION_CAUSE_NORMAL;            }            setState(CONNECTION_ALERTING, CONNECTION_LOCAL, cause);            fireSipXEvent(CALLSTATE_ALERTING, CALLSTATE_ALERTING_NORMAL) ;            // If forward on no answer is enabled set the timer            if(ringingTimeOutSeconds > 0 )            {                // Set a timer to post a message to this call                // to timeout the ringing and forward                setRingingTimer(ringingTimeOutSeconds);            }            // Free up the codec copies and array            for(int codecIndex = 0; codecIndex < numMatchingCodecs; codecIndex++)            {               if (NULL == matchingCodecs[codecIndex])               {                   osPrintf("Null pointer matchingCodecs[%d]\n", codecIndex);                }               else               {                  delete matchingCodecs[codecIndex];                  matchingCodecs[codecIndex] = NULL;               }            }            if(matchingCodecs)             {               delete[] matchingCodecs;            }            matchingCodecs = NULL;        }    }    return(ringingSent);}UtlBoolean SipConnection::reject(){    UtlBoolean responseSent = FALSE;    if(inviteMsg && !inviteFromThisSide)    {        int state = getState();        if (state == CONNECTION_OFFERING)        {            UtlString replaceCallId;            UtlString replaceToTag;            UtlString replaceFromTag;            // Make sure that this isn't part of a transfer.  If we find a            // REPLACES header, then we shouldn't accept the call, but rather            // we should return a 481 response.            if (inviteMsg->getReplacesData(replaceCallId, replaceToTag, replaceFromTag))            {                SipMessage badTransaction;                badTransaction.setBadTransactionData(inviteMsg);                responseSent = send(badTransaction);#ifdef TEST_PRINT                osPrintf("SipConnection::reject - CONNECTION_FAILED, cause BUSY : 825\n");#endif                setState(CONNECTION_FAILED, CONNECTION_REMOTE, CONNECTION_CAUSE_BUSY);                fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_UNKNOWN) ;            }            else            {                SipMessage busyMessage;                busyMessage.setInviteBusyData(inviteMsg);                responseSent = send(busyMessage);#ifdef TEST_PRINT                osPrintf("SipConnection::reject - CONNECTION_FAILED, cause BUSY : 833\n");#endif                setState(CONNECTION_FAILED, CONNECTION_REMOTE, CONNECTION_CAUSE_BUSY);                fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL) ;            }        }        else if (state == CONNECTION_ALERTING)        {            SipMessage terminateMessage;            terminateMessage.setRequestTerminatedResponseData(inviteMsg);            responseSent = send(terminateMessage);#ifdef TEST_PRINT            osPrintf("SipConnection::reject - CONNECTION_DISCONNECTED, cause CONNECTION_CAUSE_CANCELLED : 845\n");#endif            setState(CONNECTION_DISCONNECTED, CONNECTION_REMOTE, CONNECTION_CAUSE_CANCELLED);            fireSipXEvent(CALLSTATE_DISCONNECTED, CALLSTATE_DISCONNECTED_NORMAL) ;                   }    }

⌨️ 快捷键说明

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