diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index 5a2a7a36..25429824 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -378,18 +378,22 @@ void HlsPlayerImp::onPlayResult(const SockException &ex) { } void HlsPlayerImp::onShutdown(const SockException &ex) { - if (_demuxer) { - std::weak_ptr weak_self = static_pointer_cast(shared_from_this()); - static_pointer_cast(_demuxer)->pushTask([weak_self, ex]() { - auto strong_self = weak_self.lock(); - if (strong_self) { - strong_self->_demuxer = nullptr; - strong_self->onShutdown(ex); - } - }); - } else { - PlayerImp::onShutdown(ex); + while (_demuxer) { + try { + std::weak_ptr weak_self = static_pointer_cast(shared_from_this()); + static_pointer_cast(_demuxer)->pushTask([weak_self, ex]() { + auto strong_self = weak_self.lock(); + if (strong_self) { + strong_self->_demuxer = nullptr; + strong_self->onShutdown(ex); + } + }); + return; + } catch (...) { + break; + } } + PlayerImp::onShutdown(ex); } vector HlsPlayerImp::getTracks(bool ready) const { diff --git a/src/Http/TsplayerImp.cpp b/src/Http/TsplayerImp.cpp index b906600c..042c1b43 100644 --- a/src/Http/TsplayerImp.cpp +++ b/src/Http/TsplayerImp.cpp @@ -45,18 +45,22 @@ void TsPlayerImp::onPlayResult(const SockException &ex) { } void TsPlayerImp::onShutdown(const SockException &ex) { - if (_demuxer) { - std::weak_ptr weak_self = static_pointer_cast(shared_from_this()); - static_pointer_cast(_demuxer)->pushTask([weak_self, ex]() { - auto strong_self = weak_self.lock(); - if (strong_self) { - strong_self->_demuxer = nullptr; - strong_self->onShutdown(ex); - } - }); - } else { - PlayerImp::onShutdown(ex); + while (_demuxer) { + try { + std::weak_ptr weak_self = static_pointer_cast(shared_from_this()); + static_pointer_cast(_demuxer)->pushTask([weak_self, ex]() { + auto strong_self = weak_self.lock(); + if (strong_self) { + strong_self->_demuxer = nullptr; + strong_self->onShutdown(ex); + } + }); + return; + } catch (...) { + break; + } } + PlayerImp::onShutdown(ex); } vector TsPlayerImp::getTracks(bool ready) const {