From b7ef766701a5620fa17e306e8c46326c6a9ff072 Mon Sep 17 00:00:00 2001 From: Dw9 Date: Sat, 20 Aug 2022 10:28:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E7=8B=AC=E7=9A=84da?= =?UTF-8?q?tachannel=E9=80=9A=E9=81=93=20(#1894)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 支持单独的datachannel 通道 * 当仅有datachannel时 ,忽略rtp和rtcp超时 * 单独开启datachannel时,通过dtls包维持心跳 Co-authored-by: xiongziliang <771730766@qq.com> --- webrtc/Sdp.cpp | 12 ++++++++++++ webrtc/Sdp.h | 1 + webrtc/WebRtcTransport.cpp | 11 ++++++++++- webrtc/WebRtcTransport.h | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index a0562e7b..b8eb3304 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1311,6 +1311,10 @@ void RtcSession::checkValid() const{ bool have_active_media = false; for (auto &item : media) { item.checkValid(); + + if (TrackApplication == item.type) { + have_active_media = true; + } switch (item.direction) { case RtpDirection::sendrecv: case RtpDirection::sendonly: @@ -1348,6 +1352,10 @@ bool RtcSession::supportSimulcast() const { return false; } +bool RtcSession::isOnlyDatachannel() const { + return 1 == media.size() && TrackApplication == media[0].type; +} + string const SdpConst::kTWCCRtcpFb = "transport-cc"; string const SdpConst::kRembRtcpFb = "goog-remb"; @@ -1596,6 +1604,10 @@ RETRY: #ifdef ENABLE_SCTP answer_media.direction = matchDirection(offer_media.direction, configure.direction); answer_media.candidate = configure.candidate; + 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; #else answer_media.direction = RtpDirection::inactive; #endif diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index 41e1d5d3..240a6a07 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -678,6 +678,7 @@ public: const RtcMedia *getMedia(mediakit::TrackType type) const; bool supportRtcpFb(const std::string &name, mediakit::TrackType type = mediakit::TrackType::TrackVideo) const; bool supportSimulcast() const; + bool isOnlyDatachannel() const; private: RtcSessionSdp::Ptr toRtcSessionSdp() const; diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 1819c347..9f1dc284 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -377,7 +377,7 @@ void WebRtcTransportImp::onCreate() { return false; } if (strong_self->_alive_ticker.elapsedTime() > timeoutSec * 1000) { - strong_self->onShutdown(SockException(Err_timeout, "接受rtp和rtcp超时")); + strong_self->onShutdown(SockException(Err_timeout, "接受rtp/rtcp/datachannel超时")); } return true; }, @@ -386,6 +386,15 @@ void WebRtcTransportImp::onCreate() { _twcc_ctx.setOnSendTwccCB([this](uint32_t ssrc, string fci) { onSendTwcc(ssrc, fci); }); } +void WebRtcTransportImp::OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) { + WebRtcTransport::OnDtlsTransportApplicationDataReceived(dtlsTransport, data, len); +#ifdef ENABLE_SCTP + if (_answer_sdp->isOnlyDatachannel()) { + _alive_ticker.resetTime(); + } +#endif +} + WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) { InfoL << getIdentifier(); diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index c6570226..23f5880b 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -248,6 +248,7 @@ public: protected: WebRtcTransportImp(const EventPoller::Ptr &poller); + void OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) override; void onStartWebRTC() override; void onSendSockData(Buffer::Ptr buf, bool flush = true, RTC::TransportTuple *tuple = nullptr) override; void onCheckSdp(SdpType type, RtcSession &sdp) override;