Jrtp的简单应用,以及内存泄漏的问题。

工程发生了内存泄漏,排查许久发现是jrtp传输的问题。 在此备份一下,以共勉。

接收端代码段:

int main(void)
{
#ifdef RTP_SOCKETTYPE_WINSOCK
	WSADATA dat;
	WSAStartup(MAKEWORD(2, 2), &dat);
#endif // RTP_SOCKETTYPE_WINSOCK

	RTPSession sess;
	uint16_t portbase;
	int status, i, num;

	cout << "Using version " << RTPLibraryVersion::GetVersion().GetVersionString() << endl;
	cout << "Enter local portbase:" << endl;
	cin >> portbase;
	cout << endl;

	// Now, we'll create a RTP session, set the destination, send some
	// packets and poll for incoming data.

	RTPUDPv4TransmissionParams transparams;
	RTPSessionParams sessparams;

	// IMPORTANT: The local timestamp unit MUST be set, otherwise
	//            RTCP Sender Report info will be calculated wrong
	// In this case, we'll be sending 10 samples each second, so we'll
	// put the timestamp unit to (1.0/10.0)

	sessparams.SetOwnTimestampUnit(1.0 / 10.0);
	sessparams.SetAcceptOwnPackets(true);
	transparams.SetPortbase(portbase);
	status = sess.Create(sessparams, &transparams);

	checkerror(status);

	while (1)
	{
		sess.BeginDataAccess();
		// check incoming packets
		if (sess.GotoFirstSourceWithData())
		{
			do
			{
				RTPPacket *pack;
				while ((pack = sess.GetNextPacket()) != NULL)
				{
					// You can examine the data here
					cout << "Got packet !" << endl;
					cout << pack->GetPayloadData() << endl;
					// we don't longer need the packet, so
					// we'll delete it
					sess.DeletePacket(pack);
				}
			} while (sess.GotoNextSourceWithData());
		}
		sess.EndDataAccess();

#ifndef RTP_SUPPORT_THREAD
		status = sess.Poll();
		checkerror(status);
#endif // RTP_SUPPORT_THREAD

		RTPTime::Wait(RTPTime(1, 0));
	}
	sess.BYEDestroy(RTPTime(10, 0), 0, 0);

#ifdef RTP_SOCKETTYPE_WINSOCK
	WSACleanup();
#endif // RTP_SOCKETTYPE_WINSOCK

	return 0;
}

问题一:
GetNextPacket()和DeletePacket()必须配对使用。
如果只GetNextPacket()而不DeletePacket(),发送端不断地发送数据,接收端就会不断地发生内存泄漏。

问题二:

while (1)
{
	//		sess.BeginDataAccess();
	//		// check incoming packets
	//		if (sess.GotoFirstSourceWithData())
	//		{
	//			do
	//			{
	//				RTPPacket *pack;
	//				while ((pack = sess.GetNextPacket()) != NULL)
	//				{
	//					// You can examine the data here
	//					cout << "Got packet !" << endl;
	//					cout << pack->GetPayloadData() << endl;
	//					// we don't longer need the packet, so
	//					// we'll delete it
	//					sess.DeletePacket(pack);
	//				}
	//			} while (sess.GotoNextSourceWithData());
	//		}
	//		sess.EndDataAccess();
	//
	//#ifndef RTP_SUPPORT_THREAD
	//		status = sess.Poll();
	//		checkerror(status);
	//#endif // RTP_SUPPORT_THREAD
	//
	//		RTPTime::Wait(RTPTime(1, 0));
}

如果将线程里的循环全都注释让线程空跑,当发送端发送数据时,接收端依然会不断地发生内存泄漏。深层原因需要钻研jrtp源码,懒得看了,如果有同胞发现原因。望告知

程序代码:
https://download.csdn.net/download/qq_25359343/11461800

参考:
https://blog.csdn.net/wastedsoul/article/details/80581864

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值