diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index d4a1d8f3..4db1f14c 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -190,7 +190,7 @@ SdpItem::Ptr RtcSdpBase::getItem(char key, const char *attr_key) const { } auto attr = dynamic_pointer_cast(item); if (attr && attr->detail->getKey() == attr_key) { - return item; + return attr->detail; } } } @@ -869,3 +869,32 @@ void test_sdp(){ InfoL << sdp1.toString(); InfoL << sdp2.toString(); } + +void RtcSession::loadFrom(const string &str) { + RtcSessionSdp sdp; + sdp.parse(str); + + version = sdp.getVersion(); + origin = sdp.getOrigin(); + session_name = sdp.getSessionName(); + session_info = sdp.getSessionInfo(); + connection = sdp.getConnection(); + bandwidth = sdp.getBandwidth(); + auto group = sdp.getItemClass('a', "group"); + auto mids = group.mids; + + for (auto &media : sdp.medias) { + auto mline = media.getItemClass('m'); + switch (mline.type) { + case TrackVideo: + case TrackAudio: + case TrackApplication: + break; + default: throw std::invalid_argument(StrPrinter << "不识别的media类型:" << mline.toString()); + } + RtcMedia rtc_media; + rtc_media.type = mline.type; + rtc_media.mid = media.getStringItem('a', "mid"); + } + +} diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index 381f51c3..ec38fb05 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -444,9 +444,6 @@ public: string getRepeatTimes() const; RtpDirection getDirection() const; -private: - SdpItem::Ptr getItem(char key, const char *attr_key = nullptr) const; - template cls getItemClass(char key, const char *attr_key = nullptr) const{ auto item = dynamic_pointer_cast(getItem(key, attr_key)); @@ -463,6 +460,9 @@ private: } return item->toString(); } + +private: + SdpItem::Ptr getItem(char key, const char *attr_key = nullptr) const; }; class RtcSessionSdp : public RtcSdpBase{ @@ -551,6 +551,8 @@ public: SdpBandwidth bandwidth; set group_bundle; vector media; + + void loadFrom(const string &sdp); };