Bug 1353607. P4 - change the type of mFragmentEndTime to TimeUnit. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 28 Mar 2017 17:14:01 +0800
changeset 557651 ea05e191918813dfe0d722d9a664f8f71e267762
parent 557650 0e0edc3033ba32806080b23b2ad605dd0b9ad348
child 557652 9b6bde5c7577dbbe8f2eea31180c771854b8c277
push id52775
push userjwwang@mozilla.com
push dateFri, 07 Apr 2017 03:28:07 +0000
bugs1353607
milestone55.0a1
Bug 1353607. P4 - change the type of mFragmentEndTime to TimeUnit. MozReview-Commit-ID: FhUZMpXokSt
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2606,17 +2606,16 @@ MediaDecoderStateMachine::MediaDecoderSt
   mAudioChannel(aDecoder->GetAudioChannel()),
   mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
                            /* aSupportsTailDispatch = */ true)),
   mWatchManager(this, mTaskQueue),
   mDispatchedStateMachine(false),
   mDelayedScheduler(mTaskQueue),
   mCurrentFrameID(0),
   INIT_WATCHABLE(mObservedDuration, TimeUnit()),
-  mFragmentEndTime(-1),
   mReader(new MediaDecoderReaderWrapper(mTaskQueue, aReader)),
   mDecodedAudioEndTime(0),
   mDecodedVideoEndTime(0),
   mPlaybackRate(1.0),
   mLowAudioThreshold(detail::LOW_AUDIO_THRESHOLD),
   mAmpleAudioThreshold(detail::AMPLE_AUDIO_THRESHOLD),
   mAudioCaptured(false),
   mMinimizePreroll(aDecoder->GetMinimizePreroll()),
@@ -2930,18 +2929,18 @@ MediaDecoderStateMachine::UpdatePlayback
 }
 
 void
 MediaDecoderStateMachine::UpdatePlaybackPosition(const TimeUnit& aTime)
 {
   MOZ_ASSERT(OnTaskQueue());
   UpdatePlaybackPositionInternal(aTime);
 
-  bool fragmentEnded = mFragmentEndTime >= 0
-    && GetMediaTime().ToMicroseconds() >= mFragmentEndTime;
+  bool fragmentEnded = mFragmentEndTime.IsValid()
+    && GetMediaTime() >= mFragmentEndTime;
   mMetadataManager.DispatchMetadataIfNeeded(aTime);
 
   if (fragmentEnded) {
     StopPlayback();
   }
 }
 
 /* static */ const char*
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -189,17 +189,20 @@ public:
 
   RefPtr<ShutdownPromise> BeginShutdown();
 
   // Set the media fragment end time. aEndTime is in microseconds.
   void DispatchSetFragmentEndTime(int64_t aEndTime)
   {
     RefPtr<MediaDecoderStateMachine> self = this;
     nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([self, aEndTime] () {
-      self->mFragmentEndTime = aEndTime;
+      // A negative number means we don't have a fragment end time at all.
+      self->mFragmentEndTime = aEndTime >= 0
+        ? media::TimeUnit::FromMicroseconds(aEndTime)
+        : media::TimeUnit::Invalid();
     });
     OwnerThread()->Dispatch(r.forget());
   }
 
   // Drop reference to mResource. Only called during shutdown dance.
   void BreakCycles() {
     MOZ_ASSERT(NS_IsMainThread());
     mResource = nullptr;
@@ -535,18 +538,18 @@ private:
   // The decoder monitor must be held.
   bool IsLogicallyPlaying()
   {
     MOZ_ASSERT(OnTaskQueue());
     return mPlayState == MediaDecoder::PLAY_STATE_PLAYING
            || mNextPlayState == MediaDecoder::PLAY_STATE_PLAYING;
   }
 
-  // Media Fragment end time in microseconds. Access controlled by decoder monitor.
-  int64_t mFragmentEndTime;
+  // Media Fragment end time.
+  media::TimeUnit mFragmentEndTime = media::TimeUnit::Invalid();
 
   // The media sink resource.  Used on the state machine thread.
   RefPtr<media::MediaSink> mMediaSink;
 
   const RefPtr<MediaDecoderReaderWrapper> mReader;
 
   // The end time of the last audio frame that's been pushed onto the media sink
   // in microseconds. This will approximately be the end time