?? jb_utl.cpp
字號:
/********************************************************************20**
Nhce: Jitter Buffer - Utilities
Type: C source file
Desc: Utilities file for Jitter Buffer. This file contains
support functions for the jitter buffer
File: jb_utl.c
Sid: jb_utl.c 1.0 - 01/25/2000
Prg: sdg
*********************************************************************21*/
/************************************************************************
The following functions are provided in this file:
JbInsertPacket Insert Packet into buffer
JbRemovePacket Remove Packet from buffer
JbUpdateJitter Update Current jitter
************************************************************************/
/* 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 */
//#endif
//
//#include "hrt.h"
#include "jb.h" /* Jitter Buffer definitions */
//#ifdef HC
//#include "hc_acc.h"
//#endif
//#ifdef SO
//#include "lso.h"
//#include "sot.h" /* SOT definitions */
//#include "so_macros.h"
//#endif
//#ifdef SS_VW
//#include "dspManager.h"
//#endif
//#include "ss_gen.h"
//
//
//#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" /* hash list */
//#include "cm_llist.x" /* llist mngmt */
//#include "cm5.x" /* common timer */
//#include "cm_mblk.x" /* common memory alloc */
//#include "cm32x.x" /* encoding/decoding */
//#include "lhi.x" /* TUCL layer mngmt */
//#include "hit.x" /* H.323 Control lower i/f */
//
//#include "poac.h"
//#include "hrt.x"
//#ifdef HC
//#include "jb.x" /* Jitter Buffer structures/prototypes */
//#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
#include "stdafx.h"
#include "myphone.h"
#include "myphoneDlg.h"
#include "jb.h"
/* local defines */
/* local typedefs */
/* local externs */
/* slm: MR8849 now use array of coders for multiple lines */
EXTERN CdspDecoder *dspApiDecoder[DSP_MAX_DECODER_USERS];
EXTERN CdspEncoder *dspApiEncoder[DSP_MAX_ENCODER_USERS];
extern int firstseq;
extern int lastseq;
int rxpackets = 0;
int packetsRedundant = 0;
/* 1000 Hz Signal wave */
unsigned char dbgPutBuffer[80] = {0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09,
0xff, 0x89, 0x80, 0x89, 0xff,0x09, 0x00, 0x09};
/* forward references */
PRIVATE S16 jbAddPacket ARGS((U16 seq,
U32 timeStamp,
CoderInfo codec,
Data *dBuf,
JBuf *dest,
U32 frameSize));
/* public variable declarations */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef DEBUG_JB
extern unsigned long isT8300;
unsigned long gGpio = 0;
extern U32 jbdbg_d_index;
extern JbDebug_d jbdbg_d[];
#endif
#ifdef __cplusplus
}
#endif
/* private variable declarations */
/*
*
* Fun: JbInsertPacket
*
* Desc: This function is used by the FSM to
* insert a packet into the Jitter Buffer.
*
* Ret: ROK on success and RFAILED on failure
*
* Notes:
*
* File: jb_utl.c
*
*/
#ifdef ANSI
PUBLIC S16 JbInsertPacket
(
JbConnCb *connCb, /* connection control block */
Data *dBuf, /* Data to insert */
HrRtpHdr *rtpHdr /* Rtp Header of packet to insert */
)
#else
PUBLIC S16 JbInsertPacket(connCb, dBuf, rtpHdr)
JbConnCb *connCb; /* connection control block */
Data *dBuf; /* Data to insert */
HrRtpHdr *rtpHdr; /* Rtp Header of packet to insert */
#endif
{
U16 seq;
U16 numFull;
U16 numEmpty;
S16 diff;
S16 dropCount;
U32 i;
U32 timeStamp;
U32 frames; /* Number of frames of data in the packet. */
U32 frameSize;
U8 nextQ;
// TRC3(JbInsertPacket)
if ((!connCb) || (!dBuf) || (!rtpHdr->getHeader())||(!rtpHdr->getPayloadUsage()))
{
RETVALUE(RFAILED);
}
seq = rtpHdr->getSequence();
if(lastseq < seq)
{
rxpackets = connCb->sts.packetsRx;
packetsRedundant = connCb->sts.packetsRedundant;
lastseq = seq;
}
timeStamp = rtpHdr->getHeader()->timestamp;
connCb->sts.packetsRx++;
/* numFull is the number of currently occupied slots in our queue */
numFull = (connCb->jitter.q - connCb->jitter.p + jbCb.genCfg.maxSize) & (jbCb.genCfg.maxSize - 1);
/* numEmpty is the number of available slots in our queue */
numEmpty = jbCb.genCfg.maxSize - numFull;
/* diff is the delta between sequence numbers */
/* if this is the first packet, then set the diff to one */
if(connCb->jitter.gotFirst == 0)
{
firstseq = seq;
connCb->jitter.gotFirst = 1;
connCb->jitter.curTimestamp = timeStamp;
diff = 1;
}
else
{
diff = (S16)((S16)seq - (S16)connCb->jitter.lastSeqNum);
}
/* if we get a newer sequence number */
if (diff >= 0)
{
/* if this sequence number will fit in one of our empty queue slots */
if (diff < numEmpty)
{
/* if we get a new sequence number, but it's beyond our max latency, then
** we need to drop the ones we already have in the previous queue slots,
** so we keep our packets within the latency range */
dropCount = (S16)((numFull + diff) - connCb->jitter.maxLatency);
if (dropCount > 0)
{
U8 nextP;
S32 numDrop = 0;
for (i = 0; i < dropCount; i++)
{
connCb->jitter.p = (connCb->jitter.p + 1) & (jbCb.genCfg.maxSize - 1);
#if 0
ifdef DEBUG_JB
printf("pDrop s:%u c:%d d:%d e:%d f:%d q:%d p:%d max:%d dropts:%u droplen:%u\n",
seq, dropCount, diff, numEmpty, numFull, connCb->jitter.q, connCb->jitter.p,
jbCb.genCfg.maxSize,connCb->jitter.jBuf[connCb->jitter.p].timeStamp,
connCb->jitter.jBuf[connCb->jitter.p].len);
#endif
/* find out how many of these actually had data in them */
if( connCb->jitter.jBuf[connCb->jitter.p].len )
{
connCb->jitter.jBuf[connCb->jitter.p].len = 0;
numDrop++;
}
}
connCb->sts.packetsDropped += dropCount;
/* slm: need to decrease num packets, but don't go below 0 */
if(connCb->sts.numPackets > numDrop)
connCb->sts.numPackets -= numDrop;
else
connCb->sts.numPackets = 0;
/* slm: MR4213 Need to adjust our play timestamp to account for the drop */
nextP = (connCb->jitter.p + 1) & (jbCb.genCfg.maxSize - 1);
connCb->jitter.curTimestamp = connCb->jitter.jBuf[nextP].timeStamp;
}
}
else /* this sequence won't fit in our slots */
{
#if 0
ifdef DEBUG_JB
printf("pDrop room 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
/*
** There is no room for this packet, either because the jitter buffer is too
** small or because it is currently filled with older, unplayed packets.
** If lastSeqNum is not updated, diff = seq-lastSeqNum will be greater than 1,
** the more chances that (diff>numEmpty).
*/
connCb->sts.packetsDropped++;
connCb->jitter.lastSeqNum = seq;
RETVALUE(RFAILED);
}
nextQ = (connCb->jitter.q + diff) & (jbCb.genCfg.maxSize - 1);
/* slm: use len instead of seqNum, because 0 is a valid sequence
** if (connCb->jitter.jBuf[connCb->jitter.q].seqNum != 0)
*/
if (connCb->jitter.jBuf[nextQ].len != 0)
{
#if 0
ifdef DEBUG_JB
printf("pDrop 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 dup s:%u\n", seq);
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -