修改hls拉流后closestream崩溃的bug (#1678)

* 修改hls拉流后closestream崩溃的bug

Co-authored-by: 夏楚 <771730766@qq.com>
This commit is contained in:
taojishou 2022-06-01 13:05:49 +08:00 committed by GitHub
parent b0beea7781
commit 59dcd03b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 22 deletions

View File

@ -378,18 +378,22 @@ void HlsPlayerImp::onPlayResult(const SockException &ex) {
}
void HlsPlayerImp::onShutdown(const SockException &ex) {
if (_demuxer) {
std::weak_ptr<HlsPlayerImp> weak_self = static_pointer_cast<HlsPlayerImp>(shared_from_this());
static_pointer_cast<HlsDemuxer>(_demuxer)->pushTask([weak_self, ex]() {
auto strong_self = weak_self.lock();
if (strong_self) {
strong_self->_demuxer = nullptr;
strong_self->onShutdown(ex);
}
});
} else {
PlayerImp<HlsPlayer, PlayerBase>::onShutdown(ex);
while (_demuxer) {
try {
std::weak_ptr<HlsPlayerImp> weak_self = static_pointer_cast<HlsPlayerImp>(shared_from_this());
static_pointer_cast<HlsDemuxer>(_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<HlsPlayer, PlayerBase>::onShutdown(ex);
}
vector<Track::Ptr> HlsPlayerImp::getTracks(bool ready) const {

View File

@ -45,18 +45,22 @@ void TsPlayerImp::onPlayResult(const SockException &ex) {
}
void TsPlayerImp::onShutdown(const SockException &ex) {
if (_demuxer) {
std::weak_ptr<TsPlayerImp> weak_self = static_pointer_cast<TsPlayerImp>(shared_from_this());
static_pointer_cast<HlsDemuxer>(_demuxer)->pushTask([weak_self, ex]() {
auto strong_self = weak_self.lock();
if (strong_self) {
strong_self->_demuxer = nullptr;
strong_self->onShutdown(ex);
}
});
} else {
PlayerImp<TsPlayer, PlayerBase>::onShutdown(ex);
while (_demuxer) {
try {
std::weak_ptr<TsPlayerImp> weak_self = static_pointer_cast<TsPlayerImp>(shared_from_this());
static_pointer_cast<HlsDemuxer>(_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<TsPlayer, PlayerBase>::onShutdown(ex);
}
vector<Track::Ptr> TsPlayerImp::getTracks(bool ready) const {