Skip to content
Permalink
Browse files
[GStreamer][MiniBrowser] Honor GStreamer command line parameters in M…
…iniBrowser

https://bugs.webkit.org/show_bug.cgi?id=173655
<rdar://problem/37706341>

Reviewed by Philippe Normand.

Source/WebCore:

Do not assume gst is only used in the WebProcess, the MIMETypeRegistry also uses gst to get the list of
supported media types. Move the code to extract gst options from the process command line to a helper function
and use it in the UI process to pass the options to the WebProcess, but also in the current process when gst is
initialized without providing options.

Fixes several unit tests that use MIMETypeRegistry in the UI process.

* platform/graphics/gstreamer/GStreamerUtilities.cpp:
(WebCore::extractGStreamerOptionsFromCommandLine): Helper to get the gst options from the current process
command line.
(WebCore::initializeGStreamer): Ensure this is called once. Get the gst options from the given vector or extract
it from the command line if not provided.
* platform/graphics/gstreamer/GStreamerUtilities.h:
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
(WebCore::MediaPlayerPrivateGStreamerBase::initializeGStreamerAndRegisterWebKitElements): Bring back the gst
initialization here.

Source/WebKit:

Actually pass the gst command line options to the WebProcess. The options in /proc/self/cmdline are separated by
null characters, so we are effectively passing always the first option only, which is the program name. Then, in
the web process we always ignore the first option and providing WebProcess unconditionally, so we were doing
nothing.

* UIProcess/gtk/WebProcessPoolGtk.cpp:
(WebKit::WebProcessPool::platformInitializeWebProcess): Use WebCore::extractGStreamerOptionsFromCommandLine()
* UIProcess/wpe/WebProcessPoolWPE.cpp:
(WebKit::WebProcessPool::platformInitializeWebProcess): Ditto.
* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::WebProcess::platformInitializeWebProcess): Move the vector.

Canonical link: https://commits.webkit.org/198813@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228946 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Feb 23, 2018
1 parent 0c34c6a commit 3269962b96acdb030d4413e58810bc458a4f61aa
@@ -1,3 +1,28 @@
2018-02-23 Carlos Garcia Campos <cgarcia@igalia.com>

[GStreamer][MiniBrowser] Honor GStreamer command line parameters in MiniBrowser
https://bugs.webkit.org/show_bug.cgi?id=173655
<rdar://problem/37706341>

Reviewed by Philippe Normand.

Do not assume gst is only used in the WebProcess, the MIMETypeRegistry also uses gst to get the list of
supported media types. Move the code to extract gst options from the process command line to a helper function
and use it in the UI process to pass the options to the WebProcess, but also in the current process when gst is
initialized without providing options.

Fixes several unit tests that use MIMETypeRegistry in the UI process.

* platform/graphics/gstreamer/GStreamerUtilities.cpp:
(WebCore::extractGStreamerOptionsFromCommandLine): Helper to get the gst options from the current process
command line.
(WebCore::initializeGStreamer): Ensure this is called once. Get the gst options from the given vector or extract
it from the command line if not provided.
* platform/graphics/gstreamer/GStreamerUtilities.h:
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
(WebCore::MediaPlayerPrivateGStreamerBase::initializeGStreamerAndRegisterWebKitElements): Bring back the gst
initialization here.

2018-02-23 Philippe Normand <pnormand@igalia.com>

[GStreamer] HTTP totalBytes query returns 0 after seeking (sometimes)
@@ -26,9 +26,10 @@
#include "GRefPtrGStreamer.h"
#include "GstAllocatorFastMalloc.h"
#include "IntSize.h"

#include <gst/audio/audio-info.h>
#include <gst/gst.h>
#include <mutex>
#include <wtf/glib/GLibUtilities.h>
#include <wtf/glib/GUniquePtr.h>

#if ENABLE(VIDEO_TRACK) && USE(GSTREAMER_MPEGTS)
@@ -236,34 +237,54 @@ void unmapGstBuffer(GstBuffer* buffer)
fastFree(mapInfo);
}

bool initializeGStreamer(Vector<String>& parameters)
Vector<String> extractGStreamerOptionsFromCommandLine()
{
GUniqueOutPtr<char> contents;
gsize length;
if (!g_file_get_contents("/proc/self/cmdline", &contents.outPtr(), &length, nullptr))
return { };

Vector<String> options;
auto optionsString = String::fromUTF8(contents.get(), length);
optionsString.split('\0', false, [&options](StringView item) {
if (item.startsWith("--gst"))
options.append(item.toString());
});
return options;
}

bool initializeGStreamer(std::optional<Vector<String>>&& options)
{
GUniqueOutPtr<GError> error;
bool isGStreamerInitialized = false;
static std::once_flag onceFlag;
static bool isGStreamerInitialized;
std::call_once(onceFlag, [options = WTFMove(options)] {
isGStreamerInitialized = false;

#if ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
char** argv = g_new0(char*, parameters.size() + 2);
argv[0] = g_strdup("WebProcess");
for (unsigned i = 1; i < parameters.size(); i++)
argv[i] = g_strdup(parameters[i].utf8().data());

int size = g_strv_length(argv);
isGStreamerInitialized = gst_init_check(&size, &argv, &error.outPtr());
g_strfreev(argv);
ASSERT_WITH_MESSAGE(isGStreamerInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred");

if (isFastMallocEnabled()) {
const char* disableFastMalloc = getenv("WEBKIT_GST_DISABLE_FAST_MALLOC");
if (!disableFastMalloc || !strcmp(disableFastMalloc, "0"))
gst_allocator_set_default(GST_ALLOCATOR(g_object_new(gst_allocator_fast_malloc_get_type(), nullptr)));
}
Vector<String> parameters = options.value_or(extractGStreamerOptionsFromCommandLine());
char** argv = g_new0(char*, parameters.size() + 2);
int argc = parameters.size() + 1;
argv[0] = g_strdup(g_get_prgname());
for (unsigned i = 0; i < parameters.size(); i++)
argv[i + 1] = g_strdup(parameters[i].utf8().data());

GUniqueOutPtr<GError> error;
isGStreamerInitialized = gst_init_check(&argc, &argv, &error.outPtr());
ASSERT_WITH_MESSAGE(isGStreamerInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred");
g_strfreev(argv);

if (isFastMallocEnabled()) {
const char* disableFastMalloc = getenv("WEBKIT_GST_DISABLE_FAST_MALLOC");
if (!disableFastMalloc || !strcmp(disableFastMalloc, "0"))
gst_allocator_set_default(GST_ALLOCATOR(g_object_new(gst_allocator_fast_malloc_get_type(), nullptr)));
}

#if ENABLE(VIDEO_TRACK) && USE(GSTREAMER_MPEGTS)
if (isGStreamerInitialized)
gst_mpegts_initialize();
if (isGStreamerInitialized)
gst_mpegts_initialize();
#endif
#endif

});
return isGStreamerInitialized;
}

@@ -69,7 +69,8 @@ bool doCapsHaveType(const GstCaps*, const char*);
bool areEncryptedCaps(const GstCaps*);
void mapGstBuffer(GstBuffer*, uint32_t);
void unmapGstBuffer(GstBuffer*);
bool initializeGStreamer(Vector<String>& parameters);
Vector<String> extractGStreamerOptionsFromCommandLine();
bool initializeGStreamer(std::optional<Vector<String>>&& = std::nullopt);
unsigned getGstPlayFlag(const char* nick);
uint64_t toGstUnsigned64Time(const MediaTime&);

@@ -139,6 +139,9 @@ void registerWebKitGStreamerElements()

bool MediaPlayerPrivateGStreamerBase::initializeGStreamerAndRegisterWebKitElements()
{
if (!initializeGStreamer())
return false;

registerWebKitGStreamerElements();

GRefPtr<GstElementFactory> srcFactory = adoptGRef(gst_element_factory_find("webkitwebsrc"));
@@ -1,3 +1,23 @@
2018-02-23 Carlos Garcia Campos <cgarcia@igalia.com>

[GStreamer][MiniBrowser] Honor GStreamer command line parameters in MiniBrowser
https://bugs.webkit.org/show_bug.cgi?id=173655
<rdar://problem/37706341>

Reviewed by Philippe Normand.

Actually pass the gst command line options to the WebProcess. The options in /proc/self/cmdline are separated by
null characters, so we are effectively passing always the first option only, which is the program name. Then, in
the web process we always ignore the first option and providing WebProcess unconditionally, so we were doing
nothing.

* UIProcess/gtk/WebProcessPoolGtk.cpp:
(WebKit::WebProcessPool::platformInitializeWebProcess): Use WebCore::extractGStreamerOptionsFromCommandLine()
* UIProcess/wpe/WebProcessPoolWPE.cpp:
(WebKit::WebProcessPool::platformInitializeWebProcess): Ditto.
* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::WebProcess::platformInitializeWebProcess): Move the vector.

2018-02-22 Yusuke Suzuki <utatane.tea@gmail.com>

Remove currentTime() / currentTimeMS()
@@ -35,6 +35,7 @@
#include "WebProcessMessages.h"
#include <JavaScriptCore/RemoteInspectorServer.h>
#include <WebCore/FileSystem.h>
#include <WebCore/GStreamerUtilities.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/SchemeRegistry.h>
#include <wtf/glib/GUniquePtr.h>
@@ -92,10 +93,7 @@ void WebProcessPool::platformInitializeWebProcess(WebProcessCreationParameters&
parameters.proxySettings = m_networkProxySettings;

#if USE(GSTREAMER)
GUniqueOutPtr<gchar> contents;
gsize length;
if (g_file_get_contents("/proc/self/cmdline", &contents.outPtr(), &length, nullptr))
parameters.gstreamerOptions.append(String::fromUTF8(contents.get()));
parameters.gstreamerOptions = WebCore::extractGStreamerOptionsFromCommandLine();
#endif
}

@@ -36,6 +36,7 @@
#include "WebProcessMessages.h"
#include <JavaScriptCore/RemoteInspectorServer.h>
#include <WebCore/FileSystem.h>
#include <WebCore/GStreamerUtilities.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/SchemeRegistry.h>
#include <cstdlib>
@@ -92,6 +93,10 @@ WTF::String WebProcessPool::legacyPlatformDefaultMediaCacheDirectory()
void WebProcessPool::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
{
parameters.memoryCacheDisabled = m_memoryCacheDisabled || cacheModel() == CacheModelDocumentViewer;
#if USE(GSTREAMER)
parameters.gstreamerOptions = WebCore::extractGStreamerOptionsFromCommandLine();
#endif

}

void WebProcessPool::platformInvalidateContext()
@@ -53,7 +53,7 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&& par
m_waylandCompositorDisplay = WaylandCompositorDisplay::create(parameters.waylandCompositorDisplayName);
#endif
#if USE(GSTREAMER)
WebCore::initializeGStreamer(parameters.gstreamerOptions);
WebCore::initializeGStreamer(WTFMove(parameters.gstreamerOptions));
#endif
}

0 comments on commit 3269962

Please sign in to comment.