修复sdp全局信息未保存问题 (#2739)

解决rtsp拉流代理时无法区分直播点播问题
This commit is contained in:
夏楚 2023-08-05 09:24:52 +08:00 committed by GitHub
parent bd7982ecc1
commit 2935bc1932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 44 deletions

View File

@ -149,7 +149,6 @@ static TrackType toTrackType(const string &str) {
}
void SdpParser::load(const string &sdp) {
std::multimap<char, std::string> global_infos;
{
_track_vec.clear();
SdpTrack::Ptr track = std::make_shared<SdpTrack>();
@ -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<SdpTrack>();
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;
}

View File

@ -243,7 +243,6 @@ public:
private:
std::vector<SdpTrack::Ptr> _track_vec;
std::string _control_url;
};
/**