From 12a2f7d491a1376c577eefdc87e8d83ed67451ad Mon Sep 17 00:00:00 2001 From: baigao-X <1007668733@qq.com> Date: Wed, 19 Feb 2025 15:06:11 +0800 Subject: [PATCH] Handling rtsp authentication like ffmpeg, Compatible with some rtsp servers (#4154) --- src/Rtsp/RtspPlayer.cpp | 8 ++++---- src/Rtsp/RtspPlayer.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 6a2cea5c..54139466 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -174,12 +174,12 @@ bool RtspPlayer::handleAuthenticationFailure(const string ¶msStr) { return false; } -bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) { +bool RtspPlayer::handleResponse(const std::string &cmd, const Parser &parser, send_method_handler handler) { string authInfo = parser["WWW-Authenticate"]; // 发送DESCRIBE命令后的回复 [AUTO-TRANSLATED:39629cf0] // The response after sending the DESCRIBE command if ((parser.status() == "401") && handleAuthenticationFailure(authInfo)) { - sendOptions(); + (this->*handler)(); return false; } if (parser.status() == "302" || parser.status() == "301") { @@ -197,7 +197,7 @@ bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) { } void RtspPlayer::handleResDESCRIBE(const Parser &parser) { - if (!handleResponse("DESCRIBE", parser)) { + if (!handleResponse("DESCRIBE", parser, &RtspPlayer::sendDescribe)) { return; } _content_base = parser["Content-Base"]; @@ -428,7 +428,7 @@ void RtspPlayer::sendDescribe() { void RtspPlayer::sendOptions() { _on_response = [this](const Parser &parser) { - if (!handleResponse("OPTIONS", parser)) { + if (!handleResponse("OPTIONS", parser, &RtspPlayer::sendOptions)) { return; } // 获取服务器支持的命令 [AUTO-TRANSLATED:8a6a12f1] diff --git a/src/Rtsp/RtspPlayer.h b/src/Rtsp/RtspPlayer.h index 58e2cfa5..e20971d0 100644 --- a/src/Rtsp/RtspPlayer.h +++ b/src/Rtsp/RtspPlayer.h @@ -124,7 +124,8 @@ private: void handleResDESCRIBE(const Parser &parser); bool handleAuthenticationFailure(const std::string &wwwAuthenticateParamsStr); void handleResPAUSE(const Parser &parser, int type); - bool handleResponse(const std::string &cmd, const Parser &parser); + using send_method_handler = void (RtspPlayer::*)(void); + bool handleResponse(const std::string &cmd, const Parser &parser, send_method_handler handler); void sendOptions(); void sendSetup(unsigned int track_idx);