Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions node/src/ConsumerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ export type ConsumerOptions<ConsumerAppData extends AppData = AppData> = {
*/
pipe?: boolean;

/**
* When set, bypasses ortc.getConsumerRtpParameters and is used verbatim
* as the Consumer's rtpParameters. The payload types and header-extension
* ids declared here become the on-wire values for this Consumer.
*
* mediasoup validates compatibility against the Producer's
* consumableRtpParameters (1:1 codec mapping, compatible fmtp, matching
* layer/simulcast structure, header-extension URIs being a subset of the
* consumable ones) and asks the worker to rewrite outgoing RTP headers
* accordingly.
*
* Intended for advanced scenarios (e.g. WHEP) where the answer SDP
* dictates wire-level PT / ext-id values that differ from the Router's
* canonical ones.
*
* Not supported together with pipe=true.
*/
rtpParameters?: RtpParameters;

/**
* Custom application data.
*/
Expand Down
42 changes: 38 additions & 4 deletions node/src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ export abstract class TransportImpl<
ignoreDtx = false,
enableRtx,
pipe = false,
rtpParameters: overrideRtpParameters,
appData,
}: ConsumerOptions<ConsumerAppData>): Promise<Consumer<ConsumerAppData>> {
logger.debug('consume()');
Expand All @@ -595,6 +596,10 @@ export abstract class TransportImpl<
throw new TypeError('if given, appData must be an object');
} else if (mid && (typeof mid !== 'string' || mid.length === 0)) {
throw new TypeError('if given, mid must be non empty string');
} else if (overrideRtpParameters && pipe) {
throw new TypeError(
'rtpParameters override is not supported together with pipe=true'
);
}

// Clone given RTP capabilities to not modify input data.
Expand All @@ -614,16 +619,29 @@ export abstract class TransportImpl<
enableRtx = producer.kind === 'video';
}

let consumerRtpMapping: ortc.ConsumerRtpMapping | undefined;

// This may throw.
const rtpParameters = ortc.getConsumerRtpParameters({
const rtpParameters: RtpParameters = ortc.getConsumerRtpParameters({
consumableRtpParameters: producer.consumableRtpParameters,
remoteRtpCapabilities: clonedRtpCapabilities,
remoteRtpCapabilities: overrideRtpParameters ?? clonedRtpCapabilities,
pipe,
enableRtx,
});

// Set MID.
if (!pipe) {
if (overrideRtpParameters) {
consumerRtpMapping = ortc.getConsumerRtpMapping(
producer.consumableRtpParameters,
rtpParameters
);
}

// Set MID. Priority:
// 1. mid already set on rtpParameters (override path, taken from
// the caller-provided rtpParameters.mid).
// 2. ConsumerOptions.mid.
// 3. Auto-generated monotonically increasing integer.
if (!pipe && !rtpParameters.mid) {
if (mid) {
rtpParameters.mid = mid;
} else {
Expand All @@ -650,6 +668,7 @@ export abstract class TransportImpl<
preferredLayers,
ignoreDtx,
pipe,
consumerRtpMapping,
});

const response = await this.channel.request(
Expand Down Expand Up @@ -1348,6 +1367,7 @@ function createConsumeRequest({
preferredLayers,
ignoreDtx,
pipe,
consumerRtpMapping,
}: {
builder: flatbuffers.Builder;
producer: Producer;
Expand All @@ -1357,6 +1377,7 @@ function createConsumeRequest({
preferredLayers?: ConsumerLayers;
ignoreDtx?: boolean;
pipe: boolean;
consumerRtpMapping?: ortc.ConsumerRtpMapping;
}): number {
const rtpParametersOffset = serializeRtpParameters(builder, rtpParameters);
const consumerIdOffset = builder.createString(consumerId);
Expand Down Expand Up @@ -1389,6 +1410,15 @@ function createConsumeRequest({
FbsConsumer.ConsumerLayers.endConsumerLayers(builder);
}

let consumerRtpMappingOffset: number | undefined;

if (consumerRtpMapping) {
consumerRtpMappingOffset = ortc.serializeConsumerRtpMapping(
builder,
consumerRtpMapping
);
}

const ConsumeRequest = FbsTransport.ConsumeRequest;

// Create Consume Request.
Expand Down Expand Up @@ -1420,6 +1450,10 @@ function createConsumeRequest({

ConsumeRequest.addIgnoreDtx(builder, Boolean(ignoreDtx));

if (consumerRtpMappingOffset !== undefined) {
ConsumeRequest.addConsumerRtpMapping(builder, consumerRtpMappingOffset);
}

return ConsumeRequest.endConsumeRequest(builder);
}

Expand Down
Loading