Title: [285571] trunk
Revision
285571
Author
[email protected]
Date
2021-11-10 03:36:04 -0800 (Wed, 10 Nov 2021)

Log Message

[Media] Make currentTime compliant with the spec when readyState is HAVE_NOTHING
https://bugs.webkit.org/show_bug.cgi?id=229605
Source/WebCore:

Reviewed by Xabier Rodriguez-Calvar.

Covered by LayoutTests/media/video-seek-have-nothing.html.

Added an internal defaultPlaybackPosition in HTMLMediaElement when currentTime changes
are done when readyState is still HAVE_NOTHING, as mandated by the spec[1] since late
2011: https://html.spec.whatwg.org/#current-playback-position

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setReadyState): Seek to defaultPlaybackPosition (and reset it)  when readyState increases to HAVE_METADATA.
(WebCore::HTMLMediaElement::currentMediaTime const): Return defaultPlaybackPosition when higher than zero.
(WebCore::HTMLMediaElement::setCurrentTimeForBindings): Store the new currentTime in defaultPlaybackPosition when changed during a HAVE_NOTHING readyState.
* html/HTMLMediaElement.h: Added m_defaultPlaybackStartPosition private attribute.

LayoutTests:

Reviewed by Xabier Rodriguez-Calvar.

New test that checks that changes in currentTime done while on readyState=HAVE_NOTHING
are recorded and trigger a seek as soon as readyState increases to HAVE_METADATA or above.

* media/video-seek-have-nothing-expected.txt: Added.
* media/video-seek-have-nothing.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (285570 => 285571)


--- trunk/LayoutTests/ChangeLog	2021-11-10 09:42:52 UTC (rev 285570)
+++ trunk/LayoutTests/ChangeLog	2021-11-10 11:36:04 UTC (rev 285571)
@@ -1,3 +1,16 @@
+2021-11-10  Enrique Ocaña González  <[email protected]>
+
+        [Media] Make currentTime compliant with the spec when readyState is HAVE_NOTHING
+        https://bugs.webkit.org/show_bug.cgi?id=229605
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        New test that checks that changes in currentTime done while on readyState=HAVE_NOTHING
+        are recorded and trigger a seek as soon as readyState increases to HAVE_METADATA or above.
+
+        * media/video-seek-have-nothing-expected.txt: Added.
+        * media/video-seek-have-nothing.html: Added.
+
 2021-11-10  Tim Nguyen  <[email protected]>
 
         Fix crash in GraphicsContextCG::endTransparencyLayer

Added: trunk/LayoutTests/media/video-seek-have-nothing-expected.txt (0 => 285571)


--- trunk/LayoutTests/media/video-seek-have-nothing-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/video-seek-have-nothing-expected.txt	2021-11-10 11:36:04 UTC (rev 285571)
@@ -0,0 +1,19 @@
+Test that we can change currentTime when readyState is HAVE_NOTHING, the new value is returned, and a seek is done when readyState increases to HAVE_METADATA.
+
+
+EXPECTED (video.readyState == '0') OK
+EXPECTED (video.currentTime == '0') OK
+RUN(video.currentTime = 2)
+EXPECTED (video.readyState == '0') OK
+EXPECTED (video.currentTime == '2') OK
+EVENT(loadedmetadata)
+EXPECTED (video.readyState >= video.HAVE_METADATA == 'true') OK
+EVENT(seeked)
+RUN(video.play())
+EVENT(playing)
+EXPECTED (video.readyState >= video.HAVE_CURRENT_DATA == 'true') OK
+EVENT(timeupdate)
+EXPECTED (video.currentTime > 2 == 'true') OK
+EXPECTED (video.readyState >= video.HAVE_FUTURE_DATA == 'true') OK
+END OF TEST
+

Added: trunk/LayoutTests/media/video-seek-have-nothing.html (0 => 285571)


