Commit e951efc6 by xiongziliang

优化hls直播性能

parent c3302eec
...@@ -354,7 +354,8 @@ static string pathCat(const string &a, const string &b){ ...@@ -354,7 +354,8 @@ static string pathCat(const string &a, const string &b){
*/ */
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &mediaInfo, const string &strFile, const HttpFileManager::invoker &cb) { static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &mediaInfo, const string &strFile, const HttpFileManager::invoker &cb) {
bool is_hls = end_of(strFile, kHlsSuffix); bool is_hls = end_of(strFile, kHlsSuffix);
if (!is_hls && !File::is_file(strFile.data())) { bool file_exist = File::is_file(strFile.data());
if (!is_hls && !file_exist) {
//文件不存在且不是hls,那么直接返回404 //文件不存在且不是hls,那么直接返回404
sendNotFound(cb); sendNotFound(cb);
return; return;
...@@ -368,7 +369,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo ...@@ -368,7 +369,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
weak_ptr<TcpSession> weakSession = sender.shared_from_this(); weak_ptr<TcpSession> weakSession = sender.shared_from_this();
//判断是否有权限访问该文件 //判断是否有权限访问该文件
canAccessPath(sender, parser, mediaInfo, false, [cb, strFile, parser, is_hls, mediaInfo, weakSession](const string &errMsg, const HttpServerCookie::Ptr &cookie) { canAccessPath(sender, parser, mediaInfo, false, [cb, strFile, parser, is_hls, mediaInfo, weakSession , file_exist](const string &errMsg, const HttpServerCookie::Ptr &cookie) {
if (!errMsg.empty()) { if (!errMsg.empty()) {
//文件鉴权失败 //文件鉴权失败
StrCaseMap headerOut; StrCaseMap headerOut;
...@@ -397,11 +398,11 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo ...@@ -397,11 +398,11 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
invoker.responseFile(parser.getValues(), httpHeader, strFile); invoker.responseFile(parser.getValues(), httpHeader, strFile);
}; };
if (!is_hls) { if (file_exist || !is_hls) {
//不是hls,直接回复 //不是hls或者文件存在,直接回复文件或404
response_file(cookie, cb, strFile, parser); response_file(cookie, cb, strFile, parser);
} else { } else {
//文件不存在,那么说明是hls,我们等待其生成并延后回复 //hls文件不存在,我们等待其生成并延后回复
auto strongSession = weakSession.lock(); auto strongSession = weakSession.lock();
if(!strongSession){ if(!strongSession){
//http客户端已经断开,不需要回复 //http客户端已经断开,不需要回复
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论