Commit 0fa74e7f authored by Karl Tomlinson's avatar Karl Tomlinson
Browse files

Bug 1804963 get RTPCallerType in AudioContext constructor where window is known non-null r=padenot

parent 4819a4a6
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ AudioContext::AudioContext(nsPIDOMWindowInner* aWindow, bool aIsOffline,
      mSampleRate(GetSampleRateForAudioContext(aIsOffline, aSampleRate)),
      mAudioContextState(AudioContextState::Suspended),
      mNumberOfChannels(aNumberOfChannels),
      mRTPCallerType(aWindow->AsGlobal()->GetRTPCallerType()),
      mIsOffline(aIsOffline),
      mIsStarted(!aIsOffline),
      mIsShutDown(false),
@@ -739,24 +740,21 @@ double AudioContext::CurrentTime() {

  double rawTime = track->TrackTimeToSeconds(track->GetCurrentTime());

  RTPCallerType callerType = GetParentObject()->AsGlobal()->GetRTPCallerType();

  // CurrentTime increments in intervals of 128/sampleRate. If the Timer
  // Precision Reduction is smaller than this interval, the jittered time
  // can always be reversed to the raw step of the interval. In that case
  // we can simply return the un-reduced time; and avoid breaking tests.
  // We have to convert each variable into a common magnitude, we choose ms.
  if ((128 / mSampleRate) * 1000.0 >
      nsRFPService::TimerResolution(callerType) / 1000.0) {
      nsRFPService::TimerResolution(mRTPCallerType) / 1000.0) {
    return rawTime;
  }

  MOZ_ASSERT(GetParentObject()->AsGlobal());
  // The value of a MediaTrack's CurrentTime will always advance forward; it
  // will never reset (even if one rewinds a video.) Therefore we can use a
  // single Random Seed initialized at the same time as the object.
  return nsRFPService::ReduceTimePrecisionAsSecs(
      rawTime, GetRandomTimelineSeed(), callerType);
      rawTime, GetRandomTimelineSeed(), mRTPCallerType);
}

nsISerialEventTarget* AudioContext::GetMainThread() const {
+1 −0
Original line number Diff line number Diff line
@@ -420,6 +420,7 @@ class AudioContext final : public DOMEventTargetHelper,
  RefPtr<BasicWaveFormCache> mBasicWaveFormCache;
  // Number of channels passed in the OfflineAudioContext ctor.
  uint32_t mNumberOfChannels;
  const RTPCallerType mRTPCallerType;
  const bool mIsOffline;
  // true iff realtime or startRendering() has been called.
  bool mIsStarted;
+14 −0
Original line number Diff line number Diff line
<html>
<head>
  <title>
    Test currentTime after browsing context discard
  </title>
</head>
<script>
  const frame = document.createElement('frame');
  document.documentElement.appendChild(frame);
  const ctx = new frame.contentWindow.AudioContext();
  frame.remove();
  ctx.currentTime;
</script>
</html>