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

📄 jb_mgmt.cpp

📁 基于h323协议的软phone
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                        (U8)connCb.connIndex, 0, 0, 0, 0, 0, 0, 0, 0, 0);

/* slm: MR2092 TUCL changes no longer require us to run a task that reads the socket */
/*             TUCL changes now read the socket within the stack */
/* slm: MR4213 Above comment is incorrect
**             JbReadSocket() stopped working due to TUCL changes in HiConCb struct
**             which did NOT match JbConCB struct.  Therefore the offset to the
**             file descriptor was wrong and readfrom() was returning an error
**             trying to read file descriptor 0.
**             JbConCb has been updated to match HiConCb, so now we can spawn
**             the jbReadMgr Task.  This task reads the socket faster than the
**             Trillium stack reads it because Trillium only polls the socket
**             once every tick (10ms).  Polling every 10ms is not fast enough to
**             handle network jitter when receiving data that's encoded at a
**             10ms rate.
*/

    /* reset variable that controls the task exit */
    fRequestjbReadTaskStop[sId % MAX_RTP_SESSION] = 0;
#ifndef INCLUDE_RV_RTP
    taskSpawn("tJbReadMgr", 40, 0, 6000, (FUNCPTR)jbReadSocket,
            (U8)connCb.connIndex, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#else
    semTake(rtpSem, WAIT_FOREVER);
    rtpSetEventHandler(wpCallInfo[sId].rtpSession, jbReadSocket, (void *)(&connCb.connIndex));
    semGive(rtpSem);
#endif
//    cmMemset((U8*)&jitSim, 0, sizeof(jitSim));
    memset((U8*)&jitSim, 0, sizeof(jitSim));
    jitSim.burstAmount = 1;

    RETVALUE(ROK);
}


/*
*
*       Fun:   JbDiscReq
*
*       Desc:  This function is used to disconnect
*              the jitter buffer from an RTP session and DSP
*
*       Ret:   ROK on success, RFAILED on failure
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/
/*GTC - WAS: extern JbConCb *jbUdpConCb; /* sdg udpfix */
//extern JbConCb *jbUdpConCb[]; /* sdg udpfix */

