Skip to content

[GStreamer][MSE] Avoid spurious seek to 0 when seeking to end - #70855

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
eocanha:metro-issue-1634
Aug 9, 2026
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
eocanha:metro-issue-1634

Conversation

@eocanha

@eocanha eocanha commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

42a5b53

[GStreamer][MSE] Avoid spurious seek to 0 when seeking to end
https://bugs.webkit.org/show_bug.cgi?id=320981

Reviewed by Xabier Rodriguez-Calvar.

On a device where a GStreamer seek operation leads to a pipeline async
state change, we may enter a flow of internal calls that cause a second
seek to zero to be executed before the first call has returned. This was
detected with Spotify when performing a seek to the asset end (duration)
right after playback has started from the beginning (position zero).
This issue does not happen if the GStreamer seek operation does not
cause a async pipeline state change.

See: WebPlatformForEmbedded/WPEWebKit#1645

This patch avoids automatic playback when the video has ended
(effectively helping to avoid currentTime accidentally going beyond the
duration) or when a seek is still happening (avoiding currentTime to
progress and change the conditions of the video). ReadyState is
propagated to the player when seek has completed, helping the
HTMLMediaElement algorithms to take the right decisions when seek
completes. Finally, code has been added to avoid the position to ever go
beyond the duration in order to avoid a degradation of the ReadyState to
HaveMetadata, except when the duration is zero. This is a special case
used by MediaPlayerPrivateGStreamer::duration() and
MediaPlayerPrivateGStreamerMSE::duration() when the duration is
unknown/unavailable, and we don't want to mess up with that and cause a
stream that is just being loaded to trigger unexpected effects.

Co-authored-by: Enrique Ocaña González <[email protected]>

Test: media/media-source/media-source-seek-to-end-doesnt-loop.html

* LayoutTests/media/media-source/media-source-seek-to-end-doesnt-loop-expected.txt: Added.
* LayoutTests/media/media-source/media-source-seek-to-end-doesnt-loop.html: Added.
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerPlaybackStateChanged): Avoid automatic playback on seek or video end.
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::playbackPosition const): Never allow the position to go beyond duration, except in the special case when duration is zero.
* Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:
(WebCore::MediaPlayerPrivateGStreamerMSE::doSeek): Propagate readyState to player on seek completion.
(WebCore::MediaPlayerPrivateGStreamerMSE::propagateReadyStateToPlayer): Relaxed the assert so also admit m_isSeeking as a condition to not halt execution.

Canonical link: https://commits.webkit.org/318859@main

272ed49

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ❌ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug
✅ 🧪 api-ios ❌ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-AS-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-wk2-stress ✅ 🧪 gtk-wk2
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp ✅ 🛠 playstation
✅ 🛠 tv ❌ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@eocanha
eocanha requested review from cdumez, philn and rniwa as code owners August 4, 2026 12:14
@eocanha eocanha self-assigned this Aug 4, 2026
@eocanha eocanha added the New Bugs Unclassified bugs are placed in this component until the correct component can be determined. label Aug 4, 2026
@ntrrgc

ntrrgc commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Typo: s/spureous/spurious/

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Aug 4, 2026
@eocanha eocanha changed the title [GStreamer][MSE] Avoid spureous seek to 0 when seeking to end [GStreamer][MSE] Avoid spurious seek to 0 when seeking to end Aug 4, 2026
@eocanha eocanha removed the merging-blocked Applied to prevent a change from being merged label Aug 4, 2026

@ntrrgc ntrrgc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't formally review this since this is code I wrote, but I can state it's consistent with the changes I was working with, which indeed fixed the accidental seek to end.

@calvaris calvaris left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changelog: "spureous" → "spurious"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check for the duration to be > 0, otherwise we could be creating issues.

@eocanha eocanha Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the duration is 0, how can the playback position go beyond it? Note that default duration, at least in MSE, is NaN. For regular playback, it's NaN when not available and Infinity for unbound streams. So, if it's actually zero, it must be for a good reason. And if it's indeed zero, that might also trigger the undesirable seek to 0 that we're trying to avoid, entering into a potential loop of seeks.

What kind of issues were you thinking about?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ok, I see after our 1-1 chat:

Both MediaPlayerPrivateGStreamer::duration() and MediaPlayerPrivateGStreamerMSE::duration() use zero as a special case when the real duration is invalid (unknown). That's why the zero value must be had into account in this kind of conditions.

I'm adding your suggestion to the final version of the patch. Thanks! 🙏

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"miniscule" → "minuscule"

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Aug 7, 2026
@eocanha eocanha added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Aug 7, 2026
@webkit-commit-queue webkit-commit-queue added merging-blocked Applied to prevent a change from being merged and removed merge-queue Applied to send a pull request to merge-queue labels Aug 7, 2026
@eocanha

eocanha commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

The failure detected by the merge queue is a flaky that is also happening on other merge attempts today and it's unrelated to the changes in this PR. Attempting merge-queue again.

@eocanha eocanha added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Aug 7, 2026
@webkit-commit-queue webkit-commit-queue added merging-blocked Applied to prevent a change from being merged and removed merge-queue Applied to send a pull request to merge-queue labels Aug 7, 2026
@eocanha

eocanha commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

♻️

@eocanha eocanha removed the merging-blocked Applied to prevent a change from being merged label Aug 9, 2026
@eocanha eocanha added the merge-queue Applied to send a pull request to merge-queue label Aug 9, 2026
https://bugs.webkit.org/show_bug.cgi?id=320981

Reviewed by Xabier Rodriguez-Calvar.

On a device where a GStreamer seek operation leads to a pipeline async
state change, we may enter a flow of internal calls that cause a second
seek to zero to be executed before the first call has returned. This was
detected with Spotify when performing a seek to the asset end (duration)
right after playback has started from the beginning (position zero).
This issue does not happen if the GStreamer seek operation does not
cause a async pipeline state change.

See: WebPlatformForEmbedded/WPEWebKit#1645

This patch avoids automatic playback when the video has ended
(effectively helping to avoid currentTime accidentally going beyond the
duration) or when a seek is still happening (avoiding currentTime to
progress and change the conditions of the video). ReadyState is
propagated to the player when seek has completed, helping the
HTMLMediaElement algorithms to take the right decisions when seek
completes. Finally, code has been added to avoid the position to ever go
beyond the duration in order to avoid a degradation of the ReadyState to
HaveMetadata, except when the duration is zero. This is a special case
used by MediaPlayerPrivateGStreamer::duration() and
MediaPlayerPrivateGStreamerMSE::duration() when the duration is
unknown/unavailable, and we don't want to mess up with that and cause a
stream that is just being loaded to trigger unexpected effects.

Co-authored-by: Enrique Ocaña González <[email protected]>

Test: media/media-source/media-source-seek-to-end-doesnt-loop.html

* LayoutTests/media/media-source/media-source-seek-to-end-doesnt-loop-expected.txt: Added.
* LayoutTests/media/media-source/media-source-seek-to-end-doesnt-loop.html: Added.
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerPlaybackStateChanged): Avoid automatic playback on seek or video end.
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::playbackPosition const): Never allow the position to go beyond duration, except in the special case when duration is zero.
* Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:
(WebCore::MediaPlayerPrivateGStreamerMSE::doSeek): Propagate readyState to player on seek completion.
(WebCore::MediaPlayerPrivateGStreamerMSE::propagateReadyStateToPlayer): Relaxed the assert so also admit m_isSeeking as a condition to not halt execution.

Canonical link: https://commits.webkit.org/318859@main
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 318859@main (42a5b53): https://commits.webkit.org/318859@main

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

@webkit-commit-queue
webkit-commit-queue merged commit 42a5b53 into WebKit:main Aug 9, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Bugs Unclassified bugs are placed in this component until the correct component can be determined.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants