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

📄 cmchan.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
        {
            if (channel->pChannelParams.data.h225Params.redEncID<0)
                channel->pChannelParams.data.h225Params.redEncID=pvtAddRoot(hVal,NULL,0,NULL);
            pvtMoveTree(hVal,channel->dataTypeID,tmpId);
        }
        tmpId=pvtGetChild(hVal,h225ID,__h245(source),NULL);
        if (tmpId>=0)
        {
            int tmp;
            pvtGetChildValue(hVal,tmpId,__h245(mcuNumber), &(tmp),NULL);
            channel->pChannelParams.data.h225Params.source.mcuNumber=(char)tmp;
            pvtGetChildValue(hVal,tmpId,__h245(terminalNumber), &(tmp),NULL);
            channel->pChannelParams.data.h225Params.source.terminalNumber=(char)tmp;

        }
        tmpId=pvtGetChild(hVal,h225ID,__h245(destination),NULL);
        if (tmpId>=0)
        {
            int tmp;
            pvtGetChildValue(hVal,tmpId,__h245(mcuNumber), &(tmp),NULL);
            channel->pChannelParams.data.h225Params.destination.mcuNumber=(char)tmp;
            pvtGetChildValue(hVal,tmpId,__h245(terminalNumber), &(tmp),NULL);
            channel->pChannelParams.data.h225Params.destination.terminalNumber=(char)tmp;

        }
    }
    if (!channel->bIsDuplex)
        cmcCallAddressCallbacks(app, channel, h225ID, RV_FALSE);
    if (!emaWasDeleted((EMAElement)channel))
    {
        if (channel->pReplacementCh && app->cmMyChannelEvent.cmEvChannelReplace)
        {
            cmiCBEnter((HAPP)app, "cmEvChannelReplace: haCall=0x%p, hsCall=0x%p, haReplaceCall=0x%p, hsReplaceCall=0x%p.",
                            emaGetApplicationHandle((EMAElement)channel),               channel,
                            emaGetApplicationHandle((EMAElement)channel->pReplacementCh),channel->pReplacementCh);
            nesting = emaPrepareForCallback((EMAElement)channel);
            app->cmMyChannelEvent.cmEvChannelReplace((HAPPCHAN)emaGetApplicationHandle((EMAElement)channel),               (HCHAN)channel,
                                                     (HAPPCHAN)emaGetApplicationHandle((EMAElement)channel->pReplacementCh),(HCHAN)channel->pReplacementCh);
            emaReturnFromCallback((EMAElement)channel, nesting);
            cmiCBExit((HAPP)app, "cmEvChannelReplace.");

        }
    }

    if (!emaWasDeleted((EMAElement)channel))
    {
        /* -- Parameters */
        if (channel->dataTypeID <0)
        {
            RvLogError(&app->logERR, (&app->logERR, "H245Channel:establishIndication: no data type."));
            return RV_ERROR_UNKNOWN;
        }
        else
        {
            confDataType type;
            cmcCallChannelParametersCallback((HAPP)app, (HCHAN)channel, channel->dataTypeID, &type);
            if (!emaWasDeleted((EMAElement)channel))
                cmcCallDataTypeHandleCallback((HAPP)app, (HCHAN)channel, channel->dataTypeID, type);
        }
    }
    if (!emaWasDeleted((EMAElement)channel))
    {
        if (!channel->bIsDuplex)
        { /* -- dynamic RTP payload type */
            RvInt32 num;

            if((pvtGetChildValue(hVal,h225ID,__h245(dynamicRTPPayloadType),&num,NULL)>=0)&&
               (app->cmMyChannelEvent.cmEvChannelRTPDynamicPayloadType))
            {
                cmiCBEnter((HAPP)app, "cmEvChannelRTPDynamicPayloadType: haCall=0x%p, hsCall=0x%p, type=%d.", emaGetApplicationHandle((EMAElement)channel), channel, num);
                nesting = emaPrepareForCallback((EMAElement)channel);
                app->cmMyChannelEvent.cmEvChannelRTPDynamicPayloadType((HAPPCHAN)emaGetApplicationHandle((EMAElement)channel), (HCHAN)channel, (RvInt8)num);
                emaReturnFromCallback((EMAElement)channel, nesting);
                cmiCBExit((HAPP)app, "cmEvChannelRTPDynamicPayloadType.");
            }
        }
        channel->eState=ChannelStateAwaitingEstablishment;

        /* -- state changed */
        notifyChannelState(channel,cmChannelStateOffering,(channel->bIsDuplex)?cmChannelStateModeDuplex:cmChannelStateModeOff);
    }

    return RV_TRUE;
}

int openLogicalChannel(H245Control *ctrl, int message)
{
    int lcn = 0;
    HPVT hVal;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    H245Channel* channel = NULL;
    cmElem* app=(cmElem*)hApp;
    int nesting;
    int ret = RV_TRUE;
    RvBool rejectChannel = RV_FALSE;

    if (!hApp) return RV_ERROR_NULLPTR;

    hVal = ((cmElem *)hApp)->hVal;

    if (ctrl->eState == ctrlEndSession)
    {
        /* control was not even initialized (could only happen when tunneling is approved, and FastStart
        connected, and other side is working non-standard) or it has already been dropped. Reject the 
        channel and exit.*/
        RvLogError(&app->logERR,
            (&app->logERR, "Received OLC when control is not in connected state (haCall=0x%p, hsCall=0x%p)",
                emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)),cmiGetByControl((HCONTROL)ctrl)));
        rejectChannel = RV_TRUE;
    }
    else if ((ctrl->eState != ctrlConnected) && (ctrl->eState != ctrlConference))
    {
        /* received OLC when control is not connected yet (did not finish MSD and Cap-Ex), keep the
        message for later (if we have room), and exit */
        if (!RV_PVT_NODEID_IS_VALID(ctrl->incomingOLCs[0]))
        {
            ctrl->incomingOLCs[0] = pvtAddRoot(hVal,NULL,0,NULL);
            pvtMoveTree(hVal,ctrl->incomingOLCs[0],message);
            return 0;
        }
        else if (!RV_PVT_NODEID_IS_VALID(ctrl->incomingOLCs[1]))
        {
            ctrl->incomingOLCs[1] = pvtAddRoot(hVal,NULL,0,NULL);
            pvtMoveTree(hVal,ctrl->incomingOLCs[1],message);
            return 0;
        }
        rejectChannel = RV_TRUE;
    }

    if (!rejectChannel)
    {
        deriveChannels((HCONTROL)ctrl);
        pvtGetChildValue(hVal,message,__h245(forwardLogicalChannelNumber),&lcn,NULL);
        channel=allocateChannel((HCONTROL)ctrl);
        if (!channel)
        {
            RvLogError(&app->logERR,
                (&app->logERR, "Unable to allocate channel"));
            rejectChannel = RV_TRUE;
        }
    }

    if (rejectChannel)
    {
        RvPvtNodeId rejMessage, nodeId;

        pvtGetChildValue(hVal,message,__h245(forwardLogicalChannelNumber),&lcn,NULL);

        rejMessage=pvtAddRoot(hVal,app->synProtH245,0,NULL);
        nodeId=pvtAddBranch2(hVal,rejMessage, __h245(response),__h245(openLogicalChannelReject));
        pvtAdd(hVal,nodeId,__h245(forwardLogicalChannelNumber),lcn,NULL,NULL);
        pvtAddBranch2(hVal,nodeId,__h245(cause),__h245(unspecified));

        sendMessageH245((HCONTROL)ctrl, rejMessage);
        pvtDelete(hVal,rejMessage);

        return RV_ERROR_UNKNOWN;
    }

    if(emaLock((EMAElement)channel))
    {
        channel->hCtrl=(HCONTROL)ctrl;
        channel->myLogicalChannelNum=lcn;
        channel->bOrigin=RV_FALSE;

        if (app->cmMySessionEvent.cmEvCallNewChannel)
        {
            cmiCBEnter(hApp, "cmEvCallNewChannel:IN: haCall=0x%p, hsCall=0x%p. hsChan=0x%p", emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)),cmiGetByControl((HCONTROL)ctrl),channel);
            {
                HAPPCHAN haChan=NULL;
                nesting = emaPrepareForCallback((EMAElement)channel);
                app->cmMySessionEvent.cmEvCallNewChannel((HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)), (HCALL)cmiGetByControl((HCONTROL)ctrl),(HCHAN)channel, &haChan);
                emaReturnFromCallback((EMAElement)channel, nesting);
                emaSetApplicationHandle((EMAElement)channel,(void*)haChan);
            }
            cmiCBExit(hApp, "cmEvCallNewChannel:IN: haChan=0x%p.", emaGetApplicationHandle((EMAElement)channel));
        }

        if (!emaWasDeleted((EMAElement)channel))
            ret = openLogicalChannelEvent(app, hVal, channel, message);

        emaUnlock((EMAElement)channel);
    }
    return RV_TRUE;
}


static
void establishConfirmed(H245Channel*channel,int h225ID)
{
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)channel);
    HPVT hVal;
    cmElem* app=(cmElem*)hApp;
    int nesting;

    hVal = app->hVal;

    RvH323TimerCancel(cmGetTimersHandle(hApp), &channel->pTimer);
    if (!channel->bIsDuplex)
    {
        cmcCallAddressCallbacks(app, channel, h225ID, RV_FALSE);
        if (channel->pChannelParams.data.h225Params.transCapID<0)
            channel->pChannelParams.data.h225Params.transCapID=pvtAddRoot(hVal,NULL,0,NULL);
        pvtMoveTree(hVal,channel->pChannelParams.data.h225Params.transCapID,pvtGetChild(hVal,h225ID,__h245(transportCapability),NULL));
        { /* -- dynamic RTP payload type */
            RvInt32 num;

            if((pvtGetChildValue(hVal,h225ID,__h245(dynamicRTPPayloadType),&num,NULL)>=0)&&(app->cmMyChannelEvent.cmEvChannelRTPDynamicPayloadType))
            {
                cmiCBEnter(hApp, "cmEvChannelRTPDynamicPayloadType: haCall=0x%p, hsCall=0x%p, type=%d.", emaGetApplicationHandle((EMAElement)channel), channel, num);
                nesting = emaPrepareForCallback((EMAElement)channel);
                app->cmMyChannelEvent.cmEvChannelRTPDynamicPayloadType((HAPPCHAN)emaGetApplicationHandle((EMAElement)channel), (HCHAN)channel, (RvInt8)num);
                emaReturnFromCallback((EMAElement)channel, nesting);
                cmiCBExit(hApp, "cmEvChannelRTPDynamicPayloadType.");
            }
        }
    }
    if (!emaWasDeleted((EMAElement)channel))
    { /* -- Parameters */
      /* Report the same session association handles */

        HCHAN hsSameSessionH=(HCHAN)channel->pPartner;
        HAPPCHAN haSameSessionH=NULL;

        if (channel->pPartner)
            haSameSessionH=(HAPPCHAN)emaGetApplicationHandle((EMAElement)channel->pPartner);

        /* -- same session handle */
        cmiCBEnter(hApp, "cmEvChannelParameters: haChan=0x%p, hsChan=0x%p, channelName=NULL, AppSes=0x%p, Ses=0x%p, NULL, NULL, rate=-1.",
            emaGetApplicationHandle((EMAElement)channel), channel, haSameSessionH, hsSameSessionH);
        nesting = emaPrepareForCallback((EMAElement)channel);
        ifE (app->cmMyChannelEvent.cmEvChannelParameters)
            ((HAPPCHAN)emaGetApplicationHandle((EMAElement)channel), (HCHAN)channel, NULL, haSameSessionH, hsSameSessionH, NULL, NULL, (RvUint32)RV_ERROR_UNKNOWN);
        emaReturnFromCallback((EMAElement)channel, nesting);
        cmiCBExit(hApp, "cmEvChannelParameters.");
    }
    notifyChannelState(channel,cmChannelStateConnected, cmChannelStateModeOn);
    if (!emaWasDeleted((EMAElement)channel))
    if (channel->pChannelParams.data.h225Params.bFlowControlToZero)
    {
        cmiCBEnter(hApp, "cmEvChannelFlowControlToZero: haChan=0x%p, hsChan=0x%p", emaGetApplicationHandle((EMAElement)channel), channel);
        nesting = emaPrepareForCallback((EMAElement)channel);
        ifE (app->cmMyChannelEvent.cmEvChannelFlowControlToZero)((HAPPCHAN)emaGetApplicationHandle((EMAElement)channel), (HCHAN)channel);
        emaReturnFromCallback((EMAElement)channel, nesting);
        cmiCBExit(hApp, "cmEvChannelFlowControlToZero.");

    }

}

int openLogicalChannelAck(H245Control *ctrl, int message)
{
    int lcn;
    HPVT hVal;
    cmElem* app=(cmElem*)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    H245Channel* channel=NULL;
    int forwardLCP_ID,reverseLCP_ID,h225ID;

    if (!app) return RV_ERROR_UNKNOWN;
    hVal=app->hVal;

    pvtGetChildValue(hVal,message,__h245(forwardLogicalChannelNumber),&lcn,NULL);

    channel = getOutChanByLCN((HCONTROL)ctrl, lcn);
    if (!channel)
        return RV_TRUE;

    if (emaLock((EMAElement)channel))
    {
        switch(channel->eState)
        {
            case ChannelStateReleased:
            case ChannelStateIdle:
                RvLogInfo(&app->logERR,
                    (&app->logERR,"H245Channel 0x%p in released state. Message discarded", channel));
                break;

            case ChannelStateAwaitingEstablishment:
            {
                /* complete dependent channel establishment*/
                void* ptr=NULL;
                H245Channel* dependent;
                while((dependent = getNextOutChanByBase((HCONTROL)ctrl,channel, &ptr)))
                    startEstablishment((HAPP)app, (HCHAN)dependent);
                if (!emaWasDeleted((EMAElement)channel))
                {
                    forwardLCP_ID=pvtGetChild(hVal,message, __h245(forwardMultiplexAckParameters), NULL);
                    h225ID=pvtGetChild(hVal,forwardLCP_ID, __h245(h2250LogicalChannelAckParameters), NULL);
                    if (h225ID>=0)
                    {
                        reverseLCP_ID=pvtGetChild(hVal,message, __h245(reverseLogicalChannelParameters),NULL);
                        pvtGetChildValue(hVal,reverseLCP_ID,__h245(portNumber),&channel->remotePortNumber,NULL);

                        pvtGetChildValue(hVal,h225ID, __h245(sessionID),&(channel->sessionId),NULL);

                        if (channel->bIsDuplex)
                            pvtGetChildValue(hVal,rev

⌨️ 快捷键说明

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