mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
提高rtsp客户端兼容性
This commit is contained in:
parent
2b511a05cc
commit
a573d7302b
@ -85,20 +85,38 @@ string SdpTrack::toString() const {
|
||||
}
|
||||
return _printer;
|
||||
}
|
||||
|
||||
static TrackType toTrackType(const string &str) {
|
||||
if (str == "") {
|
||||
return TrackTitle;
|
||||
}
|
||||
|
||||
if (str == "video") {
|
||||
return TrackVideo;
|
||||
}
|
||||
|
||||
if (str == "audio") {
|
||||
return TrackAudio;
|
||||
}
|
||||
|
||||
return TrackInvalid;
|
||||
}
|
||||
|
||||
void SdpParser::load(const string &sdp) {
|
||||
_track_map.clear();
|
||||
{
|
||||
_track_vec.clear();
|
||||
string key;
|
||||
SdpTrack::Ptr track = std::make_shared<SdpTrack>();
|
||||
|
||||
auto lines = split(sdp,"\n");
|
||||
for (auto &line : lines){
|
||||
auto lines = split(sdp, "\n");
|
||||
for (auto &line : lines) {
|
||||
trim(line);
|
||||
if(line.size() < 2 || line[1] != '='){
|
||||
if (line.size() < 2 || line[1] != '=') {
|
||||
continue;
|
||||
}
|
||||
char opt = line[0];
|
||||
string opt_val = line.substr(2);
|
||||
switch (opt){
|
||||
switch (opt) {
|
||||
case 'o':
|
||||
track->_o = opt_val;
|
||||
break;
|
||||
@ -117,19 +135,20 @@ void SdpParser::load(const string &sdp) {
|
||||
case 'b':
|
||||
track->_b = opt_val;
|
||||
break;
|
||||
case 'm':{
|
||||
_track_map[key] = track;
|
||||
case 'm': {
|
||||
track->_type = toTrackType(key);
|
||||
_track_vec.emplace_back(track);
|
||||
track = std::make_shared<SdpTrack>();
|
||||
key = FindField(opt_val.data(), nullptr," ");
|
||||
key = FindField(opt_val.data(), nullptr, " ");
|
||||
track->_m = opt_val;
|
||||
}
|
||||
break;
|
||||
case 'a':{
|
||||
string attr = FindField(opt_val.data(), nullptr,":");
|
||||
if(attr.empty()){
|
||||
case 'a': {
|
||||
string attr = FindField(opt_val.data(), nullptr, ":");
|
||||
if (attr.empty()) {
|
||||
track->_attr[opt_val] = "";
|
||||
}else{
|
||||
track->_attr[attr] = FindField(opt_val.data(),":", nullptr);
|
||||
} else {
|
||||
track->_attr[attr] = FindField(opt_val.data(), ":", nullptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -138,21 +157,12 @@ void SdpParser::load(const string &sdp) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_track_map[key] = track;
|
||||
|
||||
|
||||
for (auto &pr : _track_map) {
|
||||
auto &track = *pr.second;
|
||||
if (pr.first == "") {
|
||||
track._type = TrackTitle;
|
||||
} else if (pr.first == "video") {
|
||||
track._type = TrackVideo;
|
||||
} else if (pr.first == "audio") {
|
||||
track._type = TrackAudio;
|
||||
} else {
|
||||
track._type = TrackInvalid;
|
||||
track->_type = toTrackType(key);
|
||||
_track_vec.emplace_back(track);
|
||||
}
|
||||
|
||||
for (auto &track_ptr : _track_vec) {
|
||||
auto &track = *track_ptr;
|
||||
auto it = track._attr.find("range");
|
||||
if (it != track._attr.end()) {
|
||||
char name[16] = {0}, start[16] = {0}, end[16] = {0};
|
||||
@ -198,9 +208,9 @@ bool SdpParser::available() const {
|
||||
}
|
||||
|
||||
SdpTrack::Ptr SdpParser::getTrack(TrackType type) const {
|
||||
for (auto &pr : _track_map){
|
||||
if(pr.second->_type == type){
|
||||
return pr.second;
|
||||
for (auto &track : _track_vec){
|
||||
if(track->_type == type){
|
||||
return track;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@ -208,31 +218,42 @@ SdpTrack::Ptr SdpParser::getTrack(TrackType type) const {
|
||||
|
||||
vector<SdpTrack::Ptr> SdpParser::getAvailableTrack() const {
|
||||
vector<SdpTrack::Ptr> ret;
|
||||
auto video = getTrack(TrackVideo);
|
||||
if(video){
|
||||
ret.emplace_back(video);
|
||||
bool audio_added = false;
|
||||
bool video_added = false;
|
||||
for (auto &track : _track_vec){
|
||||
if(track->_type == TrackAudio ){
|
||||
if(!audio_added){
|
||||
ret.emplace_back(track);
|
||||
audio_added = true;
|
||||
}
|
||||
auto audio = getTrack(TrackAudio);
|
||||
if(audio){
|
||||
ret.emplace_back(audio);
|
||||
continue;
|
||||
}
|
||||
return ret;
|
||||
|
||||
if(track->_type == TrackVideo ){
|
||||
if(!video_added){
|
||||
ret.emplace_back(track);
|
||||
video_added = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return std::move(ret);
|
||||
}
|
||||
|
||||
string SdpParser::toString() const {
|
||||
string title,audio,video;
|
||||
for(auto &pr : _track_map){
|
||||
switch (pr.second->_type){
|
||||
for(auto &track : _track_vec){
|
||||
switch (track->_type){
|
||||
case TrackTitle:{
|
||||
title = pr.second->toString();
|
||||
title = track->toString();
|
||||
}
|
||||
break;
|
||||
case TrackVideo:{
|
||||
video = pr.second->toString();
|
||||
video = track->toString();
|
||||
}
|
||||
break;
|
||||
case TrackAudio:{
|
||||
audio = pr.second->toString();
|
||||
audio = track->toString();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -122,7 +122,7 @@ public:
|
||||
vector<SdpTrack::Ptr> getAvailableTrack() const;
|
||||
string toString() const ;
|
||||
private:
|
||||
map<string, SdpTrack::Ptr> _track_map;
|
||||
vector<SdpTrack::Ptr> _track_vec;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user