#ifdef ANSI
PUBLIC S16 JbDiscReq
(
//SpId  spId,             /* Service Provider ID of RTP layer */
S32   sId,        /* ID of RTP session to connect to */
U16   maxAlSduFrames    /* max frames per packet */
)
#else
PUBLIC S16 JbDiscReq(sId, maxAlSduFrames)
//SpId  spId;             /* Service Provider ID of RTP layer */
S32   sId;        /* ID of RTP session to connect to */
U16   maxAlSduFrames;   /* max frames per packet */
#endif
{
    JbConnKey *key;
//    JbConnCb *connCb;
    /* slm: MR4216 bumped from U8 to U16 */
    U16 frameSize;
    S16 i;
//    Region region;
//    Pool pool;
	S32 sessionId;
    S16 sessionIndex;
    S16 ret;
    S32 packetscount = lastseq - firstseq;
    TRC3(JbDiscReq)
	if(packetscount > 0)	
       	packetslostpercent = ((float)(packetscount+connCb.sts.packetsRedundant-connCb.sts.packetsRx)*100)/packetscount;
	else
		packetslostpercent = 0;
	if(packetslostpercent < 0)
		packetslostpercent = 0;
//    region = jbCb.jbInit.region;
//    pool = jbCb.jbInit.pool;
	
/* printf("JbDiscReq: calling findSessionId with spId %u, sessionId %u\n",spId, sessionId); */
	sessionId = sId % MAX_RTP_SESSION;
    sessionIndex = findSessionId(sessionId);
/* printf("JbDiscReq: findSessionId found sessionIndex=%d\n",sessionIndex); */
    if (sessionIndex==-1)
    {
        RETVALUE(RFAILED);
    }
    key = jbCb.conn[sessionIndex];

//    if (cmHashListFind(&jbCb.connHlCp, (U8*)(key),
//         sizeof(JbConnKey), 0, (PTR*)&connCb) != ROK)
//    {
//        fprintf( stderr, "JbDiscReq: cmHashListFind failed for JbConnKey\n");
//        RETVALUE(RFAILED);
//    }
    if ((connCb.jitter).state == JB_UNDERFLOW)
    {
        JbStopTimer(&connCb); /* In case we disconnect during and underflow */
    }

    /* slm: MR4213 use raw frame size */
    GETRAWFRAMESIZE(key->rxCodec, frameSize);
    frameSize *= maxAlSduFrames;

#ifndef JB_TERSE
    {
        char *rc="????";
        char *ms="ms";
        switch ( key->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("jbDiscReq[%u]: sess=%u coder=%s %s=%d size=%u\n",
            sessionIndex, sessionId, rc, ms, (S16) maxAlSduFrames, frameSize );
    }
#endif

    fRequestjbReadTaskStop[sessionId] = 1 ;
    fRequestGetMgrTaskStop[sessionId] = 1 ;
    fRequestPutMgrTaskStop[sessionId] = 1 ;

#ifdef INCLUDE_RV_RTP
	semTake(rtpSem, WAIT_FOREVER);
	rtpClose(wpCallInfo[sId].rtpSession);
	wpCallInfo[sId].rtpSession = NULL;
	semGive(rtpSem);

#endif
    /*
     * stop the jbRead & other tasks
     *
     * 1 - Request outstanding that the timer task stop
     * 0 - Timer task has stopped
     */

    /*
     * request it to stop
     */
// 	fRequestjbReadTaskStop[spId] = 1 ;
//    fRequestGetMgrTaskStop[spId] = 1 ;
//    fRequestPutMgrTaskStop[spId] = 1 ;
	
    {
     int k;
     for(k=0;k<50;k++)
     {
//      if(fRequestjbReadTaskStop[spId] == 0)
      if(fRequestjbReadTaskStop[sessionId] == 0)
      {
        break;
      }
      taskDelay(1);
     }
     /* printf("JBREAD Stopped, K=%d\n",k); */

       for(k=0;k<50;k++)
       {
//        if(fRequestGetMgrTaskStop[spId] == 0)
        if(fRequestGetMgrTaskStop[sessionId] == 0)
        {
          break;
        }
        taskDelay(1);
       }
       /* printf("GetMgr Stopped, K=%d\n",k); */

       for(k=0;k<50;k++)
       {
//        if(fRequestPutMgrTaskStop[spId] == 0)
        if(fRequestPutMgrTaskStop[sessionId] == 0)
        {
          break;
        }
        taskDelay(1);
       }
       /* printf("PutMgr Stopped, K=%d\n",k); */
    }

    /*
     * assume they have stopped
     */
//    jbUdpConCb[spId] = 0;

//
//   for multi-rtpSession
//   just recyte connCb
//
//    for (i=0;i<jbCb.genCfg.maxSize;i++)
//    {
//        SPutSBuf(region, pool,
//                (Data*)connCb->jitter.jBuf[i].buffer,
//                frameSize*sizeof(Data));
//    }
//    SPutSBuf(region, pool, (Data*)connCb->jitter.jBuf,
//            jbCb.genCfg.maxSize*sizeof(JBuf));

//    cmHashListDelete(&jbCb.connHlCp,(PTR)connCb);

//    SPutSBuf(region, pool, (Data*)connCb, sizeof(JbConnCb));
/* printf("Setting jbCb.conn to NULLP for sessionIndex = %u\n", sessionIndex); */
    jbCb.conn[sessionIndex] = NULL;
    jbCb.sts.activeConnections--;
/* printf("activeConnections reduced to %u\n",jbCb.sts.activeConnections); */

    RETVALUE(ROK);
}


/*
*
*       Fun:   JbDatInd
*
*       Desc:  This function is used to indicate data
*              from the session
*
*       Ret:   ROK on success, RFAILED on failure
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/
#ifdef ANSI
PUBLIC S16 JbDatInd
(
//SpId  spId,           /* Service Provider ID of RTP layer */
S32   sId,                  /* ID of RTP session to connect to */
HrRtpHdr *rtpHdr,         /* rtp header */
Data *dBuf            /* Data */
)
#else
PUBLIC S16 JbDatInd(sId, rtpHdr, dBuf)
//SpId  spId;           /* Service Provider ID of RTP layer */
S32   sId;                  /* ID of RTP session to connect to */
HrRtpHdr *rtpHdr;         /* rtp header */
Data *dBuf;           /* Data */
#endif
{
    JbConnKey *key;
//    JbConnCb *connCb;
    S16 sessionIndex;

//    TRC3(JbDatInd)

    sessionIndex = findSessionId(sId % MAX_RTP_SESSION);
    if (sessionIndex==-1)
    {
        RETVALUE(RFAILED);
    }
    key = jbCb.conn[sessionIndex];

//    if (cmHashListFind(&jbCb.connHlCp, (U8*)(key),
//         sizeof(JbConnKey), 0, (PTR*)&connCb) != ROK)
//    {
//        RETVALUE(RFAILED);
//    }

    if( rtpHdr->getPayloadUsage() > sizeof(jitSim.jitSimBuf[0].data))
        rtpHdr->setPayloadUsage(sizeof(jitSim.jitSimBuf[0].data));
	
//    cmMemcpy(jitSim.jitSimBuf[jitSim.q].data, dBuf, rtpHdr->dataLen);
//    cmMemcpy((U8*)&jitSim.jitSimBuf[jitSim.q].rtpHdr, (U8*)rtpHdr, sizeof(HrRtpHdr));
    memcpy(jitSim.jitSimBuf[jitSim.q].data, dBuf, rtpHdr->getPayloadSize());
    memcpy((U8*)&(jitSim.jitSimBuf[jitSim.q].rtpHdr), (U8*)rtpHdr, sizeof(HrRtpHdr));
    jitSim.q = (jitSim.q+1)&(SIMMAXDELAY-1);
    if ((jitSim.delayAmount == 0) && (jitSim.burstAmount == 1))
    {
//        Random tmp;
//        Random tmp2;

//        SRandom(&tmp);
//        SRandom(&tmp2);
        U32 tmp = rand();
        srand(tmp);
        U32 tmp2 = rand();
        srand(tmp2);

        if (tmp < (655 * jitSimPercent))
        {
            jitSim.delayAmount = (S16)(((S32)((S32)(tmp2) * (S32)(jitSimDelay)))>>16)+1;
            jitSim.burstAmount = jitSim.delayAmount + 1;
        }
    }

    if (jitSim.delayAmount == 0)
    {
        U16 tmp;
        U16 tmp2 = 0;
        U16 index = 0;
//        Random tmp3;
        U32 tmp3 = rand();

        for (tmp = 0; tmp < jitSim.burstAmount; tmp++)
        {
            if (jitSimOutOfOrder == FALSE)
            {
                index = tmp;
            }
            else
            {
//                SRandom(&tmp3);
                srand(tmp3);
                tmp3 = 1<<((S16)(((S32)((S32)(tmp3)*(S32)(jitSim.burstAmount)))>>16));

                while (tmp3 & tmp2)
                {
                    tmp3 = tmp3 << 1;
                    if (tmp3 & (1 << jitSim.burstAmount))
                    {
                        tmp3 = 1;
                    }
                }
                tmp2 = tmp2 | tmp3;

                while (tmp3 != 1)
                {
                    tmp3 = tmp3 >> 1;
                    index++;
                }
            }

#ifdef DEBUG_JB
if( jbdbg_d_index < MAX_JBDBG )
{
//semTake(jbCb.sem, WAIT_FOREVER);
   semTake(jbCb.sem, JB_MAX_TICKS);
if (errnoGet() == S_objLib_OBJ_TIMEOUT)
{
	errnoSet(0);
	break;
}

jbdbg_d[jbdbg_d_index].op = JB_RECEIVE_PACKET;
if( isT8300 )
    jbdbg_d[jbdbg_d_index].timestamp = *((volatile ULONG *) 0xE000060C);
jbdbg_d[jbdbg_d_index].state = connCb->jitter.state;
jbdbg_d[jbdbg_d_index].p = connCb->jitter.p;
jbdbg_d[jbdbg_d_index].q = connCb->jitter.q;
jbdbg_d[jbdbg_d_index].frames = 0;
jbdbg_d[jbdbg_d_index].seq = jitSim.jitSimBuf[(jitSim.p+index)&(SIMMAXDELAY-1)].rtpHdr->getSequence();
jbdbg_d[jbdbg_d_index].length = jitSim.jitSimBuf[(jitSim.p+index)&(SIMMAXDELAY-1)].rtpHdr->getPayloadUsage();
jbdbg_d[jbdbg_d_index].pkttimestamp = jitSim.jitSimBuf[(jitSim.p+index)&(SIMMAXDELAY-1)].rtpHdr->getHeader()->timestamp;
jbdbg_d[jbdbg_d_index].curtimestamp = connCb->jitter.curTimestamp;
jbdbg_d[jbdbg_d_index].numPackets = connCb->sts.numPackets;
jbdbg_d[jbdbg_d_index].jitterBufferSize = connCb->sts.jitterBufferSize;
jbdbg_d_index++;
semGive(jbCb.sem);
}
#endif

            JbFSM[JB_RECEIVE_PACKET][connCb.jitter.state]
                (&connCb, jitSim.jitSimBuf[(jitSim.p+index)&(SIMMAXDELAY-1)].data,
                &jitSim.jitSimBuf[(jitSim.p+index)&(SIMMAXDELAY-1)].rtpHdr);
//            JbFSM[JB_RECEIVE_PACKET][connCb.jitter.state](&connCb, dBuf, rtpHdr);
        }
        jitSim.p = (jitSim.p + jitSim.burstAmount)&(SIMMAXDELAY-1);
        jitSim.burstAmount = 1;
    }
    else
    {
        jitSim.delayAmount--;
    }

    RETVALUE(ROK);
}


