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
22e39dc2
Commit
22e39dc2
authored
May 27, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成按需拉流测试
parent
72581cf4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
56 行增加
和
26 行删除
+56
-26
server/WebApi.cpp
+56
-26
没有找到文件。
server/WebApi.cpp
查看文件 @
22e39dc2
...
@@ -411,35 +411,27 @@ void installWebApi() {
...
@@ -411,35 +411,27 @@ void installWebApi() {
val
[
"msg"
]
=
"success"
;
val
[
"msg"
]
=
"success"
;
});
});
static
auto
addStreamProxy
=
[](
const
string
&
vhost
,
//动态添加rtsp/rtmp拉流代理
const
string
&
app
,
//测试url http://127.0.0.1/index/api/addStreamProxy?vhost=__defaultVhost__&app=proxy&stream=0&url=rtmp://127.0.0.1/live/obs
const
string
&
stream
,
API_REGIST_INVOKER
(
api
,
addStreamProxy
,{
const
string
&
url
,
CHECK_SECRET
();
bool
enable_hls
,
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
,
"url"
);
bool
enable_mp4
,
auto
key
=
getProxyKey
(
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]);
int
rtp_type
,
const
function
<
void
(
const
SockException
&
ex
,
const
string
&
key
)
>
&
cb
){
auto
key
=
getProxyKey
(
vhost
,
app
,
stream
);
//添加拉流代理
//添加拉流代理
PlayerProxy
::
Ptr
player
(
new
PlayerProxy
(
PlayerProxy
::
Ptr
player
(
new
PlayerProxy
(
vhost
,
app
,
stream
,
enable_hls
,
enable_mp4
));
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
],
allArgs
[
"enable_hls"
],
allArgs
[
"enable_mp4"
]
));
//指定RTP over TCP(播放rtsp时有效)
//指定RTP over TCP(播放rtsp时有效)
(
*
player
)[
kRtpType
]
=
allArgs
[
"rtp_type"
].
as
<
int
>
()
;
(
*
player
)[
kRtpType
]
=
rtp_type
;
//开始播放,如果播放失败或者播放中止,将会自动重试若干次,默认一直重试
//开始播放,如果播放失败或者播放中止,将会自动重试若干次,默认一直重试
player
->
setPlayCallbackOnce
([
invoker
,
val
,
headerOut
,
player
,
key
](
const
SockException
&
ex
){
player
->
setPlayCallbackOnce
([
cb
,
player
,
key
](
const
SockException
&
ex
){
if
(
ex
){
if
(
!
ex
){
const_cast
<
Value
&>
(
val
)[
"code"
]
=
API
::
OtherFailed
;
const_cast
<
Value
&>
(
val
)[
"msg"
]
=
ex
.
what
();
}
else
{
const_cast
<
Value
&>
(
val
)[
"data"
][
"key"
]
=
key
;
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
s_proxyMap
[
key
]
=
player
;
s_proxyMap
[
key
]
=
player
;
}
}
const_cast
<
PlayerProxy
::
Ptr
&>
(
player
).
reset
();
const_cast
<
PlayerProxy
::
Ptr
&>
(
player
).
reset
();
invoker
(
"200 OK"
,
headerOut
,
val
.
toStyledString
()
);
cb
(
ex
,
key
);
});
});
//被主动关闭拉流
//被主动关闭拉流
...
@@ -447,7 +439,30 @@ void installWebApi() {
...
@@ -447,7 +439,30 @@ void installWebApi() {
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
s_proxyMap
.
erase
(
key
);
s_proxyMap
.
erase
(
key
);
});
});
player
->
play
(
allArgs
[
"url"
]);
player
->
play
(
url
);
};
//动态添加rtsp/rtmp拉流代理
//测试url http://127.0.0.1/index/api/addStreamProxy?vhost=__defaultVhost__&app=proxy&stream=0&url=rtmp://127.0.0.1/live/obs
API_REGIST_INVOKER
(
api
,
addStreamProxy
,{
CHECK_SECRET
();
CHECK_ARGS
(
"vhost"
,
"app"
,
"stream"
,
"url"
);
addStreamProxy
(
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
],
allArgs
[
"url"
],
allArgs
[
"enable_hls"
],
allArgs
[
"enable_mp4"
],
allArgs
[
"rtp_type"
],
[
invoker
,
val
,
headerOut
](
const
SockException
&
ex
,
const
string
&
key
){
if
(
ex
){
const_cast
<
Value
&>
(
val
)[
"code"
]
=
API
::
OtherFailed
;
const_cast
<
Value
&>
(
val
)[
"msg"
]
=
ex
.
what
();
}
else
{
const_cast
<
Value
&>
(
val
)[
"data"
][
"key"
]
=
key
;
}
invoker
(
"200 OK"
,
headerOut
,
val
.
toStyledString
());
});
});
});
//关闭拉流代理
//关闭拉流代理
...
@@ -496,9 +511,24 @@ void installWebApi() {
...
@@ -496,9 +511,24 @@ void installWebApi() {
throw
SuccessException
();
throw
SuccessException
();
});
});
API_REGIST
(
hook
,
on_stream_not_found
,{
API_REGIST_INVOKER
(
hook
,
on_stream_not_found
,{
//媒体未找到事件
//媒体未找到事件,我们都及时拉流hks作为替代品,目的是为了测试按需拉流
throw
SuccessException
();
addStreamProxy
(
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
],
"rtmp://live.hkstv.hk.lxdns.com/live/hks2"
,
false
,
false
,
0
,
[
invoker
,
val
,
headerOut
](
const
SockException
&
ex
,
const
string
&
key
){
if
(
ex
){
const_cast
<
Value
&>
(
val
)[
"code"
]
=
API
::
OtherFailed
;
const_cast
<
Value
&>
(
val
)[
"msg"
]
=
ex
.
what
();
}
else
{
const_cast
<
Value
&>
(
val
)[
"data"
][
"key"
]
=
key
;
}
invoker
(
"200 OK"
,
headerOut
,
val
.
toStyledString
());
});
});
});
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论