Bug 1549642 - handle cue with negative duration. r=jya
authoralwu <alwu@mozilla.com>
Wed, 08 May 2019 18:09:56 +0000
changeset 531944 175f567cd163eb70fd015e585bb0ae74f60c2cfe
parent 531943 304294b29dae2db6e398ed5693d5a65821812c0d
child 531945 876559fca157d87c6b39f57ee4995dc09fff0db2
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1549642
milestone68.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 1549642 - handle cue with negative duration. r=jya According to the spec [1], the cue's end time might be negative and be smaller than its start time. In this case, when we reach the cue's start on the media time line, we should treat it as a `missing cue` (which won't be actually displayed, but will receive events) when we run the `TimeMarchesOn`. Therefore, we have to add this kind of cue into `otherCue` and let `TimeMarchesOn` handles it properly, to dispatch `enter` and `exit` event for it. [1] https://html.spec.whatwg.org/multipage/media.html#text-track-cue-end-time Differential Revision: https://phabricator.services.mozilla.com/D30242
dom/media/TextTrack.cpp
testing/web-platform/meta/html/semantics/embedded-content/media-elements/track/track-element/track-cue-negative-duration.html.ini
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -313,21 +313,28 @@ void TextTrack::GetCurrentCuesAndOtherCu
   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) {
       WEBVTT_LOG("Add cue %p [%f:%f] to current cue list", cue,
                  cue->StartTime(), cue->EndTime());
       aCurrentCues->AddCue(*cue);
     } else {
-      // Negative length cue, which is possible because user can set cue's end
-      // time arbitrary.
+      // As the spec didn't have a restriction for the negative duration, it
+      // does happen sometime if user sets it explictly. It would be treated as
+      // a `missing cue` later in the `TimeMarchesOn` but it won't be displayed.
       if (cue->EndTime() < cue->StartTime()) {
-        WEBVTT_LOG("[BAD TIME] skip cue %p [%f:%f] with negative length", cue,
-                   cue->StartTime(), cue->EndTime());
+        // Add cue into `otherCue` only when its start time is contained by the
+        // current time interval.
+        if (aInterval.Contains(
+                media::TimeUnit::FromSeconds(cue->StartTime()))) {
+          WEBVTT_LOG("[Negative duration] Add cue %p [%f:%f] to other cue list",
+                     cue, cue->StartTime(), cue->EndTime());
+          aOtherCues->AddCue(*cue);
+        }
         continue;
       }
       media::TimeInterval cueInterval(
           media::TimeUnit::FromSeconds(cue->StartTime()),
           media::TimeUnit::FromSeconds(cue->EndTime()));
       // cues are completely outside the time interval.
       if (!aInterval.Touches(cueInterval)) {
         continue;
deleted file mode 100644
--- a/testing/web-platform/meta/html/semantics/embedded-content/media-elements/track/track-element/track-cue-negative-duration.html.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[track-cue-negative-duration.html]
-  disabled:
-    if not debug and webrender and (os == "linux"): CRASH
-    TIMEOUT
-  [Enter, Exit events for a cue with negative duration]
-    expected: TIMEOUT
-