基于live555的rtsp 客户端模块优化

之前发布过一个基于testRtspClient.cpp 改装的 rtsp client模块   http://blog.csdn.net/mtour/article/details/40073371

该模块支持多路rtsp流,基于这个模块做了一个录像服务



录像服务需要稳定性比较好,在测试的过程中发现 运行几个小时 1天 后 程序出现崩溃。 经过仔细排查 做了如下优化解决


更改 BasicUsageEnvironment 库的 doeventloop函数


void BasicTaskScheduler0::doEventLoop(char* watchVariable) {
  // Repeatedly loop, handling readble sockets and timed events:
  /*while (1) {
    if (watchVariable != NULL && *watchVariable != 0) break;
    SingleStep();
  }*/
	SingleStep();
}

在库外层进行循环操作如下


static DWORD WINAPI StartRtspEventLoop(LPVOID pUser)
{
	theApp.g_scheduler=BasicTaskScheduler::createNew();
	theApp.g_env = BasicUsageEnvironment::createNew(*theApp.g_scheduler);
	while (theApp.g_WatchVariable)
	{
		//theApp.g_env->taskScheduler().doEventLoop(&eventLoopWatchVariable);
		WaitForSingleObject(theApp.g_eventLoopMutex,INFINITE);
		theApp.g_env->taskScheduler().doEventLoop();
		ReleaseMutex(theApp.g_eventLoopMutex);
	}
	
	return 0;
}

注意加互斥锁, 在 rtspclient对象的删除也加互斥锁


void CloseClientFun(void *data)
{ 
	if (!data)
	{
		return;
	}
	RTSPClient* pClient=(RTSPClient*)data;
	shutdownStream(pClient,0);
}

int CStreamItem::Close()
{
	if (m_pRtspClient)
	{
		m_pRtspClient->m_lpStreamCallBack=NULL;
		m_pRtspClient->m_pUserData=NULL;
	
		WaitForSingleObject(theApp.g_eventLoopMutex,INFINITE);	
		theApp.g_scheduler->scheduleDelayedTask(1000*1000, CloseClientFun, m_pRtspClient);		
		ReleaseMutex(theApp.g_eventLoopMutex);
		
		m_pRtspClient=NULL;
	}
	return 0;	
}

客户端打开的代码 增加互斥锁


WaitForSingleObject(theApp.g_eventLoopMutex,INFINITE);
m_pRtspClient->sendDescribeCommand(continueAfterDESCRIBE);	
ReleaseMutex(theApp.g_eventLoopMutex);


引起报错的原因归根结底还是 Live555 单线程机制






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值