全面整理转协议相关配置文件

This commit is contained in:
xiongziliang
2022-11-12 23:54:35 +08:00
parent 946945ce7b
commit 9bb6a2f828
20 changed files with 373 additions and 298 deletions

View File

@@ -20,11 +20,13 @@ class HlsRecorder final : public MediaSourceEventInterceptor, public MpegMuxer,
public:
using Ptr = std::shared_ptr<HlsRecorder>;
HlsRecorder(const std::string &m3u8_file, const std::string &params) : MpegMuxer(false) {
HlsRecorder(const std::string &m3u8_file, const std::string &params, const ProtocolOption &option) : MpegMuxer(false) {
GET_CONFIG(uint32_t, hlsNum, Hls::kSegmentNum);
GET_CONFIG(bool, hlsKeep, Hls::kSegmentKeep);
GET_CONFIG(uint32_t, hlsBufSize, Hls::kFileBufSize);
GET_CONFIG(float, hlsDuration, Hls::kSegmentDuration);
_option = option;
_hls = std::make_shared<HlsMakerImp>(m3u8_file, params, hlsBufSize, hlsDuration, hlsNum, hlsKeep);
//清空上次的残余文件
_hls->clearCache();
@@ -44,10 +46,9 @@ public:
int readerCount() { return _hls->getMediaSource()->readerCount(); }
void onReaderChanged(MediaSource &sender, int size) override {
GET_CONFIG(bool, hls_demand, General::kHlsDemand);
// hls保留切片个数为0时代表为hls录制(不删除切片)那么不管有无观看者都一直生成hls
_enabled = hls_demand ? (_hls->isLive() ? size : true) : true;
if (!size && _hls->isLive() && hls_demand) {
_enabled = _option.hls_demand ? (_hls->isLive() ? size : true) : true;
if (!size && _hls->isLive() && _option.hls_demand) {
// hls直播时如果无人观看就删除视频缓存目的是为了防止视频跳跃
_clear_cache = true;
}
@@ -55,23 +56,21 @@ public:
}
bool inputFrame(const Frame::Ptr &frame) override {
GET_CONFIG(bool, hls_demand, General::kHlsDemand);
if (_clear_cache && hls_demand) {
if (_clear_cache && _option.hls_demand) {
_clear_cache = false;
//清空旧的m3u8索引文件于ts切片
_hls->clearCache();
_hls->getMediaSource()->setIndexFile("");
}
if (_enabled || !hls_demand) {
if (_enabled || !_option.hls_demand) {
return MpegMuxer::inputFrame(frame);
}
return false;
}
bool isEnabled() {
GET_CONFIG(bool, hls_demand, General::kHlsDemand);
//缓存尚未清空时还允许触发inputFrame函数以便及时清空缓存
return hls_demand ? (_clear_cache ? true : _enabled) : true;
return _option.hls_demand ? (_clear_cache ? true : _enabled) : true;
}
private:
@@ -86,6 +85,7 @@ private:
private:
bool _enabled = true;
bool _clear_cache = false;
ProtocolOption _option;
std::shared_ptr<HlsMakerImp> _hls;
};
}//namespace mediakit