Bug 1433576 - bring rtp sources js timestamp and timebase up to spec draft
authorNico Grunbaum
Fri, 26 Jan 2018 13:40:30 -0800
changeset 747812 8ed92dd6539691e21db60cfd3ae1e90f4ca1616e
parent 747775 27b20570829c64552fc1d645bf5aa45950110b7a
push id97016
push userna-g@nostrum.com
push dateFri, 26 Jan 2018 22:09:15 +0000
bugs1433576
milestone60.0a1
Bug 1433576 - bring rtp sources js timestamp and timebase up to spec MozReview-Commit-ID: 2joFQ41NaMp
dom/media/PeerConnection.js
dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -1269,17 +1269,17 @@ class RTCPeerConnection {
       Promise.resolve().then(() => {
         this._rtpSourceCache = new RTCRtpSourceCache();
       });
     }
     // Fetch the RTP source local time, store it for reuse, calculate
     // the local offset, likewise store it for reuse.
     if (cache.tsNowInRtpSourceTime !== undefined) {
       cache.tsNowInRtpSourceTime = this._impl.getNowInRtpSourceReferenceTime();
-      cache.jsTimestamp = new Date().getTime();
+      cache.jsTimestamp = this._win.performance.now() + this._win.performance.timeOrigin;
       cache.timestampOffset = cache.jsTimestamp - cache.tsNowInRtpSourceTime;
     }
     let id = receiver.track.id;
     if (cache.rtpSourcesByTrackId[id] === undefined) {
       cache.rtpSourcesByTrackId[id] =
           this._impl.getRtpSources(receiver.track, cache.tsNowInRtpSourceTime);
     }
     return {
--- a/dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
+++ b/dom/media/tests/mochitest/test_peerConnection_audioSynchronizationSources.html
@@ -36,18 +36,20 @@
       is(syncSources.length, 1, "Each receiver has only a single sync source");
       let source = recv.getSynchronizationSources()[0];
       ok(source.audioLevel,
          `Synchronization source has audio level. (${source.audioLevel})`);
       ok(source.audioLevel < 128,
          `Synchronization source audio level < 128. (${source.audioLevel})`);
       ok(source.timestamp,
          `Synchronization source has timestamp (${source.timestamp})`);
-      ok(Number.isInteger(source.timestamp),
-        `Synchronization source timestamp is int (${source.timestamp})`);
+      ok(window.performance.now() + window.performance.timeOrigin -
+         source.timestamp < 2500, // This large value is used because sometimes
+                                  // the testing hardware is _very_ slow
+         `Synchronization source timestamp is close to now`);
       is(source.voiceActivityFlag, undefined,
         "Synchronization source unsupported voiceActivity is undefined");
     }
   };
 
   var testSynchronizationSourceCached = async (test) => {
     await waitForSyncSources(test);
     let receivers = [...test.pcRemote.getReceivers(),