修复HLS直播结束后,最后一个切片无法写入的问题
This commit is contained in:
parent
100af97d51
commit
5104252474
|
|
@ -68,10 +68,11 @@ void HlsMaker::inputData(void *data, uint32_t len, uint32_t timestamp, bool is_i
|
||||||
if (!_last_file_name.empty()) {
|
if (!_last_file_name.empty()) {
|
||||||
//存在切片才写入ts数据
|
//存在切片才写入ts数据
|
||||||
onWriteSegment((char *) data, len);
|
onWriteSegment((char *) data, len);
|
||||||
|
_last_timestamp = timestamp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//resetTracks时触发此逻辑
|
//resetTracks时触发此逻辑
|
||||||
flushLastSegment(timestamp, true);
|
flushLastSegment(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,24 +100,24 @@ void HlsMaker::addNewSegment(uint32_t stamp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//关闭并保存上一个切片,如果_seg_number==0,那么是点播。
|
//关闭并保存上一个切片,如果_seg_number==0,那么是点播。
|
||||||
flushLastSegment(stamp, _seg_number == 0);
|
flushLastSegment(_seg_number == 0);
|
||||||
//新增切片
|
//新增切片
|
||||||
_last_file_name = onOpenSegment(_file_index++);
|
_last_file_name = onOpenSegment(_file_index++);
|
||||||
//记录本次切片的起始时间戳
|
//记录本次切片的起始时间戳
|
||||||
_last_seg_timestamp = stamp;
|
_last_seg_timestamp = stamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HlsMaker::flushLastSegment(uint32_t timestamp, bool eof){
|
void HlsMaker::flushLastSegment(bool eof){
|
||||||
if (_last_file_name.empty()) {
|
if (_last_file_name.empty()) {
|
||||||
//不存在上个切片
|
//不存在上个切片
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//文件创建到最后一次数据写入的时间即为切片长度
|
//文件创建到最后一次数据写入的时间即为切片长度
|
||||||
auto seg_dur = timestamp - _last_seg_timestamp;
|
auto seg_dur = _last_timestamp - _last_seg_timestamp;
|
||||||
if (seg_dur <= 0) {
|
if (seg_dur <= 0) {
|
||||||
seg_dur = 100;
|
seg_dur = 100;
|
||||||
}
|
}
|
||||||
_seg_dur_list.push_back(std::make_tuple(seg_dur, _last_file_name));
|
_seg_dur_list.push_back(std::make_tuple(seg_dur, std::move(_last_file_name)));
|
||||||
delOldSegment();
|
delOldSegment();
|
||||||
makeIndexFile(eof);
|
makeIndexFile(eof);
|
||||||
_last_file_name.clear();
|
_last_file_name.clear();
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,9 @@ protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭上个ts切片并且写入m3u8索引
|
* 关闭上个ts切片并且写入m3u8索引
|
||||||
* @param timestamp 毫秒时间戳
|
* @param eof HLS直播是否已结束
|
||||||
* @param eof
|
|
||||||
*/
|
*/
|
||||||
void flushLastSegment(uint32_t timestamp, bool eof = false);
|
void flushLastSegment(bool eof);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,6 +105,7 @@ private:
|
||||||
private:
|
private:
|
||||||
float _seg_duration = 0;
|
float _seg_duration = 0;
|
||||||
uint32_t _seg_number = 0;
|
uint32_t _seg_number = 0;
|
||||||
|
uint32_t _last_timestamp = 0;
|
||||||
uint32_t _last_seg_timestamp = 0;
|
uint32_t _last_seg_timestamp = 0;
|
||||||
uint64_t _file_index = 0;
|
uint64_t _file_index = 0;
|
||||||
string _last_file_name;
|
string _last_file_name;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue