Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
90fff361
Unverified
提交
90fff361
authored
12月 30, 2023
作者:
Iñaki Baz Castillo
提交者:
GitHub
12月 30, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid modification of user input data (#1285)
上级
2b0f4692
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
943 行增加
和
1003 行删除
+943
-1003
Transport.ts
node/src/Transport.ts
+37
-19
Worker.ts
node/src/Worker.ts
+13
-8
index.ts
node/src/index.ts
+1
-1
ortc.ts
node/src/ortc.ts
+889
-973
test-ortc.ts
node/src/tests/test-ortc.ts
+3
-2
没有找到文件。
node/src/Transport.ts
浏览文件 @
90fff361
...
@@ -714,17 +714,20 @@ export class Transport
...
@@ -714,17 +714,20 @@ export class Transport
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
}
}
// Clone given RTP parameters to not modify input data.
const
clonedRtpParameters
=
utils
.
clone
<
RtpParameters
>
(
rtpParameters
);
// This may throw.
// This may throw.
ortc
.
validateRtpParameters
(
r
tpParameters
);
ortc
.
validateRtpParameters
(
clonedR
tpParameters
);
// If missing or empty encodings, add one.
// If missing or empty encodings, add one.
if
(
if
(
!
r
tpParameters
.
encodings
||
!
clonedR
tpParameters
.
encodings
||
!
Array
.
isArray
(
r
tpParameters
.
encodings
)
||
!
Array
.
isArray
(
clonedR
tpParameters
.
encodings
)
||
r
tpParameters
.
encodings
.
length
===
0
clonedR
tpParameters
.
encodings
.
length
===
0
)
)
{
{
r
tpParameters
.
encodings
=
[
{}
];
clonedR
tpParameters
.
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
...
@@ -733,9 +736,13 @@ export class Transport
...
@@ -733,9 +736,13 @@ export class Transport
{
{
// If CNAME is given and we don't have yet a CNAME for Producers in this
// If CNAME is given and we don't have yet a CNAME for Producers in this
// Transport, take it.
// Transport, take it.
if
(
!
this
.
#
cnameForProducers
&&
rtpParameters
.
rtcp
&&
rtpParameters
.
rtcp
.
cname
)
if
(
!
this
.
#
cnameForProducers
&&
clonedRtpParameters
.
rtcp
&&
clonedRtpParameters
.
rtcp
.
cname
)
{
{
this
.
#
cnameForProducers
=
r
tpParameters
.
rtcp
.
cname
;
this
.
#
cnameForProducers
=
clonedR
tpParameters
.
rtcp
.
cname
;
}
}
// Otherwise if we don't have yet a CNAME for Producers and the RTP
// Otherwise if we don't have yet a CNAME for Producers and the RTP
// parameters do not include CNAME, create a random one.
// parameters do not include CNAME, create a random one.
...
@@ -745,26 +752,26 @@ export class Transport
...
@@ -745,26 +752,26 @@ export class Transport
}
}
// Override Producer's CNAME.
// Override Producer's CNAME.
rtpParameters
.
rtcp
=
rtpParameters
.
rtcp
||
{};
clonedRtpParameters
.
rtcp
=
clonedRtpParameters
.
rtcp
??
{};
r
tpParameters
.
rtcp
.
cname
=
this
.
#
cnameForProducers
;
clonedR
tpParameters
.
rtcp
.
cname
=
this
.
#
cnameForProducers
;
}
}
const
routerRtpCapabilities
=
this
.
#
getRouterRtpCapabilities
();
const
routerRtpCapabilities
=
this
.
#
getRouterRtpCapabilities
();
// This may throw.
// This may throw.
const
rtpMapping
=
ortc
.
getProducerRtpParametersMapping
(
const
rtpMapping
=
ortc
.
getProducerRtpParametersMapping
(
r
tpParameters
,
routerRtpCapabilities
);
clonedR
tpParameters
,
routerRtpCapabilities
);
// This may throw.
// This may throw.
const
consumableRtpParameters
=
ortc
.
getConsumableRtpParameters
(
const
consumableRtpParameters
=
ortc
.
getConsumableRtpParameters
(
kind
,
r
tpParameters
,
routerRtpCapabilities
,
rtpMapping
);
kind
,
clonedR
tpParameters
,
routerRtpCapabilities
,
rtpMapping
);
const
producerId
=
id
||
utils
.
generateUUIDv4
();
const
producerId
=
id
||
utils
.
generateUUIDv4
();
const
requestOffset
=
createProduceRequest
({
const
requestOffset
=
createProduceRequest
({
builder
:
this
.
channel
.
bufferBuilder
,
builder
:
this
.
channel
.
bufferBuilder
,
producerId
,
producerId
,
kind
,
kind
,
rtpParameters
,
rtpParameters
:
clonedRtpParameters
,
rtpMapping
,
rtpMapping
,
keyFrameRequestDelay
,
keyFrameRequestDelay
,
paused
paused
...
@@ -787,7 +794,7 @@ export class Transport
...
@@ -787,7 +794,7 @@ export class Transport
const
data
=
const
data
=
{
{
kind
,
kind
,
rtpParameters
,
rtpParameters
:
clonedRtpParameters
,
type
:
producerTypeFromFbs
(
status
.
type
),
type
:
producerTypeFromFbs
(
status
.
type
),
consumableRtpParameters
consumableRtpParameters
};
};
...
@@ -854,8 +861,11 @@ export class Transport
...
@@ -854,8 +861,11 @@ export class Transport
throw
new
TypeError
(
'if given, mid must be non empty string'
);
throw
new
TypeError
(
'if given, mid must be non empty string'
);
}
}
// Clone given RTP capabilities to not modify input data.
const
clonedRtpCapabilities
=
utils
.
clone
<
RtpCapabilities
>
(
rtpCapabilities
);
// This may throw.
// This may throw.
ortc
.
validateRtpCapabilities
(
rtpCapabilities
!
);
ortc
.
validateRtpCapabilities
(
clonedRtpCapabilities
);
const
producer
=
this
.
getProducerById
(
producerId
);
const
producer
=
this
.
getProducerById
(
producerId
);
...
@@ -874,7 +884,7 @@ export class Transport
...
@@ -874,7 +884,7 @@ export class Transport
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
{
{
consumableRtpParameters
:
producer
.
consumableRtpParameters
,
consumableRtpParameters
:
producer
.
consumableRtpParameters
,
remoteRtpCapabilities
:
rtpCapabilities
!
,
remoteRtpCapabilities
:
clonedRtpCapabilities
,
pipe
,
pipe
,
enableRtx
enableRtx
}
}
...
@@ -996,13 +1006,17 @@ export class Transport
...
@@ -996,13 +1006,17 @@ export class Transport
let
type
:
DataProducerType
;
let
type
:
DataProducerType
;
// Clone given SCTP stream parameters to not modify input data.
let
clonedSctpStreamParameters
=
utils
.
clone
<
SctpStreamParameters
|
undefined
>
(
sctpStreamParameters
);
// If this is not a DirectTransport, sctpStreamParameters are required.
// If this is not a DirectTransport, sctpStreamParameters are required.
if
(
this
.
constructor
.
name
!==
'DirectTransport'
)
if
(
this
.
constructor
.
name
!==
'DirectTransport'
)
{
{
type
=
'sctp'
;
type
=
'sctp'
;
// This may throw.
// This may throw.
ortc
.
validateSctpStreamParameters
(
s
ctpStreamParameters
!
);
ortc
.
validateSctpStreamParameters
(
clonedS
ctpStreamParameters
!
);
}
}
// If this is a DirectTransport, sctpStreamParameters must not be given.
// If this is a DirectTransport, sctpStreamParameters must not be given.
else
else
...
@@ -1013,6 +1027,8 @@ export class Transport
...
@@ -1013,6 +1027,8 @@ export class Transport
{
{
logger
.
warn
(
logger
.
warn
(
'produceData() | sctpStreamParameters are ignored when producing data on a DirectTransport'
);
'produceData() | sctpStreamParameters are ignored when producing data on a DirectTransport'
);
clonedSctpStreamParameters
=
undefined
;
}
}
}
}
...
@@ -1021,7 +1037,7 @@ export class Transport
...
@@ -1021,7 +1037,7 @@ export class Transport
builder
:
this
.
channel
.
bufferBuilder
,
builder
:
this
.
channel
.
bufferBuilder
,
dataProducerId
,
dataProducerId
,
type
,
type
,
sctpStreamParameters
,
sctpStreamParameters
:
clonedSctpStreamParameters
,
label
,
label
,
protocol
,
protocol
,
paused
paused
...
@@ -1117,8 +1133,10 @@ export class Transport
...
@@ -1117,8 +1133,10 @@ export class Transport
if
(
this
.
constructor
.
name
!==
'DirectTransport'
)
if
(
this
.
constructor
.
name
!==
'DirectTransport'
)
{
{
type
=
'sctp'
;
type
=
'sctp'
;
sctpStreamParameters
=
(
utils
.
clone
(
dataProducer
.
sctpStreamParameters
)
??
{})
as
SctpStreamParameters
;
sctpStreamParameters
=
utils
.
clone
<
SctpStreamParameters
|
undefined
>
(
dataProducer
.
sctpStreamParameters
)
??
{}
as
SctpStreamParameters
;
// Override if given.
// Override if given.
if
(
ordered
!==
undefined
)
if
(
ordered
!==
undefined
)
...
...
node/src/Worker.ts
浏览文件 @
90fff361
...
@@ -8,8 +8,9 @@ import * as ortc from './ortc';
...
@@ -8,8 +8,9 @@ import * as ortc from './ortc';
import
{
Channel
}
from
'./Channel'
;
import
{
Channel
}
from
'./Channel'
;
import
{
Router
,
RouterOptions
}
from
'./Router'
;
import
{
Router
,
RouterOptions
}
from
'./Router'
;
import
{
WebRtcServer
,
WebRtcServerOptions
}
from
'./WebRtcServer'
;
import
{
WebRtcServer
,
WebRtcServerOptions
}
from
'./WebRtcServer'
;
import
{
RtpCodecCapability
}
from
'./RtpParameters'
;
import
{
AppData
}
from
'./types'
;
import
{
AppData
}
from
'./types'
;
import
{
generateUUIDv4
,
parseVector
}
from
'./utils'
;
import
*
as
utils
from
'./utils'
;
import
{
Event
}
from
'./fbs/notification'
;
import
{
Event
}
from
'./fbs/notification'
;
import
*
as
FbsRequest
from
'./fbs/request'
;
import
*
as
FbsRequest
from
'./fbs/request'
;
import
*
as
FbsWorker
from
'./fbs/worker'
;
import
*
as
FbsWorker
from
'./fbs/worker'
;
...
@@ -703,7 +704,7 @@ export class Worker<WorkerAppData extends AppData = AppData>
...
@@ -703,7 +704,7 @@ export class Worker<WorkerAppData extends AppData = AppData>
);
);
}
}
const
webRtcServerId
=
generateUUIDv4
();
const
webRtcServerId
=
utils
.
generateUUIDv4
();
const
createWebRtcServerRequestOffset
=
new
FbsWorker
.
CreateWebRtcServerRequestT
(
const
createWebRtcServerRequestOffset
=
new
FbsWorker
.
CreateWebRtcServerRequestT
(
webRtcServerId
,
fbsListenInfos
webRtcServerId
,
fbsListenInfos
...
@@ -747,10 +748,14 @@ export class Worker<WorkerAppData extends AppData = AppData>
...
@@ -747,10 +748,14 @@ export class Worker<WorkerAppData extends AppData = AppData>
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
}
}
// Clone given media codecs to not modify input data.
const
clonedMediaCodecs
=
utils
.
clone
<
RtpCodecCapability
[]
|
undefined
>
(
mediaCodecs
);
// This may throw.
// This may throw.
const
rtpCapabilities
=
ortc
.
generateRouterRtpCapabilities
(
m
ediaCodecs
);
const
rtpCapabilities
=
ortc
.
generateRouterRtpCapabilities
(
clonedM
ediaCodecs
);
const
routerId
=
generateUUIDv4
();
const
routerId
=
utils
.
generateUUIDv4
();
// Get flatbuffer builder.
// Get flatbuffer builder.
const
createRouterRequestOffset
=
const
createRouterRequestOffset
=
...
@@ -822,12 +827,12 @@ export function parseWorkerDumpResponse(
...
@@ -822,12 +827,12 @@ export function parseWorkerDumpResponse(
{
{
const
dump
:
WorkerDump
=
{
const
dump
:
WorkerDump
=
{
pid
:
binary
.
pid
()
!
,
pid
:
binary
.
pid
()
!
,
webRtcServerIds
:
parseVector
(
binary
,
'webRtcServerIds'
),
webRtcServerIds
:
utils
.
parseVector
(
binary
,
'webRtcServerIds'
),
routerIds
:
parseVector
(
binary
,
'routerIds'
),
routerIds
:
utils
.
parseVector
(
binary
,
'routerIds'
),
channelMessageHandlers
:
channelMessageHandlers
:
{
{
channelRequestHandlers
:
parseVector
(
binary
.
channelMessageHandlers
()
!
,
'channelRequestHandlers'
),
channelRequestHandlers
:
utils
.
parseVector
(
binary
.
channelMessageHandlers
()
!
,
'channelRequestHandlers'
),
channelNotificationHandlers
:
parseVector
(
binary
.
channelMessageHandlers
()
!
,
'channelNotificationHandlers'
)
channelNotificationHandlers
:
utils
.
parseVector
(
binary
.
channelMessageHandlers
()
!
,
'channelNotificationHandlers'
)
}
}
};
};
...
...
node/src/index.ts
浏览文件 @
90fff361
...
@@ -95,5 +95,5 @@ export async function createWorker<WorkerAppData extends types.AppData = types.A
...
@@ -95,5 +95,5 @@ export async function createWorker<WorkerAppData extends types.AppData = types.A
*/
*/
export
function
getSupportedRtpCapabilities
():
RtpCapabilities
export
function
getSupportedRtpCapabilities
():
RtpCapabilities
{
{
return
utils
.
clone
(
supportedRtpCapabilities
)
as
RtpCapabilities
;
return
utils
.
clone
<
RtpCapabilities
>
(
supportedRtpCapabilities
)
;
}
}
node/src/ortc.ts
浏览文件 @
90fff361
...
@@ -14,12 +14,7 @@ import {
...
@@ -14,12 +14,7 @@ import {
RtpHeaderExtensionParameters
,
RtpHeaderExtensionParameters
,
RtcpParameters
RtcpParameters
}
from
'./RtpParameters'
;
}
from
'./RtpParameters'
;
import
{
import
{
SctpStreamParameters
}
from
'./SctpParameters'
;
SctpCapabilities
,
NumSctpStreams
,
SctpParameters
,
SctpStreamParameters
}
from
'./SctpParameters'
;
import
*
as
utils
from
'./utils'
;
import
*
as
utils
from
'./utils'
;
import
{
UnsupportedError
}
from
'./errors'
;
import
{
UnsupportedError
}
from
'./errors'
;
import
*
as
FbsRtpParameters
from
'./fbs/rtp-parameters'
;
import
*
as
FbsRtpParameters
from
'./fbs/rtp-parameters'
;
...
@@ -91,181 +86,6 @@ export function validateRtpCapabilities(caps: RtpCapabilities): void
...
@@ -91,181 +86,6 @@ export function validateRtpCapabilities(caps: RtpCapabilities): void
}
}
}
}
/**
* 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 (just if audio).
if
(
codec
.
kind
===
'audio'
)
{
if
(
typeof
codec
.
channels
!==
'number'
)
{
codec
.
channels
=
1
;
}
}
else
{
delete
codec
.
channels
;
}
// 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
))
{
let
value
=
codec
.
parameters
[
key
];
if
(
value
===
undefined
)
{
codec
.
parameters
[
key
]
=
''
;
value
=
''
;
}
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
{
throw
new
TypeError
(
`invalid codec parameter [key:
${
key
}
s, value:
${
value
}
]`
);
}
// 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'
);
}
if
(
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
* Validates RtpParameters. It may modify given data by adding missing
* fields with default values.
* fields with default values.
...
@@ -339,1221 +159,1317 @@ export function validateRtpParameters(params: RtpParameters): void
...
@@ -339,1221 +159,1317 @@ export function validateRtpParameters(params: RtpParameters): void
}
}
/**
/**
* Validates
RtpCodec
Parameters. It may modify given data by adding missing
* Validates
SctpStream
Parameters. It may modify given data by adding missing
* fields with default values.
* fields with default values.
* It throws if invalid.
* It throws if invalid.
*/
*/
export
function
validate
RtpCodecParameters
(
codec
:
RtpCodec
Parameters
):
void
export
function
validate
SctpStreamParameters
(
params
:
SctpStream
Parameters
):
void
{
{
const
MimeTypeRegex
=
new
RegExp
(
'^(audio|video)/(.+)'
,
'i'
);
if
(
typeof
params
!==
'object'
)
if
(
typeof
codec
!==
'object'
)
{
{
throw
new
TypeError
(
'
codec
is not an object'
);
throw
new
TypeError
(
'
params
is not an object'
);
}
}
//
mimeType
is mandatory.
//
streamId
is mandatory.
if
(
!
codec
.
mimeType
||
typeof
codec
.
mimeType
!==
'string
'
)
if
(
typeof
params
.
streamId
!==
'number
'
)
{
{
throw
new
TypeError
(
'missing
codec.mimeType
'
);
throw
new
TypeError
(
'missing
params.streamId
'
);
}
}
const
mimeTypeMatch
=
MimeTypeRegex
.
exec
(
codec
.
mimeType
);
// ordered is optional.
let
orderedGiven
=
false
;
if
(
!
mimeTypeMatch
)
if
(
typeof
params
.
ordered
===
'boolean'
)
{
{
throw
new
TypeError
(
'invalid codec.mimeType'
)
;
orderedGiven
=
true
;
}
}
else
// payloadType is mandatory.
if
(
typeof
codec
.
payloadType
!==
'number'
)
{
{
throw
new
TypeError
(
'missing codec.payloadType'
)
;
params
.
ordered
=
true
;
}
}
//
clockRate is mandatory
.
//
maxPacketLifeTime is optional
.
if
(
typeof
codec
.
clockRat
e
!==
'number'
)
if
(
params
.
maxPacketLifeTime
&&
typeof
params
.
maxPacketLifeTim
e
!==
'number'
)
{
{
throw
new
TypeError
(
'
missing codec.clockRat
e'
);
throw
new
TypeError
(
'
invalid params.maxPacketLifeTim
e'
);
}
}
const
kind
=
mimeTypeMatch
[
1
].
toLowerCase
()
as
MediaKind
;
// maxRetransmits is optional.
if
(
params
.
maxRetransmits
&&
typeof
params
.
maxRetransmits
!==
'number'
)
// channels is optional. If unset, set it to 1 (just if audio).
if
(
kind
===
'audio'
)
{
if
(
typeof
codec
.
channels
!==
'number'
)
{
{
codec
.
channels
=
1
;
throw
new
TypeError
(
'invalid params.maxRetransmits'
);
}
}
}
else
if
(
params
.
maxPacketLifeTime
&&
params
.
maxRetransmits
)
{
{
delete
codec
.
channels
;
throw
new
TypeError
(
'cannot provide both maxPacketLifeTime and maxRetransmits'
)
;
}
}
// parameters is optional. If unset, set it to an empty object.
if
(
if
(
!
codec
.
parameters
||
typeof
codec
.
parameters
!==
'object'
)
orderedGiven
&&
params
.
ordered
&&
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
)
)
{
{
codec
.
parameters
=
{}
;
throw
new
TypeError
(
'cannot be ordered with maxPacketLifeTime or maxRetransmits'
)
;
}
}
else
if
(
!
orderedGiven
&&
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
))
for
(
const
key
of
Object
.
keys
(
codec
.
parameters
))
{
{
let
value
=
codec
.
parameters
[
key
];
params
.
ordered
=
false
;
}
}
if
(
value
===
undefined
)
/**
* Generate RTP capabilities for the Router based on the given media codecs and
* mediasoup supported RTP capabilities.
*/
export
function
generateRouterRtpCapabilities
(
mediaCodecs
:
RtpCodecCapability
[]
=
[]
):
RtpCapabilities
{
// Normalize supported RTP capabilities.
validateRtpCapabilities
(
supportedRtpCapabilities
);
if
(
!
Array
.
isArray
(
mediaCodecs
))
{
{
codec
.
parameters
[
key
]
=
''
;
throw
new
TypeError
(
'mediaCodecs must be an Array'
);
value
=
''
;
}
}
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
const
clonedSupportedRtpCapabilities
=
utils
.
clone
<
RtpCapabilities
>
(
supportedRtpCapabilities
);
const
dynamicPayloadTypes
=
utils
.
clone
<
number
[]
>
(
DynamicPayloadTypes
);
const
caps
:
RtpCapabilities
=
{
{
throw
new
TypeError
(
codecs
:
[],
`invalid codec parameter [key:
${
key
}
s, value:
${
value
}
]`
);
headerExtensions
:
clonedSupportedRtpCapabilities
.
headerExtensions
}
};
// Specific parameters validation.
for
(
const
mediaCodec
of
mediaCodecs
)
if
(
key
===
'apt'
)
{
if
(
typeof
value
!==
'number'
)
{
{
throw
new
TypeError
(
'invalid codec apt parameter'
);
// This may throw.
}
validateRtpCodecCapability
(
mediaCodec
);
}
}
// rtcpFeedback is optional. If unset, set it to an empty array.
const
matchedSupportedCodec
=
clonedSupportedRtpCapabilities
if
(
!
codec
.
rtcpFeedback
||
!
Array
.
isArray
(
codec
.
rtcpFeedback
))
.
codecs
!
{
.
find
((
supportedCodec
)
=>
(
codec
.
rtcpFeedback
=
[];
matchCodecs
(
mediaCodec
,
supportedCodec
,
{
strict
:
false
}))
}
);
for
(
const
fb
of
codec
.
rtcpFeedback
)
if
(
!
matchedSupportedCodec
)
{
{
validateRtcpFeedback
(
fb
);
throw
new
UnsupportedError
(
`media codec not supported [mimeType:
${
mediaCodec
.
mimeType
}
]`
);
}
}
}
/**
// Clone the supported codec.
* Validates RtpHeaderExtensionParameteters. It may modify given data by adding
const
codec
=
utils
.
clone
<
RtpCodecCapability
>
(
matchedSupportedCodec
);
* missing fields with default values. It throws if invalid.
*/
export
function
validateRtpHeaderExtensionParameters
(
ext
:
RtpHeaderExtensionParameters
):
void
{
if
(
typeof
ext
!==
'object'
)
// If the given media codec has preferredPayloadType, keep it.
if
(
typeof
mediaCodec
.
preferredPayloadType
===
'number'
)
{
{
throw
new
TypeError
(
'ext is not an object'
);
codec
.
preferredPayloadType
=
mediaCodec
.
preferredPayloadType
;
}
// uri is mandatory.
// Also remove the pt from the list of available dynamic values.
if
(
!
ext
.
uri
||
typeof
ext
.
uri
!==
'string'
)
const
idx
=
dynamicPayloadTypes
.
indexOf
(
codec
.
preferredPayloadType
);
if
(
idx
>
-
1
)
{
{
throw
new
TypeError
(
'missing ext.uri'
);
dynamicPayloadTypes
.
splice
(
idx
,
1
);
}
}
}
// id is mandatory
.
// Otherwise if the supported codec has preferredPayloadType, use it
.
if
(
typeof
ext
.
id
!
==
'number'
)
else
if
(
typeof
codec
.
preferredPayloadType
=
==
'number'
)
{
{
throw
new
TypeError
(
'missing ext.id'
);
// No need to remove it from the list since it's not a dynamic value.
}
}
// Otherwise choose a dynamic one.
else
{
// Take the first available pt and remove it from the list.
const
pt
=
dynamicPayloadTypes
.
shift
();
// encrypt is optional. If unset set it to false.
if
(
!
pt
)
if
(
ext
.
encrypt
&&
typeof
ext
.
encrypt
!==
'boolean'
)
{
{
throw
new
TypeError
(
'invalid ext.encrypt
'
);
throw
new
Error
(
'cannot allocate more dynamic codec payload types
'
);
}
}
else
if
(
!
ext
.
encrypt
)
{
codec
.
preferredPayloadType
=
pt
;
ext
.
encrypt
=
false
;
}
}
// parameters is optional. If unset, set it to an empty object
.
// Ensure there is not duplicated preferredPayloadType values
.
if
(
!
ext
.
parameters
||
typeof
ext
.
parameters
!==
'object'
)
if
(
caps
.
codecs
!
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
)
)
{
{
ext
.
parameters
=
{}
;
throw
new
TypeError
(
'duplicated codec.preferredPayloadType'
)
;
}
}
for
(
const
key
of
Object
.
keys
(
ext
.
parameters
))
// Merge the media codec parameters.
codec
.
parameters
=
{
...
codec
.
parameters
,
...
mediaCodec
.
parameters
};
// Append to the codec list.
caps
.
codecs
!
.
push
(
codec
);
// Add a RTX video codec if video.
if
(
codec
.
kind
===
'video'
)
{
{
let
value
=
ext
.
parameters
[
key
];
// Take the first available pt and remove it from the list.
const
pt
=
dynamicPayloadTypes
.
shift
();
if
(
value
===
undefined
)
if
(
!
pt
)
{
{
ext
.
parameters
[
key
]
=
''
;
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
value
=
''
;
}
}
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
const
rtxCodec
:
RtpCodecCapability
=
{
{
throw
new
TypeError
(
'invalid header extension parameter'
);
kind
:
codec
.
kind
,
mimeType
:
`
${
codec
.
kind
}
/rtx`
,
preferredPayloadType
:
pt
,
clockRate
:
codec
.
clockRate
,
parameters
:
{
apt
:
codec
.
preferredPayloadType
},
rtcpFeedback
:
[]
};
// Append to the codec list.
caps
.
codecs
!
.
push
(
rtxCodec
);
}
}
}
}
return
caps
;
}
}
/**
/**
* Validates RtpEncodingParameters. It may modify given data by adding missing
* Get a mapping of codec payloads and encodings of the given Producer RTP
* fields with default values.
* parameters as values expected by the Router.
* It throws if invalid.
*
* It may throw if invalid or non supported RTP parameters are given.
*/
*/
export
function
validateRtpEncodingParameters
(
encoding
:
RtpEncodingParameters
):
void
export
function
getProducerRtpParametersMapping
(
params
:
RtpParameters
,
caps
:
RtpCapabilities
):
RtpMapping
{
{
if
(
typeof
encoding
!==
'object'
)
const
rtpMapping
:
RtpMapping
=
{
{
throw
new
TypeError
(
'encoding is not an object'
);
codecs
:
[],
}
encodings
:
[]
};
// ssrc is optional.
// Match parameters media codecs to capabilities media codecs.
if
(
encoding
.
ssrc
&&
typeof
encoding
.
ssrc
!==
'number'
)
const
codecToCapCodec
:
Map
<
RtpCodecParameters
,
RtpCodecCapability
>
=
new
Map
();
for
(
const
codec
of
params
.
codecs
)
{
{
throw
new
TypeError
(
'invalid encoding.ssrc'
);
if
(
isRtxCodec
(
codec
))
{
continue
;
}
}
// rid is optional.
// Search for the same media codec in capabilities.
if
(
encoding
.
rid
&&
typeof
encoding
.
rid
!==
'string'
)
const
matchedCapCodec
=
caps
.
codecs
!
.
find
((
capCodec
)
=>
(
matchCodecs
(
codec
,
capCodec
,
{
strict
:
true
,
modify
:
true
}))
);
if
(
!
matchedCapCodec
)
{
{
throw
new
TypeError
(
'invalid encoding.rid'
);
throw
new
UnsupportedError
(
`unsupported codec [mimeType:
${
codec
.
mimeType
}
, payloadType:
${
codec
.
payloadType
}
]`
);
}
}
// rtx is optional.
codecToCapCodec
.
set
(
codec
,
matchedCapCodec
);
if
(
encoding
.
rtx
&&
typeof
encoding
.
rtx
!==
'object'
)
{
throw
new
TypeError
(
'invalid encoding.rtx'
);
}
}
else
if
(
encoding
.
rtx
)
// Match parameters RTX codecs to capabilities RTX codecs.
for
(
const
codec
of
params
.
codecs
)
{
{
// RTX ssrc is mandatory if rtx is present.
if
(
!
isRtxCodec
(
codec
))
if
(
typeof
encoding
.
rtx
.
ssrc
!==
'number'
)
{
{
throw
new
TypeError
(
'missing encoding.rtx.ssrc'
);
continue
;
}
}
}
// dtx is optional. If unset set it to false.
// Search for the associated media codec.
if
(
!
encoding
.
dtx
||
typeof
encoding
.
dtx
!==
'boolean'
)
const
associatedMediaCodec
=
params
.
codecs
{
.
find
((
mediaCodec
)
=>
mediaCodec
.
payloadType
===
codec
.
parameters
.
apt
);
encoding
.
dtx
=
false
;
}
// scalabilityMode is optional.
if
(
!
associatedMediaCodec
)
if
(
encoding
.
scalabilityMode
&&
typeof
encoding
.
scalabilityMode
!==
'string'
)
{
{
throw
new
TypeError
(
'invalid encoding.scalabilityMode'
);
throw
new
TypeError
(
`missing media codec found for RTX PT
${
codec
.
payloadType
}
`
);
}
}
}
/**
const
capMediaCodec
=
codecToCapCodec
.
get
(
associatedMediaCodec
);
* 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.
// Ensure that the capabilities media codec has a RTX codec.
if
(
rtcp
.
cname
&&
typeof
rtcp
.
cname
!==
'string'
)
const
associatedCapRtxCodec
=
caps
.
codecs
!
.
find
((
capCodec
)
=>
(
isRtxCodec
(
capCodec
)
&&
capCodec
.
parameters
.
apt
===
capMediaCodec
!
.
preferredPayloadType
));
if
(
!
associatedCapRtxCodec
)
{
{
throw
new
TypeError
(
'invalid rtcp.cname'
);
throw
new
UnsupportedError
(
`no RTX codec for capability codec PT
${
capMediaCodec
!
.
preferredPayloadType
}
`
);
}
}
// reducedSize is optional. If unset set it to true.
codecToCapCodec
.
set
(
codec
,
associatedCapRtxCodec
);
if
(
!
rtcp
.
reducedSize
||
typeof
rtcp
.
reducedSize
!==
'boolean'
)
{
rtcp
.
reducedSize
=
true
;
}
}
}
/**
// Generate codecs mapping.
* Validates SctpCapabilities. It may modify given data by adding missing
for
(
const
[
codec
,
capCodec
]
of
codecToCapCodec
)
* 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'
);
rtpMapping
.
codecs
.
push
(
{
payloadType
:
codec
.
payloadType
,
mappedPayloadType
:
capCodec
.
preferredPayloadType
!
});
}
}
// numStreams is mandatory.
// Generate encodings mapping.
if
(
!
caps
.
numStreams
||
typeof
caps
.
numStreams
!==
'object'
)
let
mappedSsrc
=
utils
.
generateRandomNumber
();
for
(
const
encoding
of
params
.
encodings
!
)
{
{
throw
new
TypeError
(
'missing caps.numStreams'
);
const
mappedEncoding
:
any
=
{};
}
validateNumSctpStreams
(
caps
.
numStreams
);
mappedEncoding
.
mappedSsrc
=
mappedSsrc
++
;
}
/**
if
(
encoding
.
rid
)
* 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'
)
;
mappedEncoding
.
rid
=
encoding
.
rid
;
}
}
if
(
encoding
.
ssrc
)
// OS is mandatory.
if
(
typeof
numStreams
.
OS
!==
'number'
)
{
{
throw
new
TypeError
(
'missing numStreams.OS'
)
;
mappedEncoding
.
ssrc
=
encoding
.
ssrc
;
}
}
if
(
encoding
.
scalabilityMode
)
// MIS is mandatory.
if
(
typeof
numStreams
.
MIS
!==
'number'
)
{
{
throw
new
TypeError
(
'missing numStreams.MIS'
)
;
mappedEncoding
.
scalabilityMode
=
encoding
.
scalabilityMode
;
}
}
rtpMapping
.
encodings
.
push
(
mappedEncoding
);
}
return
rtpMapping
;
}
}
/**
/**
* Validates SctpParameters. It may modify given data by adding missing
* Generate RTP parameters to be internally used by Consumers given the RTP
* fields with default values.
* parameters of a Producer and the RTP capabilities of the Router.
* It throws if invalid.
*/
*/
export
function
validateSctpParameters
(
params
:
SctpParameters
):
void
export
function
getConsumableRtpParameters
(
kind
:
string
,
params
:
RtpParameters
,
caps
:
RtpCapabilities
,
rtpMapping
:
RtpMapping
):
RtpParameters
{
{
if
(
typeof
params
!==
'object'
)
const
consumableParams
:
RtpParameters
=
{
{
throw
new
TypeError
(
'params is not an object'
);
codecs
:
[],
}
headerExtensions
:
[],
encodings
:
[],
rtcp
:
{}
};
// port is mandatory.
for
(
const
codec
of
params
.
codecs
)
if
(
typeof
params
.
port
!==
'number'
)
{
{
throw
new
TypeError
(
'missing params.port'
);
if
(
isRtxCodec
(
codec
))
}
// OS is mandatory.
if
(
typeof
params
.
OS
!==
'number'
)
{
{
throw
new
TypeError
(
'missing params.OS'
)
;
continue
;
}
}
// MIS is mandatory.
const
consumableCodecPt
=
rtpMapping
.
codecs
if
(
typeof
params
.
MIS
!==
'number'
)
.
find
((
entry
)
=>
entry
.
payloadType
===
codec
.
payloadType
)
!
{
.
mappedPayloadType
;
throw
new
TypeError
(
'missing params.MIS'
);
}
// maxMessageSize is mandatory.
const
matchedCapCodec
=
caps
.
codecs
!
if
(
typeof
params
.
maxMessageSize
!==
'number'
)
.
find
((
capCodec
)
=>
capCodec
.
preferredPayloadType
===
consumableCodecPt
)
!
;
{
throw
new
TypeError
(
'missing params.maxMessageSize'
);
}
}
/**
const
consumableCodec
:
RtpCodecParameters
=
* 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'
);
mimeType
:
matchedCapCodec
.
mimeType
,
}
payloadType
:
matchedCapCodec
.
preferredPayloadType
!
,
clockRate
:
matchedCapCodec
.
clockRate
,
channels
:
matchedCapCodec
.
channels
,
parameters
:
codec
.
parameters
,
// Keep the Producer codec parameters.
rtcpFeedback
:
matchedCapCodec
.
rtcpFeedback
};
// streamId is mandatory.
consumableParams
.
codecs
.
push
(
consumableCodec
);
if
(
typeof
params
.
streamId
!==
'number'
)
{
throw
new
TypeError
(
'missing params.streamId'
);
}
// ordered is optional.
const
consumableCapRtxCodec
=
caps
.
codecs
!
let
orderedGiven
=
false
;
.
find
((
capRtxCodec
)
=>
(
isRtxCodec
(
capRtxCodec
)
&&
capRtxCodec
.
parameters
.
apt
===
consumableCodec
.
payloadType
));
if
(
typeof
params
.
ordered
===
'boolean'
)
if
(
consumableCapRtxCodec
)
{
{
orderedGiven
=
true
;
const
consumableRtxCodec
:
RtpCodecParameters
=
}
else
{
{
params
.
ordered
=
true
;
mimeType
:
consumableCapRtxCodec
.
mimeType
,
}
payloadType
:
consumableCapRtxCodec
.
preferredPayloadType
!
,
clockRate
:
consumableCapRtxCodec
.
clockRate
,
parameters
:
consumableCapRtxCodec
.
parameters
,
rtcpFeedback
:
consumableCapRtxCodec
.
rtcpFeedback
};
// maxPacketLifeTime is optional.
consumableParams
.
codecs
.
push
(
consumableRtxCodec
);
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
)
for
(
const
capExt
of
caps
.
headerExtensions
!
)
{
{
throw
new
TypeError
(
'cannot provide both maxPacketLifeTime and maxRetransmits'
);
}
// Just take RTP header extension that can be used in Consumers.
if
(
if
(
orderedGiven
&&
capExt
.
kind
!==
kind
||
params
.
ordered
&&
(
capExt
.
direction
!==
'sendrecv'
&&
capExt
.
direction
!==
'sendonly'
)
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
)
)
)
{
{
throw
new
TypeError
(
'cannot be ordered with maxPacketLifeTime or maxRetransmits'
)
;
continue
;
}
}
else
if
(
!
orderedGiven
&&
(
params
.
maxPacketLifeTime
||
params
.
maxRetransmits
))
const
consumableExt
=
{
{
params
.
ordered
=
false
;
uri
:
capExt
.
uri
,
id
:
capExt
.
preferredId
,
encrypt
:
capExt
.
preferredEncrypt
,
parameters
:
{}
};
consumableParams
.
headerExtensions
!
.
push
(
consumableExt
);
}
}
}
/**
// Clone Producer encodings since we'll mangle them.
* Generate RTP capabilities for the Router based on the given media codecs and
const
consumableEncodings
=
* mediasoup supported RTP capabilities.
utils
.
clone
<
RtpEncodingParameters
[]
|
undefined
>
(
params
.
encodings
)
??
[];
*/
export
function
generateRouterRtpCapabilities
(
mediaCodecs
:
RtpCodecCapability
[]
=
[]
):
RtpCapabilities
{
// Normalize supported RTP capabilities.
validateRtpCapabilities
(
supportedRtpCapabilities
);
if
(
!
Array
.
isArray
(
mediaCodecs
)
)
for
(
let
i
=
0
;
i
<
consumableEncodings
.
length
;
++
i
)
{
{
throw
new
TypeError
(
'mediaCodecs must be an Array'
);
const
consumableEncoding
=
consumableEncodings
[
i
];
const
{
mappedSsrc
}
=
rtpMapping
.
encodings
[
i
];
// Remove useless fields.
delete
consumableEncoding
.
rid
;
delete
consumableEncoding
.
rtx
;
delete
consumableEncoding
.
codecPayloadType
;
// Set the mapped ssrc.
consumableEncoding
.
ssrc
=
mappedSsrc
;
consumableParams
.
encodings
!
.
push
(
consumableEncoding
);
}
}
const
clonedSupportedRtpCapabilities
=
consumableParams
.
rtcp
=
utils
.
clone
(
supportedRtpCapabilities
)
as
RtpCapabilities
;
const
dynamicPayloadTypes
=
utils
.
clone
(
DynamicPayloadTypes
)
as
number
[];
const
caps
:
RtpCapabilities
=
{
{
c
odecs
:
[]
,
c
name
:
params
.
rtcp
!
.
cname
,
headerExtensions
:
clonedSupportedRtpCapabilities
.
headerExtensions
reducedSize
:
true
};
};
for
(
const
mediaCodec
of
mediaCodecs
)
return
consumableParams
;
{
}
/**
* Check whether the given RTP capabilities can consume the given Producer.
*/
export
function
canConsume
(
consumableParams
:
RtpParameters
,
caps
:
RtpCapabilities
):
boolean
{
// This may throw.
// This may throw.
validateRtpCodecCapability
(
mediaCodec
);
validateRtpCapabilities
(
caps
);
const
matchedSupportedCodec
=
clonedSupportedRtpCapabilities
const
matchingCodecs
:
RtpCodecParameters
[]
=
[];
.
codecs
!
.
find
((
supportedCodec
)
=>
(
matchCodecs
(
mediaCodec
,
supportedCodec
,
{
strict
:
false
}))
);
if
(
!
matchedSupportedCodec
)
for
(
const
codec
of
consumableParams
.
codecs
)
{
{
throw
new
UnsupportedError
(
const
matchedCapCodec
=
caps
.
codecs
!
`media codec not supported [mimeType:
${
mediaCodec
.
mimeType
}
]`
);
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
if
(
!
matchedCapCodec
)
{
continue
;
}
}
// Clone the supported codec.
matchingCodecs
.
push
(
codec
);
const
codec
=
utils
.
clone
(
matchedSupportedCodec
)
as
RtpCodecCapability
;
}
// If the given media codec has preferredPayloadType, keep it
.
// Ensure there is at least one media codec
.
if
(
typeof
mediaCodec
.
preferredPayloadType
===
'number'
)
if
(
matchingCodecs
.
length
===
0
||
isRtxCodec
(
matchingCodecs
[
0
])
)
{
{
codec
.
preferredPayloadType
=
mediaCodec
.
preferredPayloadType
;
return
false
;
}
// Also remove the pt from the list of available dynamic values.
return
true
;
const
idx
=
dynamicPayloadTypes
.
indexOf
(
codec
.
preferredPayloadType
);
}
if
(
idx
>
-
1
)
/**
* Generate RTP parameters for a specific Consumer.
*
* It reduces encodings to just one and takes into account given RTP
* capabilities to reduce codecs, codecs' RTCP feedback and header extensions,
* and also enables or disables RTX.
*/
export
function
getConsumerRtpParameters
(
{
{
dynamicPayloadTypes
.
splice
(
idx
,
1
);
consumableRtpParameters
,
}
remoteRtpCapabilities
,
}
pipe
,
// Otherwise if the supported codec has preferredPayloadType, use it.
enableRtx
else
if
(
typeof
codec
.
preferredPayloadType
===
'number'
)
}:
{
{
// No need to remove it from the list since it's not a dynamic value.
consumableRtpParameters
:
RtpParameters
;
remoteRtpCapabilities
:
RtpCapabilities
;
pipe
:
boolean
;
enableRtx
:
boolean
;
}
}
// Otherwise choose a dynamic one.
):
RtpParameters
else
{
const
consumerParams
:
RtpParameters
=
{
{
// Take the first available pt and remove it from the list.
codecs
:
[],
const
pt
=
dynamicPayloadTypes
.
shift
();
headerExtensions
:
[],
encodings
:
[],
rtcp
:
consumableRtpParameters
.
rtcp
};
if
(
!
pt
)
for
(
const
capCodec
of
remoteRtpCapabilities
.
codecs
!
)
{
{
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
validateRtpCodecCapability
(
capCodec
);
}
}
codec
.
preferredPayloadType
=
pt
;
const
consumableCodecs
=
}
utils
.
clone
<
RtpCodecParameters
[]
|
undefined
>
(
consumableRtpParameters
.
codecs
)
??
[];
// Ensure there is not duplicated preferredPayloadType values.
let
rtxSupported
=
false
;
if
(
caps
.
codecs
!
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
for
(
const
codec
of
consumableCodecs
)
{
{
throw
new
TypeError
(
'duplicated codec.preferredPayloadType'
);
if
(
!
enableRtx
&&
isRtxCodec
(
codec
))
{
continue
;
}
}
// Merge the media codec parameters.
const
matchedCapCodec
=
remoteRtpCapabilities
.
codecs
!
codec
.
parameters
=
{
...
codec
.
parameters
,
...
mediaCodec
.
parameters
};
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
// Append to the codec list.
caps
.
codecs
!
.
push
(
codec
);
// Add a RTX video codec if video.
if
(
!
matchedCapCodec
)
if
(
codec
.
kind
===
'video'
)
{
{
// Take the first available pt and remove it from the list.
continue
;
const
pt
=
dynamicPayloadTypes
.
shift
();
}
if
(
!
pt
)
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
!
{
.
filter
((
fb
)
=>
(
throw
new
Error
(
'cannot allocate more dynamic codec payload types'
);
(
enableRtx
||
fb
.
type
!==
'nack'
||
fb
.
parameter
)
));
consumerParams
.
codecs
.
push
(
codec
);
}
}
const
rtxCodec
:
RtpCodecCapability
=
// Must sanitize the list of matched codecs by removing useless RTX codecs.
for
(
let
idx
=
consumerParams
.
codecs
.
length
-
1
;
idx
>=
0
;
--
idx
)
{
{
kind
:
codec
.
kind
,
const
codec
=
consumerParams
.
codecs
[
idx
];
mimeType
:
`
${
codec
.
kind
}
/rtx`
,
preferredPayloadType
:
pt
,
if
(
isRtxCodec
(
codec
))
clockRate
:
codec
.
clockRate
,
parameters
:
{
{
apt
:
codec
.
preferredPayloadType
// Search for the associated media codec.
},
const
associatedMediaCodec
=
consumerParams
.
codecs
rtcpFeedback
:
[]
.
find
((
mediaCodec
)
=>
mediaCodec
.
payloadType
===
codec
.
parameters
.
apt
);
};
// Append to the codec list.
if
(
associatedMediaCodec
)
caps
.
codecs
!
.
push
(
rtxCodec
);
{
rtxSupported
=
true
;
}
else
{
consumerParams
.
codecs
.
splice
(
idx
,
1
);
}
}
}
}
}
return
caps
;
// Ensure there is at least one media codec.
}
if
(
consumerParams
.
codecs
.
length
===
0
||
isRtxCodec
(
consumerParams
.
codecs
[
0
]))
/**
* Get a mapping of codec payloads and encodings of the given Producer RTP
* parameters as values expected by the Router.
*
* It may throw if invalid or non supported RTP parameters are given.
*/
export
function
getProducerRtpParametersMapping
(
params
:
RtpParameters
,
caps
:
RtpCapabilities
):
RtpMapping
{
const
rtpMapping
:
RtpMapping
=
{
{
codecs
:
[],
throw
new
UnsupportedError
(
'no compatible media codecs'
);
encodings
:
[]
}
};
// Match parameters media codecs to capabilities media codecs.
consumerParams
.
headerExtensions
=
consumableRtpParameters
.
headerExtensions
!
const
codecToCapCodec
:
Map
<
RtpCodecParameters
,
RtpCodecCapability
>
=
new
Map
();
.
filter
((
ext
)
=>
(
remoteRtpCapabilities
.
headerExtensions
!
.
some
((
capExt
)
=>
(
capExt
.
preferredId
===
ext
.
id
&&
capExt
.
uri
===
ext
.
uri
))
));
for
(
const
codec
of
params
.
codecs
)
// 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
(
isRtxCodec
(
codec
)
)
for
(
const
codec
of
consumerParams
.
codecs
)
{
{
continue
;
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
.
filter
((
fb
)
=>
fb
.
type
!==
'goog-remb'
);
}
}
}
// Search for the same media codec in capabilities.
else
if
(
const
matchedCapCodec
=
caps
.
codecs
!
consumerParams
.
headerExtensions
.
some
((
ext
)
=>
(
.
find
((
capCodec
)
=>
(
ext
.
uri
===
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
matchCodecs
(
codec
,
capCodec
,
{
strict
:
true
,
modify
:
true
}))
))
);
)
if
(
!
matchedCapCodec
)
{
{
throw
new
UnsupportedError
(
for
(
const
codec
of
consumerParams
.
codecs
)
`unsupported codec [mimeType:
${
codec
.
mimeType
}
, payloadType:
${
codec
.
payloadType
}
]`
);
{
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
.
filter
((
fb
)
=>
fb
.
type
!==
'transport-cc'
);
}
}
codecToCapCodec
.
set
(
codec
,
matchedCapCodec
);
}
}
else
// Match parameters RTX codecs to capabilities RTX codecs.
for
(
const
codec
of
params
.
codecs
)
{
{
if
(
!
isRtxCodec
(
codec
)
)
for
(
const
codec
of
consumerParams
.
codecs
)
{
{
continue
;
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
.
filter
((
fb
)
=>
(
fb
.
type
!==
'transport-cc'
&&
fb
.
type
!==
'goog-remb'
));
}
}
}
// Search for the associated media codec.
if
(
!
pipe
)
const
associatedMediaCodec
=
params
.
codecs
{
.
find
((
mediaCodec
)
=>
mediaCodec
.
payloadType
===
codec
.
parameters
.
apt
);
const
consumerEncoding
:
RtpEncodingParameters
=
{
ssrc
:
utils
.
generateRandomNumber
()
};
if
(
!
associatedMediaCodec
)
if
(
rtxSupported
)
{
{
throw
new
TypeError
(
consumerEncoding
.
rtx
=
{
ssrc
:
consumerEncoding
.
ssrc
!
+
1
};
`missing media codec found for RTX PT
${
codec
.
payloadType
}
`
);
}
}
const
capMediaCodec
=
codecToCapCodec
.
get
(
associatedMediaCodec
);
// If any of the consumableRtpParameters.encodings has scalabilityMode,
// process it (assume all encodings have the same value).
const
encodingWithScalabilityMode
=
consumableRtpParameters
.
encodings
!
.
find
((
encoding
)
=>
encoding
.
scalabilityMode
);
// Ensure that the capabilities media codec has a RTX codec.
let
scalabilityMode
=
encodingWithScalabilityMode
const
associatedCapRtxCodec
=
caps
.
codecs
!
?
encodingWithScalabilityMode
.
scalabilityMode
.
find
((
capCodec
)
=>
(
:
undefined
;
isRtxCodec
(
capCodec
)
&&
capCodec
.
parameters
.
apt
===
capMediaCodec
!
.
preferredPayloadType
));
if
(
!
associatedCapRtxCodec
)
// If there is simulast, mangle spatial layers in scalabilityMode.
if
(
consumableRtpParameters
.
encodings
!
.
length
>
1
)
{
{
throw
new
UnsupportedError
(
const
{
temporalLayers
}
=
parseScalabilityMode
(
scalabilityMode
);
`no RTX codec for capability codec PT
${
capMediaCodec
!
.
preferredPayloadType
}
`
);
}
codecToCapCodec
.
set
(
codec
,
associatedCapRtxCodec
)
;
scalabilityMode
=
`L
${
consumableRtpParameters
.
encodings
!
.
length
}
T
${
temporalLayers
}
`
;
}
}
// Generate codecs mapping.
if
(
scalabilityMode
)
for
(
const
[
codec
,
capCodec
]
of
codecToCapCodec
)
{
rtpMapping
.
codecs
.
push
(
{
{
payloadType
:
codec
.
payloadType
,
consumerEncoding
.
scalabilityMode
=
scalabilityMode
;
mappedPayloadType
:
capCodec
.
preferredPayloadType
!
});
}
}
// Generate encodings mapping.
// Use the maximum maxBitrate in any encoding and honor it in the Consumer's
let
mappedSsrc
=
utils
.
generateRandomNumber
();
// encoding.
const
maxEncodingMaxBitrate
=
consumableRtpParameters
.
encodings
!
.
reduce
((
maxBitrate
,
encoding
)
=>
(
encoding
.
maxBitrate
&&
encoding
.
maxBitrate
>
maxBitrate
?
encoding
.
maxBitrate
:
maxBitrate
),
0
);
for
(
const
encoding
of
params
.
encodings
!
)
if
(
maxEncodingMaxBitrate
)
{
{
const
mappedEncoding
:
any
=
{};
consumerEncoding
.
maxBitrate
=
maxEncodingMaxBitrate
;
}
mappedEncoding
.
mappedSsrc
=
mappedSsrc
++
;
// Set a single encoding for the Consumer.
consumerParams
.
encodings
!
.
push
(
consumerEncoding
);
}
else
{
const
consumableEncodings
=
utils
.
clone
<
RtpEncodingParameters
[]
|
undefined
>
(
consumableRtpParameters
.
encodings
)
??
[];
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
if
(
encoding
.
rid
)
for
(
let
i
=
0
;
i
<
consumableEncodings
.
length
;
++
i
)
{
{
mappedEncoding
.
rid
=
encoding
.
rid
;
const
encoding
=
consumableEncodings
[
i
];
}
if
(
encoding
.
ssrc
)
encoding
.
ssrc
=
baseSsrc
+
i
;
if
(
rtxSupported
)
{
{
mappedEncoding
.
ssrc
=
encoding
.
ssrc
;
encoding
.
rtx
=
{
ssrc
:
baseRtxSsrc
+
i
}
;
}
}
if
(
encoding
.
scalabilityMode
)
else
{
{
mappedEncoding
.
scalabilityMode
=
encoding
.
scalabilityMode
;
delete
encoding
.
rtx
;
}
}
rtpMapping
.
encodings
.
push
(
mappedEncoding
);
consumerParams
.
encodings
!
.
push
(
encoding
);
}
}
}
return
rtpMapping
;
return
consumerParams
;
}
}
/**
/**
* Generate RTP parameters to be internally used by Consumers given the RTP
* Generate RTP parameters for a pipe Consumer.
* parameters of a Producer and the RTP capabilities of the Router.
*
* It keeps all original consumable encodings and removes support for BWE. If
* enableRtx is false, it also removes RTX and NACK support.
*/
*/
export
function
getConsumableRtpParameters
(
export
function
getPipeConsumerRtpParameters
(
kind
:
string
,
{
params
:
RtpParameters
,
consumableRtpParameters
,
caps
:
RtpCapabilities
,
enableRtx
rtpMapping
:
RtpMapping
}:
{
consumableRtpParameters
:
RtpParameters
;
enableRtx
:
boolean
;
}
):
RtpParameters
):
RtpParameters
{
{
const
consum
able
Params
:
RtpParameters
=
const
consum
er
Params
:
RtpParameters
=
{
{
codecs
:
[],
codecs
:
[],
headerExtensions
:
[],
headerExtensions
:
[],
encodings
:
[],
encodings
:
[],
rtcp
:
{}
rtcp
:
consumableRtpParameters
.
rtcp
};
};
for
(
const
codec
of
params
.
codecs
)
const
consumableCodecs
=
utils
.
clone
<
RtpCodecParameters
[]
|
undefined
>
(
consumableRtpParameters
.
codecs
)
??
[];
for
(
const
codec
of
consumableCodecs
)
{
{
if
(
isRtxCodec
(
codec
))
if
(
!
enableRtx
&&
isRtxCodec
(
codec
))
{
{
continue
;
continue
;
}
}
const
consumableCodecPt
=
rtpMapping
.
codecs
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
.
find
((
entry
)
=>
entry
.
payloadType
===
codec
.
payloadType
)
!
.
filter
((
fb
)
=>
(
.
mappedPayloadType
;
(
fb
.
type
===
'nack'
&&
fb
.
parameter
===
'pli'
)
||
(
fb
.
type
===
'ccm'
&&
fb
.
parameter
===
'fir'
)
||
(
enableRtx
&&
fb
.
type
===
'nack'
&&
!
fb
.
parameter
)
));
cons
t
matchedCapCodec
=
caps
.
codecs
!
cons
umerParams
.
codecs
.
push
(
codec
);
.
find
((
capCodec
)
=>
capCodec
.
preferredPayloadType
===
consumableCodecPt
)
!
;
}
const
consumableCodec
:
RtpCodecParameters
=
// Reduce RTP extensions by disabling transport MID and BWE related ones.
{
consumerParams
.
headerExtensions
=
consumableRtpParameters
.
headerExtensions
!
mimeType
:
matchedCapCodec
.
mimeType
,
.
filter
((
ext
)
=>
(
payloadType
:
matchedCapCodec
.
preferredPayloadType
!
,
ext
.
uri
!==
'urn:ietf:params:rtp-hdrext:sdes:mid'
&&
clockRate
:
matchedCapCodec
.
clockRate
,
ext
.
uri
!==
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
&&
channels
:
matchedCapCodec
.
channels
,
ext
.
uri
!==
'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01'
parameters
:
codec
.
parameters
,
// Keep the Producer codec parameters.
));
rtcpFeedback
:
matchedCapCodec
.
rtcpFeedback
};
consumableParams
.
codecs
.
push
(
consumableCodec
);
const
consumableEncodings
=
utils
.
clone
<
RtpEncodingParameters
[]
|
undefined
>
(
consumableRtpParameters
.
encodings
)
??
[];
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
const
consumableCapRtxCodec
=
caps
.
codecs
!
for
(
let
i
=
0
;
i
<
consumableEncodings
.
length
;
++
i
)
.
find
((
capRtxCodec
)
=>
(
{
isRtxCodec
(
capRtxCodec
)
&&
const
encoding
=
consumableEncodings
[
i
];
capRtxCodec
.
parameters
.
apt
===
consumableCodec
.
payloadType
));
if
(
consumableCapRtxCodec
)
encoding
.
ssrc
=
baseSsrc
+
i
;
if
(
enableRtx
)
{
{
const
consumableRtxCodec
:
RtpCodecParameters
=
encoding
.
rtx
=
{
ssrc
:
baseRtxSsrc
+
i
};
}
else
{
{
mimeType
:
consumableCapRtxCodec
.
mimeType
,
delete
encoding
.
rtx
;
payloadType
:
consumableCapRtxCodec
.
preferredPayloadType
!
,
clockRate
:
consumableCapRtxCodec
.
clockRate
,
parameters
:
consumableCapRtxCodec
.
parameters
,
rtcpFeedback
:
consumableCapRtxCodec
.
rtcpFeedback
};
consumableParams
.
codecs
.
push
(
consumableRtxCodec
);
}
}
consumerParams
.
encodings
!
.
push
(
encoding
);
}
}
for
(
const
capExt
of
caps
.
headerExtensions
!
)
return
consumerParams
;
{
}
// Just take RTP header extension that can be used in Consumers.
function
isRtxCodec
(
codec
:
RtpCodecCapability
|
RtpCodecParameters
):
boolean
if
(
{
capExt
.
kind
!==
kind
||
return
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
);
(
capExt
.
direction
!==
'sendrecv'
&&
capExt
.
direction
!==
'sendonly'
)
}
)
function
matchCodecs
(
aCodec
:
RtpCodecCapability
|
RtpCodecParameters
,
bCodec
:
RtpCodecCapability
|
RtpCodecParameters
,
{
strict
=
false
,
modify
=
false
}
=
{}
):
boolean
{
const
aMimeType
=
aCodec
.
mimeType
.
toLowerCase
();
const
bMimeType
=
bCodec
.
mimeType
.
toLowerCase
();
if
(
aMimeType
!==
bMimeType
)
{
{
continu
e
;
return
fals
e
;
}
}
const
consumableExt
=
if
(
aCodec
.
clockRate
!==
bCodec
.
clockRate
)
{
{
uri
:
capExt
.
uri
,
return
false
;
id
:
capExt
.
preferredId
,
}
encrypt
:
capExt
.
preferredEncrypt
,
parameters
:
{}
};
consumableParams
.
headerExtensions
!
.
push
(
consumableExt
);
if
(
aCodec
.
channels
!==
bCodec
.
channels
)
{
return
false
;
}
}
// Clone Producer encodings since we'll mangle them.
// Per codec special checks.
const
consumableEncodings
=
switch
(
aMimeType
)
(
utils
.
clone
(
params
.
encodings
)
??
[])
as
RtpEncodingParameters
[];
{
case
'audio/multiopus'
:
{
const
aNumStreams
=
aCodec
.
parameters
[
'num_streams'
];
const
bNumStreams
=
bCodec
.
parameters
[
'num_streams'
];
for
(
let
i
=
0
;
i
<
consumableEncodings
.
length
;
++
i
)
if
(
aNumStreams
!==
bNumStreams
)
{
{
const
consumableEncoding
=
consumableEncodings
[
i
]
;
return
false
;
const
{
mappedSsrc
}
=
rtpMapping
.
encodings
[
i
];
}
// Remove useless fields.
const
aCoupledStreams
=
aCodec
.
parameters
[
'coupled_streams'
];
delete
consumableEncoding
.
rid
;
const
bCoupledStreams
=
bCodec
.
parameters
[
'coupled_streams'
];
delete
consumableEncoding
.
rtx
;
delete
consumableEncoding
.
codecPayloadType
;
// Set the mapped ssrc.
if
(
aCoupledStreams
!==
bCoupledStreams
)
consumableEncoding
.
ssrc
=
mappedSsrc
;
{
return
false
;
}
consumableParams
.
encodings
!
.
push
(
consumableEncoding
)
;
break
;
}
}
consumableParams
.
rtcp
=
case
'video/h264'
:
case
'video/h264-svc'
:
{
{
cname
:
params
.
rtcp
!
.
cname
,
if
(
strict
)
reducedSize
:
true
{
};
const
aPacketizationMode
=
aCodec
.
parameters
[
'packetization-mode'
]
||
0
;
const
bPacketizationMode
=
bCodec
.
parameters
[
'packetization-mode'
]
||
0
;
return
consumableParams
;
if
(
aPacketizationMode
!==
bPacketizationMode
)
}
{
return
false
;
}
/**
if
(
!
h264
.
isSameProfile
(
aCodec
.
parameters
,
bCodec
.
parameters
))
* Check whether the given RTP capabilities can consume the given Producer.
{
*/
return
false
;
export
function
canConsume
(
}
consumableParams
:
RtpParameters
,
caps
:
RtpCapabilities
):
boolean
{
// This may throw.
validateRtpCapabilities
(
caps
);
const
matchingCodecs
:
RtpCodecParameters
[]
=
[]
;
let
selectedProfileLevelId
;
for
(
const
codec
of
consumableParams
.
codecs
)
try
{
{
const
matchedCapCodec
=
caps
.
codecs
!
selectedProfileLevelId
=
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
h264
.
generateProfileLevelIdStringForAnswer
(
aCodec
.
parameters
,
bCodec
.
parameters
);
}
catch
(
error
)
{
return
false
;
}
if
(
!
matchedCapCodec
)
if
(
modify
)
{
{
continue
;
if
(
selectedProfileLevelId
)
{
aCodec
.
parameters
[
'profile-level-id'
]
=
selectedProfileLevelId
;
}
else
{
delete
aCodec
.
parameters
[
'profile-level-id'
];
}
}
}
}
matchingCodecs
.
push
(
codec
)
;
break
;
}
}
// Ensure there is at least one media codec.
case
'video/vp9'
:
if
(
matchingCodecs
.
length
===
0
||
isRtxCodec
(
matchingCodecs
[
0
]))
{
if
(
strict
)
{
const
aProfileId
=
aCodec
.
parameters
[
'profile-id'
]
||
0
;
const
bProfileId
=
bCodec
.
parameters
[
'profile-id'
]
||
0
;
if
(
aProfileId
!==
bProfileId
)
{
{
return
false
;
return
false
;
}
}
}
break
;
}
}
return
true
;
return
true
;
}
}
/**
export
function
serializeRtpMapping
(
* Generate RTP parameters for a specific Consumer.
builder
:
flatbuffers
.
Builder
,
rtpMapping
:
RtpMapping
*
):
number
* It reduces encodings to just one and takes into account given RTP capabilities
{
* to reduce codecs, codecs' RTCP feedback and header extensions, and also enables
const
codecs
:
number
[]
=
[];
* or disables RTX.
*/
for
(
const
codec
of
rtpMapping
.
codecs
)
export
function
getConsumerRtpParameters
(
{
{
consumableRtpParameters
,
codecs
.
push
(
remoteRtpCapabilities
,
FbsRtpParameters
.
CodecMapping
.
createCodecMapping
(
pipe
,
builder
,
codec
.
payloadType
,
codec
.
mappedPayloadType
enableRtx
)
}:
);
}
const
codecsOffset
=
FbsRtpParameters
.
RtpMapping
.
createCodecsVector
(
builder
,
codecs
);
const
encodings
:
number
[]
=
[];
for
(
const
encoding
of
rtpMapping
.
encodings
)
{
{
consumableRtpParameters
:
RtpParameters
;
encodings
.
push
(
remoteRtpCapabilities
:
RtpCapabilities
;
FbsRtpParameters
.
EncodingMapping
.
createEncodingMapping
(
pipe
:
boolean
;
builder
,
enableRtx
:
boolean
;
builder
.
createString
(
encoding
.
rid
),
encoding
.
ssrc
??
null
,
builder
.
createString
(
encoding
.
scalabilityMode
),
encoding
.
mappedSsrc
)
);
}
}
):
RtpParameters
const
encodingsOffset
=
FbsRtpParameters
.
RtpMapping
.
createEncodingsVector
(
builder
,
encodings
);
return
FbsRtpParameters
.
RtpMapping
.
createRtpMapping
(
builder
,
codecsOffset
,
encodingsOffset
);
}
/**
* Validates RtpCodecCapability. It may modify given data by adding missing
* fields with default values.
* It throws if invalid.
*/
function
validateRtpCodecCapability
(
codec
:
RtpCodecCapability
):
void
{
{
const
consumerParams
:
RtpParameters
=
const
MimeTypeRegex
=
new
RegExp
(
'^(audio|video)/(.+)'
,
'i'
);
{
codecs
:
[],
headerExtensions
:
[],
encodings
:
[],
rtcp
:
consumableRtpParameters
.
rtcp
};
for
(
const
capCodec
of
remoteRtpCapabilities
.
codecs
!
)
if
(
typeof
codec
!==
'object'
)
{
{
validateRtpCodecCapability
(
capCodec
);
throw
new
TypeError
(
'codec is not an object'
);
}
}
const
consumableCodecs
=
// mimeType is mandatory.
(
utils
.
clone
(
consumableRtpParameters
.
codecs
)
??
[])
as
RtpCodecParameters
[];
if
(
!
codec
.
mimeType
||
typeof
codec
.
mimeType
!==
'string'
)
let
rtxSupported
=
false
;
for
(
const
codec
of
consumableCodecs
)
{
if
(
!
enableRtx
&&
isRtxCodec
(
codec
))
{
{
continue
;
throw
new
TypeError
(
'missing codec.mimeType'
)
;
}
}
const
matchedCapCodec
=
remoteRtpCapabilities
.
codecs
!
const
mimeTypeMatch
=
MimeTypeRegex
.
exec
(
codec
.
mimeType
);
.
find
((
capCodec
)
=>
matchCodecs
(
capCodec
,
codec
,
{
strict
:
true
}));
if
(
!
matchedCapCodec
)
if
(
!
mimeTypeMatch
)
{
{
continue
;
throw
new
TypeError
(
'invalid codec.mimeType'
)
;
}
}
codec
.
rtcpFeedback
=
matchedCapCodec
.
rtcpFeedback
!
// Just override kind with media component of mimeType.
.
filter
((
fb
)
=>
(
codec
.
kind
=
mimeTypeMatch
[
1
].
toLowerCase
()
as
MediaKind
;
(
enableRtx
||
fb
.
type
!==
'nack'
||
fb
.
parameter
)
));
consumerParams
.
codecs
.
push
(
codec
);
// preferredPayloadType is optional.
if
(
codec
.
preferredPayloadType
&&
typeof
codec
.
preferredPayloadType
!==
'number'
)
{
throw
new
TypeError
(
'invalid codec.preferredPayloadType'
);
}
}
//
Must sanitize the list of matched codecs by removing useless RTX codecs
.
//
clockRate is mandatory
.
for
(
let
idx
=
consumerParams
.
codecs
.
length
-
1
;
idx
>=
0
;
--
idx
)
if
(
typeof
codec
.
clockRate
!==
'number'
)
{
{
const
codec
=
consumerParams
.
codecs
[
idx
];
throw
new
TypeError
(
'missing codec.clockRate'
);
}
if
(
isRtxCodec
(
codec
))
// channels is optional. If unset, set it to 1 (just if audio).
if
(
codec
.
kind
===
'audio'
)
{
{
// Search for the associated media codec.
if
(
typeof
codec
.
channels
!==
'number'
)
const
associatedMediaCodec
=
consumerParams
.
codecs
.
find
((
mediaCodec
)
=>
mediaCodec
.
payloadType
===
codec
.
parameters
.
apt
);
if
(
associatedMediaCodec
)
{
{
rtxSupported
=
true
;
codec
.
channels
=
1
;
}
}
}
else
else
{
{
consumerParams
.
codecs
.
splice
(
idx
,
1
);
delete
codec
.
channels
;
}
}
}
}
//
Ensure there is at least one media codec
.
//
parameters is optional. If unset, set it to an empty object
.
if
(
consumerParams
.
codecs
.
length
===
0
||
isRtxCodec
(
consumerParams
.
codecs
[
0
])
)
if
(
!
codec
.
parameters
||
typeof
codec
.
parameters
!==
'object'
)
{
{
throw
new
UnsupportedError
(
'no compatible media codecs'
)
;
codec
.
parameters
=
{}
;
}
}
consumerParams
.
headerExtensions
=
consumableRtpParameters
.
headerExtensions
!
for
(
const
key
of
Object
.
keys
(
codec
.
parameters
))
.
filter
((
ext
)
=>
(
remoteRtpCapabilities
.
headerExtensions
!
.
some
((
capExt
)
=>
(
capExt
.
preferredId
===
ext
.
id
&&
capExt
.
uri
===
ext
.
uri
))
));
// 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'
))
)
{
{
for
(
const
codec
of
consumerParams
.
codecs
)
let
value
=
codec
.
parameters
[
key
];
if
(
value
===
undefined
)
{
{
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
codec
.
parameters
[
key
]
=
''
;
.
filter
((
fb
)
=>
fb
.
type
!==
'goog-remb'
);
value
=
''
;
}
}
}
else
if
(
consumerParams
.
headerExtensions
.
some
((
ext
)
=>
(
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
ext
.
uri
===
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'
))
)
{
for
(
const
codec
of
consumerParams
.
codecs
)
{
{
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
throw
new
TypeError
(
.
filter
((
fb
)
=>
fb
.
type
!==
'transport-cc'
);
`invalid codec parameter [key:
${
key
}
s, value:
${
value
}
]`
);
}
}
}
else
// Specific parameters validation.
if
(
key
===
'apt'
)
{
{
for
(
const
codec
of
consumerParams
.
codecs
)
if
(
typeof
value
!==
'number'
)
{
{
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
throw
new
TypeError
(
'invalid codec apt parameter'
);
.
filter
((
fb
)
=>
(
}
fb
.
type
!==
'transport-cc'
&&
fb
.
type
!==
'goog-remb'
));
}
}
}
}
if
(
!
pipe
)
// rtcpFeedback is optional. If unset, set it to an empty array.
{
if
(
!
codec
.
rtcpFeedback
||
!
Array
.
isArray
(
codec
.
rtcpFeedback
))
const
consumerEncoding
:
RtpEncodingParameters
=
{
{
ssrc
:
utils
.
generateRandomNumber
()
codec
.
rtcpFeedback
=
[];
};
}
if
(
rtxSupported
)
for
(
const
fb
of
codec
.
rtcpFeedback
)
{
{
consumerEncoding
.
rtx
=
{
ssrc
:
consumerEncoding
.
ssrc
!
+
1
}
;
validateRtcpFeedback
(
fb
)
;
}
}
}
// If any of the consumableRtpParameters.encodings has scalabilityMode,
/**
// process it (assume all encodings have the same value).
* Validates RtcpFeedback. It may modify given data by adding missing
const
encodingWithScalabilityMode
=
* fields with default values.
consumableRtpParameters
.
encodings
!
.
find
((
encoding
)
=>
encoding
.
scalabilityMode
);
* It throws if invalid.
*/
let
scalabilityMode
=
encodingWithScalabilityMode
function
validateRtcpFeedback
(
fb
:
RtcpFeedback
):
void
?
encodingWithScalabilityMode
.
scalabilityMode
{
:
undefined
;
if
(
typeof
fb
!==
'object'
)
// If there is simulast, mangle spatial layers in scalabilityMode.
if
(
consumableRtpParameters
.
encodings
!
.
length
>
1
)
{
{
const
{
temporalLayers
}
=
parseScalabilityMode
(
scalabilityMode
);
throw
new
TypeError
(
'fb is not an object'
);
}
scalabilityMode
=
`L
${
consumableRtpParameters
.
encodings
!
.
length
}
T
${
temporalLayers
}
`
;
// type is mandatory.
if
(
!
fb
.
type
||
typeof
fb
.
type
!==
'string'
)
{
throw
new
TypeError
(
'missing fb.type'
);
}
}
if
(
scalabilityMode
)
// parameter is optional. If unset set it to an empty string.
if
(
!
fb
.
parameter
||
typeof
fb
.
parameter
!==
'string'
)
{
{
consumerEncoding
.
scalabilityMode
=
scalabilityMode
;
fb
.
parameter
=
''
;
}
}
}
// Use the maximum maxBitrate in any encoding and honor it in the Consumer's
/**
// encoding.
* Validates RtpHeaderExtension. It may modify given data by adding missing
const
maxEncodingMaxBitrate
=
* fields with default values.
consumableRtpParameters
.
encodings
!
.
reduce
((
maxBitrate
,
encoding
)
=>
(
* It throws if invalid.
encoding
.
maxBitrate
&&
encoding
.
maxBitrate
>
maxBitrate
*/
?
encoding
.
maxBitrate
function
validateRtpHeaderExtension
(
ext
:
RtpHeaderExtension
):
void
:
maxBitrate
{
),
0
);
if
(
maxEncodingMaxBitrate
)
if
(
typeof
ext
!==
'object'
)
{
{
consumerEncoding
.
maxBitrate
=
maxEncodingMaxBitrate
;
throw
new
TypeError
(
'ext is not an object'
)
;
}
}
// Set a single encoding for the Consumer.
if
(
ext
.
kind
!==
'audio'
&&
ext
.
kind
!==
'video'
)
consumerParams
.
encodings
!
.
push
(
consumerEncoding
);
}
else
{
{
const
consumableEncodings
=
throw
new
TypeError
(
'invalid ext.kind'
);
(
utils
.
clone
(
consumableRtpParameters
.
encodings
)
??
[])
as
RtpEncodingParameters
[];
}
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
for
(
let
i
=
0
;
i
<
consumableEncodings
.
length
;
++
i
)
// uri is mandatory.
if
(
!
ext
.
uri
||
typeof
ext
.
uri
!==
'string'
)
{
{
const
encoding
=
consumableEncodings
[
i
];
throw
new
TypeError
(
'missing ext.uri'
);
}
encoding
.
ssrc
=
baseSsrc
+
i
;
// preferredId is mandatory.
if
(
typeof
ext
.
preferredId
!==
'number'
)
{
throw
new
TypeError
(
'missing ext.preferredId'
);
}
if
(
rtxSupported
)
// preferredEncrypt is optional. If unset set it to false.
if
(
ext
.
preferredEncrypt
&&
typeof
ext
.
preferredEncrypt
!==
'boolean'
)
{
{
encoding
.
rtx
=
{
ssrc
:
baseRtxSsrc
+
i
}
;
throw
new
TypeError
(
'invalid ext.preferredEncrypt'
)
;
}
}
else
else
if
(
!
ext
.
preferredEncrypt
)
{
{
delete
encoding
.
rtx
;
ext
.
preferredEncrypt
=
false
;
}
}
consumerParams
.
encodings
!
.
push
(
encoding
);
// 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'
;
}
}
return
consumerParams
;
}
}
/**
/**
* Generate RTP parameters for a pipe Consumer.
* Validates RtpCodecParameters. It may modify given data by adding missing
*
* fields with default values.
* It keeps all original consumable encodings and removes support for BWE. If
* It throws if invalid.
* enableRtx is false, it also removes RTX and NACK support.
*/
*/
export
function
getPipeConsumerRtpParameters
(
function
validateRtpCodecParameters
(
codec
:
RtpCodecParameters
):
void
{
consumableRtpParameters
,
enableRtx
}:
{
consumableRtpParameters
:
RtpParameters
;
enableRtx
:
boolean
;
}
):
RtpParameters
{
{
const
consumerParams
:
RtpParameters
=
const
MimeTypeRegex
=
new
RegExp
(
'^(audio|video)/(.+)'
,
'i'
);
{
codecs
:
[],
headerExtensions
:
[],
encodings
:
[],
rtcp
:
consumableRtpParameters
.
rtcp
};
const
consumableCodecs
=
(
utils
.
clone
(
consumableRtpParameters
.
codecs
)
??
[])
as
RtpCodecParameters
[];
for
(
const
codec
of
consumableCodecs
)
if
(
typeof
codec
!==
'object'
)
{
{
if
(
!
enableRtx
&&
isRtxCodec
(
codec
))
throw
new
TypeError
(
'codec is not an object'
);
}
// mimeType is mandatory.
if
(
!
codec
.
mimeType
||
typeof
codec
.
mimeType
!==
'string'
)
{
{
continue
;
throw
new
TypeError
(
'missing codec.mimeType'
)
;
}
}
codec
.
rtcpFeedback
=
codec
.
rtcpFeedback
!
const
mimeTypeMatch
=
MimeTypeRegex
.
exec
(
codec
.
mimeType
);
.
filter
((
fb
)
=>
(
(
fb
.
type
===
'nack'
&&
fb
.
parameter
===
'pli'
)
||
(
fb
.
type
===
'ccm'
&&
fb
.
parameter
===
'fir'
)
||
(
enableRtx
&&
fb
.
type
===
'nack'
&&
!
fb
.
parameter
)
));
consumerParams
.
codecs
.
push
(
codec
);
if
(
!
mimeTypeMatch
)
{
throw
new
TypeError
(
'invalid codec.mimeType'
);
}
}
// Reduce RTP extensions by disabling transport MID and BWE related ones.
// payloadType is mandatory.
consumerParams
.
headerExtensions
=
consumableRtpParameters
.
headerExtensions
!
if
(
typeof
codec
.
payloadType
!==
'number'
)
.
filter
((
ext
)
=>
(
{
ext
.
uri
!==
'urn:ietf:params:rtp-hdrext:sdes:mid'
&&
throw
new
TypeError
(
'missing codec.payloadType'
);
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'
));
const
consumableEncodings
=
(
utils
.
clone
(
consumableRtpParameters
.
encodings
)
??
[])
as
RtpEncodingParameters
[];
const
baseSsrc
=
utils
.
generateRandomNumber
();
const
baseRtxSsrc
=
utils
.
generateRandomNumber
();
for
(
let
i
=
0
;
i
<
consumableEncodings
.
length
;
++
i
)
// clockRate is mandatory.
if
(
typeof
codec
.
clockRate
!==
'number'
)
{
{
const
encoding
=
consumableEncodings
[
i
];
throw
new
TypeError
(
'missing codec.clockRate'
);
}
encoding
.
ssrc
=
baseSsrc
+
i
;
const
kind
=
mimeTypeMatch
[
1
].
toLowerCase
()
as
MediaKind
;
if
(
enableRtx
)
// channels is optional. If unset, set it to 1 (just if audio).
if
(
kind
===
'audio'
)
{
{
encoding
.
rtx
=
{
ssrc
:
baseRtxSsrc
+
i
};
if
(
typeof
codec
.
channels
!==
'number'
)
{
codec
.
channels
=
1
;
}
}
}
else
else
{
{
delete
encoding
.
rtx
;
delete
codec
.
channels
;
}
}
consumerParams
.
encodings
!
.
push
(
encoding
);
// parameters is optional. If unset, set it to an empty object.
if
(
!
codec
.
parameters
||
typeof
codec
.
parameters
!==
'object'
)
{
codec
.
parameters
=
{};
}
}
return
consumerParams
;
for
(
const
key
of
Object
.
keys
(
codec
.
parameters
))
}
{
let
value
=
codec
.
parameters
[
key
];
function
isRtxCodec
(
codec
:
RtpCodecCapability
|
RtpCodecParameters
):
boolean
{
return
/.+
\/
rtx$/i
.
test
(
codec
.
mimeType
);
}
function
matchCodecs
(
aCodec
:
RtpCodecCapability
|
RtpCodecParameters
,
bCodec
:
RtpCodecCapability
|
RtpCodecParameters
,
{
strict
=
false
,
modify
=
false
}
=
{}
):
boolean
{
const
aMimeType
=
aCodec
.
mimeType
.
toLowerCase
();
const
bMimeType
=
bCodec
.
mimeType
.
toLowerCase
();
if
(
aMimeType
!==
bMimeType
)
if
(
value
===
undefined
)
{
{
return
false
;
codec
.
parameters
[
key
]
=
''
;
value
=
''
;
}
}
if
(
aCodec
.
clockRate
!==
bCodec
.
clockRate
)
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
{
{
return
false
;
throw
new
TypeError
(
`invalid codec parameter [key:
${
key
}
s, value:
${
value
}
]`
);
}
}
if
(
aCodec
.
channels
!==
bCodec
.
channels
)
// Specific parameters validation.
if
(
key
===
'apt'
)
{
{
return
false
;
if
(
typeof
value
!==
'number'
)
{
throw
new
TypeError
(
'invalid codec apt parameter'
);
}
}
}
}
// Per codec special checks.
// rtcpFeedback is optional. If unset, set it to an empty array.
switch
(
aMimeType
)
if
(
!
codec
.
rtcpFeedback
||
!
Array
.
isArray
(
codec
.
rtcpFeedback
))
{
case
'audio/multiopus'
:
{
{
const
aNumStreams
=
aCodec
.
parameters
[
'num_streams'
];
codec
.
rtcpFeedback
=
[
];
const
bNumStreams
=
bCodec
.
parameters
[
'num_streams'
];
}
if
(
aNumStreams
!==
bNumStreams
)
for
(
const
fb
of
codec
.
rtcpFeedback
)
{
{
return
false
;
validateRtcpFeedback
(
fb
)
;
}
}
}
const
aCoupledStreams
=
aCodec
.
parameters
[
'coupled_streams'
];
/**
const
bCoupledStreams
=
bCodec
.
parameters
[
'coupled_streams'
];
* Validates RtpHeaderExtensionParameteters. It may modify given data by adding
* missing fields with default values. It throws if invalid.
*/
function
validateRtpHeaderExtensionParameters
(
ext
:
RtpHeaderExtensionParameters
):
void
{
if
(
aCoupledStreams
!==
bCoupledStreams
)
if
(
typeof
ext
!==
'object'
)
{
{
return
false
;
throw
new
TypeError
(
'ext is not an object'
)
;
}
}
break
;
// uri is mandatory.
if
(
!
ext
.
uri
||
typeof
ext
.
uri
!==
'string'
)
{
throw
new
TypeError
(
'missing ext.uri'
);
}
}
case
'video/h264'
:
// id is mandatory.
case
'video/h264-svc'
:
if
(
typeof
ext
.
id
!==
'number'
)
{
if
(
strict
)
{
{
const
aPacketizationMode
=
aCodec
.
parameters
[
'packetization-mode'
]
||
0
;
throw
new
TypeError
(
'missing ext.id'
)
;
const
bPacketizationMode
=
bCodec
.
parameters
[
'packetization-mode'
]
||
0
;
}
if
(
aPacketizationMode
!==
bPacketizationMode
)
// encrypt is optional. If unset set it to false.
if
(
ext
.
encrypt
&&
typeof
ext
.
encrypt
!==
'boolean'
)
{
{
return
false
;
throw
new
TypeError
(
'invalid ext.encrypt'
);
}
else
if
(
!
ext
.
encrypt
)
{
ext
.
encrypt
=
false
;
}
}
if
(
!
h264
.
isSameProfile
(
aCodec
.
parameters
,
bCodec
.
parameters
))
// parameters is optional. If unset, set it to an empty object.
if
(
!
ext
.
parameters
||
typeof
ext
.
parameters
!==
'object'
)
{
{
return
false
;
ext
.
parameters
=
{}
;
}
}
let
selectedProfileLevelId
;
for
(
const
key
of
Object
.
keys
(
ext
.
parameters
))
{
let
value
=
ext
.
parameters
[
key
];
try
if
(
value
===
undefined
)
{
{
selectedProfileLevelId
=
ext
.
parameters
[
key
]
=
''
;
h264
.
generateProfileLevelIdStringForAnswer
(
value
=
''
;
aCodec
.
parameters
,
bCodec
.
parameters
);
}
}
catch
(
error
)
if
(
typeof
value
!==
'string'
&&
typeof
value
!==
'number'
)
{
{
return
false
;
throw
new
TypeError
(
'invalid header extension parameter'
);
}
}
}
}
if
(
modify
)
/**
{
* Validates RtpEncodingParameters. It may modify given data by adding missing
if
(
selectedProfileLevelId
)
* fields with default values.
* It throws if invalid.
*/
function
validateRtpEncodingParameters
(
encoding
:
RtpEncodingParameters
):
void
{
if
(
typeof
encoding
!==
'object'
)
{
{
aCodec
.
parameters
[
'profile-level-id'
]
=
selectedProfileLevelId
;
throw
new
TypeError
(
'encoding is not an object'
)
;
}
}
else
// ssrc is optional.
if
(
encoding
.
ssrc
&&
typeof
encoding
.
ssrc
!==
'number'
)
{
{
delete
aCodec
.
parameters
[
'profile-level-id'
];
throw
new
TypeError
(
'invalid encoding.ssrc'
);
}
}
}
}
break
;
// rid is optional.
if
(
encoding
.
rid
&&
typeof
encoding
.
rid
!==
'string'
)
{
throw
new
TypeError
(
'invalid encoding.rid'
);
}
}
case
'video/vp9'
:
// rtx is optional.
if
(
encoding
.
rtx
&&
typeof
encoding
.
rtx
!==
'object'
)
{
{
if
(
strict
)
throw
new
TypeError
(
'invalid encoding.rtx'
);
}
else
if
(
encoding
.
rtx
)
{
{
const
aProfileId
=
aCodec
.
parameters
[
'profile-id'
]
||
0
;
// RTX ssrc is mandatory if rtx is present.
const
bProfileId
=
bCodec
.
parameters
[
'profile-id'
]
||
0
;
if
(
typeof
encoding
.
rtx
.
ssrc
!==
'number'
)
if
(
aProfileId
!==
bProfileId
)
{
{
return
false
;
throw
new
TypeError
(
'missing encoding.rtx.ssrc'
)
;
}
}
}
}
break
;
// dtx is optional. If unset set it to false.
}
if
(
!
encoding
.
dtx
||
typeof
encoding
.
dtx
!==
'boolean'
)
{
encoding
.
dtx
=
false
;
}
}
return
true
;
// scalabilityMode is optional.
if
(
encoding
.
scalabilityMode
&&
typeof
encoding
.
scalabilityMode
!==
'string'
)
{
throw
new
TypeError
(
'invalid encoding.scalabilityMode'
);
}
}
}
export
function
serializeRtpMapping
(
/**
builder
:
flatbuffers
.
Builder
,
rtpMapping
:
RtpMapping
* Validates RtcpParameters. It may modify given data by adding missing
):
number
* fields with default values.
* It throws if invalid.
*/
function
validateRtcpParameters
(
rtcp
:
RtcpParameters
):
void
{
{
const
codecs
:
number
[]
=
[];
if
(
typeof
rtcp
!==
'object'
)
for
(
const
codec
of
rtpMapping
.
codecs
)
{
{
codecs
.
push
(
throw
new
TypeError
(
'rtcp is not an object'
);
FbsRtpParameters
.
CodecMapping
.
createCodecMapping
(
builder
,
codec
.
payloadType
,
codec
.
mappedPayloadType
)
);
}
}
const
codecsOffset
=
FbsRtpParameters
.
RtpMapping
.
createCodecsVector
(
builder
,
codecs
);
const
encodings
:
number
[]
=
[];
for
(
const
encoding
of
rtpMapping
.
encodings
)
// cname is optional.
if
(
rtcp
.
cname
&&
typeof
rtcp
.
cname
!==
'string'
)
{
{
encodings
.
push
(
throw
new
TypeError
(
'invalid rtcp.cname'
);
FbsRtpParameters
.
EncodingMapping
.
createEncodingMapping
(
builder
,
builder
.
createString
(
encoding
.
rid
),
encoding
.
ssrc
??
null
,
builder
.
createString
(
encoding
.
scalabilityMode
),
encoding
.
mappedSsrc
)
);
}
}
const
encodingsOffset
=
FbsRtpParameters
.
RtpMapping
.
createEncodingsVector
(
builder
,
encodings
);
return
FbsRtpParameters
.
RtpMapping
.
createRtpMapping
(
// reducedSize is optional. If unset set it to true.
builder
,
codecsOffset
,
encodingsOffset
);
if
(
!
rtcp
.
reducedSize
||
typeof
rtcp
.
reducedSize
!==
'boolean'
)
{
rtcp
.
reducedSize
=
true
;
}
}
}
node/src/tests/test-ortc.ts
浏览文件 @
90fff361
...
@@ -604,6 +604,7 @@ test('getProducerRtpParametersMapping() with incompatible params throws Unsuppor
...
@@ -604,6 +604,7 @@ test('getProducerRtpParametersMapping() with incompatible params throws Unsuppor
};
};
expect
(
expect
(
()
=>
ortc
.
getProducerRtpParametersMapping
(
rtpParameters
,
routerRtpCapabilities
))
()
=>
ortc
.
getProducerRtpParametersMapping
(
.
toThrow
(
UnsupportedError
);
rtpParameters
,
routerRtpCapabilities
)).
toThrow
(
UnsupportedError
);
});
});
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论