Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended consumer options to provide way to override MID. #586

Merged
merged 9 commits into from
Jun 21, 2021
Merged
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
5 changes: 5 additions & 0 deletions lib/Consumer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export declare type ConsumerOptions = {
* by itself.
*/
paused?: boolean;
/**
* The MID for the Consumer. If not specified, a sequentially growing
* number will be assigned.
*/
mid?: string;
/**
* Preferred spatial and temporal layer for simulcast or SVC media sources.
* If unset, the highest ones are selected.
Expand Down
2 changes: 1 addition & 1 deletion lib/Consumer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Transport.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export declare class Transport extends EnhancedEventEmitter {
*
* @virtual
*/
consume({ producerId, rtpCapabilities, paused, preferredLayers, pipe, appData }: ConsumerOptions): Promise<Consumer>;
consume({ producerId, rtpCapabilities, paused, mid, preferredLayers, pipe, appData }: ConsumerOptions): Promise<Consumer>;
/**
* Create a DataProducer.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Transport.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions lib/Transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,14 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
*
* @virtual
*/
async consume({ producerId, rtpCapabilities, paused = false, preferredLayers, pipe = false, appData = {} }) {
async consume({ producerId, rtpCapabilities, paused = false, mid, preferredLayers, pipe = false, appData = {} }) {
logger.debug('consume()');
if (!producerId || typeof producerId !== 'string')
throw new TypeError('missing producerId');
else if (appData && typeof appData !== 'object')
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');
// This may throw.
ortc.validateRtpCapabilities(rtpCapabilities);
const producer = this._getProducerById(producerId);
Expand All @@ -298,11 +300,16 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
const rtpParameters = ortc.getConsumerRtpParameters(producer.consumableRtpParameters, rtpCapabilities, pipe);
// Set MID.
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;
if (mid) {
rtpParameters.mid = mid;
}
else {
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 };
Expand Down
3 changes: 3 additions & 0 deletions rust/src/router/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub struct ConsumerOptions {
/// consuming endpoint even before it's ready to consume it, generating “black” video until the
/// device requests a keyframe by itself.
pub paused: bool,
/// The MID for the Consumer. If not specified, a sequentially growing number will be assigned.
pub mid: Option<String>,
/// Preferred spatial and temporal layer for simulcast or SVC media sources.
/// If `None`, the highest ones are selected.
pub preferred_layers: Option<ConsumerLayers>,
Expand All @@ -95,6 +97,7 @@ impl ConsumerOptions {
paused: false,
preferred_layers: None,
pipe: false,
mid: None,
app_data: AppData::default(),
}
}
Expand Down
Loading