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
60a23468
Commit
60a23468
authored
Jun 17, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
媒体源注销后不做无谓推流重试
parent
e4172b4a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
33 行删除
+40
-33
src/Pusher/PusherProxy.cpp
+39
-32
src/Pusher/PusherProxy.h
+1
-1
没有找到文件。
src/Pusher/PusherProxy.cpp
查看文件 @
60a23468
...
...
@@ -18,6 +18,7 @@ PusherProxy::PusherProxy(const MediaSource::Ptr &src, int retry_count, const Eve
:
MediaPusher
(
src
,
poller
){
_retry_count
=
retry_count
;
_on_close
=
[](
const
SockException
&
)
{};
_weak_src
=
src
;
}
PusherProxy
::~
PusherProxy
()
{
...
...
@@ -32,59 +33,65 @@ void PusherProxy::setOnClose(const function<void(const SockException &ex)> &cb)
_on_close
=
cb
;
}
void
PusherProxy
::
publish
(
const
string
&
dstU
rl
)
{
std
::
weak_ptr
<
PusherProxy
>
weak
S
elf
=
shared_from_this
();
std
::
shared_ptr
<
int
>
piFailedC
nt
(
new
int
(
0
));
void
PusherProxy
::
publish
(
const
string
&
dst_u
rl
)
{
std
::
weak_ptr
<
PusherProxy
>
weak
_s
elf
=
shared_from_this
();
std
::
shared_ptr
<
int
>
failed_c
nt
(
new
int
(
0
));
setOnPublished
([
weakSelf
,
dstUrl
,
piFailedCnt
](
const
SockException
&
err
)
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
return
;
setOnPublished
([
weak_self
,
dst_url
,
failed_cnt
](
const
SockException
&
err
)
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
return
;
}
if
(
strongS
elf
->
_on_publish
)
{
strongS
elf
->
_on_publish
(
err
);
strongS
elf
->
_on_publish
=
nullptr
;
}
if
(
strong_s
elf
->
_on_publish
)
{
strong_s
elf
->
_on_publish
(
err
);
strong_s
elf
->
_on_publish
=
nullptr
;
}
auto
src
=
strong_self
->
_weak_src
.
lock
();
if
(
!
err
)
{
// 推流成功
*
piFailedC
nt
=
0
;
InfoL
<<
"Publish "
<<
dst
U
rl
<<
" success"
;
}
else
if
(
*
piFailedCnt
<
strongSelf
->
_retry_count
||
strongSelf
->
_retry_count
<
0
)
{
*
failed_c
nt
=
0
;
InfoL
<<
"Publish "
<<
dst
_u
rl
<<
" success"
;
}
else
if
(
src
&&
(
*
failed_cnt
<
strong_self
->
_retry_count
||
strong_self
->
_retry_count
<
0
)
)
{
// 推流失败,延时重试推送
strong
Self
->
rePublish
(
dstUrl
,
(
*
piFailedC
nt
)
++
);
strong
_self
->
rePublish
(
dst_url
,
(
*
failed_c
nt
)
++
);
}
else
{
//达到了最大重试次数,回调关闭
strong
S
elf
->
_on_close
(
err
);
//
如果媒体源已经注销, 或
达到了最大重试次数,回调关闭
strong
_s
elf
->
_on_close
(
err
);
}
});
setOnShutdown
([
weakSelf
,
dstUrl
,
piFailedCnt
](
const
SockException
&
err
)
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
return
;
setOnShutdown
([
weak_self
,
dst_url
,
failed_cnt
](
const
SockException
&
err
)
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
return
;
}
auto
src
=
strong_self
->
_weak_src
.
lock
();
//推流异常中断,延时重试播放
if
(
*
piFailedCnt
<
strongSelf
->
_retry_count
||
strongSelf
->
_retry_count
<
0
)
{
strong
Self
->
rePublish
(
dstUrl
,
(
*
piFailedC
nt
)
++
);
if
(
src
&&
(
*
failed_cnt
<
strong_self
->
_retry_count
||
strong_self
->
_retry_count
<
0
)
)
{
strong
_self
->
rePublish
(
dst_url
,
(
*
failed_c
nt
)
++
);
}
else
{
//达到了最大重试次数,回调关闭
strong
S
elf
->
_on_close
(
err
);
//
如果媒体源已经注销, 或
达到了最大重试次数,回调关闭
strong
_s
elf
->
_on_close
(
err
);
}
});
MediaPusher
::
publish
(
dst
U
rl
);
MediaPusher
::
publish
(
dst
_u
rl
);
}
void
PusherProxy
::
rePublish
(
const
string
&
dst
Url
,
int
iFailedC
nt
)
{
auto
iDelay
=
MAX
(
2
*
1000
,
MIN
(
iFailedC
nt
*
3000
,
60
*
1000
));
weak_ptr
<
PusherProxy
>
weak
S
elf
=
shared_from_this
();
_timer
=
std
::
make_shared
<
Timer
>
(
iDelay
/
1000.0
f
,
[
weakSelf
,
dstUrl
,
iFailedC
nt
]()
{
void
PusherProxy
::
rePublish
(
const
string
&
dst
_url
,
int
failed_c
nt
)
{
auto
delay
=
MAX
(
2
*
1000
,
MIN
(
failed_c
nt
*
3000
,
60
*
1000
));
weak_ptr
<
PusherProxy
>
weak
_s
elf
=
shared_from_this
();
_timer
=
std
::
make_shared
<
Timer
>
(
delay
/
1000.0
f
,
[
weak_self
,
dst_url
,
failed_c
nt
]()
{
//推流失败次数越多,则延时越长
auto
strong
Pusher
=
weakS
elf
.
lock
();
if
(
!
strong
Pusher
)
{
auto
strong
_self
=
weak_s
elf
.
lock
();
if
(
!
strong
_self
)
{
return
false
;
}
WarnL
<<
"推流重试["
<<
iFailedCnt
<<
"]:"
<<
dstU
rl
;
strong
Pusher
->
MediaPusher
::
publish
(
dstU
rl
);
WarnL
<<
"推流重试["
<<
failed_cnt
<<
"]:"
<<
dst_u
rl
;
strong
_self
->
MediaPusher
::
publish
(
dst_u
rl
);
return
false
;
},
getPoller
());
}
...
...
src/Pusher/PusherProxy.h
查看文件 @
60a23468
...
...
@@ -53,7 +53,7 @@ private:
private
:
int
_retry_count
;
Timer
::
Ptr
_timer
;
std
::
weak_ptr
<
MediaSource
>
_weak_src
;
function
<
void
(
const
SockException
&
ex
)
>
_on_close
;
function
<
void
(
const
SockException
&
ex
)
>
_on_publish
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论