Skip to content

Commit

Permalink
fix(SDP) Add trackID if its missing in msid. (#2667)
Browse files Browse the repository at this point in the history
* fix(SDP) Add missing trackID if its missing in msid.
This is needed for older versions of Chrome. Also skip performance optimizations if encode resolution is missing in the stats.

* squash: address review comments
  • Loading branch information
jallamsetty1 authored Feb 25, 2025
1 parent 6e9b9c0 commit f5964f9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
8 changes: 6 additions & 2 deletions modules/qualitycontrol/QualityController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,12 @@ export class QualityController {
if (!this._enableAdaptiveMode) {
return;
}

const { encodeResolution, localTrack, qualityLimitationReason, tpc } = sourceStats;

// Older browser versions might not report the resolution in the stats.
if (Number.isNaN(encodeResolution)) {
return;
}
const trackId = localTrack.rtcId;

if (encodeResolution === tpc.calculateExpectedSendResolution(localTrack)) {
Expand Down Expand Up @@ -382,7 +386,7 @@ export class QualityController {
const track = tpc.getTrackBySSRC(ssrc);
const trackId = track.rtcId;
let existingStats = statsPerTrack.get(trackId);
const encodeResolution = Math.min(resolution.height, resolution.width);
const encodeResolution = Math.min(resolution?.height, resolution?.width);
const ssrcStats = {
encodeResolution,
encodeTime,
Expand Down
44 changes: 34 additions & 10 deletions modules/sdp/SDP.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ export default class SDP {
this.removeUdpCandidates = false;
}

/**
* Adjusts the msid semantic for a remote source based on the media type and the index of the m-line.
* This is needed for browsers that need both the streamId and trackId to be reported in the msid attribute.
*
* @param {String} msid - The msid attribute value.
* @param {Number} idx - The index of the m-line in the SDP.
* @returns {String} - The adjusted msid semantic.
*/
_adjustMsidSemantic(msid, mediaType, idx) {
if (mediaType === MediaType.AUDIO || !browser.isChromiumBased() || browser.isEngineVersionGreaterThan(116)) {
return msid;
}

const msidParts = msid.split(' ');

if (msidParts.length === 2) {
return msid;
}

return `${msid} ${msid}-${idx}`;
}

/**
* Updates the media and session sections of the SDP based on the raw SDP string.
*
Expand Down Expand Up @@ -95,15 +117,7 @@ export default class SDP {
updatedMidIndices.push(idx);

if (isAdd) {
let updatedMsid = msid;

// If the msid is not in the <stream ID> <track ID> format, create msid in that format.
// Chrome's older versions (upto 117) expect the msid to be in this format.
if (msid.split(' ').length !== 2
&& browser.isChromiumBased()
&& browser.isEngineVersionLessThan(117)) {
updatedMsid = `${msid} ${msid}-${idx}`;
}
const updatedMsid = this._adjustMsidSemantic(msid, mediaType, idx);

ssrcList.forEach(ssrc => {
this.media[idx] += `a=ssrc:${ssrc} msid:${updatedMsid}\r\n`;
Expand Down Expand Up @@ -259,12 +273,18 @@ export default class SDP {
const group = mLine.ssrcGroups?.find(g => g.ssrcs.includes(ssrcId));

if (group) {
if (ssrc.attribute === 'msid') {
ssrc.value = this._adjustMsidSemantic(ssrc.value, type, newMline.mid);
}
newMline.ssrcs.push(ssrc);
const otherSsrc = group.ssrcs.split(' ').find(s => s !== ssrcId);

if (otherSsrc) {
const otherSource = mLine.ssrcs.find(source => source.id.toString() === otherSsrc);

if (otherSource.attribute === 'msid') {
otherSource.value = this._adjustMsidSemantic(otherSource.value, type, newMline.mid);
}
newMline.ssrcs.push(otherSource);
}
newMline.ssrcGroups.push(group);
Expand Down Expand Up @@ -373,6 +393,7 @@ export default class SDP {
let sdp = '';
const sctp = transport.find(`>sctpmap[xmlns='${XEP.SCTP_DATA_CHANNEL}']`);
const media = { media: desc.attr('media') };
const mid = content.attr('name');

media.port = '9';
if (content.attr('senders') === 'rejected') {
Expand Down Expand Up @@ -445,7 +466,7 @@ export default class SDP {
sdp += `a=${MediaDirection.SENDRECV}\r\n`;
break;
}
sdp += `a=mid:${content.attr('name')}\r\n`;
sdp += `a=mid:${mid}\r\n`;

// <description><rtcp-mux/></description>
// see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec though
Expand Down Expand Up @@ -516,6 +537,9 @@ export default class SDP {
value = SDPUtil.filterSpecialChars(value);
sourceStr += `a=ssrc:${ssrc} ${name}`;

if (name === 'msid') {
value = this._adjustMsidSemantic(value, media.media, mid);
}
if (value && value.length) {
sourceStr += `:${value}`;
}
Expand Down

0 comments on commit f5964f9

Please sign in to comment.