Title: [274816] trunk
Revision
274816
Author
peng.l...@apple.com
Date
2021-03-22 16:26:23 -0700 (Mon, 22 Mar 2021)

Log Message

[GPUP] Add a "wallTime" field to struct RemoteMediaPlayerState
https://bugs.webkit.org/show_bug.cgi?id=223523

Reviewed by Eric Carlson.

Source/WebCore:

No new tests. Fix test failures:
- media/video-controller-child-rate.html
- media/media-controller-unpause.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::currentMediaTime const): A minor fix for the comment.

Source/WebKit:

Function `MediaPlayerPrivateRemote::currentMediaTime()` returns the
current media time in the cached state, which is not the "current"
media time of the media player. This patch adds a "wallTime" field
to struct `RemoteMediaPlayerState`, so that `MediaPlayerPrivateRemote`
can adjust the `currentTime` in the cached state based on `m_rate`
and `WallTime::now()` and returns a more accurate value.

* GPUProcess/media/RemoteMediaPlayerProxy.cpp:
(WebKit::RemoteMediaPlayerProxy::~RemoteMediaPlayerProxy):
(WebKit::RemoteMediaPlayerProxy::mediaPlayerPlaybackStateChanged):
(WebKit::RemoteMediaPlayerProxy::updateCachedState):
(WebKit::RemoteMediaPlayerProxy::performTaskAtMediaTime):
* GPUProcess/media/RemoteMediaPlayerProxy.h:
* GPUProcess/media/RemoteMediaPlayerProxy.messages.in:

* WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
(WebKit::MediaPlayerPrivateRemote::pause):
(WebKit::MediaPlayerPrivateRemote::currentMediaTime const):
(WebKit::MediaPlayerPrivateRemote::playbackStateChanged):
(WebKit::MediaPlayerPrivateRemote::updateCachedState):
(WebKit::MediaPlayerPrivateRemote::performTaskAtMediaTime):
* WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
* WebProcess/GPU/media/MediaPlayerPrivateRemote.messages.in:

* WebProcess/GPU/media/RemoteMediaPlayerState.h:
(WebKit::RemoteMediaPlayerState::encode const):
(WebKit::RemoteMediaPlayerState::decode):

LayoutTests:

* platform/wk2/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (274815 => 274816)


--- trunk/LayoutTests/ChangeLog	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/LayoutTests/ChangeLog	2021-03-22 23:26:23 UTC (rev 274816)
@@ -1,3 +1,12 @@
+2021-03-22  Peng Liu  <peng.l...@apple.com>
+
+        [GPUP] Add a "wallTime" field to struct RemoteMediaPlayerState
+        https://bugs.webkit.org/show_bug.cgi?id=223523
+
+        Reviewed by Eric Carlson.
+
+        * platform/wk2/TestExpectations:
+
 2021-03-22  Amir Mark Jr  <amir_m...@apple.com>
 
         [MacOS Wk1] imported/w3c/web-platform-tests/css/css-grid/grid-definition/grid-auto-repeat-max-size-001.html is a flakey failure

Modified: trunk/LayoutTests/platform/wk2/TestExpectations (274815 => 274816)


--- trunk/LayoutTests/platform/wk2/TestExpectations	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/LayoutTests/platform/wk2/TestExpectations	2021-03-22 23:26:23 UTC (rev 274816)
@@ -225,8 +225,6 @@
 
 # webkit.org/b/221693
 media/encrypted-media/clearKey/clearKey-session-life-cycle.html [ Failure Crash ]
-media/media-controller-unpause.html [ Timeout ]
-media/video-controller-child-rate.html [ Failure Pass ]
 
 # webkit.org/b/220805
 webaudio/Panner/hrtf-database.html [ Timeout ]

Modified: trunk/Source/WebCore/ChangeLog (274815 => 274816)


--- trunk/Source/WebCore/ChangeLog	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebCore/ChangeLog	2021-03-22 23:26:23 UTC (rev 274816)
@@ -1,3 +1,17 @@
+2021-03-22  Peng Liu  <peng.l...@apple.com>
+
+        [GPUP] Add a "wallTime" field to struct RemoteMediaPlayerState
+        https://bugs.webkit.org/show_bug.cgi?id=223523
+
+        Reviewed by Eric Carlson.
+
+        No new tests. Fix test failures:
+        - media/video-controller-child-rate.html
+        - media/media-controller-unpause.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::currentMediaTime const): A minor fix for the comment.
+
 2021-03-22  Rob Buis  <rb...@igalia.com>
 
         Enable ability to prevent scrolling in Element.focus()

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (274815 => 274816)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-03-22 23:26:23 UTC (rev 274816)
@@ -3170,7 +3170,7 @@
         return m_cachedTime;
     }
 
