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
936c6f79
Commit
936c6f79
authored
Jun 17, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整代码细节
parent
06023f17
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
29 行增加
和
33 行删除
+29
-33
server/WebApi.cpp
+29
-33
没有找到文件。
server/WebApi.cpp
查看文件 @
936c6f79
...
...
@@ -232,15 +232,15 @@ static inline void addHttpListener(){
}
//拉流代理器列表
static
unordered_map
<
string
,
PlayerProxy
::
Ptr
>
s_proxyMap
;
static
unordered_map
<
string
,
PlayerProxy
::
Ptr
>
s_proxyMap
;
static
recursive_mutex
s_proxyMapMtx
;
//推流代理器列表
static
unordered_map
<
string
,
PusherProxy
::
Ptr
>
s_proxyPusherMap
;
static
unordered_map
<
string
,
PusherProxy
::
Ptr
>
s_proxyPusherMap
;
static
recursive_mutex
s_proxyPusherMapMtx
;
//FFmpeg拉流代理器列表
static
unordered_map
<
string
,
FFmpegSource
::
Ptr
>
s_ffmpegMap
;
static
unordered_map
<
string
,
FFmpegSource
::
Ptr
>
s_ffmpegMap
;
static
recursive_mutex
s_ffmpegMapMtx
;
#if defined(ENABLE_RTPPROXY)
...
...
@@ -607,12 +607,12 @@ void installWebApi() {
const
string
&
stream
,
const
string
&
url
,
int
retryCount
,
const
function
<
void
(
const
SockException
&
ex
,
const
string
&
key
)
>
&
cb
)
{
const
function
<
void
(
const
SockException
&
ex
,
const
string
&
key
)
>
&
cb
)
{
auto
key
=
getProxyKey
(
vhost
,
app
,
stream
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxyPusherMapMtx
);
if
(
s_proxyPusherMap
.
find
(
key
)
!=
s_proxyPusherMap
.
end
()){
if
(
s_proxyPusherMap
.
find
(
key
)
!=
s_proxyPusherMap
.
end
())
{
//已经在推流了
cb
(
SockException
(
Err_success
),
key
);
cb
(
SockException
(
Err_success
),
key
);
return
;
}
...
...
@@ -621,21 +621,21 @@ void installWebApi() {
if
(
retryCount
!=
0
)
retry_count
=
retryCount
;
//添加推流代理
PusherProxy
::
Ptr
pusher
(
new
PusherProxy
(
schema
,
vhost
,
app
,
stream
,
retry_count
,
poller
));
PusherProxy
::
Ptr
pusher
(
new
PusherProxy
(
schema
,
vhost
,
app
,
stream
,
retry_count
,
poller
));
s_proxyPusherMap
[
key
]
=
pusher
;
//开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试
pusher
->
setPushCallbackOnce
([
cb
,
key
,
url
](
const
SockException
&
ex
){
if
(
ex
){
pusher
->
setPushCallbackOnce
([
cb
,
key
,
url
](
const
SockException
&
ex
)
{
if
(
ex
)
{
InfoL
<<
"key: "
<<
key
<<
", "
<<
"addStreamPusherProxy pusher callback error: "
<<
ex
.
what
();
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
s_proxyMap
.
erase
(
key
);
}
cb
(
ex
,
key
);
cb
(
ex
,
key
);
});
//被主动关闭推流
pusher
->
setOnClose
([
key
,
url
](
const
SockException
&
ex
){
pusher
->
setOnClose
([
key
,
url
](
const
SockException
&
ex
)
{
InfoL
<<
"key: "
<<
key
<<
", "
<<
"addStreamPusherProxy close callback error: "
<<
ex
.
what
();
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
s_proxyMap
.
erase
(
key
);
...
...
@@ -647,50 +647,46 @@ void installWebApi() {
//测试url http://127.0.0.1/index/api/addStreamPusherProxy?schema=rtmp&vhost=__defaultVhost__&app=proxy&stream=0&dst_url=rtmp://127.0.0.1/live/obs
api_regist
(
"/index/api/addStreamPusherProxy"
,
[](
API_ARGS_MAP_ASYNC
)
{
CHECK_SECRET
();
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream
"
);
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
,
"dst_url
"
);
InfoL
<<
allArgs
[
"schema"
]
<<
", "
<<
allArgs
[
"vhost"
]
<<
", "
<<
allArgs
[
"app"
]
<<
", "
<<
allArgs
[
"stream"
];
//查找源
auto
dst_url
=
allArgs
[
"dst_url"
];
auto
src_url
=
allArgs
[
"schema"
]
+
"/"
+
allArgs
[
"vhost"
]
+
"/"
+
allArgs
[
"app"
]
+
"/"
+
allArgs
[
"stream"
];
auto
src
=
MediaSource
::
find
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
]);
if
(
!
src
){
InfoL
<<
"addStreamPusherProxy, canont find source stream!"
;
const_cast
<
Value
&>
(
val
)[
"code"
]
=
API
::
OtherFaile
d
;
const_cast
<
Value
&>
(
val
)
[
"msg"
]
=
"can not find the source stream"
;
if
(
!
src
)
{
WarnL
<<
"addStreamPusherProxy, can not find source stream:"
<<
src_url
;
val
[
"code"
]
=
API
::
NotFoun
d
;
val
[
"msg"
]
=
"can not find the source stream"
;
invoker
(
200
,
headerOut
,
val
.
toStyledString
());
return
;
}
std
::
string
srcUrl
=
allArgs
[
"schema"
]
+
"://"
+
"127.0.0.1"
+
"/"
+
allArgs
[
"app"
]
+
"/"
+
allArgs
[
"stream"
];
std
::
string
pushUrl
=
decodeBase64
(
allArgs
[
"dst_url"
]);
InfoL
<<
"addStreamPusherProxy, find stream: "
<<
srcUrl
<<
", push dst url: "
<<
pushUrl
;
InfoL
<<
"addStreamPusherProxy, find stream: "
<<
src_url
<<
", push dst url: "
<<
dst_url
;
addStreamPusherProxy
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"stream"
],
pushUrl
,
allArgs
[
"dst_url"
]
,
allArgs
[
"retry_count"
],
[
invoker
,
val
,
headerOut
,
pushUrl
](
const
SockException
&
ex
,
const
string
&
key
)
{
if
(
ex
)
{
const_cast
<
Value
&>
(
val
)
[
"code"
]
=
API
::
OtherFailed
;
const_cast
<
Value
&>
(
val
)
[
"msg"
]
=
ex
.
what
();
InfoL
<<
"Publish error url: "
<<
pushU
rl
;
}
else
{
const_cast
<
Value
&>
(
val
)
[
"data"
][
"key"
]
=
key
;
InfoL
<<
"Publish success,
Please play with player:"
<<
pushU
rl
;
[
invoker
,
val
,
headerOut
,
dst_url
](
const
SockException
&
ex
,
const
string
&
key
)
mutable
{
if
(
ex
)
{
val
[
"code"
]
=
API
::
OtherFailed
;
val
[
"msg"
]
=
ex
.
what
();
WarnL
<<
"Publish stream failed, dst url is: "
<<
dst_u
rl
;
}
else
{
val
[
"data"
][
"key"
]
=
key
;
InfoL
<<
"Publish success,
please play with player:"
<<
dst_u
rl
;
}
invoker
(
200
,
headerOut
,
val
.
toStyledString
());
});
});
//关闭推流代理
//测试url http://127.0.0.1/index/api/delStreamPusherProxy?key=__defaultVhost__/proxy/0
api_regist
(
"/index/api/delStreamPusherProxy"
,
[](
API_ARGS_MAP
)
{
api_regist
(
"/index/api/delStreamPusherProxy"
,
[](
API_ARGS_MAP
)
{
CHECK_SECRET
();
CHECK_ARGS
(
"key"
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxyPusherMapMtx
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论