Bug 1353607. P3 - use TimeUnit in ScheduleStateMachineIn(). draft
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Mar 2017 17:10:59 +0800
changeset 557650 0e0edc3033ba32806080b23b2ad605dd0b9ad348
parent 557649 9caf26301417702174bcc87caebf96d66843ff54
child 557651 ea05e191918813dfe0d722d9a664f8f71e267762
push id52775
push userjwwang@mozilla.com
push dateFri, 07 Apr 2017 03:28:07 +0000
bugs1353607
milestone55.0a1
Bug 1353607. P3 - use TimeUnit in ScheduleStateMachineIn(). MozReview-Commit-ID: 5mfquK9TiDa
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1708,17 +1708,17 @@ public:
 
     MediaStatistics stats = mMaster->GetStatistics();
     SLOG("Playback rate: %.1lfKB/s%s download rate: %.1lfKB/s%s",
          stats.mPlaybackRate / 1024,
          stats.mPlaybackRateReliable ? "" : " (unreliable)",
          stats.mDownloadRate / 1024,
          stats.mDownloadRateReliable ? "" : " (unreliable)");
 
-    mMaster->ScheduleStateMachineIn(USECS_PER_S);
+    mMaster->ScheduleStateMachineIn(TimeUnit::FromMicroseconds(USECS_PER_S));
 
     mMaster->UpdateNextFrameStatus(
       MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING);
   }
 
   void Step() override;
 
   State GetState() const override
@@ -2472,17 +2472,17 @@ BufferingState::Step()
     bool isLiveStream = Resource()->IsLiveStream();
     if ((isLiveStream || !mMaster->CanPlayThrough())
         && elapsed
            < TimeDuration::FromSeconds(mBufferingWait * mMaster->mPlaybackRate)
         && mMaster->HasLowBufferedData(TimeUnit::FromSeconds(mBufferingWait))
         && IsExpectingMoreData()) {
       SLOG("Buffering: wait %ds, timeout in %.3lfs",
            mBufferingWait, mBufferingWait - elapsed.ToSeconds());
-      mMaster->ScheduleStateMachineIn(USECS_PER_S);
+      mMaster->ScheduleStateMachineIn(TimeUnit::FromMicroseconds(USECS_PER_S));
       DispatchDecodeTasksIfNeeded();
       return;
     }
   } else if (mMaster->OutOfDecodedAudio() || mMaster->OutOfDecodedVideo()) {
     DispatchDecodeTasksIfNeeded();
     MOZ_ASSERT(!mMaster->OutOfDecodedAudio()
                || mMaster->IsRequestingAudioData()
                || mMaster->IsWaitingAudioData());
@@ -3542,17 +3542,17 @@ MediaDecoderStateMachine::UpdatePlayback
     }
   }
   // 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);
-  ScheduleStateMachineIn(delay);
+  ScheduleStateMachineIn(TimeUnit::FromMicroseconds(delay));
 }
 
 /* static */ const char*
 MediaDecoderStateMachine::ToStr(NextFrameStatus aStatus)
 {
   switch (aStatus) {
     case MediaDecoderOwner::NEXT_FRAME_AVAILABLE:
       return "NEXT_FRAME_AVAILABLE";
@@ -3610,28 +3610,27 @@ MediaDecoderStateMachine::ScheduleStateM
   }
   mDispatchedStateMachine = true;
 
   OwnerThread()->Dispatch(
     NewRunnableMethod(this, &MediaDecoderStateMachine::RunStateMachine));
 }
 
 void
-MediaDecoderStateMachine::ScheduleStateMachineIn(int64_t aMicroseconds)
+MediaDecoderStateMachine::ScheduleStateMachineIn(const TimeUnit& aTime)
 {
   MOZ_ASSERT(OnTaskQueue()); // mDelayedScheduler.Ensure() may Disconnect()
                              // the promise, which must happen on the state
                              // machine task queue.
-  MOZ_ASSERT(aMicroseconds > 0);
+  MOZ_ASSERT(aTime > TimeUnit::Zero());
   if (mDispatchedStateMachine) {
     return;
   }
 
-  TimeStamp now = TimeStamp::Now();
-  TimeStamp target = now + TimeDuration::FromMicroseconds(aMicroseconds);
+  TimeStamp target = TimeStamp::Now() + aTime.ToTimeDuration();
 
   // It is OK to capture 'this' without causing UAF because the callback
   // always happens before shutdown.
   RefPtr<MediaDecoderStateMachine> self = this;
   mDelayedScheduler.Ensure(target, [self] () {
     self->mDelayedScheduler.CompleteRequest();
     self->RunStateMachine();
   }, [] () {
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -288,20 +288,20 @@ private:
   const MediaInfo& Info() const { return mInfo.ref(); }
 
   // Returns the state machine task queue.
   TaskQueue* OwnerThread() const { return mTaskQueue; }
 
   // Schedules the shared state machine thread to run the state machine.
   void ScheduleStateMachine();
 
-  // Invokes ScheduleStateMachine to run in |aMicroseconds| microseconds,
+  // Invokes ScheduleStateMachine to run in |aTime|,
   // unless it's already scheduled to run earlier, in which case the
   // request is discarded.
-  void ScheduleStateMachineIn(int64_t aMicroseconds);
+  void ScheduleStateMachineIn(const media::TimeUnit& aTime);
 
   bool HaveEnoughDecodedAudio();
   bool HaveEnoughDecodedVideo();
 
   // True if shutdown process has begun.
   bool IsShutdown() const;
 
   // Returns true if we're currently playing. The decoder monitor must