live555 处理 sdp消息 一 "OPTIONS"

前言

前面一篇 分析到了 RTSPServer::RTSPClientConnection::handleRequestBytes 进行处理请求消息

消息处理分析

 fprintf(stderr, "RTSPClientConnection[%p]::handleRequestBytes() %s %d new bytes:%s\n",
        this, numBytesRemaining > 0 ? "processing" : "read", newBytesRead, ptr);

 Boolean parseSucceeded = parseRTSPRequestString((char*)fRequestBuffer, 
                             fLastCRLF+2 - fRequestBuffer,
                            cmdName, sizeof cmdName,
                            urlPreSuffix, sizeof urlPreSuffix,
                            urlSuffix, sizeof urlSuffix,
                            cseq, sizeof cseq,
                            sessionIdStr, sizeof sessionIdStr,
                            contentLength);

第一步就是解析请求的数据
因为 解析字符串又可以写一章了,所以,这里根据log 分析

这里首先举例option ,最后分析 其他请求消息

RTSPClientConnection[0xef5bfc40]::handleRequestBytes() read 101 new bytes:
OPTIONS rtsp://192.168.100.10:554/H264Video RTSP/1.0

parseRTSPRequestString() succeeded, returning cmdName "OPTIONS", urlPreSuffix "", urlSuffix "H264Video", CSeq "1", Content-Length 0, with 0 bytes following the message.
sending response: RTSP/1.0 200 OK

知道 解析出的cmdName 是”OPTIONS” urlPreSuffix 前缀没有 “” 后缀 urlSuffix是 “H264Video”

之后判断 消息体中有没有 Session:,因为 Session:只在setup之后出现,所以这里直接不分析,代码如下

Boolean const requestIncludedSessionId = sessionIdStr[0] != '\0';
  if (requestIncludedSessionId) {
    clientSession
      = (RTSPServer::RTSPClientSession*)(fOurRTSPServer.lookupClientSession(sessionIdStr));
    if (clientSession != NULL) clientSession->noteLiveness();
  }

之后直接处理 handleCmd_OPTIONS();函数

void RTSPServer::RTSPClientConnection::handleCmd_OPTIONS() {
  snprintf((char*)fResponseBuffer, sizeof fResponseBuffer,
       "RTSP/1.0 200 OK\r\nCSeq: %s\r\n%sPublic: %s\r\n\r\n",
       fCurrentCSeq, dateHeader(), fOurRTSPServer.allowedCommandNames());
}

因为在上面fCurrentCSeq = cseq; 所以是1
dateHeader() 就是当前时间 进行格式化,类似格式如下

Date: Sat, Jan 01 2000 00:04:58 GMT

allowedCommandNames 告诉客户端 支持的请求方式

char const* RTSPServer::allowedCommandNames() {
  return "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER";
}

如上面消息处理,最后需要发送的消息 fResponseBuffer 内容
RTSP/1.0 200 OK\r\nCSeq: 1\r\nDate: Sat, Jan 01 2000 00:04:58 GMT\r\nPublic: “OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER”\r\n\r\n

客户端打印应该如下格式

RTSP/1.0 200 OK
CSeq: 1
Date: Sat, Jan 01 2000 00:04:58 GMT
Public: "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER"

最后直接通过 send发送给客户端

 send(fClientOutputSocket, (char const*)fResponseBuffer, strlen((char*)fResponseBuffer), 0);

通过是上面返回的消息,就是告诉客户端,本服务器支持的服务请求有哪一些

“OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER”


猜你喜欢

转载自blog.csdn.net/engineer_james/article/details/81516798