以testRTSPClient.cpp测试程序来对Live555 RTSP播放进行一个简单的分析。同时对Live555几大模块的功能及使用进行简单描述。
因为我对Live555使用的比较多的是在客户端播放场景下,所以可能有些不足或者错误,请指正。
上一章节描述了Live555基础模块,具备这些知识后,我们进入主题,来分析RTSP播放流程,其中最主要的流程在RTSPClient及MediaSession中。
testRTSPClient
testRTSPClient main函数其实就做了几个事情:
1、创建scheduler 及env;
2、打开播放地址;
3、让程序进入消息循环跑起来。env->taskScheduler().doEventLoop(&eventLoopWatchVariable);
int main(int argc, char** argv) {
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
// We need at least one "rtsp://" URL argument:
if (argc < 2) {
usage(*env, argv[0]);
return 1;
}
openURL(*env, argv[0], argv[1]);
if(argc >= 3 && strstr(argv[2],"tcp")){
REQUEST_STREAMING_OVER_TCP = true;
}
env->taskScheduler().doEventLoop(&eventLoopWatchVariable);
return 0;
openURL中创建了ourRTSPClient,其是RTSPClient的子类。然后调用rtspClient->sendDescribeCommand(continueAfterDESCRIBE);发出DESCRIBE。
continueAfterDESCRIBE为回调函数。
DESCRIBE
DESCRIBE比较简单,就是发出DESCRIBE命令。
unsigned RTSPClient::sendDescribeCommand(responseHandler* responseHandler, Authenticator* authenticator) {
if (fCurrentAuthenticator < authenticator) fCurrentAuthenticator = *authenticator;
return sendRequest(new RequestRecord(++fCSeq, "DESCRIBE", responseHandler));
}
简单分析下sendRequest:
首先建立TCP连接int connectResult = openConnection();
int RTSPClient::openConnection() {
do {
...省略
//1.解析是否需要账号密码,有些RTSP连接是携带账号密码的,这个在视频监控领域比较常见:
if (!parseRTSPURL(envir(), fBaseURL, username, password, destAddress, urlPortNum, &urlSuffix)) break;
portNumBits destPortNum = fTunnelOverHTTPPortNum == 0 ? urlPortNum : fTunnelOverHTTPPortNum;
if (username != NULL || password != NULL) {
fCurrentAuthenticator.setUsernameAndPassword(username, password);
delete[] username;
delete[] password;
}
//2.建立TCP Socket,连接服务器:
fInputSocketNum = fOutputSocketNum = setupStreamSocket(envir(), Port(0), destAddress.getFamily());
if (fInputSocketNum < 0) break;
ignoreSigPipeOnSocket(fInputSocketNum); // so that servers on the same host that get killed don't also kill us
// Connect to the remote endpoint:
fServerAddress = destAddress;
int connectResult = connectToServer(fInputSocketNum, destPortNum);
if (connectResult < 0) break;
else if (connectResult > 0) {
//

本文详细解析了Live555 RTSP播放流程,从testRTSPClient.cpp测试程序入手,深入分析了RTSPClient及MediaSession模块的工作原理,包括连接建立、命令发送、响应处理、媒体会话创建及媒体子会话设置等关键步骤。
2008

被折叠的 条评论
为什么被折叠?



