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

📄 jb_mgmt.cpp

📁 基于h323协议的软phone
💻 CPP
📖 第 1 页 / 共 3 页
字号:

/********************************************************************20**

     Nhce:     Jitter Buffer - management

     Type:     C source file

     Desc:     Management file for Jitter Buffer.  This file is the
               interface to the Wrapper Module

     File:     jb_mgmt.c

     Sid:      jb_mgmt.c 1.0  -  01/21/2000

     Prg:      sdg

     Revision History
     11/06/2000         mwb         Fixed latency value in JbConReq()
*********************************************************************21*/


/************************************************************************

Upper layer primitives:

The following functions are provided in this file:

   JbConfigReq      Config Request
   JbCtrlReq        Control Request
   JbConReq     Connect Request
   JbDiscReq        Disconnect Request
   JbStaReq     Statistics Request
   jbActvInit       Task Init routine

************************************************************************/


/* header include files (.h) */

//#include "envopt.h"        /* environment options */
//#include "envdep.h"        /* environment dependent */
//#include "envind.h"        /* environment independent */
//#include "gen.h"           /* general layer */
//#include "ssi.h"           /* system services */
//#include "cm_tkns.h"       /* common tokens */
//#include "cm_inet.h"       /* sockets related */
//#include "cm_tpt.h"        /* common transport */
//#include "cm_hash.h"       /* hash list */
//#include "cm_llist.h"      /* llist mgmt*/
//#include "cm5.h"           /* common timer */
//#include "cm_mblk.h"       /* common memory alloc */
//#include "cm32x.h"         /* encoding/decoding */
//#include "lhi.h"           /* TUCL layer mngmt */
//#include "hit.h"           /* H.323 Control lower i/f */
//
//#ifdef HC
//#include "lhc.h"           /* H.323 Control layer mngmt */
//#include "hct.h"           /* H.323 control upper i/f */
//#include "wpsmhc.h"
//#endif
//
//#ifdef HR
//#include "hrt.h"                /* HR upper interface defines */
//#include "lhr.h"                /* HR layer management defines */
//#include "hr_err.h"             /* HR error defines */
//#include "hr_acc.h"
//#endif
#if 0
#include <stdio.h>
#include <time.h>
#include <sys/times.h>
#endif

#include "stdafx.h"
#include "myphone.h"
#include "myphoneDlg.h"

#include "jb.h"		       /* Jitter Buffer definitions */
//#include "jb.x"            /* Jitter Buffer structures/prototypes */

//#ifdef HC
//#include "hc_acc.h"
//#endif
//
//#ifdef SO
//#include "lso.h"
//#include "sot.h"    /* SOT definitions */
//#include "so_macros.h"
//#include "wpsmso.h"
//#endif
//
//#include "ss_gen.h"
//#include "wp.h"            /* wrapper defines - added GTC */
//
//#include "gen.x"           /* general layer */
//#include "ssi.x"           /* system services */
//#include "cm_tkns.x"       /* common tokens */
//#include "cm_inet.x"       /* common sockets */
//#include "cm_tpt.x"        /* common transport */
//#include "cm_lib.x"        /* commmon Library */
//#include "cm_hash.x"       /* hashing functions */
//#include "cm_llist.x"      /* llist mngmt */
//#include "cm5.x"           /* timer functions */
//#include "cm_mblk.x"       /* common memory alloc */
//#include "cm32x.x"         /* encoding/decoding */
//#include "poac.h"
//#include "lhi.x"           /* TUCL layer mngmt */
//#include "hit.x"           /* H.323 Control lower i/f */

//#ifdef HR
//#include "hrt.x"                /* HR upper interface types */
//#include "lhr.x"
//#include "hr_acc.x"
//#endif


//#ifdef HC
//#include "lhc.x"           /* H.323 Control layer mngmt */
//#include "hct.x"           /* H.323 Control layer mngmt */
//#include "hc_acc.x"
//#endif

//#ifdef SO
//#include "cm_sdp.x"
//#include "lso.x"
//#include "sot.x"    /* SOT structure definitions */
//#include "so_acc.x"
//#endif

/* slm: MR8849 add support for ppa */
//#ifdef PPA
//#include "h/drv/ppa/ppa-app.h"
//#endif



/* local defines */

/* local typedefs */


/* local externs */


/* forward references */
//PRIVATE S16 findSessionId ARGS((SpId spId, S32 sessionId));
PRIVATE S16 findSessionId ARGS((S32 sessionId));

