Bug 1289004. Part 3 - Remove MediaDecoder::mShuttingDown. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Wed, 13 Jul 2016 16:48:27 +0800
changeset 348629 6bb2750914173c6c7a54818cd62b88d6b4101695
parent 348628 412d21e8fddc02f2ca64d42e075176dd22bd1459
child 348630 5598fd36f3d444e91938dbbfe0c150cd49f9cb28
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1289004
milestone50.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 1289004. Part 3 - Remove MediaDecoder::mShuttingDown. r=cpearce MozReview-Commit-ID: DoJ4UFuyz2h
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -320,17 +320,16 @@ MediaDecoder::IsHeuristicDormantSupporte
 
 void
 MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (IsShutdown() ||
       !mDecoderStateMachine ||
-      mPlayState == PLAY_STATE_SHUTDOWN ||
       !mOwner->GetVideoFrameContainer() ||
       (mOwner->GetMediaElement() && mOwner->GetMediaElement()->IsBeingDestroyed()) ||
       !mDormantSupported)
   {
     return;
   }
 
   DECODER_LOG("UpdateDormantState aTimeout=%d aActivity=%d mIsDormant=%d "
@@ -420,22 +419,23 @@ MediaDecoder::CancelDormantTimer()
     mDormantTimer->Cancel();
   }
 }
 
 void
 MediaDecoder::Pause()
 {
   MOZ_ASSERT(NS_IsMainThread());
-  if (mPlayState == PLAY_STATE_LOADING ||
-      IsEnded()) {
+  if (IsShutdown()) {
+    return;
+  }
+  if (mPlayState == PLAY_STATE_LOADING || IsEnded()) {
     mNextState = PLAY_STATE_PAUSED;
     return;
   }
-
   ChangeState(PLAY_STATE_PAUSED);
 }
 
 void
 MediaDecoder::SetVolume(double aVolume)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mVolume = aVolume;
@@ -499,17 +499,16 @@ MediaDecoder::MediaDecoder(MediaDecoderO
 #endif
   , mIgnoreProgressData(false)
   , mInfiniteStream(false)
   , mOwner(aOwner)
   , mFrameStats(new FrameStatistics())
   , mVideoFrameContainer(aOwner->GetVideoFrameContainer())
   , mPlaybackStatistics(new MediaChannelStatistics())
   , mPinnedForSeek(false)
-  , mShuttingDown(false)
   , mPausedForPlaybackRateNull(false)
   , mMinimizePreroll(false)
   , mMediaTracksConstructed(false)
   , mFiredMetadataLoaded(false)
   , mIsDormant(false)
   , mIsHeuristicDormantSupported(
       Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false))
   , mHeuristicDormantTimeout(
@@ -606,18 +605,16 @@ void
 MediaDecoder::Shutdown()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (IsShutdown()) {
     return;
   }
 
-  mShuttingDown = true;
-
   // Unwatch all watch targets to prevent further notifications.
   mWatchManager.Shutdown();
 
   mResourceCallback->Disconnect();
 
 #ifdef MOZ_EME
   mCDMProxyPromiseHolder.RejectIfExists(true, __func__);
 #endif
@@ -1073,17 +1070,17 @@ MediaDecoder::IsSeeking() const
   MOZ_ASSERT(NS_IsMainThread());
   return mLogicallySeeking;
 }
 
 bool
 MediaDecoder::IsEndedOrShutdown() const
 {
   MOZ_ASSERT(NS_IsMainThread());
-  return IsEnded() || mPlayState == PLAY_STATE_SHUTDOWN;
+  return IsEnded() || IsShutdown();
 }
 
 bool
 MediaDecoder::OwnerHasError() const
 {
   MOZ_ASSERT(NS_IsMainThread());
   return IsShutdown() || mOwner->HasError();
 }
@@ -1122,17 +1119,17 @@ MediaDecoder::IsEnded() const
   MOZ_ASSERT(NS_IsMainThread());
   return mPlayState == PLAY_STATE_ENDED;
 }
 
 bool
 MediaDecoder::IsShutdown() const
 {
   MOZ_ASSERT(NS_IsMainThread());
-  return mShuttingDown;
+  return mPlayState == PLAY_STATE_SHUTDOWN;
 }
 
 void
 MediaDecoder::PlaybackEnded()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (IsShutdown() ||
@@ -1336,25 +1333,22 @@ MediaDecoder::SeekingStarted(MediaDecode
     mOwner->SeekStarted();
   }
 }
 
 void
 MediaDecoder::ChangeState(PlayState aState)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(!IsShutdown(), "SHUTDOWN is the final state.");
 
   if (mNextState == aState) {
     mNextState = PLAY_STATE_PAUSED;
   }
 
-  if (mPlayState == PLAY_STATE_SHUTDOWN) {
-    return;
-  }
-
   DECODER_LOG("ChangeState %s => %s", PlayStateStr(), ToPlayStateStr(aState));
   mPlayState = aState;
 
   if (mPlayState == PLAY_STATE_PLAYING) {
     ConstructMediaTracks();
   } else if (IsEnded()) {
     RemoveMediaTracks();
   }
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -679,22 +679,16 @@ protected:
   // this estimate is "decode time" (where the "current time" is the
   // time of the last decoded video frame).
   RefPtr<MediaChannelStatistics> mPlaybackStatistics;
 
   // True when our media stream has been pinned. We pin the stream
   // while seeking.
   bool mPinnedForSeek;
 
-  // True if the decoder is being shutdown. At this point all events that
-  // are currently queued need to return immediately to prevent javascript
-  // being run that operates on the element and decoder during shutdown.
-  // Read/Write from the main thread only.
-  bool mShuttingDown;
-
   // True if the playback is paused because the playback rate member is 0.0.
   bool mPausedForPlaybackRateNull;
 
   // Be assigned from media element during the initialization and pass to
   // AudioStream Class.
   dom::AudioChannel mAudioChannel;
 
   // True if the decoder has been directed to minimize its preroll before