Commit 4e33f5b4 by xiongguangjie Committed by GitHub

rtsp player add query param for content-base (#2637)

rtsp以content-base为基准,增加url的query参数(根据抓包分析,vlc是这样处理的),以兼容海康rtsp录像流与
直播流,主要是为了兼容这两个issue: #2624 #2501
parent 8ee91d70
......@@ -320,7 +320,6 @@ void splitUrl(const std::string &url, std::string &host, uint16_t &port) {
host = url.substr(0, pos);
checkHost(host);
}
#if 0
//测试代码
static onceToken token([](){
......
......@@ -38,8 +38,8 @@ RtspPlayer::~RtspPlayer(void) {
void RtspPlayer::sendTeardown() {
if (alive()) {
if (!_content_base.empty()) {
sendRtspRequest("TEARDOWN", _content_base);
if (!_control_url.empty()) {
sendRtspRequest("TEARDOWN", _control_url);
}
shutdown(SockException(Err_shutdown, "teardown"));
}
......@@ -203,6 +203,8 @@ void RtspPlayer::handleResDESCRIBE(const Parser &parser) {
// 解析sdp
SdpParser sdpParser(parser.content());
_control_url = sdpParser.getControlUrl(_content_base);
string sdp;
auto play_track = (TrackType)((int)(*this)[Client::kPlayTrack] - 1);
if (play_track != TrackInvalid) {
......@@ -412,7 +414,7 @@ void RtspPlayer::sendKeepAlive() {
_on_response = [](const Parser &parser) {};
if (_supported_cmd.find("GET_PARAMETER") != _supported_cmd.end()) {
// 支持GET_PARAMETER,用此命令保活
sendRtspRequest("GET_PARAMETER", _content_base);
sendRtspRequest("GET_PARAMETER", _control_url);
} else {
// 不支持GET_PARAMETER,用OPTIONS命令保活
sendRtspRequest("OPTIONS", _play_url);
......@@ -423,12 +425,12 @@ void RtspPlayer::sendPause(int type, uint32_t seekMS) {
_on_response = std::bind(&RtspPlayer::handleResPAUSE, this, placeholders::_1, type);
// 开启或暂停rtsp
switch (type) {
case type_pause: sendRtspRequest("PAUSE", _content_base); break;
case type_pause: sendRtspRequest("PAUSE", _control_url, {}); break;
case type_play:
// sendRtspRequest("PLAY", _content_base);
// break;
case type_seek:
sendRtspRequest("PLAY", _content_base, { "Range", StrPrinter << "npt=" << setiosflags(ios::fixed) << setprecision(2) << seekMS / 1000.0 << "-" });
sendRtspRequest("PLAY", _control_url, { "Range", StrPrinter << "npt=" << setiosflags(ios::fixed) << setprecision(2) << seekMS / 1000.0 << "-" });
break;
default:
WarnL << "unknown type : " << type;
......@@ -442,7 +444,7 @@ void RtspPlayer::pause(bool bPause) {
}
void RtspPlayer::speed(float speed) {
sendRtspRequest("PLAY", _content_base, { "Scale", StrPrinter << speed });
sendRtspRequest("PLAY", _control_url, { "Scale", StrPrinter << speed });
}
void RtspPlayer::handleResPAUSE(const Parser &parser, int type) {
......@@ -451,7 +453,7 @@ void RtspPlayer::handleResPAUSE(const Parser &parser, int type) {
case type_pause: WarnL << "Pause failed:" << parser.status() << " " << parser.statusStr(); break;
case type_play:
WarnL << "Play failed:" << parser.status() << " " << parser.statusStr();
onPlayResult_l(SockException(Err_shutdown, StrPrinter << "rtsp play failed:" << parser.status() << " " << parser.statusStr()), !_play_check_timer);
onPlayResult_l(SockException(Err_other, StrPrinter << "rtsp play failed:" << parser.status() << " " << parser.statusStr()), !_play_check_timer);
break;
case type_seek: WarnL << "Seek failed:" << parser.status() << " " << parser.statusStr(); break;
}
......@@ -571,6 +573,7 @@ void RtspPlayer::sendRtspRequest(const string &cmd, const string &url, const std
key = val;
}
}
sendRtspRequest(cmd, url, header_map);
}
......@@ -615,12 +618,9 @@ void RtspPlayer::sendRtspRequest(const string &cmd, const string &url, const Str
}
_StrPrinter printer;
if (cmd == "PLAY") {
printer << cmd << " " << _play_url << " RTSP/1.0\r\n";
} else {
printer << cmd << " " << url << " RTSP/1.0\r\n";
}
printer << cmd << " " << url << " RTSP/1.0\r\n";
TraceL << cmd << " "<< url;
for (auto &pr : header) {
printer << pr.first << ": " << pr.second << "\r\n";
}
......@@ -743,7 +743,7 @@ int RtspPlayer::getTrackIndexByTrackType(TrackType track_type) const {
if (_sdp_track.size() == 1) {
return 0;
}
throw SockException(Err_shutdown, StrPrinter << "no such track with type:" << getTrackString(track_type));
throw SockException(Err_other, StrPrinter << "no such track with type:" << getTrackString(track_type));
}
///////////////////////////////////////////////////
......
......@@ -129,6 +129,7 @@ private:
std::string _session_id;
uint32_t _cseq_send = 1;
std::string _content_base;
std::string _control_url;
Rtsp::eRtpType _rtp_type = Rtsp::RTP_TCP;
//当前rtp时间戳
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论