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
bc631427
Commit
bc631427
authored
Nov 10, 2022
by
xiongguangjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rtp server timeout hook
parent
af554bc3
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
58 行增加
和
2 行删除
+58
-2
conf/config.ini
+4
-0
server/WebApi.cpp
+5
-0
server/WebHook.cpp
+18
-0
src/Common/config.cpp
+1
-0
src/Common/config.h
+4
-0
src/Rtp/RtpServer.cpp
+26
-2
没有找到文件。
conf/config.ini
查看文件 @
bc631427
...
...
@@ -155,6 +155,10 @@ on_server_started=https://127.0.0.1/index/hook/on_server_started
on_server_keepalive
=
https://127.0.0.1/index/hook/on_server_keepalive
#发送rtp(startSendRtp)被动关闭时回调
on_send_rtp_stopped
=
https://127.0.0.1/index/hook/on_send_rtp_stopped
#rtp server 超时未收到数据
on_rtp_server_timeout
=
https://127.0.0.1/index/hook/on_rtp_server_timeout
#hook api最大等待回复时间,单位秒
timeoutSec
=
10
#keepalive hook触发间隔,单位秒,float类型
...
...
server/WebApi.cpp
查看文件 @
bc631427
...
...
@@ -1761,6 +1761,11 @@ void installWebApi() {
api_regist
(
"/index/hook/on_server_keepalive"
,[](
API_ARGS_JSON
){
//心跳hook
});
api_regist
(
"/index/hook/on_rtp_server_timeout"
,[](
API_ARGS_JSON
){
//rtp server 超时
TraceL
<<
allArgs
.
getArgs
().
toStyledString
();
});
}
void
unInstallWebApi
(){
...
...
server/WebHook.cpp
查看文件 @
bc631427
...
...
@@ -46,6 +46,7 @@ const string kOnHttpAccess = HOOK_FIELD"on_http_access";
const
string
kOnServerStarted
=
HOOK_FIELD
"on_server_started"
;
const
string
kOnServerKeepalive
=
HOOK_FIELD
"on_server_keepalive"
;
const
string
kOnSendRtpStopped
=
HOOK_FIELD
"on_send_rtp_stopped"
;
const
string
kOnRtpServerTimeout
=
HOOK_FIELD
"on_rtp_server_timeout"
;
const
string
kAdminParams
=
HOOK_FIELD
"admin_params"
;
const
string
kAliveInterval
=
HOOK_FIELD
"alive_interval"
;
const
string
kRetry
=
HOOK_FIELD
"retry"
;
...
...
@@ -70,6 +71,7 @@ onceToken token([](){
mINI
::
Instance
()[
kOnServerStarted
]
=
""
;
mINI
::
Instance
()[
kOnServerKeepalive
]
=
""
;
mINI
::
Instance
()[
kOnSendRtpStopped
]
=
""
;
mINI
::
Instance
()[
kOnRtpServerTimeout
]
=
""
;
mINI
::
Instance
()[
kAdminParams
]
=
"secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc"
;
mINI
::
Instance
()[
kAliveInterval
]
=
30.0
;
mINI
::
Instance
()[
kRetry
]
=
1
;
...
...
@@ -648,6 +650,22 @@ void installWebHook(){
});
});
NoticeCenter
::
Instance
().
addListener
(
&
web_hook_tag
,
Broadcast
::
KBroadcastRtpServerTimeout
,[](
BroadcastRtpServerTimeout
){
GET_CONFIG
(
string
,
rtp_server_timeout
,
Hook
::
kOnRtpServerTimeout
);
if
(
!
hook_enable
||
rtp_server_timeout
.
empty
()){
return
;
}
ArgsType
body
;
body
[
"local_port"
]
=
local_port
;
body
[
"stream_id"
]
=
stream_id
;
body
[
"tcp_mode"
]
=
tcp_mode
;
body
[
"re_use_port"
]
=
re_use_port
;
body
[
"ssrc"
]
=
ssrc
;
do_http_hook
(
rtp_server_timeout
,
body
);
});
//汇报服务器重新启动
reportServerStarted
();
...
...
src/Common/config.cpp
查看文件 @
bc631427
...
...
@@ -56,6 +56,7 @@ const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream";
const
string
kBroadcastStreamNoneReader
=
"kBroadcastStreamNoneReader"
;
const
string
kBroadcastHttpBeforeAccess
=
"kBroadcastHttpBeforeAccess"
;
const
string
kBroadcastSendRtpStopped
=
"kBroadcastSendRtpStopped"
;
const
string
KBroadcastRtpServerTimeout
=
"KBroadcastRtpServerTimeout"
;
}
// namespace Broadcast
...
...
src/Common/config.h
查看文件 @
bc631427
...
...
@@ -114,6 +114,10 @@ extern const std::string kBroadcastSendRtpStopped;
extern
const
std
::
string
kBroadcastReloadConfig
;
#define BroadcastReloadConfigArgs void
// rtp server 超时
extern
const
std
::
string
KBroadcastRtpServerTimeout
;
#define BroadcastRtpServerTimeout uint16_t &local_port, const string &stream_id,int &tcp_mode, bool &re_use_port, uint32_t &ssrc
#define ReloadConfigTag ((void *)(0xFF))
#define RELOAD_KEY(arg, key) \
do { \
...
...
src/Rtp/RtpServer.cpp
查看文件 @
bc631427
...
...
@@ -36,12 +36,20 @@ public:
_stream_id
=
std
::
move
(
stream_id
);
}
~
RtcpHelper
()
{
if
(
_process
)
{
// 删除rtp处理器
RtpSelector
::
Instance
().
delProcess
(
_stream_id
,
_process
.
get
());
}
}
void
setRtpServerInfo
(
uint16_t
local_port
,
RtpServer
::
TcpMode
mode
,
bool
re_use_port
,
uint32_t
ssrc
){
_local_port
=
local_port
;
_tcp_mode
=
mode
;
_re_use_port
=
re_use_port
;
_ssrc
=
ssrc
;
}
void
setOnDetach
(
function
<
void
()
>
cb
)
{
if
(
_process
)
{
...
...
@@ -55,8 +63,7 @@ public:
if
(
!
_process
)
{
_process
=
RtpSelector
::
Instance
().
getProcess
(
_stream_id
,
true
);
_process
->
setOnDetach
(
std
::
move
(
_on_detach
));
_delay_task
->
cancel
();
_delay_task
=
nullptr
;
cancelDelayTask
();
}
_process
->
inputRtp
(
true
,
sock
,
buf
->
data
(),
buf
->
size
(),
addr
);
...
...
@@ -91,11 +98,21 @@ public:
if
(
!
process
&&
strong_self
->
_on_detach
)
{
strong_self
->
_on_detach
();
}
if
(
!
process
){
// process 未创建,触发rtp server 超时事件
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
KBroadcastRtpServerTimeout
,
strong_self
->
_local_port
,
strong_self
->
_stream_id
,(
int
)
strong_self
->
_tcp_mode
,
strong_self
->
_re_use_port
,
strong_self
->
_ssrc
);
}
}
return
0
;
});
}
void
cancelDelayTask
(){
if
(
_delay_task
){
_delay_task
->
cancel
();
_delay_task
=
nullptr
;
}
}
private
:
void
sendRtcp
(
uint32_t
rtp_ssrc
,
struct
sockaddr
*
addr
)
{
// 每5秒发送一次rtcp
...
...
@@ -118,6 +135,12 @@ private:
}
private
:
uint16_t
_local_port
=
0
;
RtpServer
::
TcpMode
_tcp_mode
=
RtpServer
::
NONE
;
bool
_re_use_port
=
false
;
uint32_t
_ssrc
=
0
;
Ticker
_ticker
;
Socket
::
Ptr
_rtcp_sock
;
RtpProcess
::
Ptr
_process
;
...
...
@@ -169,6 +192,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_
//指定了流id,那么一个端口一个流(不管是否包含多个ssrc的多个流,绑定rtp源后,会筛选掉ip端口不匹配的流)
helper
=
std
::
make_shared
<
RtcpHelper
>
(
std
::
move
(
rtcp_socket
),
stream_id
);
helper
->
startRtcp
();
helper
->
setRtpServerInfo
(
local_port
,
tcp_mode
,
re_use_port
,
ssrc
);
rtp_socket
->
setOnRead
([
rtp_socket
,
helper
,
ssrc
](
const
Buffer
::
Ptr
&
buf
,
struct
sockaddr
*
addr
,
int
addr_len
)
{
RtpHeader
*
header
=
(
RtpHeader
*
)
buf
->
data
();
auto
rtp_ssrc
=
ntohl
(
header
->
ssrc
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论