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
2f9b3e18
Unverified
Commit
2f9b3e18
authored
Sep 23, 2022
by
夏楚
Committed by
GitHub
Sep 23, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1984 from Dw9/master
c api support srt server
parents
c363b303
43bf7c79
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
71 行增加
和
15 行删除
+71
-15
api/include/mk_common.h
+8
-1
api/source/mk_common.cpp
+42
-0
api/tests/server.c
+1
-0
server/main.cpp
+1
-4
srt/SrtTransport.cpp
+9
-0
www/webrtc/index.html
+10
-10
没有找到文件。
api/include/mk_common.h
查看文件 @
2f9b3e18
...
...
@@ -162,11 +162,18 @@ API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port);
/**
* 创建rtc服务器
* @param port rt
p
监听端口
* @param port rt
c
监听端口
* @return 0:失败,非0:端口号
*/
API_EXPORT
uint16_t
API_CALL
mk_rtc_server_start
(
uint16_t
port
);
/**
* 创建srt服务器
* @param port srt监听端口
* @return 0:失败,非0:端口号
*/
API_EXPORT
uint16_t
API_CALL
mk_srt_server_start
(
uint16_t
port
);
/**
* 创建shell服务器
...
...
api/source/mk_common.cpp
查看文件 @
2f9b3e18
...
...
@@ -40,6 +40,11 @@ static std::shared_ptr<RtpServer> rtpServer;
static
std
::
shared_ptr
<
UdpServer
>
rtcServer
;
#endif
#if defined(ENABLE_SRT)
#include "../srt/SrtSession.hpp"
static
std
::
shared_ptr
<
UdpServer
>
srtServer
;
#endif
//////////////////////////environment init///////////////////////////
API_EXPORT
void
API_CALL
mk_env_init
(
const
mk_config
*
cfg
)
{
...
...
@@ -62,9 +67,16 @@ API_EXPORT void API_CALL mk_stop_all_server(){
CLEAR_ARR
(
rtsp_server
);
CLEAR_ARR
(
rtmp_server
);
CLEAR_ARR
(
http_server
);
shell_server
=
nullptr
;
#ifdef ENABLE_RTPPROXY
rtpServer
=
nullptr
;
#endif
#ifdef ENABLE_WEBRTC
rtcServer
=
nullptr
;
#endif
#ifdef ENABLE_SRT
srtServer
=
nullptr
;
#endif
stopAllTcpServer
();
}
...
...
@@ -254,6 +266,36 @@ API_EXPORT uint16_t API_CALL mk_rtc_server_start(uint16_t port) {
#endif
}
API_EXPORT
uint16_t
API_CALL
mk_srt_server_start
(
uint16_t
port
)
{
#ifdef ENABLE_SRT
try
{
srtServer
=
std
::
make_shared
<
UdpServer
>
();
srtServer
->
setOnCreateSocket
([](
const
EventPoller
::
Ptr
&
poller
,
const
Buffer
::
Ptr
&
buf
,
struct
sockaddr
*
,
int
)
{
if
(
!
buf
)
{
return
Socket
::
createSocket
(
poller
,
false
);
}
auto
new_poller
=
SRT
::
SrtSession
::
queryPoller
(
buf
);
if
(
!
new_poller
)
{
//握手第一阶段
return
Socket
::
createSocket
(
poller
,
false
);
}
return
Socket
::
createSocket
(
new_poller
,
false
);
});
srtServer
->
start
<
SRT
::
SrtSession
>
(
port
);
return
srtServer
->
getPort
();
}
catch
(
std
::
exception
&
ex
)
{
srtServer
.
reset
();
WarnL
<<
ex
.
what
();
return
0
;
}
#else
WarnL
<<
"未启用该功能!"
;
return
0
;
#endif
}
API_EXPORT
uint16_t
API_CALL
mk_shell_server_start
(
uint16_t
port
){
try
{
shell_server
=
std
::
make_shared
<
TcpServer
>
();
...
...
api/tests/server.c
查看文件 @
2f9b3e18
...
...
@@ -416,6 +416,7 @@ int main(int argc, char *argv[]) {
mk_shell_server_start
(
9000
);
mk_rtp_server_start
(
10000
);
mk_rtc_server_start
(
8000
);
mk_srt_server_start
(
9000
);
mk_events
events
=
{
.
on_mk_media_changed
=
on_mk_media_changed
,
...
...
server/main.cpp
查看文件 @
2f9b3e18
...
...
@@ -336,12 +336,9 @@ int start_main(int argc,char *argv[]) {
if
(
rtcPort
)
{
rtcSrv
->
start
<
WebRtcSession
>
(
rtcPort
);
}
#endif//defined(ENABLE_WEBRTC)
#if defined(ENABLE_SRT)
// srt udp服务器
if
(
srtPort
){
srtSrv
->
start
<
SRT
::
SrtSession
>
(
srtPort
);
}
if
(
srtPort
)
{
srtSrv
->
start
<
SRT
::
SrtSession
>
(
srtPort
);
}
#endif//defined(ENABLE_SRT)
}
catch
(
std
::
exception
&
ex
)
{
...
...
srt/SrtTransport.cpp
查看文件 @
2f9b3e18
#
include
"Util/onceToken.h"
#include "Util/mini.h"
#include <iterator>
#include <stdlib.h>
...
...
@@ -15,6 +17,13 @@ const std::string kPort = SRT_FIELD "port";
const
std
::
string
kLatencyMul
=
SRT_FIELD
"latencyMul"
;
const
std
::
string
kPktBufSize
=
SRT_FIELD
"pktBufSize"
;
static
onceToken
token
([]()
{
mINI
::
Instance
()[
kTimeOutSec
]
=
5
;
mINI
::
Instance
()[
kPort
]
=
9000
;
mINI
::
Instance
()[
kLatencyMul
]
=
4
;
mINI
::
Instance
()[
kPktBufSize
]
=
8192
;
});
static
std
::
atomic
<
uint32_t
>
s_srt_socket_id_generate
{
125
};
//////////// SrtTransport //////////////////////////
SrtTransport
::
SrtTransport
(
const
EventPoller
::
Ptr
&
poller
)
...
...
www/webrtc/index.html
查看文件 @
2f9b3e18
...
...
@@ -46,14 +46,14 @@
</p>
<p>
<label
for=
"metho
nd"
>
methon
d(play or push or echo):
</label>
<input
type=
"radio"
name=
"metho
n
d"
value=
"echo"
>
echo
<input
type=
"radio"
name=
"metho
n
d"
value=
"push"
>
push
<input
type=
"radio"
name=
"metho
n
d"
value=
"play"
checked =
true
>
play
<label
for=
"metho
d"
>
metho
d(play or push or echo):
</label>
<input
type=
"radio"
name=
"method"
value=
"echo"
>
echo
<input
type=
"radio"
name=
"method"
value=
"push"
>
push
<input
type=
"radio"
name=
"method"
value=
"play"
checked =
true
>
play
</p>
<p>
<label
for=
"res
i
lution"
>
resolution:
</label>
<select
id=
"res
i
lution"
>
<label
for=
"res
o
lution"
>
resolution:
</label>
<select
id=
"res
o
lution"
>
</select>
</p>
<p>
...
...
@@ -98,7 +98,7 @@
url
=
"http://127.0.0.1"
+
"/index/api/webrtc?app=live&stream=test&type=play"
}
document
.
getElementById
(
'streamUrl'
).
value
=
url
document
.
getElementsByName
(
"metho
n
d"
).
forEach
((
el
,
idx
)
=>
{
document
.
getElementsByName
(
"method"
).
forEach
((
el
,
idx
)
=>
{
el
.
onclick
=
function
(
e
){
let
url
=
new
URL
(
document
.
getElementById
(
'streamUrl'
).
value
);
url
.
searchParams
.
set
(
"type"
,
el
.
value
)
...
...
@@ -118,14 +118,14 @@
opt
=
document
.
createElement
(
'option'
);
opt
.
text
=
r
.
label
+
"("
+
r
.
width
+
"x"
+
r
.
height
+
")"
;
opt
.
value
=
r
;
document
.
getElementById
(
"res
i
lution"
).
add
(
opt
,
null
)
document
.
getElementById
(
"res
o
lution"
).
add
(
opt
,
null
)
//console.log(opt.text.match(/\d+/g))
})
function
start_play
(){
let
elr
=
document
.
getElementById
(
"res
i
lution"
);
let
elr
=
document
.
getElementById
(
"res
o
lution"
);
let
res
=
elr
.
options
[
elr
.
selectedIndex
].
text
.
match
(
/
\d
+/g
);
let
h
=
parseInt
(
res
.
pop
());
let
w
=
parseInt
(
res
.
pop
());
...
...
@@ -204,7 +204,7 @@
function
start
()
{
stop
();
let
elr
=
document
.
getElementById
(
"res
i
lution"
);
let
elr
=
document
.
getElementById
(
"res
o
lution"
);
let
res
=
elr
.
options
[
elr
.
selectedIndex
].
text
.
match
(
/
\d
+/g
);
let
h
=
parseInt
(
res
.
pop
());
let
w
=
parseInt
(
res
.
pop
());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论