Commit 39a528cc by Weiwei.Zhou

停止写之后将最后的片段也写进m3u8文件中

parent 5704d817
...@@ -42,6 +42,12 @@ HlsMaker::~HlsMaker() { ...@@ -42,6 +42,12 @@ HlsMaker::~HlsMaker() {
void HlsMaker::makeIndexFile(bool eof) { void HlsMaker::makeIndexFile(bool eof) {
char file_content[1024]; char file_content[1024];
int maxSegmentDuration = 0; int maxSegmentDuration = 0;
//停止写之后将最后的片段也写进m3u8文件中
if (eof && stampInc > 0) {
_seg_dur_list.push_back(std::make_tuple(stampInc, _last_file_name));
}
for (auto &tp : _seg_dur_list) { for (auto &tp : _seg_dur_list) {
int dur = std::get<0>(tp); int dur = std::get<0>(tp);
if (dur > maxSegmentDuration) { if (dur > maxSegmentDuration) {
...@@ -57,7 +63,7 @@ void HlsMaker::makeIndexFile(bool eof) { ...@@ -57,7 +63,7 @@ void HlsMaker::makeIndexFile(bool eof) {
"#EXT-X-TARGETDURATION:%u\n" "#EXT-X-TARGETDURATION:%u\n"
"#EXT-X-MEDIA-SEQUENCE:%llu\n", "#EXT-X-MEDIA-SEQUENCE:%llu\n",
(maxSegmentDuration + 999) / 1000, (maxSegmentDuration + 999) / 1000,
_file_index); _seg_number ? _file_index : 0);
m3u8.assign(file_content); m3u8.assign(file_content);
...@@ -96,7 +102,7 @@ void HlsMaker::delOldFile() { ...@@ -96,7 +102,7 @@ void HlsMaker::delOldFile() {
} }
void HlsMaker::addNewFile(uint32_t) { void HlsMaker::addNewFile(uint32_t) {
int stampInc = _ticker.elapsedTime(); stampInc = _ticker.elapsedTime();
if (stampInc >= _seg_duration * 1000) { if (stampInc >= _seg_duration * 1000) {
_ticker.resetTime(); _ticker.resetTime();
auto file_name = onOpenFile(_file_index); auto file_name = onOpenFile(_file_index);
......
...@@ -92,6 +92,7 @@ protected: ...@@ -92,6 +92,7 @@ protected:
protected: protected:
uint32_t _seg_number = 0; uint32_t _seg_number = 0;
private: private:
int stampInc = 0;
float _seg_duration = 0; float _seg_duration = 0;
uint64_t _file_index = 0; uint64_t _file_index = 0;
Ticker _ticker; Ticker _ticker;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论