优化hls录制

This commit is contained in:
xiongziliang 2019-12-17 09:18:11 +08:00
parent 1169f29ca6
commit a1e5724c70
4 changed files with 13 additions and 5 deletions

View File

@ -134,4 +134,8 @@ void HlsMaker::flushLastSegment(bool eof){
_last_file_name.clear(); _last_file_name.clear();
} }
bool HlsMaker::isLive() {
return _seg_number != 0;
}
}//namespace mediakit }//namespace mediakit

View File

@ -87,6 +87,11 @@ protected:
* @param eof * @param eof
*/ */
void flushLastSegment(bool eof = false); void flushLastSegment(bool eof = false);
/**
*
*/
bool isLive();
private: private:
/** /**
* m3u8文件 * m3u8文件

View File

@ -40,7 +40,6 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
_path_hls = m3u8_file; _path_hls = m3u8_file;
_params = params; _params = params;
_buf_size = bufSize; _buf_size = bufSize;
_is_vod = seg_number == 0;
_file_buf.reset(new char[bufSize],[](char *ptr){ _file_buf.reset(new char[bufSize],[](char *ptr){
delete[] ptr; delete[] ptr;
}); });
@ -49,7 +48,7 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
HlsMakerImp::~HlsMakerImp() { HlsMakerImp::~HlsMakerImp() {
//录制完了 //录制完了
flushLastSegment(true); flushLastSegment(true);
if(!_is_vod){ if(isLive()){
//hls直播才删除文件 //hls直播才删除文件
File::delete_file(_path_prefix.data()); File::delete_file(_path_prefix.data());
} }
@ -62,7 +61,9 @@ string HlsMakerImp::onOpenSegment(int index) {
auto strTime = getTimeStr("%H-%M-%S"); auto strTime = getTimeStr("%H-%M-%S");
segment_name = StrPrinter << strDate + "/" + strTime << "_" << index << ".ts"; segment_name = StrPrinter << strDate + "/" + strTime << "_" << index << ".ts";
segment_path = _path_prefix + "/" + segment_name; segment_path = _path_prefix + "/" + segment_name;
_segment_file_paths.emplace(index,segment_path); if(isLive()){
_segment_file_paths.emplace(index,segment_path);
}
} }
_file = makeFile(segment_path, true); _file = makeFile(segment_path, true);
if(!_file){ if(!_file){

View File

@ -58,8 +58,6 @@ private:
string _path_hls; string _path_hls;
string _params; string _params;
int _buf_size; int _buf_size;
//是否为点播
bool _is_vod;
}; };
}//namespace mediakit }//namespace mediakit