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

📄 jb_timer.cpp

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

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

     Nhce:     Jitter Buffer - Timer Processing Module

     Type:     C source file

     Desc:     Timer Processing File for Jitter Buffer.

     File:     jb_timer.c

     Sid:      jb_timer.c 1.0  -  01/25/2000

     Prg:      sdg

  Change Log:

  Date        By      Description
  ========    ===     ====================================================
  03/12/2001  mwb     Add support for third-party pause

*********************************************************************21*/


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

The following functions are provided in this file:

   jbActvTmr            Main timer activation routine
   JbStartTimer         Start a long silence timer
   JbStopTimer          Stop a long silence timer

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


/* 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
//
//#ifdef HR
//#include "hrt.h"                /* HR upper interface defines */
//#include "lhr.h"                /* HR layer management defines */
//#ifdef DEBUG_JB
//#include "hr.h"                 /* HR layer defines */
//#endif
//#include "hr_err.h"             /* HR error defines */
//#include "hr_acc.h"
//#endif
//

#include "stdafx.h"
#include "myphone.h"
#include "myphoneDlg.h"
#include "jb.h"        /* Jitter Buffer definitions */
//#include "jb.x"
//#include "dspManager.h"

#ifdef INCLUDE_RV_RTP
#include "mti.h"
#include "payload.h"
#include "rvmemory.h"
#include "rvwpt.h"
#include "rvrtp.h"
#endif

//
//#ifdef HC
//#include "hc_acc.h"
//#include "wpsmhc.h"
//#endif
//
//#ifdef SO
//#include "lso.h"
//#include "sot.h"    /* SOT definitions */
//#include "so_macros.h"
//#include "wpsmso.h"
//#endif
//
//#ifdef SS_VW
//#endif
//
//#include "ss_gen.h"
#ifdef CHECKDSP
extern "C" void checkDSP(int sid);
#endif

/* slm: MR7049 Only Tornado 2.0.1 uses tag8021QLib functions */
#if ((__GNUC__ == 2) && ( __GNUC_MINOR__ == 7 ))
#include "../config/ipt_arm/tag8021QLib.h"
#endif

//#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"
//
//#ifdef HR
//#include "hrt.x"                /* HR upper interface types */
//#include "lhr.x"
//#ifdef DEBUG_JB
//#include "hr.x"                 /* HR layer types */
//#endif
//#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


/* local defines */

/* local typedefs */


/* local externs */
/* slm WAS 300 - need to increase to handle max size */
Data getBuf[JB_MAX_BUF_SIZE];
/*GTC - WAS: JbConCb *jbUdpConCb=0; /* sdg udpfix */
/* slm: MR5637 use define for array size */
//#ifdef HC
//JbConCb * jbUdpConCb[WP_SM_HC_MAX_SSAPS] = {0,0,0,0}; /* sdg udpfix */
//#endif
//#ifdef SO
//JbConCb * jbUdpConCb[WP_SM_SO_MAX_SSAPS] = {0,0,0,0}; /* sdg udpfix */
//#endif
//#ifdef MGCP
//JbConCb * jbUdpConCb[MAX_RTP_SESSION] = {0,0,0,0}; /* sdg udpfix */
//#endif

//CmTptAddr jbLocalAddr; /* Local Address - not used by our JB, but populated by Trillium */

/* added Peer address, MR-3191 */
/* slm: MR5637 use define for array size */
//#ifdef HC
//CmTptAddr jbPeerAddr[WP_SM_HC_MAX_SSAPS];     /* peer transport addresses */
//#endif
//#ifdef SO
//CmTptAddr jbPeerAddr[WP_SM_SO_MAX_SSAPS];     /* peer transport addresses */
//#endif
//#ifdef MGCP
//CmTptAddr jbPeerAddr[MAX_RTP_SESSION];     /* peer transport addresses */
//#endif

