Live555 RTSP播放分析(二)--RTSPClient及MediaSession

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

以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) {
      //
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值