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

📄 jb_mgmt.cpp

📁 基于h323协议的软phone
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                        (Data**)&jbCb.conn, sizeof(JbConnKey*) * maxConnections);
            if (ret != ROK)
            {
                RETVALUE(RFAILED);
            }
            for (i=0;i<maxConnections;i++)
            {
                jbCb.conn[i] = NULLP;
            }
            jbCb.jbTqCp.tmrLen = JB_TQSIZE;
            for (i = 0; i < JB_TQSIZE; i++)
            {
                jbCb.jbTq[i].first = NULLP;
            }
            cmInitTimers(jbCb.jbTimers, maxConnections);
            /* GTC - WAS: SRegTmr(ENTJB, 1, jbCb.timerRes, (PFS16)jbActvTmr); */
/*            SRegTmr(ENTJB, WPTSTINST, jbCb.timerRes, (PFS16)jbActvTmr);
            cmHashListInit(&jbCb.connHlCp, maxConnections, 0, FALSE,
                            0, jbCb.jbInit.region, jbCb.jbInit.pool);*/
            break;

        case JIT:         /* buffer configuration request */
            jbCb.jitCfg.maxLatency = cfg->c.jitterCfg.maxLatency;
            jbCb.jitCfg.maxHoldTime = cfg->c.jitterCfg.maxHoldTime;
            jbCb.jitCfg.minSize = cfg->c.jitterCfg.minSize;
            jbCb.jitCfg.minStableTime = cfg->c.jitterCfg.minStableTime;
            jbCb.jitCfg.incAmount = cfg->c.jitterCfg.incAmount;
            jbCb.jitCfg.decAmount = cfg->c.jitterCfg.decAmount;
            jbCb.jitCfg.longSilenceTimer = cfg->c.jitterCfg.longSilenceTimer;
//            jbCb.jitCfg.longSilenceTimer.enb = cfg->c.jitterCfg.longSilenceTimer.enb;
//            jbCb.jitCfg.longSilenceTimer.val = cfg->c.jitterCfg.longSilenceTimer.val;
            break;
    }
    RETVALUE(ROK);
} /* JbCfgReq */


/*
*
*       Fun:   JbCntrlReq
*
*       Desc:  This function is used by the Wrapper to
*              set the active connection
*
*       Ret:   ROK on success and RFAILED when connection
*              specified does not exist.
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/
#ifdef ANSI
PUBLIC S16 JbCntrlReq
(
//SpId spId,                    /* desired spId */
S32 sessionId                 /* desired connection index */
)
#else
PUBLIC S16 JbCntrlReq(spId, sessionId)
SpId spId;                    /* desired spId */
S32 sessionId;                /* desired connection index */
#endif
{
    S16 sessionIndex;
    JbConnKey *key;

    TRC3(JbCntrlReq)

    sessionIndex = findSessionId(sessionId);

    if (sessionIndex==-1)
    {
        RETVALUE(RFAILED);
    }

    /* slm: MR8849 changed to index based on line number */
    key = jbCb.conn[sessionIndex];
    jbCb.activeConn[key->lineNo] = sessionIndex;
/* printf("jbCb.activeConn[%u] set to sessionIndex of %u\n",key->lineNo,jbCb.activeConn[key->lineNo]); */

    RETVALUE(ROK);
}


/*
*
*       Fun:   JbStaReq
*
*       Desc:  This function is used by the Wrapper to
*              retrieve statistics information
*
*       Ret:   ROK on success and RFAILED on failure
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/
#ifdef ANSI
PUBLIC S16 JbStaReq
(
//SpId  spId,                /* desired spId */
S32   sessionId,           /* desired connection */
JbSts *sts                 /* statistics structure */
)
#else
PUBLIC S16 JbStaReq(spId, sessionId, sts)
SpId  spId;        /* desired spId */
S32   sessionId;       /* desired connection */
JbCfg *sts;                /* statistics structure */
#endif
{
   S16 sessionIndex;
//    JbConnCb *connCb;

    TRC3(JbStaReq)

    switch (sts->type)
    {
        case CB:          /* Control Block statistics request */
//          cmMemcpy((U8*)&sts->s.jbCbSts, (U8*)&jbCb.sts, sizeof(jbCb.sts));
            memcpy((U8*)&sts->s.jbCbSts, (U8*)&jbCb.sts, sizeof(jbCb.sts));
            break;

        case CONN:        /* Connections statistics request */
            sessionIndex = findSessionId(sessionId);
            if (sessionIndex == -1)
            {
                RETVALUE(RFAILED);
            }
/*            if (cmHashListFind(&jbCb.connHlCp, (U8*)(*(jbCb.conn)+sessionIndex),
                                sizeof(JbConnKey), 0, (PTR*)&connCb) != ROK)
            {
                RETVALUE(RFAILED);
            }*/
//          cmMemcpy((U8*)&sts->s.jbConnSts, (U8*)&connCb->sts, sizeof(JbConnSts));
            memcpy((U8*)&sts->s.jbConnSts, (U8*)&connCb.sts, sizeof(JbConnSts));
            if (sts->clearConnSts)
            {
//              cmMemset((Data*)&connCb->sts, 0, sizeof(JbConnSts));
                memset((Data*)&connCb.sts, 0, sizeof(JbConnSts));
            }
            connCb.sts.currentJitter = 0;
            break;
    }
    RETVALUE(ROK);
}


