From b0f0bdb6aea6240839401ee77aa412f87be3d6dc Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 20 May 2022 22:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BC=98=E5=8C=96webrtc=20sd?= =?UTF-8?q?p=E5=A4=84=E7=90=86=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 10 +++++----- webrtc/Sdp.h | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 9e80d54a..c5b1f174 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -286,9 +286,9 @@ void RtcSessionSdp::parse(const string &str) { item->parse(value); } if (media) { - media->items.push_back(std::move(item)); + media->addItem(std::move(item)); } else { - items.push_back(std::move(item)); + addItem(std::move(item)); } } } @@ -953,7 +953,7 @@ void RtcSession::loadFrom(const string &str) { group = sdp.getItemClass('a', "group"); } -static void toRtsp(vector &items) { +void RtcSdpBase::toRtsp() { for (auto it = items.begin(); it != items.end();) { switch ((*it)->getKey()[0]) { case 'v': @@ -1010,10 +1010,10 @@ string RtcSession::toRtspSdp() const{ CHECK(!copy.media.empty()); auto sdp = copy.toRtcSessionSdp(); - toRtsp(sdp->items); + sdp->toRtsp(); int i = 0; for (auto &m : sdp->medias) { - toRtsp(m.items); + m.toRtsp(); m.addAttr(std::make_shared("control", string("trackID=") + to_string(i++))); } return sdp->toString(); diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index d49a72aa..90746260 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -490,18 +490,16 @@ public: class RtcSdpBase { public: - std::vector items; - void addItem(SdpItem::Ptr item) { items.push_back(item); } + void addItem(SdpItem::Ptr item) { items.push_back(std::move(item)); } void addAttr(SdpItem::Ptr attr) { auto item = std::make_shared(); item->detail = std::move(attr); - items.push_back(item); + items.push_back(std::move(item)); } - SdpItem::Ptr findItem(char key) const { return getItem(key);} - SdpItem::Ptr findAttr(const char* key) const { return getItem('a', key);} -public: + virtual ~RtcSdpBase() = default; virtual std::string toString() const; + void toRtsp(); RtpDirection getDirection() const; @@ -548,6 +546,9 @@ public: } return ret; } + +private: + std::vector items; }; class RtcSessionSdp : public RtcSdpBase{