提交 e51c3af8 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

ortc.ts: Add functions to validate RTP/SCTP parameters

上级 7971dcd0
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../src/Transport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,WAAW,iBAAiB;IAEjC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,oBAAY,iBAAiB,GAAG,KAAK,GAAG,KAAK,CAAC;AAE9C,MAAM,WAAW,cAAc;IAE9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,iBAAiB,CAAC;CAC5B;AAED;;GAEG;AACH,oBAAY,uBAAuB,GAAG,WAAW,GAAG,KAAK,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IAEvC;;OAEG;IACH,IAAI,EAAE,uBAAuB,CAAC;IAE9B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,IAAI,GAAG,KAAK,CAAC;IAExB;;OAEG;IACH,IAAI,EAAE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CACZ,EACC,EAAc,EACd,IAAI,EACJ,aAAa,EACb,MAAc,EACd,OAAY,EACZ,EAAE,eAAe,GAChB,OAAO,CAAC,QAAQ,CAAC;IA8FpB;;;;OAIG;IACG,OAAO,CACZ,EACC,UAAU,EACV,eAAe,EACf,MAAc,EACd,eAAe,EACf,OAAY,EACZ,EAAE,eAAe,GAChB,OAAO,CAAC,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
......@@ -234,13 +234,16 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
throw new TypeError(`a Producer with same id "${id}" already exists`);
else if (!['audio', 'video'].includes(kind))
throw new TypeError(`invalid kind "${kind}"`);
else if (typeof rtpParameters !== 'object')
throw new TypeError('missing rtpParameters');
else if (appData && typeof appData !== 'object')
throw new TypeError('if given, appData must be an object');
// If missing encodings, add one.
if (!rtpParameters.encodings || !Array.isArray(rtpParameters.encodings))
// This may throw.
ortc.validateRtpParameters(rtpParameters);
// If missing or empty encodings, add one.
if (!rtpParameters.encodings ||
!Array.isArray(rtpParameters.encodings) ||
rtpParameters.encodings.length === 0) {
rtpParameters.encodings = [{}];
}
// Don't do this in PipeTransports since there we must keep CNAME value in
// each Producer.
if (this.constructor.name !== 'PipeTransport') {
......@@ -300,10 +303,10 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
logger.debug('consume()');
if (!producerId || typeof producerId !== 'string')
throw new TypeError('missing producerId');
else if (typeof rtpCapabilities !== 'object')
throw new TypeError('missing rtpCapabilities');
else if (appData && typeof appData !== 'object')
throw new TypeError('if given, appData must be an object');
// This may throw.
ortc.validateRtpCapabilities(rtpCapabilities);
const producer = this._getProducerById(producerId);
if (!producer)
throw Error(`Producer with id "${producerId}" not found`);
......@@ -346,10 +349,10 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
logger.debug('produceData()');
if (id && this._dataProducers.has(id))
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')
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 reqData = { sctpStreamParameters, label, protocol };
const data = yield this._channel.request('transport.produceData', internal, reqData);
......
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 {
codecs: {
payloadType: number;
......@@ -11,11 +12,89 @@ interface RtpMapping {
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
* mediasoup supported RTP capabilities.
*/
export declare function generateRouterRtpCapabilities(mediaCodecs?: RtpCodecCapability[]): RTCRtpCapabilities;
export declare function generateRouterRtpCapabilities(mediaCodecs?: RtpCodecCapability[]): RtpCapabilities;
/**
* Get a mapping of codec payloads and encodings of the given Producer RTP
* parameters as values expected by the Router.
......
{"version":3,"file":"ortc.d.ts","sourceRoot":"","sources":["../src/ortc.ts"],"names":[],"mappings":"AAKA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;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI,CAYvE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAoBnE;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAwC/E;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC5C,WAAW,GAAE,kBAAkB,EAAO,GACpC,eAAe,CAsGjB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,eAAe,GACnB,UAAU,CA+FZ;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,UAAU,GACpB,aAAa,CA0Gf;AAED;;GAEG;AACH,wBAAgB,UAAU,CACzB,gBAAgB,EAAE,aAAa,EAC/B,IAAI,EAAE,eAAe,GACnB,OAAO,CAuBT;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,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
......@@ -17,22 +17,393 @@ const DynamicPayloadTypes = [
111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
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
* mediasoup supported RTP capabilities.
*/
function generateRouterRtpCapabilities(mediaCodecs = []) {
// Normalize supported RTP capabilities.
validateRtpCapabilities(supportedRtpCapabilities_1.supportedRtpCapabilities);
if (!Array.isArray(mediaCodecs))
throw new TypeError('mediaCodecs must be an Array');
const dynamicPayloadTypes = utils.clone(DynamicPayloadTypes);
const supportedCodecs = supportedRtpCapabilities_1.supportedRtpCapabilities.codecs;
const caps = {
codecs: [],
headerExtensions: supportedRtpCapabilities_1.supportedRtpCapabilities.headerExtensions,
fecMechanisms: supportedRtpCapabilities_1.supportedRtpCapabilities.fecMechanisms
headerExtensions: supportedRtpCapabilities_1.supportedRtpCapabilities.headerExtensions
};
for (const mediaCodec of mediaCodecs) {
assertCodecCapability(mediaCodec);
// This may throw.
validateRtpCodecCapability(mediaCodec);
const matchedSupportedCodec = supportedCodecs
.find((supportedCodec) => (matchCodecs(mediaCodec, supportedCodec, { strict: false })));
if (!matchedSupportedCodec) {
......@@ -62,16 +433,9 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
}
// Ensure there is not duplicated preferredPayloadType values.
if (caps.codecs.some((c) => c.preferredPayloadType === codec.preferredPayloadType))
throw new Error('duplicated codec.preferredPayloadType');
// Normalize channels.
if (codec.kind !== 'audio')
delete codec.channels;
else if (!codec.channels)
codec.channels = 1;
throw new TypeError('duplicated codec.preferredPayloadType');
// Merge the media codec parameters.
codec.parameters = Object.assign(Object.assign({}, codec.parameters), mediaCodec.parameters);
// Make rtcpFeedback an array.
codec.rtcpFeedback = codec.rtcpFeedback || [];
// Append to the codec list.
caps.codecs.push(codec);
// Add a RTX video codec if video.
......@@ -85,10 +449,11 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
mimeType: `${codec.kind}/rtx`,
preferredPayloadType: pt,
clockRate: codec.clockRate,
rtcpFeedback: [],
channels: 1,
parameters: {
apt: codec.preferredPayloadType
}
},
rtcpFeedback: []
};
// Append to the codec list.
caps.codecs.push(rtxCodec);
......@@ -110,9 +475,8 @@ function getProducerRtpParametersMapping(params, caps) {
};
// Match parameters media codecs to capabilities media codecs.
const codecToCapCodec = new Map();
for (const codec of params.codecs || []) {
assertCodecParameters(codec);
if (/.+\/rtx$/i.test(codec.mimeType))
for (const codec of params.codecs) {
if (isRtxCodec(codec))
continue;
// Search for the same media codec in capabilities.
const matchedCapCodec = caps.codecs
......@@ -123,11 +487,9 @@ function getProducerRtpParametersMapping(params, caps) {
codecToCapCodec.set(codec, matchedCapCodec);
}
// Match parameters RTX codecs to capabilities RTX codecs.
for (const codec of params.codecs || []) {
if (!/.+\/rtx$/i.test(codec.mimeType))
for (const codec of params.codecs) {
if (!isRtxCodec(codec))
continue;
else if (typeof codec.parameters !== 'object')
throw TypeError('missing parameters in RTX codec');
// Search for the associated media codec.
const associatedMediaCodec = params.codecs
.find((mediaCodec) => mediaCodec.payloadType === codec.parameters.apt);
......@@ -137,7 +499,7 @@ function getProducerRtpParametersMapping(params, caps) {
const capMediaCodec = codecToCapCodec.get(associatedMediaCodec);
// Ensure that the capabilities media codec has a RTX codec.
const associatedCapRtxCodec = caps.codecs
.find((capCodec) => (/.+\/rtx$/i.test(capCodec.mimeType) &&
.find((capCodec) => (isRtxCodec(capCodec) &&
capCodec.parameters.apt === capMediaCodec.preferredPayloadType));
if (!associatedCapRtxCodec) {
throw new errors_1.UnsupportedError(`no RTX codec for capability codec PT ${capMediaCodec.preferredPayloadType}`);
......@@ -153,7 +515,7 @@ function getProducerRtpParametersMapping(params, caps) {
}
// Generate encodings mapping.
let mappedSsrc = utils.generateRandomNumber();
for (const encoding of (params.encodings || [])) {
for (const encoding of params.encodings) {
const mappedEncoding = {};
mappedEncoding.mappedSsrc = mappedSsrc++;
if (encoding.rid)
......@@ -178,9 +540,8 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
encodings: [],
rtcp: {}
};
for (const codec of params.codecs || []) {
assertCodecParameters(codec);
if (/.+\/rtx$/i.test(codec.mimeType))
for (const codec of params.codecs) {
if (isRtxCodec(codec))
continue;
const consumableCodecPt = rtpMapping.codecs
.find((entry) => entry.payloadType === codec.payloadType)
......@@ -189,29 +550,25 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
.find((capCodec) => capCodec.preferredPayloadType === consumableCodecPt);
const consumableCodec = {
mimeType: matchedCapCodec.mimeType,
clockRate: matchedCapCodec.clockRate,
payloadType: matchedCapCodec.preferredPayloadType,
clockRate: matchedCapCodec.clockRate,
channels: matchedCapCodec.channels,
rtcpFeedback: matchedCapCodec.rtcpFeedback,
parameters: codec.parameters // Keep the Producer parameters.
parameters: codec.parameters,
rtcpFeedback: matchedCapCodec.rtcpFeedback
};
if (!consumableCodec.channels)
delete consumableCodec.channels;
consumableParams.codecs.push(consumableCodec);
const consumableCapRtxCodec = caps.codecs
.find((capRtxCodec) => (/.+\/rtx$/i.test(capRtxCodec.mimeType) &&
.find((capRtxCodec) => (isRtxCodec(capRtxCodec) &&
capRtxCodec.parameters.apt === consumableCodec.payloadType));
if (consumableCapRtxCodec) {
const consumableRtxCodec = {
mimeType: consumableCapRtxCodec.mimeType,
clockRate: consumableCapRtxCodec.clockRate,
payloadType: consumableCapRtxCodec.preferredPayloadType,
channels: consumableCapRtxCodec.channels,
rtcpFeedback: consumableCapRtxCodec.rtcpFeedback,
parameters: consumableCapRtxCodec.parameters
clockRate: consumableCapRtxCodec.clockRate,
channels: 1,
parameters: consumableCapRtxCodec.parameters,
rtcpFeedback: consumableCapRtxCodec.rtcpFeedback
};
if (!consumableRtxCodec.channels)
delete consumableRtxCodec.channels;
consumableParams.codecs.push(consumableRtxCodec);
}
}
......@@ -223,7 +580,9 @@ function getConsumableRtpParameters(kind, params, caps, rtpMapping) {
}
const consumableExt = {
uri: capExt.uri,
id: capExt.preferredId
id: capExt.preferredId,
encrypt: capExt.preferredEncrypt,
parameters: {}
};
consumableParams.headerExtensions.push(consumableExt);
}
......@@ -253,10 +612,9 @@ exports.getConsumableRtpParameters = getConsumableRtpParameters;
* Check whether the given RTP capabilities can consume the given Producer.
*/
function canConsume(consumableParams, caps) {
// This may throw.
validateRtpCapabilities(caps);
const matchingCodecs = [];
for (const capCodec of caps.codecs || []) {
assertCodecCapability(capCodec);
}
for (const codec of consumableParams.codecs) {
const matchedCapCodec = caps.codecs
.find((capCodec) => matchCodecs(capCodec, codec, { strict: true }));
......@@ -265,10 +623,8 @@ function canConsume(consumableParams, caps) {
matchingCodecs.push(codec);
}
// Ensure there is at least one media codec.
if (matchingCodecs.length === 0 ||
/.+\/rtx$/i.test(matchingCodecs[0].mimeType)) {
if (matchingCodecs.length === 0 || isRtxCodec(matchingCodecs[0]))
return false;
}
return true;
}
exports.canConsume = canConsume;
......@@ -286,45 +642,44 @@ function getConsumerRtpParameters(consumableParams, caps) {
encodings: [],
rtcp: consumableParams.rtcp
};
for (const capCodec of caps.codecs || []) {
assertCodecCapability(capCodec);
for (const capCodec of caps.codecs) {
validateRtpCodecCapability(capCodec);
}
const consumableCodecs = utils.clone(consumableParams.codecs || []);
const consumableCodecs = utils.clone(consumableParams.codecs);
let rtxSupported = false;
for (const codec of consumableCodecs) {
const matchedCapCodec = caps.codecs
.find((capCodec) => matchCodecs(capCodec, codec, { strict: true }));
if (!matchedCapCodec)
continue;
codec.rtcpFeedback = matchedCapCodec.rtcpFeedback || [];
codec.rtcpFeedback = matchedCapCodec.rtcpFeedback;
consumerParams.codecs.push(codec);
if (!rtxSupported && /.+\/rtx$/i.test(codec.mimeType))
if (!rtxSupported && isRtxCodec(codec))
rtxSupported = true;
}
// Ensure there is at least one media codec.
if (consumerParams.codecs.length === 0 ||
/.+\/rtx$/i.test(consumerParams.codecs[0].mimeType)) {
if (consumerParams.codecs.length === 0 || isRtxCodec(consumerParams.codecs[0])) {
throw new errors_1.UnsupportedError('no compatible media codecs');
}
consumerParams.headerExtensions = consumableParams.headerExtensions
.filter((ext) => ((caps.headerExtensions || [])
.filter((ext) => ((caps.headerExtensions)
.some((capExt) => capExt.preferredId === ext.id)));
// 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) {
codec.rtcpFeedback = (codec.rtcpFeedback || [])
codec.rtcpFeedback = (codec.rtcpFeedback)
.filter((fb) => fb.type !== 'goog-remb');
}
}
else if (consumerParams.headerExtensions.some((ext) => (ext.uri === 'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time'))) {
for (const codec of consumerParams.codecs) {
codec.rtcpFeedback = (codec.rtcpFeedback || [])
codec.rtcpFeedback = (codec.rtcpFeedback)
.filter((fb) => fb.type !== 'transport-cc');
}
}
else {
for (const codec of consumerParams.codecs) {
codec.rtcpFeedback = (codec.rtcpFeedback || [])
codec.rtcpFeedback = (codec.rtcpFeedback)
.filter((fb) => (fb.type !== 'transport-cc' &&
fb.type !== 'goog-remb'));
}
......@@ -367,10 +722,11 @@ function getPipeConsumerRtpParameters(consumableParams) {
encodings: [],
rtcp: consumableParams.rtcp
};
const consumableCodecs = utils.clone(consumableParams.codecs || []);
const consumableCodecs = utils.clone(consumableParams.codecs);
for (const codec of consumableCodecs) {
if (/.+\/rtx$/i.test(codec.mimeType))
if (isRtxCodec(codec))
continue;
// No support for NACK, PLI, FIR and RTX in PipeTransport.
// Reduce RTCP feedbacks by removing NACK support and other features.
codec.rtcpFeedback = codec.rtcpFeedback
.filter((fb) => ((fb.type === 'nack' && fb.parameter === 'pli') ||
......@@ -381,7 +737,8 @@ function getPipeConsumerRtpParameters(consumableParams) {
consumerParams.headerExtensions = consumableParams.headerExtensions
.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'));
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) {
delete encoding.rtx;
consumerParams.encodings.push(encoding);
......@@ -389,22 +746,8 @@ function getPipeConsumerRtpParameters(consumableParams) {
return consumerParams;
}
exports.getPipeConsumerRtpParameters = getPipeConsumerRtpParameters;
function assertCodecCapability(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 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 isRtxCodec(codec) {
return /.+\/rtx$/i.test(codec.mimeType);
}
function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
const aMimeType = aCodec.mimeType.toLowerCase();
......@@ -413,18 +756,14 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
return false;
if (aCodec.clockRate !== bCodec.clockRate)
return false;
if (/^audio\/.+$/i.test(aMimeType) &&
((aCodec.channels !== undefined && aCodec.channels !== 1) ||
(bCodec.channels !== undefined && bCodec.channels !== 1)) &&
aCodec.channels !== bCodec.channels) {
if (aCodec.channels !== bCodec.channels)
return false;
}
// Per codec special checks.
switch (aMimeType) {
case 'video/h264':
{
const aPacketizationMode = (aCodec.parameters || {})['packetization-mode'] || 0;
const bPacketizationMode = (bCodec.parameters || {})['packetization-mode'] || 0;
const aPacketizationMode = aCodec.parameters['packetization-mode'] || 0;
const bPacketizationMode = bCodec.parameters['packetization-mode'] || 0;
if (aPacketizationMode !== bPacketizationMode)
return false;
// If strict matching check profile-level-id.
......@@ -440,7 +779,6 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
return false;
}
if (modify) {
aCodec.parameters = aCodec.parameters || {};
if (selectedProfileLevelId)
aCodec.parameters['profile-level-id'] = selectedProfileLevelId;
else
......@@ -453,8 +791,8 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
{
// If strict matching check profile-id.
if (strict) {
const aProfileId = (aCodec.parameters || {})['profile-id'] || 0;
const bProfileId = (bCodec.parameters || {})['profile-id'] || 0;
const aProfileId = aCodec.parameters['profile-id'] || 0;
const bProfileId = bCodec.parameters['profile-id'] || 0;
if (aProfileId !== bProfileId)
return false;
}
......
{"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"}
\ No newline at end of file
{"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
......@@ -315,7 +315,6 @@ const supportedRtpCapabilities = {
preferredEncrypt: false,
direction: 'sendrecv'
}
],
fecMechanisms: []
]
};
exports.supportedRtpCapabilities = supportedRtpCapabilities;
......@@ -397,14 +397,21 @@ export class Transport extends EnhancedEventEmitter
throw new TypeError(`a Producer with same id "${id}" already exists`);
else if (![ 'audio', 'video' ].includes(kind))
throw new TypeError(`invalid kind "${kind}"`);
else if (typeof rtpParameters !== 'object')
throw new TypeError('missing rtpParameters');
else if (appData && typeof appData !== 'object')
throw new TypeError('if given, appData must be an object');
// If missing encodings, add one.
if (!rtpParameters.encodings || !Array.isArray(rtpParameters.encodings))
// This may throw.
ortc.validateRtpParameters(rtpParameters);
// If missing or empty encodings, add one.
if (
!rtpParameters.encodings ||
!Array.isArray(rtpParameters.encodings) ||
rtpParameters.encodings.length === 0
)
{
rtpParameters.encodings = [ {} ];
}
// Don't do this in PipeTransports since there we must keep CNAME value in
// each Producer.
......@@ -495,11 +502,12 @@ export class Transport extends EnhancedEventEmitter
if (!producerId || typeof producerId !== 'string')
throw new TypeError('missing producerId');
else if (typeof rtpCapabilities !== 'object')
throw new TypeError('missing rtpCapabilities');
else if (appData && typeof appData !== 'object')
throw new TypeError('if given, appData must be an object');
// This may throw.
ortc.validateRtpCapabilities(rtpCapabilities);
const producer = this._getProducerById(producerId);
if (!producer)
......@@ -564,11 +572,12 @@ export class Transport extends EnhancedEventEmitter
if (id && this._dataProducers.has(id))
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')
throw new TypeError('if given, appData must be an object');
// This may throw.
ortc.validateSctpStreamParameters(sctpStreamParameters);
const internal = { ...this._internal, dataProducerId: id || uuidv4() };
const reqData = { sctpStreamParameters, label, protocol };
......
......@@ -4,14 +4,23 @@ import { UnsupportedError } from './errors';
import { supportedRtpCapabilities } from './supportedRtpCapabilities';
import { parse as parseScalabilityMode } from './scalabilityModes';
import {
MediaKind,
RtpCapabilities,
MediaKind,
RtpCodecCapability,
RtpHeaderExtension,
RtpParameters,
RtpCodecParameters,
RtcpFeedback,
RtpEncodingParameters
RtpEncodingParameters,
RtpHeaderExtensionParameters,
RtcpParameters
} from './RtpParameters';
import {
SctpCapabilities,
NumSctpStreams,
SctpParameters,
SctpStreamParameters
} from './SctpParameters';
interface RtpMapping
{
......@@ -37,29 +46,512 @@ const DynamicPayloadTypes =
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
* mediasoup supported RTP capabilities.
*/
export function generateRouterRtpCapabilities(
mediaCodecs: RtpCodecCapability[] = []
): RTCRtpCapabilities
): RtpCapabilities
{
// Normalize supported RTP capabilities.
validateRtpCapabilities(supportedRtpCapabilities);
if (!Array.isArray(mediaCodecs))
throw new TypeError('mediaCodecs must be an Array');
const dynamicPayloadTypes = utils.clone(DynamicPayloadTypes) as number[];
const supportedCodecs = supportedRtpCapabilities.codecs;
const caps =
const caps: RtpCapabilities =
{
codecs : [] as RtpCodecCapability[],
headerExtensions : supportedRtpCapabilities.headerExtensions,
fecMechanisms : supportedRtpCapabilities.fecMechanisms
codecs : [],
headerExtensions : supportedRtpCapabilities.headerExtensions
};
for (const mediaCodec of mediaCodecs)
{
assertCodecCapability(mediaCodec);
// This may throw.
validateRtpCodecCapability(mediaCodec);
const matchedSupportedCodec = supportedCodecs
.find((supportedCodec) => (
......@@ -105,20 +597,11 @@ export function generateRouterRtpCapabilities(
// Ensure there is not duplicated preferredPayloadType values.
if (caps.codecs.some((c) => c.preferredPayloadType === codec.preferredPayloadType))
throw new Error('duplicated codec.preferredPayloadType');
// Normalize channels.
if (codec.kind !== 'audio')
delete codec.channels;
else if (!codec.channels)
codec.channels = 1;
throw new TypeError('duplicated codec.preferredPayloadType');
// Merge the media codec parameters.
codec.parameters = { ...codec.parameters, ...mediaCodec.parameters };
// Make rtcpFeedback an array.
codec.rtcpFeedback = codec.rtcpFeedback || [];
// Append to the codec list.
caps.codecs.push(codec);
......@@ -131,17 +614,18 @@ export function generateRouterRtpCapabilities(
if (!pt)
throw new Error('cannot allocate more dynamic codec payload types');
const rtxCodec =
const rtxCodec: RtpCodecCapability =
{
kind : codec.kind,
mimeType : `${codec.kind}/rtx`,
preferredPayloadType : pt,
clockRate : codec.clockRate,
rtcpFeedback : [] as RtcpFeedback[],
channels : 1,
parameters :
{
apt : codec.preferredPayloadType
}
},
rtcpFeedback : []
};
// Append to the codec list.
......@@ -172,11 +656,9 @@ export function getProducerRtpParametersMapping(
// Match parameters media codecs to capabilities media codecs.
const codecToCapCodec: Map<RtpCodecParameters, RtpCodecCapability> = new Map();
for (const codec of params.codecs || [])
for (const codec of params.codecs)
{
assertCodecParameters(codec);
if (/.+\/rtx$/i.test(codec.mimeType))
if (isRtxCodec(codec))
continue;
// Search for the same media codec in capabilities.
......@@ -195,12 +677,10 @@ export function getProducerRtpParametersMapping(
}
// 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;
else if (typeof codec.parameters !== 'object')
throw TypeError('missing parameters in RTX codec');
// Search for the associated media codec.
const associatedMediaCodec = params.codecs
......@@ -217,7 +697,7 @@ export function getProducerRtpParametersMapping(
// Ensure that the capabilities media codec has a RTX codec.
const associatedCapRtxCodec = caps.codecs
.find((capCodec) => (
/.+\/rtx$/i.test(capCodec.mimeType) &&
isRtxCodec(capCodec) &&
capCodec.parameters.apt === capMediaCodec.preferredPayloadType
));
......@@ -243,7 +723,7 @@ export function getProducerRtpParametersMapping(
// Generate encodings mapping.
let mappedSsrc = utils.generateRandomNumber();
for (const encoding of (params.encodings || []))
for (const encoding of params.encodings)
{
const mappedEncoding: any = {};
......@@ -281,11 +761,9 @@ export function getConsumableRtpParameters(
rtcp : {}
};
for (const codec of params.codecs || [])
for (const codec of params.codecs)
{
assertCodecParameters(codec);
if (/.+\/rtx$/i.test(codec.mimeType))
if (isRtxCodec(codec))
continue;
const consumableCodecPt = rtpMapping.codecs
......@@ -298,21 +776,18 @@ export function getConsumableRtpParameters(
const consumableCodec =
{
mimeType : matchedCapCodec.mimeType,
clockRate : matchedCapCodec.clockRate,
payloadType : matchedCapCodec.preferredPayloadType,
clockRate : matchedCapCodec.clockRate,
channels : matchedCapCodec.channels,
rtcpFeedback : matchedCapCodec.rtcpFeedback,
parameters : codec.parameters // Keep the Producer parameters.
parameters : codec.parameters, // Keep the Producer codec parameters.
rtcpFeedback : matchedCapCodec.rtcpFeedback
};
if (!consumableCodec.channels)
delete consumableCodec.channels;
consumableParams.codecs.push(consumableCodec);
const consumableCapRtxCodec = caps.codecs
.find((capRtxCodec) => (
/.+\/rtx$/i.test(capRtxCodec.mimeType) &&
isRtxCodec(capRtxCodec) &&
capRtxCodec.parameters.apt === consumableCodec.payloadType
));
......@@ -321,16 +796,13 @@ export function getConsumableRtpParameters(
const consumableRtxCodec =
{
mimeType : consumableCapRtxCodec.mimeType,
clockRate : consumableCapRtxCodec.clockRate,
payloadType : consumableCapRtxCodec.preferredPayloadType,
channels : consumableCapRtxCodec.channels,
rtcpFeedback : consumableCapRtxCodec.rtcpFeedback,
parameters : consumableCapRtxCodec.parameters
clockRate : consumableCapRtxCodec.clockRate,
channels : 1,
parameters : consumableCapRtxCodec.parameters,
rtcpFeedback : consumableCapRtxCodec.rtcpFeedback
};
if (!consumableRtxCodec.channels)
delete consumableRtxCodec.channels;
consumableParams.codecs.push(consumableRtxCodec);
}
}
......@@ -349,8 +821,10 @@ export function getConsumableRtpParameters(
const consumableExt =
{
uri : capExt.uri,
id : capExt.preferredId
uri : capExt.uri,
id : capExt.preferredId,
encrypt : capExt.preferredEncrypt,
parameters : {}
};
consumableParams.headerExtensions.push(consumableExt);
......@@ -393,12 +867,10 @@ export function canConsume(
caps: RtpCapabilities
): boolean
{
const matchingCodecs = [] as RtpCodecParameters[];
// This may throw.
validateRtpCapabilities(caps);
for (const capCodec of caps.codecs || [])
{
assertCodecCapability(capCodec);
}
const matchingCodecs: RtpCodecParameters[] = [];
for (const codec of consumableParams.codecs)
{
......@@ -412,13 +884,8 @@ export function canConsume(
}
// Ensure there is at least one media codec.
if (
matchingCodecs.length === 0 ||
/.+\/rtx$/i.test(matchingCodecs[0].mimeType)
)
{
if (matchingCodecs.length === 0 || isRtxCodec(matchingCodecs[0]))
return false;
}
return true;
}
......@@ -443,13 +910,13 @@ export function getConsumerRtpParameters(
rtcp : consumableParams.rtcp
};
for (const capCodec of caps.codecs || [])
for (const capCodec of caps.codecs)
{
assertCodecCapability(capCodec);
validateRtpCodecCapability(capCodec);
}
const consumableCodecs =
utils.clone(consumableParams.codecs || []) as RtpCodecParameters[];
utils.clone(consumableParams.codecs) as RtpCodecParameters[];
let rtxSupported = false;
......@@ -461,26 +928,23 @@ export function getConsumerRtpParameters(
if (!matchedCapCodec)
continue;
codec.rtcpFeedback = matchedCapCodec.rtcpFeedback || [];
codec.rtcpFeedback = matchedCapCodec.rtcpFeedback;
consumerParams.codecs.push(codec);
if (!rtxSupported && /.+\/rtx$/i.test(codec.mimeType))
if (!rtxSupported && isRtxCodec(codec))
rtxSupported = true;
}
// Ensure there is at least one media codec.
if (
consumerParams.codecs.length === 0 ||
/.+\/rtx$/i.test(consumerParams.codecs[0].mimeType)
)
if (consumerParams.codecs.length === 0 || isRtxCodec(consumerParams.codecs[0]))
{
throw new UnsupportedError('no compatible media codecs');
}
consumerParams.headerExtensions = consumableParams.headerExtensions
.filter((ext) => (
(caps.headerExtensions || [])
(caps.headerExtensions)
.some((capExt) => capExt.preferredId === ext.id)
));
......@@ -493,7 +957,7 @@ export function getConsumerRtpParameters(
{
for (const codec of consumerParams.codecs)
{
codec.rtcpFeedback = (codec.rtcpFeedback || [])
codec.rtcpFeedback = (codec.rtcpFeedback)
.filter((fb) => fb.type !== 'goog-remb');
}
}
......@@ -505,7 +969,7 @@ export function getConsumerRtpParameters(
{
for (const codec of consumerParams.codecs)
{
codec.rtcpFeedback = (codec.rtcpFeedback || [])
codec.rtcpFeedback = (codec.rtcpFeedback)
.filter((fb) => fb.type !== 'transport-cc');
}
}
......@@ -513,7 +977,7 @@ export function getConsumerRtpParameters(
{
for (const codec of consumerParams.codecs)
{
codec.rtcpFeedback = (codec.rtcpFeedback || [])
codec.rtcpFeedback = (codec.rtcpFeedback)
.filter((fb) => (
fb.type !== 'transport-cc' &&
fb.type !== 'goog-remb'
......@@ -577,13 +1041,14 @@ export function getPipeConsumerRtpParameters(
};
const consumableCodecs =
utils.clone(consumableParams.codecs || []) as RtpCodecParameters[];
utils.clone(consumableParams.codecs) as RtpCodecParameters[];
for (const codec of consumableCodecs)
{
if (/.+\/rtx$/i.test(codec.mimeType))
if (isRtxCodec(codec))
continue;
// No support for NACK, PLI, FIR and RTX in PipeTransport.
// Reduce RTCP feedbacks by removing NACK support and other features.
codec.rtcpFeedback = codec.rtcpFeedback
.filter((fb) => (
......@@ -602,8 +1067,9 @@ export function getPipeConsumerRtpParameters(
));
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)
{
delete encoding.rtx;
......@@ -614,30 +1080,9 @@ export function getPipeConsumerRtpParameters(
return consumerParams;
}
function assertCodecCapability(codec: RtpCodecCapability): void
function isRtxCodec(codec: RtpCodecCapability | RtpCodecParameters): boolean
{
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 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');
return /.+\/rtx$/i.test(codec.mimeType);
}
function matchCodecs(
......@@ -655,25 +1100,16 @@ function matchCodecs(
if (aCodec.clockRate !== bCodec.clockRate)
return false;
if (
/^audio\/.+$/i.test(aMimeType) &&
(
(aCodec.channels !== undefined && aCodec.channels !== 1) ||
(bCodec.channels !== undefined && bCodec.channels !== 1)
) &&
aCodec.channels !== bCodec.channels
)
{
if (aCodec.channels !== bCodec.channels)
return false;
}
// Per codec special checks.
switch (aMimeType)
{
case 'video/h264':
{
const aPacketizationMode = (aCodec.parameters || {})['packetization-mode'] || 0;
const bPacketizationMode = (bCodec.parameters || {})['packetization-mode'] || 0;
const aPacketizationMode = aCodec.parameters['packetization-mode'] || 0;
const bPacketizationMode = bCodec.parameters['packetization-mode'] || 0;
if (aPacketizationMode !== bPacketizationMode)
return false;
......@@ -698,8 +1134,6 @@ function matchCodecs(
if (modify)
{
aCodec.parameters = aCodec.parameters || {};
if (selectedProfileLevelId)
aCodec.parameters['profile-level-id'] = selectedProfileLevelId;
else
......@@ -715,8 +1149,8 @@ function matchCodecs(
// If strict matching check profile-id.
if (strict)
{
const aProfileId = (aCodec.parameters || {})['profile-id'] || 0;
const bProfileId = (bCodec.parameters || {})['profile-id'] || 0;
const aProfileId = aCodec.parameters['profile-id'] || 0;
const bProfileId = bCodec.parameters['profile-id'] || 0;
if (aProfileId !== bProfileId)
return false;
......
......@@ -340,8 +340,7 @@ const supportedRtpCapabilities: RtpCapabilities =
preferredEncrypt : false,
direction : 'sendrecv'
}
],
fecMechanisms : []
]
};
export { supportedRtpCapabilities };
......@@ -106,9 +106,9 @@ const videoProducerParameters =
},
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'goog-remb' }
{ type: 'goog-remb', parameter: '' }
]
},
{
......@@ -151,39 +151,39 @@ const consumerDeviceCapabilities =
{
mimeType : 'audio/opus',
kind : 'audio',
clockRate : 48000,
preferredPayloadType : 100,
clockRate : 48000,
channels : 2
},
{
mimeType : 'video/H264',
kind : 'video',
clockRate : 90000,
preferredPayloadType : 101,
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb' }
],
parameters :
clockRate : 90000,
parameters :
{
'level-asymmetry-allowed' : 1,
'packetization-mode' : 1,
'profile-level-id' : '4d0032'
}
},
rtcpFeedback :
[
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb', parameter: '' }
]
},
{
mimeType : 'video/rtx',
kind : 'video',
clockRate : 90000,
preferredPayloadType : 102,
rtcpFeedback : [],
clockRate : 90000,
parameters :
{
apt : 101
}
},
rtcpFeedback : []
}
],
headerExtensions :
......@@ -236,8 +236,7 @@ const consumerDeviceCapabilities =
preferredId : 12,
preferredEncrypt : false
}
],
fecMechanisms : []
]
};
beforeAll(async () =>
......@@ -293,8 +292,8 @@ test('transport.consume() succeeds', async () =>
expect(audioConsumer.rtpParameters.codecs[0]).toEqual(
{
mimeType : 'audio/opus',
clockRate : 48000,
payloadType : 100,
clockRate : 48000,
channels : 2,
parameters :
{
......@@ -363,8 +362,9 @@ test('transport.consume() succeeds', async () =>
expect(videoConsumer.rtpParameters.codecs[0]).toEqual(
{
mimeType : 'video/H264',
clockRate : 90000,
payloadType : 103,
clockRate : 90000,
channels : 1,
parameters :
{
'packetization-mode' : 1,
......@@ -372,17 +372,18 @@ test('transport.consume() succeeds', async () =>
},
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb' }
{ type: 'goog-remb', parameter: '' }
]
});
expect(videoConsumer.rtpParameters.codecs[1]).toEqual(
{
mimeType : 'video/rtx',
clockRate : 90000,
payloadType : 104,
clockRate : 90000,
channels : 1,
parameters : { apt: 103 },
rtcpFeedback : []
});
......@@ -432,8 +433,8 @@ test('transport.consume() with incompatible rtpCapabilities rejects with Unsuppo
{
kind : 'audio',
mimeType : 'audio/ISAC',
clockRate : 32000,
preferredPayloadType : 100,
clockRate : 32000,
channels : 1
}
],
......
......@@ -138,17 +138,17 @@ const consumerDeviceCapabilities =
codecs :
[
{
mimeType : 'audio/opus',
kind : 'audio',
clockRate : 48000,
mimeType : 'audio/opus',
preferredPayloadType : 100,
clockRate : 48000,
channels : 2
},
{
mimeType : 'video/VP8',
kind : 'video',
clockRate : 90000,
mimeType : 'video/VP8',
preferredPayloadType : 101,
clockRate : 90000,
rtcpFeedback :
[
{ type: 'nack' },
......@@ -158,15 +158,15 @@ const consumerDeviceCapabilities =
]
},
{
mimeType : 'video/rtx',
kind : 'video',
clockRate : 90000,
mimeType : 'video/rtx',
preferredPayloadType : 102,
rtcpFeedback : [],
clockRate : 90000,
parameters :
{
apt : 101
}
},
rtcpFeedback : []
}
],
headerExtensions :
......@@ -270,8 +270,10 @@ test('router.pipeToRouter() succeeds with audio', async () =>
expect(pipeConsumer.rtpParameters.headerExtensions).toEqual(
[
{
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
id : 10
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
id : 10,
encrypt : false,
parameters : {}
}
]);
expect(pipeConsumer.rtpParameters.encodings).toEqual(
......@@ -293,8 +295,8 @@ test('router.pipeToRouter() succeeds with audio', async () =>
[
{
mimeType : 'audio/opus',
clockRate : 48000,
payloadType : 100,
clockRate : 48000,
channels : 2,
parameters :
{
......@@ -307,8 +309,10 @@ test('router.pipeToRouter() succeeds with audio', async () =>
expect(pipeProducer.rtpParameters.headerExtensions).toEqual(
[
{
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
id : 10
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
id : 10,
encrypt : false,
parameters : {}
}
]);
expect(pipeProducer.rtpParameters.encodings).toEqual(
......@@ -347,8 +351,10 @@ test('router.pipeToRouter() succeeds with video', async () =>
[
{
mimeType : 'video/VP8',
clockRate : 90000,
payloadType : 101,
clockRate : 90000,
channels : 1,
parameters : {},
rtcpFeedback :
[
{ type: 'nack', parameter: 'pli' },
......@@ -360,20 +366,28 @@ test('router.pipeToRouter() succeeds with video', async () =>
[
// NOTE: Remove this once framemarking draft becomes RFC.
{
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
id : 6
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
id : 6,
encrypt : false,
parameters : {}
},
{
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
id : 7
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
id : 7,
encrypt : false,
parameters : {}
},
{
uri : 'urn:3gpp:video-orientation',
id : 11
uri : 'urn:3gpp:video-orientation',
id : 11,
encrypt : false,
parameters : {}
},
{
uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 12
uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 12,
encrypt : false,
parameters : {}
}
]);
expect(pipeConsumer.rtpParameters.encodings).toEqual(
......@@ -398,8 +412,10 @@ test('router.pipeToRouter() succeeds with video', async () =>
[
{
mimeType : 'video/VP8',
clockRate : 90000,
payloadType : 101,
clockRate : 90000,
channels : 1,
parameters : {},
rtcpFeedback :
[
{ type: 'nack', parameter: 'pli' },
......@@ -411,20 +427,28 @@ test('router.pipeToRouter() succeeds with video', async () =>
[
// NOTE: Remove this once framemarking draft becomes RFC.
{
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
id : 6
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
id : 6,
encrypt : false,
parameters : {}
},
{
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
id : 7
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
id : 7,
encrypt : false,
parameters : {}
},
{
uri : 'urn:3gpp:video-orientation',
id : 11
uri : 'urn:3gpp:video-orientation',
id : 11,
encrypt : false,
parameters : {}
},
{
uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 12
uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 12,
encrypt : false,
parameters : {}
}
]);
expect(pipeProducer.paused).toBe(true);
......@@ -447,36 +471,43 @@ test('transport.consume() for a pipe Producer succeeds', async () =>
[
{
mimeType : 'video/VP8',
clockRate : 90000,
payloadType : 101,
clockRate : 90000,
channels : 1,
parameters : {},
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: '' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'google-remb' },
{ type: 'transport-cc' }
{ type: 'google-remb', parameter: '' },
{ type: 'transport-cc', parameter: '' }
]
},
{
mimeType : 'video/rtx',
clockRate : 90000,
payloadType : 102,
rtcpFeedback : [],
parameters :
mimeType : 'video/rtx',
payloadType : 102,
clockRate : 90000,
channels : 1,
parameters :
{
apt : 101
}
},
rtcpFeedback : []
}
]);
expect(videoConsumer.rtpParameters.headerExtensions).toEqual(
[
{
uri : 'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time',
id : 4
uri : 'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time',
id : 4,
encrypt : false,
parameters : {}
},
{
uri : 'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01',
id : 5
uri : 'http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01',
id : 5,
encrypt : false,
parameters : {}
}
]);
expect(videoConsumer.rtpParameters.encodings.length).toBe(1);
......
......@@ -27,17 +27,17 @@ const mediaCodecs =
clockRate : 90000
},
{
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
rtcpFeedback : [], // Will be ignored.
parameters :
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
parameters :
{
'level-asymmetry-allowed' : 1,
'packetization-mode' : 1,
'profile-level-id' : '4d0032',
foo : 'bar'
}
},
rtcpFeedback : [] // Will be ignored.
}
];
......
......@@ -30,17 +30,17 @@ const mediaCodecs =
clockRate : 90000
},
{
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
rtcpFeedback : [], // Will be ignored.
parameters :
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
parameters :
{
'level-asymmetry-allowed' : 1,
'packetization-mode' : 1,
'profile-level-id' : '4d0032',
foo : 'bar'
}
},
rtcpFeedback : [] // Will be ignored.
}
];
......
......@@ -29,16 +29,16 @@ const mediaCodecs =
clockRate : 90000
},
{
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
rtcpFeedback : [], // Will be ignored.
parameters :
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
parameters :
{
'level-asymmetry-allowed' : 1,
'packetization-mode' : 1,
'profile-level-id' : '4d0032'
}
},
rtcpFeedback : [] // Will be ignored.
}
];
......@@ -59,7 +59,6 @@ test('worker.createRouter() succeeds', async () =>
expect(router.rtpCapabilities).toBeType('object');
expect(router.rtpCapabilities.codecs).toBeType('array');
expect(router.rtpCapabilities.headerExtensions).toBeType('array');
expect(router.rtpCapabilities.fecMechanisms).toEqual([]);
expect(router.appData).toEqual({ foo: 123 });
await expect(worker.dump())
......
......@@ -21,21 +21,21 @@ test('generateRouterRtpCapabilities() succeeds', () =>
},
{
kind : 'video',
preferredPayloadType : 125, // Let's force it.
mimeType : 'video/VP8',
preferredPayloadType : 125, // Let's force it.
clockRate : 90000
},
{
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
rtcpFeedback : [], // Will be ignored.
parameters :
kind : 'video',
mimeType : 'video/H264',
clockRate : 90000,
parameters :
{
'level-asymmetry-allowed' : 1,
'profile-level-id' : '42e01f',
foo : 'bar'
}
},
rtcpFeedback : [] // Will be ignored.
}
];
......@@ -51,15 +51,15 @@ test('generateRouterRtpCapabilities() succeeds', () =>
preferredPayloadType : 100, // 100 is the first available dynamic PT.
clockRate : 48000,
channels : 2,
rtcpFeedback :
[
{ type: 'transport-cc' }
],
parameters :
parameters :
{
useinbandfec : 1,
foo : 'bar'
}
},
rtcpFeedback :
[
{ type: 'transport-cc', parameter: '' }
]
});
// VP8.
......@@ -69,15 +69,16 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType : 'video/VP8',
preferredPayloadType : 125,
clockRate : 90000,
channels : 1,
parameters : {},
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb' },
{ type: 'transport-cc' }
],
parameters : {}
{ type: 'goog-remb', parameter: '' },
{ type: 'transport-cc', parameter: '' }
]
});
// VP8 RTX.
......@@ -87,11 +88,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType : 'video/rtx',
preferredPayloadType : 101, // 101 is the second available dynamic PT.
clockRate : 90000,
rtcpFeedback : [],
channels : 1,
parameters :
{
apt : 125
}
},
rtcpFeedback : []
});
// H264.
......@@ -101,22 +103,23 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType : 'video/H264',
preferredPayloadType : 102, // 102 is the second available dynamic PT.
clockRate : 90000,
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb' },
{ type: 'transport-cc' }
],
parameters :
channels : 1,
parameters :
{
'packetization-mode' : 0,
'level-asymmetry-allowed' : 1,
'profile-level-id' : '42e01f',
foo : 'bar'
}
},
rtcpFeedback :
[
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb', parameter: '' },
{ type: 'transport-cc', parameter: '' }
]
});
// H264 RTX.
......@@ -126,11 +129,12 @@ test('generateRouterRtpCapabilities() succeeds', () =>
mimeType : 'video/rtx',
preferredPayloadType : 103,
clockRate : 90000,
rtcpFeedback : [],
channels : 1,
parameters :
{
apt : 102
}
},
rtcpFeedback : []
});
});
......@@ -231,30 +235,33 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
codecs :
[
{
mimeType : 'video/H264',
payloadType : 111,
clockRate : 90000,
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: 'pli' },
{ type: 'goog-remb' }
],
parameters :
mimeType : 'video/H264',
payloadType : 111,
clockRate : 90000,
channels : 1,
parameters :
{
foo : 1234,
'packetization-mode' : 1,
'profile-level-id' : '4d0032'
}
},
rtcpFeedback :
[
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'goog-remb', parameter: '' }
]
},
{
mimeType : 'video/rtx',
payloadType : 112,
clockRate : 90000,
channels : 1,
parameters :
{
apt : 111
}
},
rtcpFeedback : []
}
],
headerExtensions :
......@@ -366,35 +373,40 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
mimeType : 'audio/opus',
preferredPayloadType : 100,
clockRate : 48000,
channels : 2
channels : 2,
parameters : {},
rtcpFeedback : []
},
{
kind : 'video',
mimeType : 'video/H264',
preferredPayloadType : 101,
clockRate : 90000,
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: 'pli' },
{ type: 'foo', parameter: 'FOO' }
],
parameters :
channels : 1,
parameters :
{
'packetization-mode' : 1,
'profile-level-id' : '4d0032',
baz : 'LOLOLO'
}
},
rtcpFeedback :
[
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'foo', parameter: 'FOO' }
]
},
{
kind : 'video',
mimeType : 'video/rtx',
preferredPayloadType : 102,
clockRate : 90000,
channels : 1,
parameters :
{
apt : 101
}
},
rtcpFeedback : []
}
],
headerExtensions :
......@@ -403,37 +415,43 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
kind : 'audio',
uri : 'urn:ietf:params:rtp-hdrext:sdes:mid',
preferredId : 1,
preferredEncrypt : false
preferredEncrypt : false,
direction : 'sendrecv'
},
{
kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:sdes:mid',
preferredId : 1,
preferredEncrypt : false
preferredEncrypt : false,
direction : 'sendrecv'
},
{
kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id',
preferredId : 2,
preferredEncrypt : false
preferredEncrypt : false,
direction : 'sendrecv'
},
{
kind : 'audio',
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
preferredId : 8,
preferredEncrypt : false
preferredEncrypt : false,
direction : 'sendrecv'
},
{
kind : 'video',
uri : 'urn:3gpp:video-orientation',
preferredId : 11,
preferredEncrypt : false
preferredEncrypt : false,
direction : 'sendrecv'
},
{
kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:toffset',
preferredId : 12,
preferredEncrypt : false
preferredEncrypt : false,
direction : 'sendrecv'
}
]
};
......@@ -444,32 +462,34 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
expect(consumerRtpParameters.codecs.length).toEqual(2);
expect(consumerRtpParameters.codecs[0]).toEqual(
{
mimeType : 'video/H264',
payloadType : 101,
clockRate : 90000,
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: 'pli' },
{ type: 'foo', parameter: 'FOO' }
],
parameters :
mimeType : 'video/H264',
payloadType : 101,
clockRate : 90000,
channels : 1,
parameters :
{
foo : 1234,
'packetization-mode' : 1,
'profile-level-id' : '4d0032'
}
},
rtcpFeedback :
[
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'foo', parameter: 'FOO' }
]
});
expect(consumerRtpParameters.codecs[1]).toEqual(
{
mimeType : 'video/rtx',
payloadType : 102,
clockRate : 90000,
rtcpFeedback : [],
parameters :
mimeType : 'video/rtx',
payloadType : 102,
clockRate : 90000,
channels : 1,
parameters :
{
apt : 101
}
},
rtcpFeedback : []
});
expect(consumerRtpParameters.encodings.length).toBe(1);
......@@ -481,12 +501,16 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
expect(consumerRtpParameters.headerExtensions).toEqual(
[
{
uri : 'urn:3gpp:video-orientation',
id : 11
uri : 'urn:3gpp:video-orientation',
id : 11,
encrypt : false,
parameters : {}
},
{
uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 12
uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 12,
encrypt : false,
parameters : {}
}
]);
......@@ -503,20 +527,21 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
expect(pipeConsumerRtpParameters.codecs.length).toEqual(1);
expect(pipeConsumerRtpParameters.codecs[0]).toEqual(
{
mimeType : 'video/H264',
payloadType : 101,
clockRate : 90000,
rtcpFeedback :
[
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' }
],
parameters :
mimeType : 'video/H264',
payloadType : 101,
clockRate : 90000,
channels : 1,
parameters :
{
foo : 1234,
'packetization-mode' : 1,
'profile-level-id' : '4d0032'
}
},
rtcpFeedback :
[
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' }
]
});
expect(pipeConsumerRtpParameters.encodings.length).toBe(3);
......@@ -575,7 +600,7 @@ test('getProducerRtpParametersMapping() with incompatible params throws Unsuppor
clockRate : 90000,
rtcpFeedback :
[
{ type: 'nack' },
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'fir' }
]
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论