【视频开发】【Live555】live555实现h264码流RTSP传输
2017-07-28 23:31
726 查看
1.概述
liveMedia 库中有一系列类,基类是Medium,这些类针对不同的流媒体类型和编码。 其中的StreamFrame类文件(如MPEG4VideoStreamFramer)为流传输关键。
2 重要概念:
StreamFrame类:该类继承FramedSource基类,实现数据流的控制和传输。
StreamFrame(H264VideoStreamFramer) -->FramedFilter--> FramedSource----> MediaSource
FramedSource 派继承MediaSource父类,一帧码流的实现。
注意:unsigned char* fTo;为指向发送的码流的指针,采集到视频数据后填充到该指针中即可实现码流的传输。
主要步骤:1.定义自己的StreamFramer类,实现
[cpp] view
plain copy
void FramedSource::getNextFrame(unsignedchar* to, unsigned maxSize,
afterGettingFunc*afterGettingFunc,
void*afterGettingClientData,
onCloseFunc*onCloseFunc,
void*onCloseClientData) {
// Make sure we're not already beingread:
if (fIsCurrentlyAwaitingData){
envir() <<"FramedSource[" <<this <<"]::getNextFrame(): attempting to read more than once at the sametime!\n";
envir().internalError();
}
fTo = to;
fMaxSize = maxSize;
fNumTruncatedBytes = 0; // by default;could be changed by doGetNextFrame()
fDurationInMicroseconds = 0; // bydefault; could be changed by doGetNextFrame()
fAfterGettingFunc = afterGettingFunc;
fAfterGettingClientData =afterGettingClientData;
fOnCloseFunc = onCloseFunc;
fOnCloseClientData = onCloseClientData;
fIsCurrentlyAwaitingData = True;
doGetNextFrame();
}
[cpp] view
plain copy
voidH264FramedLiveSource::doGetNextFrame()
{
printf("doGetNextFrame\n");
if( filesize(fp) > fMaxSize)
fFrameSize = fread(fTo,1,fMaxSize,fp);
else
{
fFrameSize =fread(fTo,1,filesize(fp),fp);
fseek(fp, 0, SEEK_SET);
}
//fFrameSize = fMaxSize;
nextTask() =envir().taskScheduler().scheduleDelayedTask( 0,
(TaskFunc*)FramedSource::afterGetting, this);
return;
}
2.实现fTO与会话连接,自定义
[cpp] view
plain copy
FramedSource*H264LiveVideoServerMediaSubssion::createNewStreamSource( unsignedclientSessionId, unsigned& estBitrate )
{
/* Remain to do : assign estBitrate */
estBitrate = 1000; // kbps, estimate
// Create the video source:
H264FramedLiveSource* liveSource =H264FramedLiveSource::createNew(envir(), fFileName);
if (liveSource == NULL)
{
return NULL;
}
// Create a framer for the Video ElementaryStream:
returnH264VideoStreamFramer::createNew(envir(), liveSource);
}
主要最后返回的H264VideoStreamFramer继承自FramedSource,定义了从文件获取source的方法,从而将ServerMedia 与source联系起来。
代码为vs2008工程,采用VLC测试,测试结果如下图所示
代码见http://download.csdn.NET/detail/xiahua882/9619900
注:工程中CaremaLive为该博客代码,MediaServer为live555标准服务器工程也可以运行。代码工程图见下
liveMedia 库中有一系列类,基类是Medium,这些类针对不同的流媒体类型和编码。 其中的StreamFrame类文件(如MPEG4VideoStreamFramer)为流传输关键。
2 重要概念:
StreamFrame类:该类继承FramedSource基类,实现数据流的控制和传输。
StreamFrame(H264VideoStreamFramer) -->FramedFilter--> FramedSource----> MediaSource
FramedSource 派继承MediaSource父类,一帧码流的实现。
注意:unsigned char* fTo;为指向发送的码流的指针,采集到视频数据后填充到该指针中即可实现码流的传输。
主要步骤:1.定义自己的StreamFramer类,实现
getNextFrame
重写。
getNextFrame函数来自
live\liveMedia\FramedSource
文件,代码见下
[cpp] view
plain copy
void FramedSource::getNextFrame(unsignedchar* to, unsigned maxSize,
afterGettingFunc*afterGettingFunc,
void*afterGettingClientData,
onCloseFunc*onCloseFunc,
void*onCloseClientData) {
// Make sure we're not already beingread:
if (fIsCurrentlyAwaitingData){
envir() <<"FramedSource[" <<this <<"]::getNextFrame(): attempting to read more than once at the sametime!\n";
envir().internalError();
}
fTo = to;
fMaxSize = maxSize;
fNumTruncatedBytes = 0; // by default;could be changed by doGetNextFrame()
fDurationInMicroseconds = 0; // bydefault; could be changed by doGetNextFrame()
fAfterGettingFunc = afterGettingFunc;
fAfterGettingClientData =afterGettingClientData;
fOnCloseFunc = onCloseFunc;
fOnCloseClientData = onCloseClientData;
fIsCurrentlyAwaitingData = True;
doGetNextFrame();
}
其中最后的doGetNextFrame(); 是一个虚函数,具体各种编码模式,我们可以根据自己的码流类型定义一个派生自FramedSource的类(本工程H264FramedLiveSource类), 重新再定义doGetNextFrame如何获得下一帧的码流,在自己重定义的doGetNextFrame() 中将fTo指向要发送的缓存即可。这样我们就实现了流的传输而非文件传输。
本工程中doGetNextFrame()代码如下:
[cpp] view
plain copy
voidH264FramedLiveSource::doGetNextFrame()
{
printf("doGetNextFrame\n");
if( filesize(fp) > fMaxSize)
fFrameSize = fread(fTo,1,fMaxSize,fp);
else
{
fFrameSize =fread(fTo,1,filesize(fp),fp);
fseek(fp, 0, SEEK_SET);
}
//fFrameSize = fMaxSize;
nextTask() =envir().taskScheduler().scheduleDelayedTask( 0,
(TaskFunc*)FramedSource::afterGetting, this);
return;
}
2.实现fTO与会话连接,自定义
ServerMediaSubsession
类
定义ServerMediaSubsession类H264LiveVideoServerMediaSubssion,该类由ServerMediaSubsession 派生而来。该类中有私有函数virtual
FramedSource* createNewStreamSource
,在该函数中进行重新定义即可实现。
[cpp] view
plain copy
FramedSource*H264LiveVideoServerMediaSubssion::createNewStreamSource( unsignedclientSessionId, unsigned& estBitrate )
{
/* Remain to do : assign estBitrate */
estBitrate = 1000; // kbps, estimate
// Create the video source:
H264FramedLiveSource* liveSource =H264FramedLiveSource::createNew(envir(), fFileName);
if (liveSource == NULL)
{
return NULL;
}
// Create a framer for the Video ElementaryStream:
returnH264VideoStreamFramer::createNew(envir(), liveSource);
}
主要最后返回的H264VideoStreamFramer继承自FramedSource,定义了从文件获取source的方法,从而将ServerMedia 与source联系起来。
代码为vs2008工程,采用VLC测试,测试结果如下图所示
代码见http://download.csdn.NET/detail/xiahua882/9619900
注:工程中CaremaLive为该博客代码,MediaServer为live555标准服务器工程也可以运行。代码工程图见下
相关文章推荐
- live555实现h264码流RTSP传输
- 【视频开发】【Live555】通过live555实现H264 RTSP直播
- 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(七)RTP音视频传输解析层之H264传输格式
- live555实现TS码流RTSP传输
- live555+MediaCodec实现获取并解码RTSP视频(H264)
- H.264/ACC音视频编码流的RTP/RTSP传输实现(1)
- 通过live555实现H264 RTSP直播(Windows版)
- javaCV开发详解之3:收流器实现,录制流媒体服务器的rtsp/rtmp视频文件(基于javaCV-FFMPEG)
- 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(八)RTP音视频传输解析层之MPA传输格式
- 按照RFC3984协议实现H264视频流媒体 RTSP H264
- 通过live555实现H264 RTSP直播
- Live555学习之(七)---------- Live555实现h264视频的点播
- javaCV开发详解之4:转流器实现(也可作为本地收流器、推流器,新增添加图片及文字水印,视频图像帧保存),实现rtsp/rtmp/本地文件转发到rtmp流媒体服务器(基于javaCV-FFMPEG)
- 海思hi3518 移植live555 实现H264的RTSP播放
- live555实现ffmpeg解码H264的rtsp流
- Windows下利用live555实现H264实时流RTSP发送
- 基于live555实现rtsp视频直播
- Windows下利用live555实现H264实时流RTSP发送
- 移植live555到hi3516a实现rtsp传输
- Windows下利用live555实现H264实时流RTSP发送