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

📄 rtpsources.cpp

📁 最新的jrtplib
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{	int newtotalcount = 0;	int newsendercount = 0;	int newactivecount = 0;	RTPTime checktime = curtime;	checktime -= timeoutdelay;		sourcelist.GotoFirstElement();	while (sourcelist.HasCurrentElement())	{		RTPInternalSourceData *srcdat = sourcelist.GetCurrentElement();		newtotalcount++;		if (srcdat->IsActive())			newactivecount++;		if (srcdat->IsSender())		{			RTPTime lastrtppacktime = srcdat->INF_GetLastRTPPacketTime();			if (lastrtppacktime < checktime) // timeout			{				srcdat->ClearSenderFlag();				sendercount--;			}			else				newsendercount++;		}		sourcelist.GotoNextElement();	}	#ifdef RTPDEBUG	if (newtotalcount != totalcount)	{		std::cout << "New total count " << newtotalcount << " doesnt match old total count " << totalcount << std::endl;		SafeCountTotal();	}	if (newsendercount != sendercount)	{		std::cout << "New sender count " << newsendercount << " doesnt match old sender count " << sendercount << std::endl;		SafeCountSenders();	}	if (newactivecount != activecount)	{		std::cout << "New active count " << newactivecount << " doesnt match old active count " << activecount << std::endl;		SafeCountActive();	}#endif // RTPDEBUG		totalcount = newtotalcount; // just to play it safe	sendercount = newsendercount;	activecount = newactivecount;}void RTPSources::BYETimeout(const RTPTime &curtime,const RTPTime &timeoutdelay){	int newtotalcount = 0;	int newsendercount = 0;	int newactivecount = 0;	RTPTime checktime = curtime;	checktime -= timeoutdelay;		sourcelist.GotoFirstElement();	while (sourcelist.HasCurrentElement())	{		RTPInternalSourceData *srcdat = sourcelist.GetCurrentElement();				if (srcdat->ReceivedBYE())		{			RTPTime byetime = srcdat->GetBYETime();			if ((srcdat != owndata) && (checktime > byetime))			{				totalcount--;				if (srcdat->IsSender())					sendercount--;				if (srcdat->IsActive())					activecount--;				sourcelist.DeleteCurrentElement();				OnBYETimeout(srcdat);				OnRemoveSource(srcdat);				RTPDelete(srcdat,GetMemoryManager());			}			else			{				newtotalcount++;				if (srcdat->IsSender())					newsendercount++;				if (srcdat->IsActive())					newactivecount++;				sourcelist.GotoNextElement();			}		}		else		{			newtotalcount++;			if (srcdat->IsSender())				newsendercount++;			if (srcdat->IsActive())				newactivecount++;			sourcelist.GotoNextElement();		}	}	#ifdef RTPDEBUG	if (newtotalcount != totalcount)	{		std::cout << "New total count " << newtotalcount << " doesnt match old total count " << totalcount << std::endl;		SafeCountTotal();	}	if (newsendercount != sendercount)	{		std::cout << "New sender count " << newsendercount << " doesnt match old sender count " << sendercount << std::endl;		SafeCountSenders();	}	if (newactivecount != activecount)	{		std::cout << "New active count " << newactivecount << " doesnt match old active count " << activecount << std::endl;		SafeCountActive();	}#endif // RTPDEBUG		totalcount = newtotalcount; // just to play it safe	sendercount = newsendercount;	activecount = newactivecount;}void RTPSources::NoteTimeout(const RTPTime &curtime,const RTPTime &timeoutdelay){	int newtotalcount = 0;	int newsendercount = 0;	int newactivecount = 0;	RTPTime checktime = curtime;	checktime -= timeoutdelay;		sourcelist.GotoFirstElement();	while (sourcelist.HasCurrentElement())	{		RTPInternalSourceData *srcdat = sourcelist.GetCurrentElement();		uint8_t *note;		size_t notelen;		note = srcdat->SDES_GetNote(&notelen);		if (notelen != 0) // Note has been set		{			RTPTime notetime = srcdat->INF_GetLastSDESNoteTime();						if (checktime > notetime)			{				srcdat->ClearNote();				OnNoteTimeout(srcdat);			}		}				newtotalcount++;		if (srcdat->IsSender())			newsendercount++;		if (srcdat->IsActive())			newactivecount++;		sourcelist.GotoNextElement();	}	#ifdef RTPDEBUG	if (newtotalcount != totalcount)	{		std::cout << "New total count " << newtotalcount << " doesnt match old total count " << totalcount << std::endl;		SafeCountTotal();	}	if (newsendercount != sendercount)	{		std::cout << "New sender count " << newsendercount << " doesnt match old sender count " << sendercount << std::endl;		SafeCountSenders();	}	if (newactivecount != activecount)	{		std::cout << "New active count " << newactivecount << " doesnt match old active count " << activecount << std::endl;		SafeCountActive();	}#endif // RTPDEBUG		totalcount = newtotalcount; // just to play it safe	sendercount = newsendercount;	activecount = newactivecount;}	void RTPSources::MultipleTimeouts(const RTPTime &curtime,const RTPTime &sendertimeout,const RTPTime &byetimeout,const RTPTime &generaltimeout,const RTPTime &notetimeout){	int newtotalcount = 0;	int newsendercount = 0;	int newactivecount = 0;	RTPTime senderchecktime = curtime;	RTPTime byechecktime = curtime;	RTPTime generaltchecktime = curtime;	RTPTime notechecktime = curtime;	senderchecktime -= sendertimeout;	byechecktime -= byetimeout;	generaltchecktime -= generaltimeout;	notechecktime -= notetimeout;		sourcelist.GotoFirstElement();	while (sourcelist.HasCurrentElement())	{		RTPInternalSourceData *srcdat = sourcelist.GetCurrentElement();		bool deleted,issender,isactive;		bool byetimeout,normaltimeout,notetimeout;		uint8_t *note;		size_t notelen;				issender = srcdat->IsSender();		isactive = srcdat->IsActive();		deleted = false;		byetimeout = false;		normaltimeout = false;		notetimeout = false;		note = srcdat->SDES_GetNote(&notelen);		if (notelen != 0) // Note has been set		{			RTPTime notetime = srcdat->INF_GetLastSDESNoteTime();						if (notechecktime > notetime)			{				notetimeout = true;				srcdat->ClearNote();			}		}		if (srcdat->ReceivedBYE())		{			RTPTime byetime = srcdat->GetBYETime();			if ((srcdat != owndata) && (byechecktime > byetime))			{				sourcelist.DeleteCurrentElement();				deleted = true;				byetimeout = true;			}		}		if (!deleted)		{			RTPTime lastmsgtime = srcdat->INF_GetLastMessageTime();			if ((srcdat != owndata) && (lastmsgtime < generaltchecktime))			{				sourcelist.DeleteCurrentElement();				deleted = true;				normaltimeout = true;			}		}				if (!deleted)		{			newtotalcount++;						if (issender)			{				RTPTime lastrtppacktime = srcdat->INF_GetLastRTPPacketTime();				if (lastrtppacktime < senderchecktime)				{					srcdat->ClearSenderFlag();					sendercount--;				}				else					newsendercount++;			}			if (isactive)				newactivecount++;			if (notetimeout)				OnNoteTimeout(srcdat);			sourcelist.GotoNextElement();		}		else // deleted entry		{			if (issender)				sendercount--;			if (isactive)				activecount--;			totalcount--;			if (byetimeout)				OnBYETimeout(srcdat);			if (normaltimeout)				OnTimeout(srcdat);			OnRemoveSource(srcdat);			RTPDelete(srcdat,GetMemoryManager());		}	}		#ifdef RTPDEBUG	if (newtotalcount != totalcount)	{		SafeCountTotal();		std::cout << "New total count " << newtotalcount << " doesnt match old total count " << totalcount << std::endl;	}	if (newsendercount != sendercount)	{		SafeCountSenders();		std::cout << "New sender count " << newsendercount << " doesnt match old sender count " << sendercount << std::endl;	}	if (newactivecount != activecount)	{		std::cout << "New active count " << newactivecount << " doesnt match old active count " << activecount << std::endl;		SafeCountActive();	}#endif // RTPDEBUG		totalcount = newtotalcount; // just to play it safe	sendercount = newsendercount;	activecount = newactivecount;}#ifdef RTPDEBUGvoid RTPSources::Dump(){	std::cout << "Total count:  " << totalcount << std::endl;	std::cout << "Sender count: " << sendercount << std::endl;	std::cout << "Active count: " << activecount << std::endl;	if (GotoFirstSource())	{		do		{			RTPSourceData *s;			s = GetCurrentSourceInfo();			s->Dump();			std::cout << std::endl;		} while (GotoNextSource());	}}void RTPSources::SafeCountTotal(){	int count = 0;		if (GotoFirstSource())	{		do		{			count++;			} while (GotoNextSource());	}	std::cout << "Actual total count: " << count << std::endl;}void RTPSources::SafeCountSenders(){	int count = 0;		if (GotoFirstSource())	{		do		{			RTPSourceData *s;			s = GetCurrentSourceInfo();			if (s->IsSender())				count++;			} while (GotoNextSource());	}	std::cout << "Actual sender count: " << count << std::endl;}void RTPSources::SafeCountActive(){	int count = 0;		if (GotoFirstSource())	{		do		{			RTPSourceData *s;			s = GetCurrentSourceInfo();			if (s->IsActive())				count++;			} while (GotoNextSource());	}	std::cout << "Actual active count: " << count << std::endl;}#endif // RTPDEBUGbool RTPSources::CheckCollision(RTPInternalSourceData *srcdat,const RTPAddress *senderaddress,bool isrtp){	bool isset,otherisset;	const RTPAddress *addr,*otheraddr;		if (isrtp)	{		isset = srcdat->IsRTPAddressSet();		addr = srcdat->GetRTPDataAddress();		otherisset = srcdat->IsRTCPAddressSet();		otheraddr = srcdat->GetRTCPDataAddress();	}	else	{		isset = srcdat->IsRTCPAddressSet();		addr = srcdat->GetRTCPDataAddress();		otherisset = srcdat->IsRTPAddressSet();		otheraddr = srcdat->GetRTPDataAddress();	}	if (!isset)	{		if (otherisset) // got other address, can check if it comes from same host		{			if (otheraddr == 0) // other came from our own session			{				if (senderaddress != 0)				{					OnSSRCCollision(srcdat,senderaddress,isrtp);					return true;				}				// Ok, store it				if (isrtp)					srcdat->SetRTPDataAddress(senderaddress);				else					srcdat->SetRTCPDataAddress(senderaddress);			}			else			{				if (!otheraddr->IsFromSameHost(senderaddress))				{					OnSSRCCollision(srcdat,senderaddress,isrtp);					return true;				}				// Ok, comes from same host, store the address				if (isrtp)					srcdat->SetRTPDataAddress(senderaddress);				else					srcdat->SetRTCPDataAddress(senderaddress);			}		}		else // no other address, store this one		{			if (isrtp)				srcdat->SetRTPDataAddress(senderaddress);			else				srcdat->SetRTCPDataAddress(senderaddress);		}	}	else // already got an address	{		if (addr == 0)		{			if (senderaddress != 0)			{				OnSSRCCollision(srcdat,senderaddress,isrtp);				return true;			}		}		else		{			if (!addr->IsSameAddress(senderaddress))			{				OnSSRCCollision(srcdat,senderaddress,isrtp);				return true;			}		}	}		return false;}

⌨️ 快捷键说明

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