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
fb003714
Commit
fb003714
authored
May 04, 2022
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增webrtc datachannel功能: #1216
parent
200a193c
全部展开
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
245 行增加
和
8 行删除
+245
-8
CMakeLists.txt
+16
-7
cmake/FindSCTP.cmake
+24
-0
webrtc/SctpAssociation.cpp
+0
-0
webrtc/SctpAssociation.hpp
+142
-0
webrtc/WebRtcTransport.cpp
+43
-0
webrtc/WebRtcTransport.h
+20
-1
没有找到文件。
CMakeLists.txt
查看文件 @
fb003714
...
...
@@ -176,13 +176,13 @@ endif ()
set
(
LINK_LIB_LIST zlmediakit zltoolkit
)
#默认链接jemalloc库避免内存碎片
find_package
(
JEMALLOC QUIET
)
if
(
JEMALLOC_FOUND
)
message
(
STATUS
"found library:
\"
${
JEMALLOC_LIBRARIES
}
\"
"
)
include_directories
(
${
JEMALLOC_INCLUDE_DIR
}
)
list
(
APPEND LINK_LIB_LIST
${
JEMALLOC_LIBRARIES
}
)
endif
()
#
#
默认链接jemalloc库避免内存碎片
#
find_package(JEMALLOC QUIET)
#
if (JEMALLOC_FOUND)
#
message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"")
#
include_directories(${JEMALLOC_INCLUDE_DIR})
#
list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES})
#
endif ()
#查找openssl是否安装
find_package
(
OpenSSL QUIET
)
...
...
@@ -351,6 +351,15 @@ if (ENABLE_WEBRTC)
add_library
(
webrtc
${
SRC_WEBRTC_LIST
}
)
list
(
APPEND LINK_LIB_LIST webrtc
)
message
(
STATUS
"webrtc功能已开启"
)
find_package
(
SCTP QUIET
)
if
(
SCTP_FOUND
)
message
(
STATUS
"found library:
${
SCTP_INCLUDE_DIRS
}
${
SCTP_LIBRARIES
}
"
)
include_directories
(
${
SCTP_INCLUDE_DIRS
}
)
list
(
APPEND LINK_LIB_LIST
${
SCTP_LIBRARIES
}
)
add_definitions
(
-DENABLE_SCTP
)
message
(
STATUS
"webrtc datachannel功能已打开"
)
endif
()
else
()
set
(
ENABLE_WEBRTC off
)
message
(
WARNING
"srtp未找到, webrtc相关功能打开失败"
)
...
...
cmake/FindSCTP.cmake
0 → 100644
查看文件 @
fb003714
# - Try to find sctp
#
# Once done this will define
# SCTP_FOUND - System has mbedtls
# SCTP_INCLUDE_DIRS - The mbedtls include directories
# SCTP_LIBRARIES - The mbedtls library
#find Mbedtls
FIND_PATH
(
SCTP_INCLUDE_DIRS
NAMES usrsctp.h
)
FIND_LIBRARY
(
SCTP_LIBRARIES
NAMES usrsctp
)
message
(
STATUS
"SCTP LIBRARIES: "
${
SCTP_LIBRARIES
}
)
message
(
STATUS
"SCTP INCLUDE DIRS: "
${
SCTP_INCLUDE_DIRS
}
)
INCLUDE
(
FindPackageHandleStandardArgs
)
FIND_PACKAGE_HANDLE_STANDARD_ARGS
(
SCTP DEFAULT_MSG SCTP_LIBRARIES SCTP_INCLUDE_DIRS
)
webrtc/SctpAssociation.cpp
0 → 100644
查看文件 @
fb003714
差异被折叠。
点击展开。
webrtc/SctpAssociation.hpp
0 → 100644
查看文件 @
fb003714
#ifndef MS_RTC_SCTP_ASSOCIATION_HPP
#define MS_RTC_SCTP_ASSOCIATION_HPP
#ifdef ENABLE_SCTP
#include <usrsctp.h>
#include "Utils.hpp"
#include "Poller/EventPoller.h"
namespace
RTC
{
class
SctpEnv
;
class
SctpStreamParameters
{
public
:
uint16_t
streamId
{
0u
};
bool
ordered
{
true
};
uint16_t
maxPacketLifeTime
{
0u
};
uint16_t
maxRetransmits
{
0u
};
};
class
SctpAssociation
{
public
:
enum
class
SctpState
{
NEW
=
1
,
CONNECTING
,
CONNECTED
,
FAILED
,
CLOSED
};
private
:
enum
class
StreamDirection
{
INCOMING
=
1
,
OUTGOING
};
public
:
class
Listener
{
public
:
virtual
void
OnSctpAssociationConnecting
(
RTC
::
SctpAssociation
*
sctpAssociation
)
=
0
;
virtual
void
OnSctpAssociationConnected
(
RTC
::
SctpAssociation
*
sctpAssociation
)
=
0
;
virtual
void
OnSctpAssociationFailed
(
RTC
::
SctpAssociation
*
sctpAssociation
)
=
0
;
virtual
void
OnSctpAssociationClosed
(
RTC
::
SctpAssociation
*
sctpAssociation
)
=
0
;
virtual
void
OnSctpAssociationSendData
(
RTC
::
SctpAssociation
*
sctpAssociation
,
const
uint8_t
*
data
,
size_t
len
)
=
0
;
virtual
void
OnSctpAssociationMessageReceived
(
RTC
::
SctpAssociation
*
sctpAssociation
,
uint16_t
streamId
,
uint32_t
ppid
,
const
uint8_t
*
msg
,
size_t
len
)
=
0
;
};
public
:
static
bool
IsSctp
(
const
uint8_t
*
data
,
size_t
len
)
{
// clang-format off
return
(
(
len
>=
12
)
&&
// Must have Source Port Number and Destination Port Number set to 5000 (hack).
(
Utils
::
Byte
::
Get2Bytes
(
data
,
0
)
==
5000
)
&&
(
Utils
::
Byte
::
Get2Bytes
(
data
,
2
)
==
5000
)
);
// clang-format on
}
public
:
SctpAssociation
(
Listener
*
listener
,
uint16_t
os
,
uint16_t
mis
,
size_t
maxSctpMessageSize
,
bool
isDataChannel
);
virtual
~
SctpAssociation
();
public
:
void
TransportConnected
();
size_t
GetMaxSctpMessageSize
()
const
{
return
this
->
maxSctpMessageSize
;
}
SctpState
GetState
()
const
{
return
this
->
state
;
}
void
ProcessSctpData
(
const
uint8_t
*
data
,
size_t
len
);
void
SendSctpMessage
(
const
RTC
::
SctpStreamParameters
&
params
,
uint32_t
ppid
,
const
uint8_t
*
msg
,
size_t
len
);
void
HandleDataConsumer
(
const
RTC
::
SctpStreamParameters
&
params
);
void
DataProducerClosed
(
const
RTC
::
SctpStreamParameters
&
params
);
void
DataConsumerClosed
(
const
RTC
::
SctpStreamParameters
&
params
);
private
:
void
ResetSctpStream
(
uint16_t
streamId
,
StreamDirection
);
void
AddOutgoingStreams
(
bool
force
=
false
);
public
:
/* Callbacks fired by usrsctp events. */
virtual
void
OnUsrSctpSendSctpData
(
void
*
buffer
,
size_t
len
);
virtual
void
OnUsrSctpReceiveSctpData
(
uint16_t
streamId
,
uint16_t
ssn
,
uint32_t
ppid
,
int
flags
,
const
uint8_t
*
data
,
size_t
len
);
virtual
void
OnUsrSctpReceiveSctpNotification
(
union
sctp_notification
*
notification
,
size_t
len
);
private
:
// Passed by argument.
Listener
*
listener
{
nullptr
};
uint16_t
os
{
1024u
};
uint16_t
mis
{
1024u
};
size_t
maxSctpMessageSize
{
262144u
};
bool
isDataChannel
{
false
};
// Allocated by this.
uint8_t
*
messageBuffer
{
nullptr
};
// Others.
SctpState
state
{
SctpState
::
NEW
};
struct
socket
*
socket
{
nullptr
};
uint16_t
desiredOs
{
0u
};
size_t
messageBufferLen
{
0u
};
uint16_t
lastSsnReceived
{
0u
};
// Valid for us since no SCTP I-DATA support.
std
::
shared_ptr
<
SctpEnv
>
_env
;
};
//保证线程安全
class
SctpAssociationImp
:
public
SctpAssociation
,
public
std
::
enable_shared_from_this
<
SctpAssociationImp
>
{
public
:
using
Ptr
=
std
::
shared_ptr
<
SctpAssociationImp
>
;
template
<
typename
...
ARGS
>
SctpAssociationImp
(
toolkit
::
EventPoller
::
Ptr
poller
,
ARGS
&&
...
args
)
:
SctpAssociation
(
std
::
forward
<
ARGS
>
(
args
)...)
{
_poller
=
std
::
move
(
poller
);
}
~
SctpAssociationImp
()
override
=
default
;
protected
:
void
OnUsrSctpSendSctpData
(
void
*
buffer
,
size_t
len
)
override
;
void
OnUsrSctpReceiveSctpData
(
uint16_t
streamId
,
uint16_t
ssn
,
uint32_t
ppid
,
int
flags
,
const
uint8_t
*
data
,
size_t
len
)
override
;
void
OnUsrSctpReceiveSctpNotification
(
union
sctp_notification
*
notification
,
size_t
len
)
override
;
private
:
toolkit
::
EventPoller
::
Ptr
_poller
;
};
}
// namespace RTC
#endif //ENABLE_SCTP
#endif //MS_RTC_SCTP_ASSOCIATION_HPP
webrtc/WebRtcTransport.cpp
查看文件 @
fb003714
...
...
@@ -60,6 +60,9 @@ void WebRtcTransport::onCreate(){
}
void
WebRtcTransport
::
onDestory
(){
#ifdef ENABLE_SCTP
_sctp
=
nullptr
;
#endif
_dtls_transport
=
nullptr
;
_ice_server
=
nullptr
;
}
...
...
@@ -112,6 +115,10 @@ void WebRtcTransport::OnDtlsTransportConnected(
InfoL
;
_srtp_session_send
=
std
::
make_shared
<
RTC
::
SrtpSession
>
(
RTC
::
SrtpSession
::
Type
::
OUTBOUND
,
srtpCryptoSuite
,
srtpLocalKey
,
srtpLocalKeyLen
);
_srtp_session_recv
=
std
::
make_shared
<
RTC
::
SrtpSession
>
(
RTC
::
SrtpSession
::
Type
::
INBOUND
,
srtpCryptoSuite
,
srtpRemoteKey
,
srtpRemoteKeyLen
);
#ifdef ENABLE_SCTP
_sctp
=
std
::
make_shared
<
RTC
::
SctpAssociationImp
>
(
getPoller
(),
this
,
128
,
128
,
262144
,
true
);
_sctp
->
TransportConnected
();
#endif
onStartWebRTC
();
}
...
...
@@ -134,8 +141,44 @@ void WebRtcTransport::OnDtlsTransportClosed(const RTC::DtlsTransport *dtlsTransp
}
void
WebRtcTransport
::
OnDtlsTransportApplicationDataReceived
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
{
#ifdef ENABLE_SCTP
_sctp
->
ProcessSctpData
(
data
,
len
);
#else
InfoL
<<
hexdump
(
data
,
len
);
#endif
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef ENABLE_SCTP
void
WebRtcTransport
::
OnSctpAssociationConnecting
(
RTC
::
SctpAssociation
*
sctpAssociation
)
{
TraceL
;
}
void
WebRtcTransport
::
OnSctpAssociationConnected
(
RTC
::
SctpAssociation
*
sctpAssociation
)
{
InfoL
<<
getIdentifier
();
}
void
WebRtcTransport
::
OnSctpAssociationFailed
(
RTC
::
SctpAssociation
*
sctpAssociation
)
{
WarnL
<<
getIdentifier
();
}
void
WebRtcTransport
::
OnSctpAssociationClosed
(
RTC
::
SctpAssociation
*
sctpAssociation
)
{
InfoL
<<
getIdentifier
();
}
void
WebRtcTransport
::
OnSctpAssociationSendData
(
RTC
::
SctpAssociation
*
sctpAssociation
,
const
uint8_t
*
data
,
size_t
len
)
{
_dtls_transport
->
SendApplicationData
(
data
,
len
);
}
void
WebRtcTransport
::
OnSctpAssociationMessageReceived
(
RTC
::
SctpAssociation
*
sctpAssociation
,
uint16_t
streamId
,
uint32_t
ppid
,
const
uint8_t
*
msg
,
size_t
len
)
{
InfoL
<<
getIdentifier
()
<<
" "
<<
streamId
<<
" "
<<
ppid
<<
" "
<<
len
<<
" "
<<
string
((
char
*
)
msg
,
len
);
RTC
::
SctpStreamParameters
params
;
params
.
streamId
=
streamId
;
//回显数据
_sctp
->
SendSctpMessage
(
params
,
ppid
,
msg
,
len
);
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
WebRtcTransport
::
sendSockData
(
const
char
*
buf
,
size_t
len
,
RTC
::
TransportTuple
*
tuple
){
...
...
webrtc/WebRtcTransport.h
查看文件 @
fb003714
...
...
@@ -25,6 +25,7 @@
#include "Nack.h"
#include "Network/Session.h"
#include "TwccContext.h"
#include "SctpAssociation.hpp"
//RTC配置项目
namespace
RTC
{
...
...
@@ -56,7 +57,11 @@ private:
SockException
_ex
;
};
class
WebRtcTransport
:
public
WebRtcInterface
,
public
RTC
::
DtlsTransport
::
Listener
,
public
RTC
::
IceServer
::
Listener
,
public
std
::
enable_shared_from_this
<
WebRtcTransport
>
{
class
WebRtcTransport
:
public
WebRtcInterface
,
public
RTC
::
DtlsTransport
::
Listener
,
public
RTC
::
IceServer
::
Listener
,
public
std
::
enable_shared_from_this
<
WebRtcTransport
>
#ifdef ENABLE_SCTP
,
public
RTC
::
SctpAssociation
::
Listener
#endif
{
public
:
using
Ptr
=
std
::
shared_ptr
<
WebRtcTransport
>
;
WebRtcTransport
(
const
EventPoller
::
Ptr
&
poller
);
...
...
@@ -128,6 +133,16 @@ protected:
void
OnIceServerCompleted
(
const
RTC
::
IceServer
*
iceServer
)
override
;
void
OnIceServerDisconnected
(
const
RTC
::
IceServer
*
iceServer
)
override
;
#ifdef ENABLE_SCTP
void
OnSctpAssociationConnecting
(
RTC
::
SctpAssociation
*
sctpAssociation
)
override
;
void
OnSctpAssociationConnected
(
RTC
::
SctpAssociation
*
sctpAssociation
)
override
;
void
OnSctpAssociationFailed
(
RTC
::
SctpAssociation
*
sctpAssociation
)
override
;
void
OnSctpAssociationClosed
(
RTC
::
SctpAssociation
*
sctpAssociation
)
override
;
void
OnSctpAssociationSendData
(
RTC
::
SctpAssociation
*
sctpAssociation
,
const
uint8_t
*
data
,
size_t
len
)
override
;
void
OnSctpAssociationMessageReceived
(
RTC
::
SctpAssociation
*
sctpAssociation
,
uint16_t
streamId
,
uint32_t
ppid
,
const
uint8_t
*
msg
,
size_t
len
)
override
;
#endif
protected
:
virtual
void
onStartWebRTC
()
=
0
;
virtual
void
onRtcConfigure
(
RtcConfigure
&
configure
)
const
;
...
...
@@ -163,6 +178,10 @@ private:
Ticker
_ticker
;
//循环池
ResourcePool
<
BufferRaw
>
_packet_pool
;
#ifdef ENABLE_SCTP
RTC
::
SctpAssociationImp
::
Ptr
_sctp
;
#endif
};
class
RtpChannel
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论