Bug 1277188. Part 2 - fix AudioStream::GetPositionInFrames(). r=kinetik.
authorJW Wang <jwwang@mozilla.com>
Wed, 01 Jun 2016 16:18:56 +0800
changeset 339308 79f157a49a16cdb1b00716146b3537f7ce2b9797
parent 339307 2692780925cf8bd1990144318bd54e72f4fc05f4
child 339309 76384d9681f05f0ecbf441da86f488263b76523f
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1277188
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1277188. Part 2 - fix AudioStream::GetPositionInFrames(). r=kinetik. MozReview-Commit-ID: 3NhoRCPu8fU
dom/media/AudioStream.cpp
dom/media/AudioStream.h
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -476,17 +476,18 @@ AudioStream::GetPosition()
   int64_t frames = GetPositionInFramesUnlocked();
   return frames >= 0 ? mAudioClock.GetPosition(frames) : -1;
 }
 
 int64_t
 AudioStream::GetPositionInFrames()
 {
   MonitorAutoLock mon(mMonitor);
-  return mAudioClock.GetPositionInFrames();
+  int64_t frames = GetPositionInFramesUnlocked();
+  return frames >= 0 ? mAudioClock.GetPositionInFrames(frames) : -1;
 }
 
 int64_t
 AudioStream::GetPositionInFramesUnlocked()
 {
   mMonitor.AssertCurrentThreadOwns();
 
   if (mState == ERRORED) {
@@ -667,19 +668,19 @@ void AudioClock::UpdateFrameHistory(uint
 int64_t AudioClock::GetPositionUnlocked() const
 {
   // GetPositionInFramesUnlocked() asserts it owns the monitor
   int64_t frames = mAudioStream->GetPositionInFramesUnlocked();
   NS_ASSERTION(frames < 0 || (mInRate != 0 && mOutRate != 0), "AudioClock not initialized.");
   return frames >= 0 ? mFrameHistory->GetPosition(frames) : -1;
 }
 
-int64_t AudioClock::GetPositionInFrames() const
+int64_t AudioClock::GetPositionInFrames(int64_t frames) const
 {
-  return (GetPositionUnlocked() * mInRate) / USECS_PER_S;
+  return (GetPosition(frames) * mInRate) / USECS_PER_S;
 }
 
 int64_t AudioClock::GetPosition(int64_t frames) const
 {
   return mFrameHistory->GetPosition(frames);
 }
 
 void AudioClock::SetPlaybackRateUnlocked(double aPlaybackRate)
--- a/dom/media/AudioStream.h
+++ b/dom/media/AudioStream.h
@@ -42,19 +42,23 @@ public:
   // Update the number of samples that has been written in the audio backend.
   // Called on the state machine thread.
   void UpdateFrameHistory(uint32_t aServiced, uint32_t aUnderrun);
   // Get the read position of the stream, in microseconds.
   // Called on the state machine thead.
   // Assumes the AudioStream lock is held and thus calls Unlocked versions
   // of AudioStream funcs.
   int64_t GetPositionUnlocked() const;
-  // Get the read position of the stream, in frames.
-  // Called on the state machine thead.
-  int64_t GetPositionInFrames() const;
+
+  /**
+   * @param frames The playback position in frames of the audio engine.
+   * @return The playback position in frames of the stream,
+   *         adjusted by playback rate changes and underrun frames.
+   */
+  int64_t GetPositionInFrames(int64_t frames) const;
 
   /**
    * @param frames The playback position in frames of the audio engine.
    * @return The playback position in microseconds of the stream,
    *         adjusted by playback rate changes and underrun frames.
    */
   int64_t GetPosition(int64_t frames) const;