C++ liveMedia RTSP服务器的CPU使用率非常高
我正在开发一个多媒体应用程序,它使用liveMedia库通过RTSP传输视频和音频。 我从摄像机中读取原始视频帧,使用libx264对其进行编码,将其保存在tbb::concurrent_队列中,然后运行RTSP server。我使用DynamicRTSPServer.cpp和live555MediaServer.cpp作为创建RTSP模块的示例,我遇到了一个问题—一个线程(执行BasicTaskScheduler::doEventLoop)占用了太多处理器时间—超过了一个处理器核心的80-90%(我有Intel双核T3100)。 对于我的视频流,我有很长的延迟,VLC无法播放视频流(音频流正常播放),错误如下: 主警告:图片太晚无法显示(缺少3780毫秒) avcodec错误:超过5秒的延迟视频->丢弃帧(计算机太慢?) 当我禁用音频子会话时,我的cpu使用率也很高,但VLC可以正常播放视频流 我读取了服务器的日志文件,发现有很多尝试从空队列读取新数据失败。 这是我的日志文件的片段(查看调试消息的时间-这是对FramedSource::doGetNextFrame的不同调用) 我的视频流的帧速率很低(摄像头只能达到8 fps或更低),当调用doGetNextFrame时,我的缓冲区中还没有任何编码帧。 在此尝试中,我有下一个调用堆栈:C++ liveMedia RTSP服务器的CPU使用率非常高,c++,streaming,live555,C++,Streaming,Live555,我正在开发一个多媒体应用程序,它使用liveMedia库通过RTSP传输视频和音频。 我从摄像机中读取原始视频帧,使用libx264对其进行编码,将其保存在tbb::concurrent_队列中,然后运行RTSP server。我使用DynamicRTSPServer.cpp和live555MediaServer.cpp作为创建RTSP模块的示例,我遇到了一个问题—一个线程(执行BasicTaskScheduler::doEventLoop)占用了太多处理器时间—超过了一个处理器核心的80-90
ConcurrentQueueBuffer::doGetNextFrame()
FramedSource::getNextFrame(unsigned char* to, unsigned maxSize,
afterGettingFunc* afterGettingFunc,
void* afterGettingClientData,
onCloseFunc* onCloseFunc,
void* onCloseClientData)
StreamParser::ensureValidBytes1(unsigned numBytesNeeded)
StreamParser::ensureValidBytes(unsigned numBytesNeeded)
StreamParser::test4Bytes()
H264VideoStreamParser::parse()
MPEGVideoStreamFramer::continueReadProcessing()
MPEGVideoStreamFramer::continueReadProcessing(void* clientData,
unsigned char* /*ptr*/, unsigned /*size*/,
struct timeval /*presentationTime*/)
StreamParser::afterGettingBytes1(unsigned numBytesRead, struct timeval presentationTime)
StreamParser::afterGettingBytes(void* clientData,
unsigned numBytesRead,
unsigned /*numTruncatedBytes*/,
struct timeval presentationTime,
unsigned /*durationInMicroseconds*/)
FramedSource::afterGetting(FramedSource* source)
AlarmHandler::handleTimeout()
...
当编码器给我新的帧时,我试图改变缓冲区和锁线程的逻辑,但在这种情况下,我的音频流也有很长的延迟。
我在服务器启动时设置了一些延迟,以便在缓冲区中保存更多数据,但livemedia从缓冲区读取数据的速度要快于编码器编码:(
这个问题的原因是什么?liveMedia如何检测尝试读取FramedSource的频率
我的H264BufferMediaSubsession继承liveMedia的H264VideoFileServerMediaSubsession并仅覆盖createNewStreamSource()虚拟方法,我在其中创建FramedSource,它将从我的缓冲区读取数据。当队列经常为空时,为什么要使用非阻塞pop调用?改用tbb::concurrent\u bounded\u queue?我不知道concurrent\u bounded\u queue。谢谢。我以后会阅读库的文档:)
ConcurrentQueueBuffer::doGetNextFrame()
FramedSource::getNextFrame(unsigned char* to, unsigned maxSize,
afterGettingFunc* afterGettingFunc,
void* afterGettingClientData,
onCloseFunc* onCloseFunc,
void* onCloseClientData)
StreamParser::ensureValidBytes1(unsigned numBytesNeeded)
StreamParser::ensureValidBytes(unsigned numBytesNeeded)
StreamParser::test4Bytes()
H264VideoStreamParser::parse()
MPEGVideoStreamFramer::continueReadProcessing()
MPEGVideoStreamFramer::continueReadProcessing(void* clientData,
unsigned char* /*ptr*/, unsigned /*size*/,
struct timeval /*presentationTime*/)
StreamParser::afterGettingBytes1(unsigned numBytesRead, struct timeval presentationTime)
StreamParser::afterGettingBytes(void* clientData,
unsigned numBytesRead,
unsigned /*numTruncatedBytes*/,
struct timeval presentationTime,
unsigned /*durationInMicroseconds*/)
FramedSource::afterGetting(FramedSource* source)
AlarmHandler::handleTimeout()
...