From 3b3a83b524cefe02a9a5fd6e3ca1caa62a55f75f Mon Sep 17 00:00:00 2001 From: Dw9 Date: Sat, 7 Jan 2023 21:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=20=E4=BF=AE=E5=A4=8DMediaSource=E5=9C=A8startS?= =?UTF-8?q?endRtp=E5=90=8E=E6=97=A0=E6=B3=95=E6=B3=A8=E9=94=80=E7=9A=84bug?= =?UTF-8?q?=20(#2187)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MultiMediaSourceMuxer.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index bcac76b5..f1a076c9 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -238,9 +238,9 @@ bool MultiMediaSourceMuxer::isRecording(MediaSource &sender, Recorder::type type void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const MediaSourceEvent::SendRtpArgs &args, const std::function cb) { #if defined(ENABLE_RTPPROXY) auto rtp_sender = std::make_shared(getOwnerPoller(sender)); - auto sender_ptr = sender.shared_from_this(); + weak_ptr weak_sender = sender.shared_from_this(); weak_ptr weak_self = shared_from_this(); - rtp_sender->startSend(args, [args, weak_self, rtp_sender, cb, sender_ptr](uint16_t local_port, const SockException &ex) mutable { + rtp_sender->startSend(args, [args, weak_self, rtp_sender, cb, weak_sender](uint16_t local_port, const SockException &ex) mutable { cb(local_port, ex); auto strong_self = weak_self.lock(); if (!strong_self || ex) { @@ -252,17 +252,23 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const MediaSourceE rtp_sender->addTrackCompleted(); auto ssrc = args.ssrc; - rtp_sender->setOnClose([weak_self, ssrc, sender_ptr](const toolkit::SockException &ex) { + rtp_sender->setOnClose([weak_self, ssrc, weak_sender](const toolkit::SockException &ex) { if (auto strong_self = weak_self.lock()) { WarnL << "stream:" << strong_self->shortUrl() << " stop send rtp:" << ssrc << ", reason:" << ex.what(); strong_self->_rtp_sender.erase(ssrc); //触发观看人数统计 - strong_self->onReaderChanged(*sender_ptr, strong_self->totalReaderCount()); + auto strong_sender = weak_sender.lock(); + if (strong_sender) { + strong_self->onReaderChanged(*strong_sender, strong_self->totalReaderCount()); + } NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastSendRtpStopped, *strong_self, ssrc, ex); } }); strong_self->_rtp_sender[args.ssrc] = std::move(rtp_sender); - strong_self->onReaderChanged(*sender_ptr, strong_self->totalReaderCount()); + auto strong_sender = weak_sender.lock(); + if (strong_sender) { + strong_self->onReaderChanged(*strong_sender, strong_self->totalReaderCount()); + } }); #else cb(0, SockException(Err_other, "该功能未启用,编译时请打开ENABLE_RTPPROXY宏"));