/*
*
*       Fun:   findSessionId
*
*       Desc:  This function is used to locate
*              the index of sessionId in the connection array
*
*       Ret:   Index into array or -1 on failure
*
*       Notes:
*
*       File:  jb_mgmt.c
*
*/
#ifdef ANSI
PRIVATE S16 findSessionId
(
//SpId  spId,         /* desired spId */
S32   sessionId             /* desired connection */
)
#else
PRIVATE S16 findSessionId(spId, sessionId)
SpId  spId;                /* desired spId */
S32   sessionId;       /* desired connection */
#endif
{
    S16 i;
   /*WAS: JbConnKey *conn=*(jbCb.conn); */
//   JbConnKey **conn = jbCb.conn;
    vector<JbConnKey*>& conn = jbCb.conn;

//    TRC3(findSessionId)
    /* Search all active connections for sessionId and on success, set the
    * activeConn element in jbCb to the index in the connKey array */
//    for (i=0;i<jbCb.genCfg.maxConnections;i++,conn++)
     for (i = 0; i < conn.size(); i++)
      {
        /* No, don't bail just because you found a nulled-out conn pointer.
         * There may be more non-null ones in the list, so you need to
         * search the WHOLE list.
         */
        if (!(conn[i]))
            continue;
//        if(((*conn)->sessionId==sessionId) && ((*conn)->spId==spId))
        if (conn[i]->sessionId % MAX_RTP_SESSION == sessionId)
          {
            RETVALUE(i);
          }
      }
    /* searched the whole list and didn't find it, so return -1 to indicate failure */
    RETVALUE(-1);

}   /* ends findSessionId() */


