From 6961afb1a905ca638e01f58d95edf24acbf76334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 4 Jan 2021 15:45:35 +0100 Subject: [PATCH] Add pipe boolean option to transport.consume() (#494) --- CHANGELOG.md | 5 +- lib/Consumer.d.ts | 5 ++ lib/Consumer.d.ts.map | 2 +- lib/Transport.d.ts | 2 +- lib/Transport.d.ts.map | 2 +- lib/Transport.js | 24 +++++---- lib/ortc.d.ts | 2 +- lib/ortc.d.ts.map | 2 +- lib/ortc.js | 76 ++++++++++++++++----------- src/Consumer.ts | 6 +++ src/Transport.ts | 29 +++++++---- src/ortc.ts | 94 ++++++++++++++++++++------------- test/test-Consumer.js | 114 ++++++++++++++++++++++++++++++++++------- 13 files changed, 253 insertions(+), 110 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8593213241..3e6409e598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ # Changelog -### 3.6.30 (WIP) +### 3.7.30 (WIP) +* Add `pipe` option to `transport.consume()`(PR #494). + - So the receiver will get all streams from the `Producer`. + - It works for any kind of transport (but `PipeTransport` which is always like this). * Update NPM deps. * Add `LICENSE` and `PATENTS` files in `libwebrtc` dependency (issue #495). * Added `worker/src/Utils/README_BASE64_UTILS` (issue #497). diff --git a/lib/Consumer.d.ts b/lib/Consumer.d.ts index 51b4b6e9cc..c6b6909a66 100644 --- a/lib/Consumer.d.ts +++ b/lib/Consumer.d.ts @@ -32,6 +32,11 @@ export declare type ConsumerOptions = { * If unset, the highest ones are selected. */ preferredLayers?: ConsumerLayers; + /** + * Whether this Consumer should consume all RTP streams generated by the + * Producer. + */ + pipe?: boolean; /** * Custom application data. */ diff --git a/lib/Consumer.d.ts.map b/lib/Consumer.d.ts.map index dc8b54323f..d330bd79a9 100644 --- a/lib/Consumer.d.ts.map +++ b/lib/Consumer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Consumer.d.ts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AAC;IAe7B;;OAEG;IACG,kBAAkB,CACvB,EACC,YAAY,EACZ,aAAa,EACb,EAAE,cAAc,GACf,OAAO,CAAC,IAAI,CAAC;IAYhB;;OAEG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAYpC;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtC;;OAEG;IACG,gBAAgB,CAAC,KAAK,GAAE,sBAAsB,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3E,OAAO,CAAC,0BAA0B;CAsIlC"} \ No newline at end of file diff --git a/lib/Transport.d.ts b/lib/Transport.d.ts index b0fcbbfcd7..6521b5c4c5 100644 --- a/lib/Transport.d.ts +++ b/lib/Transport.d.ts @@ -166,7 +166,7 @@ export declare class Transport extends EnhancedEventEmitter { * * @virtual */ - consume({ producerId, rtpCapabilities, paused, preferredLayers, appData }: ConsumerOptions): Promise; + consume({ producerId, rtpCapabilities, paused, preferredLayers, pipe, appData }: ConsumerOptions): Promise; /** * Create a DataProducer. */ diff --git a/lib/Transport.d.ts.map b/lib/Transport.d.ts.map index 42e141aa9a..3b0024f5e7 100644 --- a/lib/Transport.d.ts.map +++ b/lib/Transport.d.ts.map @@ -1 +1 @@ -{"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,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACN,YAAY,EACZ,mBAAmB,EAEnB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I,IAAI;IAqDpB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAO1B;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAMhC;;;;OAIG;IAEG,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzC;;OAEG;IACG,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3D;;OAEG;IACG,OAAO,CACZ,EACC,EAAc,EACd,IAAI,EACJ,aAAa,EACb,MAAc,EACd,oBAAoB,EACpB,OAAY,EACZ,EAAE,eAAe,GAChB,OAAO,CAAC,QAAQ,CAAC;IA+FpB;;;;OAIG;IACG,OAAO,CACZ,EACC,UAAU,EACV,eAAe,EACf,MAAc,EACd,eAAe,EACf,IAAY,EACZ,OAAY,EACZ,EAAE,eAAe,GAChB,OAAO,CAAC,QAAQ,CAAC;IAgFpB;;OAEG;IACG,WAAW,CAChB,EACC,EAAc,EACd,oBAAoB,EACpB,KAAU,EACV,QAAa,EACb,OAAY,EACZ,GAAE,mBAAwB,GACzB,OAAO,CAAC,YAAY,CAAC;IAmExB;;OAEG;IACG,WAAW,CAChB,EACC,cAAc,EACd,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,OAAY,EACZ,EAAE,mBAAmB,GACpB,OAAO,CAAC,YAAY,CAAC;IAuGxB;;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 diff --git a/lib/Transport.js b/lib/Transport.js index 85933f259d..88b2d1d04c 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -275,7 +275,7 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter { * * @virtual */ - async consume({ producerId, rtpCapabilities, paused = false, preferredLayers, appData = {} }) { + async consume({ producerId, rtpCapabilities, paused = false, preferredLayers, pipe = false, appData = {} }) { logger.debug('consume()'); if (!producerId || typeof producerId !== 'string') throw new TypeError('missing producerId'); @@ -287,25 +287,31 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter { if (!producer) throw Error(`Producer with id "${producerId}" not found`); // This may throw. - const rtpParameters = ortc.getConsumerRtpParameters(producer.consumableRtpParameters, rtpCapabilities); + const rtpParameters = ortc.getConsumerRtpParameters(producer.consumableRtpParameters, rtpCapabilities, pipe); // Set MID. - rtpParameters.mid = `${this._nextMidForConsumers++}`; - // We use up to 8 bytes for MID (string). - if (this._nextMidForConsumers === 100000000) { - logger.error(`consume() | reaching max MID value "${this._nextMidForConsumers}"`); - this._nextMidForConsumers = 0; + if (!pipe) { + rtpParameters.mid = `${this._nextMidForConsumers++}`; + // We use up to 8 bytes for MID (string). + if (this._nextMidForConsumers === 100000000) { + logger.error(`consume() | reaching max MID value "${this._nextMidForConsumers}"`); + this._nextMidForConsumers = 0; + } } const internal = { ...this._internal, consumerId: uuid_1.v4(), producerId }; const reqData = { kind: producer.kind, rtpParameters, - type: producer.type, + type: pipe ? 'pipe' : producer.type, consumableRtpEncodings: producer.consumableRtpParameters.encodings, paused, preferredLayers }; const status = await this._channel.request('transport.consume', internal, reqData); - const data = { kind: producer.kind, rtpParameters, type: producer.type }; + const data = { + kind: producer.kind, + rtpParameters, + type: pipe ? 'pipe' : producer.type + }; const consumer = new Consumer_1.Consumer({ internal, data, diff --git a/lib/ortc.d.ts b/lib/ortc.d.ts index 6279b03ed9..9d510ac5cf 100644 --- a/lib/ortc.d.ts +++ b/lib/ortc.d.ts @@ -118,7 +118,7 @@ export declare function canConsume(consumableParams: RtpParameters, caps: RtpCap * to reduce codecs, codecs' RTCP feedback and header extensions, and also enables * or disabled RTX. */ -export declare function getConsumerRtpParameters(consumableParams: RtpParameters, caps: RtpCapabilities): RtpParameters; +export declare function getConsumerRtpParameters(consumableParams: RtpParameters, caps: RtpCapabilities, pipe: boolean): RtpParameters; /** * Generate RTP parameters for a pipe Consumer. * diff --git a/lib/ortc.d.ts.map b/lib/ortc.d.ts.map index 802887f70e..2228fc2155 100644 --- a/lib/ortc.d.ts.map +++ b/lib/ortc.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"ortc.d.ts","sourceRoot":"","sources":["../src/ortc.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,eAAe,EAEf,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,cAAc,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,aAAK,UAAU,GACf;IACC,MAAM,EACN;QACC,WAAW,EAAE,MAAM,CAAC;QACpB,iBAAiB,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;IAEJ,SAAS,EACT;QACC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;KACnB,EAAE,CAAC;CACJ,CAAA;AASD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CA0BnE;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CA0E1E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAY3D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAgCxE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CA+CjE;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,kBAAkB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AQ,GACf,aAAa,CAwDf"} \ No newline at end of file +{"version":3,"file":"ortc.d.ts","sourceRoot":"","sources":["../src/ortc.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,eAAe,EAEf,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,cAAc,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,aAAK,UAAU,GACf;IACC,MAAM,EACN;QACC,WAAW,EAAE,MAAM,CAAC;QACpB,iBAAiB,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;IAEJ,SAAS,EACT;QACC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;KACnB,EAAE,CAAC;CACJ,CAAA;AASD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CA0BnE;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CA0E1E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAY3D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAgCxE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CA+CjE;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAyE1E;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CACnD,GAAG,EAAE,4BAA4B,GAC/B,IAAI,CAqCN;AAED;;;;GA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a/lib/ortc.js +++ b/lib/ortc.js @@ -652,7 +652,7 @@ exports.canConsume = canConsume; * to reduce codecs, codecs' RTCP feedback and header extensions, and also enables * or disabled RTX. */ -function getConsumerRtpParameters(consumableParams, caps) { +function getConsumerRtpParameters(consumableParams, caps, pipe) { const consumerParams = { codecs: [], headerExtensions: [], @@ -713,36 +713,50 @@ function getConsumerRtpParameters(consumableParams, caps) { fb.type !== 'goog-remb')); } } - const consumerEncoding = { - ssrc: utils.generateRandomNumber() - }; - if (rtxSupported) - consumerEncoding.rtx = { ssrc: utils.generateRandomNumber() }; - // If any of the consumableParams.encodings has scalabilityMode, process it - // (assume all encodings have the same value). - const encodingWithScalabilityMode = consumableParams.encodings.find((encoding) => encoding.scalabilityMode); - let scalabilityMode = encodingWithScalabilityMode - ? encodingWithScalabilityMode.scalabilityMode - : undefined; - // If there is simulast, mangle spatial layers in scalabilityMode. - if (consumableParams.encodings.length > 1) { - const { temporalLayers } = scalabilityModes_1.parse(scalabilityMode); - scalabilityMode = `S${consumableParams.encodings.length}T${temporalLayers}`; - } - if (scalabilityMode) - consumerEncoding.scalabilityMode = scalabilityMode; - // Use the maximum maxBitrate in any encoding and honor it in the Consumer's - // encoding. - const maxEncodingMaxBitrate = consumableParams.encodings.reduce((maxBitrate, encoding) => (encoding.maxBitrate && encoding.maxBitrate > maxBitrate - ? encoding.maxBitrate - : maxBitrate), 0); - if (maxEncodingMaxBitrate) { - consumerEncoding.maxBitrate = maxEncodingMaxBitrate; - } - // Set a single encoding for the Consumer. - consumerParams.encodings.push(consumerEncoding); - // Copy verbatim. - consumerParams.rtcp = consumableParams.rtcp; + if (!pipe) { + const consumerEncoding = { + ssrc: utils.generateRandomNumber() + }; + if (rtxSupported) + consumerEncoding.rtx = { ssrc: consumerEncoding.ssrc + 1 }; + // If any of the consumableParams.encodings has scalabilityMode, process it + // (assume all encodings have the same value). + const encodingWithScalabilityMode = consumableParams.encodings.find((encoding) => encoding.scalabilityMode); + let scalabilityMode = encodingWithScalabilityMode + ? encodingWithScalabilityMode.scalabilityMode + : undefined; + // If there is simulast, mangle spatial layers in scalabilityMode. + if (consumableParams.encodings.length > 1) { + const { temporalLayers } = scalabilityModes_1.parse(scalabilityMode); + scalabilityMode = `S${consumableParams.encodings.length}T${temporalLayers}`; + } + if (scalabilityMode) + consumerEncoding.scalabilityMode = scalabilityMode; + // Use the maximum maxBitrate in any encoding and honor it in the Consumer's + // encoding. + const maxEncodingMaxBitrate = consumableParams.encodings.reduce((maxBitrate, encoding) => (encoding.maxBitrate && encoding.maxBitrate > maxBitrate + ? encoding.maxBitrate + : maxBitrate), 0); + if (maxEncodingMaxBitrate) { + consumerEncoding.maxBitrate = maxEncodingMaxBitrate; + } + // Set a single encoding for the Consumer. + consumerParams.encodings.push(consumerEncoding); + } + else { + const consumableEncodings = utils.clone(consumableParams.encodings); + const baseSsrc = utils.generateRandomNumber(); + const baseRtxSsrc = utils.generateRandomNumber(); + for (let i = 0; i < consumableEncodings.length; ++i) { + const encoding = consumableEncodings[i]; + encoding.ssrc = baseSsrc + i; + if (rtxSupported) + encoding.rtx = { ssrc: baseRtxSsrc + i }; + else + delete encoding.rtx; + consumerParams.encodings.push(encoding); + } + } return consumerParams; } exports.getConsumerRtpParameters = getConsumerRtpParameters; diff --git a/src/Consumer.ts b/src/Consumer.ts index af44451b8d..c6a988e812 100644 --- a/src/Consumer.ts +++ b/src/Consumer.ts @@ -43,6 +43,12 @@ export type ConsumerOptions = */ preferredLayers?: ConsumerLayers; + /** + * Whether this Consumer should consume all RTP streams generated by the + * Producer. + */ + pipe?: boolean; + /** * Custom application data. */ diff --git a/src/Transport.ts b/src/Transport.ts index 1484451f0a..5cc1cff658 100644 --- a/src/Transport.ts +++ b/src/Transport.ts @@ -522,6 +522,7 @@ export class Transport extends EnhancedEventEmitter rtpCapabilities, paused = false, preferredLayers, + pipe = false, appData = {} }: ConsumerOptions ): Promise @@ -543,18 +544,21 @@ export class Transport extends EnhancedEventEmitter // This may throw. const rtpParameters = ortc.getConsumerRtpParameters( - producer.consumableRtpParameters, rtpCapabilities!); + producer.consumableRtpParameters, rtpCapabilities!, pipe); // Set MID. - rtpParameters.mid = `${this._nextMidForConsumers++}`; - - // We use up to 8 bytes for MID (string). - if (this._nextMidForConsumers === 100000000) + if (!pipe) { - logger.error( - `consume() | reaching max MID value "${this._nextMidForConsumers}"`); + rtpParameters.mid = `${this._nextMidForConsumers++}`; + + // We use up to 8 bytes for MID (string). + if (this._nextMidForConsumers === 100000000) + { + logger.error( + `consume() | reaching max MID value "${this._nextMidForConsumers}"`); - this._nextMidForConsumers = 0; + this._nextMidForConsumers = 0; + } } const internal = { ...this._internal, consumerId: uuidv4(), producerId }; @@ -562,7 +566,7 @@ export class Transport extends EnhancedEventEmitter { kind : producer.kind, rtpParameters, - type : producer.type, + type : pipe ? 'pipe' : producer.type, consumableRtpEncodings : producer.consumableRtpParameters.encodings, paused, preferredLayers @@ -571,7 +575,12 @@ export class Transport extends EnhancedEventEmitter const status = await this._channel.request('transport.consume', internal, reqData); - const data = { kind: producer.kind, rtpParameters, type: producer.type }; + const data = + { + kind : producer.kind, + rtpParameters, + type : pipe ? 'pipe' : producer.type + }; const consumer = new Consumer( { diff --git a/src/ortc.ts b/src/ortc.ts index 032339cf02..f0a55dd702 100644 --- a/src/ortc.ts +++ b/src/ortc.ts @@ -939,7 +939,8 @@ export function canConsume( */ export function getConsumerRtpParameters( consumableParams: RtpParameters, - caps: RtpCapabilities + caps: RtpCapabilities, + pipe: boolean ): RtpParameters { const consumerParams: RtpParameters = @@ -1043,53 +1044,74 @@ export function getConsumerRtpParameters( } } - const consumerEncoding: RtpEncodingParameters = + if (!pipe) { - ssrc : utils.generateRandomNumber() - }; + const consumerEncoding: RtpEncodingParameters = + { + ssrc : utils.generateRandomNumber() + }; - if (rtxSupported) - consumerEncoding.rtx = { ssrc: utils.generateRandomNumber() }; + if (rtxSupported) + consumerEncoding.rtx = { ssrc: consumerEncoding.ssrc! + 1 }; - // If any of the consumableParams.encodings has scalabilityMode, process it - // (assume all encodings have the same value). - const encodingWithScalabilityMode = - consumableParams.encodings!.find((encoding) => encoding.scalabilityMode); + // If any of the consumableParams.encodings has scalabilityMode, process it + // (assume all encodings have the same value). + const encodingWithScalabilityMode = + consumableParams.encodings!.find((encoding) => encoding.scalabilityMode); - let scalabilityMode = encodingWithScalabilityMode - ? encodingWithScalabilityMode.scalabilityMode - : undefined; + let scalabilityMode = encodingWithScalabilityMode + ? encodingWithScalabilityMode.scalabilityMode + : undefined; - // If there is simulast, mangle spatial layers in scalabilityMode. - if (consumableParams.encodings!.length > 1) - { - const { temporalLayers } = parseScalabilityMode(scalabilityMode); + // If there is simulast, mangle spatial layers in scalabilityMode. + if (consumableParams.encodings!.length > 1) + { + const { temporalLayers } = parseScalabilityMode(scalabilityMode); - scalabilityMode = `S${consumableParams.encodings!.length}T${temporalLayers}`; - } + scalabilityMode = `S${consumableParams.encodings!.length}T${temporalLayers}`; + } - if (scalabilityMode) - consumerEncoding.scalabilityMode = scalabilityMode; + if (scalabilityMode) + consumerEncoding.scalabilityMode = scalabilityMode; - // Use the maximum maxBitrate in any encoding and honor it in the Consumer's - // encoding. - const maxEncodingMaxBitrate = - consumableParams.encodings!.reduce((maxBitrate, encoding) => ( - encoding.maxBitrate && encoding.maxBitrate > maxBitrate - ? encoding.maxBitrate - : maxBitrate - ), 0); + // Use the maximum maxBitrate in any encoding and honor it in the Consumer's + // encoding. + const maxEncodingMaxBitrate = + consumableParams.encodings!.reduce((maxBitrate, encoding) => ( + encoding.maxBitrate && encoding.maxBitrate > maxBitrate + ? encoding.maxBitrate + : maxBitrate + ), 0); - if (maxEncodingMaxBitrate) - { - consumerEncoding.maxBitrate = maxEncodingMaxBitrate; + if (maxEncodingMaxBitrate) + { + consumerEncoding.maxBitrate = maxEncodingMaxBitrate; + } + + // Set a single encoding for the Consumer. + consumerParams.encodings!.push(consumerEncoding); } + else + { + const consumableEncodings = + utils.clone(consumableParams.encodings) as RtpEncodingParameters[]; + const baseSsrc = utils.generateRandomNumber(); + const baseRtxSsrc = utils.generateRandomNumber(); + + for (let i = 0; i < consumableEncodings.length; ++i) + { + const encoding = consumableEncodings[i]; + + encoding.ssrc = baseSsrc + i; - // Set a single encoding for the Consumer. - consumerParams.encodings!.push(consumerEncoding); + if (rtxSupported) + encoding.rtx = { ssrc: baseRtxSsrc + i }; + else + delete encoding.rtx; - // Copy verbatim. - consumerParams.rtcp = consumableParams.rtcp; + consumerParams.encodings!.push(encoding); + } + } return consumerParams; } diff --git a/test/test-Consumer.js b/test/test-Consumer.js index 9475e9a0eb..3e0d5d0862 100644 --- a/test/test-Consumer.js +++ b/test/test-Consumer.js @@ -13,6 +13,7 @@ let audioProducer; let videoProducer; let audioConsumer; let videoConsumer; +let videoPipeConsumer; const mediaCodecs = [ @@ -396,21 +397,90 @@ test('transport.consume() succeeds', async () => expect(videoConsumer.currentLayers).toBeUndefined(); expect(videoConsumer.appData).toEqual({ baz: 'LOL' }); - await expect(router.dump()) - .resolves - .toMatchObject( + const onObserverNewConsumer3 = jest.fn(); + + transport2.observer.once('newconsumer', onObserverNewConsumer3); + + expect(router.canConsume( + { + producerId : videoProducer.id, + rtpCapabilities : consumerDeviceCapabilities + })) + .toBe(true); + + videoPipeConsumer = await transport2.consume( + { + producerId : videoProducer.id, + rtpCapabilities : consumerDeviceCapabilities, + pipe : true + }); + + expect(onObserverNewConsumer3).toHaveBeenCalledTimes(1); + expect(onObserverNewConsumer3).toHaveBeenCalledWith(videoPipeConsumer); + expect(videoPipeConsumer.id).toBeType('string'); + expect(videoPipeConsumer.producerId).toBe(videoProducer.id); + expect(videoPipeConsumer.closed).toBe(false); + expect(videoPipeConsumer.kind).toBe('video'); + expect(videoPipeConsumer.rtpParameters).toBeType('object'); + expect(videoPipeConsumer.rtpParameters.mid).toBeUndefined(); + expect(videoPipeConsumer.rtpParameters.codecs.length).toBe(2); + expect(videoPipeConsumer.rtpParameters.codecs[0]).toEqual( + { + mimeType : 'video/H264', + payloadType : 103, + clockRate : 90000, + parameters : { - mapProducerIdConsumerIds : - { - [audioProducer.id] : [ audioConsumer.id ], - [videoProducer.id] : [ videoConsumer.id ] - }, - mapConsumerIdProducerId : - { - [audioConsumer.id] : audioProducer.id, - [videoConsumer.id] : videoProducer.id - } - }); + 'packetization-mode' : 1, + 'profile-level-id' : '4d0032' + }, + rtcpFeedback : + [ + { type: 'nack', parameter: '' }, + { type: 'nack', parameter: 'pli' }, + { type: 'ccm', parameter: 'fir' }, + { type: 'goog-remb', parameter: '' } + ] + }); + expect(videoPipeConsumer.rtpParameters.codecs[1]).toEqual( + { + mimeType : 'video/rtx', + payloadType : 104, + clockRate : 90000, + parameters : { apt: 103 }, + rtcpFeedback : [] + }); + expect(videoPipeConsumer.type).toBe('pipe'); + expect(videoPipeConsumer.paused).toBe(false); + expect(videoPipeConsumer.producerPaused).toBe(true); + expect(videoPipeConsumer.priority).toBe(1); + expect(videoPipeConsumer.score).toEqual( + { score: 10, producerScore: 10, producerScores: [ 0, 0, 0, 0 ] }); + expect(videoPipeConsumer.preferredLayers).toBeUndefined(); + expect(videoPipeConsumer.currentLayers).toBeUndefined(); + expect(videoPipeConsumer.appData).toBeUndefined; + + const dump = await router.dump(); + + for (const key of Object.keys(dump.mapProducerIdConsumerIds)) + { + dump.mapProducerIdConsumerIds[key] = dump.mapProducerIdConsumerIds[key].sort(); + } + + expect(dump).toMatchObject( + { + mapProducerIdConsumerIds : + { + [audioProducer.id] : [ audioConsumer.id ], + [videoProducer.id] : [ videoConsumer.id, videoPipeConsumer.id ].sort() + }, + mapConsumerIdProducerId : + { + [audioConsumer.id] : audioProducer.id, + [videoConsumer.id] : videoProducer.id, + [videoPipeConsumer.id] : videoProducer.id + } + }); await expect(transport2.dump()) .resolves @@ -418,7 +488,12 @@ test('transport.consume() succeeds', async () => { id : transport2.id, producerIds : [], - consumerIds : expect.arrayContaining([ audioConsumer.id, videoConsumer.id ]) + consumerIds : expect.arrayContaining( + [ + audioConsumer.id, + videoConsumer.id, + videoPipeConsumer.id + ]) }); }, 2000); @@ -822,13 +897,16 @@ test('consumer.close() succeeds', async () => mapConsumerIdProducerId : {} }); - await expect(transport2.dump()) - .resolves + const dump = await transport2.dump(); + + dump.consumerIds = dump.consumerIds.sort(); + + expect(dump) .toMatchObject( { id : transport2.id, producerIds : [], - consumerIds : [ videoConsumer.id ] + consumerIds : [ videoConsumer.id, videoPipeConsumer.id ].sort() }); }, 2000);