Changeset 228946 in webkit


Ignore:
Timestamp:
Feb 23, 2018 4:53:04 AM (6 years ago)
Author:
Carlos Garcia Campos
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.

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r228945 r228946  
     12018-02-23  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GStreamer][MiniBrowser] Honor GStreamer command line parameters in MiniBrowser
     4        https://bugs.webkit.org/show_bug.cgi?id=173655
     5        <rdar://problem/37706341>
     6
     7        Reviewed by Philippe Normand.
     8
     9        Do not assume gst is only used in the WebProcess, the MIMETypeRegistry also uses gst to get the list of
     10        supported media types. Move the code to extract gst options from the process command line to a helper function
     11        and use it in the UI process to pass the options to the WebProcess, but also in the current process when gst is
     12        initialized without providing options.
     13
     14        Fixes several unit tests that use MIMETypeRegistry in the UI process.
     15
     16        * platform/graphics/gstreamer/GStreamerUtilities.cpp:
     17        (WebCore::extractGStreamerOptionsFromCommandLine): Helper to get the gst options from the current process
     18        command line.
     19        (WebCore::initializeGStreamer): Ensure this is called once. Get the gst options from the given vector or extract
     20        it from the command line if not provided.
     21        * platform/graphics/gstreamer/GStreamerUtilities.h:
     22        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
     23        (WebCore::MediaPlayerPrivateGStreamerBase::initializeGStreamerAndRegisterWebKitElements): Bring back the gst
     24        initialization here.
     25
    1262018-02-23  Philippe Normand  <pnormand@igalia.com>
    227
  • trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp

    r228818 r228946  
    2727#include "GstAllocatorFastMalloc.h"
    2828#include "IntSize.h"
    29 
    3029#include <gst/audio/audio-info.h>
    3130#include <gst/gst.h>
     31#include <mutex>
     32#include <wtf/glib/GLibUtilities.h>
    3233#include <wtf/glib/GUniquePtr.h>
    3334
     
    237238}
    238239
    239 bool initializeGStreamer(Vector<String>& parameters)
    240 {
    241     GUniqueOutPtr<GError> error;
    242     bool isGStreamerInitialized = false;
     240Vector<String> extractGStreamerOptionsFromCommandLine()
     241{
     242    GUniqueOutPtr<char> contents;
     243    gsize length;
     244    if (!g_file_get_contents("/proc/self/cmdline", &contents.outPtr(), &length, nullptr))
     245        return { };
     246
     247    Vector<String> options;
     248    auto optionsString = String::fromUTF8(contents.get(), length);
     249    optionsString.split('\0', false, [&options](StringView item) {
     250        if (item.startsWith("--gst"))
     251            options.append(item.toString());
     252    });
     253    return options;
     254}
     255
     256bool initializeGStreamer(std::optional<Vector<String>>&& options)
     257{
     258    static std::once_flag onceFlag;
     259    static bool isGStreamerInitialized;
     260    std::call_once(onceFlag, [options = WTFMove(options)] {
     261        isGStreamerInitialized = false;
    243262
    244263#if ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
    245     char** argv = g_new0(char*, parameters.size() + 2);
    246     argv[0] = g_strdup("WebProcess");
    247     for (unsigned i = 1; i < parameters.size(); i++)
    248         argv[i] = g_strdup(parameters[i].utf8().data());
    249 
    250     int size = g_strv_length(argv);
    251     isGStreamerInitialized = gst_init_check(&size, &argv, &error.outPtr());
    252     g_strfreev(argv);
    253     ASSERT_WITH_MESSAGE(isGStreamerInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred");
    254 
    255     if (isFastMallocEnabled()) {
    256         const char* disableFastMalloc = getenv("WEBKIT_GST_DISABLE_FAST_MALLOC");
    257         if (!disableFastMalloc || !strcmp(disableFastMalloc, "0"))
    258             gst_allocator_set_default(GST_ALLOCATOR(g_object_new(gst_allocator_fast_malloc_get_type(), nullptr)));
    259     }
     264        Vector<String> parameters = options.value_or(extractGStreamerOptionsFromCommandLine());
     265        char** argv = g_new0(char*, parameters.size() + 2);
     266        int argc = parameters.size() + 1;
     267        argv[0] = g_strdup(g_get_prgname());
     268        for (unsigned i = 0; i < parameters.size(); i++)
     269            argv[i + 1] = g_strdup(parameters[i].utf8().data());
     270
     271        GUniqueOutPtr<GError> error;
     272        isGStreamerInitialized = gst_init_check(&argc, &argv, &error.outPtr());
     273        ASSERT_WITH_MESSAGE(isGStreamerInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred");
     274        g_strfreev(argv);
     275
     276        if (isFastMallocEnabled()) {
     277            const char* disableFastMalloc = getenv("WEBKIT_GST_DISABLE_FAST_MALLOC");
     278            if (!disableFastMalloc || !strcmp(disableFastMalloc, "0"))
     279                gst_allocator_set_default(GST_ALLOCATOR(g_object_new(gst_allocator_fast_malloc_get_type(), nullptr)));
     280        }
    260281
    261282#if ENABLE(VIDEO_TRACK) && USE(GSTREAMER_MPEGTS)
    262     if (isGStreamerInitialized)
    263         gst_mpegts_initialize();
    264 #endif
    265 #endif
    266 
     283        if (isGStreamerInitialized)
     284            gst_mpegts_initialize();
     285#endif
     286#endif
     287    });
    267288    return isGStreamerInitialized;
    268289}
  • trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h

    r228818 r228946  
    7070void mapGstBuffer(GstBuffer*, uint32_t);
    7171void unmapGstBuffer(GstBuffer*);
    72 bool initializeGStreamer(Vector<String>& parameters);
     72Vector<String> extractGStreamerOptionsFromCommandLine();
     73bool initializeGStreamer(std::optional<Vector<String>>&& = std::nullopt);
    7374unsigned getGstPlayFlag(const char* nick);
    7475uint64_t toGstUnsigned64Time(const MediaTime&);
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp

    r228869 r228946  
    140140bool MediaPlayerPrivateGStreamerBase::initializeGStreamerAndRegisterWebKitElements()
    141141{
     142    if (!initializeGStreamer())
     143        return false;
     144
    142145    registerWebKitGStreamerElements();
    143146
  • trunk/Source/WebKit/ChangeLog

    r228942 r228946  
     12018-02-23  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GStreamer][MiniBrowser] Honor GStreamer command line parameters in MiniBrowser
     4        https://bugs.webkit.org/show_bug.cgi?id=173655
     5        <rdar://problem/37706341>
     6
     7        Reviewed by Philippe Normand.
     8
     9        Actually pass the gst command line options to the WebProcess. The options in /proc/self/cmdline are separated by
     10        null characters, so we are effectively passing always the first option only, which is the program name. Then, in
     11        the web process we always ignore the first option and providing WebProcess unconditionally, so we were doing
     12        nothing.
     13
     14        * UIProcess/gtk/WebProcessPoolGtk.cpp:
     15        (WebKit::WebProcessPool::platformInitializeWebProcess): Use WebCore::extractGStreamerOptionsFromCommandLine()
     16        * UIProcess/wpe/WebProcessPoolWPE.cpp:
     17        (WebKit::WebProcessPool::platformInitializeWebProcess): Ditto.
     18        * WebProcess/soup/WebProcessSoup.cpp:
     19        (WebKit::WebProcess::platformInitializeWebProcess): Move the vector.
     20
    1212018-02-22  Yusuke Suzuki  <utatane.tea@gmail.com>
    222
  • trunk/Source/WebKit/UIProcess/gtk/WebProcessPoolGtk.cpp

    r228818 r228946  
    3636#include <JavaScriptCore/RemoteInspectorServer.h>
    3737#include <WebCore/FileSystem.h>
     38#include <WebCore/GStreamerUtilities.h>
    3839#include <WebCore/NotImplemented.h>
    3940#include <WebCore/SchemeRegistry.h>
     
    9394
    9495#if USE(GSTREAMER)
    95     GUniqueOutPtr<gchar> contents;
    96     gsize length;
    97     if (g_file_get_contents("/proc/self/cmdline", &contents.outPtr(), &length, nullptr))
    98         parameters.gstreamerOptions.append(String::fromUTF8(contents.get()));
     96    parameters.gstreamerOptions = WebCore::extractGStreamerOptionsFromCommandLine();
    9997#endif
    10098}
  • trunk/Source/WebKit/UIProcess/wpe/WebProcessPoolWPE.cpp

    r228019 r228946  
    3737#include <JavaScriptCore/RemoteInspectorServer.h>
    3838#include <WebCore/FileSystem.h>
     39#include <WebCore/GStreamerUtilities.h>
    3940#include <WebCore/NotImplemented.h>
    4041#include <WebCore/SchemeRegistry.h>
     
    9394{
    9495    parameters.memoryCacheDisabled = m_memoryCacheDisabled || cacheModel() == CacheModelDocumentViewer;
     96#if USE(GSTREAMER)
     97    parameters.gstreamerOptions = WebCore::extractGStreamerOptionsFromCommandLine();
     98#endif
     99
    95100}
    96101
  • trunk/Source/WebKit/WebProcess/soup/WebProcessSoup.cpp

    r228818 r228946  
    5454#endif
    5555#if USE(GSTREAMER)
    56     WebCore::initializeGStreamer(parameters.gstreamerOptions);
     56    WebCore::initializeGStreamer(WTFMove(parameters.gstreamerOptions));
    5757#endif
    5858}
Note: See TracChangeset for help on using the changeset viewer.