修复hls按需拉流一次播放可能失败的问题 (#3153)

This commit is contained in:
voidon 2024-01-06 16:15:55 +08:00
parent aeda47ec8c
commit b77515d217
3 changed files with 13 additions and 0 deletions

View File

@ -87,7 +87,11 @@ void HlsMediaSource::setIndexFile(std::string index_file)
strongSelf->onReaderChanged(size);
};
_ring = std::make_shared<RingType>(0, std::move(lam));
}
if (!_registered && !_clear_cache) {
//在清空缓存期间不进行注册否则可能播放中的ts文件会被清空
regist();
_registered = true;
}
//赋值m3u8索引文件内容

View File

@ -62,9 +62,16 @@ public:
_ring->getInfoList(cb, on_change);
}
/**
*
*/
void setClearCache(bool clear_cache) { _clear_cache = clear_cache; };
private:
RingType::Ptr _ring;
std::string _index_file;
bool _clear_cache = false;
bool _registered = false;
mutable std::mutex _mtx_index;
toolkit::List<std::function<void(const std::string &)>> _list_cb;
};

View File

@ -49,6 +49,7 @@ public:
_enabled = _option.hls_demand ? (_hls->isLive() ? size : true) : true;
if (!size && _hls->isLive() && _option.hls_demand) {
// hls直播时如果无人观看就删除视频缓存目的是为了防止视频跳跃
_hls->getMediaSource()->setClearCache(true);
_clear_cache = true;
}
MediaSourceEventInterceptor::onReaderChanged(sender, size);
@ -59,6 +60,7 @@ public:
_clear_cache = false;
//清空旧的m3u8索引文件于ts切片
_hls->clearCache();
_hls->getMediaSource()->setClearCache(false);
_hls->getMediaSource()->setIndexFile("");
}
if (_enabled || !_option.hls_demand) {