Bug 1280814 - Prevent the media::Interval crash due to the unexpected playback position. r=rillian
authorbechen <bechen@mozilla.com>
Mon, 20 Jun 2016 15:58:58 +0800
changeset 302146 0cefc193909c8878ca39cae149a36f3d08739e82
parent 302145 0aeee92e288e305a6c29a683a48a9c7a5fc7c079
child 302147 eefc9532e7152d0b03e9489af0b54a1df7ea29f8
push id78618
push usercbook@mozilla.com
push dateTue, 21 Jun 2016 07:32:37 +0000
treeherdermozilla-inbound@0cefc193909c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1280814
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 1280814 - Prevent the media::Interval crash due to the unexpected playback position. r=rillian MozReview-Commit-ID: AZ9Gb2Y0wDF
dom/html/HTMLMediaElement.cpp
dom/html/TextTrackManager.cpp
dom/html/TextTrackManager.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -792,16 +792,20 @@ void HTMLMediaElement::AbortExistingLoad
     UpdateAudioChannelPlayingState();
   }
 
   // We may have changed mPaused, mAutoplaying, and other
   // things which can affect AddRemoveSelfReference
   AddRemoveSelfReference();
 
   mIsRunningSelectResource = false;
+
+  if (mTextTrackManager) {
+    mTextTrackManager->NotifyReset();
+  }
 }
 
 void HTMLMediaElement::NoSupportedMediaSourceError()
 {
   NS_ASSERTION(mNetworkState == NETWORK_LOADING,
                "Not loading during source selection?");
 
   mError = new MediaError(this, nsIDOMMediaError::MEDIA_ERR_SRC_NOT_SUPPORTED);
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -522,16 +522,21 @@ TextTrackManager::DispatchTimeMarchesOn(
 // https://html.spec.whatwg.org/multipage/embedded-content.html#time-marches-on
 void
 TextTrackManager::TimeMarchesOn()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   mTimeMarchesOnDispatched = false;
 
+  // Early return if we don't have any TextTracks.
+  if (mTextTracks->Length() == 0) {
+    return;
+  }
+
   nsISupports* parentObject =
     mMediaElement->OwnerDoc()->GetParentObject();
   if (NS_WARN_IF(!parentObject)) {
     return;
   }
   nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentObject);
 
   if (mMediaElement &&
@@ -559,16 +564,21 @@ TextTrackManager::TimeMarchesOn()
         for (uint32_t i = 0; i < activeCueList->Length(); ++i) {
           currentCues->AddCue(*((*activeCueList)[i]));
         }
       }
     }
   }
   // Populate otherCues with 'non-active" cues.
   if (hasNormalPlayback) {
+    if (currentPlaybackTime < mLastTimeMarchesOnCalled) {
+      // TODO: Add log and find the root cause why the
+      // playback position goes backward.
+      mLastTimeMarchesOnCalled = currentPlaybackTime;
+    }
     media::Interval<double> interval(mLastTimeMarchesOnCalled,
                                      currentPlaybackTime);
     otherCues = mNewCues->GetCueListByTimeInterval(interval);;
   } else {
     // Seek case. Put the mLastActiveCues into otherCues.
     otherCues = mLastActiveCues;
   }
   for (uint32_t i = 0; i < currentCues->Length(); ++i) {
@@ -713,10 +723,16 @@ TextTrackManager::TimeMarchesOn()
 
 void
 TextTrackManager::NotifyCueUpdated(TextTrackCue *aCue)
 {
   // TODO: Add/Reorder the cue to mNewCues if we have some optimization?
   DispatchTimeMarchesOn();
 }
 
+void
+TextTrackManager::NotifyReset()
+{
+  mLastTimeMarchesOnCalled = 0.0;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/html/TextTrackManager.h
+++ b/dom/html/TextTrackManager.h
@@ -95,16 +95,18 @@ public:
 
   void NotifyShutdown()
   {
     mShutdown = true;
   }
 
   void NotifyCueUpdated(TextTrackCue *aCue);
 
+  void NotifyReset();
+
 private:
   /**
    * Converts the TextTrackCue's cuetext into a tree of DOM objects
    * and attaches it to a div on its owning TrackElement's
    * MediaElement's caption overlay.
    */
   void UpdateCueDisplay();