Bug 1277188. Part 1 - fix AudioStream::GetPosition(). r=kinetik.
MozReview-Commit-ID: ECGPX04hM6U
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -468,17 +468,18 @@ AudioStream::Shutdown()
mState = SHUTDOWN;
}
int64_t
AudioStream::GetPosition()
{
MonitorAutoLock mon(mMonitor);
- return mAudioClock.GetPositionUnlocked();
+ int64_t frames = GetPositionInFramesUnlocked();
+ return frames >= 0 ? mAudioClock.GetPosition(frames) : -1;
}
int64_t
AudioStream::GetPositionInFrames()
{
MonitorAutoLock mon(mMonitor);
return mAudioClock.GetPositionInFrames();
}
@@ -671,16 +672,21 @@ int64_t AudioClock::GetPositionUnlocked(
return frames >= 0 ? mFrameHistory->GetPosition(frames) : -1;
}
int64_t AudioClock::GetPositionInFrames() const
{
return (GetPositionUnlocked() * mInRate) / USECS_PER_S;
}
+int64_t AudioClock::GetPosition(int64_t frames) const
+{
+ return mFrameHistory->GetPosition(frames);
+}
+
void AudioClock::SetPlaybackRateUnlocked(double aPlaybackRate)
{
mOutRate = static_cast<uint32_t>(mInRate / aPlaybackRate);
}
double AudioClock::GetPlaybackRate() const
{
return static_cast<double>(mInRate) / mOutRate;
--- a/dom/media/AudioStream.h
+++ b/dom/media/AudioStream.h
@@ -45,16 +45,24 @@ public:
// 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 microseconds of the stream,
+ * adjusted by playback rate changes and underrun frames.
+ */
+ int64_t GetPosition(int64_t frames) const;
+
// Set the playback rate.
// Called on the audio thread.
// Assumes the AudioStream lock is held and thus calls Unlocked versions
// of AudioStream funcs.
void SetPlaybackRateUnlocked(double aPlaybackRate);
// Get the current playback rate.
// Called on the audio thread.
double GetPlaybackRate() const;