一、简介

先看一下官网上的介绍:

testOnDemandRTSPServercreates a RTSP server that can stream, via RTP unicast, from various types of media file, on demand. (Supported media types include: MPEG-1 or 2 audio or video (elementary stream), including MP3 audio; MPEG-4 video (elementary stream); H.264 video (elementary stream); H.265 video (elementary stream); MPEG Program or Transport streams, including VOB files; DV video; AMR audio; WAV (PCM) audio.) The server can also stream from aMatroskaorWebMfile (by demultiplexing and streaming the tracks within the file). MPEG Transport Streams can also be streamed over raw UDP, if requested - e.g., by a set-top box.

  • This server application also demonstrates how to deliver - via RTSP - a MPEG Transport Stream that arrived at the server as a UDP (raw-UDP or RTP/UDP) multicast or unicast stream. In particular, it is set up, by default, to accept input from the "testMPEG2TransportStreamer" demo application.

翻译一下:

testOnDemandRTSPServer 创建一个 RTSP 服务器,可以根据需要通过 RTP 单播从各种类型的媒体文件流式传输。 (支持的媒体类型包括:MPEG-1或2音频或视频(基本流),包括MP3音频; MPEG-4视频(基本流); H.264视频(基本流); H.265视频(基本流) MPEG程序或传输流,包括VOB文件; DV视频; AMR音频; WAV(PCM)音频。)服务器还可以从 Matroska 或 WebM 文件流(通过解复用和流式传输文件中的轨道)。 如果需要,MPEG传输流也可以通过原始UDP流传输,例如通过机顶盒。
该服务器应用程序还演示了如何通过 RTSP 传送作为 UDP(原始UDP或RTP / UDP)组播或单播流到达服务器的MPEG传输流。 特别地,默认情况下,它设置为接受来自“testMPEG2TransportStreamer”演示应用程序的输入。

二、源码分析

参看:live555 testOnDemandRTSPServer例程解析

此例程是关于构建live555 RTSP服务器的,可以点播很多类型的文件,这里只讲解H264的,本例程是点播,用的单播unicast的形式

#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"  //创建交互环境,用来打印相关信息的
UsageEnvironment* env;  // To make the second and subsequent client for each stream reuse the same
// input stream as the first client (rather than playing the file from the
// start for each client), change the following "False" to "True":
Boolean reuseFirstSource = False;  // To stream *only* MPEG-1 or 2 video "I" frames
// (e.g., to reduce network bandwidth),
// change the following "False" to "True":
Boolean iFramesOnly = False;  //打印相关信息的函数
static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,  char const* streamName, char const* inputFileName); // fwd  int main(int argc, char** argv) {  // Begin by setting up our usage environment:  // 1.创建任务调度器,createNew其实就是创建类的实例  TaskScheduler* scheduler = BasicTaskScheduler::createNew();
// 2. 创建交互环境  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  // 3. 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);  }  char const* descriptionString  = "Session streamed by \"testOnDemandRTSPServer\"";  // Set up each of the possible streams that can be served by the  // RTSP server.  Each such stream is implemented using a  // "ServerMediaSession" object, plus one or more  // "ServerMediaSubsession" objects for each audio/video substream.  // A H.264 video elementary stream:  {  char const* streamName = "H264unicast";//流名字,媒体名  char const* inputFileName = "test.264";//文件名,当客户端输入的流名字为h264ESVideoTest时,实际上打开的是test.264文件  // 4.创建媒体会话  //当客户点播时,要输入流名字streamName,告诉RTSP服务器点播的是哪个流。  //流名字和文件名的对应关系是通过增加子会话建立起来的(流名字streamName不是文件名inputFileName)。媒体会话对会话描述、会话持续时间、流名字等与会话有关的信息进行管理  //第二个参数:媒体名、三:媒体信息、四:媒体描述  ServerMediaSession* sms  = ServerMediaSession::createNew(*env, streamName, streamName,  descriptionString);  //5.添加264子会话 这里的文件名才是真正打开文件的名字  //reuseFirstSource:  //这里的H264VideoFileS...类派生自FileServerMediaSubsession派生自OnDemandServerMediaSubsession  //而OnDemandServerMediaSubsession和PassiveMediaSubsession共同派生自ServerMediaSubsession  //关于读取文件之类都在这个类中实现的,如果要将点播改为直播就是要新建类继承此类然后添加新的方法  sms->addSubsession(H264VideoFileServerMediaSubsession  ::createNew(*env, inputFileName, reuseFirstSource));  //6.为rtspserver添加session  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";  }  //执行循环方法,来执行循环方法,对套接字的读取事件和对媒体文件的延时发送操作都在这个循环中完成。  env->taskScheduler().doEventLoop(); // does not return  return 0; // only to prevent compiler warning
}  static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,  char const* streamName, char const* inputFileName) {  char* url = rtspServer->rtspURL(sms);  UsageEnvironment& env = rtspServer->envir();  env << "\n\"" << streamName << "\" stream, from the file \""  << inputFileName << "\"\n";  env << "Play this stream using the URL \"" << url << "\"\n";  delete[] url;
}  

上面的源码分析很清楚了,和官方源码对比一下一目了然。

然后你可以跟 LIVE555再学习 -- testH264VideoStreamer 源码分析 里的代码做一下比较。

玛德 豁然开朗,单播原来也就是这么回事。

想了解更多,参看:Live555学习之(二)------- testOnDemandRTSPServer

这部分看来有点必要后面再认真的讲一下吧

其中的 doEventLoop 函数有点意思 详解参看:LIVE555再学习 -- live555实现RTSP直播服务器 分析

三、测试

在 testProgs 目录下放入 test.264,执行 ./testOnDemandRTSPServer

可以看到有提示嘛,在 VLC 上输入URL rtsp://192.168.2.xx:8554/h264ESVideoTest

OK,有视频显示。此时,我还没看单播和多播区别,也没看testOnDemandRTSPServer的源码,不过好奇怪为什么

上面测试,现在了解到 testOnDemandRTSPServer 是单播,传输现有的 test.264 有是点播。

LIVE555再学习 -- testOnDemandRTSPServer 源码分析相关推荐

  1. LIVE555再学习 -- testH264VideoStreamer 源码分析

    上一篇文章我们已经讲了一部分: testH264VideoStreamer 重复从 H.264 基本流视频文件(名为"test.264")中读取,并使用 RTP 多播进行流式传输. ...

  2. LIVE555再学习 -- OpenRTSP 源码分析

    看了很多东西,感觉有点杂.源码分析部分也看了,讲的也就那样.现在有点不知道从哪讲起了. 参看:nkmnkm的专栏-流媒体 参看:smilestone322的专栏-live555 一.源码组成 包括上述 ...

  3. LIVE555再学习 -- testRTSPClient 源码分析

    现在开讲 testRTSPClient.在官网这这样一段介绍,参看:RTSP client 翻译下来就是: testRTSPClient 是一个命令行程序,显示如何打开和接收由 RTSP URL 指定 ...

  4. MyBatis学习笔记-源码分析篇

    引言 SQL 语句的执行涉及多个组件,其中比较重要的是 Executor. StatementHandler. ParameterHandler 和 ResultSetHandler. Executo ...

  5. Java学习集合源码分析

    集合源码分析 1.集合存在的原因 可以用数组来表示集合,那为什么还需要集合? 1)数组的缺陷 ​ 在创建数组时,必须指定长度,一旦指定便不能改变 数组保存必须是同一个类型的数据 数组的增加和删除不方便 ...

  6. Android学习——LitePal源码分析

    原创技术博客,请认准Azzssss的原文http://www.cnblogs.com/Azzssss/p/4147704.html. 这两天项目终于上线了,松了一口气,虽然还是很不稳定,见一步走一步吧 ...

  7. 【TencentOS tiny学习】源码分析(2)——调度器

    文章目录 调度器的基本概念 启动调度器 Cortex-M内核关中断指令 回归正题 看看任务栈的初始化 查找最高优先级任务 任务切换的实现 SysTick SysTick初始化 SysTick中断 温馨 ...

  8. 【TencentOS tiny学习】源码分析(3)——队列

    文章目录 队列基本概念 队列的阻塞机制 队列实现的数据结构 队列控制块 消息控制块 任务控制块中的消息成员变量 与消息相关的宏定义 消息池 队列创建 销毁队列 清空队列 等待队列(消息) (消息)写入 ...

  9. 【TencentOS tiny学习】源码分析(5)——信号量

    文章目录 信号量 信号量的数据结构 信号量控制块 与信号量相关的宏定义 信号量实现 创建信号量 销毁信号量 获取信号量 释放信号量 总结 关注我吧! 信号量 信号量(sem)在操作系统中是一种实现系统 ...

最新文章

  1. python pandas for循环_高逼格使用Pandas加速代码,向for循环说拜拜!
  2. 金三银四面试季来临,最新BAT面试资料分享给大家
  3. 精通python网络爬虫-精通Python网络爬虫:核心技术、框架与项目实战
  4. Java进阶:Set、Map线程安全问题
  5. 【资源共享】RockChip_LCD开发文档v1.6
  6. 亚信安全与安徽电信共创“云网融合”安全新局面
  7. 如何在ASP.NET Core程序启动时运行异步任务(2)
  8. 《信号与系统》期中总结
  9. 在caffe中使用hdf5的数据
  10. JS高程5.引用类型(6)Array类型的位置方法,迭代方法,归并方法
  11. 拓端tecdat|R语言随机搜索变量选择SSVS估计贝叶斯向量自回归(BVAR)模型
  12. java开发spc分析软件,告诉你们什么才叫真的SPC软件?
  13. 解读汽车机械工作原理GIF图 懂得三个算你牛!
  14. node.js实现网络爬虫获取区划代码和城乡划分代码
  15. 简单实现手机号验证码注册功能
  16. 计算机实验报告双绞线制作,双绞线的制作实验报告.docx
  17. 0717Python总结-return返回值,全局及局部变量,函数名的使用,函数的嵌套,nonlocal修改局部变量,及locals和globals
  18. Android动画了解—转场/过渡(Transition) 动画
  19. Oracle 考试题 答案
  20. 读书笔记:《狼图腾》

热门文章

  1. dubbo的学习使用,第一章
  2. python+selenium七:下拉框、选项框、select用法
  3. 判断字符串NSString是否是整形或者浮点型
  4. TypeError: Cannot red property 'style' of null 错误解决
  5. 3月16日 winform
  6. weblogic配置domain和删除domain
  7. 科大星云诗社动态20210204
  8. 科大星云诗社动态20210323
  9. 二、“究恒常之宇宙,成一家之学说”
  10. Chrome扩展程序——TabCopy:一键复制网页标题和网址