Title: [291029] trunk
Revision
291029
Author
[email protected]
Date
2022-03-08 19:34:18 -0800 (Tue, 08 Mar 2022)

Log Message

[Cocoa] metadata cue endTime may not be updated
https://bugs.webkit.org/show_bug.cgi?id=237630
rdar://88690874

Reviewed by Jer Noble.

Source/WebCore:

Data cues have a start time but not an explicit duration, a data cue ends when
the next data cue from the same track starts. This means we don’t know the
duration of cue #1 until cue #2 is delivered, so when cue #1 is delivered it is
given the end time of the media file’s duration and the actual end time is updated
when cue #2 arrives.

http://webkit.org/b/229924 refactored text, audio, and video tracks to not depend
on HTMLMediaElement. Because InbandDataTextTrack could no longer access the
HTMLMediaElement to get its duration, a duration property was added to TextTrackList
that InbandDataTextTrack uses to set the duration of temporary cues.
TextTrackList.duration is set when it is created and updated when the media player
reports a duration change.

This means that if the media file’s duration is not known when the text track list
is created, and the file's duration never changes, the text track list never has a
valid duration and data cues were not added to the temporary list.

Fix this by updating TextTrackList.duration when a HTMLMediaElement reaches HAVE_METADATA.

Test: http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::durationChanged): Update m_textTracks.duration and post
the 'durationchange' event.
(WebCore::HTMLMediaElement::setReadyState): Call durationChanged.
(WebCore::HTMLMediaElement::mediaPlayerDurationChanged): Ditto.
* html/HTMLMediaElement.h:

* html/track/InbandDataTextTrack.cpp:
(WebCore::InbandDataTextTrack::addDataCue): Add cues to the incomplete cue map
even if the track list doesn't have duration.

LayoutTests:

* http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt: Added.
* http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (291028 => 291029)


--- trunk/LayoutTests/ChangeLog	2022-03-09 02:58:53 UTC (rev 291028)
+++ trunk/LayoutTests/ChangeLog	2022-03-09 03:34:18 UTC (rev 291029)
@@ -1,3 +1,14 @@
+2022-03-08  Eric Carlson  <[email protected]>
+
+        [Cocoa] metadata cue endTime may not be updated
+        https://bugs.webkit.org/show_bug.cgi?id=237630
+        rdar://88690874
+
+        Reviewed by Jer Noble.
+
+        * http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt: Added.
+        * http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html: Added.
+
 2022-03-08  J Pascoe  <[email protected]>
 
         [WebAuthn] Using WebAuthn within cross-origin iframe elements

Added: trunk/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt (0 => 291029)


--- trunk/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt	2022-03-09 03:34:18 UTC (rev 291029)
@@ -0,0 +1,38 @@
+
+Test that metadata cues have valid duration.
+
+
+** Set video.src, wait for media data to load
+RUN(video.src = ""
+EVENT(addtrack)
+RUN(track = video.textTracks[0])
+RUN(track.mode = "hidden")
+EVENT(canplaythrough)
+
+
+cue 1
+EXPECTED (cue.startTime != 'Infinity') OK
+EXPECTED (cue.endTime != 'Infinity') OK
+
+cue 2
+EXPECTED (cue.startTime != 'Infinity') OK
+EXPECTED (cue.endTime != 'Infinity') OK
+
+cue 3
+EXPECTED (cue.startTime != 'Infinity') OK
+EXPECTED (cue.endTime != 'Infinity') OK
+
+cue 4
+EXPECTED (cue.startTime != 'Infinity') OK
+EXPECTED (cue.endTime != 'Infinity') OK
+
+cue 5
+EXPECTED (cue.startTime != 'Infinity') OK
+EXPECTED (cue.endTime != 'Infinity') OK
+
+cue 6
+EXPECTED (cue.startTime != 'Infinity') OK
+EXPECTED (cue.endTime != 'Infinity') OK
+
+END OF TEST
+

Added: trunk/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html (0 => 291029)


--- trunk/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html	2022-03-09 03:34:18 UTC (rev 291029)
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=""
+        <script src=""
+
+        <script>
+            let cuechangeCount = 0;
+
+            async function start()
+            {
+                failTestIn(10000);
+
+                consoleWrite('<br><em>** Set video.src, wait for media data to load</em>');
+                findMediaElement();
+
+                waitForAndFail(video, 'error')
+                run('video.src = ""
+
+                waitFor(video.textTracks, 'addtrack').then(evt => {
+                    run('track = video.textTracks[0]');
+                    run('track.mode = "hidden"');
+                    track.addEventListener('cuechange', evt => {
+                        if (++cuechangeCount != 6)
+                            return;
+
+                        for (var i = 0; i < 6; i++) {
+                            cue = track.cues[i];
+                            consoleWrite(`<br>cue ${i + 1}`);
+                            testExpected('cue.startTime', Number.POSITIVE_INFINITY, "!=");
+                            testExpected('cue.endTime', Number.POSITIVE_INFINITY, "!=");
+                        }
+
+                        consoleWrite('');
+                        endTest();
+                    });
+                });
+
+                await waitFor(video, 'canplaythrough');
+                await video.play();
+
+                consoleWrite('');
+            }
+        </script>
+    </head>
+    <body _onload_='start()'>
+        <video controls></video>
+        <p>Test that metadata cues have valid duration.</p>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (291028 => 291029)


--- trunk/Source/WebCore/ChangeLog	2022-03-09 02:58:53 UTC (rev 291028)
+++ trunk/Source/WebCore/ChangeLog	2022-03-09 03:34:18 UTC (rev 291029)
@@ -1,3 +1,43 @@
+2022-03-08  Eric Carlson  <[email protected]>
+
+        [Cocoa] metadata cue endTime may not be updated
+        https://bugs.webkit.org/show_bug.cgi?id=237630
+        rdar://88690874
+
+        Reviewed by Jer Noble.
+
+        Data cues have a start time but not an explicit duration, a data cue ends when 
+        the next data cue from the same track starts. This means we don’t know the 
+        duration of cue #1 until cue #2 is delivered, so when cue #1 is delivered it is 
+        given the end time of the media file’s duration and the actual end time is updated
+        when cue #2 arrives.
+
+        http://webkit.org/b/229924 refactored text, audio, and video tracks to not depend
+        on HTMLMediaElement. Because InbandDataTextTrack could no longer access the
+        HTMLMediaElement to get its duration, a duration property was added to TextTrackList
+        that InbandDataTextTrack uses to set the duration of temporary cues.
+        TextTrackList.duration is set when it is created and updated when the media player
+        reports a duration change.
+
+        This means that if the media file’s duration is not known when the text track list
+        is created, and the file's duration never changes, the text track list never has a
+        valid duration and data cues were not added to the temporary list.
+
+        Fix this by updating TextTrackList.duration when a HTMLMediaElement reaches HAVE_METADATA.
+
+        Test: http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::durationChanged): Update m_textTracks.duration and post
+        the 'durationchange' event.
+        (WebCore::HTMLMediaElement::setReadyState): Call durationChanged.
+        (WebCore::HTMLMediaElement::mediaPlayerDurationChanged): Ditto.
+        * html/HTMLMediaElement.h:
+
+        * html/track/InbandDataTextTrack.cpp:
+        (WebCore::InbandDataTextTrack::addDataCue): Add cues to the incomplete cue map
+        even if the track list doesn't have duration.
+
 2022-03-08  Cameron McCormack  <[email protected]>
 
         Skip scheduling lazy UA shadow tree creation if already created or not needed

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (291028 => 291029)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2022-03-09 02:58:53 UTC (rev 291028)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2022-03-09 03:34:18 UTC (rev 291029)
@@ -2448,6 +2448,13 @@
     scheduleEvent(eventNames().pauseEvent);
 }
 
