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
b96052d3
Commit
b96052d3
authored
Apr 07, 2021
by
xia-chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善rtc异常管理
parent
d354c946
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
65 行增加
和
10 行删除
+65
-10
server/WebApi.cpp
+0
-3
webrtc/WebRtcTransport.cpp
+54
-2
webrtc/WebRtcTransport.h
+11
-5
没有找到文件。
server/WebApi.cpp
查看文件 @
b96052d3
...
...
@@ -1081,7 +1081,6 @@ void installWebApi() {
});
#ifdef ENABLE_WEBRTC
static
list
<
WebRtcTransportImp
::
Ptr
>
rtcs
;
api_regist
(
"/index/api/webrtc"
,[](
API_ARGS_STRING_ASYNC
){
CHECK_ARGS
(
"app"
,
"stream"
);
...
...
@@ -1108,7 +1107,6 @@ void installWebApi() {
rtc
->
attach
(
src
,
true
);
val
[
"sdp"
]
=
rtc
->
getAnswerSdp
(
offer_sdp
);
val
[
"type"
]
=
"answer"
;
rtcs
.
emplace_back
(
rtc
);
invoker
(
200
,
headerOut
,
val
.
toStyledString
());
}
catch
(
std
::
exception
&
ex
)
{
val
[
"code"
]
=
API
::
Exception
;
...
...
@@ -1142,7 +1140,6 @@ void installWebApi() {
rtc
->
attach
(
push_src
,
false
);
val
[
"sdp"
]
=
rtc
->
getAnswerSdp
(
offer_sdp
);
val
[
"type"
]
=
"answer"
;
rtcs
.
emplace_back
(
rtc
);
invoker
(
200
,
headerOut
,
val
.
toStyledString
());
}
catch
(
std
::
exception
&
ex
)
{
val
[
"code"
]
=
API
::
Exception
;
...
...
webrtc/WebRtcTransport.cpp
查看文件 @
b96052d3
...
...
@@ -6,6 +6,21 @@
#define RTP_CNAME "zlmediakit-rtp"
#define RTX_CNAME "zlmediakit-rtx"
//RTC配置项目
namespace
RTC
{
#define RTC_FIELD "rtc."
//rtp和rtcp接受超时时间
const
string
kTimeOutSec
=
RTC_FIELD
"timeoutSec"
;
//服务器外网ip
const
string
kExternIP
=
RTC_FIELD
"externIP"
;
static
onceToken
token
([]()
{
mINI
::
Instance
()[
kTimeOutSec
]
=
15
;
mINI
::
Instance
()[
kExternIP
]
=
""
;
});
}
//namespace RTC
WebRtcTransport
::
WebRtcTransport
(
const
EventPoller
::
Ptr
&
poller
)
{
_poller
=
poller
;
_dtls_transport
=
std
::
make_shared
<
RTC
::
DtlsTransport
>
(
poller
,
this
);
...
...
@@ -72,6 +87,23 @@ void WebRtcTransport::OnDtlsTransportSendData(const RTC::DtlsTransport *dtlsTran
onSendSockData
((
char
*
)
data
,
len
);
}
void
WebRtcTransport
::
OnDtlsTransportConnecting
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
{
InfoL
;
}
void
WebRtcTransport
::
OnDtlsTransportFailed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
{
InfoL
;
onShutdown
(
SockException
(
Err_shutdown
,
"dtls transport failed"
));
}
void
WebRtcTransport
::
OnDtlsTransportClosed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
{
InfoL
;
onShutdown
(
SockException
(
Err_shutdown
,
"dtls close notify received"
));
}
void
WebRtcTransport
::
OnDtlsTransportApplicationDataReceived
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
{
InfoL
<<
hexdump
(
data
,
len
);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void
WebRtcTransport
::
onSendSockData
(
const
char
*
buf
,
size_t
len
,
bool
flush
){
...
...
@@ -228,10 +260,27 @@ void WebRtcTransportImp::onCreate(){
strong_self
->
inputSockData
(
buf
->
data
(),
buf
->
size
(),
addr
);
}
});
_self
=
shared_from_this
();
GET_CONFIG
(
float
,
timeoutSec
,
RTC
::
kTimeOutSec
);
_timer
=
std
::
make_shared
<
Timer
>
(
timeoutSec
/
2
,
[
weak_self
]()
{
auto
strong_self
=
weak_self
.
lock
();
if
(
!
strong_self
)
{
return
false
;
}
if
(
strong_self
->
_alive_ticker
.
elapsedTime
()
>
timeoutSec
*
1000
)
{
strong_self
->
onShutdown
(
SockException
(
Err_timeout
,
"接受rtp和rtcp超时"
));
}
return
true
;
},
getPoller
());
}
WebRtcTransportImp
::
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
)
:
WebRtcTransport
(
poller
)
{
InfoL
<<
this
;
}
WebRtcTransportImp
::~
WebRtcTransportImp
()
{
InfoL
<<
this
;
}
void
WebRtcTransportImp
::
onDestory
()
{
...
...
@@ -367,8 +416,8 @@ SdpAttrCandidate::Ptr WebRtcTransportImp::getIceCandidate() const{
candidate
->
transport
=
"udp"
;
//优先级,单candidate时随便
candidate
->
priority
=
100
;
//todo 此处修改为配置文件
candidate
->
address
=
SockUtil
::
get_local_ip
()
;
GET_CONFIG
(
string
,
extern_ip
,
RTC
::
kExternIP
);
candidate
->
address
=
extern_ip
.
empty
()
?
SockUtil
::
get_local_ip
()
:
extern_ip
;
candidate
->
port
=
_socket
->
get_local_port
();
candidate
->
type
=
"host"
;
return
candidate
;
...
...
@@ -421,6 +470,7 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
break
;
}
case
RtcpType
:
:
RTCP_RR
:
{
_alive_ticker
.
resetTime
();
//对方汇报rtp接收情况
RtcpRR
*
rr
=
(
RtcpRR
*
)
rtcp
;
auto
it
=
_rtp_info_ssrc
.
find
(
rr
->
ssrc
);
...
...
@@ -454,6 +504,7 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
}
void
WebRtcTransportImp
::
onRtp
(
const
char
*
buf
,
size_t
len
)
{
_alive_ticker
.
resetTime
();
RtpHeader
*
rtp
=
(
RtpHeader
*
)
buf
;
//根据接收到的rtp的pt信息,找到该流的信息
auto
it
=
_rtp_info_pt
.
find
(
rtp
->
pt
);
...
...
@@ -505,5 +556,6 @@ void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){
void
WebRtcTransportImp
::
onShutdown
(
const
SockException
&
ex
){
InfoL
<<
ex
.
what
();
_self
=
nullptr
;
}
webrtc/WebRtcTransport.h
查看文件 @
b96052d3
...
...
@@ -59,7 +59,7 @@ public:
protected
:
//// dtls相关的回调 ////
void
OnDtlsTransportConnecting
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
{}
;
void
OnDtlsTransportConnecting
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
;
void
OnDtlsTransportConnected
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuite
,
uint8_t
*
srtpLocalKey
,
...
...
@@ -68,10 +68,10 @@ protected:
size_t
srtpRemoteKeyLen
,
std
::
string
&
remoteCert
)
override
;
void
OnDtlsTransportFailed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
{}
;
void
OnDtlsTransportClosed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
{}
;
void
OnDtlsTransportFailed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
;
void
OnDtlsTransportClosed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
;
void
OnDtlsTransportSendData
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
void
OnDtlsTransportApplicationDataReceived
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
{}
;
void
OnDtlsTransportApplicationDataReceived
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
;
protected
:
//// ice相关的回调 ///
...
...
@@ -113,7 +113,7 @@ class RtpReceiverImp;
class
WebRtcTransportImp
:
public
WebRtcTransport
,
public
std
::
enable_shared_from_this
<
WebRtcTransportImp
>
{
public
:
using
Ptr
=
std
::
shared_ptr
<
WebRtcTransportImp
>
;
~
WebRtcTransportImp
()
override
=
default
;
~
WebRtcTransportImp
()
override
;
/**
* 创建WebRTC对象
...
...
@@ -162,6 +162,12 @@ private:
void
onBeforeSortedRtp
(
const
RtpPayloadInfo
&
info
,
const
RtpPacket
::
Ptr
&
rtp
);
private
:
//保持自我强引用
Ptr
_self
;
//检测超时的定时器
Timer
::
Ptr
_timer
;
//刷新计时器
Ticker
_alive_ticker
;
//pli rtcp计时器
Ticker
_pli_ticker
;
//rtc rtp推流的视频ssrc
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论