-    // Is it too soon use a cached time?
+    // Is it too soon to use a cached time?
     MonotonicTime now = MonotonicTime::now();
     double maximumDurationToCacheMediaTime = m_player->maximumDurationToCacheMediaTime();
 

Modified: trunk/Source/WebKit/ChangeLog (274815 => 274816)


--- trunk/Source/WebKit/ChangeLog	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/ChangeLog	2021-03-22 23:26:23 UTC (rev 274816)
@@ -1,3 +1,38 @@
+2021-03-22  Peng Liu  <peng.l...@apple.com>
+
+        [GPUP] Add a "wallTime" field to struct RemoteMediaPlayerState
+        https://bugs.webkit.org/show_bug.cgi?id=223523
+
+        Reviewed by Eric Carlson.
+
+        Function `MediaPlayerPrivateRemote::currentMediaTime()` returns the
+        current media time in the cached state, which is not the "current"
+        media time of the media player. This patch adds a "wallTime" field
+        to struct `RemoteMediaPlayerState`, so that `MediaPlayerPrivateRemote`
+        can adjust the `currentTime` in the cached state based on `m_rate`
+        and `WallTime::now()` and returns a more accurate value.
+
+        * GPUProcess/media/RemoteMediaPlayerProxy.cpp:
+        (WebKit::RemoteMediaPlayerProxy::~RemoteMediaPlayerProxy):
+        (WebKit::RemoteMediaPlayerProxy::mediaPlayerPlaybackStateChanged):
+        (WebKit::RemoteMediaPlayerProxy::updateCachedState):
+        (WebKit::RemoteMediaPlayerProxy::performTaskAtMediaTime):
+        * GPUProcess/media/RemoteMediaPlayerProxy.h:
+        * GPUProcess/media/RemoteMediaPlayerProxy.messages.in:
+
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
+        (WebKit::MediaPlayerPrivateRemote::pause):
+        (WebKit::MediaPlayerPrivateRemote::currentMediaTime const):
+        (WebKit::MediaPlayerPrivateRemote::playbackStateChanged):
+        (WebKit::MediaPlayerPrivateRemote::updateCachedState):
+        (WebKit::MediaPlayerPrivateRemote::performTaskAtMediaTime):
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.messages.in:
+
+        * WebProcess/GPU/media/RemoteMediaPlayerState.h:
+        (WebKit::RemoteMediaPlayerState::encode const):
+        (WebKit::RemoteMediaPlayerState::decode):
+
 2021-03-22  BJ Burg  <bb...@apple.com>
 
         Web Inspector: rename WebInspectorProxy to WebInspectorUIProxy

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp (274815 => 274816)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp	2021-03-22 23:26:23 UTC (rev 274816)
@@ -88,7 +88,7 @@
 RemoteMediaPlayerProxy::~RemoteMediaPlayerProxy()
 {
     if (m_performTaskAtMediaTimeCompletionHandler)
-        m_performTaskAtMediaTimeCompletionHandler(WTF::nullopt);
+        m_performTaskAtMediaTimeCompletionHandler(WTF::nullopt, WTF::nullopt);
     setShouldEnableAudioSourceProvider(false);
 }
 
@@ -455,10 +455,9 @@
     return m_configuration.isVideo;
 }
 
-// FIXME: Unimplemented
 void RemoteMediaPlayerProxy::mediaPlayerPlaybackStateChanged()
 {
-    m_webProcessConnection->send(Messages::MediaPlayerPrivateRemote::PlaybackStateChanged(m_player->paused()), m_id);
+    m_webProcessConnection->send(Messages::MediaPlayerPrivateRemote::PlaybackStateChanged(m_player->paused(), m_player->currentTime(), WallTime::now()), m_id);
 }
 
 void RemoteMediaPlayerProxy::mediaPlayerBufferedTimeRangesChanged()
@@ -816,6 +815,7 @@
 
 void RemoteMediaPlayerProxy::updateCachedState()
 {
+    m_cachedState.wallTime = WallTime::now();
     m_cachedState.currentTime = m_player->currentTime();
     m_cachedState.duration = m_player->duration();
     m_cachedState.networkState = m_player->networkState();
@@ -952,7 +952,7 @@
     m_player->tracksChanged();
 }
 