+void HTMLMediaElement::durationChanged()
+{
+    if (m_textTracks)
+        m_textTracks->setDuration(durationMediaTime());
+    scheduleEvent(eventNames().durationchangeEvent);
+}
+
 void HTMLMediaElement::setReadyState(MediaPlayer::ReadyState state)
 {
     // Set "wasPotentiallyPlaying" BEFORE updating m_readyState, potentiallyPlaying() uses it
@@ -2508,7 +2515,7 @@
         // HAVE_METADATA.
         if (m_readyState >= HAVE_METADATA && oldState < HAVE_METADATA) {
             prepareMediaFragmentURI();
-            scheduleEvent(eventNames().durationchangeEvent);
+            durationChanged();
             scheduleResizeEvent();
             scheduleEvent(eventNames().loadedmetadataEvent);
 
@@ -5163,7 +5170,7 @@
 {
     beginProcessingMediaPlayerCallback();
 
-    scheduleEvent(eventNames().durationchangeEvent);
+    durationChanged();
     mediaPlayerCharacteristicChanged();
 
     MediaTime now = currentMediaTime();
@@ -5172,9 +5179,6 @@
     if (now > dur)
         seekInternal(dur);
 
-    if (m_textTracks)
-        m_textTracks->setDuration(dur);
-
     endProcessingMediaPlayerCallback();
 }
 

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (291028 => 291029)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2022-03-09 02:58:53 UTC (rev 291028)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2022-03-09 03:34:18 UTC (rev 291029)
@@ -202,6 +202,7 @@
     void resolvePendingPlayPromises(PlayPromiseVector&&);
     void scheduleNotifyAboutPlaying();
     void notifyAboutPlaying(PlayPromiseVector&&);
+    void durationChanged();
     
     MediaPlayer::MovieLoadType movieLoadType() const;
     

Modified: trunk/Source/WebCore/html/track/InbandDataTextTrack.cpp (291028 => 291029)


--- trunk/Source/WebCore/html/track/InbandDataTextTrack.cpp	2022-03-09 02:58:53 UTC (rev 291028)
+++ trunk/Source/WebCore/html/track/InbandDataTextTrack.cpp	2022-03-09 03:34:18 UTC (rev 291029)
@@ -71,8 +71,9 @@
     }
 
     auto* textTrackList = downcast<TextTrackList>(trackList());
-    if (end.isPositiveInfinite() && textTrackList && textTrackList->duration().isValid()) {
-        cue->setEndTime(textTrackList->duration());
+    if (end.isPositiveInfinite()) {
+        if (textTrackList && textTrackList->duration().isValid())
+            cue->setEndTime(textTrackList->duration());
         m_incompleteCueMap.append(&cue.get());
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to