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

📄 jb_utl.cpp

📁 基于h323协议的软phone
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                connCb->sts.packetsRedundant++;
            }
			
            RETVALUE(RFAILED);
        }

        connCb->jitter.q = nextQ;
        connCb->jitter.lastSeqNum = seq;

    }
    /* if we get an older sequence number */
    else
    {
        if (abs(diff) >= numFull)
        {
#if 0
ifdef DEBUG_JB
printf("pDrop late s:%u d:%d e:%d f:%d q:%d p:%d max:%d\n",
seq, diff, numEmpty, numFull, connCb->jitter.q, connCb->jitter.p, jbCb.genCfg.maxSize);
#endif
            connCb->sts.packetsDropped++;
            connCb->sts.packetsLate++;
		
            RETVALUE(RFAILED);
        }

        nextQ = (connCb->jitter.q + diff + jbCb.genCfg.maxSize) & (jbCb.genCfg.maxSize-1);

        /* slm: use len instead of seqNum, because 0 is a valid sequence
        ** if (connCb->jitter.jBuf[(connCb->jitter.q+diff+
        **    jbCb.genCfg.maxSize)&(jbCb.genCfg.maxSize-1)].seqNum!=0)
        */
        if (connCb->jitter.jBuf[nextQ].len != 0)
        {
#if 0
ifdef DEBUG_JB
printf("pDrop old full s:%u d:%d e:%d f:%d q:%d p:%d max:%d\n",
seq, diff, numEmpty, numFull, connCb->jitter.q, connCb->jitter.p, jbCb.genCfg.maxSize);
#endif
            connCb->sts.packetsDropped++;
            /* slm: packet is redundant only if seq numbers match */
            if (connCb->jitter.jBuf[nextQ].seqNum == seq)
            {
#if 0
ifdef DEBUG_JB
printf("pDrop old dup s:%u\n", seq);
#endif
                connCb->sts.packetsRedundant++;
            }
			
            RETVALUE(RFAILED);
        }
    }

    connCb->jitter.receivePacketCount++;

    /* sanity check, make sure far end isn't sending more data
    ** than they said they would */
    frames = connCb->jitter.maxAlSduFrames;
    /* slm: MR4213 use raw frame size */
    GETRAWFRAMESIZE(connCb->key.rxCodec, frameSize);
    if( rtpHdr->getPayloadUsage() > frameSize * frames )
    {
#ifndef JB_TERSE
printf("JbInsertPacket: buf truncated from %u to %u\n", rtpHdr->getPayloadUsage(), (frameSize * frames));
#endif
        rtpHdr->setPayloadUsage(frameSize * frames);
    }
/* debug JB out */
#ifdef DEBUG_JB
{
unsigned char foo[4];
static int speech = 0;
foo[0] = dBuf[0] | 0x80;
foo[1] = dBuf[1] | 0x80;
foo[2] = dBuf[2] | 0x80;
foo[3] = dBuf[3] | 0x80;
/* check for speech */
if((speech == 0) && ((foo[0] < 0xf0) && (foo[1] < 0xf0) && (foo[2] < 0xf0) && (foo[3] < 0xf0)))
{
    speech = 1;
    gGpio |= (1 << 5);
    if( isT8300 )
        *((volatile ULONG *)0xE000C014) = gGpio;
}
/* check for silence */
if((speech == 1) && ((foo[0] >= 0xf8) && (foo[1] >= 0xf8) && (foo[2] >= 0xf8) && (foo[3] >= 0xf8)))
{
    speech = 0;
    gGpio &= ~(1 << 5);
    if( isT8300 )
        *((volatile ULONG *)0xE000C014) = gGpio;
}
}
#endif
	
	
    jbAddPacket(seq, timeStamp, connCb->key.rxCodec,
        dBuf, &(connCb->jitter.jBuf[nextQ]), rtpHdr->getPayloadUsage());

    connCb->sts.numPackets++;

    RETVALUE(ROK);
} /* JbInsertPacket */

