Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GStreamer][MSE] Take playbin's states lock when sending seek event #29897

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

calvaris
Copy link
Contributor

@calvaris calvaris commented Jun 17, 2024

81376ca

[GStreamer][MSE] Take playbin's states lock when sending seek event
https://bugs.webkit.org/show_bug.cgi?id=275566

Reviewed by Alicia Boya Garcia.

This fixes possible race between application (triggering another seek from 'seeked' event) and 'state chagne'
continuation (triggered by playbin).

Top level bin element does change the state as result of 'async-done' handling from previous seek request (see
gst_bin_continue_func in gstbin.c). Which may race with handling of 'async-start' posted by sinks on flushing seek. And
may leave the pipeline in inconsistent state and 'hanging' seek that never finishes.

By taking the states lock of top level bin element player will wait for possible state change continuation to complete
before sending next seek event.

Based on a patch by Eugene Mutavchi <[email protected]>.

* Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:
(WebCore::MediaPlayerPrivateGStreamerMSE::doSeek):

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

a5b17e9

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2 βœ… πŸ§ͺ wincairo-tests
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-cairo
  πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
⏳ πŸ›  vision βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ gtk-wk2
⏳ πŸ›  vision-sim βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge ⏳ πŸ§ͺ vision-wk2
βœ… πŸ›  tv
βœ… πŸ›  tv-sim
βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@calvaris calvaris requested a review from philn as a code owner June 17, 2024 14:39
@calvaris calvaris self-assigned this Jun 17, 2024
@calvaris calvaris added the Media Bugs related to the HTML 5 Media elements. label Jun 17, 2024
@calvaris calvaris requested review from ntrrgc and achristensen07 and removed request for achristensen07 June 17, 2024 14:40
Copy link
Contributor

@ntrrgc ntrrgc left a comment

Choose a reason for hiding this comment

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

LGTM.

gst_element_seek(m_source.get(), rate, GST_FORMAT_TIME, m_seekFlags,
GST_SEEK_TYPE_SET, toGstClockTime(target.time), GST_SEEK_TYPE_NONE, 0);
{
auto locker = GstStateLocker(pipeline());
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs an explanation. For instance:

// Take the STATE_LOCK of the __pipeline__.
//
// gst_element_send_event() [which is called by gst_element_seek()] already takes the
// STATE_LOCK of the element in order to delay any state change attempts from other 
// threads while the event is travelling the pipeline.
//
// Normally that would happen to both the pipeline and then recursively to the 
// elements inside as they handle the seek event, but since we're sending the event
// directly to the source element we need to take the STATE_LOCK on the pipeline ourselves.

@calvaris calvaris added the merge-queue Applied to send a pull request to merge-queue label Jun 19, 2024
@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 Jun 19, 2024
@calvaris calvaris 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 Jun 19, 2024
https://bugs.webkit.org/show_bug.cgi?id=275566

Reviewed by Alicia Boya Garcia.

This fixes possible race between application (triggering another seek from 'seeked' event) and 'state chagne'
continuation (triggered by playbin).

Top level bin element does change the state as result of 'async-done' handling from previous seek request (see
gst_bin_continue_func in gstbin.c). Which may race with handling of 'async-start' posted by sinks on flushing seek. And
may leave the pipeline in inconsistent state and 'hanging' seek that never finishes.

By taking the states lock of top level bin element player will wait for possible state change continuation to complete
before sending next seek event.

Based on a patch by Eugene Mutavchi <[email protected]>.

* Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:
(WebCore::MediaPlayerPrivateGStreamerMSE::doSeek):

Canonical link: https://commits.webkit.org/280168@main
@webkit-commit-queue
Copy link
Collaborator

Committed 280168@main (81376ca): https://commits.webkit.org/280168@main

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

@webkit-commit-queue webkit-commit-queue merged commit 81376ca into WebKit:main Jun 19, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 19, 2024
@calvaris calvaris deleted the eng/275566 branch June 19, 2024 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Media Bugs related to the HTML 5 Media elements.
Projects
None yet
4 participants