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(SDP): Generate msid attr for source when browser doesn't produce one. #2471

Merged
merged 1 commit into from
Feb 29, 2024
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
41 changes: 19 additions & 22 deletions modules/sdp/LocalSdpMunger.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,28 @@ export default class LocalSdpMunger {
const msidLine = mediaSection.mLine?.msid;
const sources = [ ...new Set(mediaSection.mLine?.ssrcs?.map(s => s.id)) ];
const streamId = `${this.localEndpointId}-${mediaType}`;
const trackId = msidLine && msidLine.split(' ')[1];
let trackId = msidLine ? msidLine.split(' ')[1] : `${this.localEndpointId}-${mediaSection.mLine.mid}`;

// Always overwrite msid since we want the msid to be in this format even if the browser generates one.
for (const source of sources) {
const msid = mediaSection.ssrcs.find(ssrc => ssrc.id === source && ssrc.attribute === 'msid');

// Update the msid if the 'msid' attribute exists.
if (msid) {
const streamAndTrackIDs = msid.value.split(' ');
const trackID = streamAndTrackIDs[1];

this._updateSourcesToMsidMap(mediaType, streamId, trackID);

// Update the msid.
const storedStreamId = mediaType === MediaType.VIDEO
? this.videoSourcesToMsidMap.get(trackID)
: this.audioSourcesToMsidMap.get(trackID);

msid.value = this._generateMsidAttribute(mediaType, trackID, storedStreamId);
trackId = msid.value.split(' ')[1];
}
this._updateSourcesToMsidMap(mediaType, streamId, trackId);
const storedStreamId = mediaType === MediaType.VIDEO
? this.videoSourcesToMsidMap.get(trackId)
: this.audioSourcesToMsidMap.get(trackId);

// Generate the msid attribute using the 'trackId' from the msid line from the media description. Only
// descriptions that have the direction set to 'sendonly' or 'sendrecv' will have the 'a=msid' line.
} else if (trackId) {
this._updateSourcesToMsidMap(mediaType, streamId, trackId);
const generatedMsid = this._generateMsidAttribute(mediaType, trackId, storedStreamId);

const storedStreamId = mediaType === MediaType.VIDEO
? this.videoSourcesToMsidMap.get(trackId)
: this.audioSourcesToMsidMap.get(trackId);
const generatedMsid = this._generateMsidAttribute(mediaType, trackId, storedStreamId);
// Update the msid if the 'msid' attribute exists.
if (msid) {
msid.value = generatedMsid;

// Generate the 'msid' attribute if there is a local source.
} else if (mediaDirection === MediaDirection.SENDONLY || mediaDirection === MediaDirection.SENDRECV) {
mediaSection.ssrcs.push({
id: source,
attribute: 'msid',
Expand Down Expand Up @@ -167,7 +159,6 @@ export default class LocalSdpMunger {
* (a modified copy of the one given as the input).
*/
transformStreamIdentifiers(sessionDesc) {
// FIXME similar check is probably duplicated in all other transformers
if (!sessionDesc || !sessionDesc.sdp || !sessionDesc.type) {
return sessionDesc;
}
Expand All @@ -187,6 +178,12 @@ export default class LocalSdpMunger {
this._injectSourceNames(videoMLine);
}

// Reset the local tracks based maps for msid after every transformation since Chrome 122 is generating
// a new set of SSRCs for the same source when the direction of transceiver changes because of a remote
// source getting added on the p2p connection.
this.audioSourcesToMsidMap.clear();
this.videoSourcesToMsidMap.clear();

return new RTCSessionDescription({
type: sessionDesc.type,
sdp: transformer.toRawSDP()
Expand Down
Loading