Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
22425776
Commit
22425776
authored
Aug 27, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化解析复杂数据结构配置项时的性能
parent
e044d5ce
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
54 行增加
和
30 行删除
+54
-30
src/Common/config.h
+32
-14
src/Http/HttpFileManager.cpp
+16
-12
src/Rtsp/RtpMultiCaster.cpp
+6
-4
没有找到文件。
src/Common/config.h
查看文件 @
22425776
...
...
@@ -107,27 +107,45 @@ extern const string kBroadcastReloadConfig;
#define ReloadConfigTag ((void *)(0xFF))
#define RELOAD_KEY(arg,key) \
do{ \
decltype(arg) arg##tmp = mINI::Instance()[key]; \
if(arg != arg##tmp ) { \
arg = arg##tmp; \
InfoL << "reload config:" << key << "=" << arg; \
do { \
decltype(arg) arg##_tmp = mINI::Instance()[key]; \
if (arg == arg##_tmp) { \
return; \
} \
}while(0);
arg = arg##_tmp; \
InfoL << "reload config:" << key << "=" << arg; \
} while(0)
//监听某个配置发送变更
#define LISTEN_RELOAD_KEY(arg,key) \
do{ \
static onceToken s_token([](){ \
NoticeCenter::Instance().addListener(ReloadConfigTag,Broadcast::kBroadcastReloadConfig,[](BroadcastReloadConfigArgs){ \
RELOAD_KEY(arg,key); \
#define LISTEN_RELOAD_KEY(arg, key, ...) \
do { \
static onceToken s_token_listen([](){ \
NoticeCenter::Instance().addListener(ReloadConfigTag, \
Broadcast::kBroadcastReloadConfig,[](BroadcastReloadConfigArgs) { \
__VA_ARGS__; \
}); \
}); \
}
while(0);
}
while(0)
#define GET_CONFIG(type,
arg,key)
\
#define GET_CONFIG(type,
arg, key)
\
static type arg = mINI::Instance()[key]; \
LISTEN_RELOAD_KEY(arg,key);
LISTEN_RELOAD_KEY(arg, key, { \
RELOAD_KEY(arg, key); \
});
#define GET_CONFIG_FUNC(type, arg, key, ...) \
static type arg; \
do { \
static onceToken s_token_set([](){ \
static auto lam = __VA_ARGS__ ; \
static auto arg##_str = mINI::Instance()[key]; \
arg = lam(arg##_str); \
LISTEN_RELOAD_KEY(arg, key, { \
RELOAD_KEY(arg##_str, key); \
arg = lam(arg##_str); \
}); \
}); \
} while(0)
}
//namespace Broadcast
...
...
src/Http/HttpFileManager.cpp
查看文件 @
22425776
...
...
@@ -135,9 +135,10 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
}
//如果是root目录,添加虚拟目录
if
(
httpPath
==
"/"
)
{
GET_CONFIG
(
string
,
virtualPath
,
Http
::
kVirtualPath
);
StrCaseMap
args
=
Parser
::
parseArgs
(
virtualPath
,
";"
,
","
);
for
(
auto
&
pr
:
args
)
{
GET_CONFIG_FUNC
(
StrCaseMap
,
virtualPathMap
,
Http
::
kVirtualPath
,
[](
const
string
&
str
)
{
return
Parser
::
parseArgs
(
str
,
";"
,
","
);
});
for
(
auto
&
pr
:
virtualPathMap
)
{
file_map
.
emplace
(
pr
.
first
,
std
::
make_pair
(
string
(
"虚拟目录:"
)
+
pr
.
first
,
File
::
absolutePath
(
""
,
pr
.
second
)));
}
}
...
...
@@ -472,18 +473,21 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
static
string
getFilePath
(
const
Parser
&
parser
,
const
MediaInfo
&
mediaInfo
,
TcpSession
&
sender
){
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
GET_CONFIG
(
string
,
virtualPath
,
Http
::
kVirtualPath
);
StrCaseMap
args
=
Parser
::
parseArgs
(
virtualPath
,
";"
,
","
);
auto
path
=
args
[
mediaInfo
.
_app
];
string
url
;
if
(
path
.
empty
())
{
//访问的是根路径
GET_CONFIG
(
string
,
rootPath
,
Http
::
kRootPath
);
GET_CONFIG_FUNC
(
StrCaseMap
,
virtualPathMap
,
Http
::
kVirtualPath
,
[](
const
string
&
str
)
{
return
Parser
::
parseArgs
(
str
,
";"
,
","
);
});
string
url
,
path
;
auto
it
=
virtualPathMap
.
find
(
mediaInfo
.
_app
);
if
(
it
!=
virtualPathMap
.
end
())
{
//访问的是virtualPath
path
=
it
->
second
;
url
=
parser
.
Url
().
substr
(
1
+
mediaInfo
.
_app
.
size
());
}
else
{
//访问的是rootPath
path
=
rootPath
;
url
=
parser
.
Url
();
}
else
{
//访问的是虚拟路径
url
=
parser
.
Url
().
substr
(
1
+
mediaInfo
.
_app
.
size
());
}
auto
ret
=
File
::
absolutePath
(
enableVhost
?
mediaInfo
.
_vhost
+
url
:
url
,
path
);
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastHttpBeforeAccess
,
parser
,
ret
,
static_cast
<
SockInfo
&>
(
sender
));
...
...
src/Rtsp/RtpMultiCaster.cpp
查看文件 @
22425776
...
...
@@ -45,10 +45,12 @@ static uint32_t addressToInt(const string &ip){
std
::
shared_ptr
<
uint32_t
>
MultiCastAddressMaker
::
obtain
(
uint32_t
max_try
)
{
lock_guard
<
recursive_mutex
>
lck
(
_mtx
);
GET_CONFIG
(
string
,
addrMinStr
,
MultiCast
::
kAddrMin
);
GET_CONFIG
(
string
,
addrMaxStr
,
MultiCast
::
kAddrMax
);
uint32_t
addrMin
=
addressToInt
(
addrMinStr
);
uint32_t
addrMax
=
addressToInt
(
addrMaxStr
);
GET_CONFIG_FUNC
(
uint32_t
,
addrMin
,
MultiCast
::
kAddrMin
,
[](
const
string
&
str
)
{
return
addressToInt
(
str
);
});
GET_CONFIG_FUNC
(
uint32_t
,
addrMax
,
MultiCast
::
kAddrMax
,
[](
const
string
&
str
)
{
return
addressToInt
(
str
);
});
if
(
_addr
>
addrMax
||
_addr
==
0
)
{
_addr
=
addrMin
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论