Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
2f8af638
提交
2f8af638
authored
4月 04, 2017
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Transport: trigger PLI if uplink bitrate abruptly decreases
上级
922152e7
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
201 行增加
和
57 行删除
+201
-57
Logger.hpp
worker/include/Logger.hpp
+12
-0
Peer.hpp
worker/include/RTC/Peer.hpp
+1
-0
RtpStreamRecv.hpp
worker/include/RTC/RtpStreamRecv.hpp
+0
-9
Transport.hpp
worker/include/RTC/Transport.hpp
+3
-0
Peer.cpp
worker/src/RTC/Peer.cpp
+24
-0
AimdRateControl.cpp
worker/src/RTC/RemoteBitrateEstimator/AimdRateControl.cpp
+11
-6
InterArrival.cpp
worker/src/RTC/RemoteBitrateEstimator/InterArrival.cpp
+8
-0
OveruseDetector.cpp
worker/src/RTC/RemoteBitrateEstimator/OveruseDetector.cpp
+2
-0
RemoteBitrateEstimatorAbsSendTime.cpp
...oteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.cpp
+55
-23
RemoteBitrateEstimatorSingleStream.cpp
...teBitrateEstimator/RemoteBitrateEstimatorSingleStream.cpp
+22
-11
RtpStreamRecv.cpp
worker/src/RTC/RtpStreamRecv.cpp
+20
-0
RtpStreamSend.cpp
worker/src/RTC/RtpStreamSend.cpp
+1
-1
Transport.cpp
worker/src/RTC/Transport.cpp
+42
-7
没有找到文件。
worker/include/Logger.hpp
浏览文件 @
2f8af638
...
...
@@ -16,6 +16,12 @@
* Logs the current method/function if MS_LOG_TRACE macro is defined and the
* current debug level is "debug".
*
* MS_HAS_DEBUG_TAG(tag)
* MS_HAS_WARN_TAG(tag)
*
* True if the current debug level is satisfied and the given tag is enabled
* (or if the current source file defines the MS_LOG_DEV macro).
*
* MS_DEBUG_TAG(tag, ...)
* MS_WARN_TAG(tag, ...)
*
...
...
@@ -152,6 +158,12 @@ public:
#define MS_TRACE_STD() ;
#endif
#define MS_HAS_DEBUG_TAG(tag) \
(LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED))
#define MS_HAS_WARN_TAG(tag) \
(LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED))
#define MS_DEBUG_TAG(tag, desc, ...) \
do \
{ \
...
...
worker/include/RTC/Peer.hpp
浏览文件 @
2f8af638
...
...
@@ -79,6 +79,7 @@ namespace RTC
virtual
void
onTransportConnected
(
RTC
::
Transport
*
transport
)
override
;
virtual
void
onTransportClosed
(
RTC
::
Transport
*
transport
)
override
;
virtual
void
onTransportRtcpPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTCP
::
Packet
*
packet
)
override
;
virtual
void
onTransportFullFrameRequired
(
RTC
::
Transport
*
transport
)
override
;
/* Pure virtual methods inherited from RTC::RtpReceiver::Listener. */
public
:
...
...
worker/include/RTC/RtpStreamRecv.hpp
浏览文件 @
2f8af638
...
...
@@ -52,15 +52,6 @@ namespace RTC
uint32_t
jitter
=
0
;
// Estimated jitter.
std
::
unique_ptr
<
RTC
::
NackGenerator
>
nackGenerator
;
};
/* Inline instance methods. */
inline
void
RtpStreamRecv
::
RequestFullFrame
()
{
if
(
this
->
params
.
usePli
)
this
->
listener
->
onPliRequired
(
this
);
}
}
#endif
worker/include/RTC/Transport.hpp
浏览文件 @
2f8af638
...
...
@@ -40,6 +40,7 @@ namespace RTC
virtual
void
onTransportConnected
(
RTC
::
Transport
*
transport
)
=
0
;
virtual
void
onTransportClosed
(
RTC
::
Transport
*
transport
)
=
0
;
virtual
void
onTransportRtcpPacket
(
RTC
::
Transport
*
transport
,
RTC
::
RTCP
::
Packet
*
packet
)
=
0
;
virtual
void
onTransportFullFrameRequired
(
RTC
::
Transport
*
transport
)
=
0
;
};
private
:
...
...
@@ -136,6 +137,8 @@ namespace RTC
// REMB and bitrate stuff.
std
::
unique_ptr
<
RemoteBitrateEstimatorAbsSendTime
>
remoteBitrateEstimator
;
uint32_t
maxBitrate
=
0
;
uint32_t
effectiveMaxBitrate
=
0
;
uint64_t
lastEffectiveMaxBitrateAt
=
0
;
};
/* Inline instance methods. */
...
...
worker/src/RTC/Peer.cpp
浏览文件 @
2f8af638
...
...
@@ -761,6 +761,30 @@ namespace RTC
this
->
transports
.
erase
(
transport
->
transportId
);
}
void
Peer
::
onTransportFullFrameRequired
(
RTC
::
Transport
*
transport
)
{
MS_TRACE
();
// If the transport is used by any RtpReceiver (video/depth) notify the
// listener.
for
(
auto
&
kv
:
this
->
rtpReceivers
)
{
RTC
::
RtpReceiver
*
rtpReceiver
=
kv
.
second
;
if
(
rtpReceiver
->
kind
!=
RTC
::
Media
::
Kind
::
VIDEO
&&
rtpReceiver
->
kind
!=
RTC
::
Media
::
Kind
::
DEPTH
)
{
continue
;
}
if
(
rtpReceiver
->
GetTransport
()
!=
transport
)
continue
;
rtpReceiver
->
RequestFullFrame
();
}
}
void
Peer
::
onRtpReceiverParameters
(
RTC
::
RtpReceiver
*
rtpReceiver
)
{
MS_TRACE
();
...
...
worker/src/RTC/RemoteBitrateEstimator/AimdRateControl.cpp
浏览文件 @
2f8af638
...
...
@@ -41,10 +41,10 @@ namespace RTC
MS_TRACE
();
const
int64_t
bitrateReductionInterval
=
std
::
max
<
int64_t
>
(
std
::
min
<
int64_t
>
(
this
->
rtt
,
200
),
10
);
if
(
timeNow
-
this
->
timeLastBitrateChange
>=
bitrateReductionInterval
)
{
return
true
;
}
if
(
ValidEstimate
())
{
// TODO(terelius/holmer): Investigate consequences of increasing
...
...
@@ -108,10 +108,10 @@ namespace RTC
double
avgPacketSizeBits
=
bitsPerFrame
/
packetsPerFrame
;
// Approximate the over-use estimator delay to 100 ms.
const
int64_t
responseTime
=
(
this
->
rtt
+
100
)
*
2
;
constexpr
double
kMinIncreaseRateBps
=
4000
;
return
static_cast
<
int
>
(
std
::
max
(
kMinIncreaseRateBps
,
(
avgPacketSizeBits
*
1000
)
/
responseTime
));
return
static_cast
<
int
>
(
std
::
max
(
kMinIncreaseRateBps
,
(
avgPacketSizeBits
*
1000
)
/
responseTime
));
}
uint32_t
AimdRateControl
::
ChangeBitrate
(
uint32_t
newBitrateBps
,
uint32_t
incomingBitrateBps
,
int64_t
nowMs
)
...
...
@@ -119,9 +119,7 @@ namespace RTC
MS_TRACE
();
if
(
!
this
->
updated
)
{
return
this
->
currentBitrateBps
;
}
// An over-use should always trigger us to reduce the bitrate, even though
// we have not yet established our first estimate. By acting on the over-use,
...
...
@@ -152,11 +150,13 @@ namespace RTC
if
(
this
->
rateControlRegion
==
kRcNearMax
)
{
uint32_t
additiveIncreaseBps
=
AdditiveRateIncrease
(
nowMs
,
this
->
timeLastBitrateChange
);
newBitrateBps
+=
additiveIncreaseBps
;
}
else
{
uint32_t
multiplicativeIncreaseBps
=
MultiplicativeRateIncrease
(
nowMs
,
this
->
timeLastBitrateChange
,
newBitrateBps
);
newBitrateBps
+=
multiplicativeIncreaseBps
;
}
...
...
@@ -168,6 +168,7 @@ namespace RTC
// Set bit rate to something slightly lower than max
// to get rid of any self-induced delay.
newBitrateBps
=
static_cast
<
uint32_t
>
(
this
->
beta
*
incomingBitrateBps
+
0.5
);
if
(
newBitrateBps
>
this
->
currentBitrateBps
)
{
// Avoid increasing the rate when over-using.
...
...
@@ -177,12 +178,14 @@ namespace RTC
}
newBitrateBps
=
std
::
min
(
newBitrateBps
,
this
->
currentBitrateBps
);
}
ChangeRegion
(
kRcNearMax
);
if
(
incomingBitrateBps
<
this
->
currentBitrateBps
)
{
this
->
lastDecrease
=
int
(
this
->
currentBitrateBps
-
newBitrateBps
);
}
if
(
incomingBitrateKbps
<
this
->
avgMaxBitrateKbps
-
3
*
stdMaxBitRate
)
{
this
->
avgMaxBitrateKbps
=
-
1.0
f
;
...
...
@@ -228,6 +231,7 @@ namespace RTC
if
(
lastMs
>
-
1
)
{
int
timeSinceLastUpdateMs
=
std
::
min
(
static_cast
<
int
>
(
nowMs
-
lastMs
),
1000
);
alpha
=
pow
(
alpha
,
timeSinceLastUpdateMs
/
1000.0
);
}
...
...
@@ -257,6 +261,7 @@ namespace RTC
this
->
varMaxBitrateKbps
=
(
1
-
alpha
)
*
this
->
varMaxBitrateKbps
+
alpha
*
(
this
->
avgMaxBitrateKbps
-
incomingBitrateKbps
)
*
(
this
->
avgMaxBitrateKbps
-
incomingBitrateKbps
)
/
norm
;
// 0.4 ~= 14 kbit/s at 500 kbit/s
if
(
this
->
varMaxBitrateKbps
<
0.4
f
)
{
...
...
worker/src/RTC/RemoteBitrateEstimator/InterArrival.cpp
浏览文件 @
2f8af638
...
...
@@ -49,9 +49,11 @@ namespace RTC
{
*
timestamp_delta
=
this
->
currentTimestampGroup
.
timestamp
-
this
->
prevTimestampGroup
.
timestamp
;
*
arrival_time_delta_ms
=
this
->
currentTimestampGroup
.
complete_time_ms
-
this
->
prevTimestampGroup
.
complete_time_ms
;
// Check system time differences to see if we have an unproportional jump
// in arrival time. In that case reset the inter-arrival computations.
int64_t
system_time_delta_ms
=
this
->
currentTimestampGroup
.
last_system_time_ms
-
this
->
prevTimestampGroup
.
last_system_time_ms
;
if
(
*
arrival_time_delta_ms
-
system_time_delta_ms
>=
kArrivalTimeOffsetThresholdMs
)
{
MS_WARN_TAG
(
rbe
,
"the arrival time clock offset has changed, resetting [diff:%"
PRId64
"ms]"
,
...
...
@@ -60,6 +62,7 @@ namespace RTC
Reset
();
return
false
;
}
if
(
*
arrival_time_delta_ms
<
0
)
{
// The group of packets has been reordered since receiving its local
...
...
@@ -72,6 +75,7 @@ namespace RTC
"packet for bandwidth estimation, resetting"
);
Reset
();
}
return
false
;
}
else
...
...
@@ -84,6 +88,7 @@ namespace RTC
*
packet_size_delta
=
static_cast
<
int
>
(
this
->
currentTimestampGroup
.
size
)
-
static_cast
<
int
>
(
this
->
prevTimestampGroup
.
size
);
calculated_deltas
=
true
;
}
this
->
prevTimestampGroup
=
this
->
currentTimestampGroup
;
// The new timestamp is now the current frame.
this
->
currentTimestampGroup
.
first_timestamp
=
timestamp
;
...
...
@@ -138,6 +143,7 @@ namespace RTC
else
{
uint32_t
timestamp_diff
=
timestamp
-
this
->
currentTimestampGroup
.
first_timestamp
;
return
timestamp_diff
>
kTimestampGroupLengthTicks
;
}
}
...
...
@@ -150,7 +156,9 @@ namespace RTC
{
return
false
;
}
MS_ASSERT
(
this
->
currentTimestampGroup
.
complete_time_ms
>=
0
,
"invalid complete_time_ms value"
);
int64_t
arrival_time_delta_ms
=
arrival_time_ms
-
this
->
currentTimestampGroup
.
complete_time_ms
;
uint32_t
timestamp_diff
=
timestamp
-
this
->
currentTimestampGroup
.
timestamp
;
int64_t
ts_delta_ms
=
this
->
timestampToMsCoeff
*
timestamp_diff
+
0.5
;
...
...
worker/src/RTC/RemoteBitrateEstimator/OveruseDetector.cpp
浏览文件 @
2f8af638
...
...
@@ -95,10 +95,12 @@ namespace RTC
const
double
k
=
fabs
(
modifiedOffset
)
<
this
->
threshold
?
this
->
kDown
:
this
->
kUp
;
const
int64_t
kMaxTimeDeltaMs
=
100
;
int64_t
timeDeltaMs
=
std
::
min
(
nowMs
-
this
->
lastUpdateMs
,
kMaxTimeDeltaMs
);
this
->
threshold
+=
k
*
(
fabs
(
modifiedOffset
)
-
this
->
threshold
)
*
timeDeltaMs
;
const
double
kMinThreshold
=
6
;
const
double
kMaxThreshold
=
600
;
this
->
threshold
=
std
::
min
(
std
::
max
(
this
->
threshold
,
kMinThreshold
),
kMaxThreshold
);
this
->
lastUpdateMs
=
nowMs
;
...
...
worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.cpp
浏览文件 @
2f8af638
...
...
@@ -38,17 +38,21 @@ namespace RTC
std
::
vector
<
K
>
Keys
(
const
std
::
map
<
K
,
V
>&
map
)
{
std
::
vector
<
K
>
keys
;
keys
.
reserve
(
map
.
size
());
for
(
typename
std
::
map
<
K
,
V
>::
const_iterator
it
=
map
.
begin
();
it
!=
map
.
end
();
++
it
)
{
keys
.
push_back
(
it
->
first
);
}
return
keys
;
}
uint32_t
ConvertMsTo24Bits
(
int64_t
timeMs
)
{
uint32_t
time_24Bits
=
static_cast
<
uint32_t
>
(((
static_cast
<
uint64_t
>
(
timeMs
)
<<
kAbsSendTimeFraction
)
+
500
)
/
1000
)
&
0x00FFFFFF
;
return
time_24Bits
;
}
...
...
@@ -58,7 +62,9 @@ namespace RTC
if
(
clusterAggregate
.
count
==
0
)
return
true
;
float
clusterMean
=
clusterAggregate
.
sendMeanMs
/
static_cast
<
float
>
(
clusterAggregate
.
count
);
return
fabs
(
static_cast
<
float
>
(
sendDeltaMs
)
-
clusterMean
)
<
2.5
f
;
}
...
...
@@ -79,30 +85,37 @@ namespace RTC
Cluster
current
;
int64_t
prevSendTime
=
-
1
;
int64_t
prevRecvTime
=
-
1
;
for
(
std
::
list
<
Probe
>::
const_iterator
it
=
this
->
probes
.
begin
();
it
!=
this
->
probes
.
end
();
++
it
)
{
if
(
prevSendTime
>=
0
)
{
int
sendDeltaMs
=
it
->
sendTimeMs
-
prevSendTime
;
int
recvDeltaMs
=
it
->
recvTimeMs
-
prevRecvTime
;
if
(
sendDeltaMs
>=
1
&&
recvDeltaMs
>=
1
)
{
++
current
.
numAboveMinDelta
;
}
if
(
!
IsWithinClusterBounds
(
sendDeltaMs
,
current
))
{
if
(
current
.
count
>=
kMinClusterSize
)
AddCluster
(
clusters
,
&
current
);
current
=
Cluster
();
}
current
.
sendMeanMs
+=
sendDeltaMs
;
current
.
recvMeanMs
+=
recvDeltaMs
;
current
.
meanSize
+=
it
->
payloadSize
;
++
current
.
count
;
}
prevSendTime
=
it
->
sendTimeMs
;
prevRecvTime
=
it
->
recvTimeMs
;
}
if
(
current
.
count
>=
kMinClusterSize
)
AddCluster
(
clusters
,
&
current
);
}
...
...
@@ -113,13 +126,16 @@ namespace RTC
int
highestProbeBitrateBps
=
0
;
std
::
list
<
Cluster
>::
const_iterator
bestIt
=
clusters
.
end
();
for
(
std
::
list
<
Cluster
>::
const_iterator
it
=
clusters
.
begin
();
it
!=
clusters
.
end
();
++
it
)
{
if
(
it
->
sendMeanMs
==
0
||
it
->
recvMeanMs
==
0
)
continue
;
if
(
it
->
numAboveMinDelta
>
it
->
count
/
2
&&
(
it
->
recvMeanMs
-
it
->
sendMeanMs
<=
2.0
f
&&
it
->
sendMeanMs
-
it
->
recvMeanMs
<=
5.0
f
))
{
int
probeBitrateBps
=
std
::
min
(
it
->
GetSendBitrateBps
(),
it
->
GetRecvBitrateBps
());
if
(
probeBitrateBps
>
highestProbeBitrateBps
)
{
highestProbeBitrateBps
=
probeBitrateBps
;
...
...
@@ -137,6 +153,7 @@ namespace RTC
break
;
}
}
return
bestIt
;
}
...
...
@@ -146,12 +163,14 @@ namespace RTC
std
::
list
<
Cluster
>
clusters
;
ComputeClusters
(
&
clusters
);
if
(
clusters
.
empty
())
{
// If we reach the max number of probe packets and still have no clusters,
// we will remove the oldest one.
if
(
this
->
probes
.
size
()
>=
kMaxProbePackets
)
this
->
probes
.
pop_front
();
return
ProbeResult
::
kNoUpdate
;
}
...
...
@@ -159,6 +178,7 @@ namespace RTC
if
(
bestIt
!=
clusters
.
end
())
{
int
probeBitrateBps
=
std
::
min
(
bestIt
->
GetSendBitrateBps
(),
bestIt
->
GetRecvBitrateBps
());
// Make sure that a probe sent on a lower bitrate than our estimate can't
// reduce the estimate.
if
(
IsBitrateImproving
(
probeBitrateBps
))
...
...
@@ -167,6 +187,7 @@ namespace RTC
bestIt
->
GetSendBitrateBps
(),
bestIt
->
GetRecvBitrateBps
(),
bestIt
->
sendMeanMs
,
bestIt
->
recvMeanMs
,
bestIt
->
count
);
this
->
remoteRate
.
SetEstimate
(
probeBitrateBps
,
nowMs
);
return
ProbeResult
::
kBitrateUpdated
;
}
}
...
...
@@ -175,6 +196,7 @@ namespace RTC
// of probes.
if
(
clusters
.
size
()
>=
kExpectedNumberOfProbes
)
this
->
probes
.
clear
();
return
ProbeResult
::
kNoUpdate
;
}
...
...
@@ -183,7 +205,9 @@ namespace RTC
MS_TRACE
();
bool
initialProbe
=
!
this
->
remoteRate
.
ValidEstimate
()
&&
newBitrateBps
>
0
;
bool
bitrateAboveEstimate
=
this
->
remoteRate
.
ValidEstimate
()
&&
newBitrateBps
>
static_cast
<
int
>
(
this
->
remoteRate
.
LatestEstimate
());
bool
bitrateAboveEstimate
=
this
->
remoteRate
.
ValidEstimate
()
&&
newBitrateBps
>
static_cast
<
int
>
(
this
->
remoteRate
.
LatestEstimate
());
return
initialProbe
||
bitrateAboveEstimate
;
}
...
...
@@ -201,9 +225,7 @@ namespace RTC
MS_ASSERT
(
sendTime_24bits
<
(
1ul
<<
24
),
"invalid sendTime_24bits value"
);
if
(
!
this
->
umaRecorded
)
{
this
->
umaRecorded
=
true
;
}
// Shift up send time to use the full 32 bits that interArrival works with,
// so wrapping works properly.
...
...
@@ -212,9 +234,9 @@ namespace RTC
int64_t
nowMs
=
DepLibUV
::
GetTime
();
// TODO(holmer): SSRCs are only needed for REMB, should be broken out from
// here.
// Check if incoming bitrate estimate is valid, and if it needs to be reset.
uint32_t
incomingBitrate
=
this
->
incomingBitrate
.
GetRate
(
arrivalTimeMs
);
if
(
incomingBitrate
)
{
this
->
incomingBitrateInitialized
=
true
;
...
...
@@ -227,6 +249,7 @@ namespace RTC
this
->
incomingBitrate
.
Reset
();
this
->
incomingBitrateInitialized
=
false
;
}
this
->
incomingBitrate
.
Update
(
payloadSize
,
arrivalTimeMs
);
if
(
this
->
firstPacketTimeMs
==
-
1
)
...
...
@@ -238,16 +261,20 @@ namespace RTC
bool
updateEstimate
=
false
;
uint32_t
targetBitrateBps
=
0
;
std
::
vector
<
uint32_t
>
ssrcs
;
{
TimeoutStreams
(
nowMs
);
// MS_DASSERT(this->interArrival.get());
// MS_DASSERT(this->estimator.get());
// MS_ASSERT(this->interArrival.get());
// MS_ASSERT(this->estimator.get());
this
->
ssrcs
[
ssrc
]
=
nowMs
;
// For now only try to detect probes while we don't have a valid estimate.
// We currently assume that only packets larger than 200 bytes are paced by
// the sender.
const
size_t
kMinProbePacketSize
=
200
;
if
(
payloadSize
>
kMinProbePacketSize
&&
(
!
this
->
remoteRate
.
ValidEstimate
()
||
nowMs
-
this
->
firstPacketTimeMs
<
kInitialProbingIntervalMs
))
{
// TODO(holmer): Use a map instead to get correct order?
...
...
@@ -255,23 +282,30 @@ namespace RTC
{
int
sendDeltaMs
=
-
1
;
int
recvDeltaMs
=
-
1
;
if
(
!
this
->
probes
.
empty
())
{
sendDeltaMs
=
sendTimeMs
-
this
->
probes
.
back
().
sendTimeMs
;
recvDeltaMs
=
arrivalTimeMs
-
this
->
probes
.
back
().
recvTimeMs
;
}
MS_DEBUG_TAG
(
rbe
,
"probe packet received: send time=%"
PRId64
" ms, recv time=%"
PRId64
" ms, send delta=%d ms, recv delta=%d ms"
,
sendTimeMs
,
arrivalTimeMs
,
sendDeltaMs
,
recvDeltaMs
);
MS_DEBUG_TAG
(
rbe
,
"probe packet received [send time:%"
PRId64
"ms, recv time:%"
PRId64
"ms, send delta:%dms, recv delta:%d ms]"
,
sendTimeMs
,
arrivalTimeMs
,
sendDeltaMs
,
recvDeltaMs
);
}
this
->
probes
.
push_back
(
Probe
(
sendTimeMs
,
arrivalTimeMs
,
payloadSize
));
++
this
->
totalProbesReceived
;
// Make sure that a probe which updated the bitrate immediately has an
// effect by calling the onReceiveBitrateChanged callback.
if
(
ProcessClusters
(
nowMs
)
==
ProbeResult
::
kBitrateUpdated
)
updateEstimate
=
true
;
}
if
(
this
->
interArrival
->
ComputeDeltas
(
timestamp
,
arrivalTimeMs
,
nowMs
,
payloadSize
,
&
tsDelta
,
&
tDelta
,
&
sizeDelta
))
{
double
tsDeltaMs
=
(
1000.0
*
tsDelta
)
/
(
1
<<
kInterArrivalShift
);
this
->
estimator
->
Update
(
tDelta
,
tsDeltaMs
,
sizeDelta
,
this
->
detector
.
State
(),
arrivalTimeMs
);
this
->
detector
.
Detect
(
this
->
estimator
->
GetOffset
(),
tsDeltaMs
,
this
->
estimator
->
GetNumOfDeltas
(),
arrivalTimeMs
);
}
...
...
@@ -280,17 +314,18 @@ namespace RTC
{
// Check if it's time for a periodic update or if we should update because
// of an over-use.
if
(
this
->
lastUpdateMs
==
-
1
||
nowMs
-
this
->
lastUpdateMs
>
this
->
remoteRate
.
GetFeedbackInterval
())
if
(
this
->
lastUpdateMs
==
-
1
||
nowMs
-
this
->
lastUpdateMs
>
this
->
remoteRate
.
GetFeedbackInterval
())
{
updateEstimate
=
true
;
}
else
if
(
this
->
detector
.
State
()
==
kBwOverusing
)
{
uint32_t
incomingRate
=
this
->
incomingBitrate
.
GetRate
(
arrivalTimeMs
);
if
(
incomingRate
&&
this
->
remoteRate
.
TimeToReduceFurther
(
nowMs
,
incomingRate
))
{
updateEstimate
=
true
;
}
}
}
...
...
@@ -299,13 +334,17 @@ namespace RTC
// The first overuse should immediately trigger a new estimate.
// We also have to update the estimate immediately if we are overusing
// and the target bitrate is too high compared to what we are receiving.
const
RateControlInput
input
(
this
->
detector
.
State
(),
this
->
incomingBitrate
.
GetRate
(
arrivalTimeMs
),
this
->
estimator
->
GetVarNoise
());
const
RateControlInput
input
(
this
->
detector
.
State
(),
this
->
incomingBitrate
.
GetRate
(
arrivalTimeMs
),
this
->
estimator
->
GetVarNoise
());
this
->
remoteRate
.
Update
(
&
input
,
nowMs
);
targetBitrateBps
=
this
->
remoteRate
.
UpdateBandwidthEstimate
(
nowMs
);
updateEstimate
=
this
->
remoteRate
.
ValidEstimate
();
ssrcs
=
Keys
(
this
->
ssrcs
);
}
}
if
(
updateEstimate
)
{
this
->
lastUpdateMs
=
nowMs
;
...
...
@@ -320,14 +359,11 @@ namespace RTC
for
(
Ssrcs
::
iterator
it
=
this
->
ssrcs
.
begin
();
it
!=
this
->
ssrcs
.
end
();)
{
if
((
nowMs
-
it
->
second
)
>
kStreamTimeOutMs
)
{
this
->
ssrcs
.
erase
(
it
++
);
}
else
{
++
it
;
}
}
if
(
this
->
ssrcs
.
empty
())
{
// We can't update the estimate if we don't have any active streams.
...
...
@@ -342,21 +378,17 @@ namespace RTC
{
MS_TRACE
();
// MS_DASSERT(ssrcs);
// MS_DASSERT(bitrateBps);
// MS_ASSERT(ssrcs);
// MS_ASSERT(bitrateBps);
if
(
!
this
->
remoteRate
.
ValidEstimate
())
{
return
false
;
}
*
ssrcs
=
Keys
(
this
->
ssrcs
);
if
(
this
->
ssrcs
.
empty
())
{
*
bitrateBps
=
0
;
}
else
{
*
bitrateBps
=
this
->
remoteRate
.
LatestEstimate
();
}
return
true
;
}
...
...
worker/src/RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorSingleStream.cpp
浏览文件 @
2f8af638
...
...
@@ -30,9 +30,11 @@ namespace RTC
{
this
->
umaRecorded
=
true
;
}
uint32_t
ssrc
=
packet
.
GetSsrc
();
uint32_t
rtpTimestamp
=
packet
.
GetTimestamp
()
+
transmissionTimeOffset
;
int64_t
nowMs
=
DepLibUV
::
GetTime
();
SsrcOveruseEstimatorMap
::
iterator
it
=
this
->
overuseDetectors
.
find
(
ssrc
);
if
(
it
==
this
->
overuseDetectors
.
end
())
{
...
...
@@ -46,11 +48,13 @@ namespace RTC
this
->
overuseDetectors
.
insert
(
std
::
make_pair
(
ssrc
,
new
Detector
(
nowMs
,
OverUseDetectorOptions
(),
true
)));
it
=
insertResult
.
first
;
}
Detector
*
estimator
=
it
->
second
;
estimator
->
lastPacketTimeMs
=
nowMs
;
// Check if incoming bitrate estimate is valid, and if it needs to be reset.
uint32_t
incomingBitrate
=
this
->
incomingBitrate
.
GetRate
(
nowMs
);
if
(
incomingBitrate
)
{
this
->
lastValidIncomingBitrate
=
incomingBitrate
;
...
...
@@ -63,21 +67,26 @@ namespace RTC
this
->
incomingBitrate
.
Reset
();
this
->
lastValidIncomingBitrate
=
0
;
}
this
->
incomingBitrate
.
Update
(
payloadSize
,
nowMs
);
const
BandwidthUsage
priorState
=
estimator
->
detector
.
State
();
uint32_t
timestampDelta
=
0
;
int64_t
timeDelta
=
0
;
int
sizeDelta
=
0
;
if
(
estimator
->
interArrival
.
ComputeDeltas
(
rtpTimestamp
,
arrivalTimeMs
,
nowMs
,
payloadSize
,
&
timestampDelta
,
&
timeDelta
,
&
sizeDelta
))
{
double
timestampDeltaMs
=
timestampDelta
*
kTimestampToMs
;
estimator
->
estimator
.
Update
(
timeDelta
,
timestampDeltaMs
,
sizeDelta
,
estimator
->
detector
.
State
(),
nowMs
);
estimator
->
detector
.
Detect
(
estimator
->
estimator
.
GetOffset
(),
timestampDeltaMs
,
estimator
->
estimator
.
GetNumOfDeltas
(),
nowMs
);
}
if
(
estimator
->
detector
.
State
()
==
kBwOverusing
)
{
uint32_t
incomingBitrateBps
=
this
->
incomingBitrate
.
GetRate
(
nowMs
);
if
(
incomingBitrateBps
&&
(
priorState
!=
kBwOverusing
||
GetRemoteRate
()
->
TimeToReduceFurther
(
nowMs
,
incomingBitrateBps
)))
{
// The first overuse should immediately trigger a new estimate.
...
...
@@ -93,10 +102,9 @@ namespace RTC
MS_TRACE
();
if
(
this
->
lastProcessTime
<
0
)
{
return
0
;
}
// MS_
D
ASSERT(this->processIntervalMs > 0);
// MS_ASSERT(this->processIntervalMs > 0);
return
this
->
lastProcessTime
+
this
->
processIntervalMs
-
DepLibUV
::
GetTime
();
}
...
...
@@ -107,9 +115,11 @@ namespace RTC
BandwidthUsage
bwState
=
kBwNormal
;
double
sumVarNoise
=
0.0
;
SsrcOveruseEstimatorMap
::
iterator
it
=
this
->
overuseDetectors
.
begin
();
while
(
it
!=
this
->
overuseDetectors
.
end
())
{
const
int64_t
timeOfLastReceivedPacket
=
it
->
second
->
lastPacketTimeMs
;
if
(
timeOfLastReceivedPacket
>=
0
&&
nowMs
-
timeOfLastReceivedPacket
>
kStreamTimeOutMs
)
{
// This over-use detector hasn't received packets for |kStreamTimeOutMs|
...
...
@@ -123,9 +133,8 @@ namespace RTC
// Make sure that we trigger an over-use if any of the over-use detectors
// is detecting over-use.
if
(
it
->
second
->
detector
.
State
()
>
bwState
)
{
bwState
=
it
->
second
->
detector
.
State
();
}
++
it
;
}
}
...
...
@@ -134,16 +143,19 @@ namespace RTC
{
return
;
}
AimdRateControl
*
remoteRate
=
GetRemoteRate
();
AimdRateControl
*
remoteRate
=
GetRemoteRate
();
double
meanNoiseVar
=
sumVarNoise
/
static_cast
<
double
>
(
this
->
overuseDetectors
.
size
());
const
RateControlInput
input
(
bwState
,
this
->
incomingBitrate
.
GetRate
(
nowMs
),
meanNoiseVar
);
remoteRate
->
Update
(
&
input
,
nowMs
);
uint32_t
targetBitrate
=
remoteRate
->
UpdateBandwidthEstimate
(
nowMs
);
if
(
remoteRate
->
ValidEstimate
())
{
this
->
processIntervalMs
=
remoteRate
->
GetFeedbackInterval
();
// MS_
D
ASSERT(this->processIntervalMs > 0);
// MS_ASSERT(this->processIntervalMs > 0);
std
::
vector
<
uint32_t
>
ssrcs
;
...
...
@@ -156,12 +168,10 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
bitrateBps
,
"
'bitrateBps'
missing"
);
MS_ASSERT
(
bitrateBps
,
"
bitrateBps
missing"
);
if
(
!
this
->
remoteRate
->
ValidEstimate
())
{
return
false
;
}
GetSsrcs
(
ssrcs
);
if
(
ssrcs
->
empty
())
...
...
@@ -176,11 +186,12 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
ssrcs
,
"
'ssrcs'
missing"
);
MS_ASSERT
(
ssrcs
,
"
ssrcs
missing"
);
ssrcs
->
resize
(
this
->
overuseDetectors
.
size
());
int
i
=
0
;
for
(
SsrcOveruseEstimatorMap
::
const_iterator
it
=
this
->
overuseDetectors
.
begin
();
it
!=
this
->
overuseDetectors
.
end
();
++
it
,
++
i
)
{
(
*
ssrcs
)[
i
]
=
it
->
first
;
...
...
worker/src/RTC/RtpStreamRecv.cpp
浏览文件 @
2f8af638
...
...
@@ -69,6 +69,8 @@ namespace RTC
RTC
::
RTCP
::
ReceiverReport
*
RtpStreamRecv
::
GetRtcpReceiverReport
()
{
MS_TRACE
();
RTC
::
RTCP
::
ReceiverReport
*
report
=
new
RTC
::
RTCP
::
ReceiverReport
();
// Calculate Packets Expected and Lost.
...
...
@@ -123,13 +125,31 @@ namespace RTC
void
RtpStreamRecv
::
ReceiveRtcpSenderReport
(
RTC
::
RTCP
::
SenderReport
*
report
)
{
MS_TRACE
();
this
->
last_sr_received
=
DepLibUV
::
GetTime
();
this
->
last_sr_timestamp
=
report
->
GetNtpSec
()
<<
16
;
this
->
last_sr_timestamp
+=
report
->
GetNtpFrac
()
>>
16
;
}
void
RtpStreamRecv
::
RequestFullFrame
()
{
MS_TRACE
();
if
(
this
->
params
.
usePli
)
{
// Reset NackGenerator.
if
(
this
->
params
.
useNack
)
this
->
nackGenerator
.
reset
(
new
RTC
::
NackGenerator
(
this
));
this
->
listener
->
onPliRequired
(
this
);
}
}
void
RtpStreamRecv
::
CalculateJitter
(
uint32_t
rtpTimestamp
)
{
MS_TRACE
();
if
(
!
this
->
params
.
clockRate
)
return
;
...
...
worker/src/RTC/RtpStreamSend.cpp
浏览文件 @
2f8af638
...
...
@@ -7,7 +7,7 @@
#include "Utils.hpp"
#define RTP_SEQ_MOD (1<<16)
#define MAX_RETRANSMISSION_AGE
10
00 // Don't retransmit packets older than this (ms).
#define MAX_RETRANSMISSION_AGE
5
00 // Don't retransmit packets older than this (ms).
#define DEFAULT_RTT 100 // Default RTT if not set (in ms).
namespace
RTC
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
2f8af638
...
...
@@ -8,6 +8,8 @@
#include "Utils.hpp"
#include "MediaSoupError.hpp"
#include "Logger.hpp"
#include <sstream> // std::ostringstream()
#include <iterator> // std::ostream_iterator<>()
#include <cmath> // std::pow()
#define ICE_CANDIDATE_DEFAULT_LOCAL_PRIORITY 20000
...
...
@@ -34,6 +36,11 @@ uint32_t generateIceCandidatePriority(uint16_t local_preference)
namespace
RTC
{
/* Consts. */
static
constexpr
uint64_t
EffectiveMaxBitrateCheckInterval
=
2000
;
// In ms.
static
constexpr
double
EffectiveMaxBitrateThresholdBeforeFullFrame
=
0.6
;
// 0.0 - 1.0.
/* Class variables. */
uint8_t
Transport
::
rtcpBuffer
[
MS_RTCP_BUFFER_SIZE
];
...
...
@@ -282,6 +289,7 @@ namespace RTC
static
const
Json
::
StaticString
v_failed
(
"failed"
);
static
const
Json
::
StaticString
k_useRemb
(
"useRemb"
);
static
const
Json
::
StaticString
k_maxBitrate
(
"maxBitrate"
);
static
const
Json
::
StaticString
k_effectiveMaxBitrate
(
"effectiveMaxBitrate"
);
static
const
Json
::
StaticString
k_rtpListener
(
"rtpListener"
);
Json
::
Value
json
(
Json
::
objectValue
);
...
...
@@ -368,6 +376,9 @@ namespace RTC
// Add `maxBitrate`.
json
[
k_maxBitrate
]
=
(
Json
::
UInt
)
this
->
maxBitrate
;
// Add `effectiveMaxBitrate`.
json
[
k_effectiveMaxBitrate
]
=
(
Json
::
UInt
)
this
->
effectiveMaxBitrate
;
// Add `rtpListener`.
json
[
k_rtpListener
]
=
this
->
rtpListener
.
toJson
();
...
...
@@ -1164,19 +1175,25 @@ namespace RTC
{
MS_TRACE
();
uint32_t
effective_bitrate
=
bitrate
;
uint32_t
effective_bitrate
;
uint64_t
now
=
DepLibUV
::
GetTime
();
// Limit bitrate if requested via API.
if
(
this
->
maxBitrate
)
effective_bitrate
=
std
::
min
(
bitrate
,
this
->
maxBitrate
);
else
effective_bitrate
=
bitrate
;
MS_DEBUG_TAG
(
rbe
,
"sending RTCP REMB packet [estimated:%"
PRIu32
"bps, effective:%"
PRIu32
"bps]"
,
bitrate
,
effective_bitrate
);
for
(
auto
ssrc
:
ssrcs
)
if
(
MS_HAS_DEBUG_TAG
(
rbe
))
{
MS_DEBUG_TAG
(
rbe
,
" ssrc : %"
PRIu32
,
ssrc
);
std
::
ostringstream
ssrcs_stream
;
std
::
copy
(
ssrcs
.
begin
(),
ssrcs
.
end
()
-
1
,
std
::
ostream_iterator
<
int
>
(
ssrcs_stream
,
","
));
ssrcs_stream
<<
ssrcs
.
back
();
MS_DEBUG_TAG
(
rbe
,
"sending RTCP REMB packet [estimated:%"
PRIu32
"bps, effective:%"
PRIu32
"bps, ssrcs:%s]"
,
bitrate
,
effective_bitrate
,
ssrcs_stream
.
str
().
c_str
());
}
RTC
::
RTCP
::
FeedbackPsRembPacket
packet
(
0
,
0
);
...
...
@@ -1184,5 +1201,23 @@ namespace RTC
packet
.
SetSsrcs
(
ssrcs
);
packet
.
Serialize
(
Transport
::
rtcpBuffer
);
this
->
SendRtcpPacket
(
&
packet
);
// Trigger a full frame for all the suitable strams if the effective max bitrate
// has decreased abruptly.
if
(
now
-
this
->
lastEffectiveMaxBitrateAt
>
EffectiveMaxBitrateCheckInterval
)
{
if
(
bitrate
&&
this
->
effectiveMaxBitrate
&&
(
double
)
effective_bitrate
/
(
double
)
this
->
effectiveMaxBitrate
<
EffectiveMaxBitrateThresholdBeforeFullFrame
)
{
MS_WARN_TAG
(
rbe
,
"uplink effective max bitrate abruptly decrease, requesting full frames"
);
this
->
listener
->
onTransportFullFrameRequired
(
this
);
}
this
->
lastEffectiveMaxBitrateAt
=
now
;
this
->
effectiveMaxBitrate
=
effective_bitrate
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论