Bug 1509446 - part2 : use current cue in 'TimeMarchesOn' algorithm. r=jya
authorAlastor Wu <alwu@mozilla.com>
Thu, 07 Mar 2019 19:21:22 +0000
changeset 520963 fa26e1068b50
parent 520962 3944dae3dabd
child 520964 d1046aea2e0e
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1509446
milestone67.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 1509446 - part2 : use current cue in 'TimeMarchesOn' algorithm. r=jya According to the spec [1], the `current cue` is not equal with the `active cue`, because it might contain non active cues, which might be set to active later during the `TimeMarchesOn`. The `current cue` should be a list of cues, initialized to contain all the cues of all the hidden or showing text tracks of the media element (not the disabled ones) whose start times are less than or equal to the current playback position and whose end times are greater than the current playback position. [1] https://html.spec.whatwg.org/multipage/media.html#time-marches-on Differential Revision: https://phabricator.services.mozilla.com/D22148
dom/html/TextTrackManager.cpp
dom/media/TextTrack.cpp
dom/media/TextTrack.h
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -656,22 +656,17 @@ void TextTrackManager::TimeMarchesOn() {
   // Step 1, 2.
   RefPtr<TextTrackCueList> currentCues = new TextTrackCueList(window);
   RefPtr<TextTrackCueList> otherCues = new TextTrackCueList(window);
   bool dummy;
   for (uint32_t index = 0; index < mTextTracks->Length(); ++index) {
     TextTrack* ttrack = mTextTracks->IndexedGetter(index, dummy);
     if (ttrack && dummy) {
       // TODO: call GetCueListByTimeInterval on mNewCues?
-      TextTrackCueList* activeCueList = ttrack->GetActiveCues();
-      if (activeCueList) {
-        for (uint32_t i = 0; i < activeCueList->Length(); ++i) {
-          currentCues->AddCue(*((*activeCueList)[i]));
-        }
-      }
+      ttrack->GetCurrentCueList(currentCues);
     }
   }
   WEBVTT_LOGV("TimeMarchesOn currentCues %d", currentCues->Length());
   // 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.
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -264,10 +264,34 @@ void TextTrack::NotifyCueActiveStateChan
     MOZ_ASSERT(!mActiveCueList->IsCueExist(aCue));
     mActiveCueList->AddCue(*aCue);
   } else {
     MOZ_ASSERT(mActiveCueList->IsCueExist(aCue));
     mActiveCueList->RemoveCue(*aCue);
   }
 }
 
+void TextTrack::GetCurrentCueList(RefPtr<TextTrackCueList>& aCueList) const {
+  if (!mTextTrackList) {
+    return;
+  }
+
+  const HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
+  if (!mediaElement) {
+    return;
+  }
+
+  // According to `time marches on` step1, current cue list contains the cues
+  // whose start times are less than or equal to the current playback position
+  // and whose end times are greater than the current playback position.
+  // https://html.spec.whatwg.org/multipage/media.html#time-marches-on
+  MOZ_ASSERT(aCueList);
+  const double playbackTime = mediaElement->CurrentTime();
+  for (uint32_t idx = 0; idx < mCueList->Length(); idx++) {
+    TextTrackCue* cue = (*mCueList)[idx];
+    if (cue->StartTime() <= playbackTime && cue->EndTime() > playbackTime) {
+      aCueList->AddCue(*cue);
+    }
+  }
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/media/TextTrack.h
+++ b/dom/media/TextTrack.h
@@ -97,16 +97,21 @@ class TextTrack final : public DOMEventT
   void DispatchAsyncTrustedEvent(const nsString& aEventName);
 
   bool IsLoaded();
 
   // Called when associated cue's active flag has been changed, and then we
   // would add or remove the cue to the active cue list.
   void NotifyCueActiveStateChanged(TextTrackCue* aCue);
 
+  // Use this function to request current cues which start time are less than or
+  // equal to the current playback position and whose end times are greater than
+  // the current playback position.
+  void GetCurrentCueList(RefPtr<TextTrackCueList>& aCueList) const;
+
  private:
   ~TextTrack();
 
   RefPtr<TextTrackList> mTextTrackList;
 
   TextTrackKind mKind;
   nsString mLabel;
   nsString mLanguage;