Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
30f9b95c
提交
30f9b95c
authored
12月 08, 2017
作者:
José Luis Millán
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
RtpMonitor
上级
3af445c0
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
260 行增加
和
0 行删除
+260
-0
RtpMonitor.hpp
worker/include/RTC/RtpMonitor.hpp
+52
-0
mediasoup-worker.gyp
worker/mediasoup-worker.gyp
+3
-0
RtpMonitor.cpp
worker/src/RTC/RtpMonitor.cpp
+83
-0
TestRtpMonitor.cpp
worker/test/RTC/TestRtpMonitor.cpp
+122
-0
没有找到文件。
worker/include/RTC/RtpMonitor.hpp
0 → 100644
浏览文件 @
30f9b95c
#ifndef MS_RTC_RTP_MONITOR_HPP
#define MS_RTC_RTP_MONITOR_HPP
#include "common.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include <vector>
namespace
RTC
{
class
RtpMonitor
{
public
:
class
Listener
{
public
:
virtual
void
OnRtpMonitorHealthy
()
=
0
;
virtual
void
OnRtpMonitorUnhealthy
()
=
0
;
};
RtpMonitor
(
Listener
*
listener
);
void
ReceiveRtcpReceiverReport
(
RTC
::
RTCP
::
ReceiverReport
*
report
);
bool
IsHealthy
()
const
;
void
Reset
();
private
:
void
AddScore
(
int8_t
score
);
bool
IsHealthyScore
(
int8_t
score
);
private
:
Listener
*
listener
{
nullptr
};
std
::
vector
<
int8_t
>
scores
;
bool
healthy
{
true
};
};
inline
bool
RtpMonitor
::
IsHealthy
()
const
{
return
this
->
healthy
;
}
inline
void
RtpMonitor
::
Reset
()
{
this
->
scores
.
clear
();
this
->
healthy
=
true
;
}
inline
bool
RtpMonitor
::
IsHealthyScore
(
int8_t
score
)
{
return
score
>=
0
;
}
}
// namespace RTC
#endif
worker/mediasoup-worker.gyp
浏览文件 @
30f9b95c
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
'src/RTC/Producer.cpp',
'src/RTC/Producer.cpp',
'src/RTC/Router.cpp',
'src/RTC/Router.cpp',
'src/RTC/RtpListener.cpp',
'src/RTC/RtpListener.cpp',
'src/RTC/RtpMonitor.cpp',
'src/RTC/RtpPacket.cpp',
'src/RTC/RtpPacket.cpp',
'src/RTC/RtpStream.cpp',
'src/RTC/RtpStream.cpp',
'src/RTC/RtpStreamRecv.cpp',
'src/RTC/RtpStreamRecv.cpp',
...
@@ -123,6 +124,7 @@
...
@@ -123,6 +124,7 @@
'include/RTC/Router.hpp',
'include/RTC/Router.hpp',
'include/RTC/RtpDictionaries.hpp',
'include/RTC/RtpDictionaries.hpp',
'include/RTC/RtpListener.hpp',
'include/RTC/RtpListener.hpp',
'include/RTC/RtpMonitor.hpp',
'include/RTC/RtpPacket.hpp',
'include/RTC/RtpPacket.hpp',
'include/RTC/RtpStream.hpp',
'include/RTC/RtpStream.hpp',
'include/RTC/RtpStreamRecv.hpp',
'include/RTC/RtpStreamRecv.hpp',
...
@@ -266,6 +268,7 @@
...
@@ -266,6 +268,7 @@
'test/RTC/TestNackGenerator.cpp',
'test/RTC/TestNackGenerator.cpp',
'test/RTC/TestRtpPacket.cpp',
'test/RTC/TestRtpPacket.cpp',
'test/RTC/TestRtpDataCounter.cpp',
'test/RTC/TestRtpDataCounter.cpp',
'test/RTC/TestRtpMonitor.cpp',
'test/RTC/TestRtpStreamRecv.cpp',
'test/RTC/TestRtpStreamRecv.cpp',
'test/RTC/TestSeqManager.cpp',
'test/RTC/TestSeqManager.cpp',
'test/RTC/Codecs/TestVP8.cpp',
'test/RTC/Codecs/TestVP8.cpp',
...
...
worker/src/RTC/RtpMonitor.cpp
0 → 100644
浏览文件 @
30f9b95c
#define MS_CLASS "RTC::RtpMonitor"
// #define MS_LOG_DEV
#include "RTC/RtpMonitor.hpp"
#include "Logger.hpp"
namespace
RTC
{
/* Static. */
static
constexpr
size_t
LossPercentageScoreRatio
{
2
};
static
constexpr
size_t
MaxScore
{
10
};
static
constexpr
size_t
HistogramLength
{
8
};
/* Instance methods. */
RtpMonitor
::
RtpMonitor
(
Listener
*
listener
)
:
listener
(
listener
)
{
MS_TRACE
();
}
void
RtpMonitor
::
ReceiveRtcpReceiverReport
(
RTC
::
RTCP
::
ReceiverReport
*
report
)
{
MS_TRACE
();
auto
fractionLost
=
report
->
GetFractionLost
();
auto
lossPercentage
=
static_cast
<
uint8_t
>
(
fractionLost
*
100
/
255
);
auto
score
=
MaxScore
-
static_cast
<
int8_t
>
(
lossPercentage
/
LossPercentageScoreRatio
);
this
->
AddScore
(
score
);
}
void
RtpMonitor
::
AddScore
(
int8_t
currentScore
)
{
MS_TRACE
();
auto
it
=
this
->
scores
.
crbegin
();
auto
lastScore
=
MaxScore
;
if
(
it
!=
this
->
scores
.
crend
())
{
lastScore
=
*
it
;
}
// Transitioning to unhealthy...
if
(
IsHealthyScore
(
lastScore
)
&&
!
IsHealthyScore
(
currentScore
))
{
this
->
scores
.
clear
();
this
->
scores
.
push_back
(
currentScore
);
}
// Transitioning to healthy...
else
if
(
!
IsHealthyScore
(
lastScore
)
&&
IsHealthyScore
(
currentScore
))
{
this
->
scores
.
clear
();
this
->
scores
.
push_back
(
currentScore
);
}
// HistogramLength healthy or unhealthy scores achieved. Notify listener.
else
if
(
this
->
scores
.
size
()
==
HistogramLength
-
1
)
{
this
->
scores
.
clear
();
this
->
scores
.
push_back
(
currentScore
);
if
(
IsHealthyScore
(
currentScore
))
{
this
->
healthy
=
true
;
this
->
listener
->
OnRtpMonitorHealthy
();
}
else
{
this
->
healthy
=
false
;
this
->
listener
->
OnRtpMonitorUnhealthy
();
}
}
else
{
this
->
scores
.
push_back
(
currentScore
);
}
}
}
// namespace RTC
worker/test/RTC/TestRtpMonitor.cpp
0 → 100644
浏览文件 @
30f9b95c
#include "common.hpp"
#include "catch.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RtpMonitor.hpp"
#include <cmath>
using
namespace
RTC
;
SCENARIO
(
"RTP Monitor"
,
"[rtp][monitor]"
)
{
class
TestRtpMonitorListener
:
public
RtpMonitor
::
Listener
{
public
:
virtual
void
OnHealthy
(
RTC
::
RtpMonitor
*
/*rtpMonitor*/
)
override
{
INFO
(
"OnHealthy"
);
this
->
healthyTriggered
=
true
;
}
virtual
void
OnUnhealthy
(
RTC
::
RtpMonitor
*
/*rtpMonitor*/
)
override
{
INFO
(
"OnUnhealthy"
);
this
->
unhealthyTriggered
=
true
;
}
void
Check
(
bool
shouldHaveTriggeredHealthy
,
bool
shouldHaveTriggeredUnhealthy
)
{
REQUIRE
(
shouldHaveTriggeredHealthy
==
this
->
healthyTriggered
);
REQUIRE
(
shouldHaveTriggeredUnhealthy
==
this
->
unhealthyTriggered
);
this
->
healthyTriggered
=
this
->
unhealthyTriggered
=
false
;
}
public
:
bool
healthyTriggered
=
false
;
bool
unhealthyTriggered
=
false
;
};
// RTCP Receiver Report Packet.
// clang-format off
uint8_t
buffer
[]
=
{
// Receiver Report
0x01
,
0x93
,
0x2d
,
0xb4
,
// SSRC. 0x01932db4
0x00
,
0x00
,
0x00
,
0x01
,
// Fraction lost: 0, Total lost: 1
0x00
,
0x00
,
0x00
,
0x00
,
// Extended highest sequence number: 0
0x00
,
0x00
,
0x00
,
0x00
,
// Jitter: 0
0x00
,
0x00
,
0x00
,
0x00
,
// Last SR: 0
0x00
,
0x00
,
0x00
,
0x05
// DLSR: 0
};
// clang-format on
RTCP
::
ReceiverReport
*
report
=
RTCP
::
ReceiverReport
::
Parse
(
buffer
,
sizeof
(
buffer
));
if
(
!
report
)
FAIL
(
"failed parsing RTCP::ReceiverReport"
);
SECTION
(
"Four consecutive bad reports trigger unhealthy state"
)
{
TestRtpMonitorListener
listener
;
RtpMonitor
rtpMonitor
(
&
listener
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
255
);
/* 100% */
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
listener
.
Check
(
false
,
true
);
SECTION
(
"Good report after unhealth triggers healty state"
)
{
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
report
->
SetFractionLost
(
0
);
rtpMonitor
.
ReceiveRtcpReceiverReport
(
report
);
listener
.
Check
(
true
,
false
);
}
}
delete
report
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论