Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
58903ebf
提交
58903ebf
authored
4月 05, 2019
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Properly transmit scalabilityMode to Consumers by mangling spatial layers if simulcast
上级
3d9c41c8
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
73 行增加
和
107 行删除
+73
-107
ortc.js
lib/ortc.js
+29
-7
test-ortc.js
test/test-ortc.js
+27
-6
RtpEncodingParameters.cpp
worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp
+17
-94
没有找到文件。
lib/ortc.js
浏览文件 @
58903ebf
...
@@ -3,7 +3,7 @@ const utils = require('./utils');
...
@@ -3,7 +3,7 @@ const utils = require('./utils');
const
{
UnsupportedError
}
=
require
(
'./errors'
);
const
{
UnsupportedError
}
=
require
(
'./errors'
);
const
supportedRtpCapabilities
=
require
(
'./supportedRtpCapabilities'
);
const
supportedRtpCapabilities
=
require
(
'./supportedRtpCapabilities'
);
const
D
YNAMIC_PAYLOAD_TYPES
=
const
D
ynamicPayloadTypes
=
[
[
100
,
101
,
102
,
103
,
104
,
105
,
106
,
107
,
108
,
109
,
110
,
111
,
112
,
113
,
114
,
115
,
100
,
101
,
102
,
103
,
104
,
105
,
106
,
107
,
108
,
109
,
110
,
111
,
112
,
113
,
114
,
115
,
116
,
117
,
118
,
119
,
120
,
121
,
122
,
123
,
124
,
125
,
126
,
127
,
96
,
97
,
98
,
99
,
77
,
116
,
117
,
118
,
119
,
120
,
121
,
122
,
123
,
124
,
125
,
126
,
127
,
96
,
97
,
98
,
99
,
77
,
...
@@ -12,6 +12,8 @@ const DYNAMIC_PAYLOAD_TYPES =
...
@@ -12,6 +12,8 @@ const DYNAMIC_PAYLOAD_TYPES =
57
,
58
,
59
,
60
,
61
,
62
,
63
,
64
,
65
,
66
,
67
,
68
,
69
,
70
,
71
57
,
58
,
59
,
60
,
61
,
62
,
63
,
64
,
65
,
66
,
67
,
68
,
69
,
70
,
71
];
];
const
ScalabilityModeRegex
=
new
RegExp
(
'^L(
\\
d+)T(
\\
d+)'
);
/**
/**
* Generate RTP capabilities for the Router based on the given media codecs and
* Generate RTP capabilities for the Router based on the given media codecs and
* mediasoup supported RTP capabilities.
* mediasoup supported RTP capabilities.
...
@@ -72,7 +74,7 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
...
@@ -72,7 +74,7 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
// Assign a payload type.
// Assign a payload type.
if
(
typeof
codec
.
preferredPayloadType
!==
'number'
)
if
(
typeof
codec
.
preferredPayloadType
!==
'number'
)
{
{
const
pt
=
D
YNAMIC_PAYLOAD_TYPES
[
dynamicPayloadTypeIdx
++
];
const
pt
=
D
ynamicPayloadTypes
[
dynamicPayloadTypeIdx
++
];
if
(
!
pt
)
if
(
!
pt
)
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
...
@@ -86,7 +88,7 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
...
@@ -86,7 +88,7 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
// Add a RTX video codec if video.
// Add a RTX video codec if video.
if
(
codec
.
kind
===
'video'
)
if
(
codec
.
kind
===
'video'
)
{
{
const
pt
=
D
YNAMIC_PAYLOAD_TYPES
[
dynamicPayloadTypeIdx
++
];
const
pt
=
D
ynamicPayloadTypes
[
dynamicPayloadTypeIdx
++
];
if
(
!
pt
)
if
(
!
pt
)
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
...
@@ -123,7 +125,7 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
...
@@ -123,7 +125,7 @@ exports.generateRouterRtpCapabilities = function(mediaCodecs)
*
*
* @returns {Object} with codecs, headerExtensions and encodings arrays of objects.
* @returns {Object} with codecs, headerExtensions and encodings arrays of objects.
* Each codec has payloadType and mappedPayloadType.
* Each codec has payloadType and mappedPayloadType.
* Each encoding may have rid and/or ssrc, and mandatory mappedSsrc.
* Each encoding may have rid and/or ssrc,
scalabilityMode
and mandatory mappedSsrc.
* @throws {TypeError} if wrong arguments.
* @throws {TypeError} if wrong arguments.
* @throws {UnsupportedError} if codec not supported.
* @throws {UnsupportedError} if codec not supported.
* @throws {Error}
* @throws {Error}
...
@@ -210,15 +212,16 @@ exports.getProducerRtpParametersMapping = function(params, caps)
...
@@ -210,15 +212,16 @@ exports.getProducerRtpParametersMapping = function(params, caps)
// Generate encodings mapping.
// Generate encodings mapping.
for
(
const
encoding
of
(
params
.
encodings
||
[]))
for
(
const
encoding
of
(
params
.
encodings
||
[]))
{
{
const
mappedSsrc
=
utils
.
generateRandomNumber
();
const
mappedEncoding
=
{};
const
mappedEncoding
=
{};
mappedEncoding
.
mappedSsrc
=
utils
.
generateRandomNumber
();
if
(
encoding
.
rid
)
if
(
encoding
.
rid
)
mappedEncoding
.
rid
=
encoding
.
rid
;
mappedEncoding
.
rid
=
encoding
.
rid
;
if
(
encoding
.
ssrc
)
if
(
encoding
.
ssrc
)
mappedEncoding
.
ssrc
=
encoding
.
ssrc
;
mappedEncoding
.
ssrc
=
encoding
.
ssrc
;
if
(
mappedSsrc
)
if
(
encoding
.
scalabilityMode
)
mappedEncoding
.
mappedSsrc
=
mappedSsrc
;
mappedEncoding
.
scalabilityMode
=
encoding
.
scalabilityMode
;
rtpMapping
.
encodings
.
push
(
mappedEncoding
);
rtpMapping
.
encodings
.
push
(
mappedEncoding
);
}
}
...
@@ -465,6 +468,25 @@ exports.getConsumerRtpParameters = function(consumableParams, caps)
...
@@ -465,6 +468,25 @@ exports.getConsumerRtpParameters = function(consumableParams, caps)
if
(
rtxSupported
)
if
(
rtxSupported
)
consumerEncoding
.
rtx
=
{
ssrc
:
utils
.
generateRandomNumber
()
};
consumerEncoding
.
rtx
=
{
ssrc
:
utils
.
generateRandomNumber
()
};
// If any of the consumableParams.encodings has scalabilityMode, process it.
const
encodingWithScalabilityMode
=
consumableParams
.
encodings
.
find
((
encoding
)
=>
encoding
.
scalabilityMode
);
if
(
encodingWithScalabilityMode
)
{
let
scalabilityMode
=
encodingWithScalabilityMode
.
scalabilityMode
;
const
match
=
ScalabilityModeRegex
.
exec
(
scalabilityMode
);
if
(
match
)
{
// If there is simulast, mangle spatial layers.
if
(
consumableParams
.
encodings
.
length
>
1
)
scalabilityMode
=
`L
${
consumableParams
.
encodings
.
length
}
T
${
match
[
2
]}
`
;
consumerEncoding
.
scalabilityMode
=
scalabilityMode
;
}
}
consumerParams
.
encodings
.
push
(
consumerEncoding
);
consumerParams
.
encodings
.
push
(
consumerEncoding
);
// Copy verbatim.
// Copy verbatim.
...
...
test/test-ortc.js
浏览文件 @
58903ebf
...
@@ -264,9 +264,23 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -264,9 +264,23 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
],
],
encodings
:
encodings
:
[
[
{
ssrc
:
11111111
,
rtx
:
{
ssrc
:
11111112
},
maxBitrate
:
111111
},
{
{
ssrc
:
21111111
,
rtx
:
{
ssrc
:
21111112
},
maxBitrate
:
222222
},
ssrc
:
11111111
,
{
rid
:
'high'
,
maxBitrate
:
333333
}
rtx
:
{
ssrc
:
11111112
},
maxBitrate
:
111111
,
scalabilityMode
:
'L1T3'
},
{
ssrc
:
21111111
,
rtx
:
{
ssrc
:
21111112
},
maxBitrate
:
222222
,
scalabilityMode
:
'L1T3'
},
{
rid
:
'high'
,
maxBitrate
:
333333
,
scalabilityMode
:
'L1T3'
}
],
],
rtcp
:
rtcp
:
{
{
...
@@ -314,17 +328,20 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -314,17 +328,20 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
expect
(
consumableRtpParameters
.
encodings
[
0
]).
toEqual
(
expect
(
consumableRtpParameters
.
encodings
[
0
]).
toEqual
(
{
{
ssrc
:
rtpMapping
.
encodings
[
0
].
mappedSsrc
,
ssrc
:
rtpMapping
.
encodings
[
0
].
mappedSsrc
,
maxBitrate
:
111111
maxBitrate
:
111111
,
scalabilityMode
:
'L1T3'
});
});
expect
(
consumableRtpParameters
.
encodings
[
1
]).
toEqual
(
expect
(
consumableRtpParameters
.
encodings
[
1
]).
toEqual
(
{
{
ssrc
:
rtpMapping
.
encodings
[
1
].
mappedSsrc
,
ssrc
:
rtpMapping
.
encodings
[
1
].
mappedSsrc
,
maxBitrate
:
222222
maxBitrate
:
222222
,
scalabilityMode
:
'L1T3'
});
});
expect
(
consumableRtpParameters
.
encodings
[
2
]).
toEqual
(
expect
(
consumableRtpParameters
.
encodings
[
2
]).
toEqual
(
{
{
ssrc
:
rtpMapping
.
encodings
[
2
].
mappedSsrc
,
ssrc
:
rtpMapping
.
encodings
[
2
].
mappedSsrc
,
maxBitrate
:
333333
maxBitrate
:
333333
,
scalabilityMode
:
'L1T3'
});
});
expect
(
consumableRtpParameters
.
rtcp
).
toEqual
(
expect
(
consumableRtpParameters
.
rtcp
).
toEqual
(
...
@@ -453,6 +470,7 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -453,6 +470,7 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
expect
(
consumerRtpParameters
.
encodings
[
0
].
ssrc
).
toBeType
(
'number'
);
expect
(
consumerRtpParameters
.
encodings
[
0
].
ssrc
).
toBeType
(
'number'
);
expect
(
consumerRtpParameters
.
encodings
[
0
].
rtx
).
toBeType
(
'object'
);
expect
(
consumerRtpParameters
.
encodings
[
0
].
rtx
).
toBeType
(
'object'
);
expect
(
consumerRtpParameters
.
encodings
[
0
].
rtx
.
ssrc
).
toBeType
(
'number'
);
expect
(
consumerRtpParameters
.
encodings
[
0
].
rtx
.
ssrc
).
toBeType
(
'number'
);
expect
(
consumerRtpParameters
.
encodings
[
0
].
scalabilityMode
).
toBe
(
'L3T3'
);
expect
(
consumerRtpParameters
.
headerExtensions
).
toEqual
(
expect
(
consumerRtpParameters
.
headerExtensions
).
toEqual
(
[
[
...
@@ -499,12 +517,15 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -499,12 +517,15 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
expect
(
pipeConsumerRtpParameters
.
encodings
[
0
].
ssrc
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
0
].
ssrc
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
0
].
rtx
).
toBe
(
undefined
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
0
].
rtx
).
toBe
(
undefined
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
0
].
maxBitrate
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
0
].
maxBitrate
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
0
].
scalabilityMode
).
toBe
(
'L1T3'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
1
].
ssrc
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
1
].
ssrc
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
1
].
rtx
).
toBe
(
undefined
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
1
].
rtx
).
toBe
(
undefined
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
1
].
maxBitrate
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
1
].
maxBitrate
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
1
].
scalabilityMode
).
toBe
(
'L1T3'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
2
].
ssrc
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
2
].
ssrc
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
2
].
rtx
).
toBe
(
undefined
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
2
].
rtx
).
toBe
(
undefined
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
2
].
maxBitrate
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
2
].
maxBitrate
).
toBeType
(
'number'
);
expect
(
pipeConsumerRtpParameters
.
encodings
[
2
].
scalabilityMode
).
toBe
(
'L1T3'
);
expect
(
pipeConsumerRtpParameters
.
rtcp
).
toEqual
(
expect
(
pipeConsumerRtpParameters
.
rtcp
).
toEqual
(
{
{
...
...
worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp
浏览文件 @
58903ebf
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include "Logger.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpDictionaries.hpp"
#include <exception>
#include <regex>
namespace
RTC
namespace
RTC
{
{
...
@@ -63,106 +65,27 @@ namespace RTC
...
@@ -63,106 +65,27 @@ namespace RTC
// scalabilityMode is optional.
// scalabilityMode is optional.
if
(
jsonScalabilityModeIt
!=
data
.
end
()
&&
jsonScalabilityModeIt
->
is_string
())
if
(
jsonScalabilityModeIt
!=
data
.
end
()
&&
jsonScalabilityModeIt
->
is_string
())
{
{
this
->
scalabilityMode
=
jsonScalabilityModeIt
->
get
<
std
::
string
>
();
std
::
string
scalabilityMode
=
jsonScalabilityModeIt
->
get
<
std
::
string
>
();
if
(
this
->
scalabilityMode
==
"L1T2"
)
static
const
std
::
regex
ScalabilityModeRegex
(
"^L(
\\
d+)T(
\\
d+)"
);
{
this
->
spatialLayers
=
1
;
std
::
smatch
match
;
this
->
temporalLayers
=
2
;
}
std
::
regex_match
(
scalabilityMode
,
match
,
ScalabilityModeRegex
);
else
if
(
this
->
scalabilityMode
==
"L1T3"
)
{
if
(
match
.
size
()
>
0
)
this
->
spatialLayers
=
1
;
this
->
temporalLayers
=
3
;
}
else
if
(
this
->
scalabilityMode
==
"L2T1"
)
{
this
->
spatialLayers
=
2
;
this
->
temporalLayers
=
1
;
}
else
if
(
this
->
scalabilityMode
==
"L2T2"
)
{
this
->
spatialLayers
=
2
;
this
->
temporalLayers
=
2
;
}
else
if
(
this
->
scalabilityMode
==
"L2T3"
)
{
this
->
spatialLayers
=
2
;
this
->
temporalLayers
=
3
;
}
else
if
(
this
->
scalabilityMode
==
"L3T1"
)
{
this
->
spatialLayers
=
3
;
this
->
temporalLayers
=
1
;
}
else
if
(
this
->
scalabilityMode
==
"L3T2"
)
{
this
->
spatialLayers
=
3
;
this
->
temporalLayers
=
2
;
}
else
if
(
this
->
scalabilityMode
==
"L3T3"
)
{
this
->
spatialLayers
=
3
;
this
->
temporalLayers
=
3
;
}
else
if
(
this
->
scalabilityMode
==
"L2T1h"
)
{
this
->
spatialLayers
=
2
;
this
->
temporalLayers
=
1
;
}
else
if
(
this
->
scalabilityMode
==
"L2T2h"
)
{
this
->
spatialLayers
=
2
;
this
->
temporalLayers
=
2
;
}
else
if
(
this
->
scalabilityMode
==
"L2T3h"
)
{
this
->
spatialLayers
=
2
;
this
->
temporalLayers
=
3
;
}
else
if
(
this
->
scalabilityMode
==
"L3T2_KEY"
)
{
this
->
spatialLayers
=
3
;
this
->
temporalLayers
=
2
;
}
else
if
(
this
->
scalabilityMode
==
"L3T3_KEY"
)
{
this
->
spatialLayers
=
3
;
this
->
temporalLayers
=
3
;
}
else
if
(
this
->
scalabilityMode
==
"L4T5_KEY"
)
{
this
->
spatialLayers
=
4
;
this
->
temporalLayers
=
5
;
}
else
if
(
this
->
scalabilityMode
==
"L4T7_KEY"
)
{
this
->
spatialLayers
=
4
;
this
->
temporalLayers
=
7
;
}
else
if
(
this
->
scalabilityMode
==
"L3T2_KEY_SHIFT"
)
{
this
->
spatialLayers
=
3
;
this
->
temporalLayers
=
2
;
}
else
if
(
this
->
scalabilityMode
==
"L3T3_KEY_SHIFT"
)
{
{
this
->
spatialLayers
=
3
;
this
->
scalabilityMode
=
scalabilityMode
;
this
->
temporalLayers
=
3
;
}
try
else
if
(
this
->
scalabilityMode
==
"L4T5_KEY_SHIFT"
)
{
{
this
->
spatialLayers
=
4
;
this
->
spatialLayers
=
std
::
stoul
(
match
[
1
].
str
())
;
this
->
temporalLayers
=
5
;
this
->
temporalLayers
=
std
::
stoul
(
match
[
2
].
str
())
;
}
}
else
if
(
this
->
scalabilityMode
==
"L4T7_KEY_SHIFT"
)
catch
(
std
::
exception
&
e
)
{
{
this
->
spatialLayers
=
4
;
MS_THROW_TYPE_ERROR
(
"invalid scalabilityMode: %s"
,
e
.
what
());
this
->
temporalLayers
=
7
;
}
}
else
{
MS_THROW_TYPE_ERROR
(
"invalid scalabilityMode"
);
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论