支持单独的datachannel通道 (#1894)

* 支持单独的datachannel 通道

* 当仅有datachannel时 ,忽略rtp和rtcp超时

* 单独开启datachannel时,通过dtls包维持心跳

Co-authored-by: xiongziliang <771730766@qq.com>
This commit is contained in:
Dw9 2022-08-20 10:28:19 +08:00 committed by GitHub
parent 39d2255771
commit b7ef766701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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;