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

📄 faststart.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 4 页
字号:
                {
                    getGoodAddressForCall((HCALL)call,rtp);
                    cmTAToVt_H245(hVal,tmpNodeId, rtp);
                }
                else
                    pvtDelete(hVal, tmpNodeId);

                tmpNodeId = pvtAddBranch(hVal, h2250ParametersNodeId, __h245(mediaControlChannel));
                if ((rtcp != NULL) && (rtcp->ip || rtcp->port))
                {
                    getGoodAddressForCall((HCALL)call,rtcp);
                    cmTAToVt_H245(hVal,tmpNodeId, rtcp);
                }
                else
                    pvtDelete(hVal, pvtGetChild(hVal, h2250ParametersNodeId, __h245(mediaControlChannel), NULL));
            }
        }
        ret = outOLCNodeId;

        emaUnlock((EMAElement)hsCall);
    }

    cmiAPIExit(hApp, "cmFastStartChannelsAckIndex: [%d]", ret);
    return ret;
}


RVAPI int RVCALLCONV
cmFastStartChannelsAck(
    IN HCALL                hsCall,
    IN cmFastStartChannel*  pFastChannel)
{
    int ret=1;
    callElem* call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    if (!hsCall || !hApp) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp, "cmFastStartChannelsAck: hsCall=0x%p",hsCall);
    if (emaLock((EMAElement)hsCall))
    {
        ret = cmFastStartChannelsAckIndex(hsCall,pFastChannel->index, &(pFastChannel->rtcp), &(pFastChannel->rtp));
        emaUnlock((EMAElement)hsCall);
    }

    cmiAPIExit(hApp, "cmFastStartChannelsAck: [%d]",ret);

    return ret;
}


RVAPI int RVCALLCONV
cmFastStartChannelsReady(IN HCALL hsCall)
{
    callElem* call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);
    if (!hsCall || !hApp) return RV_ERROR_UNKNOWN;

    cmiAPIEnter(hApp, "cmFastStartChannelsReady: hsCall=0x%p",hsCall);
    if (emaLock((EMAElement)hsCall))
    {
        H245Control *ctrl = (H245Control *)cmiGetControl(hsCall);
        int fastStartPrpd[2*MAX_FS_SESSION_ID];
        int i;
        int limit = RvMin(call->fastStartNodesAckCount, (2*MAX_FS_SESSION_ID));

        memset(fastStartPrpd, 0xff, sizeof(fastStartPrpd));
        for(i=0; i<limit; i++)
        {
            fastStartPrpd[i] = call->fastStartNodes[call->fastStartIndexes[i]];
        }

        if (cmCallFastStartOpenChannels((HCALL)hsCall, fastStartPrpd, call->fastStartNodesAck, RV_FALSE) >= 0)
        {
            /* Notify the application that the fast staart procedure is complete */
            cmiReportControl(hsCall,cmControlStateFastStartComplete,(cmControlStateMode)0);
        }

        m_callset(call, fastStartFinished, RV_TRUE);
        cmcReadyEvent(ctrl);
        emaUnlock((EMAElement)hsCall);
    }

    cmiAPIExit(hApp, "cmFastStartChannelsReady: [OK]");

    return RV_TRUE;
}

RVAPI int RVCALLCONV
cmFastStartChannelsRefuse(IN HCALL hsCall)
{
    callElem* call=(callElem*)hsCall;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)call);

    if ((hsCall == NULL) || (hApp == NULL))
        return RV_ERROR_NULLPTR;

    cmiAPIEnter(hApp, "cmFastStartChannelsRefuse: hsCall=0x%p",hsCall);
    if (emaLock((EMAElement)hsCall))
    {
        H245Control *ctrl = (H245Control *)cmiGetControl(hsCall);

        call->fastStartState = fssRej;
        m_callset(call, fastStartFinished, RV_TRUE);
        cmcReadyEvent(ctrl);
        emaUnlock((EMAElement)hsCall);
    }

    cmiAPIExit(hApp, "cmFastStartChannelsRefuse: [OK]");
    return RV_TRUE;
}

/******************************************************************************************
 * cmFastStartReply
 *
 * Purpose:  This function is called from the CM whenever a response message after SETUP
 *           is received (CallProceeding, Alerting, Connect, Facility and Progress).
 *           It checks for FastStart response. If such exists, it processes it and opens
 *           the relevant channels.
 *
 * Input:    call       - call object instance
 *           uuNodeId   - UserUser node ID of the message
 *
 * Reurned Value: Non-negative value on success
 *                Negative value on failure
 ****************************************************************************************/
