Bug 1277188. Part 2 - fix AudioStream::GetPositionInFrames(). r=kinetik. draft 1274214_remove_WMFMediaDataDecoder_TaskQueue
authorJW Wang <jwwang@mozilla.com>
Wed, 01 Jun 2016 16:18:56 +0800
branch1274214_remove_WMFMediaDataDecoder_TaskQueue
changeset 374964 d3b177d25a86f03ac65c5231dc389e66cbb5aba5
parent 374963 0a0762173432be070582ea789ea58ca4e63b73cf
child 374965 216e0a7e9909572ad828c262063e348df462a5ef
push id20123
push userjwwang@mozilla.com
push dateFri, 03 Jun 2016 03:02:34 +0000
reviewerskinetik
bugs1277188
milestone49.0a1
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;