Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
529538ae
提交
529538ae
authored
4月 09, 2019
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve SimulcastConsumer::RecalculateTargetSpatialLayer()
上级
54dde57d
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
127 行增加
和
187 行删除
+127
-187
Consumer.hpp
worker/include/RTC/Consumer.hpp
+4
-4
PipeConsumer.hpp
worker/include/RTC/PipeConsumer.hpp
+3
-3
Producer.hpp
worker/include/RTC/Producer.hpp
+2
-2
Router.hpp
worker/include/RTC/Router.hpp
+2
-2
SimpleConsumer.hpp
worker/include/RTC/SimpleConsumer.hpp
+3
-3
SimulcastConsumer.hpp
worker/include/RTC/SimulcastConsumer.hpp
+4
-4
Transport.hpp
worker/include/RTC/Transport.hpp
+4
-4
PipeConsumer.cpp
worker/src/RTC/PipeConsumer.cpp
+3
-3
Producer.cpp
worker/src/RTC/Producer.cpp
+3
-2
Router.cpp
worker/src/RTC/Router.cpp
+2
-5
SimpleConsumer.cpp
worker/src/RTC/SimpleConsumer.cpp
+3
-3
SimulcastConsumer.cpp
worker/src/RTC/SimulcastConsumer.cpp
+88
-150
Transport.cpp
worker/src/RTC/Transport.cpp
+2
-2
TestNackGenerator.cpp
worker/test/src/RTC/TestNackGenerator.cpp
+4
-0
没有找到文件。
worker/include/RTC/Consumer.hpp
浏览文件 @
529538ae
...
...
@@ -11,7 +11,7 @@
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpHeaderExtensionIds.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStream
Recv
.hpp"
#include "RTC/RtpStream.hpp"
#include <string>
#include <unordered_set>
#include <vector>
...
...
@@ -55,9 +55,9 @@ namespace RTC
virtual
uint32_t
UseBandwidth
(
uint32_t
availableBandwidth
)
=
0
;
void
ProducerPaused
();
void
ProducerResumed
();
virtual
void
ProducerRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
=
0
;
virtual
void
ProducerNewRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
=
0
;
virtual
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
=
0
;
virtual
void
ProducerRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
=
0
;
virtual
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
=
0
;
virtual
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
=
0
;
void
ProducerClosed
();
virtual
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
)
=
0
;
virtual
void
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
)
=
0
;
...
...
worker/include/RTC/PipeConsumer.hpp
浏览文件 @
529538ae
...
...
@@ -18,9 +18,9 @@ namespace RTC
void
FillJsonScore
(
json
&
jsonObject
)
const
override
;
void
HandleRequest
(
Channel
::
Request
*
request
)
override
;
uint32_t
UseBandwidth
(
uint32_t
availableBandwidth
)
override
;
void
ProducerRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerNewRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
override
;
void
ProducerRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
override
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
)
override
;
void
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
)
override
;
void
NeedWorstRemoteFractionLost
(
uint32_t
mappedSsrc
,
uint8_t
&
worstRemoteFractionLost
)
override
;
...
...
worker/include/RTC/Producer.hpp
浏览文件 @
529538ae
...
...
@@ -27,9 +27,9 @@ namespace RTC
virtual
void
OnProducerPaused
(
RTC
::
Producer
*
producer
)
=
0
;
virtual
void
OnProducerResumed
(
RTC
::
Producer
*
producer
)
=
0
;
virtual
void
OnProducerNewRtpStream
(
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
=
0
;
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
=
0
;
virtual
void
OnProducerRtpStreamScore
(
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
=
0
;
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
=
0
;
virtual
void
OnProducerRtpPacketReceived
(
RTC
::
Producer
*
producer
,
RTC
::
RtpPacket
*
packet
)
=
0
;
virtual
void
OnProducerSendRtcpPacket
(
RTC
::
Producer
*
producer
,
RTC
::
RTCP
::
Packet
*
packet
)
=
0
;
virtual
void
OnProducerNeedWorstRemoteFractionLost
(
...
...
worker/include/RTC/Router.hpp
浏览文件 @
529538ae
...
...
@@ -44,7 +44,7 @@ namespace RTC
void
OnTransportProducerNewRtpStream
(
RTC
::
Transport
*
transport
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
OnTransportProducerRtpPacketReceived
(
RTC
::
Transport
*
transport
,
RTC
::
Producer
*
producer
,
RTC
::
RtpPacket
*
packet
)
override
;
...
...
@@ -56,7 +56,7 @@ namespace RTC
void
OnTransportProducerRtpStreamScore
(
RTC
::
Transport
*
transport
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
override
;
void
OnTransportNewConsumer
(
RTC
::
Transport
*
transport
,
RTC
::
Consumer
*
consumer
,
std
::
string
&
producerId
)
override
;
...
...
worker/include/RTC/SimpleConsumer.hpp
浏览文件 @
529538ae
...
...
@@ -19,9 +19,9 @@ namespace RTC
void
FillJsonScore
(
json
&
jsonObject
)
const
override
;
void
HandleRequest
(
Channel
::
Request
*
request
)
override
;
uint32_t
UseBandwidth
(
uint32_t
availableBandwidth
)
override
;
void
ProducerRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerNewRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
override
;
void
ProducerRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
override
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
)
override
;
void
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
)
override
;
void
NeedWorstRemoteFractionLost
(
uint32_t
mappedSsrc
,
uint8_t
&
worstRemoteFractionLost
)
override
;
...
...
worker/include/RTC/SimulcastConsumer.hpp
浏览文件 @
529538ae
...
...
@@ -20,9 +20,9 @@ namespace RTC
void
FillJsonScore
(
json
&
jsonObject
)
const
override
;
void
HandleRequest
(
Channel
::
Request
*
request
)
override
;
uint32_t
UseBandwidth
(
uint32_t
availableBandwidth
)
override
;
void
ProducerRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerNewRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
override
;
void
ProducerRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
override
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
)
override
;
void
GetRtcp
(
RTC
::
RTCP
::
CompoundPacket
*
packet
,
uint64_t
now
)
override
;
void
NeedWorstRemoteFractionLost
(
uint32_t
mappedSsrc
,
uint8_t
&
worstRemoteFractionLost
)
override
;
...
...
@@ -39,7 +39,7 @@ namespace RTC
void
RequestKeyFrame
();
void
RetransmitRtpPacket
(
RTC
::
RtpPacket
*
packet
);
void
EmitScore
()
const
;
void
UpdateLayers
();
void
Update
Current
Layers
();
void
RecalculateTargetSpatialLayer
();
RTC
::
RtpStream
*
GetProducerCurrentRtpStream
()
const
;
RTC
::
RtpStream
*
GetProducerTargetRtpStream
()
const
;
...
...
worker/include/RTC/Transport.hpp
浏览文件 @
529538ae
...
...
@@ -35,12 +35,12 @@ namespace RTC
virtual
void
OnTransportProducerNewRtpStream
(
RTC
::
Transport
*
transport
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
=
0
;
virtual
void
OnTransportProducerRtpStreamScore
(
RTC
::
Transport
*
transport
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
=
0
;
virtual
void
OnTransportProducerRtpPacketReceived
(
RTC
::
Transport
*
transport
,
RTC
::
Producer
*
producer
,
RTC
::
RtpPacket
*
packet
)
=
0
;
...
...
@@ -101,9 +101,9 @@ namespace RTC
void
OnProducerPaused
(
RTC
::
Producer
*
producer
)
override
;
void
OnProducerResumed
(
RTC
::
Producer
*
producer
)
override
;
void
OnProducerNewRtpStream
(
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
OnProducerRtpStreamScore
(
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
override
;
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
override
;
void
OnProducerRtpPacketReceived
(
RTC
::
Producer
*
producer
,
RTC
::
RtpPacket
*
packet
)
override
;
void
OnProducerSendRtcpPacket
(
RTC
::
Producer
*
producer
,
RTC
::
RTCP
::
Packet
*
packet
)
override
;
void
OnProducerNeedWorstRemoteFractionLost
(
...
...
worker/src/RTC/PipeConsumer.cpp
浏览文件 @
529538ae
...
...
@@ -90,21 +90,21 @@ namespace RTC
return
0
;
}
void
PipeConsumer
::
ProducerRtpStream
(
RTC
::
RtpStream
Recv
*
/*rtpStream*/
,
uint32_t
/*mappedSsrc*/
)
void
PipeConsumer
::
ProducerRtpStream
(
RTC
::
RtpStream
*
/*rtpStream*/
,
uint32_t
/*mappedSsrc*/
)
{
MS_TRACE
();
// Do nothing.
}
void
PipeConsumer
::
ProducerNewRtpStream
(
RTC
::
RtpStream
Recv
*
/*rtpStream*/
,
uint32_t
/*mappedSsrc*/
)
void
PipeConsumer
::
ProducerNewRtpStream
(
RTC
::
RtpStream
*
/*rtpStream*/
,
uint32_t
/*mappedSsrc*/
)
{
MS_TRACE
();
// Do nothing.
}
void
PipeConsumer
::
ProducerRtpStreamScore
(
RTC
::
RtpStream
Recv
*
/*rtpStream*/
,
uint8_t
/*score*/
)
void
PipeConsumer
::
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
/*rtpStream*/
,
uint8_t
/*score*/
)
{
MS_TRACE
();
...
...
worker/src/RTC/Producer.cpp
浏览文件 @
529538ae
...
...
@@ -776,7 +776,8 @@ namespace RTC
rtpStream
->
Pause
();
// Notify to the listener.
this
->
listener
->
OnProducerNewRtpStream
(
this
,
rtpStream
,
encodingMapping
.
mappedSsrc
);
this
->
listener
->
OnProducerNewRtpStream
(
this
,
static_cast
<
RTC
::
RtpStream
*>
(
rtpStream
),
encodingMapping
.
mappedSsrc
);
// Request a key frame for this stream since we may have lost the first packets
// (do not do it if this is a key frame).
...
...
@@ -983,7 +984,7 @@ namespace RTC
MS_TRACE
();
// Notify the listener.
this
->
listener
->
OnProducerRtpStreamScore
(
this
,
static_cast
<
RTC
::
RtpStreamRecv
*>
(
rtpStream
)
,
score
);
this
->
listener
->
OnProducerRtpStreamScore
(
this
,
rtpStream
,
score
);
// Emit the score event.
EmitScore
();
...
...
worker/src/RTC/Router.cpp
浏览文件 @
529538ae
...
...
@@ -549,10 +549,7 @@ namespace RTC
}
inline
void
Router
::
OnTransportProducerNewRtpStream
(
RTC
::
Transport
*
/*transport*/
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStreamRecv
*
rtpStream
,
uint32_t
mappedSsrc
)
RTC
::
Transport
*
/*transport*/
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
{
MS_TRACE
();
...
...
@@ -565,7 +562,7 @@ namespace RTC
}
inline
void
Router
::
OnTransportProducerRtpStreamScore
(
RTC
::
Transport
*
/*transport*/
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
RTC
::
Transport
*
/*transport*/
,
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
{
MS_TRACE
();
...
...
worker/src/RTC/SimpleConsumer.cpp
浏览文件 @
529538ae
...
...
@@ -109,7 +109,7 @@ namespace RTC
return
0
;
}
void
SimpleConsumer
::
ProducerRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
/*mappedSsrc*/
)
void
SimpleConsumer
::
ProducerRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
/*mappedSsrc*/
)
{
MS_TRACE
();
...
...
@@ -119,7 +119,7 @@ namespace RTC
EmitScore
();
}
void
SimpleConsumer
::
ProducerNewRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
/*mappedSsrc*/
)
void
SimpleConsumer
::
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
/*mappedSsrc*/
)
{
MS_TRACE
();
...
...
@@ -136,7 +136,7 @@ namespace RTC
EmitScore
();
}
void
SimpleConsumer
::
ProducerRtpStreamScore
(
RTC
::
RtpStream
Recv
*
/*rtpStream*/
,
uint8_t
/*score*/
)
void
SimpleConsumer
::
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
/*rtpStream*/
,
uint8_t
/*score*/
)
{
MS_TRACE
();
...
...
worker/src/RTC/SimulcastConsumer.cpp
浏览文件 @
529538ae
...
...
@@ -62,6 +62,10 @@ namespace RTC
if
(
this
->
preferredTemporalLayer
>
encoding
.
temporalLayers
-
1
)
this
->
preferredTemporalLayer
=
encoding
.
temporalLayers
-
1
;
}
else
{
this
->
preferredTemporalLayer
=
encoding
.
temporalLayers
-
1
;
}
}
else
{
...
...
@@ -179,31 +183,31 @@ namespace RTC
MS_THROW_TYPE_ERROR
(
"missing spatialLayer"
);
}
auto
preferredSpatialLayer
=
jsonSpatialLayerIt
->
get
<
int16_t
>
();
if
(
preferredSpatialLayer
>
this
->
rtpStream
->
GetSpatialLayers
()
-
1
)
preferredSpatialLayer
=
this
->
rtpStream
->
GetSpatialLayers
()
-
1
;
this
->
preferredSpatialLayer
=
jsonSpatialLayerIt
->
get
<
int16_t
>
();
// Temporal layer.
uint16_t
preferredTemporalLayer
;
if
(
this
->
preferredSpatialLayer
>
this
->
rtpStream
->
GetSpatialLayers
()
-
1
)
this
->
preferredSpatialLayer
=
this
->
rtpStream
->
GetSpatialLayers
()
-
1
;
// p
er
ferredTemporaLayer is optional.
// p
re
ferredTemporaLayer is optional.
if
(
jsonTemporalLayerIt
!=
request
->
data
.
end
()
&&
jsonTemporalLayerIt
->
is_number_unsigned
())
{
preferredTemporalLayer
=
jsonTemporalLayerIt
->
get
<
int16_t
>
();
this
->
preferredTemporalLayer
=
jsonTemporalLayerIt
->
get
<
int16_t
>
();
if
(
this
->
preferredTemporalLayer
>
this
->
rtpStream
->
GetTemporalLayers
()
-
1
)
this
->
preferredTemporalLayer
=
this
->
rtpStream
->
GetTemporalLayers
()
-
1
;
}
else
{
preferredTemporalLayer
=
this
->
preferredTemporalLayer
;
this
->
preferredTemporalLayer
=
this
->
rtpStream
->
GetTemporalLayers
()
-
1
;
}
this
->
preferredSpatialLayer
=
preferredSpatialLayer
;
this
->
preferredTemporalLayer
=
preferredTemporalLayer
;
this
->
targetTemporalLayer
=
preferredTemporalLayer
;
if
(
this
->
currentSpatialLayer
==
this
->
preferredSpatialLayer
)
{
this
->
targetTemporalLayer
=
this
->
preferredTemporalLayer
;
if
(
this
->
currentSpatialLayer
==
this
->
targetSpatialLayer
&&
this
->
encodingContext
)
this
->
encodingContext
->
preferences
.
temporalLayer
=
this
->
targetTemporalLayer
;
if
(
this
->
encodingContext
)
this
->
encodingContext
->
preferences
.
temporalLayer
=
this
->
targetTemporalLayer
;
}
MS_DEBUG_DEV
(
"preferred layers changed to [spatial:%"
PRIi16
", temporal:%"
PRIi16
", consumerId:%s]"
,
...
...
@@ -242,7 +246,7 @@ namespace RTC
return
0
;
}
void
SimulcastConsumer
::
ProducerRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
void
SimulcastConsumer
::
ProducerRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
{
MS_TRACE
();
...
...
@@ -258,7 +262,7 @@ namespace RTC
EmitScore
();
}
void
SimulcastConsumer
::
ProducerNewRtpStream
(
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
void
SimulcastConsumer
::
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
{
MS_TRACE
();
...
...
@@ -296,7 +300,7 @@ namespace RTC
EmitScore
();
}
void
SimulcastConsumer
::
ProducerRtpStreamScore
(
RTC
::
RtpStream
Recv
*
/*rtpStream*/
,
uint8_t
/*score*/
)
void
SimulcastConsumer
::
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
/*rtpStream*/
,
uint8_t
/*score*/
)
{
MS_TRACE
();
...
...
@@ -338,7 +342,7 @@ namespace RTC
return
;
// Change current spatial layer.
UpdateLayers
();
Update
Current
Layers
();
// Need to resync the stream.
this
->
syncRequired
=
true
;
...
...
@@ -382,9 +386,6 @@ namespace RTC
this
->
syncRequired
=
false
;
}
// TODO: Not sure how to deal with it, but if this happens (and we drop the packet)
// we shouldn't have unset the syncRequired flag, etc.
//
// Rewrite payload if needed. Drop packet if necessary.
if
(
this
->
encodingContext
&&
!
packet
->
EncodePayload
(
this
->
encodingContext
.
get
()))
{
...
...
@@ -394,13 +395,12 @@ namespace RTC
return
;
}
// Update temporal layer only if we are
us
ing the target spatial layer.
// Update temporal layer only if we are
send
ing the target spatial layer.
if
(
this
->
currentSpatialLayer
==
this
->
targetSpatialLayer
&&
this
->
currentTemporalLayer
!=
this
->
targetTemporalLayer
&&
packet
->
GetTemporalLayer
()
==
this
->
targetTemporalLayer
)
{
UpdateLayers
();
Update
Current
Layers
();
}
// Update RTP seq number and timestamp.
...
...
@@ -561,8 +561,17 @@ namespace RTC
this
->
rtpStream
->
Pause
();
// Unset current and target layers.
this
->
targetSpatialLayer
=
-
1
;
this
->
currentSpatialLayer
=
-
1
;
this
->
targetSpatialLayer
=
-
1
;
this
->
currentSpatialLayer
=
-
1
;
this
->
targetTemporalLayer
=
-
1
;
this
->
currentTemporalLayer
=
-
1
;
if
(
this
->
encodingContext
)
{
this
->
encodingContext
->
preferences
.
temporalLayer
=
this
->
rtpStream
->
GetTemporalLayers
()
-
1
;
}
// TODO: Emit JS event?
}
void
SimulcastConsumer
::
Resumed
()
...
...
@@ -702,16 +711,31 @@ namespace RTC
Channel
::
Notifier
::
Emit
(
this
->
id
,
"score"
,
data
);
}
void
SimulcastConsumer
::
UpdateLayers
()
void
SimulcastConsumer
::
Update
Current
Layers
()
{
MS_TRACE
();
if
(
this
->
targetSpatialLayer
==
this
->
currentSpatialLayer
&&
this
->
targetTemporalLayer
==
this
->
currentTemporalLayer
)
if
(
this
->
currentSpatialLayer
==
this
->
targetSpatialLayer
&&
this
->
currentTemporalLayer
==
this
->
targetTemporalLayer
)
{
return
;
}
// Reset the score of our RtpStream to 10 if spatial layer changed.
if
(
this
->
targetSpatialLayer
!=
this
->
currentSpatialLayer
)
this
->
rtpStream
->
ResetScore
(
10
,
false
);
// If the new current spatial layer is the preferred one honor the preferred
// temporal layer.
if
(
this
->
targetSpatialLayer
==
this
->
preferredSpatialLayer
)
{
this
->
targetTemporalLayer
=
this
->
preferredTemporalLayer
;
}
// Otherwise, choose the highest temporal layer.
else
{
this
->
targetTemporalLayer
=
this
->
rtpStream
->
GetTemporalLayers
()
-
1
;
}
this
->
currentSpatialLayer
=
this
->
targetSpatialLayer
;
this
->
currentTemporalLayer
=
this
->
targetTemporalLayer
;
...
...
@@ -739,128 +763,29 @@ namespace RTC
{
MS_TRACE
();
uint8_t
maxProducerScore
{
0
};
int16_t
newTargetSpatialLayer
{
-
1
};
// No current spatial layer, select the highest possible.
if
(
this
->
currentSpatialLayer
==
-
1
)
for
(
size_t
idx
=
0
;
idx
<
this
->
producerRtpStreams
.
size
();
++
idx
)
{
MS_DEBUG_TAG
(
simulcast
,
"no current spatial layer, selecting the highest possible"
);
auto
spatialLayer
=
static_cast
<
int16_t
>
(
idx
);
auto
*
producerRtpStream
=
this
->
producerRtpStreams
[
idx
];
auto
producerScore
=
producerRtpStream
?
producerRtpStream
->
GetScore
()
:
0
;
uint8_t
maxScore
=
0
;
// Ignore spatial layers for non existing Producer streams or for those
// with score 0.
if
(
producerScore
==
0
)
continue
;
// Ignore spatial layers higher than the preferred one.
for
(
int
idx
=
this
->
preferredSpatialLayer
;
idx
>=
0
;
--
idx
)
if
(
producerScore
>=
maxProducerScore
)
{
auto
spatialLayer
=
static_cast
<
int16_t
>
(
idx
);
auto
*
producerRtpStream
=
this
->
producerRtpStreams
[
idx
];
// Ignore spatial layers for non existing Producer streams.
if
(
!
producerRtpStream
)
continue
;
if
(
producerRtpStream
->
GetScore
()
>=
maxScore
)
{
maxScore
=
producerRtpStream
->
GetScore
();
newTargetSpatialLayer
=
spatialLayer
;
if
(
maxScore
>
7
)
{
MS_DEBUG_TAG
(
simulcast
,
"found Producer RtpStream with score > 7, keep it"
);
break
;
}
}
}
}
// Downgrade is desired.
else
if
(
this
->
preferredSpatialLayer
<
this
->
currentSpatialLayer
)
{
MS_DEBUG_TAG
(
simulcast
,
"trying to downgrade current spatial layer to preferred one"
);
int16_t
idx
=
this
->
preferredSpatialLayer
;
uint8_t
maxScore
=
0
;
for
(;
idx
<
this
->
currentSpatialLayer
;
++
idx
)
{
auto
spatialLayer
=
static_cast
<
int16_t
>
(
idx
);
auto
*
producerRtpStream
=
this
->
producerRtpStreams
[
idx
];
// Ignore spatial layers for non existing Producer streams.
if
(
!
producerRtpStream
)
continue
;
if
(
producerRtpStream
->
GetScore
()
>=
maxScore
)
{
maxScore
=
producerRtpStream
->
GetScore
();
newTargetSpatialLayer
=
spatialLayer
;
if
(
maxScore
>
7
)
{
MS_DEBUG_TAG
(
simulcast
,
"found Producer RtpStream with score > 7, keep it"
);
break
;
}
}
}
}
// Downgrade is needed.
else
if
(
!
this
->
GetProducerCurrentRtpStream
()
||
this
->
GetProducerCurrentRtpStream
()
->
GetScore
()
<
7
||
this
->
rtpStream
->
GetScore
()
<=
6
)
{
MS_DEBUG_TAG
(
simulcast
,
"trying to downgrade current spatial layer"
);
uint8_t
maxScore
=
0
;
for
(
int
idx
=
this
->
currentSpatialLayer
-
1
;
idx
>=
0
;
--
idx
)
{
auto
spatialLayer
=
static_cast
<
int16_t
>
(
idx
);
auto
*
producerRtpStream
=
this
->
producerRtpStreams
[
idx
];
// Ignore spatial layers for non existing Producer streams.
if
(
!
producerRtpStream
)
continue
;
if
(
producerRtpStream
->
GetScore
()
>=
maxScore
)
{
maxScore
=
producerRtpStream
->
GetScore
();
newTargetSpatialLayer
=
spatialLayer
;
if
(
maxScore
>
7
)
{
MS_DEBUG_TAG
(
simulcast
,
"found Producer RtpStream with score > 7, keep it"
);
break
;
}
}
}
}
// Update to the highest possible spatial layer.
else
{
MS_DEBUG_TAG
(
simulcast
,
"trying to upgrade current spatial layer"
);
int16_t
idx
=
this
->
currentSpatialLayer
==
-
1
?
0
:
this
->
currentSpatialLayer
+
1
;
// Ignore spatial layers above the preferred one.
for
(;
idx
<=
this
->
preferredSpatialLayer
;
++
idx
)
{
auto
spatialLayer
=
idx
;
auto
*
producerRtpStream
=
this
->
producerRtpStreams
[
idx
];
// Ignore spatial layers for non existing Producer streams.
if
(
!
producerRtpStream
)
continue
;
// Take this as the new target if it is good enough.
if
(
producerRtpStream
->
GetScore
()
>=
7
)
{
MS_DEBUG_TAG
(
simulcast
,
"good enough spatial layer found: %"
PRIi16
,
spatialLayer
);
newTargetSpatialLayer
=
spatialLayer
;
maxProducerScore
=
producerScore
;
newTargetSpatialLayer
=
spatialLayer
;
// If this is the preferred or higher spatial layer and has good score,
// take it and exit.
if
(
spatialLayer
>=
this
->
preferredSpatialLayer
&&
maxProducerScore
>=
7
)
break
;
}
}
}
...
...
@@ -872,7 +797,20 @@ namespace RTC
if
(
newTargetSpatialLayer
==
-
1
)
{
MS_DEBUG_TAG
(
simulcast
,
"newTargetSpatialLayer remains unset"
);
MS_DEBUG_TAG
(
simulcast
,
"no valid spatial layer found"
);
// Unset current and target layers.
this
->
targetSpatialLayer
=
-
1
;
this
->
currentSpatialLayer
=
-
1
;
this
->
targetTemporalLayer
=
-
1
;
this
->
currentTemporalLayer
=
-
1
;
if
(
this
->
encodingContext
)
{
this
->
encodingContext
->
preferences
.
temporalLayer
=
this
->
rtpStream
->
GetTemporalLayers
()
-
1
;
}
// TODO: Emit JS event?
return
;
}
...
...
@@ -883,17 +821,17 @@ namespace RTC
this
->
targetSpatialLayer
=
newTargetSpatialLayer
;
// Already using the target layer. Do nothing.
if
(
this
->
targetSpatialLayer
==
this
->
currentSpatialLayer
)
return
;
RequestKeyFrame
();
MS_DEBUG_TAG
(
simulcast
,
"target spatial layer changed to %"
PRIi16
" [consumerId:%s]"
,
this
->
targetSpatialLayer
,
this
->
id
.
c_str
());
// Already using the target layer. Do nothing.
if
(
this
->
targetSpatialLayer
==
this
->
currentSpatialLayer
)
return
;
RequestKeyFrame
();
}
inline
RTC
::
RtpStream
*
SimulcastConsumer
::
GetProducerCurrentRtpStream
()
const
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
529538ae
...
...
@@ -826,7 +826,7 @@ namespace RTC
}
inline
void
Transport
::
OnProducerNewRtpStream
(
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
uint32_t
mappedSsrc
)
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
{
MS_TRACE
();
...
...
@@ -834,7 +834,7 @@ namespace RTC
}
inline
void
Transport
::
OnProducerRtpStreamScore
(
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
Recv
*
rtpStream
,
uint8_t
score
)
RTC
::
Producer
*
producer
,
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
)
{
MS_TRACE
();
...
...
worker/test/src/RTC/TestNackGenerator.cpp
浏览文件 @
529538ae
...
...
@@ -51,6 +51,10 @@ public:
{
return
this
->
isKeyFrame
;
};
uint8_t
GetTemporalLayer
()
const
{
return
0
;
};
private
:
bool
isKeyFrame
{
false
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论