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
781708f0
Commit
781708f0
authored
Dec 27, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除兼容代码
parent
322ebdf4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
63 行删除
+48
-63
server/WebApi.cpp
+48
-63
没有找到文件。
server/WebApi.cpp
查看文件 @
781708f0
...
@@ -145,9 +145,6 @@ static void api_regist(const string &api_path, FUNC &&func) {
...
@@ -145,9 +145,6 @@ static void api_regist(const string &api_path, FUNC &&func) {
s_map_api
.
emplace
(
api_path
,
toApi
(
std
::
move
(
func
)));
s_map_api
.
emplace
(
api_path
,
toApi
(
std
::
move
(
func
)));
}
}
#define api_regist1 api_regist
#define api_regist2 api_regist
//获取HTTP请求中url参数、content参数
//获取HTTP请求中url参数、content参数
static
ApiArgsType
getAllArgs
(
const
Parser
&
parser
)
{
static
ApiArgsType
getAllArgs
(
const
Parser
&
parser
)
{
...
@@ -288,7 +285,7 @@ void installWebApi() {
...
@@ -288,7 +285,7 @@ void installWebApi() {
//获取线程负载
//获取线程负载
//测试url http://127.0.0.1/index/api/getThreadsLoad
//测试url http://127.0.0.1/index/api/getThreadsLoad
api_regist
2
(
"/index/api/getThreadsLoad"
,[](
API_ARGS2
){
api_regist
(
"/index/api/getThreadsLoad"
,[](
API_ARGS2
){
EventPollerPool
::
Instance
().
getExecutorDelay
([
invoker
,
headerOut
](
const
vector
<
int
>
&
vecDelay
)
{
EventPollerPool
::
Instance
().
getExecutorDelay
([
invoker
,
headerOut
](
const
vector
<
int
>
&
vecDelay
)
{
Value
val
;
Value
val
;
auto
vec
=
EventPollerPool
::
Instance
().
getExecutorLoad
();
auto
vec
=
EventPollerPool
::
Instance
().
getExecutorLoad
();
...
@@ -306,7 +303,7 @@ void installWebApi() {
...
@@ -306,7 +303,7 @@ void installWebApi() {
//获取后台工作线程负载
//获取后台工作线程负载
//测试url http://127.0.0.1/index/api/getWorkThreadsLoad
//测试url http://127.0.0.1/index/api/getWorkThreadsLoad
api_regist
2
(
"/index/api/getWorkThreadsLoad"
,
[](
API_ARGS2
){
api_regist
(
"/index/api/getWorkThreadsLoad"
,
[](
API_ARGS2
){
WorkThreadPool
::
Instance
().
getExecutorDelay
([
invoker
,
headerOut
](
const
vector
<
int
>
&
vecDelay
)
{
WorkThreadPool
::
Instance
().
getExecutorDelay
([
invoker
,
headerOut
](
const
vector
<
int
>
&
vecDelay
)
{
Value
val
;
Value
val
;
auto
vec
=
WorkThreadPool
::
Instance
().
getExecutorLoad
();
auto
vec
=
WorkThreadPool
::
Instance
().
getExecutorLoad
();
...
@@ -324,7 +321,7 @@ void installWebApi() {
...
@@ -324,7 +321,7 @@ void installWebApi() {
//获取服务器配置
//获取服务器配置
//测试url http://127.0.0.1/index/api/getServerConfig
//测试url http://127.0.0.1/index/api/getServerConfig
api_regist
1
(
"/index/api/getServerConfig"
,[](
API_ARGS1
){
api_regist
(
"/index/api/getServerConfig"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
Value
obj
;
Value
obj
;
for
(
auto
&
pr
:
mINI
::
Instance
())
{
for
(
auto
&
pr
:
mINI
::
Instance
())
{
...
@@ -336,7 +333,7 @@ void installWebApi() {
...
@@ -336,7 +333,7 @@ void installWebApi() {
//设置服务器配置
//设置服务器配置
//测试url(比如关闭http api调试) http://127.0.0.1/index/api/setServerConfig?api.apiDebug=0
//测试url(比如关闭http api调试) http://127.0.0.1/index/api/setServerConfig?api.apiDebug=0
//你也可以通过http post方式传参,可以通过application/x-www-form-urlencoded或application/json方式传参
//你也可以通过http post方式传参,可以通过application/x-www-form-urlencoded或application/json方式传参
api_regist
1
(
"/index/api/setServerConfig"
,[](
API_ARGS1
){
api_regist
(
"/index/api/setServerConfig"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
auto
&
ini
=
mINI
::
Instance
();
auto
&
ini
=
mINI
::
Instance
();
int
changed
=
API
::
Success
;
int
changed
=
API
::
Success
;
...
@@ -369,20 +366,20 @@ void installWebApi() {
...
@@ -369,20 +366,20 @@ void installWebApi() {
//获取服务器api列表
//获取服务器api列表
//测试url http://127.0.0.1/index/api/getApiList
//测试url http://127.0.0.1/index/api/getApiList
api_regist
1
(
"/index/api/getApiList"
,[](
API_ARGS1
){
api_regist
(
"/index/api/getApiList"
,[](
API_ARGS1
){
s_get_api_list
(
API_ARGS_VALUE1
);
s_get_api_list
(
API_ARGS_VALUE1
);
});
});
//获取服务器api列表
//获取服务器api列表
//测试url http://127.0.0.1/index/
//测试url http://127.0.0.1/index/
api_regist
1
(
"/index/"
,[](
API_ARGS1
){
api_regist
(
"/index/"
,[](
API_ARGS1
){
s_get_api_list
(
API_ARGS_VALUE1
);
s_get_api_list
(
API_ARGS_VALUE1
);
});
});
#if !defined(_WIN32)
#if !defined(_WIN32)
//重启服务器,只有Daemon方式才能重启,否则是直接关闭!
//重启服务器,只有Daemon方式才能重启,否则是直接关闭!
//测试url http://127.0.0.1/index/api/restartServer
//测试url http://127.0.0.1/index/api/restartServer
api_regist
1
(
"/index/api/restartServer"
,[](
API_ARGS1
){
api_regist
(
"/index/api/restartServer"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
EventPollerPool
::
Instance
().
getPoller
()
->
doDelayTask
(
1000
,[](){
EventPollerPool
::
Instance
().
getPoller
()
->
doDelayTask
(
1000
,[](){
//尝试正常退出
//尝试正常退出
...
@@ -460,7 +457,7 @@ void installWebApi() {
...
@@ -460,7 +457,7 @@ void installWebApi() {
//测试url0(获取所有流) http://127.0.0.1/index/api/getMediaList
//测试url0(获取所有流) http://127.0.0.1/index/api/getMediaList
//测试url1(获取虚拟主机为"__defaultVost__"的流) http://127.0.0.1/index/api/getMediaList?vhost=__defaultVost__
//测试url1(获取虚拟主机为"__defaultVost__"的流) http://127.0.0.1/index/api/getMediaList?vhost=__defaultVost__
//测试url2(获取rtsp类型的流) http://127.0.0.1/index/api/getMediaList?schema=rtsp
//测试url2(获取rtsp类型的流) http://127.0.0.1/index/api/getMediaList?schema=rtsp
api_regist
1
(
"/index/api/getMediaList"
,[](
API_ARGS1
){
api_regist
(
"/index/api/getMediaList"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
//获取所有MediaSource列表
//获取所有MediaSource列表
MediaSource
::
for_each_media
([
&
](
const
MediaSource
::
Ptr
&
media
){
MediaSource
::
for_each_media
([
&
](
const
MediaSource
::
Ptr
&
media
){
...
@@ -478,14 +475,14 @@ void installWebApi() {
...
@@ -478,14 +475,14 @@ void installWebApi() {
});
});
//测试url http://127.0.0.1/index/api/isMediaOnline?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs
//测试url http://127.0.0.1/index/api/isMediaOnline?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs
api_regist
1
(
"/index/api/isMediaOnline"
,[](
API_ARGS1
){
api_regist
(
"/index/api/isMediaOnline"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
);
val
[
"online"
]
=
(
bool
)
(
MediaSource
::
find
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]));
val
[
"online"
]
=
(
bool
)
(
MediaSource
::
find
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]));
});
});
//测试url http://127.0.0.1/index/api/getMediaInfo?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs
//测试url http://127.0.0.1/index/api/getMediaInfo?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs
api_regist
1
(
"/index/api/getMediaInfo"
,[](
API_ARGS1
){
api_regist
(
"/index/api/getMediaInfo"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
);
auto
src
=
MediaSource
::
find
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]);
auto
src
=
MediaSource
::
find
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]);
...
@@ -500,7 +497,7 @@ void installWebApi() {
...
@@ -500,7 +497,7 @@ void installWebApi() {
//主动关断流,包括关断拉流、推流
//主动关断流,包括关断拉流、推流
//测试url http://127.0.0.1/index/api/close_stream?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs&force=1
//测试url http://127.0.0.1/index/api/close_stream?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs&force=1
api_regist
1
(
"/index/api/close_stream"
,[](
API_ARGS1
){
api_regist
(
"/index/api/close_stream"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
);
//踢掉推流器
//踢掉推流器
...
@@ -522,7 +519,7 @@ void installWebApi() {
...
@@ -522,7 +519,7 @@ void installWebApi() {
//批量主动关断流,包括关断拉流、推流
//批量主动关断流,包括关断拉流、推流
//测试url http://127.0.0.1/index/api/close_streams?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs&force=1
//测试url http://127.0.0.1/index/api/close_streams?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs&force=1
api_regist
1
(
"/index/api/close_streams"
,[](
API_ARGS1
){
api_regist
(
"/index/api/close_streams"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
//筛选命中个数
//筛选命中个数
int
count_hit
=
0
;
int
count_hit
=
0
;
...
@@ -558,7 +555,7 @@ void installWebApi() {
...
@@ -558,7 +555,7 @@ void installWebApi() {
//获取所有TcpSession列表信息
//获取所有TcpSession列表信息
//可以根据本地端口和远端ip来筛选
//可以根据本地端口和远端ip来筛选
//测试url(筛选某端口下的tcp会话) http://127.0.0.1/index/api/getAllSession?local_port=1935
//测试url(筛选某端口下的tcp会话) http://127.0.0.1/index/api/getAllSession?local_port=1935
api_regist
1
(
"/index/api/getAllSession"
,[](
API_ARGS1
){
api_regist
(
"/index/api/getAllSession"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
Value
jsession
;
Value
jsession
;
uint16_t
local_port
=
allArgs
[
"local_port"
].
as
<
uint16_t
>
();
uint16_t
local_port
=
allArgs
[
"local_port"
].
as
<
uint16_t
>
();
...
@@ -583,7 +580,7 @@ void installWebApi() {
...
@@ -583,7 +580,7 @@ void installWebApi() {
//断开tcp连接,比如说可以断开rtsp、rtmp播放器等
//断开tcp连接,比如说可以断开rtsp、rtmp播放器等
//测试url http://127.0.0.1/index/api/kick_session?id=123456
//测试url http://127.0.0.1/index/api/kick_session?id=123456
api_regist
1
(
"/index/api/kick_session"
,[](
API_ARGS1
){
api_regist
(
"/index/api/kick_session"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"id"
);
CHECK_ARGS
(
"id"
);
//踢掉tcp会话
//踢掉tcp会话
...
@@ -597,7 +594,7 @@ void installWebApi() {
...
@@ -597,7 +594,7 @@ void installWebApi() {
//批量断开tcp连接,比如说可以断开rtsp、rtmp播放器等
//批量断开tcp连接,比如说可以断开rtsp、rtmp播放器等
//测试url http://127.0.0.1/index/api/kick_sessions?local_port=1935
//测试url http://127.0.0.1/index/api/kick_sessions?local_port=1935
api_regist
1
(
"/index/api/kick_sessions"
,[](
API_ARGS1
){
api_regist
(
"/index/api/kick_sessions"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
uint16_t
local_port
=
allArgs
[
"local_port"
].
as
<
uint16_t
>
();
uint16_t
local_port
=
allArgs
[
"local_port"
].
as
<
uint16_t
>
();
string
&
peer_ip
=
allArgs
[
"peer_ip"
];
string
&
peer_ip
=
allArgs
[
"peer_ip"
];
...
@@ -661,7 +658,7 @@ void installWebApi() {
...
@@ -661,7 +658,7 @@ void installWebApi() {
//动态添加rtsp/rtmp拉流代理
//动态添加rtsp/rtmp拉流代理
//测试url http://127.0.0.1/index/api/addStreamProxy?vhost=__defaultVhost__&app=proxy&enable_rtsp=1&enable_rtmp=1&stream=0&url=rtmp://127.0.0.1/live/obs
//测试url http://127.0.0.1/index/api/addStreamProxy?vhost=__defaultVhost__&app=proxy&enable_rtsp=1&enable_rtmp=1&stream=0&url=rtmp://127.0.0.1/live/obs
api_regist
2
(
"/index/api/addStreamProxy"
,[](
API_ARGS2
){
api_regist
(
"/index/api/addStreamProxy"
,[](
API_ARGS2
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
,
"url"
);
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
,
"url"
);
addStreamProxy
(
allArgs
[
"vhost"
],
addStreamProxy
(
allArgs
[
"vhost"
],
...
@@ -684,7 +681,7 @@ void installWebApi() {
...
@@ -684,7 +681,7 @@ void installWebApi() {
//关闭拉流代理
//关闭拉流代理
//测试url http://127.0.0.1/index/api/delStreamProxy?key=__defaultVhost__/proxy/0
//测试url http://127.0.0.1/index/api/delStreamProxy?key=__defaultVhost__/proxy/0
api_regist
1
(
"/index/api/delStreamProxy"
,[](
API_ARGS1
){
api_regist
(
"/index/api/delStreamProxy"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"key"
);
CHECK_ARGS
(
"key"
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
...
@@ -724,7 +721,7 @@ void installWebApi() {
...
@@ -724,7 +721,7 @@ void installWebApi() {
//动态添加rtsp/rtmp拉流代理
//动态添加rtsp/rtmp拉流代理
//测试url http://127.0.0.1/index/api/addFFmpegSource?src_url=http://live.hkstv.hk.lxdns.com/live/hks2/playlist.m3u8&dst_url=rtmp://127.0.0.1/live/hks2&timeout_ms=10000
//测试url http://127.0.0.1/index/api/addFFmpegSource?src_url=http://live.hkstv.hk.lxdns.com/live/hks2/playlist.m3u8&dst_url=rtmp://127.0.0.1/live/hks2&timeout_ms=10000
api_regist
2
(
"/index/api/addFFmpegSource"
,[](
API_ARGS2
){
api_regist
(
"/index/api/addFFmpegSource"
,[](
API_ARGS2
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"src_url"
,
"dst_url"
,
"timeout_ms"
);
CHECK_ARGS
(
"src_url"
,
"dst_url"
,
"timeout_ms"
);
auto
src_url
=
allArgs
[
"src_url"
];
auto
src_url
=
allArgs
[
"src_url"
];
...
@@ -745,34 +742,24 @@ void installWebApi() {
...
@@ -745,34 +742,24 @@ void installWebApi() {
});
});
});
});
//关闭拉流代理
static
auto
api_delFFmpegSource
=
[](
API_ARGS1
){
//测试url http://127.0.0.1/index/api/delFFmepgSource?key=key
api_regist
(
"/index/api/delFFmpegSource"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"key"
);
CHECK_ARGS
(
"key"
);
lock_guard
<
decltype
(
s_ffmpegMapMtx
)
>
lck
(
s_ffmpegMapMtx
);
lock_guard
<
decltype
(
s_ffmpegMapMtx
)
>
lck
(
s_ffmpegMapMtx
);
val
[
"data"
][
"flag"
]
=
s_ffmpegMap
.
erase
(
allArgs
[
"key"
])
==
1
;
val
[
"data"
][
"flag"
]
=
s_ffmpegMap
.
erase
(
allArgs
[
"key"
])
==
1
;
};
//关闭拉流代理
//测试url http://127.0.0.1/index/api/delFFmepgSource?key=key
api_regist1
(
"/index/api/delFFmpegSource"
,[](
API_ARGS1
){
api_delFFmpegSource
(
API_ARGS_VALUE1
);
});
//此处为了兼容之前的拼写错误
api_regist1
(
"/index/api/delFFmepgSource"
,[](
API_ARGS1
){
api_delFFmpegSource
(
API_ARGS_VALUE1
);
});
});
//新增http api下载可执行程序文件接口
//新增http api下载可执行程序文件接口
//测试url http://127.0.0.1/index/api/downloadBin
//测试url http://127.0.0.1/index/api/downloadBin
api_regist
2
(
"/index/api/downloadBin"
,[](
API_ARGS2
){
api_regist
(
"/index/api/downloadBin"
,[](
API_ARGS2
){
CHECK_SECRET
();
CHECK_SECRET
();
invoker
.
responseFile
(
headerIn
,
StrCaseMap
(),
exePath
());
invoker
.
responseFile
(
headerIn
,
StrCaseMap
(),
exePath
());
});
});
#if defined(ENABLE_RTPPROXY)
#if defined(ENABLE_RTPPROXY)
api_regist
1
(
"/index/api/getRtpInfo"
,[](
API_ARGS1
){
api_regist
(
"/index/api/getRtpInfo"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"stream_id"
);
CHECK_ARGS
(
"stream_id"
);
...
@@ -788,7 +775,7 @@ void installWebApi() {
...
@@ -788,7 +775,7 @@ void installWebApi() {
val
[
"local_ip"
]
=
process
->
get_local_ip
();
val
[
"local_ip"
]
=
process
->
get_local_ip
();
});
});
api_regist
1
(
"/index/api/openRtpServer"
,[](
API_ARGS1
){
api_regist
(
"/index/api/openRtpServer"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"port"
,
"enable_tcp"
,
"stream_id"
);
CHECK_ARGS
(
"port"
,
"enable_tcp"
,
"stream_id"
);
...
@@ -814,7 +801,7 @@ void installWebApi() {
...
@@ -814,7 +801,7 @@ void installWebApi() {
val
[
"port"
]
=
server
->
getPort
();
val
[
"port"
]
=
server
->
getPort
();
});
});
api_regist
1
(
"/index/api/closeRtpServer"
,[](
API_ARGS1
){
api_regist
(
"/index/api/closeRtpServer"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"stream_id"
);
CHECK_ARGS
(
"stream_id"
);
...
@@ -829,7 +816,7 @@ void installWebApi() {
...
@@ -829,7 +816,7 @@ void installWebApi() {
val
[
"hit"
]
=
1
;
val
[
"hit"
]
=
1
;
});
});
api_regist
1
(
"/index/api/listRtpServer"
,[](
API_ARGS1
){
api_regist
(
"/index/api/listRtpServer"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
...
@@ -841,7 +828,7 @@ void installWebApi() {
...
@@ -841,7 +828,7 @@ void installWebApi() {
}
}
});
});
api_regist
2
(
"/index/api/startSendRtp"
,[](
API_ARGS2
){
api_regist
(
"/index/api/startSendRtp"
,[](
API_ARGS2
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
,
"ssrc"
,
"dst_url"
,
"dst_port"
,
"is_udp"
);
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
,
"ssrc"
,
"dst_url"
,
"dst_port"
,
"is_udp"
);
...
@@ -860,7 +847,7 @@ void installWebApi() {
...
@@ -860,7 +847,7 @@ void installWebApi() {
});
});
});
});
api_regist
1
(
"/index/api/stopSendRtp"
,[](
API_ARGS1
){
api_regist
(
"/index/api/stopSendRtp"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
...
@@ -875,7 +862,7 @@ void installWebApi() {
...
@@ -875,7 +862,7 @@ void installWebApi() {
}
}
});
});
api_regist
1
(
"/index/api/pauseRtpCheck"
,
[](
API_ARGS1
)
{
api_regist
(
"/index/api/pauseRtpCheck"
,
[](
API_ARGS1
)
{
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"stream_id"
);
CHECK_ARGS
(
"stream_id"
);
//只是暂停流的检查,流媒体服务器做为流负载服务,收流就转发,RTSP/RTMP有自己暂停协议
//只是暂停流的检查,流媒体服务器做为流负载服务,收流就转发,RTSP/RTMP有自己暂停协议
...
@@ -890,7 +877,7 @@ void installWebApi() {
...
@@ -890,7 +877,7 @@ void installWebApi() {
val
[
"hit"
]
=
1
;
val
[
"hit"
]
=
1
;
});
});
api_regist
1
(
"/index/api/resumeRtpCheck"
,
[](
API_ARGS1
)
{
api_regist
(
"/index/api/resumeRtpCheck"
,
[](
API_ARGS1
)
{
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"stream_id"
);
CHECK_ARGS
(
"stream_id"
);
...
@@ -908,7 +895,7 @@ void installWebApi() {
...
@@ -908,7 +895,7 @@ void installWebApi() {
#endif//ENABLE_RTPPROXY
#endif//ENABLE_RTPPROXY
// 开始录制hls或MP4
// 开始录制hls或MP4
api_regist
1
(
"/index/api/startRecord"
,[](
API_ARGS1
){
api_regist
(
"/index/api/startRecord"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"type"
,
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"type"
,
"vhost"
,
"app"
,
"stream"
);
auto
result
=
Recorder
::
startRecord
((
Recorder
::
type
)
allArgs
[
"type"
].
as
<
int
>
(),
auto
result
=
Recorder
::
startRecord
((
Recorder
::
type
)
allArgs
[
"type"
].
as
<
int
>
(),
...
@@ -922,7 +909,7 @@ void installWebApi() {
...
@@ -922,7 +909,7 @@ void installWebApi() {
});
});
// 停止录制hls或MP4
// 停止录制hls或MP4
api_regist
1
(
"/index/api/stopRecord"
,[](
API_ARGS1
){
api_regist
(
"/index/api/stopRecord"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"type"
,
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"type"
,
"vhost"
,
"app"
,
"stream"
);
auto
result
=
Recorder
::
stopRecord
((
Recorder
::
type
)
allArgs
[
"type"
].
as
<
int
>
(),
auto
result
=
Recorder
::
stopRecord
((
Recorder
::
type
)
allArgs
[
"type"
].
as
<
int
>
(),
...
@@ -935,7 +922,7 @@ void installWebApi() {
...
@@ -935,7 +922,7 @@ void installWebApi() {
});
});
// 获取hls或MP4录制状态
// 获取hls或MP4录制状态
api_regist
1
(
"/index/api/isRecording"
,[](
API_ARGS1
){
api_regist
(
"/index/api/isRecording"
,[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"type"
,
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"type"
,
"vhost"
,
"app"
,
"stream"
);
val
[
"status"
]
=
Recorder
::
isRecording
((
Recorder
::
type
)
allArgs
[
"type"
].
as
<
int
>
(),
val
[
"status"
]
=
Recorder
::
isRecording
((
Recorder
::
type
)
allArgs
[
"type"
].
as
<
int
>
(),
...
@@ -946,7 +933,7 @@ void installWebApi() {
...
@@ -946,7 +933,7 @@ void installWebApi() {
//获取录像文件夹列表或mp4文件列表
//获取录像文件夹列表或mp4文件列表
//http://127.0.0.1/index/api/getMp4RecordFile?vhost=__defaultVhost__&app=live&stream=ss&period=2020-01
//http://127.0.0.1/index/api/getMp4RecordFile?vhost=__defaultVhost__&app=live&stream=ss&period=2020-01
api_regist
1
(
"/index/api/getMp4RecordFile"
,
[](
API_ARGS1
){
api_regist
(
"/index/api/getMp4RecordFile"
,
[](
API_ARGS1
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
auto
record_path
=
Recorder
::
getRecordPath
(
Recorder
::
type_mp4
,
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]);
auto
record_path
=
Recorder
::
getRecordPath
(
Recorder
::
type_mp4
,
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]);
...
@@ -1001,7 +988,7 @@ void installWebApi() {
...
@@ -1001,7 +988,7 @@ void installWebApi() {
//获取截图缓存或者实时截图
//获取截图缓存或者实时截图
//http://127.0.0.1/index/api/getSnap?url=rtmp://127.0.0.1/record/robot.mp4&timeout_sec=10&expire_sec=3
//http://127.0.0.1/index/api/getSnap?url=rtmp://127.0.0.1/record/robot.mp4&timeout_sec=10&expire_sec=3
api_regist
2
(
"/index/api/getSnap"
,
[](
API_ARGS2
){
api_regist
(
"/index/api/getSnap"
,
[](
API_ARGS2
){
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"url"
,
"timeout_sec"
,
"expire_sec"
);
CHECK_ARGS
(
"url"
,
"timeout_sec"
,
"expire_sec"
);
GET_CONFIG
(
string
,
snap_root
,
API
::
kSnapRoot
);
GET_CONFIG
(
string
,
snap_root
,
API
::
kSnapRoot
);
...
@@ -1064,7 +1051,7 @@ void installWebApi() {
...
@@ -1064,7 +1051,7 @@ void installWebApi() {
});
});
////////////以下是注册的Hook API////////////
////////////以下是注册的Hook API////////////
api_regist
1
(
"/index/hook/on_publish"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_publish"
,[](
API_ARGS1
){
//开始推流事件
//开始推流事件
//转换成rtsp或rtmp
//转换成rtsp或rtmp
val
[
"enableRtxp"
]
=
true
;
val
[
"enableRtxp"
]
=
true
;
...
@@ -1074,21 +1061,21 @@ void installWebApi() {
...
@@ -1074,21 +1061,21 @@ void installWebApi() {
val
[
"enableMP4"
]
=
false
;
val
[
"enableMP4"
]
=
false
;
});
});
api_regist
1
(
"/index/hook/on_play"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_play"
,[](
API_ARGS1
){
//开始播放事件
//开始播放事件
});
});
api_regist
1
(
"/index/hook/on_flow_report"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_flow_report"
,[](
API_ARGS1
){
//流量统计hook api
//流量统计hook api
});
});
api_regist
1
(
"/index/hook/on_rtsp_realm"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_rtsp_realm"
,[](
API_ARGS1
){
//rtsp是否需要鉴权,默认需要鉴权
//rtsp是否需要鉴权,默认需要鉴权
val
[
"code"
]
=
API
::
Success
;
val
[
"code"
]
=
API
::
Success
;
val
[
"realm"
]
=
"zlmediakit_reaml"
;
val
[
"realm"
]
=
"zlmediakit_reaml"
;
});
});
api_regist
1
(
"/index/hook/on_rtsp_auth"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_rtsp_auth"
,[](
API_ARGS1
){
//rtsp鉴权密码,密码等于用户名
//rtsp鉴权密码,密码等于用户名
//rtsp可以有双重鉴权!后面还会触发on_play事件
//rtsp可以有双重鉴权!后面还会触发on_play事件
CHECK_ARGS
(
"user_name"
);
CHECK_ARGS
(
"user_name"
);
...
@@ -1097,13 +1084,13 @@ void installWebApi() {
...
@@ -1097,13 +1084,13 @@ void installWebApi() {
val
[
"passwd"
]
=
allArgs
[
"user_name"
].
data
();
val
[
"passwd"
]
=
allArgs
[
"user_name"
].
data
();
});
});
api_regist
1
(
"/index/hook/on_stream_changed"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_stream_changed"
,[](
API_ARGS1
){
//媒体注册或反注册事件
//媒体注册或反注册事件
});
});
#if !defined(_WIN32)
#if !defined(_WIN32)
api_regist
2
(
"/index/hook/on_stream_not_found_ffmpeg"
,[](
API_ARGS2
){
api_regist
(
"/index/hook/on_stream_not_found_ffmpeg"
,[](
API_ARGS2
){
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
...
@@ -1135,7 +1122,7 @@ void installWebApi() {
...
@@ -1135,7 +1122,7 @@ void installWebApi() {
});
});
#endif//!defined(_WIN32)
#endif//!defined(_WIN32)
api_regist
2
(
"/index/hook/on_stream_not_found"
,[](
API_ARGS2
){
api_regist
(
"/index/hook/on_stream_not_found"
,[](
API_ARGS2
){
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
);
...
@@ -1159,15 +1146,15 @@ void installWebApi() {
...
@@ -1159,15 +1146,15 @@ void installWebApi() {
});
});
});
});
api_regist
1
(
"/index/hook/on_record_mp4"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_record_mp4"
,[](
API_ARGS1
){
//录制mp4分片完毕事件
//录制mp4分片完毕事件
});
});
api_regist
1
(
"/index/hook/on_shell_login"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_shell_login"
,[](
API_ARGS1
){
//shell登录调试事件
//shell登录调试事件
});
});
api_regist
1
(
"/index/hook/on_stream_none_reader"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_stream_none_reader"
,[](
API_ARGS1
){
//无人观看流默认关闭
//无人观看流默认关闭
val
[
"close"
]
=
true
;
val
[
"close"
]
=
true
;
});
});
...
@@ -1177,7 +1164,7 @@ void installWebApi() {
...
@@ -1177,7 +1164,7 @@ void installWebApi() {
return
true
;
return
true
;
};
};
api_regist
1
(
"/index/hook/on_http_access"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_http_access"
,[](
API_ARGS1
){
//在这里根据allArgs["params"](url参数)来判断该http客户端是否有权限访问该文件
//在这里根据allArgs["params"](url参数)来判断该http客户端是否有权限访问该文件
if
(
!
checkAccess
(
allArgs
[
"params"
])){
if
(
!
checkAccess
(
allArgs
[
"params"
])){
//无访问权限
//无访问权限
...
@@ -1198,11 +1185,9 @@ void installWebApi() {
...
@@ -1198,11 +1185,9 @@ void installWebApi() {
});
});
api_regist
1
(
"/index/hook/on_server_started"
,[](
API_ARGS1
){
api_regist
(
"/index/hook/on_server_started"
,[](
API_ARGS1
){
//服务器重启报告
//服务器重启报告
});
});
}
}
void
unInstallWebApi
(){
void
unInstallWebApi
(){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论