diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 04d7b184..97003f3b 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -76,24 +76,35 @@ void RtspPlayer::teardown(){ } void RtspPlayer::play(const string &strUrl){ - auto userAndPwd = FindField(strUrl.data(),"://","@"); Rtsp::eRtpType eType = (Rtsp::eRtpType)(int)(*this)[kRtpType]; - if(userAndPwd.empty()){ - play(strUrl,"","",eType); - return; + auto schema = FindField(strUrl.data(), nullptr,"://"); + bool isSSL = strcasecmp(schema.data(),"rtsps") == 0; + //查找"://"与"/"之间的字符串,用于提取用户名密码 + auto middle_url = FindField(strUrl.data(),"://","/"); + if(middle_url.empty()){ + middle_url = FindField(strUrl.data(),"://", nullptr); } - auto suffix = FindField(strUrl.data(),"@",nullptr); + auto pos = middle_url.rfind('@'); + if(pos == string::npos){ + //并没有用户名密码 + play(isSSL,strUrl,"","",eType); + return; + } + + //包含用户名密码 + auto user_pwd = middle_url.substr(0,pos); + auto suffix = strUrl.substr(schema.size() + 3 + pos + 1); auto url = StrPrinter << "rtsp://" << suffix << endl; - if(userAndPwd.find(":") == string::npos){ - play(url,userAndPwd,"",eType); + if(user_pwd.find(":") == string::npos){ + play(isSSL,url,user_pwd,"",eType); return; } - auto user = FindField(userAndPwd.data(),nullptr,":"); - auto pwd = FindField(userAndPwd.data(),":",nullptr); - play(url,user,pwd,eType); + auto user = FindField(user_pwd.data(),nullptr,":"); + auto pwd = FindField(user_pwd.data(),":",nullptr); + play(isSSL,url,user,pwd,eType); } -//播放,指定是否走rtp over tcp -void RtspPlayer::play(const string &strUrl, const string &strUser, const string &strPwd, Rtsp::eRtpType eType ) { + +void RtspPlayer::play(bool isSSL,const string &strUrl, const string &strUser, const string &strPwd, Rtsp::eRtpType eType ) { DebugL << strUrl << " " << (strUser.size() ? strUser : "null") << " " << (strPwd.size() ? strPwd:"null") << " " @@ -117,7 +128,7 @@ void RtspPlayer::play(const string &strUrl, const string &strUser, const string auto port = atoi(FindField(ip.data(), ":", NULL).data()); if (port <= 0) { //rtsp 默认端口554 - port = 554; + port = isSSL ? 322 : 554; } else { //服务器域名 ip = FindField(ip.data(), NULL, ":"); diff --git a/src/Rtsp/RtspPlayer.h b/src/Rtsp/RtspPlayer.h index 4de652d8..be170953 100644 --- a/src/Rtsp/RtspPlayer.h +++ b/src/Rtsp/RtspPlayer.h @@ -107,7 +107,7 @@ private: int getTrackIndexByInterleaved(int interleaved) const; int getTrackIndexByTrackType(TrackType trackType) const; - void play(const string &strUrl, const string &strUser, const string &strPwd, Rtsp::eRtpType eType); + void play(bool isSSL,const string &strUrl, const string &strUser, const string &strPwd, Rtsp::eRtpType eType); void handleResSETUP(const Parser &parser, unsigned int uiTrackIndex); void handleResDESCRIBE(const Parser &parser); bool handleAuthenticationFailure(const string &wwwAuthenticateParamsStr);