From ff6e9f4fc7810ba5438aad969385a481a57b48f9 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 18 Oct 2022 19:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=81=E6=B3=A8=E9=94=80?= =?UTF-8?q?=E6=97=B6=EF=BC=8Chls=E6=97=A0=E6=B3=95=E6=92=AD=E5=AE=8C?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E5=88=87=E7=89=87=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98:=20#1955?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 2 +- src/Common/config.cpp | 2 +- src/Http/HttpCookieManager.h | 4 ++-- src/Http/HttpFileManager.cpp | 12 ++++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index a60fa4cc..aaff9999 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -110,7 +110,7 @@ segRetain=5 #是否广播 ts 切片完成通知 broadcastRecordTs=0 #直播hls文件删除延时,单位秒,issue: #913 -deleteDelaySec=0 +deleteDelaySec=10 #是否保留hls文件,此功能部分等效于segNum=0的情况 #不同的是这个保留不会在m3u8文件中体现 #0为不保留,不起作用 diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 4520f798..fa66c450 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -274,7 +274,7 @@ static onceToken token([]() { mINI::Instance()[kFileBufSize] = 64 * 1024; mINI::Instance()[kFilePath] = "./www"; mINI::Instance()[kBroadcastRecordTs] = false; - mINI::Instance()[kDeleteDelaySec] = 0; + mINI::Instance()[kDeleteDelaySec] = 10; }); } // namespace Hls diff --git a/src/Http/HttpCookieManager.h b/src/Http/HttpCookieManager.h index f1dcfa68..e55c2086 100644 --- a/src/Http/HttpCookieManager.h +++ b/src/Http/HttpCookieManager.h @@ -91,8 +91,8 @@ public: * 获取附加数据 */ template - const T& getAttach() const { - return *static_cast(_attach.get()); + T& getAttach() { + return *static_cast(_attach.get()); } private: diff --git a/src/Http/HttpFileManager.cpp b/src/Http/HttpFileManager.cpp index 51d9af2b..a7d90497 100644 --- a/src/Http/HttpFileManager.cpp +++ b/src/Http/HttpFileManager.cpp @@ -33,8 +33,9 @@ static int kHlsCookieSecond = 60; static const string kCookieName = "ZL_COOKIE"; static const string kHlsSuffix = "/hls.m3u8"; -class HttpCookieAttachment { -public: +struct HttpCookieAttachment { + //是否已经查找到过MediaSource + bool _find_src = false; //cookie生效作用域,本cookie只对该目录下的文件生效 string _path; //上次鉴权失败信息,为空则上次鉴权成功 @@ -425,6 +426,11 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo response_file(cookie, cb, file_path, parser, src->getIndexFile()); return; } + if (cookie->getAttach()._find_src) { + //查找过MediaSource,但是流已经注销了,不用再查找 + response_file(cookie, cb, file_path, parser); + return; + } //hls流可能未注册,MediaSource::findAsync可以触发not_found事件,然后再按需推拉流 MediaSource::findAsync(media_info, strongSession, [response_file, cookie, cb, file_path, parser](const MediaSource::Ptr &src) { @@ -439,6 +445,8 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo attach._hls_data->setMediaSource(hls); //添加HlsMediaSource的观看人数(HLS是按需生成的,这样可以触发HLS文件的生成) attach._hls_data->addByteUsage(0); + //标记找到MediaSource + attach._find_src = true; // m3u8文件可能不存在, 等待m3u8索引文件按需生成 hls->getIndexFile([response_file, file_path, cookie, cb, parser](const string &file) {