Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
d6632c9a
提交
d6632c9a
authored
11月 17, 2019
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP: Working on Consumer bitrate priority and new bitrate distribution logic
上级
3bae47a1
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
43 行增加
和
136 行删除
+43
-136
Consumer.hpp
worker/include/RTC/Consumer.hpp
+1
-1
PipeConsumer.hpp
worker/include/RTC/PipeConsumer.hpp
+1
-1
SimpleConsumer.hpp
worker/include/RTC/SimpleConsumer.hpp
+1
-1
SimulcastConsumer.hpp
worker/include/RTC/SimulcastConsumer.hpp
+1
-1
SvcConsumer.hpp
worker/include/RTC/SvcConsumer.hpp
+1
-1
PipeConsumer.cpp
worker/src/RTC/PipeConsumer.cpp
+1
-1
SimpleConsumer.cpp
worker/src/RTC/SimpleConsumer.cpp
+14
-3
SimulcastConsumer.cpp
worker/src/RTC/SimulcastConsumer.cpp
+7
-38
SvcConsumer.cpp
worker/src/RTC/SvcConsumer.cpp
+4
-32
Transport.cpp
worker/src/RTC/Transport.cpp
+12
-57
没有找到文件。
worker/include/RTC/Consumer.hpp
浏览文件 @
d6632c9a
...
...
@@ -79,7 +79,7 @@ namespace RTC
virtual
void
ProducerRtcpSenderReport
(
RTC
::
RtpStream
*
rtpStream
,
bool
first
)
=
0
;
void
ProducerClosed
();
void
SetExternallyManagedBitrate
();
virtual
uint
16_t
GetBitratePriority
()
const
=
0
;
virtual
uint
8_t
GetBitratePriority
()
const
=
0
;
virtual
uint32_t
UseAvailableBitrate
(
uint32_t
bitrate
,
bool
considerLoss
)
=
0
;
virtual
uint32_t
IncreaseLayer
(
uint32_t
bitrate
,
bool
considerLoss
)
=
0
;
virtual
void
ApplyLayers
()
=
0
;
...
...
worker/include/RTC/PipeConsumer.hpp
浏览文件 @
d6632c9a
...
...
@@ -22,7 +22,7 @@ namespace RTC
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
,
uint8_t
previousScore
)
override
;
void
ProducerRtcpSenderReport
(
RTC
::
RtpStream
*
rtpStream
,
bool
first
)
override
;
uint
16
_t
GetBitratePriority
()
const
override
;
uint
8
_t
GetBitratePriority
()
const
override
;
uint32_t
UseAvailableBitrate
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
uint32_t
IncreaseLayer
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
void
ApplyLayers
()
override
;
...
...
worker/include/RTC/SimpleConsumer.hpp
浏览文件 @
d6632c9a
...
...
@@ -23,7 +23,7 @@ namespace RTC
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
,
uint8_t
previousScore
)
override
;
void
ProducerRtcpSenderReport
(
RTC
::
RtpStream
*
rtpStream
,
bool
first
)
override
;
uint
16
_t
GetBitratePriority
()
const
override
;
uint
8
_t
GetBitratePriority
()
const
override
;
uint32_t
UseAvailableBitrate
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
uint32_t
IncreaseLayer
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
void
ApplyLayers
()
override
;
...
...
worker/include/RTC/SimulcastConsumer.hpp
浏览文件 @
d6632c9a
...
...
@@ -24,7 +24,7 @@ namespace RTC
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
,
uint8_t
previousScore
)
override
;
void
ProducerRtcpSenderReport
(
RTC
::
RtpStream
*
rtpStream
,
bool
first
)
override
;
uint
16
_t
GetBitratePriority
()
const
override
;
uint
8
_t
GetBitratePriority
()
const
override
;
uint32_t
UseAvailableBitrate
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
uint32_t
IncreaseLayer
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
void
ApplyLayers
()
override
;
...
...
worker/include/RTC/SvcConsumer.hpp
浏览文件 @
d6632c9a
...
...
@@ -25,7 +25,7 @@ namespace RTC
void
ProducerNewRtpStream
(
RTC
::
RtpStream
*
rtpStream
,
uint32_t
mappedSsrc
)
override
;
void
ProducerRtpStreamScore
(
RTC
::
RtpStream
*
rtpStream
,
uint8_t
score
,
uint8_t
previousScore
)
override
;
void
ProducerRtcpSenderReport
(
RTC
::
RtpStream
*
rtpStream
,
bool
first
)
override
;
uint
16
_t
GetBitratePriority
()
const
override
;
uint
8
_t
GetBitratePriority
()
const
override
;
uint32_t
UseAvailableBitrate
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
uint32_t
IncreaseLayer
(
uint32_t
bitrate
,
bool
considerLoss
)
override
;
void
ApplyLayers
()
override
;
...
...
worker/src/RTC/PipeConsumer.cpp
浏览文件 @
d6632c9a
...
...
@@ -135,7 +135,7 @@ namespace RTC
// Do nothing.
}
uint
16
_t
PipeConsumer
::
GetBitratePriority
()
const
uint
8
_t
PipeConsumer
::
GetBitratePriority
()
const
{
MS_TRACE
();
...
...
worker/src/RTC/SimpleConsumer.cpp
浏览文件 @
d6632c9a
...
...
@@ -136,12 +136,23 @@ namespace RTC
// Do nothing.
}
uint
16
_t
SimpleConsumer
::
GetBitratePriority
()
const
uint
8
_t
SimpleConsumer
::
GetBitratePriority
()
const
{
MS_TRACE
();
// SimpleConsumer does not play the BWE game.
return
0u
;
// Audio SimpleConsumer does not play the BWE game.
if
(
this
->
kind
!=
RTC
::
Media
::
Kind
::
VIDEO
)
return
0u
;
// TODO: Yes?
MS_ASSERT
(
this
->
externallyManagedBitrate
,
"bitrate is not externally managed"
);
if
(
!
IsActive
())
return
0u
;
// TODO: Use app given priority.
return
1u
;
}
uint32_t
SimpleConsumer
::
UseAvailableBitrate
(
uint32_t
/*bitrate*/
,
bool
/*considerLoss*/
)
...
...
worker/src/RTC/SimulcastConsumer.cpp
浏览文件 @
d6632c9a
...
...
@@ -332,45 +332,18 @@ namespace RTC
MayChangeLayers
();
}
uint
16
_t
SimulcastConsumer
::
GetBitratePriority
()
const
uint
8
_t
SimulcastConsumer
::
GetBitratePriority
()
const
{
MS_TRACE
();
MS_ASSERT
(
this
->
externallyManagedBitrate
,
"bitrate is not externally managed"
);
if
(
!
RTC
::
Consumer
::
IsActive
())
if
(
!
IsActive
())
return
0u
;
int16_t
prioritySpatialLayer
{
-
1
};
for
(
size_t
sIdx
{
0u
};
sIdx
<
this
->
producerRtpStreams
.
size
();
++
sIdx
)
{
auto
spatialLayer
=
static_cast
<
int16_t
>
(
sIdx
);
// Do not choose a layer greater than the preferred one if we already found
// an available layer equal or less than the preferred one.
if
(
spatialLayer
>
this
->
preferredSpatialLayer
&&
prioritySpatialLayer
!=
-
1
)
break
;
auto
*
producerRtpStream
=
this
->
producerRtpStreams
.
at
(
sIdx
);
// Ignore spatial layers for non existing Producer streams or for those
// with score 0.
if
(
!
producerRtpStream
||
producerRtpStream
->
GetScore
()
==
0
)
continue
;
// Choose this layer for now.
prioritySpatialLayer
=
spatialLayer
;
}
// If no spatial layer was chosen (because all producer streams were inactive),
// we have to return >0 anyway. Otherwise UseAvailableBitrate() won't be called
// and we could never switch to target & current spatial -1.
if
(
prioritySpatialLayer
==
-
1
)
return
1u
;
// TODO: Use app given priority.
// Return the choosen spatial layer plus one.
return
static_cast
<
uint16_t
>
(
prioritySpatialLayer
+
1
);
return
1u
;
}
uint32_t
SimulcastConsumer
::
UseAvailableBitrate
(
uint32_t
bitrate
,
bool
considerLoss
)
...
...
@@ -553,9 +526,7 @@ namespace RTC
MS_TRACE
();
MS_ASSERT
(
this
->
externallyManagedBitrate
,
"bitrate is not externally managed"
);
if
(
!
RTC
::
Consumer
::
IsActive
())
return
0u
;
MS_ASSERT
(
IsActive
(),
"should be active (Consumer::IsActive())"
);
// If already in the preferred layers, do nothing.
// clang-format off
...
...
@@ -657,7 +628,7 @@ namespace RTC
requiredBitrate
=
producerRtpStream
->
GetLayerBitrate
(
nowMs
,
0
,
temporalLayer
);
// This is simulcast so we must substra
x
ct the bitrate of the current temporal
// This is simulcast so we must substract the bitrate of the current temporal
// spatial layer if this is the temporal layer 0 of a higher spatial layer.
//
// clang-format off
...
...
@@ -728,6 +699,7 @@ namespace RTC
MS_TRACE
();
MS_ASSERT
(
this
->
externallyManagedBitrate
,
"bitrate is not externally managed"
);
MS_ASSERT
(
RTC
::
Consumer
::
IsActive
(),
"should be active (Consumer::IsActive())"
);
auto
provisionalTargetSpatialLayer
=
this
->
provisionalTargetSpatialLayer
;
auto
provisionalTargetTemporalLayer
=
this
->
provisionalTargetTemporalLayer
;
...
...
@@ -736,9 +708,6 @@ namespace RTC
this
->
provisionalTargetSpatialLayer
=
-
1
;
this
->
provisionalTargetTemporalLayer
=
-
1
;
if
(
!
RTC
::
Consumer
::
IsActive
())
return
;
// clang-format off
if
(
provisionalTargetSpatialLayer
!=
this
->
targetSpatialLayer
||
...
...
worker/src/RTC/SvcConsumer.cpp
浏览文件 @
d6632c9a
...
...
@@ -292,46 +292,18 @@ namespace RTC
// Do nothing.
}
uint
16
_t
SvcConsumer
::
GetBitratePriority
()
const
uint
8
_t
SvcConsumer
::
GetBitratePriority
()
const
{
MS_TRACE
();
MS_ASSERT
(
this
->
externallyManagedBitrate
,
"bitrate is not externally managed"
);
if
(
!
RTC
::
Consumer
::
IsActive
())
return
0u
;
// Return a 0 priority if score of producer stream is 0.
if
(
!
this
->
producerRtpStream
||
this
->
producerRtpStream
->
GetScore
()
==
0u
)
if
(
!
IsActive
())
return
0u
;
auto
nowMs
=
DepLibUV
::
GetTimeMs
();
int16_t
prioritySpatialLayer
{
-
1
};
int16_t
spatialLayer
{
0
};
for
(;
spatialLayer
<
this
->
producerRtpStream
->
GetSpatialLayers
();
++
spatialLayer
)
{
// Do not choose a layer greater than the preferred one if we already found
// an available layer equal or less than the preferred one.
if
(
spatialLayer
>
this
->
preferredSpatialLayer
&&
prioritySpatialLayer
!=
-
1
)
break
;
// Ignore spatial layers with 0 bitrate.
if
(
this
->
producerRtpStream
->
GetSpatialLayerBitrate
(
nowMs
,
spatialLayer
)
==
0u
)
continue
;
// Choose this layer for now.
prioritySpatialLayer
=
spatialLayer
;
}
// If no spatial layer was chosen (because the producer stream was inactive),
// we have to return >0 anyway. Otherwise UseAvailableBitrate() won't be called
// and we could never switch to target & current spatial -1.
if
(
prioritySpatialLayer
==
-
1
)
return
1u
;
// TODO: Use app given priority.
// Return the choosen spatial layer plus one.
return
static_cast
<
uint16_t
>
(
prioritySpatialLayer
+
1
);
return
1u
;
}
uint32_t
SvcConsumer
::
UseAvailableBitrate
(
uint32_t
bitrate
,
bool
considerLoss
)
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
d6632c9a
...
...
@@ -1957,8 +1957,7 @@ namespace RTC
MS_ASSERT
(
this
->
tccClient
,
"no TransportCongestionClient"
);
std
::
multimap
<
uint16_t
,
RTC
::
Consumer
*>
multimapPriorityConsumer
;
uint16_t
totalPriorities
{
0u
};
std
::
multimap
<
uint8_t
,
RTC
::
Consumer
*>
multimapPriorityConsumer
;
// Fill the map with Consumers and their priority (if > 0).
for
(
auto
&
kv
:
this
->
mapConsumers
)
...
...
@@ -1967,14 +1966,11 @@ namespace RTC
auto
priority
=
consumer
->
GetBitratePriority
();
if
(
priority
>
0u
)
{
multimapPriorityConsumer
.
emplace
(
priority
,
consumer
);
totalPriorities
+=
priority
;
}
}
// Nobody wants bitrate. Exit.
if
(
totalPriorities
==
0u
)
if
(
multimapPriorityConsumer
.
empty
()
)
return
;
uint32_t
availableBitrate
=
this
->
tccClient
->
GetAvailableBitrate
();
...
...
@@ -1983,48 +1979,11 @@ namespace RTC
MS_DEBUG_DEV
(
"before iterations [availableBitrate:%"
PRIu32
"]"
,
availableBitrate
);
uint32_t
remainingBitrate
=
availableBitrate
;
// First of all, redistribute the available bitrate by taking into account
// Consumers' priorities.
for
(
auto
it
=
multimapPriorityConsumer
.
rbegin
();
it
!=
multimapPriorityConsumer
.
rend
();
++
it
)
{
auto
priority
=
it
->
first
;
auto
*
consumer
=
it
->
second
;
uint32_t
bitrate
=
(
availableBitrate
*
priority
)
/
totalPriorities
;
MS_DEBUG_DEV
(
"main bitrate for Consumer [priority:%"
PRIu16
", bitrate:%"
PRIu32
", consumerId:%s]"
,
priority
,
bitrate
,
consumer
->
id
.
c_str
());
uint32_t
usedBitrate
;
auto
bweType
=
this
->
tccClient
->
GetBweType
();
switch
(
bweType
)
{
case
RTC
:
:
BweType
::
TRANSPORT_CC
:
usedBitrate
=
consumer
->
UseAvailableBitrate
(
bitrate
,
/*considerLoss*/
false
);
break
;
case
RTC
:
:
BweType
::
REMB
:
usedBitrate
=
consumer
->
UseAvailableBitrate
(
bitrate
,
/*considerLoss*/
true
);
break
;
}
if
(
usedBitrate
<=
remainingBitrate
)
remainingBitrate
-=
usedBitrate
;
else
remainingBitrate
=
0u
;
}
MS_DEBUG_DEV
(
"after first main iteration [remainingBitrate:%"
PRIu32
"]"
,
remainingBitrate
);
// Then redistribute the remaining bitrate by allowing Consumers to increase
// Redistribute the available bitrate by allowing Consumers to increase
// layer by layer.
while
(
remainingBitrate
>=
200
0u
)
while
(
availableBitrate
>
0u
)
{
auto
previous
RemainingBitrate
=
remaining
Bitrate
;
auto
previous
AvailableBitrate
=
available
Bitrate
;
for
(
auto
it
=
multimapPriorityConsumer
.
rbegin
();
it
!=
multimapPriorityConsumer
.
rend
();
++
it
)
{
...
...
@@ -2032,7 +1991,7 @@ namespace RTC
MS_DEBUG_DEV
(
"layer bitrate for Consumer [bitrate:%"
PRIu32
", consumerId:%s]"
,
remaining
Bitrate
,
available
Bitrate
,
consumer
->
id
.
c_str
());
uint32_t
usedBitrate
;
...
...
@@ -2041,27 +2000,23 @@ namespace RTC
switch
(
bweType
)
{
case
RTC
:
:
BweType
::
TRANSPORT_CC
:
usedBitrate
=
consumer
->
IncreaseLayer
(
remaining
Bitrate
,
/*considerLoss*/
false
);
usedBitrate
=
consumer
->
IncreaseLayer
(
available
Bitrate
,
/*considerLoss*/
false
);
break
;
case
RTC
:
:
BweType
::
REMB
:
usedBitrate
=
consumer
->
IncreaseLayer
(
remaining
Bitrate
,
/*considerLoss*/
true
);
usedBitrate
=
consumer
->
IncreaseLayer
(
available
Bitrate
,
/*considerLoss*/
true
);
}
MS_ASSERT
(
usedBitrate
<=
remaining
Bitrate
,
"Consumer used more layer bitrate than given"
);
MS_ASSERT
(
usedBitrate
<=
available
Bitrate
,
"Consumer used more layer bitrate than given"
);
remainingBitrate
-=
usedBitrate
;
// No more.
if
(
remainingBitrate
<
2000u
)
break
;
availableBitrate
-=
usedBitrate
;
}
// If no Consumer used bitrate, exit the loop.
if
(
remainingBitrate
==
previousRemaining
Bitrate
)
if
(
availableBitrate
==
previousAvailable
Bitrate
)
break
;
}
MS_DEBUG_DEV
(
"after layer-by-layer iteration [
remainingBitrate:%"
PRIu32
"]"
,
remaining
Bitrate
);
MS_DEBUG_DEV
(
"after layer-by-layer iteration [
availableBitrate:%"
PRIu32
"]"
,
available
Bitrate
);
// Finally instruct Consumers to apply their computed layers.
for
(
auto
it
=
multimapPriorityConsumer
.
rbegin
();
it
!=
multimapPriorityConsumer
.
rend
();
++
it
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论