/*
*
*       Fun:   JbRemovePacket
*
*       Desc:  This function is used to remove a packet from the Jitter Buffer
*              and send it to the DSP
*
*       Ret:   ROK on success and RFAILED on failure
*
*       Notes:
*
*       File:  jb_utl.c
*
*/
/* slm
** static U8 putBuffer[240];
*/
#if 0 /* don't need this unless we do a memcpy */
static U8 pBufIndex = 0;
static U8 pBuf[8][JB_MAX_BUF_SIZE];
#endif
DSPBuffer dspBuffer = {0,0,0};
//extern int codecIndex;
#ifdef ANSI
PUBLIC S16 JbRemovePacket
(
JbConnCb *connCb                /* connection control block */
)
#else
PUBLIC S16 JbRemovePacket(connCb)
JbConnCb *connCb;               /* connection control block */
#endif
{
    U16 seq;
    U32 timeStamp;
    S32 timeDelta;
    U32 i;
    U32 bufLen;
    U8 nextP;
    U8 * putBuffer;
    U32 frames;
    U32 framesize;


#if 1 
   nextP = (connCb->jitter.p + 1) & (jbCb.genCfg.maxSize - 1);
    if (connCb->jitter.jBuf[nextP].len == 0)
    {
       connCb->jitter.p = nextP;
        connCb->sts.packetsLost++;
	//printf("len\n");
        RETVALUE(RFAILED);
    }
   connCb->sts.packetsTx++;
    if( connCb->sts.numPackets > 0 )
        connCb->sts.numPackets--;
    bufLen = connCb->jitter.jBuf[nextP].len;
    putBuffer = connCb->jitter.jBuf[nextP].buffer;
    connCb->jitter.jBuf[nextP].len = 0;
    connCb->jitter.p = nextP;
    GETRAWFRAMESIZE(connCb->key.rxCodec, framesize);
    frames = bufLen / framesize;
	//printf("seqNum = %d,timeStamp = %d\n",connCb->jitter.jBuf[nextP].seqNum,
	//		connCb->jitter.jBuf[nextP].timeStamp);
	//printf("packetsLost = %d,packetsDropped=%d,packetsRx = %d\n",connCb->sts.packetsLost,
	//	connCb->sts.packetsDropped,connCb->sts.packetsRx);
	//printf("playPacketCount = %d\n",connCb->jitter.playPacketCount);
	
	if(connCb->key.rxCodec == JB_G711)
		 frames = frames / JB_G711_MS_PER_FRAME;
	connCb->jitter.curTimestamp = connCb->jitter.jBuf[nextP].timeStamp;
	dspBuffer.bufLen = bufLen;
	dspBuffer.frames = frames;
	dspBuffer.putBuffer = putBuffer;
	RETVALUE(ROK);
#endif

#if 0
     //TRC3(JbRemovePacket)
    /* slm: MR4213 If our jitter has dropped down, we need to drop some packets to maintain
    ** nominal path delay, because when our jitter had increased, we had to pause
    ** our play to let rcv packets build up in the queue */
   // printf("removepacket=%d\n",tickGet());

    if( connCb->jitter.bufferDrop )
    {
        while( connCb->sts.numPackets > connCb->sts.jitterBufferSize )
        {
            nextP = (connCb->jitter.p + 1) & (jbCb.genCfg.maxSize - 1);

#ifdef DEBUG_JB
printf("> Dropped (%s) ts:%u np:%u q:%d p:%d jb:%u \n",
(connCb->jitter.bufferDrop == 1) ? "creep" : "burst",
connCb->jitter.jBuf[nextP].timeStamp, connCb->sts.numPackets,
connCb->jitter.q, nextP, connCb->sts.jitterBufferSize);
#endif

            connCb->jitter.jBuf[nextP].len = 0;
            connCb->jitter.p = nextP;

            connCb->sts.packetsDropped++;
            connCb->sts.numPackets--;
		printf("jitterBufferSize = %d\n",connCb->sts.jitterBufferSize);
            if( connCb->jitter.bufferDrop == 1 )
                break;
			
        }
        /* update the curtimestamp to reflect dropped packets */
        nextP = (connCb->jitter.p + 1) & (jbCb.genCfg.maxSize - 1);
        connCb->jitter.curTimestamp = connCb->jitter.jBuf[nextP].timeStamp;

        connCb->jitter.bufferDrop = 0;
    }

    nextP = (connCb->jitter.p + 1) & (jbCb.genCfg.maxSize - 1);

    /* slm: use length instead of seqNum, because 0 is a valid sequence number
    ** if (connCb->jitter.jBuf[connCb->jitter.p].seqNum == 0)
    */
    if (connCb->jitter.jBuf[nextP].len == 0)
    {
#ifdef DEBUG_JB
printf("pLost p:%u len=0\n", nextP);
#endif
        connCb->jitter.p = nextP;
        connCb->sts.packetsLost++;
	//printf("len\n");
        RETVALUE(RFAILED);
    }
    /* slm: MR4213 Don't play packet unless the timestamp matches
            This is needed for coders that are sending silence frames
            to ensure we play them out at the proper time */
    /* If pkt timestamp is greater than current timestamp, then return so
    ** we wait until the right time to play the packet.
    ** Handle wrap case by doing signed comparision
    */
    timeDelta = (S32)((S32) connCb->jitter.jBuf[nextP].timeStamp - (S32) connCb->jitter.curTimestamp);
#if 1
/*chen*/
     if( timeDelta > 0 )
    {
#ifdef DEBUG_JB
if( jbdbg_d_index && jbdbg_d_index < MAX_JBDBG )
{
jbdbg_d[jbdbg_d_index-1].seq = connCb->jitter.jBuf[nextP].seqNum;
jbdbg_d[jbdbg_d_index-1].pkttimestamp = connCb->jitter.jBuf[nextP].timeStamp;
}
#endif
	printf("timedelta > 0\n");
        RETVALUE(RFAILED);
    }
    if( timeDelta < 0 )
    {/**/
        /* if our current timestamp is ahead, resync to the packet timestamp */
	printf("timeDelta < 0\n");
        connCb->jitter.curTimestamp = connCb->jitter.jBuf[nextP].timeStamp;
    }  /*chen*/
#endif
#if 0
    if( timeDelta > 0 )
		connCb->jitter.curTimestamp = connCb->jitter.jBuf[nextP].timeStamp;
#endif
    connCb->sts.packetsTx++;

    if( connCb->sts.numPackets > 0 )
        connCb->sts.numPackets--;

    /* slm: use length instead of seqNum, because 0 is a valid sequence number
    ** connCb->jitter.jBuf[connCb->jitter.p].seqNum = 0;
    */

    /* slm: extract the amount of buffer data */
    bufLen = connCb->jitter.jBuf[nextP].len;
    /* slm: sanity check */
    if( bufLen > JB_MAX_BUF_SIZE )
    {
#ifndef JB_TERSE
        printf("JbRemovePacket: buf cropped from %u to %u\n", bufLen, JB_MAX_BUF_SIZE);
#endif
        bufLen = JB_MAX_BUF_SIZE;
    }

    /*
    ** slm: MR4213
    ** Save some mips and data space by removing this memcpy
    ** and its associated static buffers and just pass JB ptr
    ** directly to the putBuffer()
    */
#if 0 /* memcpy to local buffer */
    /* slm use a circular buffer to prevent overwrite */
    putBuffer = pBuf[pBufIndex];
    pBufIndex++;
    if(pBufIndex >= (sizeof(pBuf)/sizeof(pBuf[0])))
        pBufIndex = 0;

    cmMemcpy((U8*)putBuffer, connCb->jitter.jBuf[nextP].buffer,
        /* slm: was 240 */ bufLen);
#else
    /* point to data directly in JB instead of doing a memcpy */
    putBuffer = connCb->jitter.jBuf[nextP].buffer;
#endif

    /* clear the len */
    connCb->jitter.jBuf[nextP].len = 0;
    connCb->jitter.p = nextP;

    /* slm: MR8849 framesize is based on 1ms for G711/G722/G726 (was 10ms) */
    GETRAWFRAMESIZE(connCb->key.rxCodec, framesize);
    frames = bufLen / framesize;
    /* check if we have an SID frame in the buffer */

  if( connCb->key.rxCodec == JB_G729 )
    {
       

⌨️ 快捷键说明

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