From f1ed0194379f2d21b3c442502b1ed71a879c2e86 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 11 Oct 2019 17:51:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6#106?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MediaSink.cpp | 3 ++- src/MediaFile/HlsMaker.cpp | 17 ++++------------- src/MediaFile/HlsMaker.h | 1 - src/MediaFile/MediaRecorder.h | 24 ++++++++++++------------ 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/Common/MediaSink.cpp b/src/Common/MediaSink.cpp index 960ea7e9..e8dae600 100644 --- a/src/Common/MediaSink.cpp +++ b/src/Common/MediaSink.cpp @@ -61,7 +61,8 @@ void MediaSink::addTrack(const Track::Ptr &track_in) { } void MediaSink::resetTracks() { - _anyTrackUnReady = true; + lock_guard lck(_mtx); + _anyTrackUnReady = false; _allTrackReady = false; _track_map.clear(); _trackReadyCallback.clear(); diff --git a/src/MediaFile/HlsMaker.cpp b/src/MediaFile/HlsMaker.cpp index 1a80fba0..2c1e91ca 100644 --- a/src/MediaFile/HlsMaker.cpp +++ b/src/MediaFile/HlsMaker.cpp @@ -85,13 +85,10 @@ void HlsMaker::inputData(void *data, uint32_t len, uint32_t timestamp) { if (data && len) { addNewFile(timestamp); onWriteFile((char *) data, len); - } - else { - _noData = true; - _stampInc = _ticker.elapsedTime(); - _seg_dur_list.push_back(std::make_tuple(_stampInc, _last_file_name)); - delOldFile(); - makeIndexFile(); + } else { + //调用resetTracks触发,这个时候生成直播hls被中断, + //我们记录为点播,等待下次拉流再恢复为直播。 + makeIndexFile(true); } } @@ -112,12 +109,6 @@ 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 46731759..3e288b73 100644 --- a/src/MediaFile/HlsMaker.h +++ b/src/MediaFile/HlsMaker.h @@ -92,7 +92,6 @@ protected: protected: uint32_t _seg_number = 0; private: - bool _noData = false; int _stampInc = 0; float _seg_duration = 0; uint64_t _file_index = 0; diff --git a/src/MediaFile/MediaRecorder.h b/src/MediaFile/MediaRecorder.h index 9619e338..c36f8613 100644 --- a/src/MediaFile/MediaRecorder.h +++ b/src/MediaFile/MediaRecorder.h @@ -48,22 +48,22 @@ public: virtual ~MediaRecorder(); /** - * 输入frame - * @param frame - */ + * 输入frame + * @param frame + */ void inputFrame(const Frame::Ptr &frame) override; /** - * 添加track,内部会调用Track的clone方法 - * 只会克隆sps pps这些信息 ,而不会克隆Delegate相关关系 - * @param track - */ - void addTrack(const Track::Ptr & track) override; + * 添加track,内部会调用Track的clone方法 + * 只会克隆sps pps这些信息 ,而不会克隆Delegate相关关系 + * @param track + */ + void addTrack(const Track::Ptr &track) override; - /** - * 重置track - */ - void resetTracks() override; + /** + * 重置track + */ + void resetTracks() override; private: #if defined(ENABLE_HLS) std::shared_ptr _hlsRecorder;