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
752590f8
Commit
752590f8
authored
Jun 17, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善addStreamPusherProxy相关功能并修复自动删除相关的bug
parent
aa39680c
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
17 行增加
和
42 行删除
+17
-42
server/WebApi.cpp
+12
-24
src/Pusher/PusherProxy.cpp
+3
-9
src/Pusher/PusherProxy.h
+2
-9
没有找到文件。
server/WebApi.cpp
查看文件 @
752590f8
...
@@ -616,6 +616,11 @@ void installWebApi() {
...
@@ -616,6 +616,11 @@ void installWebApi() {
float
timeout_sec
,
float
timeout_sec
,
const
function
<
void
(
const
SockException
&
ex
,
const
string
&
key
)
>
&
cb
)
{
const
function
<
void
(
const
SockException
&
ex
,
const
string
&
key
)
>
&
cb
)
{
auto
key
=
getPusherKey
(
schema
,
vhost
,
app
,
stream
,
url
);
auto
key
=
getPusherKey
(
schema
,
vhost
,
app
,
stream
,
url
);
auto
src
=
MediaSource
::
find
(
schema
,
vhost
,
app
,
stream
);
if
(
!
src
)
{
cb
(
SockException
(
Err_other
,
"can not find the source stream"
),
key
);
return
;
}
lock_guard
<
recursive_mutex
>
lck
(
s_proxyPusherMapMtx
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxyPusherMapMtx
);
if
(
s_proxyPusherMap
.
find
(
key
)
!=
s_proxyPusherMap
.
end
())
{
if
(
s_proxyPusherMap
.
find
(
key
)
!=
s_proxyPusherMap
.
end
())
{
//已经在推流了
//已经在推流了
...
@@ -624,7 +629,7 @@ void installWebApi() {
...
@@ -624,7 +629,7 @@ void installWebApi() {
}
}
//添加推流代理
//添加推流代理
PusherProxy
::
Ptr
pusher
(
new
PusherProxy
(
s
chema
,
vhost
,
app
,
stream
,
retry_count
?
retry_count
:
-
1
));
PusherProxy
::
Ptr
pusher
(
new
PusherProxy
(
s
rc
,
retry_count
?
retry_count
:
-
1
));
s_proxyPusherMap
[
key
]
=
pusher
;
s_proxyPusherMap
[
key
]
=
pusher
;
//指定RTP over TCP(播放rtsp时有效)
//指定RTP over TCP(播放rtsp时有效)
...
@@ -638,18 +643,18 @@ void installWebApi() {
...
@@ -638,18 +643,18 @@ void installWebApi() {
//开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试
//开始推流,如果推流失败或者推流中止,将会自动重试若干次,默认一直重试
pusher
->
setPushCallbackOnce
([
cb
,
key
,
url
](
const
SockException
&
ex
)
{
pusher
->
setPushCallbackOnce
([
cb
,
key
,
url
](
const
SockException
&
ex
)
{
if
(
ex
)
{
if
(
ex
)
{
InfoL
<<
"key: "
<<
key
<<
", "
<<
"addStreamPusherProxy pusher callback erro
r: "
<<
ex
.
what
();
WarnL
<<
"Push "
<<
url
<<
" failed, key: "
<<
key
<<
", er
r: "
<<
ex
.
what
();
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxy
Pusher
MapMtx
);
s_proxyMap
.
erase
(
key
);
s_proxy
Pusher
Map
.
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 erro
r: "
<<
ex
.
what
();
WarnL
<<
"Push "
<<
url
<<
" failed, key: "
<<
key
<<
", er
r: "
<<
ex
.
what
();
lock_guard
<
recursive_mutex
>
lck
(
s_proxyMapMtx
);
lock_guard
<
recursive_mutex
>
lck
(
s_proxy
Pusher
MapMtx
);
s_proxyMap
.
erase
(
key
);
s_proxy
Pusher
Map
.
erase
(
key
);
});
});
pusher
->
publish
(
url
);
pusher
->
publish
(
url
);
};
};
...
@@ -659,23 +664,7 @@ void installWebApi() {
...
@@ -659,23 +664,7 @@ void installWebApi() {
api_regist
(
"/index/api/addStreamPusherProxy"
,
[](
API_ARGS_MAP_ASYNC
)
{
api_regist
(
"/index/api/addStreamPusherProxy"
,
[](
API_ARGS_MAP_ASYNC
)
{
CHECK_SECRET
();
CHECK_SECRET
();
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
,
"dst_url"
);
CHECK_ARGS
(
"schema"
,
"vhost"
,
"app"
,
"stream"
,
"dst_url"
);
auto
dst_url
=
allArgs
[
"dst_url"
];
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
)
{
WarnL
<<
"addStreamPusherProxy, can not find source stream:"
<<
src_url
;
val
[
"code"
]
=
API
::
NotFound
;
val
[
"msg"
]
=
"can not find the source stream"
;
invoker
(
200
,
headerOut
,
val
.
toStyledString
());
return
;
}
InfoL
<<
"addStreamPusherProxy, find stream: "
<<
src_url
<<
", push dst url: "
<<
dst_url
;
addStreamPusherProxy
(
allArgs
[
"schema"
],
addStreamPusherProxy
(
allArgs
[
"schema"
],
allArgs
[
"vhost"
],
allArgs
[
"vhost"
],
allArgs
[
"app"
],
allArgs
[
"app"
],
...
@@ -688,7 +677,6 @@ void installWebApi() {
...
@@ -688,7 +677,6 @@ void installWebApi() {
if
(
ex
)
{
if
(
ex
)
{
val
[
"code"
]
=
API
::
OtherFailed
;
val
[
"code"
]
=
API
::
OtherFailed
;
val
[
"msg"
]
=
ex
.
what
();
val
[
"msg"
]
=
ex
.
what
();
WarnL
<<
"Publish stream failed, dst url is: "
<<
dst_url
;
}
else
{
}
else
{
val
[
"data"
][
"key"
]
=
key
;
val
[
"data"
][
"key"
]
=
key
;
InfoL
<<
"Publish success, please play with player:"
<<
dst_url
;
InfoL
<<
"Publish success, please play with player:"
<<
dst_url
;
...
...
src/Pusher/PusherProxy.cpp
查看文件 @
752590f8
...
@@ -14,13 +14,8 @@ using namespace toolkit;
...
@@ -14,13 +14,8 @@ using namespace toolkit;
namespace
mediakit
{
namespace
mediakit
{
PusherProxy
::
PusherProxy
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
PusherProxy
::
PusherProxy
(
const
MediaSource
::
Ptr
&
src
,
int
retry_count
,
const
EventPoller
::
Ptr
&
poller
)
int
retry_count
,
const
EventPoller
::
Ptr
&
poller
)
:
MediaPusher
(
src
,
poller
){
:
MediaPusher
(
schema
,
vhost
,
app
,
stream
,
poller
){
_schema
=
schema
;
_vhost
=
vhost
;
_app
=
app
;
_stream_id
=
stream
;
_retry_count
=
retry_count
;
_retry_count
=
retry_count
;
_on_close
=
[](
const
SockException
&
)
{};
_on_close
=
[](
const
SockException
&
)
{};
}
}
...
@@ -53,7 +48,7 @@ void PusherProxy::publish(const string& dstUrl) {
...
@@ -53,7 +48,7 @@ void PusherProxy::publish(const string& dstUrl) {
if
(
!
err
)
{
if
(
!
err
)
{
// 推流成功
// 推流成功
*
piFailedCnt
=
0
;
*
piFailedCnt
=
0
;
InfoL
<<
"
pusher p
ublish "
<<
dstUrl
<<
" success"
;
InfoL
<<
"
P
ublish "
<<
dstUrl
<<
" success"
;
}
else
if
(
*
piFailedCnt
<
strongSelf
->
_retry_count
||
strongSelf
->
_retry_count
<
0
)
{
}
else
if
(
*
piFailedCnt
<
strongSelf
->
_retry_count
||
strongSelf
->
_retry_count
<
0
)
{
// 推流失败,延时重试推送
// 推流失败,延时重试推送
strongSelf
->
rePublish
(
dstUrl
,
(
*
piFailedCnt
)
++
);
strongSelf
->
rePublish
(
dstUrl
,
(
*
piFailedCnt
)
++
);
...
@@ -77,7 +72,6 @@ void PusherProxy::publish(const string& dstUrl) {
...
@@ -77,7 +72,6 @@ void PusherProxy::publish(const string& dstUrl) {
});
});
MediaPusher
::
publish
(
dstUrl
);
MediaPusher
::
publish
(
dstUrl
);
_publish_url
=
dstUrl
;
}
}
void
PusherProxy
::
rePublish
(
const
string
&
dstUrl
,
int
iFailedCnt
)
{
void
PusherProxy
::
rePublish
(
const
string
&
dstUrl
,
int
iFailedCnt
)
{
...
...
src/Pusher/PusherProxy.h
查看文件 @
752590f8
...
@@ -24,10 +24,8 @@ public:
...
@@ -24,10 +24,8 @@ public:
typedef
std
::
shared_ptr
<
PusherProxy
>
Ptr
;
typedef
std
::
shared_ptr
<
PusherProxy
>
Ptr
;
// 如果retry_count<0,则一直重试播放;否则重试retry_count次数
// 如果retry_count<0,则一直重试播放;否则重试retry_count次数
// 默认一直重试,创建此对象时候,需要外部保证mediaSource存在
// 默认一直重试,创建此对象时候,需要外部保证MediaSource存在
PusherProxy
(
const
string
&
schema
,
const
string
&
vhost
,
const
string
&
app
,
const
string
&
stream
,
PusherProxy
(
const
MediaSource
::
Ptr
&
src
,
int
retry_count
=
-
1
,
const
EventPoller
::
Ptr
&
poller
=
nullptr
);
int
retry_count
=
-
1
,
const
EventPoller
::
Ptr
&
poller
=
nullptr
);
~
PusherProxy
()
override
;
~
PusherProxy
()
override
;
/**
/**
...
@@ -54,11 +52,6 @@ private:
...
@@ -54,11 +52,6 @@ private:
private
:
private
:
int
_retry_count
;
int
_retry_count
;
std
::
string
_schema
;
string
_vhost
;
string
_app
;
string
_stream_id
;
std
::
string
_publish_url
;
Timer
::
Ptr
_timer
;
Timer
::
Ptr
_timer
;
function
<
void
(
const
SockException
&
ex
)
>
_on_close
;
function
<
void
(
const
SockException
&
ex
)
>
_on_close
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论