From a0c1bc13ccaa794e2bbf58ad305188fc5d35b86f Mon Sep 17 00:00:00 2001 From: alexliyu7352 Date: Sun, 10 Apr 2022 19:09:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E6=AC=A1=E8=B0=83?= =?UTF-8?q?=E7=94=A8onShutdown=E7=9A=84bug=20(#1552)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当HlsPlayer拉取索引失败后会触发PlayerProxy的重试机制. 但是这里就有一个bug会导致重试次数不准确. 因为HlsPlayer播放失败会调用onShutdown. 然后回调PlayerProxy. 之后如果触发重试, 那么在HlsPlayer析构的时候又会在调用一次onShutdown. 这时候是安全的, 因为_on_shutdown已经被置空. 但是如果重试时又再次失败, 那么首先会调用 onPlayResult 这时候在PlayerProxy中会再次触发重试, 紧接着HlsPlayer析构, 又会调用一次onShutdown, 那么就又会触发一次重试. 修复方法有很多, 最简单的就是直接在 onShutdown中判断如果没有_demuxer就不需要父类的onShutdown方法来释放资源与重连了. 因为针对HlsPlayer来说, 如果重试拉取索引没有成功, 应该没有什么资源需要在onShutdown方法中释放了. 当然更完善的修复应该是在PlayerProxy中增加相关的判断逻辑, 给rePlay一个状态. 确保rePlay执行完成前, 不再执行一次rePlay. 具体哪种方式, 大佬您可以看着办. --- src/Http/HlsPlayer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index 352bd7f2..e401ad2b 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -367,8 +367,10 @@ void HlsPlayerImp::onPlayResult(const SockException &ex) { } void HlsPlayerImp::onShutdown(const SockException &ex) { - PlayerImp::onShutdown(ex); - _demuxer = nullptr; + if (_demuxer) { + PlayerImp::onShutdown(ex); + _demuxer = nullptr; + } } vector HlsPlayerImp::getTracks(bool ready) const {