From 5b57b9d6aeef33d30a2c0b01bc697298f55e1f12 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 16 May 2021 22:13:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A1=AE=E4=BF=9Drtc=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E4=B8=8D=E5=BC=BA=E5=BC=95=E7=94=A8rtsp=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcTransport.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 0d8fb0d8..15ffe15e 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -344,7 +344,7 @@ void WebRtcTransportImp::onDestory() { //流量统计事件广播 GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); - if (_play_src) { + if (_reader) { WarnL << "RTC播放器(" << _media_info._vhost << "/" << _media_info._app << "/" @@ -457,6 +457,13 @@ void WebRtcTransportImp::onStartWebRTC() { strongSelf->onSendRtp(rtp, ++i == pkt->size()); }); }); + _reader->setDetachCB([weak_self](){ + auto strongSelf = weak_self.lock(); + if (!strongSelf) { + return; + } + strongSelf->onShutdown(SockException(Err_eof, "rtsp ring buffer detached")); + }); RtcSession rtsp_send_sdp; rtsp_send_sdp.loadFrom(_play_src->getSdp(), false); @@ -473,6 +480,8 @@ void WebRtcTransportImp::onStartWebRTC() { } } } + //使用完毕后,释放强引用,这样确保推流器断开后能及时注销媒体 + _play_src = nullptr; } void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp){ @@ -849,7 +858,7 @@ void WebRtcTransportImp::onBeforeEncryptRtp(const char *buf, size_t &len, void * } void WebRtcTransportImp::onShutdown(const SockException &ex){ - InfoL << ex.what(); + WarnL << ex.what(); _self = nullptr; }