-void RemoteMediaPlayerProxy::performTaskAtMediaTime(const MediaTime& taskTime, WallTime messageTime, CompletionHandler<void(Optional<MediaTime>)>&& completionHandler)
+void RemoteMediaPlayerProxy::performTaskAtMediaTime(const MediaTime& taskTime, WallTime messageTime, PerformTaskAtMediaTimeCompletionHandler&& completionHandler)
 {
     if (m_performTaskAtMediaTimeCompletionHandler) {
         // A media player is only expected to track one pending task-at-time at once (e.g. see
@@ -959,7 +959,7 @@
         // MediaPlayerPrivateAVFoundationObjC::performTaskAtMediaTime), so cancel the existing
         // CompletionHandler.
         auto handler = WTFMove(m_performTaskAtMediaTimeCompletionHandler);
-        handler(WTF::nullopt);
+        handler(WTF::nullopt, WTF::nullopt);
     }
 
     auto transmissionTime = MediaTime::createWithDouble((WallTime::now() - messageTime).value(), 1);
@@ -966,7 +966,7 @@
     auto adjustedTaskTime = taskTime - transmissionTime;
     auto currentTime = m_player->currentTime();
     if (adjustedTaskTime <= currentTime) {
-        completionHandler(currentTime);
+        completionHandler(currentTime, WallTime::now());
         return;
     }
 
@@ -976,7 +976,7 @@
             return;
 
         auto completionHandler = WTFMove(m_performTaskAtMediaTimeCompletionHandler);
-        completionHandler(m_player->currentTime());
+        completionHandler(m_player->currentTime(), WallTime::now());
     }, adjustedTaskTime);
 }
 

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h (274815 => 274816)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h	2021-03-22 23:26:23 UTC (rev 274816)
@@ -185,7 +185,8 @@
     void videoTrackSetSelected(const TrackPrivateRemoteIdentifier&, bool);
     void textTrackSetMode(const TrackPrivateRemoteIdentifier&, WebCore::InbandTextTrackPrivate::Mode);
 
-    void performTaskAtMediaTime(const MediaTime&, WallTime, CompletionHandler<void(Optional<MediaTime>)>&&);
+    using PerformTaskAtMediaTimeCompletionHandler = CompletionHandler<void(Optional<MediaTime>, Optional<WallTime>)>;
+    void performTaskAtMediaTime(const MediaTime&, WallTime, PerformTaskAtMediaTimeCompletionHandler&&);
     void wouldTaintOrigin(struct WebCore::SecurityOriginData, CompletionHandler<void(Optional<bool>)>&&);
     void setShouldUpdatePlaybackMetrics(bool);
 
@@ -313,7 +314,7 @@
     RunLoop::Timer<RemoteMediaPlayerProxy> m_updateCachedStateMessageTimer;
     RemoteMediaPlayerState m_cachedState;
     RemoteMediaPlayerProxyConfiguration m_configuration;
-    CompletionHandler<void(Optional<MediaTime>)> m_performTaskAtMediaTimeCompletionHandler;
+    PerformTaskAtMediaTimeCompletionHandler m_performTaskAtMediaTimeCompletionHandler;
 #if ENABLE(MEDIA_SOURCE)
     RefPtr<RemoteMediaSourceProxy> m_mediaSourceProxy;
 #endif

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in (274815 => 274816)


--- trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.messages.in	2021-03-22 23:26:23 UTC (rev 274816)
@@ -111,7 +111,7 @@
     SetWirelessPlaybackTarget(WebCore::MediaPlaybackTargetContext target)
 #endif
 
-    PerformTaskAtMediaTime(MediaTime mediaTime, WallTime messageTime) -> (Optional<MediaTime> mediaTime) Async
+    PerformTaskAtMediaTime(MediaTime mediaTime, WallTime messageTime) -> (Optional<MediaTime> mediaTime, Optional<WallTime> wallTime) Async
     WouldTaintOrigin(struct WebCore::SecurityOriginData origin) -> (Optional<bool> wouldTaint) Synchronous
     SetShouldUpdatePlaybackMetrics(bool should)
 

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp (274815 => 274816)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2021-03-22 23:26:23 UTC (rev 274816)
@@ -203,6 +203,9 @@
 void MediaPlayerPrivateRemote::pause()
 {
     m_cachedState.paused = true;
+    auto now = WallTime::now();
+    m_cachedState.currentTime += MediaTime::createWithDouble(m_rate * (now - m_cachedState.wallTime).seconds());
+    m_cachedState.wallTime = now;
     connection().send(Messages::RemoteMediaPlayerProxy::Pause(), m_id);
 }
 
@@ -248,7 +251,10 @@
 
 MediaTime MediaPlayerPrivateRemote::currentMediaTime() const
 {
-    return m_cachedState.currentTime;
+    if (m_cachedState.paused || !m_cachedState.currentTime)
+        return m_cachedState.currentTime;
+
+    return m_cachedState.currentTime + MediaTime::createWithDouble(m_rate * (WallTime::now() - m_cachedState.wallTime).seconds());
 }
 
 void MediaPlayerPrivateRemote::seek(const MediaTime& time)
