From 7f203ce9b7d8249c60c2700b98a79d260708be3e Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 11 Oct 2019 19:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=9E=E5=A4=8Dhls?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MediaFile/HlsMaker.cpp | 14 +++++++++++--- src/MediaFile/HlsMaker.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/MediaFile/HlsMaker.cpp b/src/MediaFile/HlsMaker.cpp index 2c1e91ca..a438ad0b 100644 --- a/src/MediaFile/HlsMaker.cpp +++ b/src/MediaFile/HlsMaker.cpp @@ -86,9 +86,11 @@ void HlsMaker::inputData(void *data, uint32_t len, uint32_t timestamp) { addNewFile(timestamp); onWriteFile((char *) data, len); } else { - //调用resetTracks触发,这个时候生成直播hls被中断, - //我们记录为点播,等待下次拉流再恢复为直播。 - makeIndexFile(true); + _noData = true; + _stampInc = _ticker.elapsedTime(); + _seg_dur_list.push_back(std::make_tuple(_stampInc, _last_file_name)); + delOldFile(); + makeIndexFile(); } } @@ -109,6 +111,12 @@ void HlsMaker::delOldFile() { } void HlsMaker::addNewFile(uint32_t) { + //上次分片数据中断结束,重置时间避免中途的等待 + if (_noData) { + _ticker.resetTime(); + _last_file_name = onOpenFile(_file_index++); + _noData = false; + } _stampInc = _ticker.elapsedTime(); if (_file_index == 0 || _stampInc >= _seg_duration * 1000) { _ticker.resetTime(); diff --git a/src/MediaFile/HlsMaker.h b/src/MediaFile/HlsMaker.h index 3e288b73..46731759 100644 --- a/src/MediaFile/HlsMaker.h +++ b/src/MediaFile/HlsMaker.h @@ -92,6 +92,7 @@ protected: protected: uint32_t _seg_number = 0; private: + bool _noData = false; int _stampInc = 0; float _seg_duration = 0; uint64_t _file_index = 0;