Bug 254256 - `playing` event isn't fired as early as it should
Summary: `playing` event isn't fired as early as it should
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-03-21 23:34 PDT by Jean-Yves Avenard [:jya]
Modified: 2023-03-22 05:09 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2023-03-21 23:34:27 PDT
In bug 225396, changes were added to reduce how many times the content process would poll the MediaPlayer running in the GPU process.
This was done through simulating the currentTime progress by using the wall clock to assume by how much the MediaPlayer's currentTime actually progressed.

This caused regression where when the real currentTime was re-synchronised, it could make the clock appears to go backward due to drift.
In bug 239471 a check was added to force the refresh and notify the HTMLMediaElement that the time changed if it did go backward [1].

When we call `play()` on a media element, it waits to be notified of a time change [2] to determine if playback has started, and then fire the `playing` event [3]

However, when the MediaPlayer update the currentTime for the first time, it calls `MediaPlayerPrivateRemote::currentTimeChanged` followed by multiple calls `MediaPlayerPrivateRemote::timeChanged` whenever some significant player change occurs.

The first time `MediaPlayerPrivateRemote::currentTimeChanged` is called, the previous currentTime was 0, the new time is positive and so we don't call HTMLMediaPlayer::mediaPlayerTimeChanged() [2]
only on following call to timeChanged will the HTMLMediaElement be notified [4]

As such, we only fire `playing` after the 2nd time update by the MediaPlayer rather than the first.

This issue is exposed by the MocKMSE test `media/media-source/media-source-end-of-stream-buffered.html` as the MockMediaPlayer only ever send a single time update.

[1]https://searchfox.org/wubkat/rev/c1fb4e9f678eb1aacf9b056070aced47d70502f7/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp#418-429
[2]https://searchfox.org/wubkat/rev/c1fb4e9f678eb1aacf9b056070aced47d70502f7/Source/WebCore/html/HTMLMediaElement.cpp#5335
[3]https://searchfox.org/wubkat/rev/c1fb4e9f678eb1aacf9b056070aced47d70502f7/Source/WebCore/html/HTMLMediaElement.cpp#5966
[4]https://searchfox.org/wubkat/rev/c1fb4e9f678eb1aacf9b056070aced47d70502f7/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp#366-369
Comment 1 Radar WebKit Bug Importer 2023-03-21 23:35:01 PDT
<rdar://problem/107041118>
Comment 2 Jean-Yves Avenard [:jya] 2023-03-21 23:57:17 PDT
Pull request: https://github.com/WebKit/WebKit/pull/11797
Comment 3 EWS 2023-03-22 05:08:57 PDT
Committed 261959@main (84eb2324cde9): <https://commits.webkit.org/261959@main>

Reviewed commits have been landed. Closing PR #11797 and removing active labels.