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

📄 cmctrlrtd.c

📁 基于h323协议的软phone
💻 C
字号:
/***********************************************************************
        Copyright (c) 2002 RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Ltd.. No part of this document may be reproduced in any
form whatsoever without written prior approval by RADVISION Ltd..

RADVISION Ltd. reserve the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
***********************************************************************/

#include "rvinternal.h"
#include "rvtimestamp.h"
#include "cmictrl.h"
#include "cmConf.h"
#include "caputils.h"
#include "strutils.h"
#include "cmchan.h"
#include "oidutils.h"
#include "stkutils.h"
#include "h245.h"
#include "cmCtrlMSD.h"
#include "cmdebprn.h"

#ifdef __cplusplus
extern "C" {
#endif

static RvBool rtdTimeoutEventsHandler(void*hsCall);


/* round trip delay________________________________________________________________________________ */

RVAPI int RVCALLCONV
cmCallRoundTripDelay(
             /* Measure the round trip delay to the remote terminal */
             /* Note: maxDelay=0 --> delay taken from configuration */
             IN     HCALL       hsCall,
             IN     RvInt32     maxDelay /* maximum waiting delay in seconds */
             )
{
    H245Control*   ctrl=(H245Control*)cmiGetControl(hsCall);
    HAPP           hApp=(HAPP)emaGetInstance((EMAElement)hsCall);
    int            ret=0;
    HPVT           hVal;
    int            nodeId,message;
    RoundTripInfo* rtd;

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

    cmiAPIEnter(hApp, "cmCallRoundTripDelay: hsCall=0x%p, delay=%d", hsCall, maxDelay);

    if (emaLock((EMAElement)hsCall))
    {
        hVal = ((cmElem *)hApp)->hVal;

        rtd=&ctrl->roundTrip;

        RvH323TimerCancel(cmGetTimersHandle(hApp),&rtd->timer);

        if (maxDelay)
            pvtGetChildValue(hVal,((cmElem*)hApp)->h245Conf,__h245(roundTripTimeout),&maxDelay,NULL);

        rtd->seqNum++;
        rtd->seqNum%=256;

        message=pvtAddRoot(hVal,((cmElem*)hApp)->synProtH245,0,NULL);
        __pvtBuildByFieldIds(nodeId,hVal,message, {_h245(request) _h245(roundTripDelayRequest)
                                                   _h245(sequenceNumber) LAST_TOKEN}, rtd->seqNum, NULL);
        ret = sendMessageH245((HCONTROL)ctrl, message);
        pvtDelete(hVal,message);


        if (ret >= 0)
        {
            rtd->timer=RvH323TimerStart(cmGetTimersHandle(hApp),rtdTimeoutEventsHandler,(void*)ctrl,maxDelay*1000);
            rtd->timeStart = (RvInt32)Rv64Divide(RvTimestampGet(), RV_TIME64_NSECPERMSEC);
            rtd->waiting=RV_TRUE;
        }
        emaUnlock((EMAElement)hsCall);
    }

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


int roundTripDelayRequest(H245Control* ctrl, int message)
{
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    HPVT hVal;
    int nodeId, rmessage, res;
    int sqNumber;

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

    pvtGetChildValue(hVal,message, __h245(sequenceNumber),&sqNumber,NULL);
    rmessage=pvtAddRoot(hVal,((cmElem*)hApp)->synProtH245,0,NULL);
    __pvtBuildByFieldIds(nodeId,hVal,rmessage, {_h245(response) _h245(roundTripDelayResponse)
                                                _h245(sequenceNumber) LAST_TOKEN}, sqNumber, NULL);
    res = sendMessageH245((HCONTROL)ctrl, rmessage);
    pvtDelete(hVal,rmessage);
    return res;
}

int roundTripDelayResponse(H245Control* ctrl, int message)
{
    HAPP           hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    cmElem*        app = (cmElem *)hApp;
    HPVT           hVal;
    RoundTripInfo* rtd=&ctrl->roundTrip;
    int            sqNumber;
    RvInt32        delay;

    hVal = app->hVal;

    pvtGetChildValue(hVal,message, __h245(sequenceNumber),&sqNumber,NULL);

    RvH323TimerCancel(cmGetTimersHandle(hApp),&rtd->timer);

    if ((sqNumber == rtd->seqNum) && (app->cmMySessionEvent.cmEvCallRoundTripDelay != NULL))
    {
        int nesting;

        delay = (RvInt32)Rv64Divide(RvTimestampGet(), RV_TIME64_NSECPERMSEC) - rtd->timeStart;
        cmiCBEnter(hApp, "cmEvCallRoundTripDelay: haCall=0x%p, hsCall=0x%p, delay=%d.",(HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)), cmiGetByControl((HCONTROL)ctrl), delay);
        nesting=emaPrepareForCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl));
        app->cmMySessionEvent.cmEvCallRoundTripDelay(
            (HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)),
            (HCALL)cmiGetByControl((HCONTROL)ctrl),
            delay);
        emaReturnFromCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl),nesting);
        cmiCBExit(hApp, "cmEvCallRoundTripDelay.");
    }
    return RV_TRUE;
}


static RvBool rtdTimeoutEventsHandler(void*_ctrl)
{
    H245Control*   ctrl=(H245Control*)_ctrl;
    HAPP           hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    cmElem*        app = (cmElem *)hApp;
    RoundTripInfo* rtd=&ctrl->roundTrip;

    if (app->cmMySessionEvent.cmEvCallRoundTripDelay == NULL)
        return RV_FALSE;

    if (emaLock((EMAElement)cmiGetByControl((HCONTROL)ctrl)))
    {
        int nesting;

        RvH323TimerClear(cmGetTimersHandle(hApp), &rtd->timer);
        cmiCBEnter(hApp, "cmEvCallRoundTripDelay: haCall=0x%p, hsCall=0x%p, delay=%d.",(HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)), cmiGetByControl((HCONTROL)ctrl), -1);
        nesting=emaPrepareForCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl));
        app->cmMySessionEvent.cmEvCallRoundTripDelay(
            (HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)),
            (HCALL)cmiGetByControl((HCONTROL)ctrl), -1);
        emaReturnFromCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl),nesting);
        cmiCBExit(hApp, "cmEvCallRoundTripDelay.");
        emaUnlock((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    }
    return RV_FALSE;
}

/************************************************************************
 * rtdInit
 * purpose: Initialize the round trip delay process on a control channel
 * input  : ctrl    - Control object
 * output : none
 * return : none
 ************************************************************************/
int rtdInit(H245Control* ctrl)
{
    RoundTripInfo* rtd=&ctrl->roundTrip;
    rtd->seqNum=0;
    rtd->timer=NULL;
    return 0;
}

/************************************************************************
 * rtdEnd
 * purpose: Stop the round trip delay process on a control channel
 * input  : ctrl    - Control object
 * output : none
 * return : none
 ************************************************************************/
void rtdEnd(IN H245Control* ctrl)
{
    RoundTripInfo*   rtd=&ctrl->roundTrip;
    HAPP             hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));

    /* Get rid of the timer if one exists */
    RvH323TimerCancel(cmGetTimersHandle(hApp),&rtd->timer);
}

#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

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