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); }