From ba06def4d8113d2c046998e0eac8fd513a4067e6 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Mon, 29 Mar 2021 12:00:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E6=8F=90=E5=8F=96=E6=B1=87?= =?UTF-8?q?=E6=80=BBsdp=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 31 ++++++++++++++++++++++++++++++- webrtc/Sdp.h | 8 +++++--- 2 files changed, 35 insertions(+), 4 deletions(-) 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); };