From 1b9550cfc4c418acdca32e7d49ff964b26626c4e Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 12 Sep 2020 20:42:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DHLS=E6=8C=89=E9=9C=80?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9B=B8=E5=85=B3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpFileManager.cpp | 6 +++++- src/Record/HlsMakerImp.cpp | 2 +- src/Record/HlsMediaSource.h | 9 +++++++-- src/Record/HlsRecorder.h | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Http/HttpFileManager.cpp b/src/Http/HttpFileManager.cpp index 69944624..28fca855 100644 --- a/src/Http/HttpFileManager.cpp +++ b/src/Http/HttpFileManager.cpp @@ -557,6 +557,10 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo } //hls文件不存在,我们等待其生成并延后回复 MediaSource::findAsync(mediaInfo, strongSession, [response_file, cookie, cb, strFile, parser](const MediaSource::Ptr &src) { + if(cookie){ + //尝试添加HlsMediaSource的观看人数 + (*cookie)[kCookieName].get()._hls_data->addByteUsage(0); + } if (src && File::is_file(strFile.data())) { //流和m3u8文件都存在,那么直接返回文件 response_file(cookie, cb, strFile, parser); @@ -570,7 +574,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo } //流存在,但是m3u8文件不存在,那么等待生成m3u8文件 - hls->waitForHls([response_file, cookie, cb, strFile, parser]() { + hls->waitForFile([response_file, cookie, cb, strFile, parser]() { response_file(cookie, cb, strFile, parser); }); }); diff --git a/src/Record/HlsMakerImp.cpp b/src/Record/HlsMakerImp.cpp index 7310464e..10521e36 100644 --- a/src/Record/HlsMakerImp.cpp +++ b/src/Record/HlsMakerImp.cpp @@ -89,7 +89,7 @@ void HlsMakerImp::onWriteHls(const char *data, int len) { fwrite(data, len, 1, hls.get()); hls.reset(); if (_media_src) { - _media_src->registHls(); + _media_src->registHls(true); } } else { WarnL << "create hls file failed," << _path_hls << " " << get_uv_errmsg(); diff --git a/src/Record/HlsMediaSource.h b/src/Record/HlsMediaSource.h index 432d104e..1cd99c9b 100644 --- a/src/Record/HlsMediaSource.h +++ b/src/Record/HlsMediaSource.h @@ -45,14 +45,19 @@ public: /** * 生成m3u8文件时触发 + * @param file_created 是否产生了hls文件 */ - void registHls(){ + void registHls(bool file_created){ if (!_is_regist) { _is_regist = true; onReaderChanged(0); regist(); } + if (!file_created) { + //没产生文件 + return; + } //m3u8文件生成,发送给播放器 decltype(_list_cb) copy; { @@ -64,7 +69,7 @@ public: }); } - void waitForHls(function cb){ + void waitForFile(function cb){ //等待生成m3u8文件 lock_guard lck(_mtx_cb); _list_cb.emplace_back(std::move(cb)); diff --git a/src/Record/HlsRecorder.h b/src/Record/HlsRecorder.h index 8b1c4495..c753c8b4 100644 --- a/src/Record/HlsRecorder.h +++ b/src/Record/HlsRecorder.h @@ -37,7 +37,7 @@ public: _listener = listener; _hls->getMediaSource()->setListener(shared_from_this()); //先注册媒体流,后续可以按需生成 - _hls->getMediaSource()->registHls(); + _hls->getMediaSource()->registHls(false); } int readerCount() {