Skip to content

Commit

Permalink
fix(quality-control) Configure encodings for all sources on media ses…
Browse files Browse the repository at this point in the history
…sion creation.

When multi-stream-support is enabled, configure the encodings on all the local video sources.
  • Loading branch information
jallamsetty1 committed Feb 14, 2022
1 parent 436e241 commit 61265e3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
33 changes: 28 additions & 5 deletions modules/qualitycontrol/SendVideoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FeatureFlags from '../flags/FeatureFlags';
import MediaSessionEvents from '../xmpp/MediaSessionEvents';

const logger = getLogger(__filename);
const MAX_LOCAL_RESOLUTION = 2160;

/**
* The class manages send video constraints across media sessions({@link JingleSessionPC}) which belong to
Expand All @@ -24,6 +25,7 @@ export default class SendVideoController {
*/
constructor(conference, rtc) {
this._conference = conference;
this._preferredSendMaxFrameHeight = MAX_LOCAL_RESOLUTION;
this._rtc = rtc;

/**
Expand All @@ -37,12 +39,30 @@ export default class SendVideoController {
session => this._onMediaSessionStarted(session));
this._conference.on(
JitsiConferenceEvents._MEDIA_SESSION_ACTIVE_CHANGED,
() => this._propagateSendMaxFrameHeight());
() => this._configureConstraintsForLocalSources());
this._rtc.on(
RTCEvents.SENDER_VIDEO_CONSTRAINTS_CHANGED,
videoConstraints => this._onSenderConstraintsReceived(videoConstraints));
}

/**
* Configures the video encodings on the local sources when a media connection is established or becomes active.
*
* @returns {Promise<void[]>}
* @private
*/
_configureConstraintsForLocalSources() {
if (FeatureFlags.isSourceNameSignalingEnabled()) {
for (const track of this._rtc.getLocalVideoTracks()) {
const sourceName = track.getSourceName();

sourceName && this._propagateSendMaxFrameHeight(sourceName);
}
} else {
this._propagateSendMaxFrameHeight();
}
}

/**
* Handles the {@link JitsiConferenceEvents.MEDIA_SESSION_STARTED}, that is when the conference creates new media
* session. It doesn't mean it's already active though. For example the JVB connection may be created after
Expand All @@ -56,7 +76,7 @@ export default class SendVideoController {
MediaSessionEvents.REMOTE_VIDEO_CONSTRAINTS_CHANGED,
session => {
if (session === this._conference.getActiveMediaSession()) {
this._propagateSendMaxFrameHeight();
this._configureConstraintsForLocalSources();
}
});
}
Expand All @@ -65,6 +85,8 @@ export default class SendVideoController {
* Propagates the video constraints if they have changed.
*
* @param {Object} videoConstraints - The sender video constraints received from the bridge.
* @returns {Promise<void[]>}
* @private
*/
_onSenderConstraintsReceived(videoConstraints) {
if (FeatureFlags.isSourceNameSignalingEnabled()) {
Expand All @@ -88,7 +110,7 @@ export default class SendVideoController {
}

/**
* Figures out the send video constraint as specified by {@link selectSendMaxFrameHeight} and sets it on all media
* Figures out the send video constraint as specified by {@link _selectSendMaxFrameHeight} and sets it on all media
* sessions for the reasons mentioned in this class description.
*
* @param {string} sourceName - The source for which sender constraints have changed.
Expand All @@ -99,7 +121,7 @@ export default class SendVideoController {
if (FeatureFlags.isSourceNameSignalingEnabled() && !sourceName) {
throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
}
const sendMaxFrameHeight = this.selectSendMaxFrameHeight(sourceName);
const sendMaxFrameHeight = this._selectSendMaxFrameHeight(sourceName);
const promises = [];

if (sendMaxFrameHeight >= 0) {
Expand All @@ -117,8 +139,9 @@ export default class SendVideoController {
*
* @param {string} sourceName - The source for which sender constraints have changed.
* @returns {number|undefined}
* @private
*/
selectSendMaxFrameHeight(sourceName = null) {
_selectSendMaxFrameHeight(sourceName = null) {
if (FeatureFlags.isSourceNameSignalingEnabled() && !sourceName) {
throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
}
Expand Down
18 changes: 14 additions & 4 deletions types/auto/modules/qualitycontrol/SendVideoController.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ export default class SendVideoController {
*/
constructor(conference: any, rtc: any);
_conference: any;
_preferredSendMaxFrameHeight: number;
_rtc: any;
/**
* Source name based sender constraints.
* @type {Map<string, number>};
*/
_sourceSenderConstraints: Map<string, number>;
/**
* Configures the video encodings on the local sources when a media connection is established or becomes active.
*
* @returns {Promise<void[]>}
* @private
*/
private _configureConstraintsForLocalSources;
/**
* Handles the {@link JitsiConferenceEvents.MEDIA_SESSION_STARTED}, that is when the conference creates new media
* session. It doesn't mean it's already active though. For example the JVB connection may be created after
Expand All @@ -34,11 +42,13 @@ export default class SendVideoController {
* Propagates the video constraints if they have changed.
*
* @param {Object} videoConstraints - The sender video constraints received from the bridge.
* @returns {Promise<void[]>}
* @private
*/
_onSenderConstraintsReceived(videoConstraints: any): void;
private _onSenderConstraintsReceived;
_senderVideoConstraints: any;
/**
* Figures out the send video constraint as specified by {@link selectSendMaxFrameHeight} and sets it on all media
* Figures out the send video constraint as specified by {@link _selectSendMaxFrameHeight} and sets it on all media
* sessions for the reasons mentioned in this class description.
*
* @param {string} sourceName - The source for which sender constraints have changed.
Expand All @@ -52,14 +62,14 @@ export default class SendVideoController {
*
* @param {string} sourceName - The source for which sender constraints have changed.
* @returns {number|undefined}
* @private
*/
selectSendMaxFrameHeight(sourceName?: string): number | undefined;
private _selectSendMaxFrameHeight;
/**
* Sets local preference for max send video frame height.
*
* @param {number} maxFrameHeight - the new value to set.
* @returns {Promise<void[]>} - resolved when the operation is complete.
*/
setPreferredSendMaxFrameHeight(maxFrameHeight: number): Promise<void[]>;
_preferredSendMaxFrameHeight: number;
}

0 comments on commit 61265e3

Please sign in to comment.