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

fix(ssrc-rewriting) Update the track owner correctly. #2392

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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
44 changes: 22 additions & 22 deletions modules/xmpp/JingleSessionPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -1783,48 +1783,48 @@ export default class JingleSessionPC extends JingleSession {
* @returns {void}
*/
processSourceMap(message, mediaType) {
if (!FeatureFlags.isSsrcRewritingSupported()) {
return;
}
const newSsrcs = [];

for (const src of message.mappedSources) {
// eslint-disable-next-line prefer-const
let { owner, source, ssrc } = src;
const { owner, source, ssrc } = src;
const isNewSsrc = this.peerconnection.addRemoteSsrc(ssrc, source);
let lookupSsrc = ssrc;

if (isNewSsrc) {
newSsrcs.push(src);
logger.debug(`New SSRC signaled ${ssrc}: owner=${owner}, source-name=${source}`);

// Check if there is an old mapping for the given source and clear the owner on the associated track.
const oldSsrc = this.peerconnection.remoteSources.get(source);

if (oldSsrc) {
lookupSsrc = oldSsrc;
owner = undefined;
source = undefined;
}
}
const track = this.peerconnection.getTrackBySSRC(lookupSsrc);
this._signalingLayer.removeSSRCOwners([ oldSsrc ]);
const track = this.peerconnection.getTrackBySSRC(oldSsrc);

if (track) {
logger.debug(`Existing SSRC ${ssrc}: new owner=${owner}, source-name=${source}`);
if (track) {
track.setSourceName(undefined);
track.setOwner(undefined);
track._setVideoType(undefined);
}
}
} else {
logger.debug(`Existing SSRC re-mapped ${ssrc}: new owner=${owner}, source-name=${source}`);
const track = this.peerconnection.getTrackBySSRC(ssrc);

// Update the SSRC owner.
this._signalingLayer.setSSRCOwner(ssrc, owner, source);

// Update the track with all the relevant info.
track.setSourceName(source);
track.setOwner(owner);

// Update the video type based on the type published by peer in its presence.
const { videoType } = this._signalingLayer.getPeerSourceInfo(owner, source);

track._setVideoType(videoType);

// Update the muted state on the track since the presence for this track could have been received
// before the updated source map is received on the bridge channel.
// Update the muted state and the video type on the track since the presence for this track could have
// been received before the updated source map is received on the bridge channel.
const peerMediaInfo = this._signalingLayer.getPeerMediaInfo(owner, mediaType, source);

peerMediaInfo && this.peerconnection._sourceMutedChanged(source, peerMediaInfo.muted);
if (peerMediaInfo) {
track._setVideoType(peerMediaInfo.videoType);
this.peerconnection._sourceMutedChanged(source, peerMediaInfo.muted);
}
}
}

Expand Down