Bug 1277776 - Use SaferMultDiv in AudioClock::GetPositionInFrames(). r=jya.
MozReview-Commit-ID: 711czooNf55
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -658,19 +658,20 @@ void AudioClock::Init(uint32_t aRate)
mInRate = aRate;
}
void AudioClock::UpdateFrameHistory(uint32_t aServiced, uint32_t aUnderrun)
{
mFrameHistory->Append(aServiced, aUnderrun, mOutRate);
}
-int64_t AudioClock::GetPositionInFrames(int64_t frames) const
+int64_t AudioClock::GetPositionInFrames(int64_t aFrames) const
{
- return (GetPosition(frames) * mInRate) / USECS_PER_S;
+ CheckedInt64 v = UsecsToFrames(GetPosition(aFrames), mInRate);
+ return v.isValid() ? v.value() : -1;
}
int64_t AudioClock::GetPosition(int64_t frames) const
{
return mFrameHistory->GetPosition(frames);
}
void AudioClock::SetPlaybackRate(double aPlaybackRate)
--- a/dom/media/AudioStream.h
+++ b/dom/media/AudioStream.h
@@ -41,21 +41,21 @@ public:
// Need to be called before querying the clock.
void Init(uint32_t aRate);
// 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);
/**
- * @param frames The playback position in frames of the audio engine.
+ * @param aFrames 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;
+ int64_t GetPositionInFrames(int64_t aFrames) 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;