From 918b1fce6c14be209e13c9459d3d9d555b6d3a4b Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Sun, 30 Oct 2022 23:50:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhls/ts=E6=8B=89=E6=B5=81?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98=EF=BC=9A#2057?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HlsPlayer.cpp | 11 ++++++----- src/Http/TsplayerImp.cpp | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index 60bda337..f22ca7c4 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -380,10 +380,14 @@ void HlsPlayerImp::onPlayResult(const SockException &ex) { void HlsPlayerImp::onShutdown(const SockException &ex) { while (_demuxer) { try { + //shared_from_this()可能抛异常 std::weak_ptr weak_self = static_pointer_cast(shared_from_this()); + if (_decoder) { + _decoder->flush(); + } + //等待所有frame flush输出后,再触发onShutdown事件 static_pointer_cast(_demuxer)->pushTask([weak_self, ex]() { - auto strong_self = weak_self.lock(); - if (strong_self) { + if (auto strong_self = weak_self.lock()) { strong_self->_demuxer = nullptr; strong_self->onShutdown(ex); } @@ -393,9 +397,6 @@ void HlsPlayerImp::onShutdown(const SockException &ex) { break; } } - if (_decoder) { - _decoder->flush(); - } PlayerImp::onShutdown(ex); } diff --git a/src/Http/TsplayerImp.cpp b/src/Http/TsplayerImp.cpp index d41fcb97..05db8a61 100644 --- a/src/Http/TsplayerImp.cpp +++ b/src/Http/TsplayerImp.cpp @@ -47,10 +47,14 @@ void TsPlayerImp::onPlayResult(const SockException &ex) { void TsPlayerImp::onShutdown(const SockException &ex) { while (_demuxer) { try { + //shared_from_this()可能抛异常 std::weak_ptr weak_self = static_pointer_cast(shared_from_this()); + if (_decoder) { + _decoder->flush(); + } + //等待所有frame flush输出后,再触发onShutdown事件 static_pointer_cast(_demuxer)->pushTask([weak_self, ex]() { - auto strong_self = weak_self.lock(); - if (strong_self) { + if (auto strong_self = weak_self.lock()) { strong_self->_demuxer = nullptr; strong_self->onShutdown(ex); } @@ -60,9 +64,6 @@ void TsPlayerImp::onShutdown(const SockException &ex) { break; } } - if (_decoder) { - _decoder->flush(); - } PlayerImp::onShutdown(ex); }