From 4853a5af4821ef486d1ba512c4bf352146aa08eb Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Thu, 1 Apr 2021 11:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84answer=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 34 +++++++++++++++++++--------------- webrtc/Sdp.h | 4 ++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index eca66a61..0230f914 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -924,12 +924,14 @@ string RtcSession::toString() const{ sdp.items.emplace_back(std::make_shared >(session_info)); } sdp.items.emplace_back(std::make_shared(time)); - sdp.items.emplace_back(std::make_shared(connection)); + if(connection.empty()){ + sdp.items.emplace_back(std::make_shared(connection)); + } if (!bandwidth.empty()) { sdp.items.emplace_back(std::make_shared(bandwidth)); } - sdp.items.emplace_back(wrapSdpAttr(std::make_shared(msid_semantic))); sdp.items.emplace_back(wrapSdpAttr(std::make_shared(group))); + sdp.items.emplace_back(wrapSdpAttr(std::make_shared(msid_semantic))); for (auto &m : media) { sdp.medias.emplace_back(); auto &sdp_media = sdp.medias.back(); @@ -944,18 +946,22 @@ string RtcSession::toString() const{ mline->fmts.emplace_back(m.sctp_port); } sdp_media.items.emplace_back(std::move(mline)); - sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.mid))); sdp_media.items.emplace_back(std::make_shared(m.addr)); + if (!m.rtcp_addr.empty()) { + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.rtcp_addr))); + } + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.ice_ufrag))); sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.ice_pwd))); - sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.fingerprint))); - sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.role))); if (m.ice_trickle || m.ice_renomination) { auto attr = std::make_shared(); attr->trickle = m.ice_trickle; attr->renomination = m.ice_renomination; sdp_media.items.emplace_back(wrapSdpAttr(attr)); } + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.fingerprint))); + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.role))); + sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.mid))); if (m.ice_lite) { sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared("ice-lite"))); } @@ -965,9 +971,6 @@ string RtcSession::toString() const{ if (m.direction != RtpDirection::invalid) { sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.direction))); } - if (m.rtcp_addr.port) { - sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared(m.rtcp_addr))); - } if (m.rtcp_mux) { sdp_media.items.emplace_back(wrapSdpAttr(std::make_shared("rtcp-mux"))); } @@ -1145,7 +1148,7 @@ RtcMedia *RtcSession::getMedia(TrackType type){ void RtcConfigure::RtcTrackConfigure::setDefaultSetting(TrackType type){ enable = true; rtcp_mux = true; - rtcp_rsize = false; + rtcp_rsize = true; group_bundle = true; unified_plan = false; support_rtx = true; @@ -1238,11 +1241,9 @@ shared_ptr RtcConfigure::createOffer(){ shared_ptr RtcConfigure::createAnswer(const RtcSession &offer){ shared_ptr ret = std::make_shared(); ret->version = offer.version; - ret->origin.parse("- 0 0 IN IP4 0.0.0.0"); - ret->session_name = "zlmediakit_webrtc_session"; - ret->session_info = "zlmediakit_webrtc_session"; - ret->connection.parse("IN IP4 0.0.0.0"); - ret->msid_semantic.parse("WMS *"); + ret->origin = offer.origin; + ret->session_name = offer.session_name; + ret->msid_semantic = offer.msid_semantic; matchMedia(ret, TrackAudio, offer.media, audio); matchMedia(ret, TrackVideo, offer.media, video); matchMedia(ret, TrackApplication, offer.media, application); @@ -1283,19 +1284,22 @@ void RtcConfigure::matchMedia(shared_ptr &ret, TrackType type, const answer_media.type = offer_media.type; answer_media.mid = offer_media.mid; answer_media.proto = offer_media.proto; + answer_media.port = offer_media.port; answer_media.rtcp_mux = offer_media.rtcp_mux && configure.rtcp_mux; answer_media.rtcp_rsize = offer_media.rtcp_rsize && configure.rtcp_rsize; + answer_media.rtcp_addr = offer_media.rtcp_addr; answer_media.ice_trickle = offer_media.ice_trickle && configure.ice_trickle; answer_media.ice_renomination = offer_media.ice_renomination && configure.ice_renomination; answer_media.ice_ufrag = configure.ice_ufrag; answer_media.ice_pwd = configure.ice_pwd; answer_media.fingerprint = configure.fingerprint; + answer_media.ice_lite = configure.ice_lite; switch (offer_media.role) { - case DtlsRole::actpass : case DtlsRole::active : { answer_media.role = DtlsRole::passive; break; } + case DtlsRole::actpass : case DtlsRole::passive : { answer_media.role = DtlsRole::active; break; diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index fa167fbc..895610ff 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -159,6 +159,7 @@ public: void parse(const string &str) override; string toString() const override; const char* getKey() const override { return "c";} + bool empty() const {return address.empty();} }; class SdpBandwidth : public SdpItem { @@ -261,6 +262,9 @@ public: void parse(const string &str) override;; string toString() const override; const char* getKey() const override { return "rtcp";} + bool empty() const { + return address.empty() || !port; + } }; class SdpAttrIceUfrag : public SdpItem {