RTC: 链接迁移后确保老链接及时销毁

This commit is contained in:
ziyue 2021-12-15 15:55:43 +08:00
parent d3a92c4ab8
commit 254bc6889e
2 changed files with 16 additions and 10 deletions

View File

@ -333,13 +333,13 @@ void WebRtcTransportImp::onDestory() {
} }
void WebRtcTransportImp::onSendSockData(Buffer::Ptr buf, bool flush, RTC::TransportTuple *tuple) { void WebRtcTransportImp::onSendSockData(Buffer::Ptr buf, bool flush, RTC::TransportTuple *tuple) {
if (!_session) { if (!_selected_session) {
WarnL << "send data failed:" << buf->size(); WarnL << "send data failed:" << buf->size();
return; return;
} }
//一次性发送一帧的rtp数据提高网络io性能 //一次性发送一帧的rtp数据提高网络io性能
_session->setSendFlushFlag(flush); _selected_session->setSendFlushFlag(flush);
_session->send(std::move(buf)); _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){ void WebRtcTransportImp::onShutdown(const SockException &ex){
WarnL << ex.what(); WarnL << ex.what();
unrefSelf(); unrefSelf();
if (_session) { for (auto &pr : _history_sessions) {
_session->shutdown(ex); auto session = pr.second.lock();
if (session) {
session->shutdown(ex);
}
} }
} }
void WebRtcTransportImp::setSession(Session::Ptr session) { void WebRtcTransportImp::setSession(Session::Ptr session) {
_session = std::move(session); _history_sessions.emplace(session.get(), session);
_selected_session = std::move(session);
unrefSelf(); unrefSelf();
} }
const Session::Ptr &WebRtcTransportImp::getSession() const { const Session::Ptr &WebRtcTransportImp::getSession() const {
return _session; return _selected_session;
} }
uint64_t WebRtcTransportImp::getBytesUsage() const{ uint64_t WebRtcTransportImp::getBytesUsage() const{

View File

@ -270,8 +270,10 @@ private:
Ticker _alive_ticker; Ticker _alive_ticker;
//pli rtcp计时器 //pli rtcp计时器
Ticker _pli_ticker; Ticker _pli_ticker;
//udp session //当前选中的udp链接
Session::Ptr _session; Session::Ptr _selected_session;
//链接迁移前后使用过的udp链接
unordered_map<Session *, weak_ptr<Session> > _history_sessions;
//twcc rtcp发送上下文对象 //twcc rtcp发送上下文对象
TwccContext _twcc_ctx; TwccContext _twcc_ctx;
//根据发送rtp的track类型获取相关信息 //根据发送rtp的track类型获取相关信息