Handling rtsp authentication like ffmpeg, Compatible with some rtsp servers (#4154)

This commit is contained in:
baigao-X 2025-02-19 15:06:11 +08:00 committed by GitHub
parent b66806deb6
commit 12a2f7d491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -174,12 +174,12 @@ bool RtspPlayer::handleAuthenticationFailure(const string &paramsStr) {
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]

View File

@ -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);