兼容一些不规范的rtsp sdp: #1128

This commit is contained in:
xiongziliang 2021-09-29 01:16:52 +08:00
parent 892e151063
commit 4ff206fa42
2 changed files with 18 additions and 57 deletions

View File

@ -19,8 +19,7 @@ int RtpPayload::getClockRate(int pt) {
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return clock_rate; #define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return clock_rate;
RTP_PT_MAP(SWITCH_CASE) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return 90000;
return 90000;
} }
} }
@ -29,8 +28,7 @@ TrackType RtpPayload::getTrackType(int pt) {
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return type; #define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return type;
RTP_PT_MAP(SWITCH_CASE) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return TrackInvalid;
return TrackInvalid;
} }
} }
@ -39,8 +37,7 @@ int RtpPayload::getAudioChannel(int pt) {
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return channel; #define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return channel;
RTP_PT_MAP(SWITCH_CASE) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return 1;
return 1;
} }
} }
@ -49,8 +46,7 @@ const char *RtpPayload::getName(int pt) {
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return #name; #define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return #name;
RTP_PT_MAP(SWITCH_CASE) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return "unknown payload type";
return "unknown payload type";
} }
} }
@ -59,8 +55,7 @@ CodecId RtpPayload::getCodecId(int pt) {
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return codec_id; #define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return codec_id;
RTP_PT_MAP(SWITCH_CASE) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default : default: return CodecInvalid;
return CodecInvalid;
} }
} }
@ -87,8 +82,7 @@ string SdpTrack::getName() const {
#define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return #name; #define SWITCH_CASE(name, type, value, clock_rate, channel, codec_id) case value : return #name;
RTP_PT_MAP(SWITCH_CASE) RTP_PT_MAP(SWITCH_CASE)
#undef SWITCH_CASE #undef SWITCH_CASE
default: default: return _codec;
return _codec;
} }
} }
@ -104,21 +98,11 @@ string SdpTrack::toString() const {
_StrPrinter _printer; _StrPrinter _printer;
switch (_type) { switch (_type) {
case TrackTitle: { case TrackTitle: {
_printer << "v=" << 0 << "\r\n"; TitleSdp title(atof(_t.data()));
if (!_o.empty()) { _printer << title.getSdp();
_printer << "o=" << _o << "\r\n";
}
if (!_c.empty()) {
_printer << "c=" << _c << "\r\n";
}
if (!_t.empty()) {
_printer << "t=" << _t << "\r\n";
}
_printer << "s=Streamed by " << SERVER_NAME << "\r\n";
getAttrSdp(_attr, _printer); getAttrSdp(_attr, _printer);
}
break; break;
}
case TrackAudio: case TrackAudio:
case TrackVideo: { case TrackVideo: {
if (_type == TrackAudio) { if (_type == TrackAudio) {
@ -130,10 +114,9 @@ string SdpTrack::toString() const {
_printer << "b=" << _b << "\r\n"; _printer << "b=" << _b << "\r\n";
} }
getAttrSdp(_attr, _printer); getAttrSdp(_attr, _printer);
break;
} }
break; default: break;
default:
break;
} }
return std::move(_printer); return std::move(_printer);
} }
@ -170,18 +153,6 @@ void SdpParser::load(const string &sdp) {
char opt = line[0]; char opt = line[0];
string opt_val = line.substr(2); string opt_val = line.substr(2);
switch (opt) { switch (opt) {
case 'o':
track->_o = opt_val;
break;
case 's':
track->_s = opt_val;
break;
case 'i':
track->_i = opt_val;
break;
case 'c':
track->_c = opt_val;
break;
case 't': case 't':
track->_t = opt_val; track->_t = opt_val;
break; break;
@ -197,12 +168,11 @@ void SdpParser::load(const string &sdp) {
track->_samplerate = RtpPayload::getClockRate(pt); track->_samplerate = RtpPayload::getClockRate(pt);
track->_channel = RtpPayload::getAudioChannel(pt); track->_channel = RtpPayload::getAudioChannel(pt);
track->_type = toTrackType(type); track->_type = toTrackType(type);
track->_m = opt_val;
track->_port = port; track->_port = port;
_track_vec.emplace_back(track); _track_vec.emplace_back(track);
} }
}
break; break;
}
case 'a': { case 'a': {
string attr = FindField(opt_val.data(), nullptr, ":"); string attr = FindField(opt_val.data(), nullptr, ":");
if (attr.empty()) { if (attr.empty()) {
@ -210,11 +180,9 @@ void SdpParser::load(const string &sdp) {
} else { } else {
track->_attr.emplace(attr, FindField(opt_val.data(), ":", nullptr)); track->_attr.emplace(attr, FindField(opt_val.data(), ":", nullptr));
} }
break;
} }
break; default: track->_other[opt] = opt_val; break;
default:
track->_other[opt] = opt_val;
break;
} }
} }
} }
@ -325,18 +293,17 @@ string SdpParser::toString() const {
switch (track->_type) { switch (track->_type) {
case TrackTitle: { case TrackTitle: {
title = track->toString(); title = track->toString();
}
break; break;
}
case TrackVideo: { case TrackVideo: {
video = track->toString(); video = track->toString();
}
break; break;
}
case TrackAudio: { case TrackAudio: {
audio = track->toString(); audio = track->toString();
break;
} }
break; default: break;
default:
break;
} }
} }
return title + video + audio; return title + video + audio;

View File

@ -205,12 +205,6 @@ private:
class SdpTrack { class SdpTrack {
public: public:
using Ptr = std::shared_ptr<SdpTrack>; using Ptr = std::shared_ptr<SdpTrack>;
string _m;
string _o;
string _s;
string _i;
string _c;
string _t; string _t;
string _b; string _b;
uint16_t _port; uint16_t _port;