Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
e51c3af8
提交
e51c3af8
authored
1月 11, 2020
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ortc.ts: Add functions to validate RTP/SCTP parameters
上级
7971dcd0
显示空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
1272 行增加
和
355 行删除
+1272
-355
Transport.d.ts.map
lib/Transport.d.ts.map
+2
-2
Transport.js
lib/Transport.js
+11
-8
ortc.d.ts
lib/ortc.d.ts
+81
-2
ortc.d.ts.map
lib/ortc.d.ts.map
+2
-2
ortc.js
lib/ortc.js
+422
-84
supportedRtpCapabilities.d.ts.map
lib/supportedRtpCapabilities.d.ts.map
+2
-2
supportedRtpCapabilities.js
lib/supportedRtpCapabilities.js
+1
-2
Transport.ts
src/Transport.ts
+17
-8
ortc.ts
src/ortc.ts
+550
-116
supportedRtpCapabilities.ts
src/supportedRtpCapabilities.ts
+1
-2
test-Consumer.js
test/test-Consumer.js
+24
-23
test-PipeTransport.js
test/test-PipeTransport.js
+61
-30
test-PlainRtpTransport.js
test/test-PlainRtpTransport.js
+2
-2
test-Producer.js
test/test-Producer.js
+2
-2
test-Router.js
test/test-Router.js
+2
-3
test-ortc.js
test/test-ortc.js
+92
-67
没有找到文件。
lib/Transport.d.ts.map
浏览文件 @
e51c3af8
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D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C,QAAQ,CAAC;IA2DpB;;OAEG;IACG,WAAW,CAChB,EACC,EAAc,EACd,oBAAoB,EACpB,KAAU,EACV,QAAa,EACb,OAAY,EACZ,EAAE,mBAAmB,GACpB,OAAO,CAAC,YAAY,CAAC;IAyCxB;;OAEG;IACG,WAAW,CAChB,EACC,cAAc,EACd,OAAY,EACZ,EAAE,mBAAmB,GACpB,OAAO,CAAC,YAAY,CAAC;IA2DxB;;OAEG;IACG,gBAAgB,CAAC,KAAK,GAAE,uBAAuB,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5E,OAAO,CAAC,oBAAoB;CA+B5B"}
\ No newline at end of file
\ No newline at end of file
lib/Transport.js
浏览文件 @
e51c3af8
...
@@ -234,13 +234,16 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -234,13 +234,16 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
else
if
(
typeof
rtpParameters
!==
'object'
)
throw
new
TypeError
(
'missing rtpParameters'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// If missing encodings, add one.
// This may throw.
if
(
!
rtpParameters
.
encodings
||
!
Array
.
isArray
(
rtpParameters
.
encodings
))
ortc
.
validateRtpParameters
(
rtpParameters
);
// If missing or empty encodings, add one.
if
(
!
rtpParameters
.
encodings
||
!
Array
.
isArray
(
rtpParameters
.
encodings
)
||
rtpParameters
.
encodings
.
length
===
0
)
{
rtpParameters
.
encodings
=
[{}];
rtpParameters
.
encodings
=
[{}];
}
// Don't do this in PipeTransports since there we must keep CNAME value in
// Don't do this in PipeTransports since there we must keep CNAME value in
// each Producer.
// each Producer.
if
(
this
.
constructor
.
name
!==
'PipeTransport'
)
{
if
(
this
.
constructor
.
name
!==
'PipeTransport'
)
{
...
@@ -300,10 +303,10 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -300,10 +303,10 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
logger
.
debug
(
'consume()'
);
logger
.
debug
(
'consume()'
);
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
throw
new
TypeError
(
'missing producerId'
);
else
if
(
typeof
rtpCapabilities
!==
'object'
)
throw
new
TypeError
(
'missing rtpCapabilities'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateRtpCapabilities
(
rtpCapabilities
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
if
(
!
producer
)
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
...
@@ -346,10 +349,10 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -346,10 +349,10 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
logger
.
debug
(
'produceData()'
);
logger
.
debug
(
'produceData()'
);
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
else
if
(
typeof
sctpStreamParameters
!==
'object'
)
throw
new
TypeError
(
'missing sctpStreamParameters'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateSctpStreamParameters
(
sctpStreamParameters
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
dataProducerId
:
id
||
v4_1
.
default
()
});
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
dataProducerId
:
id
||
v4_1
.
default
()
});
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
data
=
yield
this
.
_channel
.
request
(
'transport.produceData'
,
internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.produceData'
,
internal
,
reqData
);
...
...
lib/ortc.d.ts
浏览文件 @
e51c3af8
import
{
RtpCapabilities
,
RtpCodecCapability
,
RtpParameters
}
from
'./RtpParameters'
;
import
{
RtpCapabilities
,
RtpCodecCapability
,
RtpHeaderExtension
,
RtpParameters
,
RtpCodecParameters
,
RtcpFeedback
,
RtpEncodingParameters
,
RtpHeaderExtensionParameters
,
RtcpParameters
}
from
'./RtpParameters'
;
import
{
SctpCapabilities
,
NumSctpStreams
,
SctpParameters
,
SctpStreamParameters
}
from
'./SctpParameters'
;
interface
RtpMapping
{
interface
RtpMapping
{
codecs
:
{
codecs
:
{
payloadType
:
number
;
payloadType
:
number
;
...
@@ -11,11 +12,89 @@ interface RtpMapping {
...
@@ -11,11 +12,89 @@ interface RtpMapping {
mappedSsrc
:
number
;
mappedSsrc
:
number
;
}[];
}[];
}
}
/**
* Validates RtpCapabilities. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtpCapabilities
(
caps
:
RtpCapabilities
):
void
;
/**
* Validates RtpCodecCapability. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtpCodecCapability
(
codec
:
RtpCodecCapability
):
void
;
/**
* Validates RtcpFeedback. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtcpFeedback
(
fb
:
RtcpFeedback
):
void
;
/**
* Validates RtpHeaderExtension. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtpHeaderExtension
(
ext
:
RtpHeaderExtension
):
void
;
/**
* Validates RtpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtpParameters
(
params
:
RtpParameters
):
void
;
/**
* Validates RtpCodecParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtpCodecParameters
(
codec
:
RtpCodecParameters
):
void
;
/**
* Validates RtpHeaderExtensionParameteters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtpHeaderExtensionParameters
(
ext
:
RtpHeaderExtensionParameters
):
void
;
/**
* Validates RtpEncodingParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtpEncodingParameters
(
encoding
:
RtpEncodingParameters
):
void
;
/**
* Validates RtcpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateRtcpParameters
(
rtcp
:
RtcpParameters
):
void
;
/**
* Validates SctpCapabilities. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateSctpCapabilities
(
caps
:
SctpCapabilities
):
void
;
/**
* Validates NumSctpStreams. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateNumSctpStreams
(
numStreams
:
NumSctpStreams
):
void
;
/**
* Validates SctpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateSctpParameters
(
params
:
SctpParameters
):
void
;
/**
* Validates SctpStreamParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
declare
function
validateSctpStreamParameters
(
params
:
SctpStreamParameters
):
void
;
/**
/**
* 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.
*/
*/
export
declare
function
generateRouterRtpCapabilities
(
mediaCodecs
?:
RtpCodecCapability
[]):
R
TCR
tpCapabilities
;
export
declare
function
generateRouterRtpCapabilities
(
mediaCodecs
?:
RtpCodecCapability
[]):
RtpCapabilities
;
/**
/**
* Get a mapping of codec payloads and encodings of the given Producer RTP
* Get a mapping of codec payloads and encodings of the given Producer RTP
* parameters as values expected by the Router.
* parameters as values expected by the Router.
...
...
lib/ortc.d.ts.map
浏览文件 @
e51c3af8
{"version":3,"file":"ortc.d.ts","sourceRoot":"","sources":["../src/ortc.ts"],"names":[],"mappings":"AAKA,OAAO,EAEN,eAAe,EACf,kBAAkB,EAClB,aAAa,EAIb,MAAM,iBAAiB,CAAC;AAEzB,UAAU,UAAU;IAEnB,MAAM,EACN;QACC,WAAW,EAAE,MAAM,CAAC;QACpB,iBAAiB,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;IAEJ,SAAS,EACT;QACC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;KACnB,EAAE,CAAC;CACJ;AASD;;;GAGG;AACH,wBAAgB,6BAA6B,CAC5C,WAAW,GAAE,kBAAkB,EAAO,GACpC,kBAAkB,CA2GpB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,eAAe,GACnB,UAAU,CAmGZ;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,UAAU,GACp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BAAwB,CACvC,gBAAgB,EAAE,aAAa,EAC/B,IAAI,EAAE,eAAe,GACnB,aAAa,CAwHf;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC3C,gBAAgB,EAAE,aAAa,GAC7B,aAAa,CAgDf"}
\ No newline at end of file
\ No newline at end of file
lib/ortc.js
浏览文件 @
e51c3af8
...
@@ -17,22 +17,393 @@ const DynamicPayloadTypes = [
...
@@ -17,22 +17,393 @@ const DynamicPayloadTypes = [
111
,
112
,
113
,
114
,
115
,
116
,
117
,
118
,
119
,
120
,
121
,
111
,
112
,
113
,
114
,
115
,
116
,
117
,
118
,
119
,
120
,
121
,
122
,
123
,
124
,
125
,
126
,
127
,
96
,
97
,
98
,
99
122
,
123
,
124
,
125
,
126
,
127
,
96
,
97
,
98
,
99
];
];
/**
* Validates RtpCapabilities. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpCapabilities
(
caps
)
{
if
(
typeof
caps
!==
'object'
)
throw
new
TypeError
(
'caps is not an object'
);
// codecs is optional. If unset, fill with an empty array.
if
(
caps
.
codecs
&&
!
Array
.
isArray
(
caps
.
codecs
))
throw
new
TypeError
(
'caps.codecs is not an array'
);
else
if
(
!
caps
.
codecs
)
caps
.
codecs
=
[];
for
(
const
codec
of
caps
.
codecs
)
{
validateRtpCodecCapability
(
codec
);
}
// headerExtensions is optional. If unset, fill with an empty array.
if
(
caps
.
headerExtensions
&&
!
Array
.
isArray
(
caps
.
headerExtensions
))
throw
new
TypeError
(
'caps.headerExtensions is not an array'
);
else
if
(
!
caps
.
headerExtensions
)
caps
.
headerExtensions
=
[];
for
(
const
ext
of
caps
.
headerExtensions
)
{
validateRtpHeaderExtension
(
ext
);
}
}
exports
.
validateRtpCapabilities
=
validateRtpCapabilities
;
/**
* Validates RtpCodecCapability. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpCodecCapability
(
codec
)
{
const
MimeTypeRegex
=
new
RegExp
(
'^(audio|video)/(.+)'
,
'i'
);
if
(
typeof
codec
!==
'object'
)
throw
new
TypeError
(
'codec is not an object'
);
// mimeType is mandatory.
if
(
!
codec
.
mimeType
||
typeof
codec
.
mimeType
!==
'string'
)
throw
new
TypeError
(
'missing codec.mimeType'
);
const
mimeTypeMatch
=
MimeTypeRegex
.
exec
(
codec
.
mimeType
);
if
(
!
mimeTypeMatch
)
throw
new
TypeError
(
'invalid codec.mimeType'
);
// Just override kind with media component of mimeType.
codec
.
kind
=
mimeTypeMatch
[
1
].
toLowerCase
();
// preferredPayloadType is optional.
if
(
codec
.
preferredPayloadType
&&
typeof
codec
.
preferredPayloadType
!==
'number'
)
throw
new
TypeError
(
'invalid codec.preferredPayloadType'
);
// clockRate is mandatory.
if
(
typeof
codec
.
clockRate
!==
'number'
)
throw
new
TypeError
(
'missing codec.clockRate'
);
// channels is optional. If unset, set it to 1.
if
(
typeof
codec
.
channels
!==
'number'
)
codec
.
channels
=
1
;
// parameters is optional. If unset, set it to an empty object.
if
(
!
codec
.
parameters
||
typeof
codec
.
parameters
!==
'object'
)
codec
.
parameters
=
{};
for
(
const
key
of
Object
.
keys
(
codec
.
parameters
))
{
const
value
=
codec
.
parameters
[
key
];
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec parameter'
);
// Specific parameters validation.
if
(
key
===
'apt'
)
{
if
(
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec apt parameter'
);
}
}
// rtcpFeedback is optional. If unset, set it to an empty array.
if
(
!
codec
.
rtcpFeedback
||
!
Array
.
isArray
(
codec
.
rtcpFeedback
))
codec
.
rtcpFeedback
=
[];
for
(
const
fb
of
codec
.
rtcpFeedback
)
{
validateRtcpFeedback
(
fb
);
}
}
exports
.
validateRtpCodecCapability
=
validateRtpCodecCapability
;
/**
* Validates RtcpFeedback. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtcpFeedback
(
fb
)
{
if
(
typeof
fb
!==
'object'
)
throw
new
TypeError
(
'fb is not an object'
);
// type is mandatory.
if
(
!
fb
.
type
||
typeof
fb
.
type
!==
'string'
)
throw
new
TypeError
(
'missing fb.type'
);
// parameter is optional. If unset set it to an empty string.
if
(
!
fb
.
parameter
||
typeof
fb
.
parameter
!==
'string'
)
fb
.
parameter
=
''
;
}
exports
.
validateRtcpFeedback
=
validateRtcpFeedback
;
/**
* Validates RtpHeaderExtension. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpHeaderExtension
(
ext
)
{
if
(
typeof
ext
!==
'object'
)
throw
new
TypeError
(
'ext is not an object'
);
// kind is optional. If unset set it to an empty string.
if
(
!
ext
.
kind
||
typeof
ext
.
kind
!==
'string'
)
ext
.
kind
=
''
;
if
(
ext
.
kind
!==
''
&&
ext
.
kind
!==
'audio'
&&
ext
.
kind
!==
'video'
)
throw
new
TypeError
(
'invalid ext.kind'
);
// uri is mandatory.
if
(
!
ext
.
uri
||
typeof
ext
.
uri
!==
'string'
)
throw
new
TypeError
(
'missing ext.uri'
);
// preferredId is mandatory.
if
(
typeof
ext
.
preferredId
!==
'number'
)
throw
new
TypeError
(
'missing ext.preferredId'
);
// preferredEncrypt is optional. If unset set it to false.
if
(
ext
.
preferredEncrypt
&&
typeof
ext
.
preferredEncrypt
!==
'boolean'
)
throw
new
TypeError
(
'invalid ext.preferredEncrypt'
);
else
if
(
!
ext
.
preferredEncrypt
)
ext
.
preferredEncrypt
=
false
;
// direction is optional. If unset set it to sendrecv.
if
(
ext
.
direction
&&
typeof
ext
.
direction
!==
'string'
)
throw
new
TypeError
(
'invalid ext.direction'
);
else
if
(
!
ext
.
direction
)
ext
.
direction
=
'sendrecv'
;
}
exports
.
validateRtpHeaderExtension
=
validateRtpHeaderExtension
;
/**
* Validates RtpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpParameters
(
params
)
{
if
(
typeof
params
!==
'object'
)
throw
new
TypeError
(
'params is not an object'
);
// mid is optional.
if
(
params
.
mid
&&
typeof
params
.
mid
!==
'string'
)
throw
new
TypeError
(
'params.mid is not a string'
);
// codecs is mandatory.
if
(
!
Array
.
isArray
(
params
.
codecs
))
throw
new
TypeError
(
'missing params.codecs'
);
for
(
const
codec
of
params
.
codecs
)
{
validateRtpCodecParameters
(
codec
);
}
// headerExtensions is optional. If unset, fill with an empty array.
if
(
params
.
headerExtensions
&&
!
Array
.
isArray
(
params
.
headerExtensions
))
throw
new
TypeError
(
'params.headerExtensions is not an array'
);
else
if
(
!
params
.
headerExtensions
)
params
.
headerExtensions
=
[];
for
(
const
ext
of
params
.
headerExtensions
)
{
validateRtpHeaderExtensionParameters
(
ext
);
}
// encodings is optional. If unset, fill with an empty array.
if
(
params
.
encodings
&&
!
Array
.
isArray
(
params
.
encodings
))
throw
new
TypeError
(
'params.encodings is not an array'
);
else
if
(
!
params
.
encodings
)
params
.
encodings
=
[];
for
(
const
encoding
of
params
.
encodings
)
{
validateRtpEncodingParameters
(
encoding
);
}
// rtcp is optional. If unset, fill with an empty object.
if
(
params
.
rtcp
&&
typeof
params
.
rtcp
!==
'object'
)
throw
new
TypeError
(
'params.rtcp is not an object'
);
else
if
(
!
params
.
rtcp
)
params
.
rtcp
=
{};
validateRtcpParameters
(
params
.
rtcp
);
}
exports
.
validateRtpParameters
=
validateRtpParameters
;
/**
* Validates RtpCodecParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpCodecParameters
(
codec
)
{
const
MimeTypeRegex
=
new
RegExp
(
'^(audio|video)/(.+)'
,
'i'
);
if
(
typeof
codec
!==
'object'
)
throw
new
TypeError
(
'codec is not an object'
);
// mimeType is mandatory.
if
(
!
codec
.
mimeType
||
typeof
codec
.
mimeType
!==
'string'
)
throw
new
TypeError
(
'missing codec.mimeType'
);
const
mimeTypeMatch
=
MimeTypeRegex
.
exec
(
codec
.
mimeType
);
if
(
!
mimeTypeMatch
)
throw
new
TypeError
(
'invalid codec.mimeType'
);
// payloadType is mandatory.
if
(
typeof
codec
.
payloadType
!==
'number'
)
throw
new
TypeError
(
'missing codec.payloadType'
);
// clockRate is mandatory.
if
(
typeof
codec
.
clockRate
!==
'number'
)
throw
new
TypeError
(
'missing codec.clockRate'
);
// channels is optional. If unset, set it to 1.
if
(
typeof
codec
.
channels
!==
'number'
)
codec
.
channels
=
1
;
// parameters is optional. If unset, set it to an empty object.
if
(
!
codec
.
parameters
||
typeof
codec
.
parameters
!==
'object'
)
codec
.
parameters
=
{};
for
(
const
key
of
Object
.
keys
(
codec
.
parameters
))
{
const
value
=
codec
.
parameters
[
key
];
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec parameter'
);
// Specific parameters validation.
if
(
key
===
'apt'
)
{
if
(
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec apt parameter'
);
}
}
// rtcpFeedback is optional. If unset, set it to an empty array.
if
(
!
codec
.
rtcpFeedback
||
!
Array
.
isArray
(
codec
.
rtcpFeedback
))
codec
.
rtcpFeedback
=
[];
for
(
const
fb
of
codec
.
rtcpFeedback
)
{
validateRtcpFeedback
(
fb
);
}
}
exports
.
validateRtpCodecParameters
=
validateRtpCodecParameters
;
/**
* Validates RtpHeaderExtensionParameteters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpHeaderExtensionParameters
(
ext
)
{
if
(
typeof
ext
!==
'object'
)
throw
new
TypeError
(
'ext is not an object'
);
// uri is mandatory.
if
(
!
ext
.
uri
||
typeof
ext
.
uri
!==
'string'
)
throw
new
TypeError
(
'missing ext.uri'
);
// id is mandatory.
if
(
typeof
ext
.
id
!==
'number'
)
throw
new
TypeError
(
'missing ext.id'
);
// encrypt is optional. If unset set it to false.
if
(
ext
.
encrypt
&&
typeof
ext
.
encrypt
!==
'boolean'
)
throw
new
TypeError
(
'invalid ext.encrypt'
);
else
if
(
!
ext
.
encrypt
)
ext
.
encrypt
=
false
;
// parameters is optional. If unset, set it to an empty object.
if
(
!
ext
.
parameters
||
typeof
ext
.
parameters
!==
'object'
)
ext
.
parameters
=
{};
for
(
const
key
of
Object
.
keys
(
ext
.
parameters
))
{
const
value
=
ext
.
parameters
[
key
];
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid header extension parameter'
);
}
}
exports
.
validateRtpHeaderExtensionParameters
=
validateRtpHeaderExtensionParameters
;
/**
* Validates RtpEncodingParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpEncodingParameters
(
encoding
)
{
if
(
typeof
encoding
!==
'object'
)
throw
new
TypeError
(
'encoding is not an object'
);
// ssrc is optional.
if
(
encoding
.
ssrc
&&
typeof
encoding
.
ssrc
!==
'number'
)
throw
new
TypeError
(
'invalid encoding.ssrc'
);
// rid is optional.
if
(
encoding
.
rid
&&
typeof
encoding
.
rid
!==
'string'
)
throw
new
TypeError
(
'invalid encoding.rid'
);
// rtx is optional.
if
(
encoding
.
rtx
&&
typeof
encoding
.
rtx
!==
'object'
)
{
throw
new
TypeError
(
'invalid encoding.rtx'
);
}
else
if
(
encoding
.
rtx
)
{
// RTX ssrc is mandatory if rtx is present.
if
(
typeof
encoding
.
rtx
.
ssrc
!==
'number'
)
throw
new
TypeError
(
'missing encoding.rtx.ssrc'
);
}
// dtx is optional. If unset set it to false.
if
(
!
encoding
.
dtx
||
typeof
encoding
.
dtx
!==
'boolean'
)
encoding
.
dtx
=
false
;
// scalabilityMode is optional.
if
(
encoding
.
scalabilityMode
&&
typeof
encoding
.
scalabilityMode
!==
'string'
)
throw
new
TypeError
(
'invalid encoding.scalabilityMode'
);
}
exports
.
validateRtpEncodingParameters
=
validateRtpEncodingParameters
;
/**
* Validates RtcpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtcpParameters
(
rtcp
)
{
if
(
typeof
rtcp
!==
'object'
)
throw
new
TypeError
(
'rtcp is not an object'
);
// cname is optional.
if
(
rtcp
.
cname
&&
typeof
rtcp
.
cname
!==
'string'
)
throw
new
TypeError
(
'invalid rtcp.cname'
);
// reducedSize is optional. If unset set it to true.
if
(
!
rtcp
.
reducedSize
||
typeof
rtcp
.
reducedSize
!==
'boolean'
)
rtcp
.
reducedSize
=
true
;
}
exports
.
validateRtcpParameters
=
validateRtcpParameters
;
/**
* Validates SctpCapabilities. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateSctpCapabilities
(
caps
)
{
if
(
typeof
caps
!==
'object'
)
throw
new
TypeError
(
'caps is not an object'
);
// numStreams is mandatory.
if
(
!
caps
.
numStreams
||
typeof
caps
.
numStreams
!==
'object'
)
throw
new
TypeError
(
'missing caps.numStreams'
);
validateNumSctpStreams
(
caps
.
numStreams
);
}
exports
.
validateSctpCapabilities
=
validateSctpCapabilities
;
/**
* Validates NumSctpStreams. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateNumSctpStreams
(
numStreams
)
{
if
(
typeof
numStreams
!==
'object'
)
throw
new
TypeError
(
'numStreams is not an object'
);
// OS is mandatory.
if
(
typeof
numStreams
.
OS
!==
'number'
)
throw
new
TypeError
(
'missing numStreams.OS'
);
// MIS is mandatory.
if
(
typeof
numStreams
.
MIS
!==
'number'
)
throw
new
TypeError
(
'missing numStreams.MIS'
);
}
exports
.
validateNumSctpStreams
=
validateNumSctpStreams
;
/**
* Validates SctpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateSctpParameters
(
params
)
{
if
(
typeof
params
!==
'object'
)
throw
new
TypeError
(
'params is not an object'
);
// port is mandatory.
if
(
typeof
params
.
port
!==
'number'
)
throw
new
TypeError
(
'missing params.port'
);
// OS is mandatory.
if
(
typeof
params
.
OS
!==
'number'
)
throw
new
TypeError
(
'missing params.OS'
);
// MIS is mandatory.
if
(
typeof
params
.
MIS
!==
'number'
)
throw
new
TypeError
(
'missing params.MIS'
);
// maxMessageSize is mandatory.
if
(
typeof
params
.
maxMessageSize
!==
'number'
)
throw
new
TypeError
(
'missing params.maxMessageSize'
);
}
exports
.
validateSctpParameters
=
validateSctpParameters
;
/**
* Validates SctpStreamParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateSctpStreamParameters
(
params
)
{
if
(
typeof
params
!==
'object'
)
throw
new
TypeError
(
'params is not an object'
);
// streamId is mandatory.
if
(
typeof
params
.
streamId
!==
'number'
)
throw
new
TypeError
(
'missing params.streamId'
);
// ordered is optional.
let
orderedGiven
=
false
;
if
(
typeof
params
.
ordered
===
'boolean'
)
orderedGiven
=
true
;
else
params
.
ordered
=
true
;
// maxPacketLifeTime is optional.
if
(
params
.
maxPacketLifeTime
&&
typeof
params
.
maxPacketLifeTime
!==
'number'
)
throw
new
TypeError
(
'invalid params.maxPacketLifeTime'
);
// maxRetransmits is optional.
if
(
params
.
maxRetransmits
&&
typeof
params
.
maxRetransmits
!==
'number'
)
throw
new
TypeError
(
'invalid params.maxRetransmits'
);
if
(
params
.
maxPacketLifeTime
&&
params
.
maxRetransmits
)
throw
new
TypeError
(
'cannot provide both maxPacketLifeTime and maxRetransmits'
);
if
(
orderedGiven
&&
params
.
ordered
&&
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
))
{
throw
new
TypeError
(
'cannot be ordered with maxPacketLifeTime or maxRetransmits'
);
}
else
if
(
!
orderedGiven
&&
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
))
{
params
.
ordered
=
false
;
}
}
exports
.
validateSctpStreamParameters
=
validateSctpStreamParameters
;
/**
/**
* 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.
*/
*/
function
generateRouterRtpCapabilities
(
mediaCodecs
=
[])
{
function
generateRouterRtpCapabilities
(
mediaCodecs
=
[])
{
// Normalize supported RTP capabilities.
validateRtpCapabilities
(
supportedRtpCapabilities_1
.
supportedRtpCapabilities
);
if
(
!
Array
.
isArray
(
mediaCodecs
))
if
(
!
Array
.
isArray
(
mediaCodecs
))
throw
new
TypeError
(
'mediaCodecs must be an Array'
);
throw
new
TypeError
(
'mediaCodecs must be an Array'
);
const
dynamicPayloadTypes
=
utils
.
clone
(
DynamicPayloadTypes
);
const
dynamicPayloadTypes
=
utils
.
clone
(
DynamicPayloadTypes
);
const
supportedCodecs
=
supportedRtpCapabilities_1
.
supportedRtpCapabilities
.
codecs
;
const
supportedCodecs
=
supportedRtpCapabilities_1
.
supportedRtpCapabilities
.
codecs
;
const
caps
=
{
const
caps
=
{
codecs
:
[],
codecs
:
[],
headerExtensions
:
supportedRtpCapabilities_1
.
supportedRtpCapabilities
.
headerExtensions
,
headerExtensions
:
supportedRtpCapabilities_1
.
supportedRtpCapabilities
.
headerExtensions
fecMechanisms
:
supportedRtpCapabilities_1
.
supportedRtpCapabilities
.
fecMechanisms
};
};
for
(
const
mediaCodec
of
mediaCodecs
)
{
for
(
const
mediaCodec
of
mediaCodecs
)
{
assertCodecCapability
(
mediaCodec
);
// This may throw.
validateRtpCodecCapability
(
mediaCodec
);
const
matchedSupportedCodec
=
supportedCodecs
const
matchedSupportedCodec
=
supportedCodecs
.
find
((
supportedCodec
)
=>
(
matchCodecs
(
mediaCodec
,
supportedCodec
,
{
strict
:
false
})));
.
find
((
supportedCodec
)
=>
(
matchCodecs
(
mediaCodec
,
supportedCodec
,
{
strict
:
false
})));
if
(
!
matchedSupportedCodec
)
{
if
(
!
matchedSupportedCodec
)
{
...
@@ -62,16 +433,9 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
...
@@ -62,16 +433,9 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
}
}
// Ensure there is not duplicated preferredPayloadType values.
// Ensure there is not duplicated preferredPayloadType values.
if
(
caps
.
codecs
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
if
(
caps
.
codecs
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
throw
new
Error
(
'duplicated codec.preferredPayloadType'
);
throw
new
TypeError
(
'duplicated codec.preferredPayloadType'
);
// Normalize channels.
if
(
codec
.
kind
!==
'audio'
)
delete
codec
.
channels
;
else
if
(
!
codec
.
channels
)
codec
.
channels
=
1
;
// Merge the media codec parameters.
// Merge the media codec parameters.
codec
.
parameters
=
Object
.
assign
(
Object
.
assign
({},
codec
.
parameters
),
mediaCodec
.
parameters
);
codec
.
parameters
=
Object
.
assign
(
Object
.
assign
({},
codec
.
parameters
),
mediaCodec
.
parameters
);
// Make rtcpFeedback an array.
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
||
[];
// Append to the codec list.
// Append to the codec list.
caps
.
codecs
.
push
(
codec
);
caps
.
codecs
.
push
(
codec
);
// Add a RTX video codec if video.
// Add a RTX video codec if video.
...
@@ -85,10 +449,11 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
...
@@ -85,10 +449,11 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
mimeType
:
`
${
codec
.
kind
}
/rtx`
,
mimeType
:
`
${
codec
.
kind
}
/rtx`
,
preferredPayloadType
:
pt
,
preferredPayloadType
:
pt
,
clockRate
:
codec
.
clockRate
,
clockRate
:
codec
.
clockRate
,
rtcpFeedback
:
[]
,
channels
:
1
,
parameters
:
{
parameters
:
{
apt
:
codec
.
preferredPayloadType
apt
:
codec
.
preferredPayloadType
}
},
rtcpFeedback
:
[]
};
};
// Append to the codec list.
// Append to the codec list.
caps
.
codecs
.
push
(
rtxCodec
);
caps
.
codecs
.
push
(
rtxCodec
);
...
@@ -110,9 +475,8 @@ function getProducerRtpParametersMapping(params, caps) {
...
@@ -110,9 +475,8 @@ function getProducerRtpParametersMapping(params, caps) {
};
};
// Match parameters media codecs to capabilities media codecs.
// Match parameters media codecs to capabilities media codecs.
const
codecToCapCodec
=
new
Map
();
const
codecToCapCodec
=
new
Map
();
for
(
const
codec
of
params
.
codecs
||
[])
{
for
(
const
codec
of
params
.
codecs
)
{
assertCodecParameters
(
codec
);
if
(
isRtxCodec
(
codec
))
if
(
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
continue
;
continue
;
// Search for the same media codec in capabilities.
// Search for the same media codec in capabilities.
const
matchedCapCodec
=
caps
.
codecs
const
matchedCapCodec
=
caps
.
codecs
...
@@ -123,11 +487,9 @@ function getProducerRtpParametersMapping(params, caps) {
...
@@ -123,11 +487,9 @@ function getProducerRtpParametersMapping(params, caps) {
codecToCapCodec
.
set
(
codec
,
matchedCapCodec
);
codecToCapCodec
.
set
(
codec
,
matchedCapCodec
);
}
}
// Match parameters RTX codecs to capabilities RTX codecs.
// Match parameters RTX codecs to capabilities RTX codecs.
for
(
const
codec
of
params
.
codecs
||
[]
)
{
for
(
const
codec
of
params
.
codecs
)
{
if
(
!
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
if
(
!
isRtxCodec
(
codec
))
continue
;
continue
;
else
if
(
typeof
codec
.
parameters
!==
'object'
)
throw
TypeError
(
'missing parameters in RTX codec'
);
// Search for the associated media codec.
// Search for the associated media codec.
const
associatedMediaCodec
=
params
.
codecs
const
associatedMediaCodec
=
params
.
codecs
.
find
((
mediaCodec
)
=>
mediaCodec
.
payloadType
===
codec
.
parameters
.
apt
);
.
find
((
mediaCodec
)
=>
mediaCodec
.
payloadType
===
codec
.
parameters
.
apt
);
...
@@ -137,7 +499,7 @@ function getProducerRtpParametersMapping(params, caps) {
...
@@ -137,7 +499,7 @@ function getProducerRtpParametersMapping(params, caps) {
const
capMediaCodec
=
codecToCapCodec
.
get
(
associatedMediaCodec
);
const
capMediaCodec
=
codecToCapCodec
.
get
(
associatedMediaCodec
);
// Ensure that the capabilities media codec has a RTX codec.
// Ensure that the capabilities media codec has a RTX codec.
const
associatedCapRtxCodec
=
caps
.
codecs
const
associatedCapRtxCodec
=
caps
.
codecs
.
find
((
capCodec
)
=>
(
/.+
\/
rtx$/i
.
test
(
capCodec
.
mimeType
)
&&
.
find
((
capCodec
)
=>
(
isRtxCodec
(
capCodec
)
&&
capCodec
.
parameters
.
apt
===
capMediaCodec
.
preferredPayloadType
));
capCodec
.
parameters
.
apt
===
capMediaCodec
.
preferredPayloadType
));
if
(
!
associatedCapRtxCodec
)
{
if
(
!
associatedCapRtxCodec
)
{
throw
new
errors_1
.
UnsupportedError
(
`no RTX codec for capability codec PT
${
capMediaCodec
.
preferredPayloadType
}
`
);
throw
new
errors_1
.
UnsupportedError
(
`no RTX codec for capability codec PT
${
capMediaCodec
.
preferredPayloadType
}
`
);
...
@@ -153,7 +515,7 @@ function getProducerRtpParametersMapping(params, caps) {
...
@@ -153,7 +515,7 @@ function getProducerRtpParametersMapping(params, caps) {
}
}
// Generate encodings mapping.
// Generate encodings mapping.
let
mappedSsrc
=
utils
.
generateRandomNumber
();
let
mappedSsrc
=
utils
.
generateRandomNumber
();
for
(
const
encoding
of
(
params
.
encodings
||
[])
)
{
for
(
const
encoding
of
params
.
encodings
)
{
const
mappedEncoding
=
{};
const
mappedEncoding
=
{};
mappedEncoding
.
mappedSsrc
=
mappedSsrc
++
;
mappedEncoding
.
mappedSsrc
=
mappedSsrc
++
;
if
(
encoding
.
rid
)
if
(
encoding
.
rid
)
...
@@ -178,9 +540,8 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
...
@@ -178,9 +540,8 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
encodings
:
[],
encodings
:
[],
rtcp
:
{}
rtcp
:
{}
};
};
for
(
const
codec
of
params
.
codecs
||
[])
{
for
(
const
codec
of
params
.
codecs
)
{
assertCodecParameters
(
codec
);
if
(
isRtxCodec
(
codec
))
if
(
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
continue
;
continue
;
const
consumableCodecPt
=
rtpMapping
.
codecs
const
consumableCodecPt
=
rtpMapping
.
codecs
.
find
((
entry
)
=>
entry
.
payloadType
===
codec
.
payloadType
)
.
find
((
entry
)
=>
entry
.
payloadType
===
codec
.
payloadType
)
...
@@ -189,29 +550,25 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
...
@@ -189,29 +550,25 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
.
find
((
capCodec
)
=>
capCodec
.
preferredPayloadType
===
consumableCodecPt
);
.
find
((
capCodec
)
=>
capCodec
.
preferredPayloadType
===
consumableCodecPt
);
const
consumableCodec
=
{
const
consumableCodec
=
{
mimeType
:
matchedCapCodec
.
mimeType
,
mimeType
:
matchedCapCodec
.
mimeType
,
clockRate
:
matchedCapCodec
.
clockRate
,
payloadType
:
matchedCapCodec
.
preferredPayloadType
,
payloadType
:
matchedCapCodec
.
preferredPayloadType
,
clockRate
:
matchedCapCodec
.
clockRate
,
channels
:
matchedCapCodec
.
channels
,
channels
:
matchedCapCodec
.
channels
,
rtcpFeedback
:
matchedCapCodec
.
rtcpFeedback
,
parameters
:
codec
.
parameters
,
parameters
:
codec
.
parameters
// Keep the Producer parameters.
rtcpFeedback
:
matchedCapCodec
.
rtcpFeedback
};
};
if
(
!
consumableCodec
.
channels
)
delete
consumableCodec
.
channels
;
consumableParams
.
codecs
.
push
(
consumableCodec
);
consumableParams
.
codecs
.
push
(
consumableCodec
);
const
consumableCapRtxCodec
=
caps
.
codecs
const
consumableCapRtxCodec
=
caps
.
codecs
.
find
((
capRtxCodec
)
=>
(
/.+
\/
rtx$/i
.
test
(
capRtxCodec
.
mimeType
)
&&
.
find
((
capRtxCodec
)
=>
(
isRtxCodec
(
capRtxCodec
)
&&
capRtxCodec
.
parameters
.
apt
===
consumableCodec
.
payloadType
));
capRtxCodec
.
parameters
.
apt
===
consumableCodec
.
payloadType
));
if
(
consumableCapRtxCodec
)
{
if
(
consumableCapRtxCodec
)
{
const
consumableRtxCodec
=
{
const
consumableRtxCodec
=
{
mimeType
:
consumableCapRtxCodec
.
mimeType
,
mimeType
:
consumableCapRtxCodec
.
mimeType
,
clockRate
:
consumableCapRtxCodec
.
clockRate
,
payloadType
:
consumableCapRtxCodec
.
preferredPayloadType
,
payloadType
:
consumableCapRtxCodec
.
preferredPayloadType
,
channels
:
consumableCapRtxCodec
.
channels
,
clockRate
:
consumableCapRtxCodec
.
clockRate
,
rtcpFeedback
:
consumableCapRtxCodec
.
rtcpFeedback
,
channels
:
1
,
parameters
:
consumableCapRtxCodec
.
parameters
parameters
:
consumableCapRtxCodec
.
parameters
,
rtcpFeedback
:
consumableCapRtxCodec
.
rtcpFeedback
};
};
if
(
!
consumableRtxCodec
.
channels
)
delete
consumableRtxCodec
.
channels
;
consumableParams
.
codecs
.
push
(
consumableRtxCodec
);
consumableParams
.
codecs
.
push
(
consumableRtxCodec
);
}
}
}
}
...
@@ -223,7 +580,9 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
...
@@ -223,7 +580,9 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
}
}
const
consumableExt
=
{
const
consumableExt
=
{
uri
:
capExt
.
uri
,
uri
:
capExt
.
uri
,
id
:
capExt
.
preferredId
id
:
capExt
.
preferredId
,
encrypt
:
capExt
.
preferredEncrypt
,
parameters
:
{}
};
};
consumableParams
.
headerExtensions
.
push
(
consumableExt
);
consumableParams
.
headerExtensions
.
push
(
consumableExt
);
}
}
...
@@ -253,10 +612,9 @@ exports.getConsumableRtpParameters = getConsumableRtpParameters;
...
@@ -253,10 +612,9 @@ exports.getConsumableRtpParameters = getConsumableRtpParameters;
* Check whether the given RTP capabilities can consume the given Producer.
* Check whether the given RTP capabilities can consume the given Producer.
*/
*/
function
canConsume
(
consumableParams
,
caps
)
{
function
canConsume
(
consumableParams
,
caps
)
{
// This may throw.
validateRtpCapabilities
(
caps
);
const
matchingCodecs
=
[];
const
matchingCodecs
=
[];
for
(
const
capCodec
of
caps
.
codecs
||
[])
{
assertCodecCapability
(
capCodec
);
}
for
(
const
codec
of
consumableParams
.
codecs
)
{
for
(
const
codec
of
consumableParams
.
codecs
)
{
const
matchedCapCodec
=
caps
.
codecs
const
matchedCapCodec
=
caps
.
codecs
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
...
@@ -265,10 +623,8 @@ function canConsume(consumableParams, caps) {
...
@@ -265,10 +623,8 @@ function canConsume(consumableParams, caps) {
matchingCodecs
.
push
(
codec
);
matchingCodecs
.
push
(
codec
);
}
}
// Ensure there is at least one media codec.
// Ensure there is at least one media codec.
if
(
matchingCodecs
.
length
===
0
||
if
(
matchingCodecs
.
length
===
0
||
isRtxCodec
(
matchingCodecs
[
0
]))
/.+
\/
rtx$/i
.
test
(
matchingCodecs
[
0
].
mimeType
))
{
return
false
;
return
false
;
}
return
true
;
return
true
;
}
}
exports
.
canConsume
=
canConsume
;
exports
.
canConsume
=
canConsume
;
...
@@ -286,45 +642,44 @@ function getConsumerRtpParameters(consumableParams, caps) {
...
@@ -286,45 +642,44 @@ function getConsumerRtpParameters(consumableParams, caps) {
encodings
:
[],
encodings
:
[],
rtcp
:
consumableParams
.
rtcp
rtcp
:
consumableParams
.
rtcp
};
};
for
(
const
capCodec
of
caps
.
codecs
||
[]
)
{
for
(
const
capCodec
of
caps
.
codecs
)
{
assert
CodecCapability
(
capCodec
);
validateRtp
CodecCapability
(
capCodec
);
}
}
const
consumableCodecs
=
utils
.
clone
(
consumableParams
.
codecs
||
[]
);
const
consumableCodecs
=
utils
.
clone
(
consumableParams
.
codecs
);
let
rtxSupported
=
false
;
let
rtxSupported
=
false
;
for
(
const
codec
of
consumableCodecs
)
{
for
(
const
codec
of
consumableCodecs
)
{
const
matchedCapCodec
=
caps
.
codecs
const
matchedCapCodec
=
caps
.
codecs
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
if
(
!
matchedCapCodec
)
if
(
!
matchedCapCodec
)
continue
;
continue
;
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
||
[]
;
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
;
consumerParams
.
codecs
.
push
(
codec
);
consumerParams
.
codecs
.
push
(
codec
);
if
(
!
rtxSupported
&&
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
if
(
!
rtxSupported
&&
isRtxCodec
(
codec
))
rtxSupported
=
true
;
rtxSupported
=
true
;
}
}
// Ensure there is at least one media codec.
// Ensure there is at least one media codec.
if
(
consumerParams
.
codecs
.
length
===
0
||
if
(
consumerParams
.
codecs
.
length
===
0
||
isRtxCodec
(
consumerParams
.
codecs
[
0
]))
{
/.+
\/
rtx$/i
.
test
(
consumerParams
.
codecs
[
0
].
mimeType
))
{
throw
new
errors_1
.
UnsupportedError
(
'no compatible media codecs'
);
throw
new
errors_1
.
UnsupportedError
(
'no compatible media codecs'
);
}
}
consumerParams
.
headerExtensions
=
consumableParams
.
headerExtensions
consumerParams
.
headerExtensions
=
consumableParams
.
headerExtensions
.
filter
((
ext
)
=>
((
caps
.
headerExtensions
||
[]
)
.
filter
((
ext
)
=>
((
caps
.
headerExtensions
)
.
some
((
capExt
)
=>
capExt
.
preferredId
===
ext
.
id
)));
.
some
((
capExt
)
=>
capExt
.
preferredId
===
ext
.
id
)));
// Reduce codecs' RTCP feedback. Use Transport-CC if available, REMB otherwise.
// Reduce codecs' RTCP feedback. Use Transport-CC if available, REMB otherwise.
if
(
consumerParams
.
headerExtensions
.
some
((
ext
)
=>
(
ext
.
uri
===
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01'
)))
{
if
(
consumerParams
.
headerExtensions
.
some
((
ext
)
=>
(
ext
.
uri
===
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01'
)))
{
for
(
const
codec
of
consumerParams
.
codecs
)
{
for
(
const
codec
of
consumerParams
.
codecs
)
{
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
||
[]
)
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
)
.
filter
((
fb
)
=>
fb
.
type
!==
'goog-remb'
);
.
filter
((
fb
)
=>
fb
.
type
!==
'goog-remb'
);
}
}
}
}
else
if
(
consumerParams
.
headerExtensions
.
some
((
ext
)
=>
(
ext
.
uri
===
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
)))
{
else
if
(
consumerParams
.
headerExtensions
.
some
((
ext
)
=>
(
ext
.
uri
===
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
)))
{
for
(
const
codec
of
consumerParams
.
codecs
)
{
for
(
const
codec
of
consumerParams
.
codecs
)
{
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
||
[]
)
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
)
.
filter
((
fb
)
=>
fb
.
type
!==
'transport-cc'
);
.
filter
((
fb
)
=>
fb
.
type
!==
'transport-cc'
);
}
}
}
}
else
{
else
{
for
(
const
codec
of
consumerParams
.
codecs
)
{
for
(
const
codec
of
consumerParams
.
codecs
)
{
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
||
[]
)
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
)
.
filter
((
fb
)
=>
(
fb
.
type
!==
'transport-cc'
&&
.
filter
((
fb
)
=>
(
fb
.
type
!==
'transport-cc'
&&
fb
.
type
!==
'goog-remb'
));
fb
.
type
!==
'goog-remb'
));
}
}
...
@@ -367,10 +722,11 @@ function getPipeConsumerRtpParameters(consumableParams) {
...
@@ -367,10 +722,11 @@ function getPipeConsumerRtpParameters(consumableParams) {
encodings
:
[],
encodings
:
[],
rtcp
:
consumableParams
.
rtcp
rtcp
:
consumableParams
.
rtcp
};
};
const
consumableCodecs
=
utils
.
clone
(
consumableParams
.
codecs
||
[]
);
const
consumableCodecs
=
utils
.
clone
(
consumableParams
.
codecs
);
for
(
const
codec
of
consumableCodecs
)
{
for
(
const
codec
of
consumableCodecs
)
{
if
(
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
if
(
isRtxCodec
(
codec
))
continue
;
continue
;
// No support for NACK, PLI, FIR and RTX in PipeTransport.
// Reduce RTCP feedbacks by removing NACK support and other features.
// Reduce RTCP feedbacks by removing NACK support and other features.
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
.
filter
((
fb
)
=>
((
fb
.
type
===
'nack'
&&
fb
.
parameter
===
'pli'
)
||
.
filter
((
fb
)
=>
((
fb
.
type
===
'nack'
&&
fb
.
parameter
===
'pli'
)
||
...
@@ -381,7 +737,8 @@ function getPipeConsumerRtpParameters(consumableParams) {
...
@@ -381,7 +737,8 @@ function getPipeConsumerRtpParameters(consumableParams) {
consumerParams
.
headerExtensions
=
consumableParams
.
headerExtensions
consumerParams
.
headerExtensions
=
consumableParams
.
headerExtensions
.
filter
((
ext
)
=>
(
ext
.
uri
!==
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
&&
.
filter
((
ext
)
=>
(
ext
.
uri
!==
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
&&
ext
.
uri
!==
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01'
));
ext
.
uri
!==
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01'
));
const
consumableEncodings
=
utils
.
clone
(
consumableParams
.
encodings
||
[]);
const
consumableEncodings
=
utils
.
clone
(
consumableParams
.
encodings
);
// No support for NACK, PLI, FIR and RTX in PipeTransport.
for
(
const
encoding
of
consumableEncodings
)
{
for
(
const
encoding
of
consumableEncodings
)
{
delete
encoding
.
rtx
;
delete
encoding
.
rtx
;
consumerParams
.
encodings
.
push
(
encoding
);
consumerParams
.
encodings
.
push
(
encoding
);
...
@@ -389,22 +746,8 @@ function getPipeConsumerRtpParameters(consumableParams) {
...
@@ -389,22 +746,8 @@ function getPipeConsumerRtpParameters(consumableParams) {
return
consumerParams
;
return
consumerParams
;
}
}
exports
.
getPipeConsumerRtpParameters
=
getPipeConsumerRtpParameters
;
exports
.
getPipeConsumerRtpParameters
=
getPipeConsumerRtpParameters
;
function
assertCodecCapability
(
codec
)
{
function
isRtxCodec
(
codec
)
{
const
valid
=
(
typeof
codec
===
'object'
&&
!
Array
.
isArray
(
codec
))
&&
return
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
);
(
typeof
codec
.
mimeType
===
'string'
&&
codec
.
mimeType
)
&&
(
typeof
codec
.
clockRate
===
'number'
&&
codec
.
clockRate
);
if
(
!
valid
)
throw
new
TypeError
(
'invalid RTCRtpCodecCapability'
);
// Add kind if not present.
if
(
!
codec
.
kind
)
codec
.
kind
=
codec
.
mimeType
.
replace
(
/
\/
.*/
,
''
).
toLowerCase
();
}
function
assertCodecParameters
(
codec
)
{
const
valid
=
(
typeof
codec
===
'object'
&&
!
Array
.
isArray
(
codec
))
&&
(
typeof
codec
.
mimeType
===
'string'
&&
codec
.
mimeType
)
&&
(
typeof
codec
.
clockRate
===
'number'
&&
codec
.
clockRate
);
if
(
!
valid
)
throw
new
TypeError
(
'invalid RTCRtpCodecParameters'
);
}
}
function
matchCodecs
(
aCodec
,
bCodec
,
{
strict
=
false
,
modify
=
false
}
=
{})
{
function
matchCodecs
(
aCodec
,
bCodec
,
{
strict
=
false
,
modify
=
false
}
=
{})
{
const
aMimeType
=
aCodec
.
mimeType
.
toLowerCase
();
const
aMimeType
=
aCodec
.
mimeType
.
toLowerCase
();
...
@@ -413,18 +756,14 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
...
@@ -413,18 +756,14 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
return
false
;
return
false
;
if
(
aCodec
.
clockRate
!==
bCodec
.
clockRate
)
if
(
aCodec
.
clockRate
!==
bCodec
.
clockRate
)
return
false
;
return
false
;
if
(
/^audio
\/
.+$/i
.
test
(
aMimeType
)
&&
if
(
aCodec
.
channels
!==
bCodec
.
channels
)
((
aCodec
.
channels
!==
undefined
&&
aCodec
.
channels
!==
1
)
||
(
bCodec
.
channels
!==
undefined
&&
bCodec
.
channels
!==
1
))
&&
aCodec
.
channels
!==
bCodec
.
channels
)
{
return
false
;
return
false
;
}
// Per codec special checks.
// Per codec special checks.
switch
(
aMimeType
)
{
switch
(
aMimeType
)
{
case
'video/h264'
:
case
'video/h264'
:
{
{
const
aPacketizationMode
=
(
aCodec
.
parameters
||
{})
[
'packetization-mode'
]
||
0
;
const
aPacketizationMode
=
aCodec
.
parameters
[
'packetization-mode'
]
||
0
;
const
bPacketizationMode
=
(
bCodec
.
parameters
||
{})
[
'packetization-mode'
]
||
0
;
const
bPacketizationMode
=
bCodec
.
parameters
[
'packetization-mode'
]
||
0
;
if
(
aPacketizationMode
!==
bPacketizationMode
)
if
(
aPacketizationMode
!==
bPacketizationMode
)
return
false
;
return
false
;
// If strict matching check profile-level-id.
// If strict matching check profile-level-id.
...
@@ -440,7 +779,6 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
...
@@ -440,7 +779,6 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
return
false
;
return
false
;
}
}
if
(
modify
)
{
if
(
modify
)
{
aCodec
.
parameters
=
aCodec
.
parameters
||
{};
if
(
selectedProfileLevelId
)
if
(
selectedProfileLevelId
)
aCodec
.
parameters
[
'profile-level-id'
]
=
selectedProfileLevelId
;
aCodec
.
parameters
[
'profile-level-id'
]
=
selectedProfileLevelId
;
else
else
...
@@ -453,8 +791,8 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
...
@@ -453,8 +791,8 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
{
{
// If strict matching check profile-id.
// If strict matching check profile-id.
if
(
strict
)
{
if
(
strict
)
{
const
aProfileId
=
(
aCodec
.
parameters
||
{})
[
'profile-id'
]
||
0
;
const
aProfileId
=
aCodec
.
parameters
[
'profile-id'
]
||
0
;
const
bProfileId
=
(
bCodec
.
parameters
||
{})
[
'profile-id'
]
||
0
;
const
bProfileId
=
bCodec
.
parameters
[
'profile-id'
]
||
0
;
if
(
aProfileId
!==
bProfileId
)
if
(
aProfileId
!==
bProfileId
)
return
false
;
return
false
;
}
}
...
...
lib/supportedRtpCapabilities.d.ts.map
浏览文件 @
e51c3af8
{"version":3,"file":"supportedRtpCapabilities.d.ts","sourceRoot":"","sources":["../src/supportedRtpCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,QAAA,MAAM,wBAAwB,EAAE,eAsV/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
{"version":3,"file":"supportedRtpCapabilities.d.ts","sourceRoot":"","sources":["../src/supportedRtpCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,QAAA,MAAM,wBAAwB,EAAE,eAqV/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
\ No newline at end of file
\ No newline at end of file
lib/supportedRtpCapabilities.js
浏览文件 @
e51c3af8
...
@@ -315,7 +315,6 @@ const supportedRtpCapabilities = {
...
@@ -315,7 +315,6 @@ const supportedRtpCapabilities = {
preferredEncrypt
:
false
,
preferredEncrypt
:
false
,
direction
:
'sendrecv'
direction
:
'sendrecv'
}
}
],
]
fecMechanisms
:
[]
};
};
exports
.
supportedRtpCapabilities
=
supportedRtpCapabilities
;
exports
.
supportedRtpCapabilities
=
supportedRtpCapabilities
;
src/Transport.ts
浏览文件 @
e51c3af8
...
@@ -397,14 +397,21 @@ export class Transport extends EnhancedEventEmitter
...
@@ -397,14 +397,21 @@ export class Transport extends EnhancedEventEmitter
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
else
if
(
typeof
rtpParameters
!==
'object'
)
throw
new
TypeError
(
'missing rtpParameters'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// If missing encodings, add one.
// This may throw.
if
(
!
rtpParameters
.
encodings
||
!
Array
.
isArray
(
rtpParameters
.
encodings
))
ortc
.
validateRtpParameters
(
rtpParameters
);
// If missing or empty encodings, add one.
if
(
!
rtpParameters
.
encodings
||
!
Array
.
isArray
(
rtpParameters
.
encodings
)
||
rtpParameters
.
encodings
.
length
===
0
)
{
rtpParameters
.
encodings
=
[
{}
];
rtpParameters
.
encodings
=
[
{}
];
}
// Don't do this in PipeTransports since there we must keep CNAME value in
// Don't do this in PipeTransports since there we must keep CNAME value in
// each Producer.
// each Producer.
...
@@ -495,11 +502,12 @@ export class Transport extends EnhancedEventEmitter
...
@@ -495,11 +502,12 @@ export class Transport extends EnhancedEventEmitter
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
throw
new
TypeError
(
'missing producerId'
);
else
if
(
typeof
rtpCapabilities
!==
'object'
)
throw
new
TypeError
(
'missing rtpCapabilities'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateRtpCapabilities
(
rtpCapabilities
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
if
(
!
producer
)
...
@@ -564,11 +572,12 @@ export class Transport extends EnhancedEventEmitter
...
@@ -564,11 +572,12 @@ export class Transport extends EnhancedEventEmitter
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
else
if
(
typeof
sctpStreamParameters
!==
'object'
)
throw
new
TypeError
(
'missing sctpStreamParameters'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateSctpStreamParameters
(
sctpStreamParameters
);
const
internal
=
{
...
this
.
_internal
,
dataProducerId
:
id
||
uuidv4
()
};
const
internal
=
{
...
this
.
_internal
,
dataProducerId
:
id
||
uuidv4
()
};
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
...
...
src/ortc.ts
浏览文件 @
e51c3af8
...
@@ -4,14 +4,23 @@ import { UnsupportedError } from './errors';
...
@@ -4,14 +4,23 @@ import { UnsupportedError } from './errors';
import
{
supportedRtpCapabilities
}
from
'./supportedRtpCapabilities'
;
import
{
supportedRtpCapabilities
}
from
'./supportedRtpCapabilities'
;
import
{
parse
as
parseScalabilityMode
}
from
'./scalabilityModes'
;
import
{
parse
as
parseScalabilityMode
}
from
'./scalabilityModes'
;
import
{
import
{
MediaKind
,
RtpCapabilities
,
RtpCapabilities
,
MediaKind
,
RtpCodecCapability
,
RtpCodecCapability
,
RtpHeaderExtension
,
RtpParameters
,
RtpParameters
,
RtpCodecParameters
,
RtpCodecParameters
,
RtcpFeedback
,
RtcpFeedback
,
RtpEncodingParameters
RtpEncodingParameters
,
RtpHeaderExtensionParameters
,
RtcpParameters
}
from
'./RtpParameters'
;
}
from
'./RtpParameters'
;
import
{
SctpCapabilities
,
NumSctpStreams
,
SctpParameters
,
SctpStreamParameters
}
from
'./SctpParameters'
;
interface
RtpMapping
interface
RtpMapping
{
{
...
@@ -37,29 +46,512 @@ const DynamicPayloadTypes =
...
@@ -37,29 +46,512 @@ const DynamicPayloadTypes =
122
,
123
,
124
,
125
,
126
,
127
,
96
,
97
,
98
,
99
122
,
123
,
124
,
125
,
126
,
127
,
96
,
97
,
98
,
99
];
];
/**
* Validates RtpCapabilities. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtpCapabilities
(
caps
:
RtpCapabilities
):
void
{
if
(
typeof
caps
!==
'object'
)
throw
new
TypeError
(
'caps is not an object'
);
// codecs is optional. If unset, fill with an empty array.
if
(
caps
.
codecs
&&
!
Array
.
isArray
(
caps
.
codecs
))
throw
new
TypeError
(
'caps.codecs is not an array'
);
else
if
(
!
caps
.
codecs
)
caps
.
codecs
=
[];
for
(
const
codec
of
caps
.
codecs
)
{
validateRtpCodecCapability
(
codec
);
}
// headerExtensions is optional. If unset, fill with an empty array.
if
(
caps
.
headerExtensions
&&
!
Array
.
isArray
(
caps
.
headerExtensions
))
throw
new
TypeError
(
'caps.headerExtensions is not an array'
);
else
if
(
!
caps
.
headerExtensions
)
caps
.
headerExtensions
=
[];
for
(
const
ext
of
caps
.
headerExtensions
)
{
validateRtpHeaderExtension
(
ext
);
}
}
/**
* Validates RtpCodecCapability. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtpCodecCapability
(
codec
:
RtpCodecCapability
):
void
{
const
MimeTypeRegex
=
new
RegExp
(
'^(audio|video)/(.+)'
,
'i'
);
if
(
typeof
codec
!==
'object'
)
throw
new
TypeError
(
'codec is not an object'
);
// mimeType is mandatory.
if
(
!
codec
.
mimeType
||
typeof
codec
.
mimeType
!==
'string'
)
throw
new
TypeError
(
'missing codec.mimeType'
);
const
mimeTypeMatch
=
MimeTypeRegex
.
exec
(
codec
.
mimeType
);
if
(
!
mimeTypeMatch
)
throw
new
TypeError
(
'invalid codec.mimeType'
);
// Just override kind with media component of mimeType.
codec
.
kind
=
mimeTypeMatch
[
1
].
toLowerCase
()
as
MediaKind
;
// preferredPayloadType is optional.
if
(
codec
.
preferredPayloadType
&&
typeof
codec
.
preferredPayloadType
!==
'number'
)
throw
new
TypeError
(
'invalid codec.preferredPayloadType'
);
// clockRate is mandatory.
if
(
typeof
codec
.
clockRate
!==
'number'
)
throw
new
TypeError
(
'missing codec.clockRate'
);
// channels is optional. If unset, set it to 1.
if
(
typeof
codec
.
channels
!==
'number'
)
codec
.
channels
=
1
;
// parameters is optional. If unset, set it to an empty object.
if
(
!
codec
.
parameters
||
typeof
codec
.
parameters
!==
'object'
)
codec
.
parameters
=
{};
for
(
const
key
of
Object
.
keys
(
codec
.
parameters
))
{
const
value
=
codec
.
parameters
[
key
];
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec parameter'
);
// Specific parameters validation.
if
(
key
===
'apt'
)
{
if
(
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec apt parameter'
);
}
}
// rtcpFeedback is optional. If unset, set it to an empty array.
if
(
!
codec
.
rtcpFeedback
||
!
Array
.
isArray
(
codec
.
rtcpFeedback
))
codec
.
rtcpFeedback
=
[];
for
(
const
fb
of
codec
.
rtcpFeedback
)
{
validateRtcpFeedback
(
fb
);
}
}
/**
* Validates RtcpFeedback. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtcpFeedback
(
fb
:
RtcpFeedback
):
void
{
if
(
typeof
fb
!==
'object'
)
throw
new
TypeError
(
'fb is not an object'
);
// type is mandatory.
if
(
!
fb
.
type
||
typeof
fb
.
type
!==
'string'
)
throw
new
TypeError
(
'missing fb.type'
);
// parameter is optional. If unset set it to an empty string.
if
(
!
fb
.
parameter
||
typeof
fb
.
parameter
!==
'string'
)
fb
.
parameter
=
''
;
}
/**
* Validates RtpHeaderExtension. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtpHeaderExtension
(
ext
:
RtpHeaderExtension
):
void
{
if
(
typeof
ext
!==
'object'
)
throw
new
TypeError
(
'ext is not an object'
);
// kind is optional. If unset set it to an empty string.
if
(
!
ext
.
kind
||
typeof
ext
.
kind
!==
'string'
)
ext
.
kind
=
''
;
if
(
ext
.
kind
!==
''
&&
ext
.
kind
!==
'audio'
&&
ext
.
kind
!==
'video'
)
throw
new
TypeError
(
'invalid ext.kind'
);
// uri is mandatory.
if
(
!
ext
.
uri
||
typeof
ext
.
uri
!==
'string'
)
throw
new
TypeError
(
'missing ext.uri'
);
// preferredId is mandatory.
if
(
typeof
ext
.
preferredId
!==
'number'
)
throw
new
TypeError
(
'missing ext.preferredId'
);
// preferredEncrypt is optional. If unset set it to false.
if
(
ext
.
preferredEncrypt
&&
typeof
ext
.
preferredEncrypt
!==
'boolean'
)
throw
new
TypeError
(
'invalid ext.preferredEncrypt'
);
else
if
(
!
ext
.
preferredEncrypt
)
ext
.
preferredEncrypt
=
false
;
// direction is optional. If unset set it to sendrecv.
if
(
ext
.
direction
&&
typeof
ext
.
direction
!==
'string'
)
throw
new
TypeError
(
'invalid ext.direction'
);
else
if
(
!
ext
.
direction
)
ext
.
direction
=
'sendrecv'
;
}
/**
* Validates RtpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtpParameters
(
params
:
RtpParameters
):
void
{
if
(
typeof
params
!==
'object'
)
throw
new
TypeError
(
'params is not an object'
);
// mid is optional.
if
(
params
.
mid
&&
typeof
params
.
mid
!==
'string'
)
throw
new
TypeError
(
'params.mid is not a string'
);
// codecs is mandatory.
if
(
!
Array
.
isArray
(
params
.
codecs
))
throw
new
TypeError
(
'missing params.codecs'
);
for
(
const
codec
of
params
.
codecs
)
{
validateRtpCodecParameters
(
codec
);
}
// headerExtensions is optional. If unset, fill with an empty array.
if
(
params
.
headerExtensions
&&
!
Array
.
isArray
(
params
.
headerExtensions
))
throw
new
TypeError
(
'params.headerExtensions is not an array'
);
else
if
(
!
params
.
headerExtensions
)
params
.
headerExtensions
=
[];
for
(
const
ext
of
params
.
headerExtensions
)
{
validateRtpHeaderExtensionParameters
(
ext
);
}
// encodings is optional. If unset, fill with an empty array.
if
(
params
.
encodings
&&
!
Array
.
isArray
(
params
.
encodings
))
throw
new
TypeError
(
'params.encodings is not an array'
);
else
if
(
!
params
.
encodings
)
params
.
encodings
=
[];
for
(
const
encoding
of
params
.
encodings
)
{
validateRtpEncodingParameters
(
encoding
);
}
// rtcp is optional. If unset, fill with an empty object.
if
(
params
.
rtcp
&&
typeof
params
.
rtcp
!==
'object'
)
throw
new
TypeError
(
'params.rtcp is not an object'
);
else
if
(
!
params
.
rtcp
)
params
.
rtcp
=
{};
validateRtcpParameters
(
params
.
rtcp
);
}
/**
* Validates RtpCodecParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtpCodecParameters
(
codec
:
RtpCodecParameters
):
void
{
const
MimeTypeRegex
=
new
RegExp
(
'^(audio|video)/(.+)'
,
'i'
);
if
(
typeof
codec
!==
'object'
)
throw
new
TypeError
(
'codec is not an object'
);
// mimeType is mandatory.
if
(
!
codec
.
mimeType
||
typeof
codec
.
mimeType
!==
'string'
)
throw
new
TypeError
(
'missing codec.mimeType'
);
const
mimeTypeMatch
=
MimeTypeRegex
.
exec
(
codec
.
mimeType
);
if
(
!
mimeTypeMatch
)
throw
new
TypeError
(
'invalid codec.mimeType'
);
// payloadType is mandatory.
if
(
typeof
codec
.
payloadType
!==
'number'
)
throw
new
TypeError
(
'missing codec.payloadType'
);
// clockRate is mandatory.
if
(
typeof
codec
.
clockRate
!==
'number'
)
throw
new
TypeError
(
'missing codec.clockRate'
);
// channels is optional. If unset, set it to 1.
if
(
typeof
codec
.
channels
!==
'number'
)
codec
.
channels
=
1
;
// parameters is optional. If unset, set it to an empty object.
if
(
!
codec
.
parameters
||
typeof
codec
.
parameters
!==
'object'
)
codec
.
parameters
=
{};
for
(
const
key
of
Object
.
keys
(
codec
.
parameters
))
{
const
value
=
codec
.
parameters
[
key
];
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec parameter'
);
// Specific parameters validation.
if
(
key
===
'apt'
)
{
if
(
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid codec apt parameter'
);
}
}
// rtcpFeedback is optional. If unset, set it to an empty array.
if
(
!
codec
.
rtcpFeedback
||
!
Array
.
isArray
(
codec
.
rtcpFeedback
))
codec
.
rtcpFeedback
=
[];
for
(
const
fb
of
codec
.
rtcpFeedback
)
{
validateRtcpFeedback
(
fb
);
}
}
/**
* Validates RtpHeaderExtensionParameteters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtpHeaderExtensionParameters
(
ext
:
RtpHeaderExtensionParameters
):
void
{
if
(
typeof
ext
!==
'object'
)
throw
new
TypeError
(
'ext is not an object'
);
// uri is mandatory.
if
(
!
ext
.
uri
||
typeof
ext
.
uri
!==
'string'
)
throw
new
TypeError
(
'missing ext.uri'
);
// id is mandatory.
if
(
typeof
ext
.
id
!==
'number'
)
throw
new
TypeError
(
'missing ext.id'
);
// encrypt is optional. If unset set it to false.
if
(
ext
.
encrypt
&&
typeof
ext
.
encrypt
!==
'boolean'
)
throw
new
TypeError
(
'invalid ext.encrypt'
);
else
if
(
!
ext
.
encrypt
)
ext
.
encrypt
=
false
;
// parameters is optional. If unset, set it to an empty object.
if
(
!
ext
.
parameters
||
typeof
ext
.
parameters
!==
'object'
)
ext
.
parameters
=
{};
for
(
const
key
of
Object
.
keys
(
ext
.
parameters
))
{
const
value
=
ext
.
parameters
[
key
];
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
throw
new
TypeError
(
'invalid header extension parameter'
);
}
}
/**
* Validates RtpEncodingParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtpEncodingParameters
(
encoding
:
RtpEncodingParameters
):
void
{
if
(
typeof
encoding
!==
'object'
)
throw
new
TypeError
(
'encoding is not an object'
);
// ssrc is optional.
if
(
encoding
.
ssrc
&&
typeof
encoding
.
ssrc
!==
'number'
)
throw
new
TypeError
(
'invalid encoding.ssrc'
);
// rid is optional.
if
(
encoding
.
rid
&&
typeof
encoding
.
rid
!==
'string'
)
throw
new
TypeError
(
'invalid encoding.rid'
);
// rtx is optional.
if
(
encoding
.
rtx
&&
typeof
encoding
.
rtx
!==
'object'
)
{
throw
new
TypeError
(
'invalid encoding.rtx'
);
}
else
if
(
encoding
.
rtx
)
{
// RTX ssrc is mandatory if rtx is present.
if
(
typeof
encoding
.
rtx
.
ssrc
!==
'number'
)
throw
new
TypeError
(
'missing encoding.rtx.ssrc'
);
}
// dtx is optional. If unset set it to false.
if
(
!
encoding
.
dtx
||
typeof
encoding
.
dtx
!==
'boolean'
)
encoding
.
dtx
=
false
;
// scalabilityMode is optional.
if
(
encoding
.
scalabilityMode
&&
typeof
encoding
.
scalabilityMode
!==
'string'
)
throw
new
TypeError
(
'invalid encoding.scalabilityMode'
);
}
/**
* Validates RtcpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateRtcpParameters
(
rtcp
:
RtcpParameters
):
void
{
if
(
typeof
rtcp
!==
'object'
)
throw
new
TypeError
(
'rtcp is not an object'
);
// cname is optional.
if
(
rtcp
.
cname
&&
typeof
rtcp
.
cname
!==
'string'
)
throw
new
TypeError
(
'invalid rtcp.cname'
);
// reducedSize is optional. If unset set it to true.
if
(
!
rtcp
.
reducedSize
||
typeof
rtcp
.
reducedSize
!==
'boolean'
)
rtcp
.
reducedSize
=
true
;
}
/**
* Validates SctpCapabilities. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateSctpCapabilities
(
caps
:
SctpCapabilities
):
void
{
if
(
typeof
caps
!==
'object'
)
throw
new
TypeError
(
'caps is not an object'
);
// numStreams is mandatory.
if
(
!
caps
.
numStreams
||
typeof
caps
.
numStreams
!==
'object'
)
throw
new
TypeError
(
'missing caps.numStreams'
);
validateNumSctpStreams
(
caps
.
numStreams
);
}
/**
* Validates NumSctpStreams. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateNumSctpStreams
(
numStreams
:
NumSctpStreams
):
void
{
if
(
typeof
numStreams
!==
'object'
)
throw
new
TypeError
(
'numStreams is not an object'
);
// OS is mandatory.
if
(
typeof
numStreams
.
OS
!==
'number'
)
throw
new
TypeError
(
'missing numStreams.OS'
);
// MIS is mandatory.
if
(
typeof
numStreams
.
MIS
!==
'number'
)
throw
new
TypeError
(
'missing numStreams.MIS'
);
}
/**
* Validates SctpParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateSctpParameters
(
params
:
SctpParameters
):
void
{
if
(
typeof
params
!==
'object'
)
throw
new
TypeError
(
'params is not an object'
);
// port is mandatory.
if
(
typeof
params
.
port
!==
'number'
)
throw
new
TypeError
(
'missing params.port'
);
// OS is mandatory.
if
(
typeof
params
.
OS
!==
'number'
)
throw
new
TypeError
(
'missing params.OS'
);
// MIS is mandatory.
if
(
typeof
params
.
MIS
!==
'number'
)
throw
new
TypeError
(
'missing params.MIS'
);
// maxMessageSize is mandatory.
if
(
typeof
params
.
maxMessageSize
!==
'number'
)
throw
new
TypeError
(
'missing params.maxMessageSize'
);
}
/**
* Validates SctpStreamParameters. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
export
function
validateSctpStreamParameters
(
params
:
SctpStreamParameters
):
void
{
if
(
typeof
params
!==
'object'
)
throw
new
TypeError
(
'params is not an object'
);
// streamId is mandatory.
if
(
typeof
params
.
streamId
!==
'number'
)
throw
new
TypeError
(
'missing params.streamId'
);
// ordered is optional.
let
orderedGiven
=
false
;
if
(
typeof
params
.
ordered
===
'boolean'
)
orderedGiven
=
true
;
else
params
.
ordered
=
true
;
// maxPacketLifeTime is optional.
if
(
params
.
maxPacketLifeTime
&&
typeof
params
.
maxPacketLifeTime
!==
'number'
)
throw
new
TypeError
(
'invalid params.maxPacketLifeTime'
);
// maxRetransmits is optional.
if
(
params
.
maxRetransmits
&&
typeof
params
.
maxRetransmits
!==
'number'
)
throw
new
TypeError
(
'invalid params.maxRetransmits'
);
if
(
params
.
maxPacketLifeTime
&&
params
.
maxRetransmits
)
throw
new
TypeError
(
'cannot provide both maxPacketLifeTime and maxRetransmits'
);
if
(
orderedGiven
&&
params
.
ordered
&&
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
)
)
{
throw
new
TypeError
(
'cannot be ordered with maxPacketLifeTime or maxRetransmits'
);
}
else
if
(
!
orderedGiven
&&
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
))
{
params
.
ordered
=
false
;
}
}
/**
/**
* 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.
*/
*/
export
function
generateRouterRtpCapabilities
(
export
function
generateRouterRtpCapabilities
(
mediaCodecs
:
RtpCodecCapability
[]
=
[]
mediaCodecs
:
RtpCodecCapability
[]
=
[]
):
R
TCR
tpCapabilities
):
RtpCapabilities
{
{
// Normalize supported RTP capabilities.
validateRtpCapabilities
(
supportedRtpCapabilities
);
if
(
!
Array
.
isArray
(
mediaCodecs
))
if
(
!
Array
.
isArray
(
mediaCodecs
))
throw
new
TypeError
(
'mediaCodecs must be an Array'
);
throw
new
TypeError
(
'mediaCodecs must be an Array'
);
const
dynamicPayloadTypes
=
utils
.
clone
(
DynamicPayloadTypes
)
as
number
[];
const
dynamicPayloadTypes
=
utils
.
clone
(
DynamicPayloadTypes
)
as
number
[];
const
supportedCodecs
=
supportedRtpCapabilities
.
codecs
;
const
supportedCodecs
=
supportedRtpCapabilities
.
codecs
;
const
caps
=
const
caps
:
RtpCapabilities
=
{
{
codecs
:
[]
as
RtpCodecCapability
[],
codecs
:
[],
headerExtensions
:
supportedRtpCapabilities
.
headerExtensions
,
headerExtensions
:
supportedRtpCapabilities
.
headerExtensions
fecMechanisms
:
supportedRtpCapabilities
.
fecMechanisms
};
};
for
(
const
mediaCodec
of
mediaCodecs
)
for
(
const
mediaCodec
of
mediaCodecs
)
{
{
assertCodecCapability
(
mediaCodec
);
// This may throw.
validateRtpCodecCapability
(
mediaCodec
);
const
matchedSupportedCodec
=
supportedCodecs
const
matchedSupportedCodec
=
supportedCodecs
.
find
((
supportedCodec
)
=>
(
.
find
((
supportedCodec
)
=>
(
...
@@ -105,20 +597,11 @@ export function generateRouterRtpCapabilities(
...
@@ -105,20 +597,11 @@ export function generateRouterRtpCapabilities(
// Ensure there is not duplicated preferredPayloadType values.
// Ensure there is not duplicated preferredPayloadType values.
if
(
caps
.
codecs
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
if
(
caps
.
codecs
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
throw
new
Error
(
'duplicated codec.preferredPayloadType'
);
throw
new
TypeError
(
'duplicated codec.preferredPayloadType'
);
// Normalize channels.
if
(
codec
.
kind
!==
'audio'
)
delete
codec
.
channels
;
else
if
(
!
codec
.
channels
)
codec
.
channels
=
1
;
// Merge the media codec parameters.
// Merge the media codec parameters.
codec
.
parameters
=
{
...
codec
.
parameters
,
...
mediaCodec
.
parameters
};
codec
.
parameters
=
{
...
codec
.
parameters
,
...
mediaCodec
.
parameters
};
// Make rtcpFeedback an array.
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
||
[];
// Append to the codec list.
// Append to the codec list.
caps
.
codecs
.
push
(
codec
);
caps
.
codecs
.
push
(
codec
);
...
@@ -131,17 +614,18 @@ export function generateRouterRtpCapabilities(
...
@@ -131,17 +614,18 @@ export function generateRouterRtpCapabilities(
if
(
!
pt
)
if
(
!
pt
)
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
const
rtxCodec
=
const
rtxCodec
:
RtpCodecCapability
=
{
{
kind
:
codec
.
kind
,
kind
:
codec
.
kind
,
mimeType
:
`
${
codec
.
kind
}
/rtx`
,
mimeType
:
`
${
codec
.
kind
}
/rtx`
,
preferredPayloadType
:
pt
,
preferredPayloadType
:
pt
,
clockRate
:
codec
.
clockRate
,
clockRate
:
codec
.
clockRate
,
rtcpFeedback
:
[]
as
RtcpFeedback
[]
,
channels
:
1
,
parameters
:
parameters
:
{
{
apt
:
codec
.
preferredPayloadType
apt
:
codec
.
preferredPayloadType
}
},
rtcpFeedback
:
[]
};
};
// Append to the codec list.
// Append to the codec list.
...
@@ -172,11 +656,9 @@ export function getProducerRtpParametersMapping(
...
@@ -172,11 +656,9 @@ export function getProducerRtpParametersMapping(
// Match parameters media codecs to capabilities media codecs.
// Match parameters media codecs to capabilities media codecs.
const
codecToCapCodec
:
Map
<
RtpCodecParameters
,
RtpCodecCapability
>
=
new
Map
();
const
codecToCapCodec
:
Map
<
RtpCodecParameters
,
RtpCodecCapability
>
=
new
Map
();
for
(
const
codec
of
params
.
codecs
||
[]
)
for
(
const
codec
of
params
.
codecs
)
{
{
assertCodecParameters
(
codec
);
if
(
isRtxCodec
(
codec
))
if
(
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
continue
;
continue
;
// Search for the same media codec in capabilities.
// Search for the same media codec in capabilities.
...
@@ -195,12 +677,10 @@ export function getProducerRtpParametersMapping(
...
@@ -195,12 +677,10 @@ export function getProducerRtpParametersMapping(
}
}
// Match parameters RTX codecs to capabilities RTX codecs.
// Match parameters RTX codecs to capabilities RTX codecs.
for
(
const
codec
of
params
.
codecs
||
[]
)
for
(
const
codec
of
params
.
codecs
)
{
{
if
(
!
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
if
(
!
isRtxCodec
(
codec
))
continue
;
continue
;
else
if
(
typeof
codec
.
parameters
!==
'object'
)
throw
TypeError
(
'missing parameters in RTX codec'
);
// Search for the associated media codec.
// Search for the associated media codec.
const
associatedMediaCodec
=
params
.
codecs
const
associatedMediaCodec
=
params
.
codecs
...
@@ -217,7 +697,7 @@ export function getProducerRtpParametersMapping(
...
@@ -217,7 +697,7 @@ export function getProducerRtpParametersMapping(
// Ensure that the capabilities media codec has a RTX codec.
// Ensure that the capabilities media codec has a RTX codec.
const
associatedCapRtxCodec
=
caps
.
codecs
const
associatedCapRtxCodec
=
caps
.
codecs
.
find
((
capCodec
)
=>
(
.
find
((
capCodec
)
=>
(
/.+
\/
rtx$/i
.
test
(
capCodec
.
mimeType
)
&&
isRtxCodec
(
capCodec
)
&&
capCodec
.
parameters
.
apt
===
capMediaCodec
.
preferredPayloadType
capCodec
.
parameters
.
apt
===
capMediaCodec
.
preferredPayloadType
));
));
...
@@ -243,7 +723,7 @@ export function getProducerRtpParametersMapping(
...
@@ -243,7 +723,7 @@ export function getProducerRtpParametersMapping(
// Generate encodings mapping.
// Generate encodings mapping.
let
mappedSsrc
=
utils
.
generateRandomNumber
();
let
mappedSsrc
=
utils
.
generateRandomNumber
();
for
(
const
encoding
of
(
params
.
encodings
||
[])
)
for
(
const
encoding
of
params
.
encodings
)
{
{
const
mappedEncoding
:
any
=
{};
const
mappedEncoding
:
any
=
{};
...
@@ -281,11 +761,9 @@ export function getConsumableRtpParameters(
...
@@ -281,11 +761,9 @@ export function getConsumableRtpParameters(
rtcp
:
{}
rtcp
:
{}
};
};
for
(
const
codec
of
params
.
codecs
||
[]
)
for
(
const
codec
of
params
.
codecs
)
{
{
assertCodecParameters
(
codec
);
if
(
isRtxCodec
(
codec
))
if
(
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
continue
;
continue
;
const
consumableCodecPt
=
rtpMapping
.
codecs
const
consumableCodecPt
=
rtpMapping
.
codecs
...
@@ -298,21 +776,18 @@ export function getConsumableRtpParameters(
...
@@ -298,21 +776,18 @@ export function getConsumableRtpParameters(
const
consumableCodec
=
const
consumableCodec
=
{
{
mimeType
:
matchedCapCodec
.
mimeType
,
mimeType
:
matchedCapCodec
.
mimeType
,
clockRate
:
matchedCapCodec
.
clockRate
,
payloadType
:
matchedCapCodec
.
preferredPayloadType
,
payloadType
:
matchedCapCodec
.
preferredPayloadType
,
clockRate
:
matchedCapCodec
.
clockRate
,
channels
:
matchedCapCodec
.
channels
,
channels
:
matchedCapCodec
.
channels
,
rtcpFeedback
:
matchedCapCodec
.
rtcpFeedback
,
parameters
:
codec
.
parameters
,
// Keep the Producer codec parameters.
parameters
:
codec
.
parameters
// Keep the Producer parameters.
rtcpFeedback
:
matchedCapCodec
.
rtcpFeedback
};
};
if
(
!
consumableCodec
.
channels
)
delete
consumableCodec
.
channels
;
consumableParams
.
codecs
.
push
(
consumableCodec
);
consumableParams
.
codecs
.
push
(
consumableCodec
);
const
consumableCapRtxCodec
=
caps
.
codecs
const
consumableCapRtxCodec
=
caps
.
codecs
.
find
((
capRtxCodec
)
=>
(
.
find
((
capRtxCodec
)
=>
(
/.+
\/
rtx$/i
.
test
(
capRtxCodec
.
mimeType
)
&&
isRtxCodec
(
capRtxCodec
)
&&
capRtxCodec
.
parameters
.
apt
===
consumableCodec
.
payloadType
capRtxCodec
.
parameters
.
apt
===
consumableCodec
.
payloadType
));
));
...
@@ -321,16 +796,13 @@ export function getConsumableRtpParameters(
...
@@ -321,16 +796,13 @@ export function getConsumableRtpParameters(
const
consumableRtxCodec
=
const
consumableRtxCodec
=
{
{
mimeType
:
consumableCapRtxCodec
.
mimeType
,
mimeType
:
consumableCapRtxCodec
.
mimeType
,
clockRate
:
consumableCapRtxCodec
.
clockRate
,
payloadType
:
consumableCapRtxCodec
.
preferredPayloadType
,
payloadType
:
consumableCapRtxCodec
.
preferredPayloadType
,
channels
:
consumableCapRtxCodec
.
channels
,
clockRate
:
consumableCapRtxCodec
.
clockRate
,
rtcpFeedback
:
consumableCapRtxCodec
.
rtcpFeedback
,
channels
:
1
,
parameters
:
consumableCapRtxCodec
.
parameters
parameters
:
consumableCapRtxCodec
.
parameters
,
rtcpFeedback
:
consumableCapRtxCodec
.
rtcpFeedback
};
};
if
(
!
consumableRtxCodec
.
channels
)
delete
consumableRtxCodec
.
channels
;
consumableParams
.
codecs
.
push
(
consumableRtxCodec
);
consumableParams
.
codecs
.
push
(
consumableRtxCodec
);
}
}
}
}
...
@@ -350,7 +822,9 @@ export function getConsumableRtpParameters(
...
@@ -350,7 +822,9 @@ export function getConsumableRtpParameters(
const
consumableExt
=
const
consumableExt
=
{
{
uri
:
capExt
.
uri
,
uri
:
capExt
.
uri
,
id
:
capExt
.
preferredId
id
:
capExt
.
preferredId
,
encrypt
:
capExt
.
preferredEncrypt
,
parameters
:
{}
};
};
consumableParams
.
headerExtensions
.
push
(
consumableExt
);
consumableParams
.
headerExtensions
.
push
(
consumableExt
);
...
@@ -393,12 +867,10 @@ export function canConsume(
...
@@ -393,12 +867,10 @@ export function canConsume(
caps
:
RtpCapabilities
caps
:
RtpCapabilities
):
boolean
):
boolean
{
{
const
matchingCodecs
=
[]
as
RtpCodecParameters
[];
// This may throw.
validateRtpCapabilities
(
caps
);
for
(
const
capCodec
of
caps
.
codecs
||
[])
const
matchingCodecs
:
RtpCodecParameters
[]
=
[];
{
assertCodecCapability
(
capCodec
);
}
for
(
const
codec
of
consumableParams
.
codecs
)
for
(
const
codec
of
consumableParams
.
codecs
)
{
{
...
@@ -412,13 +884,8 @@ export function canConsume(
...
@@ -412,13 +884,8 @@ export function canConsume(
}
}
// Ensure there is at least one media codec.
// Ensure there is at least one media codec.
if
(
if
(
matchingCodecs
.
length
===
0
||
isRtxCodec
(
matchingCodecs
[
0
]))
matchingCodecs
.
length
===
0
||
/.+
\/
rtx$/i
.
test
(
matchingCodecs
[
0
].
mimeType
)
)
{
return
false
;
return
false
;
}
return
true
;
return
true
;
}
}
...
@@ -443,13 +910,13 @@ export function getConsumerRtpParameters(
...
@@ -443,13 +910,13 @@ export function getConsumerRtpParameters(
rtcp
:
consumableParams
.
rtcp
rtcp
:
consumableParams
.
rtcp
};
};
for
(
const
capCodec
of
caps
.
codecs
||
[]
)
for
(
const
capCodec
of
caps
.
codecs
)
{
{
assert
CodecCapability
(
capCodec
);
validateRtp
CodecCapability
(
capCodec
);
}
}
const
consumableCodecs
=
const
consumableCodecs
=
utils
.
clone
(
consumableParams
.
codecs
||
[]
)
as
RtpCodecParameters
[];
utils
.
clone
(
consumableParams
.
codecs
)
as
RtpCodecParameters
[];
let
rtxSupported
=
false
;
let
rtxSupported
=
false
;
...
@@ -461,26 +928,23 @@ export function getConsumerRtpParameters(
...
@@ -461,26 +928,23 @@ export function getConsumerRtpParameters(
if
(
!
matchedCapCodec
)
if
(
!
matchedCapCodec
)
continue
;
continue
;
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
||
[]
;
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
;
consumerParams
.
codecs
.
push
(
codec
);
consumerParams
.
codecs
.
push
(
codec
);
if
(
!
rtxSupported
&&
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
if
(
!
rtxSupported
&&
isRtxCodec
(
codec
))
rtxSupported
=
true
;
rtxSupported
=
true
;
}
}
// Ensure there is at least one media codec.
// Ensure there is at least one media codec.
if
(
if
(
consumerParams
.
codecs
.
length
===
0
||
isRtxCodec
(
consumerParams
.
codecs
[
0
]))
consumerParams
.
codecs
.
length
===
0
||
/.+
\/
rtx$/i
.
test
(
consumerParams
.
codecs
[
0
].
mimeType
)
)
{
{
throw
new
UnsupportedError
(
'no compatible media codecs'
);
throw
new
UnsupportedError
(
'no compatible media codecs'
);
}
}
consumerParams
.
headerExtensions
=
consumableParams
.
headerExtensions
consumerParams
.
headerExtensions
=
consumableParams
.
headerExtensions
.
filter
((
ext
)
=>
(
.
filter
((
ext
)
=>
(
(
caps
.
headerExtensions
||
[]
)
(
caps
.
headerExtensions
)
.
some
((
capExt
)
=>
capExt
.
preferredId
===
ext
.
id
)
.
some
((
capExt
)
=>
capExt
.
preferredId
===
ext
.
id
)
));
));
...
@@ -493,7 +957,7 @@ export function getConsumerRtpParameters(
...
@@ -493,7 +957,7 @@ export function getConsumerRtpParameters(
{
{
for
(
const
codec
of
consumerParams
.
codecs
)
for
(
const
codec
of
consumerParams
.
codecs
)
{
{
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
||
[]
)
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
)
.
filter
((
fb
)
=>
fb
.
type
!==
'goog-remb'
);
.
filter
((
fb
)
=>
fb
.
type
!==
'goog-remb'
);
}
}
}
}
...
@@ -505,7 +969,7 @@ export function getConsumerRtpParameters(
...
@@ -505,7 +969,7 @@ export function getConsumerRtpParameters(
{
{
for
(
const
codec
of
consumerParams
.
codecs
)
for
(
const
codec
of
consumerParams
.
codecs
)
{
{
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
||
[]
)
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
)
.
filter
((
fb
)
=>
fb
.
type
!==
'transport-cc'
);
.
filter
((
fb
)
=>
fb
.
type
!==
'transport-cc'
);
}
}
}
}
...
@@ -513,7 +977,7 @@ export function getConsumerRtpParameters(
...
@@ -513,7 +977,7 @@ export function getConsumerRtpParameters(
{
{
for
(
const
codec
of
consumerParams
.
codecs
)
for
(
const
codec
of
consumerParams
.
codecs
)
{
{
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
||
[]
)
codec
.
rtcpFeedback
=
(
codec
.
rtcpFeedback
)
.
filter
((
fb
)
=>
(
.
filter
((
fb
)
=>
(
fb
.
type
!==
'transport-cc'
&&
fb
.
type
!==
'transport-cc'
&&
fb
.
type
!==
'goog-remb'
fb
.
type
!==
'goog-remb'
...
@@ -577,13 +1041,14 @@ export function getPipeConsumerRtpParameters(
...
@@ -577,13 +1041,14 @@ export function getPipeConsumerRtpParameters(
};
};
const
consumableCodecs
=
const
consumableCodecs
=
utils
.
clone
(
consumableParams
.
codecs
||
[]
)
as
RtpCodecParameters
[];
utils
.
clone
(
consumableParams
.
codecs
)
as
RtpCodecParameters
[];
for
(
const
codec
of
consumableCodecs
)
for
(
const
codec
of
consumableCodecs
)
{
{
if
(
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
))
if
(
isRtxCodec
(
codec
))
continue
;
continue
;
// No support for NACK, PLI, FIR and RTX in PipeTransport.
// Reduce RTCP feedbacks by removing NACK support and other features.
// Reduce RTCP feedbacks by removing NACK support and other features.
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
.
filter
((
fb
)
=>
(
.
filter
((
fb
)
=>
(
...
@@ -602,8 +1067,9 @@ export function getPipeConsumerRtpParameters(
...
@@ -602,8 +1067,9 @@ export function getPipeConsumerRtpParameters(
));
));
const
consumableEncodings
=
const
consumableEncodings
=
utils
.
clone
(
consumableParams
.
encodings
||
[]
)
as
RtpEncodingParameters
[];
utils
.
clone
(
consumableParams
.
encodings
)
as
RtpEncodingParameters
[];
// No support for NACK, PLI, FIR and RTX in PipeTransport.
for
(
const
encoding
of
consumableEncodings
)
for
(
const
encoding
of
consumableEncodings
)
{
{
delete
encoding
.
rtx
;
delete
encoding
.
rtx
;
...
@@ -614,30 +1080,9 @@ export function getPipeConsumerRtpParameters(
...
@@ -614,30 +1080,9 @@ export function getPipeConsumerRtpParameters(
return
consumerParams
;
return
consumerParams
;
}
}
function
assertCodecCapability
(
codec
:
RtpCodecCapability
):
void
function
isRtxCodec
(
codec
:
RtpCodecCapability
|
RtpCodecParameters
):
boolean
{
{
const
valid
=
return
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
);
(
typeof
codec
===
'object'
&&
!
Array
.
isArray
(
codec
))
&&
(
typeof
codec
.
mimeType
===
'string'
&&
codec
.
mimeType
)
&&
(
typeof
codec
.
clockRate
===
'number'
&&
codec
.
clockRate
);
if
(
!
valid
)
throw
new
TypeError
(
'invalid RTCRtpCodecCapability'
);
// Add kind if not present.
if
(
!
codec
.
kind
)
codec
.
kind
=
codec
.
mimeType
.
replace
(
/
\/
.*/
,
''
).
toLowerCase
()
as
MediaKind
;
}
function
assertCodecParameters
(
codec
:
RtpCodecCapability
|
RtpCodecParameters
):
void
{
const
valid
=
(
typeof
codec
===
'object'
&&
!
Array
.
isArray
(
codec
))
&&
(
typeof
codec
.
mimeType
===
'string'
&&
codec
.
mimeType
)
&&
(
typeof
codec
.
clockRate
===
'number'
&&
codec
.
clockRate
);
if
(
!
valid
)
throw
new
TypeError
(
'invalid RTCRtpCodecParameters'
);
}
}
function
matchCodecs
(
function
matchCodecs
(
...
@@ -655,25 +1100,16 @@ function matchCodecs(
...
@@ -655,25 +1100,16 @@ function matchCodecs(
if
(
aCodec
.
clockRate
!==
bCodec
.
clockRate
)
if
(
aCodec
.
clockRate
!==
bCodec
.
clockRate
)
return
false
;
return
false
;
if
(
if
(
aCodec
.
channels
!==
bCodec
.
channels
)
/^audio
\/
.+$/i
.
test
(
aMimeType
)
&&
(
(
aCodec
.
channels
!==
undefined
&&
aCodec
.
channels
!==
1
)
||
(
bCodec
.
channels
!==
undefined
&&
bCodec
.
channels
!==
1
)
)
&&
aCodec
.
channels
!==
bCodec
.
channels
)
{
return
false
;
return
false
;
}
// Per codec special checks.
// Per codec special checks.
switch
(
aMimeType
)
switch
(
aMimeType
)
{
{
case
'video/h264'
:
case
'video/h264'
:
{
{
const
aPacketizationMode
=
(
aCodec
.
parameters
||
{})
[
'packetization-mode'
]
||
0
;
const
aPacketizationMode
=
aCodec
.
parameters
[
'packetization-mode'
]
||
0
;
const
bPacketizationMode
=
(
bCodec
.
parameters
||
{})
[
'packetization-mode'
]
||
0
;
const
bPacketizationMode
=
bCodec
.
parameters
[
'packetization-mode'
]
||
0
;
if
(
aPacketizationMode
!==
bPacketizationMode
)
if
(
aPacketizationMode
!==
bPacketizationMode
)
return
false
;
return
false
;
...
@@ -698,8 +1134,6 @@ function matchCodecs(
...
@@ -698,8 +1134,6 @@ function matchCodecs(
if
(
modify
)
if
(
modify
)
{
{
aCodec
.
parameters
=
aCodec
.
parameters
||
{};
if
(
selectedProfileLevelId
)
if
(
selectedProfileLevelId
)
aCodec
.
parameters
[
'profile-level-id'
]
=
selectedProfileLevelId
;
aCodec
.
parameters
[
'profile-level-id'
]
=
selectedProfileLevelId
;
else
else
...
@@ -715,8 +1149,8 @@ function matchCodecs(
...
@@ -715,8 +1149,8 @@ function matchCodecs(
// If strict matching check profile-id.
// If strict matching check profile-id.
if
(
strict
)
if
(
strict
)
{
{
const
aProfileId
=
(
aCodec
.
parameters
||
{})
[
'profile-id'
]
||
0
;
const
aProfileId
=
aCodec
.
parameters
[
'profile-id'
]
||
0
;
const
bProfileId
=
(
bCodec
.
parameters
||
{})
[
'profile-id'
]
||
0
;
const
bProfileId
=
bCodec
.
parameters
[
'profile-id'
]
||
0
;
if
(
aProfileId
!==
bProfileId
)
if
(
aProfileId
!==
bProfileId
)
return
false
;
return
false
;
...
...
src/supportedRtpCapabilities.ts
浏览文件 @
e51c3af8
...
@@ -340,8 +340,7 @@ const supportedRtpCapabilities: RtpCapabilities =
...
@@ -340,8 +340,7 @@ const supportedRtpCapabilities: RtpCapabilities =
preferredEncrypt
:
false
,
preferredEncrypt
:
false
,
direction
:
'sendrecv'
direction
:
'sendrecv'
}
}
],
]
fecMechanisms
:
[]
};
};
export
{
supportedRtpCapabilities
};
export
{
supportedRtpCapabilities
};
test/test-Consumer.js
浏览文件 @
e51c3af8
...
@@ -106,9 +106,9 @@ const videoProducerParameters =
...
@@ -106,9 +106,9 @@ const videoProducerParameters =
},
},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'goog-remb'
}
{
type
:
'goog-remb'
,
parameter
:
''
}
]
]
},
},
{
{
...
@@ -151,39 +151,39 @@ const consumerDeviceCapabilities =
...
@@ -151,39 +151,39 @@ const consumerDeviceCapabilities =
{
{
mimeType
:
'audio/opus'
,
mimeType
:
'audio/opus'
,
kind
:
'audio'
,
kind
:
'audio'
,
clockRate
:
48000
,
preferredPayloadType
:
100
,
preferredPayloadType
:
100
,
clockRate
:
48000
,
channels
:
2
channels
:
2
},
},
{
{
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
kind
:
'video'
,
kind
:
'video'
,
clockRate
:
90000
,
preferredPayloadType
:
101
,
preferredPayloadType
:
101
,
rtcpFeedback
:
clockRate
:
90000
,
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'goog-remb'
}
],
parameters
:
parameters
:
{
{
'level-asymmetry-allowed'
:
1
,
'level-asymmetry-allowed'
:
1
,
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
'profile-level-id'
:
'4d0032'
}
},
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'goog-remb'
,
parameter
:
''
}
]
},
},
{
{
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
kind
:
'video'
,
kind
:
'video'
,
clockRate
:
90000
,
preferredPayloadType
:
102
,
preferredPayloadType
:
102
,
rtcpFeedback
:
[]
,
clockRate
:
90000
,
parameters
:
parameters
:
{
{
apt
:
101
apt
:
101
}
},
rtcpFeedback
:
[]
}
}
],
],
headerExtensions
:
headerExtensions
:
...
@@ -236,8 +236,7 @@ const consumerDeviceCapabilities =
...
@@ -236,8 +236,7 @@ const consumerDeviceCapabilities =
preferredId
:
12
,
preferredId
:
12
,
preferredEncrypt
:
false
preferredEncrypt
:
false
}
}
],
]
fecMechanisms
:
[]
};
};
beforeAll
(
async
()
=>
beforeAll
(
async
()
=>
...
@@ -293,8 +292,8 @@ test('transport.consume() succeeds', async () =>
...
@@ -293,8 +292,8 @@ test('transport.consume() succeeds', async () =>
expect
(
audioConsumer
.
rtpParameters
.
codecs
[
0
]).
toEqual
(
expect
(
audioConsumer
.
rtpParameters
.
codecs
[
0
]).
toEqual
(
{
{
mimeType
:
'audio/opus'
,
mimeType
:
'audio/opus'
,
clockRate
:
48000
,
payloadType
:
100
,
payloadType
:
100
,
clockRate
:
48000
,
channels
:
2
,
channels
:
2
,
parameters
:
parameters
:
{
{
...
@@ -363,8 +362,9 @@ test('transport.consume() succeeds', async () =>
...
@@ -363,8 +362,9 @@ test('transport.consume() succeeds', async () =>
expect
(
videoConsumer
.
rtpParameters
.
codecs
[
0
]).
toEqual
(
expect
(
videoConsumer
.
rtpParameters
.
codecs
[
0
]).
toEqual
(
{
{
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
clockRate
:
90000
,
payloadType
:
103
,
payloadType
:
103
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
parameters
:
{
{
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
...
@@ -372,17 +372,18 @@ test('transport.consume() succeeds', async () =>
...
@@ -372,17 +372,18 @@ test('transport.consume() succeeds', async () =>
},
},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'goog-remb'
}
{
type
:
'goog-remb'
,
parameter
:
''
}
]
]
});
});
expect
(
videoConsumer
.
rtpParameters
.
codecs
[
1
]).
toEqual
(
expect
(
videoConsumer
.
rtpParameters
.
codecs
[
1
]).
toEqual
(
{
{
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
clockRate
:
90000
,
payloadType
:
104
,
payloadType
:
104
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
{
apt
:
103
},
parameters
:
{
apt
:
103
},
rtcpFeedback
:
[]
rtcpFeedback
:
[]
});
});
...
@@ -432,8 +433,8 @@ test('transport.consume() with incompatible rtpCapabilities rejects with Unsuppo
...
@@ -432,8 +433,8 @@ test('transport.consume() with incompatible rtpCapabilities rejects with Unsuppo
{
{
kind
:
'audio'
,
kind
:
'audio'
,
mimeType
:
'audio/ISAC'
,
mimeType
:
'audio/ISAC'
,
clockRate
:
32000
,
preferredPayloadType
:
100
,
preferredPayloadType
:
100
,
clockRate
:
32000
,
channels
:
1
channels
:
1
}
}
],
],
...
...
test/test-PipeTransport.js
浏览文件 @
e51c3af8
...
@@ -138,17 +138,17 @@ const consumerDeviceCapabilities =
...
@@ -138,17 +138,17 @@ const consumerDeviceCapabilities =
codecs
:
codecs
:
[
[
{
{
mimeType
:
'audio/opus'
,
kind
:
'audio'
,
kind
:
'audio'
,
clockRate
:
48000
,
mimeType
:
'audio/opus'
,
preferredPayloadType
:
100
,
preferredPayloadType
:
100
,
clockRate
:
48000
,
channels
:
2
channels
:
2
},
},
{
{
mimeType
:
'video/VP8'
,
kind
:
'video'
,
kind
:
'video'
,
clockRate
:
90000
,
mimeType
:
'video/VP8'
,
preferredPayloadType
:
101
,
preferredPayloadType
:
101
,
clockRate
:
90000
,
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'nack'
},
...
@@ -158,15 +158,15 @@ const consumerDeviceCapabilities =
...
@@ -158,15 +158,15 @@ const consumerDeviceCapabilities =
]
]
},
},
{
{
mimeType
:
'video/rtx'
,
kind
:
'video'
,
kind
:
'video'
,
clockRate
:
90000
,
mimeType
:
'video/rtx'
,
preferredPayloadType
:
102
,
preferredPayloadType
:
102
,
rtcpFeedback
:
[]
,
clockRate
:
90000
,
parameters
:
parameters
:
{
{
apt
:
101
apt
:
101
}
},
rtcpFeedback
:
[]
}
}
],
],
headerExtensions
:
headerExtensions
:
...
@@ -271,7 +271,9 @@ test('router.pipeToRouter() succeeds with audio', async () =>
...
@@ -271,7 +271,9 @@ test('router.pipeToRouter() succeeds with audio', async () =>
[
[
{
{
uri
:
'urn:ietf:params:rtp-hdrext:ssrc-audio-level'
,
uri
:
'urn:ietf:params:rtp-hdrext:ssrc-audio-level'
,
id
:
10
id
:
10
,
encrypt
:
false
,
parameters
:
{}
}
}
]);
]);
expect
(
pipeConsumer
.
rtpParameters
.
encodings
).
toEqual
(
expect
(
pipeConsumer
.
rtpParameters
.
encodings
).
toEqual
(
...
@@ -293,8 +295,8 @@ test('router.pipeToRouter() succeeds with audio', async () =>
...
@@ -293,8 +295,8 @@ test('router.pipeToRouter() succeeds with audio', async () =>
[
[
{
{
mimeType
:
'audio/opus'
,
mimeType
:
'audio/opus'
,
clockRate
:
48000
,
payloadType
:
100
,
payloadType
:
100
,
clockRate
:
48000
,
channels
:
2
,
channels
:
2
,
parameters
:
parameters
:
{
{
...
@@ -308,7 +310,9 @@ test('router.pipeToRouter() succeeds with audio', async () =>
...
@@ -308,7 +310,9 @@ test('router.pipeToRouter() succeeds with audio', async () =>
[
[
{
{
uri
:
'urn:ietf:params:rtp-hdrext:ssrc-audio-level'
,
uri
:
'urn:ietf:params:rtp-hdrext:ssrc-audio-level'
,
id
:
10
id
:
10
,
encrypt
:
false
,
parameters
:
{}
}
}
]);
]);
expect
(
pipeProducer
.
rtpParameters
.
encodings
).
toEqual
(
expect
(
pipeProducer
.
rtpParameters
.
encodings
).
toEqual
(
...
@@ -347,8 +351,10 @@ test('router.pipeToRouter() succeeds with video', async () =>
...
@@ -347,8 +351,10 @@ test('router.pipeToRouter() succeeds with video', async () =>
[
[
{
{
mimeType
:
'video/VP8'
,
mimeType
:
'video/VP8'
,
clockRate
:
90000
,
payloadType
:
101
,
payloadType
:
101
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
{},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
...
@@ -361,19 +367,27 @@ test('router.pipeToRouter() succeeds with video', async () =>
...
@@ -361,19 +367,27 @@ test('router.pipeToRouter() succeeds with video', async () =>
// NOTE: Remove this once framemarking draft becomes RFC.
// NOTE: Remove this once framemarking draft becomes RFC.
{
{
uri
:
'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07'
,
uri
:
'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07'
,
id
:
6
id
:
6
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'urn:ietf:params:rtp-hdrext:framemarking'
,
uri
:
'urn:ietf:params:rtp-hdrext:framemarking'
,
id
:
7
id
:
7
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'urn:3gpp:video-orientation'
,
uri
:
'urn:3gpp:video-orientation'
,
id
:
11
id
:
11
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
id
:
12
id
:
12
,
encrypt
:
false
,
parameters
:
{}
}
}
]);
]);
expect
(
pipeConsumer
.
rtpParameters
.
encodings
).
toEqual
(
expect
(
pipeConsumer
.
rtpParameters
.
encodings
).
toEqual
(
...
@@ -398,8 +412,10 @@ test('router.pipeToRouter() succeeds with video', async () =>
...
@@ -398,8 +412,10 @@ test('router.pipeToRouter() succeeds with video', async () =>
[
[
{
{
mimeType
:
'video/VP8'
,
mimeType
:
'video/VP8'
,
clockRate
:
90000
,
payloadType
:
101
,
payloadType
:
101
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
{},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
...
@@ -412,19 +428,27 @@ test('router.pipeToRouter() succeeds with video', async () =>
...
@@ -412,19 +428,27 @@ test('router.pipeToRouter() succeeds with video', async () =>
// NOTE: Remove this once framemarking draft becomes RFC.
// NOTE: Remove this once framemarking draft becomes RFC.
{
{
uri
:
'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07'
,
uri
:
'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07'
,
id
:
6
id
:
6
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'urn:ietf:params:rtp-hdrext:framemarking'
,
uri
:
'urn:ietf:params:rtp-hdrext:framemarking'
,
id
:
7
id
:
7
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'urn:3gpp:video-orientation'
,
uri
:
'urn:3gpp:video-orientation'
,
id
:
11
id
:
11
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
id
:
12
id
:
12
,
encrypt
:
false
,
parameters
:
{}
}
}
]);
]);
expect
(
pipeProducer
.
paused
).
toBe
(
true
);
expect
(
pipeProducer
.
paused
).
toBe
(
true
);
...
@@ -447,36 +471,43 @@ test('transport.consume() for a pipe Producer succeeds', async () =>
...
@@ -447,36 +471,43 @@ test('transport.consume() for a pipe Producer succeeds', async () =>
[
[
{
{
mimeType
:
'video/VP8'
,
mimeType
:
'video/VP8'
,
clockRate
:
90000
,
payloadType
:
101
,
payloadType
:
101
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
{},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'google-remb'
},
{
type
:
'google-remb'
,
parameter
:
''
},
{
type
:
'transport-cc'
}
{
type
:
'transport-cc'
,
parameter
:
''
}
]
]
},
},
{
{
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
clockRate
:
90000
,
payloadType
:
102
,
payloadType
:
102
,
rtcpFeedback
:
[],
clockRate
:
90000
,
channels
:
1
,
parameters
:
parameters
:
{
{
apt
:
101
apt
:
101
}
},
rtcpFeedback
:
[]
}
}
]);
]);
expect
(
videoConsumer
.
rtpParameters
.
headerExtensions
).
toEqual
(
expect
(
videoConsumer
.
rtpParameters
.
headerExtensions
).
toEqual
(
[
[
{
{
uri
:
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
,
uri
:
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
,
id
:
4
id
:
4
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01'
,
uri
:
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01'
,
id
:
5
id
:
5
,
encrypt
:
false
,
parameters
:
{}
}
}
]);
]);
expect
(
videoConsumer
.
rtpParameters
.
encodings
.
length
).
toBe
(
1
);
expect
(
videoConsumer
.
rtpParameters
.
encodings
.
length
).
toBe
(
1
);
...
...
test/test-PlainRtpTransport.js
浏览文件 @
e51c3af8
...
@@ -30,14 +30,14 @@ const mediaCodecs =
...
@@ -30,14 +30,14 @@ const mediaCodecs =
kind
:
'video'
,
kind
:
'video'
,
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
[],
// Will be ignored.
parameters
:
parameters
:
{
{
'level-asymmetry-allowed'
:
1
,
'level-asymmetry-allowed'
:
1
,
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
,
'profile-level-id'
:
'4d0032'
,
foo
:
'bar'
foo
:
'bar'
}
},
rtcpFeedback
:
[]
// Will be ignored.
}
}
];
];
...
...
test/test-Producer.js
浏览文件 @
e51c3af8
...
@@ -33,14 +33,14 @@ const mediaCodecs =
...
@@ -33,14 +33,14 @@ const mediaCodecs =
kind
:
'video'
,
kind
:
'video'
,
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
[],
// Will be ignored.
parameters
:
parameters
:
{
{
'level-asymmetry-allowed'
:
1
,
'level-asymmetry-allowed'
:
1
,
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
,
'profile-level-id'
:
'4d0032'
,
foo
:
'bar'
foo
:
'bar'
}
},
rtcpFeedback
:
[]
// Will be ignored.
}
}
];
];
...
...
test/test-Router.js
浏览文件 @
e51c3af8
...
@@ -32,13 +32,13 @@ const mediaCodecs =
...
@@ -32,13 +32,13 @@ const mediaCodecs =
kind
:
'video'
,
kind
:
'video'
,
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
[],
// Will be ignored.
parameters
:
parameters
:
{
{
'level-asymmetry-allowed'
:
1
,
'level-asymmetry-allowed'
:
1
,
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
'profile-level-id'
:
'4d0032'
}
},
rtcpFeedback
:
[]
// Will be ignored.
}
}
];
];
...
@@ -59,7 +59,6 @@ test('worker.createRouter() succeeds', async () =>
...
@@ -59,7 +59,6 @@ test('worker.createRouter() succeeds', async () =>
expect
(
router
.
rtpCapabilities
).
toBeType
(
'object'
);
expect
(
router
.
rtpCapabilities
).
toBeType
(
'object'
);
expect
(
router
.
rtpCapabilities
.
codecs
).
toBeType
(
'array'
);
expect
(
router
.
rtpCapabilities
.
codecs
).
toBeType
(
'array'
);
expect
(
router
.
rtpCapabilities
.
headerExtensions
).
toBeType
(
'array'
);
expect
(
router
.
rtpCapabilities
.
headerExtensions
).
toBeType
(
'array'
);
expect
(
router
.
rtpCapabilities
.
fecMechanisms
).
toEqual
([]);
expect
(
router
.
appData
).
toEqual
({
foo
:
123
});
expect
(
router
.
appData
).
toEqual
({
foo
:
123
});
await
expect
(
worker
.
dump
())
await
expect
(
worker
.
dump
())
...
...
test/test-ortc.js
浏览文件 @
e51c3af8
...
@@ -21,21 +21,21 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -21,21 +21,21 @@ test('generateRouterRtpCapabilities() succeeds', () =>
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
preferredPayloadType
:
125
,
// Let's force it.
mimeType
:
'video/VP8'
,
mimeType
:
'video/VP8'
,
preferredPayloadType
:
125
,
// Let's force it.
clockRate
:
90000
clockRate
:
90000
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
[],
// Will be ignored.
parameters
:
parameters
:
{
{
'level-asymmetry-allowed'
:
1
,
'level-asymmetry-allowed'
:
1
,
'profile-level-id'
:
'42e01f'
,
'profile-level-id'
:
'42e01f'
,
foo
:
'bar'
foo
:
'bar'
}
},
rtcpFeedback
:
[]
// Will be ignored.
}
}
];
];
...
@@ -51,15 +51,15 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -51,15 +51,15 @@ test('generateRouterRtpCapabilities() succeeds', () =>
preferredPayloadType
:
100
,
// 100 is the first available dynamic PT.
preferredPayloadType
:
100
,
// 100 is the first available dynamic PT.
clockRate
:
48000
,
clockRate
:
48000
,
channels
:
2
,
channels
:
2
,
rtcpFeedback
:
[
{
type
:
'transport-cc'
}
],
parameters
:
parameters
:
{
{
useinbandfec
:
1
,
useinbandfec
:
1
,
foo
:
'bar'
foo
:
'bar'
}
},
rtcpFeedback
:
[
{
type
:
'transport-cc'
,
parameter
:
''
}
]
});
});
// VP8.
// VP8.
...
@@ -69,15 +69,16 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -69,15 +69,16 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType
:
'video/VP8'
,
mimeType
:
'video/VP8'
,
preferredPayloadType
:
125
,
preferredPayloadType
:
125
,
clockRate
:
90000
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
{},
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'goog-remb'
},
{
type
:
'goog-remb'
,
parameter
:
''
},
{
type
:
'transport-cc'
}
{
type
:
'transport-cc'
,
parameter
:
''
}
],
]
parameters
:
{}
});
});
// VP8 RTX.
// VP8 RTX.
...
@@ -87,11 +88,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -87,11 +88,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
preferredPayloadType
:
101
,
// 101 is the second available dynamic PT.
preferredPayloadType
:
101
,
// 101 is the second available dynamic PT.
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
[]
,
channels
:
1
,
parameters
:
parameters
:
{
{
apt
:
125
apt
:
125
}
},
rtcpFeedback
:
[]
});
});
// H264.
// H264.
...
@@ -101,14 +103,7 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -101,14 +103,7 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
preferredPayloadType
:
102
,
// 102 is the second available dynamic PT.
preferredPayloadType
:
102
,
// 102 is the second available dynamic PT.
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
channels
:
1
,
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'goog-remb'
},
{
type
:
'transport-cc'
}
],
parameters
:
parameters
:
{
{
...
@@ -116,7 +111,15 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -116,7 +111,15 @@ test('generateRouterRtpCapabilities() succeeds', () =>
'level-asymmetry-allowed'
:
1
,
'level-asymmetry-allowed'
:
1
,
'profile-level-id'
:
'42e01f'
,
'profile-level-id'
:
'42e01f'
,
foo
:
'bar'
foo
:
'bar'
}
},
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
},
{
type
:
'goog-remb'
,
parameter
:
''
},
{
type
:
'transport-cc'
,
parameter
:
''
}
]
});
});
// H264 RTX.
// H264 RTX.
...
@@ -126,11 +129,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
...
@@ -126,11 +129,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
preferredPayloadType
:
103
,
preferredPayloadType
:
103
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
[]
,
channels
:
1
,
parameters
:
parameters
:
{
{
apt
:
102
apt
:
102
}
},
rtcpFeedback
:
[]
});
});
});
});
...
@@ -234,27 +238,30 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -234,27 +238,30 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
payloadType
:
111
,
payloadType
:
111
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
channels
:
1
,
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'goog-remb'
}
],
parameters
:
parameters
:
{
{
foo
:
1234
,
foo
:
1234
,
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
'profile-level-id'
:
'4d0032'
}
},
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'goog-remb'
,
parameter
:
''
}
]
},
},
{
{
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
payloadType
:
112
,
payloadType
:
112
,
clockRate
:
90000
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
parameters
:
{
{
apt
:
111
apt
:
111
}
},
rtcpFeedback
:
[]
}
}
],
],
headerExtensions
:
headerExtensions
:
...
@@ -366,35 +373,40 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -366,35 +373,40 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
mimeType
:
'audio/opus'
,
mimeType
:
'audio/opus'
,
preferredPayloadType
:
100
,
preferredPayloadType
:
100
,
clockRate
:
48000
,
clockRate
:
48000
,
channels
:
2
channels
:
2
,
parameters
:
{},
rtcpFeedback
:
[]
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
preferredPayloadType
:
101
,
preferredPayloadType
:
101
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
channels
:
1
,
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'foo'
,
parameter
:
'FOO'
}
],
parameters
:
parameters
:
{
{
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
,
'profile-level-id'
:
'4d0032'
,
baz
:
'LOLOLO'
baz
:
'LOLOLO'
}
},
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'foo'
,
parameter
:
'FOO'
}
]
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
preferredPayloadType
:
102
,
preferredPayloadType
:
102
,
clockRate
:
90000
,
clockRate
:
90000
,
channels
:
1
,
parameters
:
parameters
:
{
{
apt
:
101
apt
:
101
}
},
rtcpFeedback
:
[]
}
}
],
],
headerExtensions
:
headerExtensions
:
...
@@ -403,37 +415,43 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -403,37 +415,43 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
kind
:
'audio'
,
kind
:
'audio'
,
uri
:
'urn:ietf:params:rtp-hdrext:sdes:mid'
,
uri
:
'urn:ietf:params:rtp-hdrext:sdes:mid'
,
preferredId
:
1
,
preferredId
:
1
,
preferredEncrypt
:
false
preferredEncrypt
:
false
,
direction
:
'sendrecv'
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
uri
:
'urn:ietf:params:rtp-hdrext:sdes:mid'
,
uri
:
'urn:ietf:params:rtp-hdrext:sdes:mid'
,
preferredId
:
1
,
preferredId
:
1
,
preferredEncrypt
:
false
preferredEncrypt
:
false
,
direction
:
'sendrecv'
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
uri
:
'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id'
,
uri
:
'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id'
,
preferredId
:
2
,
preferredId
:
2
,
preferredEncrypt
:
false
preferredEncrypt
:
false
,
direction
:
'sendrecv'
},
},
{
{
kind
:
'audio'
,
kind
:
'audio'
,
uri
:
'urn:ietf:params:rtp-hdrext:ssrc-audio-level'
,
uri
:
'urn:ietf:params:rtp-hdrext:ssrc-audio-level'
,
preferredId
:
8
,
preferredId
:
8
,
preferredEncrypt
:
false
preferredEncrypt
:
false
,
direction
:
'sendrecv'
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
uri
:
'urn:3gpp:video-orientation'
,
uri
:
'urn:3gpp:video-orientation'
,
preferredId
:
11
,
preferredId
:
11
,
preferredEncrypt
:
false
preferredEncrypt
:
false
,
direction
:
'sendrecv'
},
},
{
{
kind
:
'video'
,
kind
:
'video'
,
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
preferredId
:
12
,
preferredId
:
12
,
preferredEncrypt
:
false
preferredEncrypt
:
false
,
direction
:
'sendrecv'
}
}
]
]
};
};
...
@@ -447,29 +465,31 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -447,29 +465,31 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
payloadType
:
101
,
payloadType
:
101
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
channels
:
1
,
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'foo'
,
parameter
:
'FOO'
}
],
parameters
:
parameters
:
{
{
foo
:
1234
,
foo
:
1234
,
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
'profile-level-id'
:
'4d0032'
}
},
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'foo'
,
parameter
:
'FOO'
}
]
});
});
expect
(
consumerRtpParameters
.
codecs
[
1
]).
toEqual
(
expect
(
consumerRtpParameters
.
codecs
[
1
]).
toEqual
(
{
{
mimeType
:
'video/rtx'
,
mimeType
:
'video/rtx'
,
payloadType
:
102
,
payloadType
:
102
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
[]
,
channels
:
1
,
parameters
:
parameters
:
{
{
apt
:
101
apt
:
101
}
},
rtcpFeedback
:
[]
});
});
expect
(
consumerRtpParameters
.
encodings
.
length
).
toBe
(
1
);
expect
(
consumerRtpParameters
.
encodings
.
length
).
toBe
(
1
);
...
@@ -482,11 +502,15 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -482,11 +502,15 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
[
[
{
{
uri
:
'urn:3gpp:video-orientation'
,
uri
:
'urn:3gpp:video-orientation'
,
id
:
11
id
:
11
,
encrypt
:
false
,
parameters
:
{}
},
},
{
{
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
uri
:
'urn:ietf:params:rtp-hdrext:toffset'
,
id
:
12
id
:
12
,
encrypt
:
false
,
parameters
:
{}
}
}
]);
]);
...
@@ -506,17 +530,18 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
...
@@ -506,17 +530,18 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
mimeType
:
'video/H264'
,
mimeType
:
'video/H264'
,
payloadType
:
101
,
payloadType
:
101
,
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
channels
:
1
,
[
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
}
],
parameters
:
parameters
:
{
{
foo
:
1234
,
foo
:
1234
,
'packetization-mode'
:
1
,
'packetization-mode'
:
1
,
'profile-level-id'
:
'4d0032'
'profile-level-id'
:
'4d0032'
}
},
rtcpFeedback
:
[
{
type
:
'nack'
,
parameter
:
'pli'
},
{
type
:
'ccm'
,
parameter
:
'fir'
}
]
});
});
expect
(
pipeConsumerRtpParameters
.
encodings
.
length
).
toBe
(
3
);
expect
(
pipeConsumerRtpParameters
.
encodings
.
length
).
toBe
(
3
);
...
@@ -575,7 +600,7 @@ test('getProducerRtpParametersMapping() with incompatible params throws Unsuppor
...
@@ -575,7 +600,7 @@ test('getProducerRtpParametersMapping() with incompatible params throws Unsuppor
clockRate
:
90000
,
clockRate
:
90000
,
rtcpFeedback
:
rtcpFeedback
:
[
[
{
type
:
'nack'
},
{
type
:
'nack'
,
parameter
:
''
},
{
type
:
'nack'
,
parameter
:
'fir'
}
{
type
:
'nack'
,
parameter
:
'fir'
}
]
]
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论