修复断连续推情况下线程迁移导致崩溃的bug:#2283

如果一个MultiMediaSourceMuxer对象上挂载了很多个RtpSender对象,
这些对象会绑定MultiMediaSourceMuxer的OwnerPoller(归属线程),
在断连续推发生时,对应的MultiMediaSourceMuxer对象OwnerPoller线程
将发生变更,导致与RtpSender对象的线程不一致。
This commit is contained in:
xia-chu 2023-03-11 10:34:28 +08:00
parent 9188ed1613
commit ba4296e180
2 changed files with 6 additions and 0 deletions

View File

@ -153,6 +153,8 @@ std::shared_ptr<void> MediaSource::getOwnership() {
//已经被所有 //已经被所有
return nullptr; return nullptr;
} }
// 关闭所有rtp推流确保线程安全
stopSendRtp("");
weak_ptr<MediaSource> weak_self = shared_from_this(); weak_ptr<MediaSource> weak_self = shared_from_this();
//确保返回的Ownership智能指针不为空0x01无实际意义 //确保返回的Ownership智能指针不为空0x01无实际意义
return std::shared_ptr<void>((void *) 0x01, [weak_self](void *ptr) { return std::shared_ptr<void>((void *) 0x01, [weak_self](void *ptr) {

View File

@ -246,6 +246,10 @@ void MultiMediaSourceMuxer::startSendRtp(MediaSource &sender, const MediaSourceE
if (!strong_self || ex) { if (!strong_self || ex) {
return; return;
} }
if (!strong_self->getOwnerPoller(MediaSource::NullMediaSource())->isCurrentThread()) {
// poller线程发生变更了
return;
}
for (auto &track : strong_self->getTracks(false)) { for (auto &track : strong_self->getTracks(false)) {
rtp_sender->addTrack(track); rtp_sender->addTrack(track);
} }