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
fde6b436
Commit
fde6b436
authored
Jun 22, 2022
by
baiyfcu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
封装rtp server创建和关闭
parent
90305475
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
41 行增加
和
22 行删除
+41
-22
api/tests/h264_media_server.c
+1
-0
server/WebApi.cpp
+37
-22
server/WebApi.h
+3
-0
没有找到文件。
api/tests/h264_media_server.c
查看文件 @
fde6b436
...
...
@@ -10,6 +10,7 @@
#include <signal.h>
#include <string.h>
#include <stdio.h>
#ifdef _WIN32
#include "windows.h"
#else
...
...
server/WebApi.cpp
查看文件 @
fde6b436
...
...
@@ -368,6 +368,38 @@ Value makeMediaSourceJson(MediaSource &media){
return
item
;
}
uint16_t
openRtpServer
(
uint16_t
local_port
,
const
string
&
stream_id
,
bool
enable_tcp
,
const
string
&
local_ip
,
bool
re_use_port
,
uint32_t
ssrc
)
{
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
if
(
s_rtpServerMap
.
find
(
stream_id
)
!=
s_rtpServerMap
.
end
())
{
//为了防止RtpProcess所有权限混乱的问题,不允许重复添加相同的stream_id
return
0
;
}
RtpServer
::
Ptr
server
=
std
::
make_shared
<
RtpServer
>
();
server
->
start
(
local_port
,
stream_id
,
enable_tcp
,
local_ip
.
c_str
(),
re_use_port
,
ssrc
);
server
->
setOnDetach
([
stream_id
]()
{
//设置rtp超时移除事件
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
s_rtpServerMap
.
erase
(
stream_id
);
});
//保存对象
s_rtpServerMap
.
emplace
(
stream_id
,
server
);
//回复json
return
server
->
getPort
();
}
bool
closeRtpServer
(
const
string
&
stream_id
)
{
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
auto
it
=
s_rtpServerMap
.
find
(
stream_id
);
if
(
it
==
s_rtpServerMap
.
end
())
{
return
false
;
}
auto
server
=
it
->
second
;
s_rtpServerMap
.
erase
(
it
);
return
true
;
}
void
getStatisticJson
(
const
function
<
void
(
Value
&
val
)
>
&
cb
)
{
auto
obj
=
std
::
make_shared
<
Value
>
(
objectValue
);
auto
&
val
=
*
obj
;
...
...
@@ -1056,40 +1088,23 @@ void installWebApi() {
CHECK_SECRET
();
CHECK_ARGS
(
"port"
,
"enable_tcp"
,
"stream_id"
);
auto
stream_id
=
allArgs
[
"stream_id"
];
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
if
(
s_rtpServerMap
.
find
(
stream_id
)
!=
s_rtpServerMap
.
end
())
{
//为了防止RtpProcess所有权限混乱的问题,不允许重复添加相同的stream_id
auto
port
=
openRtpServer
(
allArgs
[
"port"
],
stream_id
,
allArgs
[
"enable_tcp"
].
as
<
bool
>
(),
"::"
,
allArgs
[
"re_use_port"
].
as
<
bool
>
(),
allArgs
[
"ssrc"
].
as
<
uint32_t
>
());
if
(
port
==
0
)
{
throw
InvalidArgsException
(
"该stream_id已存在"
);
}
RtpServer
::
Ptr
server
=
std
::
make_shared
<
RtpServer
>
();
server
->
start
(
allArgs
[
"port"
],
stream_id
,
allArgs
[
"enable_tcp"
].
as
<
bool
>
(),
"::"
,
allArgs
[
"re_use_port"
].
as
<
bool
>
(),
allArgs
[
"ssrc"
].
as
<
uint32_t
>
());
server
->
setOnDetach
([
stream_id
]()
{
//设置rtp超时移除事件
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
s_rtpServerMap
.
erase
(
stream_id
);
});
//保存对象
s_rtpServerMap
.
emplace
(
stream_id
,
server
);
//回复json
val
[
"port"
]
=
server
->
getPort
()
;
val
[
"port"
]
=
port
;
});
api_regist
(
"/index/api/closeRtpServer"
,[](
API_ARGS_MAP
){
CHECK_SECRET
();
CHECK_ARGS
(
"stream_id"
);
lock_guard
<
recursive_mutex
>
lck
(
s_rtpServerMapMtx
);
auto
it
=
s_rtpServerMap
.
find
(
allArgs
[
"stream_id"
]);
if
(
it
==
s_rtpServerMap
.
end
()){
if
(
!
closeRtpServer
(
allArgs
[
"stream_id"
])){
val
[
"hit"
]
=
0
;
return
;
}
auto
server
=
it
->
second
;
s_rtpServerMap
.
erase
(
it
);
val
[
"hit"
]
=
1
;
});
...
...
server/WebApi.h
查看文件 @
fde6b436
...
...
@@ -230,6 +230,9 @@ bool checkArgs(Args &args, const First &first, const KeyTypes &...keys) {
void
installWebApi
();
void
unInstallWebApi
();
uint16_t
openRtpServer
(
uint16_t
local_port
,
const
std
::
string
&
stream_id
,
bool
enable_tcp
,
const
std
::
string
&
local_ip
,
bool
re_use_port
,
uint32_t
ssrc
);
bool
closeRtpServer
(
const
std
::
string
&
stream_id
);
Json
::
Value
makeMediaSourceJson
(
mediakit
::
MediaSource
&
media
);
void
getStatisticJson
(
const
std
::
function
<
void
(
Json
::
Value
&
val
)
>
&
cb
);
void
addStreamProxy
(
const
std
::
string
&
vhost
,
const
std
::
string
&
app
,
const
std
::
string
&
stream
,
const
std
::
string
&
url
,
int
retry_count
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论