Bug 1280814 - Prevent the media::Interval crash due to the unexpected playback position. r=rillian draft
authorbechen <bechen@mozilla.com>
Mon, 20 Jun 2016 15:58:58 +0800
changeset 379977 8ffd8e57f2230c6ba5a478fa423dc325098984a5
parent 379746 5f95858f8ddf21ea2271a12810332efd09eff138
child 380231 bd53fc513f19187c070d06f9032c0934cb45810c
push id21104
push userbechen@mozilla.com
push dateMon, 20 Jun 2016 08:27:07 +0000
reviewersrillian
bugs1280814
milestone50.0a1
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) {
@@ -714,10 +724,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();