/*
*
*       Fun:   JbConReq
*
*       Desc:  This function is used to connect
*              the jitter buffer up to an RTP session and DSP
*
*       Ret:   ROK on success, RFAILED on failure
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/
#ifndef INCLUDE_RV_RTP
extern RtpManager* rtpManager;
#endif

extern SEM_ID rtpSem;

#ifdef ANSI
PUBLIC S16 JbConReq
(
//SpId  spId,             /* Service Provider ID of RTP layer */
S32   sId,        /* ID of RTP session to connect to */
U8    txCodec,          /* Transmit Codec */
U8    rxCodec,          /* Receive Codec */
U16  maxAlSduFrames,   /* max frames per packet */
U16  payload,
U16  encodeRate
)
#else
PUBLIC S16 JbConReq(sId,
                    txCodec, rxCodec, maxAlSduFrames, payload, encodeRate)
//SpId  spId;             /* Service Provider ID of RTP layer */
S32   sId;        /* ID of RTP session to connect to */
U8    txCodec;          /* Transmit Codec */
U8    rxCodec;          /* Receive Codec */
U16   maxAlSduFrames;   /* max frames per packet */
U16  payload;
U16  encodeRate;
#endif
{

//    JbConnCb *connCb;
    vector<JbConnKey*>& conn = jbCb.conn;
    S16 i;
    S16 j;
    /* slm: MR4216 bumped from U8 to U16 */
    U16 frameSize;
//    Region region;
//    Pool pool;
    /* slm: MR4213 variable for encode rate */
    int encRate;

    TRC3(JbConReq)
    packetslostpercent = 0;
    firstseq = 0;
    lastseq = 0;
#ifdef DEBUG_JB
/* change rtc clock to 1ms */
jbrtc();
if( isT8300 )
{
    /* Set all GPIO ports to output level 0 */
    *((volatile ULONG *)0xE000C014) = 0;
    *((volatile ULONG *)0xE000C018) = 0x000FFFFF;
}
jbdbg_d_index = 0;
jbdbg_e_index = 0;
#endif

//    region = jbCb.jbInit.region;
//    pool = jbCb.jbInit.pool;


    if (jbCb.sts.activeConnections >= jbCb.genCfg.maxConnections)
    {
        fprintf(stderr, "jbConReq: Max connections (%u) exceeded\n", jbCb.genCfg.maxConnections );
        RETVALUE(RFAILED);
    }
//    connCb = new JbConnCb();
//    if (SGetSBuf(region, pool, (Data**)&connCb, sizeof(JbConnCb)) != ROK)
//    if (NULL == connCb)
//    {
//        fprintf(stderr, "jbConReq: SGetSBuf failed for JbConnCb\n");
//        RETVALUE(RFAILED);
//    }

    /* slm: MR8849 clear the entire connCb struct */
//  cmMemset((Data*)connCb, 0, sizeof(JbConnCb));
//    memset((Data*)connCb, 0, sizeof(JbConnCb));

    /* go through all the connections, use the first empty one */
//    for (i=0; (i < jbCb.genCfg.maxConnections); i++, conn++)
    for (i=0; i < conn.size(); i++)
    {
        /* found a NULL entry */
//        if ((*conn) == (JbConnKey *) NULL)
        if (conn[i] == NULL)
        {
	        ReSetConnCb(connCb, jbCb.genCfg.maxSize);

            connCb.connIndex = (U8)i;
            connCb.key.sessionId = sId;
//            connCb->key.spId = spId;
/* printf("JbConReq: assigned connIndex %u sessionId %u for spId %u\n",i,sessionId,spId); */
            connCb.key.txCodec = (CoderInfo)txCodec;
            connCb.key.rxCodec = (CoderInfo)rxCodec;

            /* slm: MR8849 add support for PPA */

#ifdef PPA
            /* Note: lineNo is cleared to 0 (above in cmMemset) for Non-PPA code */
            /* connCb->key.lineNo = (S16) SuConnIdToLine(spId); */
//            if(( connCb->key.lineNo < 0 ) || ( JB_MAX_LINENUMS <= connCb->key.lineNo ))
//            {
//                SPutSBuf(region, pool, (Data*)connCb, sizeof(JbConnCb));
//                fprintf(stderr, "jbConReq: lineNo(%d) error for suConnId=%u\n",
//                    connCb->key.lineNo, spId );
//                RETVALUE(RFAILED);
//            }
#endif

            /* MWB: MaxLatency from jitCfg is now 16 bits and in units of "packets" */
            connCb.jitter.maxLatency = jbCb.jitCfg.maxLatency;

//            if (SGetSBuf(region, pool, (Data**)&connCb->jitter.jBuf,
//                        jbCb.genCfg.maxSize*sizeof(JBuf)) != ROK)
//            {
//                SPutSBuf(region, pool, (Data*)connCb, sizeof(JbConnCb));
//                RETVALUE(RFAILED);
//            }
            /* slm: MR4213 use raw frame size */

#ifndef INCLUDE_RV_RTP
            GETRAWFRAMESIZE(rxCodec, frameSize);
            frameSize *= maxAlSduFrames;

            /* slm: MR4213 save max frame size */
            connCb.jitter.maxAlSduFrames = maxAlSduFrames;
#endif

#ifndef JB_TERSE
            {
                char *rc="????";
                char *ms="ms";
                switch ( rxCodec )
                {
                    case JB_G711:
                        rc="G711";
                        break;
                    case JB_G722:
                        rc="G722";
                        break;
                    case JB_G723:
                        rc="G723";
                        ms="frames";
                        break;
                    case JB_G726_32:
                        rc="G726";
                        break;
                    case JB_G729:
                        rc="G729";
                        ms="frames";
                        break;
                }
//                printf("jbConReq[%u]: sess=%u spId=%u coder=%s %s=%d size=%u\n",
//                    i, sessionId, spId, rc, ms, (S16) maxAlSduFrames, frameSize );
                 printf("jbConReq[%u]: sess=%u coder=%s %s=%d size=%u\n",
                    i, sId, rc, ms, (S16) maxAlSduFrames, frameSize );
            }
#endif
            for (j=0;j<jbCb.genCfg.maxSize;j++)
//            {
//                if (SGetSBuf(region, pool,
//                        (Data**)&connCb->jitter.jBuf[j].buffer,
//                        frameSize*sizeof(Data)) != ROK)
//                {
//                    fprintf(stderr, "jbConReq[%u]: SGetSBuf failed for jBuf[%u]\n", i, j);
//                    for (;j>0;j--)
//                    {
//                        SPutSBuf(region, pool,
//                            (Data*)connCb->jitter.jBuf[j-1].buffer,
//                            frameSize*sizeof(Data));
//                    }
//                    SPutSBuf(region, pool, (Data*)connCb->jitter.jBuf,
//                            jbCb.genCfg.maxSize*sizeof(JBuf));
//                    SPutSBuf(region, pool, (Data*)connCb, sizeof(JbConnCb));
//                    RETVALUE(RFAILED);
//                }
                /* slm: use len instead of seqNum since 0 is a valid seqnum
                ** connCb->jitter.jBuf[i].seqNum = 0;
                */
                connCb.jitter.jBuf[j].len = 0;
//            }
            conn[i] = &connCb.key;
/*
#ifndef JB_TERSE
printf("Wrote *conn (0x%x) with address 0x%x for index %u\n", &(*conn), &connCb->key, i);
#endif
*/
            connCb.sts.jitterBufferSize = jbCb.jitCfg.minSize;
            break;
        }
    }
//    if (cmHashListInsert(&jbCb.connHlCp, (PTR)connCb,
//            (U8*)&connCb->key, sizeof(JbConnKey)) != ROK)
//    if (jbCb.connHlCp.insert(
//    {
//        fprintf(stderr, "jbConReq: cmHashListInsert failed for JbConnKey\n");
//        SPutSBuf(region, pool, (Data*)connCb, sizeof(JbConnCb));
//        RETVALUE(RFAILED);
//    }
    jbCb.sts.activeConnections++;
    jbCb.sts.totalConnections++;
    /* slm: MR8849 changed to index based on line number */
    connCb.key.lineNo = 0;
    jbCb.activeConn[connCb.key.lineNo] = (U8)connCb.connIndex;

/* printf("For new connection, jbCb.activeConn set to %u\n",jbCb.activeConn); */
#ifndef INCLUDE_RV_RTP
    /* slm: MR4213 support variable rates */
    switch( payload )
    {
        case RTP_PT_G722:
//            encRate = _sap(spId).currConCb->encodeRate / JB_G722_MS_PER_FRAME;
            encRate = encodeRate / JB_G722_MS_PER_FRAME;
#ifndef JB_TERSE
            printf("Encoding %u frames of G722\n", encRate);
#endif
            break;

        case RTP_PT_G726_32:
//            encRate = _sap(spId).currConCb->encodeRate / JB_G726_32_MS_PER_FRAME;
             encRate = encodeRate / JB_G726_32_MS_PER_FRAME;
#ifndef JB_TERSE
            printf("Encoding %u frames of G726-32\n", encRate);
#endif
            break;

        case RTP_PT_G723:
//            encRate = _sap(spId).currConCb->encodeRate;
            encRate = encodeRate;
#ifndef JB_TERSE
            printf("Encoding %u frames of G723\n", encRate);
#endif
            break;

        case RTP_PT_G729:
//            encRate = _sap(spId).currConCb->encodeRate;
            encRate = encodeRate;
#ifndef JB_TERSE
            printf("Encoding %u frames of G729\n", encRate);
#endif
            break;

        default:
//            encRate = _sap(spId).currConCb->encodeRate / JB_G711_MS_PER_FRAME;
            encRate = encodeRate / JB_G711_MS_PER_FRAME;
#ifndef JB_TERSE
            printf("Encoding %u frames of G711\n", encRate);
#endif
            break;
    }

#else

	switch (txCodec)
	{
		case JB_G722:
		encRate = 6;
#ifndef JB_TERSE
		printf("Encoding %u frames of G722\n", encRate);
#endif
		break;

        case JB_G726_32:
		encRate = 6;
#ifndef JB_TERSE
            printf("Encoding %u frames of G726-32\n", encRate);
#endif
            break;

        case JB_G723:
            encRate = 1;
#ifndef JB_TERSE
            printf("Encoding %u frames of G723\n", encRate);
#endif
            break;

        case JB_G729:
            encRate = 2;
#ifndef JB_TERSE
            printf("Encoding %u frames of G729\n", encRate);
#endif
            break;

        default:
            encRate = 2;
#ifndef JB_TERSE
            printf("Encoding %u frames of G711\n", encRate);
#endif
            break;
	}

            GETRAWFRAMESIZE(rxCodec, frameSize);
            frameSize *= encRate;

            /* slm: MR4213 save max frame size */
#if 0
		if(txCodec == JB_G729)
			connCb.jitter.maxAlSduFrames = 6;
           	else
			connCb.jitter.maxAlSduFrames = encRate;
#endif
		connCb.jitter.maxAlSduFrames = encRate;
		if (txCodec == JB_G711)
            	{
            		frameSize *= 10;
			connCb.jitter.maxAlSduFrames *= 10*6;/**60ms**/
            	}
		else if (txCodec == JB_G723)
			connCb.jitter.maxAlSduFrames = 2;
		else if(txCodec == JB_G729)
			connCb.jitter.maxAlSduFrames = 6;	
		
	

#endif

    /* slm: MR5118 Increase stack space for both put and get managers to prevent stack overflow */
    /* slm: MR4213 change argument to jbDspGetManager to pass encode rate variable */
    /* reset variable that controls the task exit */
//    fRequestGetMgrTaskStop[spId] = 0;
//    jbTId = taskSpawn("tGetMgr", 41, 0, 8192, (FUNCPTR)jbDspGetManager,
//                        (int)(JbConnKey**)conn, encRate,
//                        (U8)connCb.connIndex, 0, 0, 0, 0, 0, 0, 0);

    fRequestGetMgrTaskStop[sId % MAX_RTP_SESSION] = 0;
    jbTId = taskSpawn("tGetMgr", 41, 0, 8192, (FUNCPTR)jbDspGetManager,
                        encRate, (U8)connCb.connIndex, 0, 0, 0, 0, 0, 0, 0, 0);

    /* reset variable that controls the task exit */
//    fRequestPutMgrTaskStop[spId] = 0;
//    jbTId = taskSpawn("tPutMgr", 40, 0, 4096, (FUNCPTR)jbDspPutManager,
//                        (int)(JbConnKey**)conn, (U8)connCb.connIndex,
//                        0, 0, 0, 0, 0, 0, 0, 0);

    fRequestPutMgrTaskStop[sId % MAX_RTP_SESSION] = 0;
    jbTId = taskSpawn("tPutMgr", 40, 0, 4096, (FUNCPTR)jbDspPutManager,

⌨️ 快捷键说明

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