adaptivedemux: remove some deadlocks using webkitwebsrc.
authorCharlie Turner <cturner@igalia.com>
Tue, 2 Jul 2019 11:27:40 +0000 (12:27 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 10 Aug 2019 13:50:10 +0000 (14:50 +0100)
commitbdf0e342e35a3f2d4dc75ab7842f79aef9029592
treea839a891f025431cbd676cd8172f84426c313902
parente797763c0e1fe0a06ec673b7ec0b69f0d5cc3138
adaptivedemux: remove some deadlocks using webkitwebsrc.

WebKit's websrc depends on the main-thread for download completion
rendezvous. This exposed a number of deadlocks in adaptivedemux due to
it holding the MANIFEST_LOCK during network requests, and also needing
to hold it to change_state and resolve queries, which frequently occur
during these download windows.

Make demux->running MT-safe so that it can be accessed without using the
MANIFEST_LOCK. In case a source is downloading and requires a MT-thread
notification for completion of the fragment download, a state change
during this download window will deadlock unless we cancel the downloads
and ensure they are not restarted before we finish the state-change.

Also make demux->priv->have_manifest MT-safe. A duration query happening
in the window described above can deadlock for the same reason. Other
src queries (like SEEKING) that happen in this window also could
deadlock, but I haven't hit this scenario.

Increase granularity of API_LOCK'ing in change_state as well. We need to
cancel downloads before trying to take this lock, since sink events
(EOS) will hold it before starting a fragment download.
ext/hls/gsthlsdemux.c
gst-libs/gst/adaptivedemux/gstadaptivedemux.c
gst-libs/gst/adaptivedemux/gstadaptivedemux.h