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

📄 osptransapi.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 5 页
字号:
/**########################################################################*########################################################################**   COPYRIGHT (c) 1998, 1999 by TransNexus, LLC                          *                                                                    *   This software contains proprietary and confidential information  *   of TransNexus, LLC. Except as may be set forth in the license    *   agreement under which this software is supplied, use, disclosure, *   or reproduction is prohibited without the prior, express, written*   consent of TransNexus, LLC.                                      *                                     *******#########################################################################*#########################################################################*#########################################################################*//* * osptransapi.cpp - API functions for transaction object. */#include "osp.h"#include "osptrans.h"#include "ospprovider.h"#include "ospxml.h"#include "ospmsginfo.h"#include "ospdest.h"#include "ospstatus.h"#include "ospusageind.h"#include "ospauthind.h"#include "osptokeninfo.h"#include "ospmsg.h"#include "ospfail.h"#include "osputils.h"#include "osptnprobe.h"#include "ospstatistics.h"/* * OSPPTransactionAccumulateOneWayDelay() * * Accumulates one way delay for transaction. * * The OSPPTransactionAccumulateOneWayDelay function accumulates one-way * delay statistics for the call. It is used to report one way delay from * the remote peer to the reporting system. This value may be calculated  * by comparing the network time protocol (NTP) timestamp included in RTCP * messages from the peer with the local NTP time in the  reporting system. * Applications may call this function an unlimited number of times during * a transaction, but only after the transaction has been authorised and  * before its usage details are reported (i.e. after calling either the  * function OSPPTransactionRequestAuthorisation or the function  * OSPPTransactionValidateAuthorisation and before calling the function  * OSPPTransactionReportUsage). Also, each call to this function must report * statistics for a separate and distinct set of measurements. In other words, * once OSPPTransactionAccumulateOneWayDelay is successfully called, the  * application should discard (at least for subsequent calls to the function) * the data and start calculating minimum, mean, variance measures anew. * Applications may use this function to report a single sample, or they may * report statistical measurements from a collection of samples.  * The parameters to the function are: *   ospvTransaction: handle of the transaction object. *   ospvNumberOfSamples: the number of samples included in these statistics. *   ospvMinimum: the minimum delay, in milliseconds, measured within the  *      current set of samples. If the function call is used to report a single  *      sample, this parameter should indicate that measurement, and it should  *      be equal to the value of the ospvMean parameter. *   ospvMean: the mean of the delay, in milliseconds, measured within the  *      current set of samples. If the function call is used to report a single *      sample, this parameter should indicate that measurement, and it should  *      be equal to the value of the ospvMinimum parameter. *   ospvVariance: the variance of the delay, in square milliseconds, measured *      within the current set of samples. If the function call is used to  *      report a single sample, this parameter should be zero. * The SDK library is able to perform this function without network interaction, * and, therefore, does not block for network input or output during its  * execution. * * returns OSPC_ERR_NO_ERROR if successful, else error code. */intOSPPTransactionAccumulateOneWayDelay(    OSPTTRANHANDLE  ospvTransaction,    /* In - Transaction handle             */    unsigned        ospvNumberOfSamples,/* In - Number of samples included     */    unsigned        ospvMinimum,        /* In - Minimum delay in milliseconds  */    unsigned        ospvMean,           /* In - Mean of delay in milliseconds  */    float           ospvVariance)       /* In - Variance of delay in square ms */{    int         errorcode   = OSPC_ERR_NO_ERROR,                tnisnan     = OSPC_TRUE;    OSPTTRANS   *trans      = OSPC_OSNULL;    unsigned    currnumber  = 0;    double      topower     = 0,                mean        = 0,                intpart     = 0;    OSPTBOOL    accumallowed = OSPC_FALSE;    OSPTDELAY   tmpstats;    OSPM_MEMSET(&tmpstats, 0, sizeof(OSPTDELAY));    if((ospvNumberOfSamples == 0) ||        ((ospvNumberOfSamples == 1) &&        ((ospvMinimum != ospvMean) ||        (ospvVariance != 0))))    {        errorcode = OSPC_ERR_TRAN_INVALID_ENTRY;        OSPM_DBGERRORLOG(errorcode, "Invalid input for AccumulateOneWayDelay");    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        trans = OSPPTransactionGetContext(ospvTransaction, &errorcode);    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        OSPPTransactionGetAccumAllowed(trans, &accumallowed);        if(!accumallowed)        {            errorcode = OSPC_ERR_TRAN_ACCUMULATE_NOT_ALLOWED;            OSPM_DBGERRORLOG(errorcode,                 "AccumulateOneWay not allowed in this transaction state.");        }    }    if(errorcode == OSPC_ERR_NO_ERROR)    {        /* if no statistics structure, make one */        if(trans->TNStatistics == OSPC_OSNULL)        {            trans->TNStatistics = OSPPStatisticsNew();            if(trans->TNStatistics == OSPC_OSNULL)            {                errorcode = OSPC_ERR_TRAN_STATS_NEW_FAIL;                OSPM_DBGERRORLOG(errorcode, "New failed for stats struct.");            }        }        if(errorcode == OSPC_ERR_NO_ERROR)        {            /* make temporary copy so we don't corrupt our accumulator */            OSPM_MEMCPY(&tmpstats, &(trans->TNStatistics->ospmOneWay), sizeof(OSPTDELAY));            /* number of measurements */            currnumber = tmpstats.NumberOfSamples;            tmpstats.NumberOfSamples += ospvNumberOfSamples;            /* minimum measured value */            if(tmpstats.HasValue)            {                tmpstats.Minimum = osp_min(tmpstats.Minimum, ospvMinimum);            }            else            {                tmpstats.Minimum = ospvMinimum;            }            /* sample mean - have to cast NumberOfSamples to a float to get some precision             * on the mean */            mean = ((tmpstats.Mean * currnumber) + (ospvMean * ospvNumberOfSamples)) /                 (float)tmpstats.NumberOfSamples;            /* make sure we don't have overflow */            OSPM_ISNAN(mean, tnisnan);            if(tnisnan)            {                errorcode = OSPC_ERR_TRAN_INVALID_CALC;            }            else            {                /* if remainder is >= .5, round up, else round down */                if(OSPM_MODF(mean, &intpart) >= .5)                {                    tmpstats.Mean = (unsigned)OSPM_CEIL(mean);                }                else                {                    tmpstats.Mean = (unsigned)OSPM_FLOOR(mean);                }                /* sum of squares of samples */                OSPM_POW((double)ospvMean, 2, topower);                if (topower != OSPC_ERR_POW)                {                    tmpstats.SumOfSampSquares = tmpstats.SumOfSampSquares +                         ((ospvNumberOfSamples - 1) * (double)ospvVariance) +                         (ospvNumberOfSamples * topower);                    topower = 0;                }                else                {                    errorcode = (int)topower;                }            }            if(errorcode == OSPC_ERR_NO_ERROR)            {                /* variance */                OSPM_POW((double)tmpstats.Mean, 2, topower);                if(topower != OSPC_ERR_POW)                {                    tmpstats.Variance = (float)(tmpstats.SumOfSampSquares -                         (tmpstats.NumberOfSamples * topower)) /                         (tmpstats.NumberOfSamples - 1);                    topower = 0;                }                else                {                    errorcode = (int)topower;                }            }            /* Only set state if we have actually done something, otherwise no             * change in state.             */            if(errorcode == OSPC_ERR_NO_ERROR)            {                tmpstats.HasValue = OSPC_TRUE;                trans->TNStatistics->ospmHasOneWay = OSPC_TRUE;                /* now copy values back to permanent accumulator */                OSPM_MEMCPY(&(trans->TNStatistics->ospmOneWay),                     &(tmpstats), sizeof(OSPTDELAY));                OSPPTransactionSetState(trans, OSPC_ACCUMULATE_SUCCESS);            }            else            {                OSPPTransactionSetState(trans, OSPC_ACCUMULATE_FAIL);                }        }    }    return errorcode;}/* * OSPPTransactionAccumulateRoundTripDelay() * * Accumulates round trip delay for transaction. *  * The OSPPTransactionAccumulateRoundTripDelay function accumulates round trip  * delay statistics for the call. These measurements can be made using, for  * example, H.245 round trip delay requests during the call. Applications may  * call this function an unlimited number of times during a transaction, but  * only after the transaction has been authorised and before its usage details  * are reported (i.e. after calling either the function  * OSPPTransactionRequestAuthorisation or the function  * OSPPTransactionValidateAuthorisation and before calling the function  * OSPPTransactionReportUsage). Also, each call to this function must report  * statistics for a separate and distinct set of measurements. In other words,  * once OSPPTransactionAccumulateRoundTripDelay is successfully called,  * the application should discard (at least for subsequent calls to the function) * the data and start calculating minimum, mean, variance measures anew. * Applications may use this function to report a single sample, or they may  * report statistical measurements from a collection of samples.  * The parameters to the function are: *   ospvTransaction: handle of the transaction object. *   ospvNumberOfSamples: the number of samples included in these statistics. *   ospvMinimum: the minimum delay, in milliseconds, measured within the current *                set of samples. If the function call is used to report a single *                sample, this parameter should indicate that measurement, and it *                should be equal to the value of the ospvMean parameter. *   ospvMean: the mean of the delay, in milliseconds, measured within the  *             current set of samples. If the function call is used to report a  *             single sample, this parameter should indicate that measurement,  *             and it should be equal to the value of the ospvMinimum parameter. *   ospvVariance: the variance of the delay, in square milliseconds, measured  *                 within the current set of samples. If the function call is  *                 used to report a single sample, this parameter should be zero. * The SDK library is able to perform this function without network interaction, * and, therefore, does not block for network input or output during its  * execution. * * returns OSPC_ERR_NO_ERROR if successful, else error code. */intOSPPTransactionAccumulateRoundTripDelay(    OSPTTRANHANDLE ospvTransaction,    /* In - Transaction handle */    unsigned       ospvNumberOfSamples,/* In - Number of samples included */    unsigned       ospvMinimum,        /* In - Minimum delay in milliseconds */    unsigned       ospvMean,           /* In - Mean of delay in milliseconds */    float          ospvVariance)       /* In - Variance of delay in square                            milliseconds */{    int         errorcode   = OSPC_ERR_NO_ERROR,                tnisnan       = OSPC_TRUE;    OSPTTRANS   *trans      = OSPC_OSNULL;    unsigned    currnumber  = 0;    double      topower     = 0,                mean        = 0,

⌨️ 快捷键说明

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