Bug 1277776 - Use SaferMultDiv in AudioClock::GetPositionInFrames(). r=jya. draft 1274214_remove_WMFMediaDataDecoder_TaskQueue
authorJW Wang <jwwang@mozilla.com>
Mon, 06 Jun 2016 11:13:34 +0800
branch1274214_remove_WMFMediaDataDecoder_TaskQueue
changeset 375532 cf2ba4ab351775be5ab08a820de9d4a1ac356dac
parent 374967 2a94db443d9696e9f4b1ee5caa4915df69e745af
child 375533 d578e00f15300fbcf1cc41fb5242868a4b31b57d
push id20303
push userjwwang@mozilla.com
push dateMon, 06 Jun 2016 03:24:03 +0000
reviewersjya
bugs1277776
milestone49.0a1
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;