From 4ff206fa42511ab5ab37a9279dfb664e1b076590 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 29 Sep 2021 01:16:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=80=E4=BA=9B=E4=B8=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E7=9A=84rtsp=20sdp:=20#1128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/Rtsp.cpp | 69 +++++++++++++---------------------------------- src/Rtsp/Rtsp.h | 6 ----- 2 files changed, 18 insertions(+), 57 deletions(-) diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index e1d1507a..693f87a9 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -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; RTP_PT_MAP(SWITCH_CASE) #undef SWITCH_CASE - default: - return 90000; + default: 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; RTP_PT_MAP(SWITCH_CASE) #undef SWITCH_CASE - default: - return TrackInvalid; + default: 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; RTP_PT_MAP(SWITCH_CASE) #undef SWITCH_CASE - default: - return 1; + default: 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; RTP_PT_MAP(SWITCH_CASE) #undef SWITCH_CASE - default: - return "unknown payload type"; + default: 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; RTP_PT_MAP(SWITCH_CASE) #undef SWITCH_CASE - default : - return CodecInvalid; + default: 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; RTP_PT_MAP(SWITCH_CASE) #undef SWITCH_CASE - default: - return _codec; + default: return _codec; } } @@ -104,21 +98,11 @@ string SdpTrack::toString() const { _StrPrinter _printer; switch (_type) { case TrackTitle: { - _printer << "v=" << 0 << "\r\n"; - if (!_o.empty()) { - _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"; + TitleSdp title(atof(_t.data())); + _printer << title.getSdp(); getAttrSdp(_attr, _printer); - } break; + } case TrackAudio: case TrackVideo: { if (_type == TrackAudio) { @@ -130,10 +114,9 @@ string SdpTrack::toString() const { _printer << "b=" << _b << "\r\n"; } getAttrSdp(_attr, _printer); + break; } - break; - default: - break; + default: break; } return std::move(_printer); } @@ -170,18 +153,6 @@ void SdpParser::load(const string &sdp) { char opt = line[0]; string opt_val = line.substr(2); 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': track->_t = opt_val; break; @@ -197,12 +168,11 @@ void SdpParser::load(const string &sdp) { track->_samplerate = RtpPayload::getClockRate(pt); track->_channel = RtpPayload::getAudioChannel(pt); track->_type = toTrackType(type); - track->_m = opt_val; track->_port = port; _track_vec.emplace_back(track); } - } break; + } case 'a': { string attr = FindField(opt_val.data(), nullptr, ":"); if (attr.empty()) { @@ -210,11 +180,9 @@ void SdpParser::load(const string &sdp) { } else { 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) { case TrackTitle: { title = track->toString(); - } break; + } case TrackVideo: { video = track->toString(); - } break; + } case TrackAudio: { audio = track->toString(); + break; } - break; - default: - break; + default: break; } } return title + video + audio; diff --git a/src/Rtsp/Rtsp.h b/src/Rtsp/Rtsp.h index 1e566959..93713b0b 100644 --- a/src/Rtsp/Rtsp.h +++ b/src/Rtsp/Rtsp.h @@ -205,12 +205,6 @@ private: class SdpTrack { public: using Ptr = std::shared_ptr; - - string _m; - string _o; - string _s; - string _i; - string _c; string _t; string _b; uint16_t _port;