From 254bc6889ea58a56d8b396667a9baa8ad83ea559 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 15 Dec 2021 15:55:43 +0800 Subject: [PATCH] =?UTF-8?q?RTC:=20=E9=93=BE=E6=8E=A5=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=90=8E=E7=A1=AE=E4=BF=9D=E8=80=81=E9=93=BE=E6=8E=A5=E5=8F=8A?= =?UTF-8?q?=E6=97=B6=E9=94=80=E6=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcTransport.cpp | 20 ++++++++++++-------- webrtc/WebRtcTransport.h | 6 ++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 317140b8..e78a4f5e 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -47,7 +47,7 @@ static atomic s_key{0}; WebRtcTransport::WebRtcTransport(const EventPoller::Ptr &poller) { _poller = poller; - _identifier = "zlm_"+to_string(++s_key); + _identifier = "zlm_" + to_string(++s_key); _packet_pool.setSize(64); } @@ -333,13 +333,13 @@ void WebRtcTransportImp::onDestory() { } void WebRtcTransportImp::onSendSockData(Buffer::Ptr buf, bool flush, RTC::TransportTuple *tuple) { - if (!_session) { + if (!_selected_session) { WarnL << "send data failed:" << buf->size(); return; } //一次性发送一帧的rtp数据,提高网络io性能 - _session->setSendFlushFlag(flush); - _session->send(std::move(buf)); + _selected_session->setSendFlushFlag(flush); + _selected_session->send(std::move(buf)); } /////////////////////////////////////////////////////////////////// @@ -860,18 +860,22 @@ void WebRtcTransportImp::onBeforeEncryptRtp(const char *buf, int &len, void *ctx void WebRtcTransportImp::onShutdown(const SockException &ex){ WarnL << ex.what(); unrefSelf(); - if (_session) { - _session->shutdown(ex); + for (auto &pr : _history_sessions) { + auto session = pr.second.lock(); + if (session) { + session->shutdown(ex); + } } } void WebRtcTransportImp::setSession(Session::Ptr session) { - _session = std::move(session); + _history_sessions.emplace(session.get(), session); + _selected_session = std::move(session); unrefSelf(); } const Session::Ptr &WebRtcTransportImp::getSession() const { - return _session; + return _selected_session; } uint64_t WebRtcTransportImp::getBytesUsage() const{ diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index d557b710..981a9ab6 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -270,8 +270,10 @@ private: Ticker _alive_ticker; //pli rtcp计时器 Ticker _pli_ticker; - //udp session - Session::Ptr _session; + //当前选中的udp链接 + Session::Ptr _selected_session; + //链接迁移前后使用过的udp链接 + unordered_map > _history_sessions; //twcc rtcp发送上下文对象 TwccContext _twcc_ctx; //根据发送rtp的track类型获取相关信息