Title: [228946] trunk/Source
Revision
228946
Author
carlo...@webkit.org
Date
2018-02-23 04:53:04 -0800 (Fri, 23 Feb 2018)

Log Message

[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.

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228945 => 228946)


--- trunk/Source/WebCore/ChangeLog	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebCore/ChangeLog	2018-02-23 12:53:04 UTC (rev 228946)
@@ -1,3 +1,28 @@
+2018-02-23  Carlos Garcia Campos  <cgar...@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  <pnorm...@igalia.com>
 
         [GStreamer] HTTP totalBytes query returns 0 after seeking (sometimes)

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp (228945 => 228946)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp	2018-02-23 12:53:04 UTC (rev 228946)
@@ -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 @@
     fastFree(mapInfo);
 }
 
-bool initializeGStreamer(Vector<String>& parameters)
+Vector<String> extractGStreamerOptionsFromCommandLine()
 {
-    GUniqueOutPtr<GError> error;
-    bool isGStreamerInitialized = false;
+    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)
+{
+    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());
+        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());
 
-    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");
+        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 (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;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h (228945 => 228946)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h	2018-02-23 12:53:04 UTC (rev 228946)
@@ -69,7 +69,8 @@
 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&);
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp (228945 => 228946)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp	2018-02-23 12:53:04 UTC (rev 228946)
@@ -139,6 +139,9 @@
 
 bool MediaPlayerPrivateGStreamerBase::initializeGStreamerAndRegisterWebKitElements()
 {
+    if (!initializeGStreamer())
+        return false;
+
     registerWebKitGStreamerElements();
 
     GRefPtr<GstElementFactory> srcFactory = adoptGRef(gst_element_factory_find("webkitwebsrc"));

Modified: trunk/Source/WebKit/ChangeLog (228945 => 228946)


--- trunk/Source/WebKit/ChangeLog	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebKit/ChangeLog	2018-02-23 12:53:04 UTC (rev 228946)
@@ -1,3 +1,23 @@
+2018-02-23  Carlos Garcia Campos  <cgar...@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....@gmail.com>
 
         Remove currentTime() / currentTimeMS()

Modified: trunk/Source/WebKit/UIProcess/gtk/WebProcessPoolGtk.cpp (228945 => 228946)


--- trunk/Source/WebKit/UIProcess/gtk/WebProcessPoolGtk.cpp	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebKit/UIProcess/gtk/WebProcessPoolGtk.cpp	2018-02-23 12:53:04 UTC (rev 228946)
@@ -35,6 +35,7 @@
 #include "WebProcessMessages.h"
 #include <_javascript_Core/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 @@
     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
 }
 

Modified: trunk/Source/WebKit/UIProcess/wpe/WebProcessPoolWPE.cpp (228945 => 228946)


--- trunk/Source/WebKit/UIProcess/wpe/WebProcessPoolWPE.cpp	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebKit/UIProcess/wpe/WebProcessPoolWPE.cpp	2018-02-23 12:53:04 UTC (rev 228946)
@@ -36,6 +36,7 @@
 #include "WebProcessMessages.h"
 #include <_javascript_Core/RemoteInspectorServer.h>
 #include <WebCore/FileSystem.h>
+#include <WebCore/GStreamerUtilities.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/SchemeRegistry.h>
 #include <cstdlib>
@@ -92,6 +93,10 @@
 void WebProcessPool::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
 {
     parameters.memoryCacheDisabled = m_memoryCacheDisabled || cacheModel() == CacheModelDocumentViewer;
+#if USE(GSTREAMER)
+    parameters.gstreamerOptions = WebCore::extractGStreamerOptionsFromCommandLine();
+#endif
+
 }
 
 void WebProcessPool::platformInvalidateContext()

Modified: trunk/Source/WebKit/WebProcess/soup/WebProcessSoup.cpp (228945 => 228946)


--- trunk/Source/WebKit/WebProcess/soup/WebProcessSoup.cpp	2018-02-23 10:06:46 UTC (rev 228945)
+++ trunk/Source/WebKit/WebProcess/soup/WebProcessSoup.cpp	2018-02-23 12:53:04 UTC (rev 228946)
@@ -53,7 +53,7 @@
     m_waylandCompositorDisplay = WaylandCompositorDisplay::create(parameters.waylandCompositorDisplayName);
 #endif
 #if USE(GSTREAMER)
-    WebCore::initializeGStreamer(parameters.gstreamerOptions);
+    WebCore::initializeGStreamer(WTFMove(parameters.gstreamerOptions));
 #endif
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to