From ba4296e18099283799b883843d3981634a341f3e Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 11 Mar 2023 10:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=AD=E8=BF=9E=E7=BB=AD?= =?UTF-8?q?=E6=8E=A8=E6=83=85=E5=86=B5=E4=B8=8B=E7=BA=BF=E7=A8=8B=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83=E7=9A=84bug:#2283?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果一个MultiMediaSourceMuxer对象上挂载了很多个RtpSender对象, 这些对象会绑定MultiMediaSourceMuxer的OwnerPoller(归属线程), 在断连续推发生时,对应的MultiMediaSourceMuxer对象OwnerPoller线程 将发生变更,导致与RtpSender对象的线程不一致。 --- src/Common/MediaSource.cpp | 2 ++ src/Common/MultiMediaSourceMuxer.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 5e378124..66d333c1 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -153,6 +153,8 @@ std::shared_ptr MediaSource::getOwnership() { //已经被所有 return nullptr; } + // 关闭所有rtp推流,确保线程安全 + stopSendRtp(""); weak_ptr weak_self = shared_from_this(); //确保返回的Ownership智能指针不为空,0x01无实际意义 return std::shared_ptr((void *) 0x01, [weak_self](void *ptr) { diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index f1a076c9..389da30f 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -246,6 +246,10 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const MediaSourceE if (!strong_self || ex) { return; } + if (!strong_self->getOwnerPoller(MediaSource::NullMediaSource())->isCurrentThread()) { + // poller线程发生变更了 + return; + } for (auto &track : strong_self->getTracks(false)) { rtp_sender->addTrack(track); }