/* slm: MR8849 now use array of coders for multiple lines */
EXTERN CdspDecoder *dspApiDecoder[DSP_MAX_DECODER_USERS];
EXTERN CdspEncoder *dspApiEncoder[DSP_MAX_ENCODER_USERS];


#ifndef INCLUDE_RV_RTP
extern RtpManager* rtpManager;
#endif

/* forward references */
PRIVATE S16 jbProcessRxCodec ARGS((JbConnKey *conn));
PRIVATE S16 jbProcessTxCodec ARGS((S32 sessionId, JbConnKey *conn, U16 size, U16 num));
PUBLIC  Void jbProcessLongSilence ARGS((PTR connCb, S16 event));
void check8021QPortTagEnable(int port);
void layer3QosEnable(int socket);

int port;

#ifdef __cplusplus
extern "C" {
#endif
#ifdef DEBUG_JB
extern U32 isT8300;
JbDebug_d jbdbg_d[MAX_JBDBG];
U32 jbdbg_d_index;
JbDebug_e jbdbg_e[MAX_JBDBG];
U32 jbdbg_e_index;

#endif
//extern void HrSendUDatReq  ARGS((U8 *dataBuf, U32 dataLen, SpId rtpId, U32 num));
#ifdef __cplusplus
}
#endif

/* public variable declarations */
#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

/* private variable declarations */
/* 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.  TUCL changes changed HiConCb struct which
** caused recvfrom() to attempt to read from file descriptor 0 and return an error.
** Changed JbConCb to match HiConCb and changed JbSap to match HiSap.  Now recvfrom()
** uses correct file descriptor.  In the process, have found that BOTH this routine AND
** the Trillium hiRecvMsg() routine reads this socket.  However, hiRecvMsg() does it by
** polling the socket every 10ms.
** 10ms is NOT fast enough to handle network data that's bursted in during times of delay,
** especially when RTP packets are being received at a 10ms rate.
** Hence the need for this routine, to read data from the socket as soon as it arrives.
** Doing this allows us to support a 10ms encode rate from the remote end.
** Updated jbReadSocket() to
*/
#ifdef INCLUDE_RV_RTP
extern RvUint32 rtp_start_time;
RvUint8 sendCodec;
RvUint8 GetSendCodec(int callId);

#endif

extern SEM_ID rtpSem;