@@ -342,9 +348,11 @@
     m_player->rateChanged();
 }
 
-void MediaPlayerPrivateRemote::playbackStateChanged(bool paused)
+void MediaPlayerPrivateRemote::playbackStateChanged(bool paused, MediaTime&& mediaTime, WallTime&& wallTime)
 {
     m_cachedState.paused = paused;
+    m_cachedState.currentTime = mediaTime;
+    m_cachedState.wallTime = wallTime;
     m_player->playbackStateChanged();
 }
 
@@ -417,6 +425,7 @@
 
 void MediaPlayerPrivateRemote::updateCachedState(RemoteMediaPlayerState&& state)
 {
+    m_cachedState.wallTime = state.wallTime;
     m_cachedState.currentTime = state.currentTime;
     m_cachedState.duration = state.duration;
     m_cachedState.minTimeSeekable = state.minTimeSeekable;
@@ -1195,11 +1204,12 @@
 
 bool MediaPlayerPrivateRemote::performTaskAtMediaTime(WTF::Function<void()>&& completionHandler, const MediaTime& mediaTime)
 {
-    auto asyncReplyHandler = [weakThis = makeWeakPtr(*this), this, completionHandler = WTFMove(completionHandler)](Optional<MediaTime> currentTime) mutable {
-        if (!weakThis || !currentTime)
+    auto asyncReplyHandler = [weakThis = makeWeakPtr(*this), this, completionHandler = WTFMove(completionHandler)](Optional<MediaTime> currentTime, Optional<WallTime> wallTime) mutable {
+        if (!weakThis || !currentTime || !wallTime)
             return;
 
         m_cachedState.currentTime = *currentTime;
+        m_cachedState.wallTime = *wallTime;
         completionHandler();
     };
 

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h (274815 => 274816)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2021-03-22 23:26:23 UTC (rev 274816)
@@ -99,7 +99,7 @@
     void timeChanged(RemoteMediaPlayerState&&);
     void durationChanged(RemoteMediaPlayerState&&);
     void rateChanged(double);
-    void playbackStateChanged(bool);
+    void playbackStateChanged(bool, MediaTime&&, WallTime&&);
     void engineFailedToLoad(long);
     void updateCachedState(RemoteMediaPlayerState&&);
     void characteristicChanged(RemoteMediaPlayerState&&);

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.messages.in (274815 => 274816)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.messages.in	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.messages.in	2021-03-22 23:26:23 UTC (rev 274816)
@@ -32,7 +32,7 @@
     TimeChanged(struct WebKit::RemoteMediaPlayerState state)
     DurationChanged(struct WebKit::RemoteMediaPlayerState state)
     RateChanged(double rate)
-    PlaybackStateChanged(bool paused)
+    PlaybackStateChanged(bool paused, MediaTime mediaTime, WallTime wallTime)
     EngineFailedToLoad(int platformErrorCode)
     UpdateCachedState(struct WebKit::RemoteMediaPlayerState state)
     CharacteristicChanged(struct WebKit::RemoteMediaPlayerState state)

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteMediaPlayerState.h (274815 => 274816)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteMediaPlayerState.h	2021-03-22 23:26:01 UTC (rev 274815)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteMediaPlayerState.h	2021-03-22 23:26:23 UTC (rev 274816)
@@ -32,10 +32,12 @@
 #include <WebCore/PlatformTimeRanges.h>
 #include <WebCore/VideoPlaybackQualityMetrics.h>
 #include <wtf/MediaTime.h>
+#include <wtf/WallTime.h>
 
 namespace WebKit {
 
 struct RemoteMediaPlayerState {
+    WallTime wallTime;
     MediaTime currentTime;
     MediaTime duration;
     MediaTime minTimeSeekable;
@@ -70,6 +72,7 @@
     template<class Encoder>
     void encode(Encoder& encoder) const
     {
+        encoder << wallTime;
         encoder << currentTime;
         encoder << duration;
         encoder << minTimeSeekable;
@@ -105,6 +108,11 @@
     template <class Decoder>
     static Optional<RemoteMediaPlayerState> decode(Decoder& decoder)
     {
+        Optional<WallTime> wallTime;
+        decoder >> wallTime;
+        if (!wallTime)
+            return WTF::nullopt;
+
         Optional<MediaTime> currentTime;
         decoder >> currentTime;
         if (!currentTime)
@@ -252,6 +260,7 @@
             return WTF::nullopt;
 
         return {{
+            WTFMove(*wallTime),
             WTFMove(*currentTime),
             WTFMove(*duration),
             WTFMove(*minTimeSeekable),
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to