Skip to content

Commit 7e0e10a

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 330317a commit 7e0e10a

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
@@ -261,6 +261,22 @@ Vector<String> extractGStreamerOptionsFromCommandLine()
261261
return options;
262262
}
263263

264+
bool ensureGStreamerInitializedNonWebProcess()
265+
{
266+
RELEASE_ASSERT(!isInWebProcess());
267+
268+
static std::once_flag onceFlag;
269+
static bool isGStreamerInitialized;
270+
std::call_once(onceFlag, [] {
271+
GUniqueOutPtr<GError> error;
272+
isGStreamerInitialized = gst_init_check(nullptr, nullptr, &error.outPtr());
273+
ASSERT_WITH_MESSAGE(isGStreamerInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred");
274+
GST_DEBUG_CATEGORY_INIT(webkit_gst_common_debug, "webkitcommon", 0, "WebKit Common utilities");
275+
});
276+
277+
return isGStreamerInitialized;
278+
}
279+
264280
bool ensureGStreamerInitialized()
265281
{
266282
// 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
@@ -71,6 +71,7 @@ bool doCapsHaveType(const GstCaps*, const char*);
7171
bool areEncryptedCaps(const GstCaps*);
7272
Vector<String> extractGStreamerOptionsFromCommandLine();
7373
void setGStreamerOptionsFromUIProcess(Vector<String>&&);
74+
bool ensureGStreamerInitializedNonWebProcess();
7475
bool ensureGStreamerInitialized();
7576
void registerWebKitGStreamerElements();
7677
void registerWebKitGStreamerVideoEncoder();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ GStreamerRegistryScanner::GStreamerRegistryScanner(bool isMediaSource)
275275
else {
276276
// This is still needed, mostly because of the webkit_web_view_can_show_mime_type() public API (so
277277
// running from UIProcess).
278-
gst_init(nullptr, nullptr);
278+
ensureGStreamerInitializedNonWebProcess();
279279
}
280280

281281
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 "RuntimeApplicationChecks.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)