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
a6e82799
Commit
a6e82799
authored
Apr 09, 2022
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
openRtpServer接口新增re_use_port参数
parent
6073175e
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
18 行增加
和
16 行删除
+18
-16
postman/ZLMediaKit.postman_collection.json
+5
-0
server/WebApi.cpp
+1
-1
src/Rtp/RtpServer.cpp
+4
-4
src/Rtp/RtpServer.h
+2
-1
src/Rtsp/Rtsp.cpp
+5
-9
src/Rtsp/Rtsp.h
+1
-1
没有找到文件。
postman/ZLMediaKit.postman_collection.json
查看文件 @
a6e82799
...
...
@@ -1289,6 +1289,11 @@
"key"
:
"stream_id"
,
"value"
:
"test"
,
"description"
:
"该端口绑定的流id
\n
"
},
{
"key"
:
"re_use_port"
,
"value"
:
"0"
,
"description"
:
"是否重用端口,默认为0,非必选参数"
}
]
}
...
...
server/WebApi.cpp
查看文件 @
a6e82799
...
...
@@ -1056,7 +1056,7 @@ void installWebApi() {
}
RtpServer
::
Ptr
server
=
std
::
make_shared
<
RtpServer
>
();
server
->
start
(
allArgs
[
"port"
],
stream_id
,
allArgs
[
"enable_tcp"
].
as
<
bool
>
(),
"0.0.0.0"
,
false
);
server
->
start
(
allArgs
[
"port"
],
stream_id
,
allArgs
[
"enable_tcp"
].
as
<
bool
>
(),
"0.0.0.0"
,
allArgs
[
"re_use_port"
].
as
<
bool
>
()
);
server
->
setOnDetach
([
stream_id
]()
{
//设置rtp超时移除事件
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
...
...
src/Rtp/RtpServer.cpp
查看文件 @
a6e82799
...
...
@@ -88,21 +88,21 @@ private:
std
::
shared_ptr
<
struct
sockaddr
>
_rtcp_addr
;
};
void
RtpServer
::
start
(
uint16_t
local_port
,
const
string
&
stream_id
,
bool
enable_tcp
,
const
char
*
local_ip
,
bool
enable_reuse
)
{
void
RtpServer
::
start
(
uint16_t
local_port
,
const
string
&
stream_id
,
bool
enable_tcp
,
const
char
*
local_ip
,
bool
re_use_port
)
{
//创建udp服务器
Socket
::
Ptr
rtp_socket
=
Socket
::
createSocket
(
nullptr
,
true
);
Socket
::
Ptr
rtcp_socket
=
Socket
::
createSocket
(
nullptr
,
true
);
if
(
local_port
==
0
)
{
//随机端口,rtp端口采用偶数
auto
pair
=
std
::
make_pair
(
rtp_socket
,
rtcp_socket
);
makeSockPair
(
pair
,
local_ip
);
makeSockPair
(
pair
,
local_ip
,
re_use_port
);
//取偶数端口
rtp_socket
=
pair
.
first
;
rtcp_socket
=
pair
.
second
;
}
else
if
(
!
rtp_socket
->
bindUdpSock
(
local_port
,
local_ip
,
enable_reuse
))
{
}
else
if
(
!
rtp_socket
->
bindUdpSock
(
local_port
,
local_ip
,
re_use_port
))
{
//用户指定端口
throw
std
::
runtime_error
(
StrPrinter
<<
"创建rtp端口 "
<<
local_ip
<<
":"
<<
local_port
<<
" 失败:"
<<
get_uv_errmsg
(
true
));
}
else
if
(
!
rtcp_socket
->
bindUdpSock
(
rtp_socket
->
get_local_port
()
+
1
,
local_ip
,
enable_reuse
))
{
}
else
if
(
!
rtcp_socket
->
bindUdpSock
(
rtp_socket
->
get_local_port
()
+
1
,
local_ip
,
re_use_port
))
{
// rtcp端口
throw
std
::
runtime_error
(
StrPrinter
<<
"创建rtcp端口 "
<<
local_ip
<<
":"
<<
local_port
<<
" 失败:"
<<
get_uv_errmsg
(
true
));
}
...
...
src/Rtp/RtpServer.h
查看文件 @
a6e82799
...
...
@@ -37,8 +37,9 @@ public:
* @param stream_id 流id,置空则使用ssrc
* @param enable_tcp 是否启用tcp服务器
* @param local_ip 绑定的本地网卡ip
* @param re_use_port 是否设置socket为re_use属性
*/
void
start
(
uint16_t
local_port
,
const
std
::
string
&
stream_id
=
""
,
bool
enable_tcp
=
true
,
const
char
*
local_ip
=
"0.0.0.0"
,
bool
enable_reuse
=
true
);
void
start
(
uint16_t
local_port
,
const
std
::
string
&
stream_id
=
""
,
bool
enable_tcp
=
true
,
const
char
*
local_ip
=
"0.0.0.0"
,
bool
re_use_port
=
true
);
/**
* 获取绑定的本地端口
...
...
src/Rtsp/Rtsp.cpp
查看文件 @
a6e82799
...
...
@@ -384,7 +384,7 @@ public:
return
*
instance
;
}
void
bindUdpSock
(
std
::
pair
<
Socket
::
Ptr
,
Socket
::
Ptr
>
&
pair
,
const
string
&
local_ip
)
{
void
bindUdpSock
(
std
::
pair
<
Socket
::
Ptr
,
Socket
::
Ptr
>
&
pair
,
const
string
&
local_ip
,
bool
re_use_port
)
{
auto
&
sock0
=
pair
.
first
;
auto
&
sock1
=
pair
.
second
;
auto
sock_pair
=
getPortPair
();
...
...
@@ -392,12 +392,12 @@ public:
throw
runtime_error
(
"none reserved udp port in pool"
);
}
if
(
!
sock0
->
bindUdpSock
(
2
*
*
sock_pair
,
local_ip
.
data
(),
false
))
{
if
(
!
sock0
->
bindUdpSock
(
2
*
*
sock_pair
,
local_ip
.
data
(),
re_use_port
))
{
//分配端口失败
throw
runtime_error
(
"open udp socket[0] failed"
);
}
if
(
!
sock1
->
bindUdpSock
(
2
*
*
sock_pair
+
1
,
local_ip
.
data
(),
false
))
{
if
(
!
sock1
->
bindUdpSock
(
2
*
*
sock_pair
+
1
,
local_ip
.
data
(),
re_use_port
))
{
//分配端口失败
throw
runtime_error
(
"open udp socket[1] failed"
);
}
...
...
@@ -445,18 +445,14 @@ private:
deque
<
uint16_t
>
_port_pair_pool
;
};
static
void
makeSockPair_l
(
std
::
pair
<
Socket
::
Ptr
,
Socket
::
Ptr
>
&
pair
,
const
string
&
local_ip
)
{
PortManager
::
Instance
().
bindUdpSock
(
pair
,
local_ip
);
}
void
makeSockPair
(
std
::
pair
<
Socket
::
Ptr
,
Socket
::
Ptr
>
&
pair
,
const
string
&
local_ip
)
{
void
makeSockPair
(
std
::
pair
<
Socket
::
Ptr
,
Socket
::
Ptr
>
&
pair
,
const
string
&
local_ip
,
bool
re_use_port
)
{
//全局互斥锁保护,防止端口重复分配
static
recursive_mutex
s_mtx
;
lock_guard
<
recursive_mutex
>
lck
(
s_mtx
);
int
try_count
=
0
;
while
(
true
)
{
try
{
makeSockPair_l
(
pair
,
local_ip
);
PortManager
::
Instance
().
bindUdpSock
(
pair
,
local_ip
,
re_use_port
);
break
;
}
catch
(
exception
&
ex
)
{
if
(
++
try_count
==
3
)
{
...
...
src/Rtsp/Rtsp.h
查看文件 @
a6e82799
...
...
@@ -378,7 +378,7 @@ private:
//创建rtp over tcp4个字节的头
toolkit
::
Buffer
::
Ptr
makeRtpOverTcpPrefix
(
uint16_t
size
,
uint8_t
interleaved
);
//创建rtp-rtcp端口对
void
makeSockPair
(
std
::
pair
<
toolkit
::
Socket
::
Ptr
,
toolkit
::
Socket
::
Ptr
>
&
pair
,
const
std
::
string
&
local_ip
);
void
makeSockPair
(
std
::
pair
<
toolkit
::
Socket
::
Ptr
,
toolkit
::
Socket
::
Ptr
>
&
pair
,
const
std
::
string
&
local_ip
,
bool
re_use_port
=
false
);
//十六进制方式打印ssrc
std
::
string
printSSRC
(
uint32_t
ui32Ssrc
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论