From 59dcd03b7061df397092d23d2e1cfa714379ba27 Mon Sep 17 00:00:00 2001 From: taojishou Date: Wed, 1 Jun 2022 13:05:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9hls=E6=8B=89=E6=B5=81?= =?UTF-8?q?=E5=90=8Eclosestream=E5=B4=A9=E6=BA=83=E7=9A=84bug=20(#1678)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改hls拉流后closestream崩溃的bug Co-authored-by: 夏楚 <771730766@qq.com> --- src/Http/HlsPlayer.cpp | 26 +++++++++++++++----------- src/Http/TsplayerImp.cpp | 26 +++++++++++++++----------- 2 files changed, 30 insertions(+), 22 deletions(-) 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 {