概述

live555官方地址:http://www.live555.com/liveMedia/public/。该地址下有live555的工程包(比如:live.2019.10.20.tar.gz),以及h264/h265的测试流文件。本文以live.2019.10.20.tar.gz为例,介绍live555 rtspserver示例代码。

live555工程的目录结构如下所示,其中testProgs则为测试用例,本文将以OnDemandServerMediaSubsession.cpp为例,解说示例如何运行,以及代码结构。

├── BasicUsageEnvironment
│   └── include
├── groupsock
│   └── include
├── liveMedia
│   └── include
├── mediaServer
├── proxyServer
├── testProgs
├── UsageEnvironment
│   └── include
└── WindowsAudioInputDevice

运行示例

1、编译live555工程,确认testProgs中的源文件被编译。
2、执行OnDemandServerMediaSubsession,在执行该程序的目录下必须存在test.h264的码流文件。比如笔者在userdata目录下存在test.h264,则可直接在userdata目录下运行OnDemandServerMediaSubsession。完整的步骤和log如下所示:

[root@rk3328:/userdata]# ls test.264 -al
-rwxrwxrwx 1 root root 87402 Oct 17 06:56 test.264
[root@rk3328:/userdata]#
[root@rk3328:/userdata]# /usr/bin/testOnDemandRTSPServer"mpeg4ESVideoTest" stream, from the file "test.m4e"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/mpeg4ESVideoTest""h264ESVideoTest" stream, from the file "test.264"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/h264ESVideoTest""h265ESVideoTest" stream, from the file "test.265"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/h265ESVideoTest""mpeg1or2AudioVideoTest" stream, from the file "test.mpg"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/mpeg1or2AudioVideoTest""mpeg1or2ESVideoTest" stream, from the file "testv.mpg"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/mpeg1or2ESVideoTest""mp3AudioTest" stream, from the file "test.mp3"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/mp3AudioTest""wavAudioTest" stream, from the file "test.wav"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/wavAudioTest""amrAudioTest" stream, from the file "test.amr"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/amrAudioTest""vobTest" stream, from the file "test.vob"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/vobTest""mpeg2TransportStreamTest" stream, from the file "test.ts"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/mpeg2TransportStreamTest""aacAudioTest" stream, from the file "test.aac"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/aacAudioTest""dvVideoTest" stream, from the file "test.dv"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/dvVideoTest""ac3AudioTest" stream, from the file "test.ac3"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/ac3AudioTest""matroskaFileTest" stream, from the file "test.mkv"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/matroskaFileTest""webmFileTest" stream, from the file "test.webm"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/webmFileTest""oggFileTest" stream, from the file "test.ogg"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/oggFileTest""opusFileTest" stream, from the file "test.opus"
Play this stream using the URL "rtsp://xxx.xxx.xxx.xxx:8554/opusFileTest""mpeg2TransportStreamFromUDPSourceTest" stream, from a UDP Transport Stream input source (IP multicast address xxx.255.xxx.xxx, port 1234)
Play this stream using the URL "rtsp://xxx.xxx.xxx.45:8554/mpeg2TransportStreamFromUDPSourceTest"(We use port 80 for optional RTSP-over-HTTP tunneling.)

3、确保运行live555示例机器与VLC播放器机器网络互通。然后使用VLC播放器选择上述H264对应的流地址,即可播放。

代码介绍

代码主体结构很简单,main函数实现如下:

int main(int argc, char** argv) {//Live555 提供的接口,这两行必须要创建。// Begin by setting up our usage environment:TaskScheduler* scheduler = BasicTaskScheduler::createNew();env = BasicUsageEnvironment::createNew(*scheduler);UserAuthenticationDatabase* authDB = NULL;
#ifdef ACCESS_CONTROL// To implement client access control to the RTSP server, do the following:authDB = new UserAuthenticationDatabase;authDB->addUserRecord("username1", "password1"); // replace these with real strings// Repeat the above with each <username>, <password> that you wish to allow// access to the server.
#endif// Create the RTSP server:RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554, authDB);if (rtspServer == NULL) {*env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";exit(1);}..... 略 .....// A H.264 video elementary stream:{// rtsp流名称。char const* streamName = "h264ESVideoTest";// 输入h264码流文件名称。char const* inputFileName = "test.264";// 创建ServerMediaSessio,对应一个rtsp网络地址ServerMediaSession* sms= ServerMediaSession::createNew(*env, streamName, streamName,descriptionString);// 创建一个H264的MediaSubSession,并加入到sms中,// 一个MediaSubSession对应一个媒体资源。sms->addSubsession(H264VideoFileServerMediaSubsession::createNew(*env, inputFileName, reuseFirstSource));// 加入RtspServer即可完成。rtspServer->addServerMediaSession(sms);announceStream(rtspServer, sms, streamName, inputFileName);}..... 略 .....// Also, attempt to create a HTTP server for RTSP-over-HTTP tunneling.// Try first with the default HTTP port (80), and then with the alternative HTTP// port numbers (8000 and 8080).if (rtspServer->setUpTunnelingOverHTTP(80) || rtspServer->setUpTunnelingOverHTTP(8000) || rtspServer->setUpTunnelingOverHTTP(8080)) {*env << "\n(We use port " << rtspServer->httpServerPortNum() << " for optional RTSP-over-HTTP tunneling.)\n";} else {*env << "\n(RTSP-over-HTTP tunneling is not available.)\n";}// 姑且理解为mainLoopenv->taskScheduler().doEventLoop(); // does not returnreturn 0; // only to prevent compiler warning
}

【 总结】:从上面代码结构来看,创建一个rtsp server非常简单。H264VideoFileServerMediaSubsession为Live555预先实现好的H264媒体文件类,我们只需要调用该类并传入文件名即可完成RTSP server的推流。

Live555: RtspServer 示例相关推荐

  1. live555 源码分析:RTSPServer

    live555 使用 RTSP/RTP/RTCP 协议来实现流媒体的传输,其中使用 RTSP 来建立流媒体会话,并对流媒体会话进行控制.在 live555 中,通过类 RTSPServerSuppor ...

  2. 基于live555实现的RTSPServer对底层进行性能优化的方法

    在博客<EasyIPCamera高性能摄像机RTSP服务器RTSPServer解决方案>我介绍了基于live555实现的一套RTSPServer功能组件,当时开发者经过几个月的调试,已经将 ...

  3. EasyIPCamera高性能摄像机RTSP服务器RTSPServer解决方案

    EasyIPCamera EasyIPCamera是由EasyDarwin团队开发的一套非常稳定.易用.支持多种平台(包括Windows/Linux 32&64,Android,ARM his ...

  4. live555 学习笔记-建立RTSP连接的过程(RTSP服务器端)

    live555 学习笔记-建立RTSP连接的过程(RTSP服务器端) 监听 创建rtsp server,rtspserver的构造函数中,创建监听socket,添加到调度管理器BasicTaskSch ...

  5. EasyIPCamera-WindowsLinuxARM服务接口

    接口协议适用平台:(Windows&Linux&ARM) 1. SDK描述 EasyIPCamera是一套非常稳定.易用.支持多种平台(包括Windows/Linux 32&6 ...

  6. live555编译、播放示例

    最近被安排搞onvif,onvif的视频传输,就是使用live555做服务器,使用其提供的URL.所以live555也得去了解学习.本文简单介绍live555的编译,然后在原有例程上给出一个示例. 1 ...

  7. 【Live555】live555源码详解(七):GenericMediaServer、RTSPServer、RTSPClient

    [Live555]live555源码详解系列笔记 继承协作关系图 下面红色表示本博客将要介绍的三个类所在的位置: GenericMediaServer.RTSPServer.RTSPClient 14 ...

  8. live555 源码分析:RTSPServer 组件结构

    前面几篇文章分析了 live555 中 RTSP 的处理逻辑,RTSP 处理有关组件的处理逻辑有点复杂,本文就再来梳理一下它们之间的关系. live555 中 RTSP 处理有关组件关系如下图: 事件 ...

  9. live555作为RTSP流媒体服务器RTSPServer时解决对接海康NVR时G711音频不能正常播放的问题

    live555作为NVR内置的流媒体服务器RTSPServer在对接海康NVR,视频正常,音频不能正常播放, 但VLC可以正常播放. 经过问题的分析,发现live555作为NVR流媒体服务器输出视频为 ...

最新文章

  1. Ulua_toLua_基本案例(八)_LuaAccessingArray
  2. 大数据生态及其技术栈
  3. 分布式系统Lease机制
  4. 操作系统:升级Windows 11正式版的四种方法,值得收藏!
  5. jQuery load(),html include,iframe嵌框
  6. 人车物跟踪在另外的机器上跑不起来
  7. js捕捉IE窗口失去焦点事件,判断离开页面刷新或关闭的方法
  8. # 20155224 实验四 Android程序设计
  9. LODOP打印当前日期时间的方法
  10. 正则表达式之位置匹配
  11. DSDT/SSDT综合教程
  12. java如何对一个表达式开根号_java实现开根号的运算
  13. linux 16进制编辑器 知乎,狂揽2500星,开源十六进制编辑器登顶GitHub热榜
  14. 计算机网络vtp,VTP学习笔记(二)
  15. 程序员专用表情包_拿走不谢
  16. 微信官方支付接口配置教程
  17. php在线考试系统 附源码(一)
  18. arch 服务器系统,arch linux服务器
  19. 你见过程序员跳槽宝典吗,35岁后慎点
  20. 论创新工场、职业发展、offer如何比较选择、移动互联网(全文完)

热门文章

  1. 浓缩德国奎尔鱼油 (QÜELL FISH OIL™ HIGHT EPA / DHA / D)
  2. 51单片机下载完程序后不亮_为什么要学习单片机?如何开始上手学习单片机?...
  3. python 国内镜像源 2020最新
  4. 201571030139/201571030134《小学生四则运算练习软件需求说明》结对项目报告
  5. MATLAB读json文件
  6. 50个直击灵魂的问题_直击灵魂的三个问题,让你知道什么叫社会险恶
  7. 自定义view2/12----Paint常用方法(主要是ColorMatrix,Xfermode)
  8. C++ OpenCV无法调用视频的问题
  9. 计算机内功修炼:程序的机器级表示(C与汇编)
  10. http设计:错误码 三羊开泰