#ifdef ANSI
PUBLIC VOID jbReadSocket(HRTPSESSION  hRTP, void *connId)
#else
PUBLIC VOID jbReadSocket(hRTP, connId)
HRTPSESSION  hRTP;
void *connIndex;
#endif
{
//    U8                   dBuf[JB_MAX_BUF_SIZE + 54];
//    Buffer              *mBuf;
	S32 				 sessionId;
	S16					 sId;
//    S32                  ret;            /* temporary return value */
//    U32                  pendLen;        /* pending data length */
//    S32                  numBuf;         /* number of allocated dBufs */
    int                  recvLen;        /* number of received octets by recvmsg() */
//    struct sockaddr_in  *remAddr;        /* remote Internet address */
//    int                  remAddrLen;     /* length of remote address */
//    CmInetSockAddr       remSockAddr;    /* to get packet's src IP address */
//    CmTptAddr            fromAddr;
//#ifdef HI_REL_1_3
//    CmTptAddr         destAddr;/* destination address */
//    CmIpHdrParm       ipHdrParm;     /* IP Header parameters */
//#endif /* HI_REL_1_3 */
//   CmInetFd            *sockFd;         /* socket file descriptor */
//    SpId                 spId;
    /* slm: MR8849 changed to index based on line number */
    S16                  lineNo;
    extern int           fRequestjbReadTaskStop[];

	U8 connIndex = (*(U8*)connId);

//    spId = jbCb.conn[connIndex]->spId;

    /* slm: MR8849 extract line number */
    lineNo = jbCb.conn[connIndex]->lineNo;
	sId = jbCb.conn[connIndex]->sessionId;
	sessionId = sId % MAX_RTP_SESSION;
//    remAddr = (struct sockaddr_in *)&remSockAddr;

    /* Error check */
//    if(jbUdpConCb[spId] == NULL)
//    {
//#ifndef JB_TERSE
//        printf("jbReadSocket: Error jbUdpConCb ptr is NULL\n");
//#endif /* JB_TERSE */
//        return;
//    }

//    sockFd = &jbUdpConCb[spId]->conFd;
/*
#ifndef JB_TERSE
    printf("jbReadSocket: jbUdpConCb=%x spId=%u sockFd=%x fd=%u\n", jbUdpConCb[spId], spId, sockFd, sockFd->fd);
#endif
*/

    /* check if Layer3 QOS Testing enabled */
//    layer3QosEnable(sockFd->fd);
#ifndef INCLUDE_RV_RTP
    while (jbCb.conn[connIndex])
    {
#endif
//   printf("sId (read) is %d\n", sId);
//   printf("sessionId (read) is %d\n", sessionId);

        /* If we are exiting, stop the task
         *
         * 0 - normal operation
         * 1 - Request outstanding that the timer task stop
         */
        if(fRequestjbReadTaskStop[sessionId])
        {
            fRequestjbReadTaskStop[sessionId] = 0;
#ifndef INCLUDE_RV_RTP
            break;
#else
            return;
#endif
        }

        /* If this socket is not for the active connection, then sleep a
         * little while to let the other connection's processing take place.
         * Added for multi-call support - GTC
         */
        /* slm: MR8849 changed to index based on line number */
        if(jbCb.activeConn[lineNo] != connIndex)
        {
            if(jbCb.conn[connIndex] == NULLP)
                return;
            taskDelay(4);
#ifndef INCLUDE_RV_RTP
            continue;
#endif
        }
//	static int count1 = 0;
//	if (count1++ == 0)
//		taskDelay(500);
        /* clear the structure */
//        cmMemset((U8*)&remSockAddr, 0, sizeof(remSockAddr));

        /* slm: make sure len is initialized before each call to recvfrom */
//        remAddrLen = sizeof(remSockAddr);
		
//        recvLen = recvfrom(sockFd->fd, (char *)dBuf, sizeof(dBuf), 0,
//                            &remSockAddr, &remAddrLen);
        /*
         * since the above may have blocked, check again if we are supposed
         * to have stopped
         */
        if(fRequestjbReadTaskStop[sessionId])
        {
            fRequestjbReadTaskStop[sessionId] = 0;
            return;
        }

#ifndef INCLUDE_RV_RTP
		Sptr<RtpPacket> p = rtpManager->getSession(sId)->getData(300);
		
//		if(p == NULL)
//			printf("the data got is null!........\n");
//		else
		if(p != NULL)
		{
//			printf("receive data !\n");
			recvLen = p->getPayloadUsage();
			
	        if(recvLen < 0)
	        {
#ifndef JB_TERSE
	            printf("jbReadSocket: Receive error %d\n", errno);
#endif /* JB_TERSE */
	            return;
	        }
			
			JbDatInd(sId, p.getPtr(), (Data *)p->getPayloadLoc());
		}
#else
	unsigned char dBuf[1024];
	rtpParam p;

	semTake(rtpSem, WAIT_FOREVER);
	if (wpCallInfo[sId].rtpSession == NULL)
	{
		printf("wpCallInfo[sId].rtpSession == NULL, return...\n");
		fRequestjbReadTaskStop[sessionId] = 0;
		semGive(rtpSem);
		return;
	}
	if (rtpReadEx(wpCallInfo[sId].rtpSession, (void * )dBuf, 1024, 
		(timerGetTimeInSeconds() - rtp_start_time)*8, &p) < 0)
	{
		printf("rtpReadEx return error, return...\n");
		//taskDelay(4);
		//continue;
		fRequestjbReadTaskStop[sessionId] = 0;
		semGive(rtpSem);
		return;
	}
	/*printf("jbReadSocket time = %d\n",tickGet());*/
	semGive(rtpSem);

⌨️ 快捷键说明

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