/* public variable declarations */

JbCb jbCb;
int jbTId=0;
/* slm: MR5637 use define for array size */
#ifdef HC
int fRequestjbReadTaskStop[WP_SM_HC_MAX_SSAPS]= {0};
int fRequestGetMgrTaskStop[WP_SM_HC_MAX_SSAPS]= {0};
int fRequestPutMgrTaskStop[WP_SM_HC_MAX_SSAPS]= {0};
#endif /* HC */
#ifdef SO
int fRequestjbReadTaskStop[WP_SM_SO_MAX_SSAPS]= {0};
int fRequestGetMgrTaskStop[WP_SM_SO_MAX_SSAPS]= {0};
int fRequestPutMgrTaskStop[WP_SM_SO_MAX_SSAPS]= {0};
#endif /* SO */
#ifdef MGCP
int fRequestjbReadTaskStop[MAX_RTP_SESSION]= {0};
int fRequestGetMgrTaskStop[MAX_RTP_SESSION]= {0};
int fRequestPutMgrTaskStop[MAX_RTP_SESSION]= {0};
#endif /* MGCP */

JbConnCb connCb;

#define SIMMAXDELAY 8 /* Power of 2 */
typedef struct jitSimBuf {
       U8 data[JB_MAX_BUF_SIZE];
       HrRtpHdr rtpHdr;
} JitSimBuf;

typedef struct jitSim {
       JitSimBuf jitSimBuf[SIMMAXDELAY];
       S16 p;
       S16 q;
       S16 burstAmount;
       S16 delayAmount;
} JitSim;

JitSim jitSim;
S16 jitSimPercent = 0;
S16 jitSimDelay = 0;
S16 jitSimOutOfOrder = FALSE;

extern float packetslostpercent; 
int firstseq = 0;
int lastseq = 0;

#ifdef DEBUG_JB
extern U32 jbdbg_d_index;
extern U32 jbdbg_e_index;
extern JbDebug_d jbdbg_d[];
extern JbDebug_e jbdbg_e[];
U32 isT8300 = 0;
int jbrtc()
{
    if( ( *((volatile ULONG *)0xE0000010) & 0xFFFF0000 ) == 0x83000000 )
        isT8300 = 1;

    if( isT8300 )
    {
        *((volatile ULONG *)0xE0000600) = 0;
        taskDelay(1);
        *((volatile ULONG *)0xE0000604) = 1023;
        taskDelay(1);
        *((volatile ULONG *)0xE0000600) = 1;
        taskDelay(sysClkRateGet());
        printf("RTC set for 1ms rate\n");
    }
    return 0;
}
int jbclrd()
{
    jbdbg_d_index = 0;
    return 0;
}
int jbclre()
{
    jbdbg_e_index = 0;
    return 0;
}
int jbdumpd(U32 cnt)
{
    U32 i;
    U32 limit;
    U32 lastRcvTS=0;
    U32 lastPlayTS=0;
    U32 lastSilTS=0;

    if(cnt == 0)
        limit = jbdbg_d_index;
    else
        limit = (cnt < jbdbg_d_index) ? cnt : jbdbg_d_index;

    printf("Elapsed          play     packet   seq           p-q      num     delta\n");
    printf("Time      state  timestmp timestmp num   fr len  idx  dif pkt jit time\n");
/*
            031121ms ply  P 246480   246480   24037 3  240  2 6  4   4   1   (30ms)
        printf("%6ums %s %c c%-8u p%-8u s%-5u f%-2u l%-3u p%u q%u d%u r%d j%d (%ums)\n",
*/
    for(i=0; i<limit; i++)
    {
        printf("%7ums %s %c %-8u %-8u %-5u %-2u %-4u %u %-2u %-2u  %-2d  %-2d  (%ums)\n",
            jbdbg_d[i].timestamp,
            (jbdbg_d[i].op == JB_RECEIVE_PACKET) ? " rcv" :
            (jbdbg_d[i].op == JB_PLAY_PACKET) ? "ply " : " si ",
            (jbdbg_d[i].state == JB_ACTIVE_PLAY) ? 'P' :
            (jbdbg_d[i].state == JB_ACTIVE_HOLD) ? 'H' :
            (jbdbg_d[i].state == JB_UNDERFLOW) ? 'U' : 'S',
            jbdbg_d[i].curtimestamp, jbdbg_d[i].pkttimestamp,
            jbdbg_d[i].seq, jbdbg_d[i].frames, jbdbg_d[i].length,
            jbdbg_d[i].p, jbdbg_d[i].q, (((U32)jbdbg_d[i].q - (U32)jbdbg_d[i].p) & (jbCb.genCfg.maxSize - 1)),
            jbdbg_d[i].numPackets, jbdbg_d[i].jitterBufferSize,
            (jbdbg_d[i].op == JB_RECEIVE_PACKET) ? (jbdbg_d[i].timestamp - lastRcvTS) :
            (jbdbg_d[i].op == JB_PLAY_PACKET) ? (jbdbg_d[i].timestamp - lastPlayTS) : (jbdbg_d[i].timestamp - lastSilTS)
            );

        if(jbdbg_d[i].op == JB_RECEIVE_PACKET)
            lastRcvTS = jbdbg_d[i].timestamp;
        else if(jbdbg_d[i].op == JB_PLAY_PACKET)
            lastPlayTS = jbdbg_d[i].timestamp;
        else
            lastSilTS = jbdbg_d[i].timestamp;
    }
}
int jbdumpe(U32 cnt)
{
    U32 i;
    U32 limit;

    if(cnt == 0)
        limit = jbdbg_e_index;
    else
        limit = (cnt < jbdbg_e_index) ? cnt : jbdbg_e_index;

    printf("%5ums pts%-8u f%-2u l%-3u\n",
        jbdbg_e[0].timestamp, jbdbg_e[0].pkttimestamp, jbdbg_e[0].frames, jbdbg_e[0].length);

    for(i=1; i<limit; i++)
    {
        printf("%5ums pts%-8u f%-2u l%-3u (%ums)\n",
            jbdbg_e[i].timestamp, jbdbg_e[i].pkttimestamp, jbdbg_e[i].frames, jbdbg_e[i].length,
            jbdbg_e[i].timestamp - jbdbg_e[i-1].timestamp);
    }
}
#endif

/* private variable declarations */

void ReSetConnCb(JbConnCb& cb, int jitLen)
{
	cb.connIndex = 0;
	memset((void*)&cb.key, 0, sizeof(cb.key));
	memset((void*)&cb.sts, 0, sizeof(cb.sts));
	cb.jitter.bufferCreep = 0;
	cb.jitter.bufferDrop = 0;
	cb.jitter.currentStableTime = 0;
	cb.jitter.curTimestamp = 0;
	cb.jitter.dropWait = 0;
	cb.jitter.gotFirst = 0;
	cb.jitter.lastSeqNum = 0;
	cb.jitter.maxAlSduFrames = 0;
	cb.jitter.maxJitter = 0;
	cb.jitter.maxLatency = 0;
	cb.jitter.p = 0;
	cb.jitter.playAttempts = 0;
	cb.jitter.playPacketCount = 0;
	cb.jitter.q = 0;
	cb.jitter.receivePacketCount = 0;
	cb.jitter.state = (JbState)0;

	for (int i = 0; i < jitLen; i++)
	{
		cb.jitter.jBuf[i].len = 0;
		cb.jitter.jBuf[i].seqNum = 0;
		cb.jitter.jBuf[i].timeStamp = 0;
	}
}

/*
*
*       Fun:   jbActvInit
*
*       Desc:  This function is used to initialize the JitterBuffer
*
*       Ret:   Nothing
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/
#ifdef ANSI
PUBLIC S16 jbActvInit
(
//Ent entity,            /* entity */
//Inst inst,             /* instance */
//Region region,         /* region */
//Reason reason          /* reason */
)
#else
PUBLIC S16 jbActvInit(entity, inst, region, reason)
Ent entity;            /* entity */
Inst inst;             /* instance */
Region region;         /* region */
Reason reason;         /* reason */
#endif
{
    S16 i;

    TRC3(jbActvInit)

//    jbCb.jbInit.ent = entity;
//    jbCb.jbInit.inst = inst;
//    jbCb.jbInit.region = region;
//    jbCb.jbInit.reason = reason;
//    jbCb.jbInit.procId = SFndProcId();
    jbCb.genCfg.cfgDone = FALSE;
    jbCb.timerRes = JB_DEFAULT_TIMER_RES;
  jbCb.sem = semBCreate( SEM_Q_PRIORITY, SEM_EMPTY );
  semGive(jbCb.sem);
    /* slm: MR4386 Need semaphore to protect DSP writes */
    /* slm: MR8849 changed to index based on line number */
  for( i=0; i < NELEMENTS(jbCb.dspSem); i++ )
  {
      jbCb.dspSem[i] = semBCreate( SEM_Q_FIFO, SEM_EMPTY );
      semGive(jbCb.dspSem[i]);
  }

    RETVALUE(ROK);
} /* jbActvInit */


