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{