Bug 1352319. P8 - use TimeUnit in UpdatePlaybackPosition(). draft
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Mar 2017 16:01:55 +0800
changeset 554257 a69e913e906c619f0f829b7829df21ee7d38eb77
parent 554256 af1d04fc198e61e2d0bef5899d546af90bbee6ce
child 554258 213b4b7990665925643ff2ae48f0a5dd38320ff3
push id51883
push userjwwang@mozilla.com
push dateFri, 31 Mar 2017 09:16:07 +0000
bugs1352319
milestone55.0a1
Bug 1352319. P8 - use TimeUnit in UpdatePlaybackPosition(). MozReview-Commit-ID: JkopzDG45Bq
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1855,17 +1855,17 @@ public:
     // StopPlayback in order to reset the IsPlaying() state so audio
     // is restarted correctly.
     mMaster->StopPlayback();
 
     if (!mSentPlaybackEndedEvent) {
       auto clockTime =
         std::max(mMaster->AudioEndTime(), mMaster->VideoEndTime());
       clockTime = std::max(clockTime, mMaster->Duration());
-      mMaster->UpdatePlaybackPosition(clockTime.ToMicroseconds());
+      mMaster->UpdatePlaybackPosition(clockTime);
 
       // Ensure readyState is updated before firing the 'ended' event.
       mMaster->UpdateNextFrameStatus(MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE);
 
       mMaster->mOnPlaybackEvent.Notify(MediaEventType::PlaybackEnded);
 
       mSentPlaybackEndedEvent = true;
 
@@ -2920,24 +2920,25 @@ MediaDecoderStateMachine::UpdatePlayback
   LOGV("UpdatePlaybackPositionInternal(%" PRId64 ")", aTime.ToMicroseconds());
 
   mCurrentPosition = aTime.ToMicroseconds();
   NS_ASSERTION(mCurrentPosition >= 0, "CurrentTime should be positive!");
   mObservedDuration = std::max(mObservedDuration.Ref(),
                                TimeUnit::FromMicroseconds(mCurrentPosition.Ref()));
 }
 
-void MediaDecoderStateMachine::UpdatePlaybackPosition(int64_t aTime)
+void
+MediaDecoderStateMachine::UpdatePlaybackPosition(const TimeUnit& aTime)
 {
   MOZ_ASSERT(OnTaskQueue());
-  UpdatePlaybackPositionInternal(TimeUnit::FromMicroseconds(aTime));
+  UpdatePlaybackPositionInternal(aTime);
 
   bool fragmentEnded =
     mFragmentEndTime >= 0 && GetMediaTime() >= mFragmentEndTime;
-  mMetadataManager.DispatchMetadataIfNeeded(TimeUnit::FromMicroseconds(aTime));
+  mMetadataManager.DispatchMetadataIfNeeded(aTime);
 
   if (fragmentEnded) {
     StopPlayback();
   }
 }
 
 /* static */ const char*
 MediaDecoderStateMachine::ToStateStr(State aState)
@@ -3529,17 +3530,17 @@ MediaDecoderStateMachine::UpdatePlayback
 
     // These will be non -1 if we've displayed a video frame, or played an audio
     // frame.
     auto maxEndTime = std::max(VideoEndTime(), AudioEndTime());
     int64_t t = std::min(clockTime, maxEndTime.ToMicroseconds());
     // FIXME: Bug 1091422 - chained ogg files hit this assertion.
     //MOZ_ASSERT(t >= GetMediaTime());
     if (t > GetMediaTime()) {
-      UpdatePlaybackPosition(t);
+      UpdatePlaybackPosition(TimeUnit::FromMicroseconds(t));
     }
   }
   // Note we have to update playback position before releasing the monitor.
   // Otherwise, MediaDecoder::AddOutputStream could kick in when we are outside
   // the monitor and get a staled value from GetCurrentTimeUs() which hits the
   // assertion in GetClock().
 
   int64_t delay = std::max<int64_t>(1, AUDIO_DURATION_USECS / mPlaybackRate);
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -272,17 +272,17 @@ private:
 
   RefPtr<ShutdownPromise> FinishShutdown();
 
   // Update the playback position. This can result in a timeupdate event
   // and an invalidate of the frame being dispatched asynchronously if
   // there is no such event currently queued.
   // Only called on the decoder thread. Must be called with
   // the decode monitor held.
-  void UpdatePlaybackPosition(int64_t aTime);
+  void UpdatePlaybackPosition(const media::TimeUnit& aTime);
 
   bool CanPlayThrough();
 
   MediaStatistics GetStatistics();
 
   bool HasAudio() const { return mInfo.ref().HasAudio(); }
   bool HasVideo() const { return mInfo.ref().HasVideo(); }
   const MediaInfo& Info() const { return mInfo.ref(); }