/*
*
*       Fun:    activate task
*
*       Desc:   Dummy activate task for jb.  Only necessary so I can register timers
*
*       Ret:    ROK  - ok
*
*       Notes:  None
*
*       File:   jb_mgmt.c
*
*/

//#ifdef ANSI
//PUBLIC S16 jbActvTsk
//(
//Pst *pst,                   /* post */
//Buffer *mBuf                /* message buffer */
//)
//#else
//PUBLIC S16 jbActvTsk(pst, mBuf)
//Pst *pst;                   /* post */
//Buffer *mBuf;               /* message buffer */
//#endif
//{
//    RETVALUE(ROK);
//}


/*
*
*       Fun:   JbCfgReq
*
*       Desc:  This function is used by the Wrapper to
*              configure the Jitter Buffer.
*
*       Ret:   ROK on success and RFAILED on failure
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/

#ifdef ANSI
PUBLIC S16 JbCfgReq
(
JbCfg *cfg                 /* configuration structure */
)
#else
PUBLIC S16 JbCfgReq(cfg)
JbCfg *cfg;                /* configuration structure */
#endif
{
//    Size     sMemSize=0;
    S16      maxSize;
    S16      maxConnections;
    S16      i;
    S16      ret;

    TRC3(JbCfgReq)
    switch (cfg->type)
    {
        case GEN:         /* general configuration request */
            if (jbCb.genCfg.cfgDone)
            {
                RETVALUE(RFAILED);
            }
            if (cfg->c.genCfg.maxConnections > JB_MAX_LINENUMS)
            {
                RETVALUE(RFAILED);
            }

            maxConnections = cfg->c.genCfg.maxConnections;
            maxSize = cfg->c.genCfg.maxSize;
            jbCb.genCfg.cfgDone = TRUE;
            jbCb.genCfg.maxConnections = maxConnections;
            jbCb.genCfg.maxSize = maxSize;

            jbCb.jbTimers.resize(maxConnections, -1);
            jbCb.conn.resize(maxConnections, NULL);
//            for (i = 0; i < maxConnections; i++)
//            {
//                jbCb.conn[i].sessionId = -1;
//            }

            jbCb.connHlCp.resize(maxConnections);

            connCb.jitter.jBuf = new JBuf[maxSize];
            for (i = 0; i < maxSize; i++)
            {
                connCb.jitter.jBuf[i].buffer = new Data[JB_MAX_BUF_SIZE];
                connCb.jitter.jBuf[i].len = 0;
            }
            ReSetConnCb(connCb, maxSize);
//            sMemSize += (sizeof(CmTimer) * maxConnections);
//            sMemSize += (sizeof(JbConnKey*) * maxConnections);
//            sMemSize += (sizeof(JbConnCb) * maxConnections);
//            sMemSize += (CM_HASH_BINSIZE * maxConnections);
            /* slm: need to multiply by maxConnections
            ** MAX_FRAMES_SIZE needs to be multiplied by
            ** maxSize since JbCfgReg will alloc these within
            ** a for loop upto maxSize
            ** sMemSize += (sizeof(JBuf) * maxSize);
            ** sMemSize += (sizeof(Data) * JB_MAX_BUF_SIZE);
            */
/*            sMemSize += (sizeof(JBuf) * maxSize * maxConnections);
            sMemSize += (sizeof(Data) * JB_MAX_BUF_SIZE * maxSize * maxConnections);
            ret = SGetSMem(jbCb.jbInit.region, (Size) sMemSize,
                           &jbCb.jbInit.pool);
            if (ret != ROK)
            {
                RETVALUE(LCM_REASON_MEM_NOAVAIL);
            }
            ret = SGetSBuf(jbCb.jbInit.region, jbCb.jbInit.pool,
                        (Data**)&jbCb.jbTimers, sizeof(CmTimer) * maxConnections);
            if (ret != ROK)
            {
                RETVALUE(RFAILED);
            }
            ret = SGetSBuf(jbCb.jbInit.region, jbCb.jbInit.pool,

⌨️ 快捷键说明

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