兼容OPTIONS命令返回401、302等命令

This commit is contained in:
xiongziliang 2020-05-19 10:47:46 +08:00
parent cca9b1758a
commit 5cc4258ba2
2 changed files with 14 additions and 8 deletions

View File

@ -154,12 +154,12 @@ bool RtspPlayer::handleAuthenticationFailure(const string &paramsStr) {
return false; return false;
} }
void RtspPlayer::handleResDESCRIBE(const Parser& parser) { bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser){
string authInfo = parser["WWW-Authenticate"]; string authInfo = parser["WWW-Authenticate"];
//发送DESCRIBE命令后的回复 //发送DESCRIBE命令后的回复
if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) { if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) {
sendOptions(); sendOptions();
return; return false;
} }
if(parser.Url() == "302" || parser.Url() == "301"){ if(parser.Url() == "302" || parser.Url() == "301"){
auto newUrl = parser["Location"]; auto newUrl = parser["Location"];
@ -167,14 +167,19 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
throw std::runtime_error("未找到Location字段(跳转url)"); throw std::runtime_error("未找到Location字段(跳转url)");
} }
play(newUrl); play(newUrl);
return; return false;
} }
if (parser.Url() != "200") { if (parser.Url() != "200") {
throw std::runtime_error( throw std::runtime_error(StrPrinter << cmd << ":" << parser.Url() << " " << parser.Tail() << endl);
StrPrinter << "DESCRIBE:" << parser.Url() << " " << parser.Tail() << endl); }
return true;
}
void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
if (!handleResponse("DESCRIBE", parser)) {
return;
} }
_content_base = parser["Content-Base"]; _content_base = parser["Content-Base"];
if(_content_base.empty()){ if(_content_base.empty()){
_content_base = _play_url; _content_base = _play_url;
} }
@ -351,8 +356,8 @@ void RtspPlayer::sendDescribe() {
void RtspPlayer::sendOptions(){ void RtspPlayer::sendOptions(){
_on_response = [this](const Parser& parser){ _on_response = [this](const Parser& parser){
if (parser.Url() != "200") { if (!handleResponse("OPTIONS", parser)) {
throw std::runtime_error(StrPrinter << "OPTIONS:" << parser.Url() << " " << parser.Tail() << endl); return;
} }
//获取服务器支持的命令 //获取服务器支持的命令
_supported_cmd.clear(); _supported_cmd.clear();

View File

@ -94,6 +94,7 @@ private:
void handleResDESCRIBE(const Parser &parser); void handleResDESCRIBE(const Parser &parser);
bool handleAuthenticationFailure(const string &wwwAuthenticateParamsStr); bool handleAuthenticationFailure(const string &wwwAuthenticateParamsStr);
void handleResPAUSE(const Parser &parser, int type); void handleResPAUSE(const Parser &parser, int type);
bool handleResponse(const string &cmd, const Parser &parser);
void sendOptions(); void sendOptions();
void sendSetup(unsigned int uiTrackIndex); void sendSetup(unsigned int uiTrackIndex);