Bug 1277776 - Use SaferMultDiv in AudioClock::GetPositionInFrames(). r=jya.
authorJW Wang <jwwang@mozilla.com>
Mon, 06 Jun 2016 11:13:34 +0800
changeset 300500 57bdeb9f1eca2a87dba18150e93129dcc1f8d4e9
parent 300499 925a96e53262fabe127d2a6405f98438d18cff6b
child 300501 76b6cebf4b36eb64120c91ba0f536e6fd845bafe
push id77986
push userjwwang@mozilla.com
push dateMon, 06 Jun 2016 03:25:24 +0000
treeherdermozilla-inbound@57bdeb9f1eca [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1277776
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 1277776 - Use SaferMultDiv in AudioClock::GetPositionInFrames(). r=jya. MozReview-Commit-ID: 711czooNf55
dom/media/AudioStream.cpp
dom/media/AudioStream.h
--- 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;