基于live555的rtsp 客户端模块优化
2014-11-14 09:24
1291 查看
之前发布过一个基于testRtspClient.cpp 改装的 rtsp client模块 http://blog.csdn.net/mtour/article/details/40073371
该模块支持多路rtsp流,基于这个模块做了一个录像服务
![](https://img-blog.csdn.net/20141114091453537?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbXRvdXI=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
录像服务需要稳定性比较好,在测试的过程中发现 运行几个小时 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 单线程机制
该模块支持多路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 单线程机制
相关文章推荐
- 基于live555的rtsp 客户端模块优化 标签: live555rtsp客户端 2014-11-14 09:24 980人阅读 评论(0) 收藏 举报 分类: 流媒体(16) 版权声明:本文
- 基于live555的rtsp客户端模块
- live555 接收客户端连接及rtsp交互---网络连接处理及RTSP连接模块
- live555 接收客户端连接及rtsp交互---网络连接处理及RTSP连接模块
- 基于live555的rtsp客户端接收及ffmpeg解码
- EasyRTSPClient:基于live555封装的支持重连的RTSP客户端RTSPClient
- live555 接收客户端连接及rtsp交互---网络连接处理及RTSP连接模块 .
- 基于live555实现的RTSPServer对底层进行性能优化的方法 标签: live555RTSPServerlive555性能EasyDarwinlive性能优化 2017-09-12 08:1
- 基于live555实现的RTSPServer对底层进行性能优化的方法
- 基于live555的rtsp客户端接收及ffmpeg解码
- 基于live555封装的rtsp客户端rtspperf
- 基于live555实现的RTSPServer对底层进行性能优化的方法
- 基于live555的rtsp封装rtspperf的客户端源码解析
- 基于live555实现的RTSPServer对底层进行性能优化的方法
- rtsp客户端 & ffmpeg解码(基于live555)
- EasyRTSPClient:基于live555封装的支持重连的RTSP客户端RTSPClient
- 基于live555的rtsp客户端接收及ffmpeg解码
- 基于live555的rtsp客户端接收及ffmpeg解码
- 基于live555和raspberrypi的摄像头模块实现视频采集、传输、播放的功能
- RTSP点播消息流程实例(客户端:VLC, RTSP服务器:LIVE555 Media Server)