handleCmd_DESCRIBE 函数

handleCmd_DESCRIBE 函数主要的任务就,在客户端发送过来describe 是回复SDP,如果里边想实现多个session的自动创建,可以重装lookupServerMediaSession,下面是函数注释



void RTSPServer::RTSPClientConnection
::handleCmd_DESCRIBE(char const* urlPreSuffix, char const* urlSuffix, char const* fullRequestStr) {
	char* sdpDescription = NULL;
	char* rtspURL = NULL;
	do
	{
		char urlTotalSuffix[RTSP_PARAM_STRING_MAX];
		if (strlen(urlPreSuffix) + strlen(urlSuffix) + 2 > sizeof urlTotalSuffix)
		{
			handleCmd_bad();
			break;
		}
		urlTotalSuffix[0] = '\0';
		if (urlPreSuffix[0] != '\0')
		{
			strcat(urlTotalSuffix, urlPreSuffix);
			strcat(urlTotalSuffix, "/");
		}
		strcat(urlTotalSuffix, urlSuffix);

		//如果开启认证的话,此处会验证用户名和密码
		if (!authenticationOK("DESCRIBE", urlTotalSuffix, fullRequestStr)) break;

		// We should really check that the request contains an "Accept:" #####
		// for "application/sdp", because that's what we're sending back #####

		// Begin by looking up the "ServerMediaSession" object for the specified "urlTotalSuffix":
		//根据名称查找服务,如果找不到退出,也可重载,在lookupServerMediaSession中创建session,live555自带rtsp服务就这么做的。
		ServerMediaSession* session = fOurServer.lookupServerMediaSession(urlTotalSuffix);
		if (session == NULL)
		{
			handleCmd_notFound();
			break;
		}

		//获取SDP
		// Then, assemble a SDP description for this session:
		sdpDescription = session->generateSDPDescription();
		if (sdpDescription == NULL)
		{
			// This usually means that a file name that was specified for a
			// "ServerMediaSubsession" does not exist.
			setRTSPResponse("404 File Not Found, Or In Incorrect Format");
			break;
		}
		unsigned sdpDescriptionSize = strlen(sdpDescription);

		//产生RTSP URL,为了在setup中使用,一种情况是发过来是 rtsp://****/2.h264 没有2.h264 给你转成2-1.h264 
		// Also, generate our RTSP URL, for the "Content-Base:" header
		// (which is necessary to ensure that the correct URL gets used in subsequent "SETUP" requests).
		rtspURL = fOurServer.rtspURL(session, fClientInputSocket);

		snprintf((char*)fResponseBuffer, sizeof fResponseBuffer,
			"RTSP/1.0 200 OK\r\nCSeq: %s\r\n"
			"%s"
			"Content-Base: %s/\r\n"
			"Content-Type: application/sdp\r\n"
			"Content-Length: %d\r\n\r\n"
			"%s",
			fCurrentCSeq,
			dateHeader(),
			rtspURL,
			sdpDescriptionSize,
			sdpDescription);
	} while (0);

	delete[] sdpDescription;
	delete[] rtspURL;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值