Bug 260067 - [MSE][GStreamer] Deadlock while flushing on paused when there's a non in-place transform element
Summary: [MSE][GStreamer] Deadlock while flushing on paused when there's a non in-plac...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Enrique Ocaña
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-08-11 05:32 PDT by Enrique Ocaña
Modified: 2023-08-25 06:04 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 Enrique Ocaña 2023-08-11 05:32:11 PDT
There is a deadlock possible inside WebKit media src (MSE) between streaming thread handling CAPS event and pipeline flush in the main thread. This happens in case where there is a transform element in the pipeline that does transition NOT in place. Basetransform elem expects that it will allocate buffers so on CAPS change it triggers allocation negotiations (ALLOCATION query). In such case CAPS event becomes fully synchronous as basetransform does ALLOCATION query that is synchronous (serialized with data) and may block the streaming thread. If the pipeline is paused and the sink thread doesn't accept any data, this will block CAPS event until pipeline is unpaused or flushed. But flush requires a lock that streaming thread is holding (DataMutexLocker streamingMembers { stream->streamingMembersDataMutex };)

See: https://github.com/WebPlatformForEmbedded/WPEWebKit/issues/1135
Comment 1 Enrique Ocaña 2023-08-11 05:37:53 PDT
My proposal for this is to make webKitMediaSrcLoop() release the lock before pushing the caps event (which may take a long time to get processed) to let the main thread start the flush. Such a flush would cause the sink element to release the streaming thread and the caps event processing to finish.

After the caps event has been pushed, the lock would be retaken. But streamingMembers might have changed under our feet (and it certainly will, because of the flush). We should reevaluate if the flush condition is present, and in that case abort the execution of webKitMediaSrcLoop() after having paused the streaming task of the corresponding pad.
Comment 2 Enrique Ocaña 2023-08-11 06:00:10 PDT
Pull request: https://github.com/WebKit/WebKit/pull/16603
Comment 3 EWS 2023-08-25 06:03:39 PDT
Committed 267276@main (5023d703877c): <https://commits.webkit.org/267276@main>

Reviewed commits have been landed. Closing PR #16603 and removing active labels.
Comment 4 Radar WebKit Bug Importer 2023-08-25 06:04:14 PDT
<rdar://problem/114447153>