live555是使用十分广泛的开源流媒体服务器,之前也看过其他人写的live555的学习笔记,在这里自己简单总结下。
live555源代码有以下几个明显的特点:
1.头文件是.hh后缀的,但没觉得和.h后缀的有什么不同
2.采用了面向对象的程序设计思路,里面各种对象
好了,不罗嗦,使用vc2010打开live555的vc工程,看到live555源代码结构如下:
源代码由5个工程构成(4个库和一个主程序):
libUsageEnvironment.lib;libliveMedia.lib;libgroupsock.lib;libBasicUsageEnvironment.lib;以及live555MediaServer
这里我们只分析live555MediaServer这个主程序,其实代码量并不大,主要有两个CPP:DynamicRTSPServer.cpp和live555MediaServer.cpp
程序的main()在live555MediaServer.cpp中,在main()中调用了DynamicRTSPServer中的类
不废话,直接贴上有注释的源码
live555MediaServer.cpp:
#include <BasicUsageEnvironment.hh>#include "DynamicRTSPServer.hh"#include "version.hh"int main(int argc, char** argv) { // Begin by setting up our usage environment: // TaskScheduler用于任务计划 TaskScheduler* scheduler = BasicTaskScheduler::createNew(); // UsageEnvironment用于输出 UsageEnvironment* 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 //建立 RTSP server. 使用默认端口 (554), // and then with the alternative port number (8554): RTSPServer* rtspServer; portNumBits rtspServerPortNum = 554; //创建 RTSPServer实例 rtspServer = DynamicRTSPServer::createNew(*env, rtspServerPortNum, authDB); if (rtspServer == NULL) { rtspServerPortNum = 8554; rtspServer = DynamicRTSPServer::createNew(*env, rtspServerPortNum, authDB); } if (rtspServer == NULL) { *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n"; exit(1); } //用到了运算符重载 *env << "LIVE555 Media Server\n"; *env &