From 59dcd65631f9041aa48e7b2440d6aebc9d0fc517 Mon Sep 17 00:00:00 2001 From: Nico Grunbaum Date: Thu, 2 May 2019 19:57:43 +0000 Subject: [PATCH] Bug 1548097 - sort getContributingSources and getSynchronizationSources results r=jib sort getContributingSources and getSynchronizationSources results Differential Revision: https://phabricator.services.mozilla.com/D29441 --HG-- extra : moz-landing-system : lando --- dom/media/PeerConnection.jsm | 9 ++++----- ...eerConnection_audioContributingSources.html | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dom/media/PeerConnection.jsm b/dom/media/PeerConnection.jsm index 409f0bff50fc..d33c4de6aff7 100644 --- a/dom/media/PeerConnection.jsm +++ b/dom/media/PeerConnection.jsm @@ -2199,13 +2199,13 @@ class RTCRtpReceiver { _getRtpSourcesByType(type) { this._fetchRtpSources(); // Only return the values from within the last 10 seconds as per the spec - let cutoffTime = this._rtpSourcesJsTimestamp - 10 * 1000; - let sources = [...this._rtpSources.values()].filter( + const cutoffTime = this._rtpSourcesJsTimestamp - 10 * 1000; + return [...this._rtpSources.values()].filter( (entry) => { return entry.sourceType == type && (entry.timestamp + entry.sourceClockOffset) >= cutoffTime; }).map(e => { - let newEntry = { + const newEntry = { source: e.source, timestamp: e.timestamp + e.sourceClockOffset, audioLevel: e.audioLevel, @@ -2214,8 +2214,7 @@ class RTCRtpReceiver { Object.assign(newEntry, {voiceActivityFlag: e.voiceActivityFlag}); } return newEntry; - }); - return sources; + }).sort((a, b) => b.timestamp - a.timestamp); } getContributingSources() { diff --git a/dom/media/tests/mochitest/test_peerConnection_audioContributingSources.html b/dom/media/tests/mochitest/test_peerConnection_audioContributingSources.html index 880e0129b985..dcc1e194cd17 100644 --- a/dom/media/tests/mochitest/test_peerConnection_audioContributingSources.html +++ b/dom/media/tests/mochitest/test_peerConnection_audioContributingSources.html @@ -111,6 +111,24 @@ is(JSON.stringify(contributingSources), JSON.stringify(remoteReceiver.getContributingSources()), "getContributingSources is cached"); + // Check that sources are sorted in descending order by time stamp + const timestamp3 = SpWrap(test.pcLocal).mozGetNowInRtpSourceReferenceTime(); + // Larger offsets are further back in time + const testOffsets = [3, 7, 5, 6, 1, 4]; + for (const offset of testOffsets) { + SpWrap(test.pcLocal).mozInsertAudioLevelForContributingSource( + localReceiver, + offset, // Using offset for SSRC for convenience + timestamp3 - offset, + true, + offset); + } + const sources = localReceiver.getContributingSources(); + const sourceOffsets = sources.map(s => s.source); + is(JSON.stringify(sourceOffsets), + JSON.stringify([...testOffsets].sort((a, b) => a - b)), + `Contributing sources are sorted in descending order by timestamp:` + + ` ${JSON.stringify(sources)}`); }; var test;