Skip to content

Commit dd19f4d

Browse files
committed
[GStreamer] Ensure GStreamer is initialized before using the Quirks
https://bugs.webkit.org/show_bug.cgi?id=303326 Reviewed by Philippe Normand. GStreamerQuirksManager requires GStreamer to be initialized, which does not happen soon enough if neither canPlayType() nor isTypeSupported() has been called before, so in those cases no quirks are applied. However, the quirks manager may be used in other processes, e.g. NetworkProcess when determining support for a MIME type. To avoid issues, we should only fully init GStreamer if on the WebProcess, and otherwise go for a minimal initialization. * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::ensureGStreamerInitializedNonWebProcess): Added as a counterpart to ensureGStreamerInitialized, only does minimal init. * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (WebCore::GStreamerRegistryScanner::GStreamerRegistryScanner): Use the new function to initialize gst if in the UIProcess * Source/WebCore/platform/gstreamer/GStreamerQuirks.cpp: (WebCore::GStreamerQuirksManager::GStreamerQuirksManager): Init GStreamer using either of the two methods Original author: Andrzej Surdej <[email protected]> See: #1584 Canonical link: https://commits.webkit.org/303982@main
1 parent aa01883 commit dd19f4d

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,22 @@ Vector<String> extractGStreamerOptionsFromCommandLine()
347347
return options;
348348
}
349349

350+
bool ensureGStreamerInitializedNonWebProcess()
351+
{
352+
RELEASE_ASSERT(!isInWebProcess());
353+
354+
static std::once_flag onceFlag;
355+
static bool isGStreamerInitialized;
356+
std::call_once(onceFlag, [] {
357+
GUniqueOutPtr<GError> error;
358+
isGStreamerInitialized = gst_init_check(nullptr, nullptr, &error.outPtr());
359+
ASSERT_WITH_MESSAGE(isGStreamerInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred");
360+
GST_DEBUG_CATEGORY_INIT(webkit_gst_common_debug, "webkitcommon", 0, "WebKit Common utilities");
361+
});
362+
363+
return isGStreamerInitialized;
364+
}
365+
350366
bool ensureGStreamerInitialized()
351367
{
352368
// WARNING: Please note this function can be called from any thread, for instance when creating

Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ bool doCapsHaveType(const GstCaps*, const char*);
8080
bool areEncryptedCaps(const GstCaps*);
8181
Vector<String> extractGStreamerOptionsFromCommandLine();
8282
void setGStreamerOptionsFromUIProcess(Vector<String>&&);
83+
bool ensureGStreamerInitializedNonWebProcess();
8384
bool ensureGStreamerInitialized();
8485
void registerWebKitGStreamerElements();
8586
void registerWebKitGStreamerVideoEncoder();

Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ GStreamerRegistryScanner::GStreamerRegistryScanner(bool isMediaSource)
362362
else {
363363
// This is still needed, mostly because of the webkit_web_view_can_show_mime_type() public API (so
364364
// running from UIProcess).
365-
gst_init(nullptr, nullptr);
365+
ensureGStreamerInitializedNonWebProcess();
366366
}
367367

368368
GST_DEBUG_CATEGORY_INIT(webkit_media_gst_registry_scanner_debug, "webkitregistryscanner", 0, "WebKit GStreamer registry scanner");

Source/WebCore/platform/gstreamer/GStreamerQuirks.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "GStreamerQuirkWesteros.h"
3939
#include <wtf/NeverDestroyed.h>
4040
#include <wtf/OptionSet.h>
41+
#include <wtf/RuntimeApplicationChecks.h>
4142
#include <wtf/text/StringView.h>
4243

4344
namespace WebCore {
@@ -56,6 +57,12 @@ GStreamerQuirksManager::GStreamerQuirksManager(bool isForTesting, bool loadQuirk
5657
{
5758
static std::once_flag debugRegisteredFlag;
5859
std::call_once(debugRegisteredFlag, [] {
60+
if (isInWebProcess())
61+
ensureGStreamerInitialized();
62+
else
63+
// This is needed, e.g. when running in NetworkProcess to determine MIME type support
64+
ensureGStreamerInitializedNonWebProcess();
65+
5966
GST_DEBUG_CATEGORY_INIT(webkit_quirks_debug, "webkitquirks", 0, "WebKit Quirks");
6067
});
6168

0 commit comments

Comments
 (0)