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

📄 rtpsources.cpp

📁 此代码为jrtplib-2.9库文件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*  This file is a part of JRTPLIB  Copyright (c) 1999-2004 Jori Liesenborgs  Contact: jori@lumumba.luc.ac.be  This library (JRTPLIB) was partially developed for my thesis at the  School for Knowledge Technology (Belgium/The Netherlands)  Permission is hereby granted, free of charge, to any person obtaining a  copy of this software and associated documentation files (the "Software"),  to deal in the Software without restriction, including without limitation  the rights to use, copy, modify, merge, publish, distribute, sublicense,  and/or sell copies of the Software, and to permit persons to whom the  Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included  in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS  IN THE SOFTWARE.*/#include "rtpsources.h"#include "rtpsourcedata.h"#include "rtppacket.h"#include "rtpcontributingsources.h"#include "rtptimeutil.h"#include "rtphandlers.h"#include "rtpconnection.h"#include <string.h>RTPSources::RTPSources(){	int i;	for (i = 0 ; i < RTP_SOURCETABLE_HASHSIZE ; i++)		sourcetable[i] = NULL;	numsources = 0;	numsenders = 0;	handlers = NULL;	contribsources = NULL;	initialized = false;}RTPSources::~RTPSources(){	Clear();}void RTPSources::Clear(){	int i;	RTPSourceData *tmp,*tmp2;	for (i = 0 ; i < RTP_SOURCETABLE_HASHSIZE ; i++)	{		tmp = sourcetable[i];		while (tmp != NULL)		{			tmp2 = tmp->next;			delete tmp;			tmp = tmp2;		}		sourcetable[i] = NULL;	}}RTPSourceData *RTPSources::Retrieve(unsigned long src){	int index;	bool found;	RTPSourceData *tmp;	index = (int)(src%(unsigned long)RTP_SOURCETABLE_HASHSIZE);	if ((tmp = sourcetable[index]) == NULL)		return NULL;	found = false;	while (!found && tmp != NULL)	{		if (tmp->ssrc < src)			tmp = tmp->next;		else			found = true;	}	if (!found)		return NULL;	if (tmp->ssrc != src)		return NULL;	return tmp;}int RTPSources::ProcessPacket(RTPPacket *packet,unsigned long ip,int port,double localtsunit){	RTPSourceData *tmp;	bool created,collis;	int status;	if (!initialized)		return ERR_RTP_SOURCESNOTINITALIZED;	cursource = NULL;	curtablepos = RTP_SOURCETABLE_HASHSIZE;		tmp = RetrieveOrCreate(packet->syncsource,localtsunit,&created);	if (tmp == NULL)		return ERR_RTP_OUTOFMEM;	if (created)	{		tmp->ip = ip;		tmp->rtpport = port;		if (contribsources->DoesCSRCExist(tmp->ssrc))			tmp->isaCSRC = true;		if (handlers->handlers[RTP_EXCEPTION_NEWSOURCE].handler != NULL)			CallNewSourceHandler(tmp->ssrc);	}	else // src entry already existed	{		collis	= false;		if (tmp->ip != ip)			collis = true;		else		{			if (tmp->rtpport < 0) // first rtp packet from source				tmp->rtpport = port;			else if (tmp->rtpport != port)				collis = true;		}		if (collis)		{			// ssrc collision, ignore this packet			if (handlers->handlers[RTP_EXCEPTION_SSRCCOLLISION].handler != NULL)				CallSSRCCollisionHandler(tmp->ssrc,ip,true,port);			return ERR_RTP_COLLISIONBETWEENSSRCS;		}	}		status = tmp->AddPacket(packet);	if (status < 0)		return status;	if (!tmp->hassentnewdata)	{		tmp->hassentnewdata = true;		if (!tmp->isaCSRC)			numsenders++;	}	return 0;}int RTPSources::ProcessSRInfo(RTPuint32 src,RTPuint32 ntplsw,RTPuint32 ntpmsw,RTPuint32 rtptimestamp,RTPuint32 packetcount,RTPuint32 bytecount,unsigned long ip,int port,double localtsunit){	RTPSourceData *tmp;	bool created,collis;	if (!initialized)		return ERR_RTP_SOURCESNOTINITALIZED;		cursource = NULL;	curtablepos = RTP_SOURCETABLE_HASHSIZE;	tmp = RetrieveOrCreate(src,localtsunit,&created);	if (tmp == NULL)		return ERR_RTP_OUTOFMEM;	if (created)	{		tmp->ip = ip;		tmp->rtcpport = port;		if (contribsources->DoesCSRCExist(tmp->ssrc))			tmp->isaCSRC = true;		if (handlers->handlers[RTP_EXCEPTION_NEWSOURCE].handler != NULL)			CallNewSourceHandler(tmp->ssrc);	}	else // src entry already existed	{		collis = false;		if (tmp->ip != ip)			collis = true;		else		{			if (tmp->rtcpport < 0)	// first rtcppacket from source				tmp->rtcpport = port;			else  if (tmp->rtcpport != port)				collis = true;		}		if (collis)		{			// ssrc collision, ignore this packet			if (handlers->handlers[RTP_EXCEPTION_SSRCCOLLISION].handler != NULL)				CallSSRCCollisionHandler(tmp->ssrc,ip,false,port);			return 0;		}	}	tmp->sr.bytecount = bytecount;	tmp->sr.ntplsw = ntplsw;	tmp->sr.ntpmsw = ntpmsw;	tmp->sr.packetcount = packetcount;	tmp->sr.rtptimestamp = rtptimestamp;	tmp->sr.srreceived = true;	tmp->sr.srtime = rtpconn->GetRTCPReceiveTime();	tmp->stats.lastmsgtime = tmp->sr.srtime.tv_sec;	return 0;}int RTPSources::ProcessSDESInfo(RTPuint32 src,int sdestype,unsigned char *sdesdata,int len,unsigned long ip,int port,double localtsunit){	RTPSourceData *tmp;	bool created,matching,collis;	int status,index,oldlen;	if (!initialized)		return ERR_RTP_SOURCESNOTINITALIZED;		cursource = NULL;	curtablepos = RTP_SOURCETABLE_HASHSIZE;	tmp = RetrieveOrCreate(src,localtsunit,&created);	if (tmp == NULL)		return ERR_RTP_OUTOFMEM;	if (created)	{		tmp->ip = ip;		tmp->rtcpport = port;		if (contribsources->DoesCSRCExist(tmp->ssrc))			tmp->isaCSRC = true;		if (handlers->handlers[RTP_EXCEPTION_NEWSOURCE].handler != NULL)			CallNewSourceHandler(tmp->ssrc);	}	else // src entry already existed	{		collis = false;		if (tmp->ip != ip)			collis = true;		else		{			if (tmp->rtcpport < 0)	// first rtcppacket from source				tmp->rtcpport = port;			else  if (tmp->rtcpport != port)				collis = true;		}		if (collis)		{			// ssrc collision, ignore this packet			if (handlers->handlers[RTP_EXCEPTION_SSRCCOLLISION].handler != NULL)				CallSSRCCollisionHandler(tmp->ssrc,ip,false,port);			return 0;		}	}	index = sdestype-1;	if (index >= 0 && index < RTP_NUM_SDES_INDICES)	{		if (index == TYPE_SDES_CNAME-1 && tmp->sdes.cnameset)		{			// already a cname set, check if the old one and the new one are the same			matching = false;			oldlen = tmp->sdes.sdesinfolen[index];			if (len == oldlen)			{				if (oldlen == 0)					matching = true;				else				{					if (memcmp(tmp->sdes.sdesinfo[index],sdesdata,len) == 0)						matching = true;				}			}			if (!matching) // this means that there is a ssrc collision			{				if (handlers->handlers[RTP_EXCEPTION_SSRCCOLLISION].handler != NULL)					CallSSRCCollisionHandler(tmp->ssrc,ip,false,port);				return 0;			}		}		else		{			status = tmp->sdes.SetSDES(index,(char *)sdesdata,len);			if (status < 0)				return status;		}	}	else // invalid sdestype	{		if (handlers->handlers[RTP_EXCEPTION_INVALIDSDESTYPE].handler != NULL)			CallInvalidSDESTypeHandler(tmp->ssrc,sdestype,sdesdata,len);	}	tmp->stats.lastmsgtime = time(NULL);	return 0;}int RTPSources::ProcessBYEMessage(RTPuint32 src,unsigned long ip,int port){	int index;	bool found,collis;	RTPSourceData *tmp,*tmpprev;	cursource = NULL;	curtablepos = RTP_SOURCETABLE_HASHSIZE;	tmpprev = NULL;	index = (int)(src%(unsigned long)RTP_SOURCETABLE_HASHSIZE);	if ((tmp = sourcetable[index]) == NULL) // not found		found = false;	else	{		found = false;		while (!found && tmp != NULL)		{			if (tmp->ssrc < src)			{				tmpprev = tmp;				tmp = tmp->next;			}			else				found = true;		}		if (found)		{			if (tmp->ssrc != src)				found = false;		}	}		if (found)	{		collis = false;		if (tmp->ip != ip)			collis = true;		else if (tmp->rtcpport >= 0 && tmp->rtcpport != port)			collis = true;		if (!collis)		{			if (handlers->handlers[RTP_EXCEPTION_SSRCDEPARTURE].handler != NULL)				CallSSRCDepartureHandler(tmp->ssrc);			if (tmpprev == NULL)				sourcetable[index] = tmp->next;			else				tmpprev->next = tmp->next;			if (tmp->hassentnewdata && !tmp->isaCSRC)				numsenders--;			numsources--;			delete tmp;		}	}	return 0;}int RTPSources::ProcessRRInfo(RTPuint32 src,unsigned char fraclost,long packetslost,RTPuint32 exthighseqnum,RTPuint32 jitter,RTPuint32 lsr,RTPuint32 dlsr,unsigned long ip,int port,double localtsunit){	RTPSourceData *tmp;	bool created,collis;	unsigned long msw,lsw,ntp32;	unsigned long delay;			if (!initialized)		return ERR_RTP_SOURCESNOTINITALIZED;		cursource = NULL;	curtablepos = RTP_SOURCETABLE_HASHSIZE;	tmp = RetrieveOrCreate(src,localtsunit,&created);	if (tmp == NULL)		return ERR_RTP_OUTOFMEM;	if (created)	{		tmp->ip = ip;		tmp->rtcpport = port;		if (contribsources->DoesCSRCExist(tmp->ssrc))			tmp->isaCSRC = true;		if (handlers->handlers[RTP_EXCEPTION_NEWSOURCE].handler != NULL)			CallNewSourceHandler(tmp->ssrc);	}	else // src entry already existed	{		collis = false;		if (tmp->ip != ip)			collis = true;		else		{			if (tmp->rtcpport < 0)	// first rtcppacket from source				tmp->rtcpport = port;

⌨️ 快捷键说明

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