diff --git a/modules/qualitycontrol/QualityController.ts b/modules/qualitycontrol/QualityController.ts index d6dc75945e..19e0f3faeb 100644 --- a/modules/qualitycontrol/QualityController.ts +++ b/modules/qualitycontrol/QualityController.ts @@ -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)) { @@ -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, diff --git a/modules/sdp/SDP.js b/modules/sdp/SDP.js index 4f1bc21243..f8256e57bc 100644 --- a/modules/sdp/SDP.js +++ b/modules/sdp/SDP.js @@ -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. * @@ -95,15 +117,7 @@ export default class SDP { updatedMidIndices.push(idx); if (isAdd) { - let updatedMsid = msid; - - // If the msid is not in the 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`; @@ -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); @@ -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') { @@ -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`; // // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec though @@ -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}`; }