From 5cc4258ba23e9d5aa96209eac98a1b815cd34252 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 19 May 2020 10:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9OPTIONS=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=BF=94=E5=9B=9E401=E3=80=81302=E7=AD=89=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtspPlayer.cpp | 21 +++++++++++++-------- src/Rtsp/RtspPlayer.h | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 6e1aed29..297266f7 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -154,12 +154,12 @@ bool RtspPlayer::handleAuthenticationFailure(const string ¶msStr) { return false; } -void RtspPlayer::handleResDESCRIBE(const Parser& parser) { +bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser){ string authInfo = parser["WWW-Authenticate"]; //发送DESCRIBE命令后的回复 if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) { sendOptions(); - return; + return false; } if(parser.Url() == "302" || parser.Url() == "301"){ auto newUrl = parser["Location"]; @@ -167,14 +167,19 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) { throw std::runtime_error("未找到Location字段(跳转url)"); } play(newUrl); - return; + return false; } if (parser.Url() != "200") { - throw std::runtime_error( - StrPrinter << "DESCRIBE:" << parser.Url() << " " << parser.Tail() << endl); + throw std::runtime_error(StrPrinter << cmd << ":" << parser.Url() << " " << parser.Tail() << endl); + } + return true; +} + +void RtspPlayer::handleResDESCRIBE(const Parser& parser) { + if (!handleResponse("DESCRIBE", parser)) { + return; } _content_base = parser["Content-Base"]; - if(_content_base.empty()){ _content_base = _play_url; } @@ -351,8 +356,8 @@ void RtspPlayer::sendDescribe() { void RtspPlayer::sendOptions(){ _on_response = [this](const Parser& parser){ - if (parser.Url() != "200") { - throw std::runtime_error(StrPrinter << "OPTIONS:" << parser.Url() << " " << parser.Tail() << endl); + if (!handleResponse("OPTIONS", parser)) { + return; } //获取服务器支持的命令 _supported_cmd.clear(); diff --git a/src/Rtsp/RtspPlayer.h b/src/Rtsp/RtspPlayer.h index 97eadc24..5a7b8efc 100644 --- a/src/Rtsp/RtspPlayer.h +++ b/src/Rtsp/RtspPlayer.h @@ -94,6 +94,7 @@ private: void handleResDESCRIBE(const Parser &parser); bool handleAuthenticationFailure(const string &wwwAuthenticateParamsStr); void handleResPAUSE(const Parser &parser, int type); + bool handleResponse(const string &cmd, const Parser &parser); void sendOptions(); void sendSetup(unsigned int uiTrackIndex);