建立live555海思编码推流服务
因项目需要,这一周弄了一下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"
#endif typedef 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=,int srcId =,
unsigned preferredFrameSize = ,
unsigned playTimePerFrame = ); //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 EOF protected:
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 under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details. You should have received a copy of the GNU Lesser General Public License
along 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 = ); 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 交叉编译移植到海思开发板
本文章参考了.http://blog.csdn.net/lawishere/article/details/8182952,写了hi3518的配置说明.特此感谢 https://blog.csdn.n ...
- 海思hi3518 移植live555 实现H264的RTSP播放
用海思的交叉编译工具交叉编译live555 ,结合海思例子venc中的H264部分,完成RTSP的视频数据发布. 用vlc可以播放,但是实时性比较差,慢了5秒
- 在嵌入式、海思、ARM中进行统一的音频AAC编码的必要性
前言 最近来到深圳,跟许多做硬件的小伙伴聊安防.聊互联网.聊技术,受益颇多,其中聊到一点,大家一直都在想,互联网发展如此迅猛,为啥大部分的摄像机还是采用的传统G.726/G.711的音频编码格式呢,如 ...
- 海思Hi3518A 海思Hi3518C 海思Hi3518E 这几个芯片都有什么区别么
在3518A.3518C的基础上深化完善,推出了Hi3518E.作为新一代IP民用摄像机SoC,Hi3518E集成新一代ISP,优化了编码前图像处理算法,采用新一代H.264编码器.同时采用业内领先的 ...
- RTSPClient工具EasyRTSPClient支持H.265,支持海思等各种芯片平台
EasyRTSPClient是EasyDarwin开源流媒体团队开发.提供的一套非常稳定.易用.支持重连的RTSPClient工具,接口调用非常简单,再也不用像调用live555那样处理整个RTSP ...
- 海思屏幕HAL代码解析
显示屏幕(LCD)模块提供屏幕相关功能接口,调用者为上层应用模块(含 init.状态机.ui),上下文依赖关系,如图 3-7 所示. 系统框架为 linux+Huawei LiteOS 双系统架构,媒 ...
- [转帖]IPC网络高清摄像机基础知识1(IPC芯片市场分析以及“搅局者”华为海思 “来自2013年”)
IPC网络高清摄像机基础知识1(IPC芯片市场分析以及“搅局者”华为海思 “来自2013年”) 2016-06-02 14:23:49 Times_poem 阅读数 9734更多 分类专栏: IPC网 ...
- 海思HI35xx平台软件开发快速入门之H264解码实例学习
ref :https://blog.csdn.net/wytzsjzly/article/details/82500277 前言 H264视频编码技术诞生于2003年,至今已有十余载,技术相当成熟 ...
- 海思H264解码库 hi_h264dec_w.dll 水印问题
上一篇 海思h264解码库 , 实现了H264帧的简单解码,但更换相机后,出现了解码视频中央出现水印的问题,水印如下图 查找网络,基本就这一篇相关的,还没给出好的解决办法. http://bbs. ...
随机推荐
- 结构体重载运算符&srand&rand
先上代码,再按代码讲解 #include<stdio.h>#include<string.h>#include<stdlib.h>#include<time. ...
- vue——loading组件
<template> <div class="loading" :style="{height:loadingRadiusVal+'px',width: ...
- 用JS实现实时显示系统时间
废话我就不多说了,直接上图和代码了 效果图: 代码视图: 下面为大家附上代码,复制即可用: <!DOCTYPE html> <html lang="en"> ...
- 测信噪比的FPGA实现
- 如何给PDF文档添加和删除贝茨编号
PDF文件的使用频率高了,我们也不只局限于使用PDF文件了,也会需要编辑PDF文件的时候,那么如何在PDF文件中添加和去除贝茨编号呢,应该有很多小伙伴都想知道吧,今天就来跟大家分享一下吧,小伙伴们就一 ...
- Sharding-JDBC
1.官网文档:https://shardingsphere.apache.org/document/legacy/3.x/document/cn/manual/sharding-jdbc/usage/ ...
- Cesium 动态更换模型贴图方法
参考资料 github 讨论地址 示例代码地址 示例代码 var viewer = new Cesium.Viewer('cesiumContainer'); var scene = viewer.s ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(任务管理系统)-1项目说明
https://www.bug2048.com/netcore20180313/ 最近公司的一个小项目尝试使用 .net core作为服务端进行开发,并顺利上线运行了一段时间,整体效果还是比较满意的. ...
- docker报Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.19)
docker version Client: Version: 17.05.0-ce API version: 1.24 (downgraded from 1.29) Go version: go1. ...
- (二)文档请求不同源之window.name跨域
一.基本原理 window.name不是一个普通的全局变量,而是当前窗口的名字.这里要注意的是每个iframe都有包裹它的window,而这个window 是top window的子窗口,而它自然也有 ...