mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
parent
bd7982ecc1
commit
2935bc1932
@ -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;
|
||||
break;
|
||||
case 'b':
|
||||
if (_track_vec.size() == 1)
|
||||
global_infos.emplace(opt, opt_val);
|
||||
else
|
||||
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, "");
|
||||
} 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -243,7 +243,6 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<SdpTrack::Ptr> _track_vec;
|
||||
std::string _control_url;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user