Skip to content

Commit f8cd370

Browse files
emutavchieocanha
authored andcommitted
[MSE][GStreamer] block data flow until source pad is exposed
https://bugs.webkit.org/show_bug.cgi?id=276251 Reviewed by Xabier Rodriguez-Calvar. In WebKitMediaSrc, there could be a race between main thread (linking typefind element, see gsturisourcebin.c:setup_typefind) and streaming thread (pushing data). webKitMediaSrcLoop does wait for source pad to linked. However, there is no guarantee that peer pad is already active at that point. This may lead to data loss while peer the pad is being activated. This change blocks downstream flow during pad addition, allowing urisourcebin to link/activate typefind sink pad. See: #1355 Original patch by Eugene Mutavchi <Ievgen_Mutavchi@comcast.com>. * Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp: (webKitMediaSrcEmitStreams): Add blocking probes to the Streams Pads, which will be removed after the pad has been added to the element. Canonical link: https://commits.webkit.org/280813@main
1 parent 34eb5f8 commit f8cd370

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <wtf/MainThread.h>
3838
#include <wtf/MainThreadData.h>
3939
#include <wtf/RefPtr.h>
40+
#include <wtf/Scope.h>
4041
#include <wtf/glib/WTFGType.h>
4142
#include <wtf/text/AtomString.h>
4243
#include <wtf/text/AtomStringHash.h>
@@ -327,6 +328,13 @@ void webKitMediaSrcEmitStreams(WebKitMediaSrc* source, const Vector<RefPtr<Media
327328
gst_element_post_message(GST_ELEMENT(source), gst_message_new_stream_collection(GST_OBJECT(source), source->priv->collection.get()));
328329

329330
for (const RefPtr<Stream>& stream: source->priv->streams.values()) {
331+
// Block data flow until pad is exposed.
332+
gulong blockId = gst_pad_add_probe(
333+
GST_PAD(stream->pad.get()), GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
334+
[](GstPad*, GstPadProbeInfo*, gpointer) -> GstPadProbeReturn {
335+
return GST_PAD_PROBE_OK;
336+
}, nullptr, nullptr);
337+
330338
if (!webkitGstCheckVersion(1, 20, 6)) {
331339
// Workaround: gst_element_add_pad() should already call gst_pad_set_active() if the element is PAUSED or
332340
// PLAYING. Unfortunately, as of GStreamer 1.18.2 it does so with the element lock taken, causing a deadlock
@@ -340,6 +348,7 @@ void webKitMediaSrcEmitStreams(WebKitMediaSrc* source, const Vector<RefPtr<Media
340348
}
341349
GST_DEBUG_OBJECT(source, "Adding pad '%s' for stream with name '%s'", GST_OBJECT_NAME(stream->pad.get()), stream->track->trackId().string().utf8().data());
342350
gst_element_add_pad(GST_ELEMENT(source), GST_PAD(stream->pad.get()));
351+
gst_pad_remove_probe(GST_PAD(stream->pad.get()), blockId);
343352
}
344353
GST_DEBUG_OBJECT(source, "All pads added");
345354
}

0 commit comments

Comments
 (0)