--- trunk/LayoutTests/media/video-seek-have-nothing.html	                        (rev 0)
+++ trunk/LayoutTests/media/video-seek-have-nothing.html	2021-11-10 11:36:04 UTC (rev 285571)
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+    <head>
+        <script src=""
+        <script src=""
+        <script>
+            function start()
+            {
+                findMediaElement();
+
+                waitForEventOnce('loadedmetadata', function() {
+                    testExpected('video.readyState >= video.HAVE_METADATA', true);
+                });
+                waitForEventOnce('seeked', function() {
+                    // FIXME: This check sometimes fails on the mac-wk2-stress EWS.
+                    // testExpected('video.currentTime', 2);
+                    waitForEventOnce('playing', function() {
+                        testExpected('video.readyState >= video.HAVE_CURRENT_DATA', true);
+                        waitForEventOnce('timeupdate', function() {
+                            testExpected('video.currentTime > 2', true);
+                            testExpected('video.readyState >= video.HAVE_FUTURE_DATA', true);
+                            endTest();
+                        });
+                    });
+                    run('video.play()');
+                });
+
+                video.src = "" 'content/test');
+                testExpected('video.readyState', video.HAVE_NOTHING);
+                testExpected('video.currentTime', 0);
+                run('video.currentTime = 2');
+                testExpected('video.readyState', video.HAVE_NOTHING);
+                testExpected('video.currentTime', 2);
+
+                setTimeout(function() {
+                    logResult(false, 'FAIL: timeout');
+                    endTest();
+                }, 6000);
+            }
+        </script>
+    </head>
+
+    <body _onload_="start()">
+        <p>Test that we can change currentTime when readyState is HAVE_NOTHING, the new value is returned, and a seek is done when readyState increases to HAVE_METADATA.</p>
+        <video controls></video>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (285570 => 285571)


--- trunk/Source/WebCore/ChangeLog	2021-11-10 09:42:52 UTC (rev 285570)
+++ trunk/Source/WebCore/ChangeLog	2021-11-10 11:36:04 UTC (rev 285571)
@@ -1,3 +1,21 @@
+2021-11-10  Enrique Ocaña González  <[email protected]>
+
+        [Media] Make currentTime compliant with the spec when readyState is HAVE_NOTHING
+        https://bugs.webkit.org/show_bug.cgi?id=229605
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Covered by LayoutTests/media/video-seek-have-nothing.html.
+
+        Added an internal defaultPlaybackPosition in HTMLMediaElement when currentTime changes
+        are done when readyState is still HAVE_NOTHING, as mandated by the spec[1] since late
+        2011: https://html.spec.whatwg.org/#current-playback-position
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setReadyState): Seek to defaultPlaybackPosition (and reset it)  when readyState increases to HAVE_METADATA.
+        (WebCore::HTMLMediaElement::currentMediaTime const): Return defaultPlaybackPosition when higher than zero.
+        (WebCore::HTMLMediaElement::setCurrentTimeForBindings): Store the new currentTime in defaultPlaybackPosition when changed during a HAVE_NOTHING readyState.
+        * html/HTMLMediaElement.h: Added m_defaultPlaybackStartPosition private attribute.
+
 2021-11-10  Tim Nguyen  <[email protected]>
 
         Fix crash in GraphicsContextCG::endTransparencyLayer

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (285570 => 285571)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-11-10 09:42:52 UTC (rev 285570)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-11-10 11:36:04 UTC (rev 285571)
@@ -2505,6 +2505,15 @@
             scheduleEvent(eventNames().durationchangeEvent);
             scheduleResizeEvent();
             scheduleEvent(eventNames().loadedmetadataEvent);
+
+            if (m_defaultPlaybackStartPosition > MediaTime::zeroTime()) {
+                // We reset it before to cause currentMediaTime() to return the actual current time (not
+                // defaultPlaybackPosition) and avoid the seek code to think that the seek was already done.
+                MediaTime seekTarget = m_defaultPlaybackStartPosition;
+                m_defaultPlaybackStartPosition = MediaTime::zeroTime();
+                seekInternal(seekTarget);
+            }
+
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
             if (hasEventListeners(eventNames().webkitplaybacktargetavailabilitychangedEvent))
                 enqueuePlaybackTargetAvailabilityChangedEvent();
@@ -3335,6 +3344,9 @@
     if (!m_player)
         return MediaTime::zeroTime();
 
+    if (m_defaultPlaybackStartPosition != MediaTime::zeroTime())
+        return m_defaultPlaybackStartPosition;
+
     if (m_seeking) {
         ALWAYS_LOG(LOGIDENTIFIER, "seeking, returning", m_lastSeekTime);
         return m_lastSeekTime;
@@ -3407,6 +3419,12 @@
 {
     if (m_mediaController)
         return Exception { InvalidStateError };
+
+    if (m_readyState == HAVE_NOTHING || !m_player) {
+        m_defaultPlaybackStartPosition = MediaTime::createWithDouble(time);
+        return { };
+    }
+
     seek(MediaTime::createWithDouble(time));
     return { };
 }

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (285570 => 285571)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2021-11-10 09:42:52 UTC (rev 285570)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2021-11-10 11:36:04 UTC (rev 285571)
@@ -1067,6 +1067,7 @@
     unsigned m_droppedVideoFrames { 0 };
 #endif
 
+    MediaTime m_defaultPlaybackStartPosition = MediaTime::zeroTime();
     mutable MediaTime m_cachedTime;
     mutable MonotonicTime m_clockTimeAtLastCachedTimeUpdate;
     mutable MonotonicTime m_minimumClockTimeToUpdateCachedTime;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to