Bug 1280814 - Prevent the media::Interval crash due to the unexpected playback position. r=rillian
MozReview-Commit-ID: AZ9Gb2Y0wDF
--- 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();