int cmFastStartReply(
    IN callElem*    call,
    IN int          uuNodeId)
{
    cmElem*app=(cmElem*)emaGetInstance((EMAElement)call);
    H245Control *ctrl=(H245Control *)cmiGetControl((HCALL)call);
    HPVT hVal=app->hVal;
    int fsNodeId;
    RvBool fsChannelsExist;
    int  rc;

    /* Are we in the right fast-start state? */
    if ((call->fastStartState==fssAck) || (call->fastStartState==fssRej))
        return RV_ERROR_UNKNOWN;

    /* Make sure we've got fast start information here and get the first one */
    fsNodeId=pvtGetChild(hVal,uuNodeId,__q931(fastStart),NULL);
    fsChannelsExist = (fsNodeId >= 0);
    fsNodeId=pvtChild(hVal, fsNodeId);

    /* Loop through all of the acknowledgements and put them into the call's structure */
    while (fsNodeId >= 0)
    {
        RvUint8* encodeBuffer;
        int length;
        int decoded_length;
        int chanMsgId;
        int decodingResult;

        /* Decode a single OLC.Ack message */
        chanMsgId = pvtAddRoot(hVal, app->synOLC, 0, NULL);
        getEncodeDecodeBuffer(app->encodeBufferSize, &encodeBuffer);
        length=pvtGetString(hVal, fsNodeId, app->encodeBufferSize, (char*)encodeBuffer);

        decodingResult = cmEmDecode(hVal, chanMsgId, encodeBuffer, length, &decoded_length);
        if (decodingResult < 0)
        {
            pvtDelete(hVal, chanMsgId);
            chanMsgId = -1;
        }

        RvH323CmPrintMessage(&app->logFastStart, "Accepted faststart channel decoded:",
            hVal, chanMsgId, encodeBuffer, decoded_length, RV_TRUE);

        if (decodingResult >= 0)
        {
            /* Add the decoded OLC.Ack into the fast start acknowledgments of the call */
            call->fastStartNodesAck[call->fastStartNodesAckCount++] = chanMsgId;
        }

        /* Goto the next one in the next entry to the while loop */
        if (call->fastStartNodesAckCount == app->maxFsAccepted)
            /* array is maxFsAccepted+1 size, must leave the last one -1 */
            break;
        fsNodeId=pvtBrother(hVal, fsNodeId);
    }

    if (fsChannelsExist)
    {
        rc = cmCallFastStartOpenChannels((HCALL)call, call->fastStartNodes, call->fastStartNodesAck, RV_TRUE);

        /* Notify the application that the fast staart procedure is complete */
        cmiReportControl((HCALL)call,cmControlStateFastStartComplete,(cmControlStateMode)0);

        m_callset(call, fastStartFinished, RV_TRUE);
        cmcReadyEvent(ctrl);
    }
    else
        rc = RV_ERROR_UNKNOWN;

    return rc;
}

void deleteFastStart(callElem*call)
{
    cmElem*app=(cmElem*)emaGetInstance((EMAElement)call);
    int i;
    for (i=0;i<call->fastStartNodesCount;i++)
    {
        pvtDelete(app->hVal,call->fastStartNodes[i]);
        call->fastStartNodes[i]=RV_ERROR_UNKNOWN;
    }
    call->fastStartNodesCount=0;
    for (i=0;i<call->fastStartNodesAckCount;i++)
    {
        pvtDelete(app->hVal,call->fastStartNodesAck[i]);
        call->fastStartNodesAck[i]=RV_ERROR_UNKNOWN;
    }
    call->fastStartNodesAckCount=0;
}


/******************************************************************************************
 * addFastStart
 *
 * Purpose:  This function adds the fast start messages that are stored on the call
 *           to an outgoing message
 *
 * Input:    call       - call object instance
 *           message    - message's root node ID to add fast start information to
 *
 * Reurned Value: none
 ****************************************************************************************/
