From 2935bc1932a5bf50ce2dc0479dd704b1c62d77d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 5 Aug 2023 09:24:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsdp=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=9C=AA=E4=BF=9D=E5=AD=98=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#2739)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决rtsp拉流代理时无法区分直播点播问题 --- src/Rtsp/Rtsp.cpp | 54 ++++++++++------------------------------------- src/Rtsp/Rtsp.h | 1 - 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index f4963531..b5b50360 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -149,7 +149,6 @@ static TrackType toTrackType(const string &str) { } void SdpParser::load(const string &sdp) { - std::multimap global_infos; { _track_vec.clear(); SdpTrack::Ptr track = std::make_shared(); @@ -166,23 +165,17 @@ void SdpParser::load(const string &sdp) { string opt_val = line.substr(2); switch (opt) { case 't': - if (_track_vec.size() == 1) - global_infos.emplace(opt, opt_val); - else - track->_t = opt_val; + track->_t = opt_val; break; case 'b': - if (_track_vec.size() == 1) - global_infos.emplace(opt, opt_val); - else - track->_b = opt_val; + track->_b = opt_val; break; case 'm': { track = std::make_shared(); int pt, port, port_count; - char rtp[16] = { 0 }, type[16]; - if (4 == sscanf(opt_val.data(), " %15[^ ] %d %15[^ ] %d", type, &port, rtp, &pt) - || 5 == sscanf(opt_val.data(), " %15[^ ] %d/%d %15[^ ] %d", type, &port, &port_count, rtp, &pt)) { + char rtp[16] = {0}, type[16]; + if (4 == sscanf(opt_val.data(), " %15[^ ] %d %15[^ ] %d", type, &port, rtp, &pt) || + 5 == sscanf(opt_val.data(), " %15[^ ] %d/%d %15[^ ] %d", type, &port, &port_count, rtp, &pt)) { track->_pt = pt; track->_samplerate = RtpPayload::getClockRate(pt); track->_channel = RtpPayload::getAudioChannel(pt); @@ -195,43 +188,17 @@ void SdpParser::load(const string &sdp) { case 'a': { string attr = findSubString(opt_val.data(), nullptr, ":"); if (attr.empty()) { - if (_track_vec.size() == 1) - global_infos.emplace(opt, opt_val); - else - track->_attr.emplace(opt_val, ""); + track->_attr.emplace(opt_val, ""); } else { - if (_track_vec.size() == 1) - global_infos.emplace(opt, opt_val); - else - track->_attr.emplace(attr, findSubString(opt_val.data(), ":", nullptr)); - } - break; - } - default: { - if (_track_vec.size() == 1) { - global_infos.emplace(opt, opt_val); - } else { - track->_other[opt] = opt_val; + track->_attr.emplace(attr, findSubString(opt_val.data(), ":", nullptr)); } break; } + default: track->_other[opt] = opt_val; break; } } } - for (auto &info : global_infos) { - std::string attr; - switch (info.first) { - case 'a': - attr = findSubString(info.second.data(), nullptr, ":"); - if (attr == "control") { - _control_url = findSubString(info.second.data(), ":", nullptr); - } - break; - - default: break; - } - } for (auto &track_ptr : _track_vec) { auto &track = *track_ptr; auto it = track._attr.find("range"); @@ -355,9 +322,10 @@ string SdpParser::toString() const { } std::string SdpParser::getControlUrl(const std::string &url) const { - if (_control_url.find("://") != string::npos) { + auto title_track = getTrack(TrackTitle); + if (title_track && title_track->_control.find("://") != string::npos) { // 以rtsp://开头 - return _control_url; + return title_track->_control; } return url; } diff --git a/src/Rtsp/Rtsp.h b/src/Rtsp/Rtsp.h index 01817315..dc34f918 100644 --- a/src/Rtsp/Rtsp.h +++ b/src/Rtsp/Rtsp.h @@ -243,7 +243,6 @@ public: private: std::vector _track_vec; - std::string _control_url; }; /**