建立live555海思编码推流服务
来源:互联网 发布:mac导入照片到ipad 编辑:程序博客网 时间:2024/05/01 16:55
因项目需要,这一周弄了一下live555。需求:海思编码——>RTSP server,使用VLC可以访问,类似于网络摄像机的需求。看了一下,live555的架构太复杂了,半桶水的C++水平还真的需要花点时间才可以明白。由于live555的例子server使用的是读取文件,打包成RTSP包然后发送。例子运行live555MediaServer,把对应的视频文件发到该服务的目录下面,在VLC使用rtsp://ip:8554/file.264即可播放file.264视频。
个人简单理解live555的架构,具体如下:
source是数据源,负责采集数据,比如live555的默认的读取文件
sink就是分析数据、处理数据、发送数据(sendPacketIfNecessary)等
sink的做的东西最多,复杂!
server就是监听client、维护client、RTSP命令的处理等操作例如play、post、get等cmd处理
经过阅读代码可以发现读文件使用的是ByteStreamFileSource类继承的是FramedSource类。FrameSource是所有的源的基类。所以我们要添加自己的类也必须是继承FramedSource,我这里定义了ByteFrameLiveVideoSource类直接继承了FrameSource,在该类完成获取编码的数据, 具体的函数名为: void doGetNextFrameFormEncoder(),并定义了一个回调函数指针给doGetNextFrameFormEncoder函数调用,该接口主要是为了给C做lib的时候使用。
定义自己的server,以便符合自己的访问格式,这里使用的格式为:rtsp://ip:8554/chX/main 最后一个可以是mian或者sub、X代表通道地址0开始。
这里定义了自己的rtspserver类为:liveVideoRTSPServer继承RTSPServerSupportingHTTPStreaming类,完成服务器开始。至此完成自己的RTSP服务推流。
由于自定义的Source类是类似于读文件的类的作用,所以读取数据的时候还是读取一块的数据,然后传给sink分析数据,主要是H264的格式分析。解析数据帧,由于我们从编码出来的已经是一个Frame了,按道理来说不应该当做stream了。所以可以改prase,或者定义自己的prase来搞,这个比较复杂。对于轻量级的server这个已经足够了。而且单线程的live555也不足以完成重量级的server,效率也根不上。搞了一周,感觉live555理解起来比较吃力,C++又好久没搞了。
头文件代码如下:
#ifndef _BYTE_FRAME_LIVE_VIDEO_SOURCE_HH_#define _BYTE_FRAME_LIVE_VIDEO_SOURCE_HH_#ifndef _FRAMED_SOURCE_HH#include "FramedSource.hh"#endiftypedef int (*GetFrameCB)(int chId,int srcId,unsigned char* buf,int size);class ByteFrameLiveVideoSource: public FramedSource{public: static ByteFrameLiveVideoSource* createNew(UsageEnvironment& env, GetFrameCB funcCb,int chId=0,int srcId =0, unsigned preferredFrameSize = 0, unsigned playTimePerFrame = 0); //void seekToByteAbsolute(u_int64_t byteNumber, u_int64_t numBytesToStream = 0); // if "numBytesToStream" is >0, then we limit the stream to that number of bytes, before treating it as EOFprotected: ByteFrameLiveVideoSource(UsageEnvironment& env, int mchId,int msrcId, unsigned preferredFrameSize, unsigned playTimePerFrame); // called only by createNew() virtual ~ByteFrameLiveVideoSource(); static void getFrameableHandler(ByteFrameLiveVideoSource* source, int mask); void doGetNextFrameFormEncoder();private: // redefined virtual functions: virtual void doGetNextFrame(); virtual void doStopGettingFrames(); GetFrameCB getFrame;private: int chId; int srcId; unsigned fPreferredFrameSize; unsigned fPlayTimePerFrame; Boolean fFidIsSeekable; unsigned fLastPlayTime; Boolean fHaveStartedReading; Boolean fLimitNumBytesToStream; u_int64_t fNumBytesToStream; // used iff "fLimitNumBytesToStream" is True};#endif
liveVideoRTSPServer头文件:
/**********This library is free software; you can redistribute it and/or modify it underthe terms of the GNU Lesser General Public License as published by theFree Software Foundation; either version 2.1 of the License, or (at youroption) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)This library is distributed in the hope that it will be useful, but WITHOUTANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License formore details.You should have received a copy of the GNU Lesser General Public Licensealong with this library; if not, write to the Free Software Foundation, Inc.,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA**********/// Copyright (c) 1996-2013, Live Networks, Inc. All rights reserved// A subclass of "RTSPServer" that creates "ServerMediaSession"s on demand,// based on whether or not the specified stream name exists as a file// Header file#ifndef _LIVE_VIDEO_RTSP_SERVER_H#define _LIVE_VIDEO_RTSP_SERVER_H#ifndef _RTSP_SERVER_SUPPORTING_HTTP_STREAMING_HH#include "RTSPServerSupportingHTTPStreaming.hh"#endif#include <liveMedia.hh>class liveVideoRTSPServer: public RTSPServerSupportingHTTPStreaming {public: static liveVideoRTSPServer* createNew( UsageEnvironment& env,Port ourPort,UserAuthenticationDatabase* authDatabase, GetFrameCB cb,unsigned reclamationTestSeconds = 65);protected: liveVideoRTSPServer(UsageEnvironment& env, int ourSocket, Port ourPort, UserAuthenticationDatabase* authDatabase, unsigned reclamationTestSeconds); // called only by createNew(); virtual ~liveVideoRTSPServer();protected: // redefined virtual functions virtual ServerMediaSession* lookupServerMediaSession(char const* streamName);private: GetFrameCB readFreamCb;};#endif
readFrameCB是回调函数,一遍live555做成lib给c调用,海思的是C平台,所以这里用到了回调。
资源地址:
链接:http://pan.baidu.com/s/1skZax2H 密码:kzi1
- 建立live555海思编码推流服务
- LIVE555建立RTSP服务记录
- [转载]LIVE555建立RTSP服务记录
- live555 建立RTP会话
- Live555学习笔记(三)—— RTSP命令处理及RTP,RTCP服务建立
- live555搭建服务
- live555搭建简易流媒体服务
- live555搭建简易流媒体服务
- 【视频开发】【Live555】摄像头采集,264编码,live555直播
- RTSP建立及消息处理(live555)
- iOS音频AAC视频H264编码 推流最佳方案
- iOS 视频直播类,推流,转码,编码
- ffmpeg使用三:ffempg录屏编码rtmp推流
- 四款好用的免费直播编码推流软件
- Android 使用librtmp推流【音视频编码模块】
- 摄像头采集,x264编码,live555直播(1)
- 摄像头采集,x264编码,live555直播(2)
- 摄像头采集,264编码,live555直播(2)
- 解析 HTML -- SGMLParser
- 热修复框架Tinker的从0到集成之路
- 生产环境elasticsearch5.0.1集群的部署配置详解
- BFS入门-A计划
- linux系统——目录,目录项,索引节点(i node)的关系
- 建立live555海思编码推流服务
- Maven构建springMVC
- 算法竞赛入门经典 习题2-6 调和级数(harmony)
- A*B Problem
- 有无序的实数列V[N],要求求里面大小相邻的实数的差的最大值,关键是要求线性空间和线性时间。
- 前端工程目录
- 字符统计
- 流式布局代码块
- warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失