/* GTC NOTE: Added this code from SREEDEVI, but it may not be needed: */
#ifdef ANSI
PUBLIC S16 JbUpdateConCb
(
//SpId  spId,			  /* Service Provider ID of RTP layer */
S32   sessionId,       /* ID of RTP session to connect to */
U32	  h245Msg2			/* the h245 msg field to update */
)
#else
PUBLIC S16 JbUpdateConCb (spId, sessionId,h245Msg2)
SpId  spId;			  /* Service Provider ID of RTP layer */
S32   sessionId;                  /* ID of RTP session to connect to */
U32    h245Msg2;
#endif
{
   JbConnKey *key;
   JbConnCb *connCb;
   U8 frameSize;
   S16 i;
//   Region region;
//   Pool pool;
   S16 sessionIndex;
   S16 ret;

   TRC3(JbUpdateConCb)

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

//   sessionIndex = findSessionId(spId, sessionId);
   sessionIndex = findSessionId(sessionId);
   if (sessionIndex==-1)
   {
          RETVALUE(RFAILED);
   }
   key = jbCb.conn[sessionIndex];

//   if (cmHashListFind(&jbCb.connHlCp, (U8*)(key),
//         sizeof(JbConnKey), 0, (PTR*)&connCb) != ROK)
//   if (findJbConnKey(jbCb.connHlCp, key
   {
      RETVALUE(RFAILED);
   }

   /* Update the h245Msg2 field from the current connection Cb */
/* unused
   connCb->h245Msg2 = h245Msg2;
*/
   RETVALUE (ROK);
}

/* end of file jb_mgmt.c */

⌨️ 快捷键说明

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