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; }; /**