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) {
|
void SdpParser::load(const string &sdp) {
|
||||||
std::multimap<char, std::string> global_infos;
|
|
||||||
{
|
{
|
||||||
_track_vec.clear();
|
_track_vec.clear();
|
||||||
SdpTrack::Ptr track = std::make_shared<SdpTrack>();
|
SdpTrack::Ptr track = std::make_shared<SdpTrack>();
|
||||||
@ -166,23 +165,17 @@ void SdpParser::load(const string &sdp) {
|
|||||||
string opt_val = line.substr(2);
|
string opt_val = line.substr(2);
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 't':
|
case 't':
|
||||||
if (_track_vec.size() == 1)
|
track->_t = opt_val;
|
||||||
global_infos.emplace(opt, opt_val);
|
|
||||||
else
|
|
||||||
track->_t = opt_val;
|
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
if (_track_vec.size() == 1)
|
track->_b = opt_val;
|
||||||
global_infos.emplace(opt, opt_val);
|
|
||||||
else
|
|
||||||
track->_b = opt_val;
|
|
||||||
break;
|
break;
|
||||||
case 'm': {
|
case 'm': {
|
||||||
track = std::make_shared<SdpTrack>();
|
track = std::make_shared<SdpTrack>();
|
||||||
int pt, port, port_count;
|
int pt, port, port_count;
|
||||||
char rtp[16] = { 0 }, type[16];
|
char rtp[16] = {0}, type[16];
|
||||||
if (4 == sscanf(opt_val.data(), " %15[^ ] %d %15[^ ] %d", type, &port, rtp, &pt)
|
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)) {
|
5 == sscanf(opt_val.data(), " %15[^ ] %d/%d %15[^ ] %d", type, &port, &port_count, rtp, &pt)) {
|
||||||
track->_pt = pt;
|
track->_pt = pt;
|
||||||
track->_samplerate = RtpPayload::getClockRate(pt);
|
track->_samplerate = RtpPayload::getClockRate(pt);
|
||||||
track->_channel = RtpPayload::getAudioChannel(pt);
|
track->_channel = RtpPayload::getAudioChannel(pt);
|
||||||
@ -195,43 +188,17 @@ void SdpParser::load(const string &sdp) {
|
|||||||
case 'a': {
|
case 'a': {
|
||||||
string attr = findSubString(opt_val.data(), nullptr, ":");
|
string attr = findSubString(opt_val.data(), nullptr, ":");
|
||||||
if (attr.empty()) {
|
if (attr.empty()) {
|
||||||
if (_track_vec.size() == 1)
|
track->_attr.emplace(opt_val, "");
|
||||||
global_infos.emplace(opt, opt_val);
|
|
||||||
else
|
|
||||||
track->_attr.emplace(opt_val, "");
|
|
||||||
} else {
|
} else {
|
||||||
if (_track_vec.size() == 1)
|
track->_attr.emplace(attr, findSubString(opt_val.data(), ":", nullptr));
|
||||||
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;
|
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) {
|
for (auto &track_ptr : _track_vec) {
|
||||||
auto &track = *track_ptr;
|
auto &track = *track_ptr;
|
||||||
auto it = track._attr.find("range");
|
auto it = track._attr.find("range");
|
||||||
@ -355,9 +322,10 @@ string SdpParser::toString() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string SdpParser::getControlUrl(const std::string &url) 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://开头
|
// 以rtsp://开头
|
||||||
return _control_url;
|
return title_track->_control;
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<SdpTrack::Ptr> _track_vec;
|
std::vector<SdpTrack::Ptr> _track_vec;
|
||||||
std::string _control_url;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user