Bug 1277188. Part 2 - fix AudioStream::GetPositionInFrames(). r=kinetik.
MozReview-Commit-ID: 3NhoRCPu8fU
--- 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;