void addFastStart(
    IN callElem*    call,
    IN int          message)
{
    cmElem*app=(cmElem*)emaGetInstance((EMAElement)call);
    HPVT hVal=app->hVal;
    int nodeCount,*nodes;

    /* See which side is it - we need to know which fast start node to add */
    if (m_callget(call, callInitiator))
    {
        /* Initiator of the call */
        nodeCount = call->fastStartNodesCount;
        nodes = call->fastStartNodes;

        /* Make sure it's a setup message - otherwise we shouldn't add the fast start nodes */
        if (pvtGetChildTagByPath(hVal,message,"message",1) != cmQ931setup)
            return;
    }
    else
    {
        if(call->fastStartState == fssRej)
        {
            int tmpNodeId;
            /* reject the fast start - was approved with no channels */
            __pvtBuildByFieldIds(tmpNodeId, hVal, message,
                {_q931(message)
                _anyField
                _q931(userUser)
                _q931(h323_UserInformation)
                _q931(h323_uu_pdu)
                _q931(h323_message_body)
                _anyField
                _q931(fastConnectRefused)
                LAST_TOKEN},0,NULL);
            return;
        }
        /* Destination of the call sends Ack nodes */
        nodeCount = call->fastStartNodesAckCount;
        nodes = call->fastStartNodesAck;
    }

    if (nodeCount > 0)
    {
        /* We have fast start nodes - go through them and add them in */
        int i;
        RvPvtNodeId tmpNodeId;

        /* first, we'll check if we already have a fast start field in the message */
        __pvtGetByFieldIds(tmpNodeId, hVal, message,
            {_q931(message) _anyField _q931(userUser) _q931(h323_UserInformation) _q931(h323_uu_pdu)
            _q931(h323_message_body) _anyField _q931(fastStart) LAST_TOKEN},NULL,NULL,NULL);
        if (RV_PVT_NODEID_IS_VALID(tmpNodeId))
        {
            /* we have a FS element in the message already. this may be because the call was transferred,
            or it may be because the user used setParam() to set a faststart element. we can do one of 
            two things: either delete the node and put our own FS content, or we could keep the existing
            FS and return. adding to the current FS message is out of the question. */
#if 1
            /* we assume that the user will not use both setParam() and FS functions, or that this is a
            transfer, and we better update our information */
            pvtDelete(hVal, tmpNodeId);
#else
            /* we assume that we should keep whatever was set, and leave things up to the user */
            return;
#endif
        }

            /* Build the fast start SEQUENCE OF node */
        __pvtBuildByFieldIds(tmpNodeId, hVal, message,
                    {_q931(message)
                     _anyField
                     _q931(userUser)
                     _q931(h323_UserInformation)
                     _q931(h323_uu_pdu)
                     _q931(h323_message_body)
                     _anyField
                     _q931(fastStart)
                     LAST_TOKEN},0,NULL);

        for (i = 0; i < nodeCount; i++)
        {
            int iBufLen;
            RvUint8* encodeBuffer;

            getEncodeDecodeBuffer(app->encodeBufferSize, &encodeBuffer);

            /* Encode a faststart proposal/acceptance */
            if (cmEmEncode(hVal, nodes[i], encodeBuffer, app->encodeBufferSize, &iBufLen) >= 0)
            {
                /* That's it, now we can add the encoded OLC message to the SETUP message */
                pvtAdd(hVal, tmpNodeId, -800, iBufLen, (char*)encodeBuffer, NULL);
            }
            else
                iBufLen = -1;

            RvH323CmPrintMessage(&app->logFastStart,
                m_callget(call,callInitiator) ? "Suggested faststart channel encoded:":"Accepted faststart channel encoded:",
                hVal, nodes[i], encodeBuffer, iBufLen, RV_FALSE);
        }
    }
}



/************************************************************************
 * cmCallFastStartOpenChannels
 * purpose: Set the answered information to be sent for a fast start
 *          proposal and open the channels on the destination side of the
 *          call. This function should be called after receiving
 *          cmEvCallFastStart() or cmEvCallFastStartSetup().
 *          It is automatically called on the initiator of the call.
 * input  : hsCall      - Call to use
 *          proposed    - List of proposed channels. This list is searched for
 *                        their RTP and RTCP addresses.
 *                        Each parameter in this list is a root node of an
 *                        OpenLogicalChannel message to propose in faststart
 *                        The last element in this list should be a negative value.
 *          accepted    - List of accepted channels.
 *                        Each paramenter in this list is a root node of an
 *                        OpenLogicalChannel message sent to the origin of the call
 *                        by this endpoint.
 *                        The last element in this list should be a negative value.
 *          origin      - RV_TRUE if this application is the origin of the call
 *                        RV_FALSE if this application is not the origin of the call
 * output : none
 * return : non-negative value on success
 *          negative value on failure

⌨️ 快捷键说明

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