Commit a1e5724c by xiongziliang

优化hls录制

parent 1169f29c
......@@ -134,4 +134,8 @@ void HlsMaker::flushLastSegment(bool eof){
_last_file_name.clear();
}
bool HlsMaker::isLive() {
return _seg_number != 0;
}
}//namespace mediakit
\ No newline at end of file
......@@ -87,6 +87,11 @@ protected:
* @param eof
*/
void flushLastSegment(bool eof = false);
/**
* 是否为直播
*/
bool isLive();
private:
/**
* 生成m3u8文件
......
......@@ -40,7 +40,6 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
_path_hls = m3u8_file;
_params = params;
_buf_size = bufSize;
_is_vod = seg_number == 0;
_file_buf.reset(new char[bufSize],[](char *ptr){
delete[] ptr;
});
......@@ -49,7 +48,7 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
HlsMakerImp::~HlsMakerImp() {
//录制完了
flushLastSegment(true);
if(!_is_vod){
if(isLive()){
//hls直播才删除文件
File::delete_file(_path_prefix.data());
}
......@@ -62,8 +61,10 @@ string HlsMakerImp::onOpenSegment(int index) {
auto strTime = getTimeStr("%H-%M-%S");
segment_name = StrPrinter << strDate + "/" + strTime << "_" << index << ".ts";
segment_path = _path_prefix + "/" + segment_name;
if(isLive()){
_segment_file_paths.emplace(index,segment_path);
}
}
_file = makeFile(segment_path, true);
if(!_file){
WarnL << "create file falied," << segment_path << " " << get_uv_errmsg();
......
......@@ -58,8 +58,6 @@ private:
string _path_hls;
string _params;
int _buf_size;
//是否为点播
bool _is_vod;
};
}//namespace mediakit
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论