Title: [291658] branches/safari-613-branch
Revision
291658
Author
alanc...@apple.com
Date
2022-03-22 10:56:11 -0700 (Tue, 22 Mar 2022)

Log Message

Cherry-pick r291029. rdar://problem/88690874

    [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.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291029 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (291657 => 291658)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-03-22 17:56:07 UTC (rev 291657)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-03-22 17:56:11 UTC (rev 291658)
@@ -1,5 +1,68 @@
 2022-03-21  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r291029. rdar://problem/88690874
+
+    [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.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291029 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-03-08  Eric Carlson  <eric.carl...@apple.com>
+
+            [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-21  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r291009. rdar://problem/89952347
 
     AX: Speech Synthesis no longer returning list of voices in macOS 12.3

Added: branches/safari-613-branch/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt (0 => 291658)


--- branches/safari-613-branch/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration-expected.txt	2022-03-22 17:56:11 UTC (rev 291658)
@@ -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: branches/safari-613-branch/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html (0 => 291658)


--- branches/safari-613-branch/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/media/hls/track-in-band-hls-metadata-cue-duration.html	2022-03-22 17:56:11 UTC (rev 291658)
@@ -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: branches/safari-613-branch/Source/WebCore/ChangeLog (291657 => 291658)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-03-22 17:56:07 UTC (rev 291657)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-03-22 17:56:11 UTC (rev 291658)
@@ -1,5 +1,97 @@
 2022-03-21  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r291029. rdar://problem/88690874
+
+    [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.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291029 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-03-08  Eric Carlson  <eric.carl...@apple.com>
+
+            [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-21  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r290999. rdar://problem/89218299
 
     UniqueIDBDatabase::didFireVersionChangeEvent should capture identifier of UniqueIDBDatabaseConnection

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLMediaElement.cpp (291657 => 291658)


--- branches/safari-613-branch/Source/WebCore/html/HTMLMediaElement.cpp	2022-03-22 17:56:07 UTC (rev 291657)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLMediaElement.cpp	2022-03-22 17:56:11 UTC (rev 291658)
@@ -2439,6 +2439,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
@@ -2499,7 +2506,7 @@
         // HAVE_METADATA.
         if (m_readyState >= HAVE_METADATA && oldState < HAVE_METADATA) {
             prepareMediaFragmentURI();
-            scheduleEvent(eventNames().durationchangeEvent);
+            durationChanged();
             scheduleResizeEvent();
             scheduleEvent(eventNames().loadedmetadataEvent);
 
@@ -5147,7 +5154,7 @@
 {
     beginProcessingMediaPlayerCallback();
 
-    scheduleEvent(eventNames().durationchangeEvent);
+    durationChanged();
     mediaPlayerCharacteristicChanged();
 
     MediaTime now = currentMediaTime();
@@ -5156,9 +5163,6 @@
     if (now > dur)
         seekInternal(dur);
 
-    if (m_textTracks)
-        m_textTracks->setDuration(dur);
-
     endProcessingMediaPlayerCallback();
 }
 

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLMediaElement.h (291657 => 291658)


--- branches/safari-613-branch/Source/WebCore/html/HTMLMediaElement.h	2022-03-22 17:56:07 UTC (rev 291657)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLMediaElement.h	2022-03-22 17:56:11 UTC (rev 291658)
@@ -202,6 +202,7 @@
     void resolvePendingPlayPromises(PlayPromiseVector&&);
     void scheduleNotifyAboutPlaying();
     void notifyAboutPlaying(PlayPromiseVector&&);
+    void durationChanged();
     
     MediaPlayer::MovieLoadType movieLoadType() const;
     

Modified: branches/safari-613-branch/Source/WebCore/html/track/InbandDataTextTrack.cpp (291657 => 291658)


--- branches/safari-613-branch/Source/WebCore/html/track/InbandDataTextTrack.cpp	2022-03-22 17:56:07 UTC (rev 291657)
+++ branches/safari-613-branch/Source/WebCore/html/track/InbandDataTextTrack.cpp	2022-03-22 17:56:11 UTC (rev 291658)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to