RTSP支持强制协商RTP传输方式 (#2572)

当客户端发起RTSP SETUP的时候,如果rtp传输类型和配置不一致则返回461 Unsupported
transport。迫使客户端切换到对应rtp传输协议并重新SETUP;目前支持FFMPEG和VLC。
This commit is contained in:
Talus
2023-06-21 15:35:27 +08:00
committed by GitHub
parent 7e117b1c7f
commit 9f753b5e5f
4 changed files with 45 additions and 9 deletions

View File

@@ -634,19 +634,44 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
//已经初始化过该Track
throw SockException(Err_shutdown, "can not setup one track twice");
}
trackRef->_inited = true; //现在初始化
if(_rtp_type == Rtsp::RTP_Invalid){
auto &strTransport = parser["Transport"];
if(strTransport.find("TCP") != string::npos){
_rtp_type = Rtsp::RTP_TCP;
}else if(strTransport.find("multicast") != string::npos){
_rtp_type = Rtsp::RTP_MULTICAST;
}else{
_rtp_type = Rtsp::RTP_UDP;
static auto getRtpTypeStr = [](const int type) {
switch (type)
{
case Rtsp::RTP_TCP:
return "TCP";
case Rtsp::RTP_UDP:
return "UDP";
case Rtsp::RTP_MULTICAST:
return "MULTICAST";
default:
return "Invalid";
}
};
if (_rtp_type == Rtsp::RTP_Invalid) {
auto &strTransport = parser["Transport"];
auto rtpType = Rtsp::RTP_Invalid;
if (strTransport.find("TCP") != string::npos) {
rtpType = Rtsp::RTP_TCP;
} else if (strTransport.find("multicast") != string::npos) {
rtpType = Rtsp::RTP_MULTICAST;
} else {
rtpType = Rtsp::RTP_UDP;
}
//检查RTP传输类型限制
GET_CONFIG(int, transport, Rtsp::kRtpTransportType);
if (transport != Rtsp::RTP_Invalid && transport != rtpType) {
WarnL << "rtsp client setup transport " << getRtpTypeStr(rtpType) << " but config force transport " << getRtpTypeStr(transport);
//配置限定RTSP传输方式但是客户端握手方式不一致返回461
sendRtspResponse("461 Unsupported transport");
return;
}
_rtp_type = rtpType;
}
trackRef->_inited = true; //现在初始化
//允许接收rtp、rtcp包
RtspSplitter::enableRecvRtp(_rtp_type == Rtsp::RTP_TCP);