【视频开发】【Live555】live555实现h264码流RTSP传输
1.概述
liveMedia 库中有一系列类,基类是Medium,这些类针对不同的流媒体类型和编码。 其中的StreamFrame类文件(如MPEG4VideoStreamFramer)为流传输关键。
2 重要概念:
StreamFrame类:该类继承FramedSource基类,实现数据流的控制和传输。
StreamFrame(H264VideoStreamFramer) -->FramedFilter--> FramedSource----> MediaSource
FramedSource 派继承MediaSource父类,一帧码流的实现。
注意:unsigned char* fTo;为指向发送的码流的指针,采集到视频数据后填充到该指针中即可实现码流的传输。
主要步骤:1.定义自己的StreamFramer类,实现getNextFrame重写。
getNextFrame函数来自live\liveMedia\FramedSource文件,代码见下
- 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()代码如下:
- 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,在该函数中进行重新定义即可实现。
- 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】live555实现h264码流RTSP传输的更多相关文章
- 从H264码流中获取视频宽高 (SPS帧) 升级篇
之前写过 <从H264码流中获取视频宽高 (SPS帧)> . 但发现很多局限性,而且有时解出来是错误的. 所以重新去研究了. 用了 官方提供的代码库来解析. 花了点时间,从代码库里单独把解 ...
- 从H264码流中获取视频宽高 (SPS帧)
获取.h264视频宽高的方法 花了2个通宵终于搞定.(后面附上完整代码) http://write.blog.csdn.net/postedit/7852406 图像的高和宽在H264的SPS帧中.在 ...
- H264码流打包分析(精华)
H264码流打包分析 SODB 数据比特串-->最原始的编码数据 RBSP 原始字节序列载荷-->在SODB的后面填加了结尾比特(RBSP trailing bits 一个bit“1”)若 ...
- H264码流解析及NALU
ffmpeg 从mp4上提取H264的nalu http://blog.csdn.net/gavinr/article/details/7183499 639 /* bitstream fil ...
- RTP协议全解析(H264码流和PS流)
转自:http://blog.csdn.net/chen495810242/article/details/39207305 写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个 ...
- (转)RTP协议全解(H264码流和PS流)
写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个比较全面的解析, 其中借鉴了很多文章,我都列在了文章最后,在此表示感谢. 互联网的发展离不开大家的无私奉献,我决定从我做起,希 ...
- H264码流中SPS PPS详解<转>
转载地址:https://zhuanlan.zhihu.com/p/27896239 1 SPS和PPS从何处而来? 2 SPS和PPS中的每个参数起什么作用? 3 如何解析SDP中包含的H.264的 ...
- RTP协议全解(H264码流和PS流)
写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个比较全面的解析, 其中借鉴了很多文章,我都列在了文章最后,在此表示感谢. 互联网的发展离不开大家的无私奉献,我决定从我做起,希 ...
- H264编码原理以及I帧、B和P帧详解, H264码流结构分析
H264码流结构分析 http://blog.csdn.net/chenchong_219/article/details/37990541 1.码流总体结构: h264的功能分为两层,视频编码层(V ...
随机推荐
- Djiango-富文本编辑器
借助富文本编辑器,网站的编辑人员能够像使用offfice一样编写出漂亮的.所见即所得的页面.此处以tinymce为例,其它富文本编辑器的使用也是类似的. 在虚拟环境中安装包. pip install ...
- Codechef:Fibonacci Number/FN——求通项+二次剩余+bsgs
题意 定义 $F_n$ 为 $$F_n = \left\{\begin{matrix}0, n=0\\ 1, n=1 \\F_{n-1} + F_{n-2}, n > 1\end{matrix} ...
- yii2 oracle 原生sql分页
$sql_list = "SELECT ID, FID, INSID, FLIGHTNO, DEPNAME, ARRNAME, to_char(DEPDATE,'yyyy-MM-dd HH2 ...
- Oracle 分区默认segment大小变化(64k—>8M)
原文链接:http://www.cnblogs.com/wcwen1990/p/6656545.html _partition_large_extents和_index_partition_large ...
- (尚018-第二章2.1)Vue使用vue-cli创建模板项目
2.1.1 1)vue-cli是官方提供的脚手架工具(注意:脚手架本身是个库) 2)github:https://github.com/vuejs/vue-cli 3)作用:从https://gith ...
- WinDbg常用命令系列---输入内存值的命令e*
e, ea, eb, ed, eD, ef, ep, eq, eu, ew, eza (Enter Values) e*命令将您指定的值输入内存.不要将此命令与~e(Thread-Specific C ...
- requestLayout() improperly called by xxxxxxxxxxxxxxxxxxx ScrollViewContainer 问题
当scrollview内的内容更改大小时,Scrollview不会自行调整大小.效果是,当内容变小时,内容将留在原来的位置,当内容变大时,无法看到.仅当ScrollView位于作为MasterDeta ...
- 转载:Databricks孟祥瑞:ALS 在 Spark MLlib 中的实现
Databricks孟祥瑞:ALS 在 Spark MLlib 中的实现 发表于2015-05-07 21:58| 10255次阅读| 来源<程序员>电子刊| 9 条评论| 作者孟祥瑞 大 ...
- GoCN每日新闻(2019-10-08)
GoCN每日新闻(2019-10-08) <premenlo';font-size:9.0pt;">GoCN每日新闻(2019-10-08) 1. Go 构建高性能数据库中间件: ...
- Codeforces 839D Winter is here - 暴力 - 容斥原理
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n s ...