📄 m803xxrtcp.c
字号:
/**************************************************************************
* Module Name: GAR VOIP File Name: RTCP.C
* Create Date: 2003-03-24 Author:
* Version: 1.0
* History:
* Date Version Modifier Activies
* =========================================================================
**************************************************************************/
#include "vxWorks.h"
#include "ctype.h"
#include "string.h"
#include "sysLib.h"
#include "bootLib.h"
#include "stdio.h"
#include "fioLib.h"
#include "private/vmLibP.h"
#include "taskLib.h"
#include "garlib.h"
#include "inetLib.h"
#include "ioLib.h"
#include "m803xx.h"
#include "rtpmib.h"
#include "Typedef.h"
#include "lfxs/include/lfxs.h"
#include "e1vi/include/mtn1030p.h"
/*#include <protocol/port/vxworks/attache.h>*/
unsigned long RecordRTPTimeStamp[MAX_CID_NUM];
TRTCPRepElement RTCPRepBuff[MAX_CID_NUM];
TRTCPInfo RTCPInfo[MAX_CID_NUM];
extern PortStatusParameter Parameter[MAX_CID_NUM];
extern UINT16 RtpPortNumber[MAX_CID_NUM], RtcpPortNumber[MAX_CID_NUM];
extern void* endPktAlloc();
extern void endPktFree(char* buff );
extern unsigned long Swap_DwordM( unsigned long in );
extern UINT16 Swap_WordM(UINT16 in );
extern RtpSessionValue RtpValue[MAX_CID_NUM];
extern FaxSessionValue FaxValue[MAX_CID_NUM];
extern M803xx_PORT_STATE m_port[M803XX_MAX_PORT_NUM * MAX_PIN_NUM];
extern CHANNEL m_channel[PORTS_OF_CHIP * MAX_PIN_NUM];
extern M803xx_PORT CON_TO_DP[PORTS_OF_CHIP * MAX_PIN_NUM];
/* add by caowm for RTCP 2005/06/28 */
void RTCP_TimeoutProcess()
{
M803xx_PORT_STATE *PortPtr;
UINT8 slot, port;
for(slot = 0; slot < MAX_PIN_NUM; slot++)
{
if (CARD_TYPE_E1VI == Ros_GetNPType(slot+1))
{
E1vi_SendRtcp(slot);
}
else
{
if((lfxsStruct[slot].LFXType == LFXS)||(lfxsStruct[slot].LFXType == LFXO))
{
for(port = 0;port<M803XX_MAX_PORT_NUM;port++)
{
PortPtr = (M803xx_PORT_STATE *)&m_port[slot*M803XX_MAX_PORT_NUM+port];
if((PortPtr->status == TalkStatus) && (PortPtr->VAD == Voice))
{
M803xx_SendRtcpPacket(slot*M803XX_MAX_PORT_NUM+port);
}
}
}
}
}
}
void RTCP_Timeout1Process()
{
M803xx_PORT_STATE *PortPtr;
UINT8 slot, port;
for(slot = 0; slot < MAX_PIN_NUM; slot++)
{
if(lfxsStruct[slot].LFXType != NOT_LFX)
{
for(port = 0;port<M803XX_MAX_PORT_NUM;port++)
{
PortPtr = (M803xx_PORT_STATE *)&m_port[slot*M803XX_MAX_PORT_NUM+port];
if(PortPtr->status ==TalkStatus)
{
if(PortPtr->ReceiveRTCPFlag == 1)/* has received RTCP Packet */
{
PortPtr->ReceiveRTCPFlag = 0;
}
else
{
/* 发送挂断消息*/
}
}
}
}
#if 1
else
{
if (CARD_TYPE_E1VI == Ros_GetNPType(slot+1))
{
E1vi_Rtcptimeout(slot);
}
}
#endif
}
}
/* end add */
/*************************************************************************/
/* Function name: ErrorHandler */
/* Description : handle error with rtp and rtcp packet processing */
/* Return type : void */
/* Argument : PortNo -- Port No of Ipp board */
/* Format -- pointer to the error report character string */
/* Author/Date : */
/* Note: */
/* */
/*************************************************************************/
void ErrorHandler(UINT8 PortNo, char *Format)
{
char buffer[100];
int j;
j = sprintf(buffer, "\\ErrorHandler: Port %d has an error, ", PortNo);
j += sprintf(buffer+j, "\t%s", Format);
printf(buffer);
}
/*************************************************************************/
/* Function name: InitRTCPInfo */
/* Description : Initialize TRTCPInfo static structures */
/* Return type : VOID */
/* Argument : pCh -- TRTCPInfo Structure needed to be initialized */
/* PortNo -- Port No of Ipp board */
/* Author/Date : */
/* Note: */
/* */
/*************************************************************************/
void InitRTCPInfo(TRTCPInfo *pCh,UINT8 PortNo)
{
/*set RTCP parameters*/
pCh->RTPSSRC = (((unsigned int)rand())<<16)+rand();
sprintf(pCh->RTPCNAME,"Ch%d",PortNo);
pCh->RTPCNAMELength=strlen(pCh->RTPCNAME);
pCh->MaxSeq = 0;
pCh->Cycles = 0;
pCh->BaseSeq = 0;
pCh->BadSeq = 0;
pCh->Received = 0;
pCh->ExpectedPrior = 0;
pCh->ReceivedPrior = 0;
pCh->Transit= 0;
pCh->RTCPJitter= 0;
pCh->RemoteSSRC= 0;
strcpy( pCh->RemoteCNAME, "" );
pCh->SomePacketReceived = 0;
pCh->PacketRcvdSinceSR = 0;
pCh->PacketSentSinceSR = 0;
pCh->SenderPacketCount = 0;
pCh->SenderOctetCount = 0;
pCh->Lsr = 0;
pCh->LastSRArrival=0;
strcpy(pCh->TxExtension,"");
pCh->TxExtLength=0;
pCh->SendExtOnce=1;
strcpy(pCh->RxExtension,"");
pCh->RxExtLength=0;
}
/*****************************************************************************/
/* Function name: RTCPJitter */
/* Description : Updates the RTP packets interarrival jitter estimation */
/* according to RFC1889 Alg. A8 */
/* Return type : the current jitter estimation expressed in timestamp units */
/* Argument : PortNo -- Port No of Ipp board */
/* Timestamp -- The timestamp from the incoming packet */
/* Arrival -- the current time in the same units */
/* Update -- 0 : only return the current jitter estimate */
/* 1 : also update the jitter estimate */
/* Author/Date : */
/* Note: called after each received RTP packet */
/* */
/*****************************************************************************/
unsigned int RTCPJitter(UINT8 PortNo,unsigned int Timestamp,unsigned int Arrival,int Update)
{
if (Update)
{
int transit = Arrival - Timestamp;
int d = transit - RTCPInfo[PortNo].Transit;
RTCPInfo[PortNo].Transit = transit;
if (d < 0) d = -d;
RTCPInfo[PortNo].RTCPJitter += d - ((RTCPInfo[PortNo].RTCPJitter + 8) >> 4);
}
return (RTCPInfo[PortNo].RTCPJitter >> 4);
}
/******************************************************************************/
/* Function name: RTCPSRLostFill */
/* Description : This function Determines the Number of RTP Packets Expected */
/* and Lost according to RFC1889 Alg. A3 for sender reports */
/* Return type : void */
/* Argument : RTCPPacket - pointer to the packet to be built */
/* PortNo -- Port No of Ipp board */
/* Author/Date : */
/* Note: From RTCPBuildSRPacket before each RTCP RR packet */
/* is sent,to fill the parameters. */
/******************************************************************************/
void RTCPSRLostFill(TRTCP *LRTCPPacket,UINT8 PortNo)
{
unsigned int extended_max,expected,expected_interval,received_interval;
int lost,lost_interval;
unsigned char fraction;
/*The number of packets lost is defined to be the number of packets*/
/*expected less the number of packets actually received:*/
extended_max = RTCPInfo[PortNo].Cycles + RTCPInfo[PortNo].MaxSeq;
expected = extended_max - RTCPInfo[PortNo].BaseSeq + 1;
lost = expected - RTCPInfo[PortNo].Received;
/* The fraction of packets lost during the last reporting interval*/
/* (since the previous SR or RR packet was sent) is calculated from*/
/* differences in the expected and received packet counts across the*/
/* interval, where expected_prior and received_prior are the values*/
/* saved when the previous reception report was generated:*/
expected_interval = expected - RTCPInfo[PortNo].ExpectedPrior;
RTCPInfo[PortNo].ExpectedPrior = expected;
received_interval = RTCPInfo[PortNo].Received - RTCPInfo[PortNo].ReceivedPrior;
RTCPInfo[PortNo].ReceivedPrior = RTCPInfo[PortNo].Received;
lost_interval = expected_interval - received_interval;
if (expected_interval == 0 || lost_interval <= 0)
fraction = 0;
else
fraction = (unsigned char)(((unsigned int)lost_interval << 8) / expected_interval);
/*fill the parameters*/
LRTCPPacket->Report.SR.RR[0].RTCPCumLost=lost & 0xffffff ;
LRTCPPacket->Report.SR.RR[0].RTCPFraction=fraction ;
}
/******************************************************************************/
/* Function name: RTCPRRLostFill */
/* Description : This function Determines the Number of RTP Packets Expected */
/* and Lost according to RFC1889 Alg. A3 for receiver reports */
/* Return type : void */
/* Argument : RTCPPacket - pointer to the packet to be built */
/* PortNo - The channel */
/* Author/Date : */
/* Note: From RTCPBuildSRPacket before each RTCP RR packet is sent, */
/* to fill the parameters. */
/******************************************************************************/
void RTCPRRLostFill(TRTCP *LRTCPPacket,UINT8 PortNo)
{
unsigned int extended_max,expected,expected_interval,received_interval;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -