From c5fff23040e08bc547f37f23e779cd37d9b5491b Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Fri, 7 May 2021 14:08:43 +0800 Subject: [PATCH] =?UTF-8?q?extmap=E6=94=B9=E7=94=A8map=E5=AD=98=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 26 ++++++++++++++++---------- webrtc/Sdp.h | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 6adc4451..830cd52a 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -535,8 +535,8 @@ string SdpAttrSetup::toString() const { void SdpAttrExtmap::parse(const string &str) { char buf[128] = {0}; char direction_buf[32] = {0}; - if (sscanf(str.data(), "%" SCNd32 "/%31[^ ] %127s", &index, direction_buf, buf) != 3) { - if (sscanf(str.data(), "%" SCNd32 " %127s", &index, buf) != 2) { + if (sscanf(str.data(), "%" SCNd8 "/%31[^ ] %127s", &id, direction_buf, buf) != 3) { + if (sscanf(str.data(), "%" SCNd8 " %127s", &id, buf) != 2) { SDP_THROW(); } direction = RtpDirection::sendrecv; @@ -549,9 +549,9 @@ void SdpAttrExtmap::parse(const string &str) { string SdpAttrExtmap::toString() const { if (value.empty()) { if(direction == RtpDirection::invalid || direction == RtpDirection::sendrecv){ - value = to_string(index) + " " + ext; + value = to_string((int)id) + " " + ext; } else { - value = to_string(index) + "/" + getRtpDirectionString(direction) + " " + ext; + value = to_string((int)id) + "/" + getRtpDirectionString(direction) + " " + ext; } } return SdpItem::toString(); @@ -806,7 +806,13 @@ void RtcSession::loadFrom(const string &str, bool check) { } rtc_media.rtcp_addr = media.getItemClass('a', "rtcp"); rtc_media.direction = media.getDirection(); - rtc_media.extmap = media.getAllItem('a', "extmap"); + { + rtc_media.extmap.clear(); + auto arr = media.getAllItem('a', "extmap"); + for (auto &ext : arr) { + rtc_media.extmap.emplace(ext.id, ext); + } + } rtc_media.rtcp_mux = media.getItem('a', "rtcp-mux").operator bool(); rtc_media.rtcp_rsize = media.getItem('a', "rtcp-rsize").operator bool(); @@ -1055,8 +1061,8 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{ if (m.ice_lite) { sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared("ice-lite"))); } - for (auto &ext : m.extmap) { - sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(ext))); + for (auto &pr : m.extmap) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(pr.second))); } if (m.direction != RtpDirection::invalid) { sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.direction))); @@ -1562,9 +1568,9 @@ RETRY: } //对方和我方都支持的扩展,那么我们才支持 - for (auto &ext : offer_media.extmap) { - if (configure.extmap.find(RtpExt::getExtType(ext.ext)) != configure.extmap.end()) { - answer_media.extmap.emplace_back(ext); + for (auto &pr : offer_media.extmap) { + if (configure.extmap.find(RtpExt::getExtType(pr.second.ext)) != configure.extmap.end()) { + answer_media.extmap.emplace(pr); } } diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index 2195ccaf..bfff21eb 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -337,7 +337,7 @@ class SdpAttrExtmap : public SdpItem { public: //https://aggresss.blog.csdn.net/article/details/106436703 //a=extmap:1[/sendonly] urn:ietf:params:rtp-hdrext:ssrc-audio-level - uint32_t index; + uint8_t id; RtpDirection direction{RtpDirection::invalid}; string ext; void parse(const string &str) override; @@ -636,7 +636,7 @@ public: SdpAttrFingerprint fingerprint; //////// extmap //////// - vector extmap; + map extmap; //////// sctp //////////// SdpAttrSctpMap sctpmap;